Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking: Switch to ESM #24

Merged
merged 23 commits into from Jun 24, 2021
Merged

Breaking: Switch to ESM #24

merged 23 commits into from Jun 24, 2021

Conversation

brettz9
Copy link
Contributor

@brettz9 brettz9 commented Jun 20, 2021

Fixes #22.

Also:

  • Refactor(lint): Fix Object.prototype.hasOwnProperty call as per latest linting requirements
  • Chore(lint): Adjust .eslintrc.json to pass linting of modules; uses ES2021 to support import.meta.url
  • Chore(editorconfig): Add .editorconfig
  • Chore(npm): Update devDeps.
  • Chore(npm) Switches from nyc to c8 due to nyc requiring extra loader: Nyc on ESM Node.js 13 (no babel) istanbuljs/nyc#1287

Using synchronous fs API since top-level await not yet supported (nor is ESM importing of JSON well-supported).

(I'm not sure why in my IDE, Atom, I'm seeing node/no-unsupported-features/es-syntax errors but in the lint script I am not.)

@eslint-github-bot
Copy link

Hi @brettz9!, thanks for the Pull Request

The first commit message isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag must be one of the following:

    The Tag is one of the following:

    • Fix - for a bug fix.
    • Update - either for a backwards-compatible enhancement or for a rule change that adds reported problems.
    • New - implements a new feature.
    • Breaking - for a backwards-incompatible enhancement or feature.
    • Docs - changes to documentation only.
    • Build - changes to build process only.
    • Upgrade - for a dependency upgrade.
    • Chore - for anything that isn't user-facing (for example, refactoring, adding tests, etc.).

    You can use the labels of the issue you are working on to determine the best tag.

Read more about contributing to ESLint here

@brettz9 brettz9 changed the title Feat: Switch to ESM Breaking: Switch to ESM Jun 20, 2021
@brettz9
Copy link
Contributor Author

brettz9 commented Jun 20, 2021

If I can get feedback about whether I'm on the right track with this, I may be able to also look at eslint/eslint-scope#70 and eslint/eslintrc#35 .

nzakas
nzakas previously approved these changes Jun 22, 2021
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. I’d like another set of eyes on it before merging.

Thanks for doing this!

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
aladdin-add
aladdin-add previously approved these changes Jun 22, 2021
Copy link
Member

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mdjermanovic
Copy link
Member

We already have one ESM project: https://github.com/eslint/espree. Ideally, all repositories should be aligned with espree repo in that regard.

README.md Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
@brettz9
Copy link
Contributor Author

brettz9 commented Jun 22, 2021

@mdjermanovic : Do the issues you mentioned comprise the alignment changes you still feel or needed, or were there any other dimensions where you wanted alignment? I've submitted some of the other changes I aaw.

Note that I didn't align with nyc because that is broken with ESM, and I didn't align the rollup script in JSON to specify rollup.config.js as that seems redundant.

Btw, you are using prepublishOnly to invoke the build script while @nzakas mentioned a prepare script. Not sure which you want.

@brettz9
Copy link
Contributor Author

brettz9 commented Jun 22, 2021

Btw, per my alignment with espree, I didn't see much mention of the array you used with exports, though I do see mention of a fallback array in https://nodejs.org/api/packages.html (though nothing else). But I'll take your word it works. :-)

lib/index.js Outdated Show resolved Hide resolved
@mdjermanovic
Copy link
Member

@mdjermanovic : Do the issues you mentioned comprise the alignment changes you still feel or needed, or were there any other dimensions where you wanted alignment? I've submitted some of the other changes I aaw.

Thanks for the changes! I'll check everything again and let you know if there is anything left.

Note that I didn't align with nyc because that is broken with ESM

That's great, coverage is currently broken in the espree repo.

and I didn't align the rollup script in JSON to specify rollup.config.js as that seems redundant.

👍 that's fine

Btw, you are using prepublishOnly to invoke the build script while @nzakas mentioned a prepare script. Not sure which you want

Espree had an additional complexity with update-version. prepare should be fine for this project, and it's also simpler and better for various reasons.

Btw, per my alignment with espree, I didn't see much mention of the array you used with exports

That was discussed in the RFC. It's for compatibility with some Node versions, though I'm not sure if we need that anymore after #23.

@brettz9
Copy link
Contributor Author

brettz9 commented Jun 22, 2021

Ok, cool.

As far as the fallback array, since it seems less documented and more verbose, maybe it is better to avoid it if the version support mentioned in eslint/rfcs#72 (comment) are accurate. Let me know if you want to keep it or revert (and just add the "default" key).

lib/index.js Outdated Show resolved Hide resolved
@nzakas
Copy link
Member

nzakas commented Jun 23, 2021

Regarding prepare vs prepublishOnly: in general we want to use prepare everywhere. Espree had a special case where that wouldn’t work.

@mdjermanovic
Copy link
Member

Linting fails due to missing plugins required by the new eslint-config-eslint. You can add eslint-plugin-node and eslint-plugin-jsdoc.

@brettz9
Copy link
Contributor Author

brettz9 commented Jun 23, 2021

It would be nice to have a small test file that would require("../../dist/eslint-visitor-keys.cjs"), and then check e.g. if getKeys is a function etc., similar to this one:

https://github.com/eslint/espree/blob/main/tests/lib/commonjs.cjs

Added.

@mdjermanovic
Copy link
Member

It might be more suitable to do this freezing in visitor-keys.js now?

// Freeze the keys.
for (const type of NODE_TYPES) {
Object.freeze(KEYS[type]);
}
Object.freeze(KEYS);

README.md Outdated Show resolved Hide resolved
brettz9 and others added 2 commits June 23, 2021 21:40
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
@brettz9
Copy link
Contributor Author

brettz9 commented Jun 23, 2021

It might be more suitable to do this freezing in visitor-keys.js now?

// Freeze the keys.
for (const type of NODE_TYPES) {
Object.freeze(KEYS[type]);
}
Object.freeze(KEYS);

Done.

package.json Outdated Show resolved Hide resolved
.eslintrc.json Outdated Show resolved Hide resolved
.eslintrc.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
brettz9 and others added 3 commits June 23, 2021 22:10
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
.eslintrc.json Outdated Show resolved Hide resolved
@mdjermanovic
Copy link
Member

Does npm run coverage works for you? I'm getting some errors.

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
@brettz9
Copy link
Contributor Author

brettz9 commented Jun 23, 2021

Looks like it is this reported bug: bcoe/c8#184 . It had been working earlier.

(Logging shows that there is a "branchMap" expected but it only has keys 0-6, not key 7 as supplied to it from "b" as obtained from "branches".)

@mdjermanovic
Copy link
Member

Hm, it works when I remove commonjs.cjs test file. Could we maybe split *.js and *.cjs test runs and run only *.js tests through c8, like in the espree repo?

@brettz9
Copy link
Contributor Author

brettz9 commented Jun 23, 2021

Added a commit to split the tests

@mdjermanovic
Copy link
Member

Added a commit to split the tests

It works now, thanks!

lib/visitor-keys.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@brettz9
Copy link
Contributor Author

brettz9 commented Jun 23, 2021

Regarding the dist not exporting map, I've made the change, but just to be clear, as per the parity with espree, the Rollup file does build a sourcemap, so it is available for the repo/development at least.

Likewise with default having been carried over.

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert package to ESM
4 participants