-
Notifications
You must be signed in to change notification settings - Fork 14
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
Native ESM #57
Native ESM #57
Conversation
8f8a2ee
to
34c75ba
Compare
Ready to go! |
@smorimoto thank you very much for this contribution there's, a lot we can benefit from in here. Can I ask you to split this into different PRs? From going over the code once I can think of a few:
This can help us review and more quickly address each change. Thanks again. |
@febuiles Thanks a lot for the quick response! Actually, I considered that at first, but it's a bit hard to split things into different PRs except Node.js 20 upgrade. The reasons for each are: tsupThis is required to deal with the NCC outputting code which is not ESM compliant. VitestThis is not strictly required, but you will need to make some configuration changes to Jest to test the ESM code with Jest. BiomeThis is also not strictly required, but the difference is much smaller than changing ESLint configuration for ESM. |
c5146af
to
e7bd516
Compare
minify: true, | ||
sourcemap: true, | ||
splitting: true, | ||
target: 'node16', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Node.js 16 is the lower bound in the current "works but deprecated" sense. You should be able to easily update the lower bound to Node.js 20 by simply changing this in the future.
tsconfig.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use the strict recommended TSConfig.
example/tsconfig.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use the strict recommended TSConfig.
I tried to reduce the diff as much as possible. This makes reviewing easier (I guess). |
- name: Install NPM dependencies | ||
run: npm ci | ||
- name: Run all NPM build/test actions | ||
run: npm -w:example rebuild && npm run all -w:example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using prepare instead of prepack eliminates the need for rebuild. But prepack may be less noisy during the development process.
- name: Run all NPM build/test actions | ||
run: npm rebuild && npm run all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
"ci": "biome ci .", | ||
"format": "biome format --write .", | ||
"lint": "biome lint --apply .", | ||
"prepare": "npm run build", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can choose prepare or prepack depending on your needs.
with: | ||
node-version: 16.x | ||
registry-url: https://registry.npmjs.org/ | ||
cache: npm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For small projects, the cache will probably just cause thrashing, which is just a waste of compute resources.
example/package.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just removed unnecessary things out and ran sort-package-json to organise package.json order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ran sort-package-json to organise package.json order.
"directories": { | ||
"test": "test" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be unnecessary.
@@ -2,67 +2,54 @@ | |||
"name": "@github/dependency-submission-toolkit", | |||
"version": "1.2.9", | |||
"description": "A TypeScript library for creating dependency snapshots.", | |||
"prepare": "npm run build", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably misplaced at the top level?
.npmignore
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conflicts with files
in package.json
and is not needed: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#files
@febuiles I left some comments. I hope these help the review process. |
I think all of this makes sense, thanks for your contribution. I went over it and things look good, I'll try to carve up some time to do local testing before merging by next week at the latest. |
@febuiles Sorry for the lot of diff 😅 |
- name: Install NPM dependencies | ||
run: npm ci | ||
- name: Run all NPM build/test actions | ||
run: npm -w:example rebuild && npm run all -w:example | ||
run: npm run --workspace example all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old way doesn't seem to work, so for clarity, use the verbose flag here. That said, the short hand should work if you do the following: -w example
or -w=example
, not -w:example
Signed-off-by: Sora Morimoto <[email protected]>
['list', '--prod', '--all', '--json'], | ||
['list', '--all', '--json', '--omit', 'dev'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--prod
is already deprecated
"*.test.ts" | ||
] | ||
"exclude": ["dist", "node_modules"], | ||
"extends": "@tsconfig/strictest/tsconfig.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL, this is neat!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always recommend using this!
@smorimoto Thank you very much for your contribution. Once #59 is merged we'll do a new major release that will include these changes. |
@febuiles My pleasure! Thank you so much for this fantastic package! The OCaml community is really actively taking advantage of this 🙂 |
Confirmed v2 works with the ESM GHA! Thanks a lot! |
@smorimoto I think @jonjanego could help with that! |
@smorimoto Thanks for reaching out. For purposes of keeping this PR tidy, would you mind sharing some more details about what the OCaml community has built, and what sort of integration that you're thinking of, in a new issue in this repo so we can discuss it there? |
@smorimoto the ESM changes are causing at least one issue I'm aware of: https://github.com/advanced-security/maven-dependency-submission-action/actions/runs/7505596002/job/20435167951, did we miss any steps here? |
@febuiles The reason for that seems to be that the
How about exposing all public APIs in the package root like this? export * from './manifest.js'
export * from './package-cache.js'
export * from './package.js'
export * from './snapshot.js' |
Context
When building actions in ESM, some incompatibilities were caused by packaging using ncc, which caused runtime errors. So the solution is to switch the source to native ESM and generate code for ESM and CJS at build time.
Changes:
tsup
The build system is changed to tsup, and tsc is now used only for type checking. This makes support for both esm and cjs much simpler.
Vitest
Switch to vitest for faster and easier testing in ESM.
Biome
This project is not very complex, so formatting and linting are switched to biome. This results in faster, simpler setup and less dependencies.
.npmignore
If the files field is already included in package.json, you should not have to add the
.npmignore
file. As you can see by running dry-run, there are much fewer sources in the package now.Unpacked Size
1.16 MB
->0.1 MB