-
Notifications
You must be signed in to change notification settings - Fork 334
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
Fix package resolution in legacy Node.js #3816
Conversation
0ae48be
to
92c009d
Compare
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.
Neat! And nice one for the testing. If the answer to my question is "no", then all good to go 🙌🏻
- name: Export ${{ matrix.conditions }}, Node.js ${{ matrix.node-version }} | ||
env: | ||
# Node.js conditions override from "require" to "import" etc | ||
# https://nodejs.org/api/cli.html#-c-condition---conditionscondition | ||
FLAGS: ${{ matrix.conditions != 'require' && format(' --conditions {0}', matrix.conditions) || '' }} | ||
|
||
run: | | ||
node --eval "console.log(require.resolve('govuk-frontend'))"${{ env.FLAGS }} | ||
node --eval "console.log(require.resolve('govuk-frontend/package.json'))"${{ env.FLAGS }} | ||
node --eval "console.log(require.resolve('govuk-frontend/dist/govuk/i18n.js'))"${{ env.FLAGS }} | ||
node --eval "console.log(require.resolve('govuk-frontend/dist/govuk-esm/i18n.mjs'))"${{ env.FLAGS }} |
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.
Brilliant! That's going to be neat to check we're not breaking things by changing package.json
😍
packages/govuk-frontend/package.json
Outdated
"./dist/": "./dist/", | ||
"./package.json": "./package.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.
question: Is there a way we can allow "./" in a similar fashion as "./*"? That'd let us not worry about which folders are specifically accessible 😊
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.
Ah sorry, I started with that but Visual Studio Code gives me this:
Property ./ is not allowed.
Are there any new paths in v5 we should add for legacy Node.js?
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.
This was my thinking process by the way:
- Take the compatibility subpath exports from v4.6.0:
"./govuk/": "./govuk/",
"./govuk-esm/": "./govuk-esm/",
"./package.json": "./package.json"
- Convert compatibility subpath exports for v5
"./dist/govuk/": "./dist/govuk/",
"./dist/govuk-esm/": "./dist/govuk-esm/",
"./package.json": "./package.json"
- Simplify compatibility subpath exports:
"./dist/": "./dist/",
"./package.json": "./package.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.
If you take our package.json files
list (what gets published) we have these that can't be resolved:
govuk-prototype-kit.config.json
README.md
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.
Property ./ is not allowed.
That's shame 😭
If you take our package.json
files
list (what gets published) we have these that can't be resolved:govuk-prototype-kit.config.json README.md
Could we add them to the list of exports for completedness, please and then we can send it through ⛵
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.
Mind if I just do govuk-prototype-kit.config.json
as Node.js can't require/import Markdown?
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.
Done it, but let me know
For context Sass does not resolve package.json fields or exports sass/sass#2739 But bundlers like webpack use “style” and “sass” fields using loaders: https://www.npmjs.com/package/css-loader https://www.npmjs.com/package/sass-loader Note: With “exports” present in package.json the stylesheet exports must appear there too to maintain both backwards and forwards compatibility
92c009d
to
e36bc25
Compare
We switched to “subpath patterns” recently (supported in Node.js 12.20+) but hadn’t realised that “subpath exports” with trailing slashes (not asterisks) were still needed for older versions We need both flavours because trailing slashes in exports were deprecated in Node.js 16 https://nodejs.org/docs/latest-v18.x/api/deprecations.html#dep0148-folder-mappings-in-exports-trailing- Fixes: #3755
e36bc25
to
00dcfd9
Compare
As described in #3755 this PR fixes point 2)
This may also fix issues with bundlers that also follow Node.js package exports resolution