-
Notifications
You must be signed in to change notification settings - Fork 338
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
Add missing mandatory file extensions for ESM JavaScript #2658
Conversation
Option 2 feels neater to me and I guess it's more "correct" since the source code is esm. Plus I can just imagine some edge case accident with the string replacement in the first option biting us. It works locally for me for various NPM scripts, and the output of One possibly overboard thought: do we want to protect against Rollup bugs by confirming there's no |
Agreed that option 2 seems like the more 'honest' approach, and also puts us on the right track to eventually move entirely to ESM. |
dbff92f
to
4ef5bb2
Compare
4ef5bb2
to
598f378
Compare
08759e0
to
6ca275b
Compare
We added this guidance for govuk-frontend v4.1.0 - when we added the ability to use ES Modules - because our imports were not fully specified (ie: they did not have file extensions). We've [fixed this for v4.1.1](alphagov/govuk-frontend#2658), and this guidance now looks to be unneeded. Part of #194
We added this guidance for govuk-frontend v4.1.0 - when we added the ability to use ES Modules - because our imports were not fully specified (ie: they did not have file extensions). We've [fixed this for v4.1.1](alphagov/govuk-frontend#2658), and this guidance now looks to be unneeded. Part of #194
173ac91
to
06bde04
Compare
Small update needed in the Gulp Tasks doc (.js to .mjs) govuk-frontend/docs/contributing/tasks.md Line 62 in da32bb0
|
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've left a very minor comment, but otherwise this all looks good to me, and still works as expected locally. 🎉
Great spot @domoscargin , thanks! Will change that now |
06bde04
to
adffd54
Compare
… rollup Allows us to add file extensions to the end of our JavaScript imports, which means our ESM code has "fully specified" import paths as required: A file extension must be provided when using the import keyword to resolve relative or absolute specifiers. Directory indexes (e.g. './startup/index.js') must also be fully specified. https://nodejs.org/api/esm.html#mandatory-file-extensions
adffd54
to
b4e1dec
Compare
Fixes #2633
This PR has been updated to go with Option 2, where our JavaScript files are
.mjs
by default.Two approaches here at the moment:
.js
file extensions. This means we need to update these file extensions when we copy the files inpackage/govuk-esm/
so that they reference.mjs
rather than.js
.mjs
as they're already in ESM format. These can be copied directly over topackage/govuk-esm/
with no changes. UMD build (using rollup) gets rid of (resolves) import statements anyway and transform to.js
.