-
Notifications
You must be signed in to change notification settings - Fork 333
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
Update package helpers to support govuk-frontend@4
#3757
Conversation
govuk-frontend@4
govuk-frontend@4
72779c0
to
fd93e21
Compare
govuk-frontend@4
govuk-frontend@4
shared/tasks/styles.mjs
Outdated
@@ -81,8 +87,8 @@ export async function compileStylesheet ([modulePath, { configPath, srcPath, des | |||
|
|||
// Resolve @imports via | |||
loadPaths: [ | |||
packageNameToPath('govuk-frontend', 'dist'), | |||
join(paths.root, 'node_modules') | |||
packageNameToPath('govuk-frontend', 'dist', { requirePaths }), |
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 we need it, this line ensures govuk-frontend
is resolved locally from the review app first
fd93e21
to
5eb1e82
Compare
5eb1e82
to
ffad4e3
Compare
8f3e8c2
to
41f9c77
Compare
620a851
to
4071c94
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.
Nice to be able to pick our version of GOV.UK frontend and good path for resolving things like import.meta.resolve
🙌🏻 Just a couple of suggestions that I think would help us touch this area of the code more easily going forward (one for naming and one for the resolving)? No worries if they miss the mark completely though.
Preparation work to simplify how we call our package helpers, options param coming soon
Used to resolve a package’s main entry point path by name, or by resolving a full entry path using `require.resolve()` against the package’s exports
Whilst Node.js `import.meta.resolve()` is flagged experimental, this helper enables `module` field access for ES modules
Allows us to switch between `govuk-frontend@5` and `govuk-frontend@5` without issue
Node.js `require.resolve()` paths are optionally provided, for example: 1. Review app uses local `node_modules` before project level 2. Package stats uses local `node_modules` before project level This is necessary for workspace `govuk-frontend@4` installs to be found
4071c94
to
9278d1e
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.
Cheers for the changes, looks good to go for me! ⛵
/** | ||
* Return path to package entry from any npm workspace, by type | ||
* | ||
* Wraps {@link packageResolveToPath} to allow the appended `modulePath` to | ||
* include unresolvable paths, globs or files that are not yet built | ||
* | ||
* {@link https://github.com/alphagov/govuk-frontend/issues/3755} | ||
* | ||
* @example | ||
* Resolving components relative to a default package entry | ||
* | ||
* - GOV.UK Frontend v4 './govuk/components/accordion/accordion.mjs' | ||
* - GOV.UK Frontend v5 './dist/govuk/components/accordion/accordion.mjs' | ||
* | ||
* ```mjs | ||
* const templatePath = packageResolveToPath('govuk-frontend', { | ||
* modulePath: `components/accordion/accordion.mjs` | ||
* }) | ||
* ``` | ||
* @param {string} packageName - Installed npm package name | ||
* @param {PackageOptions} [options] - Package resolution options | ||
* @returns {string} Path to installed npm package field | ||
*/ |
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.
Super neat and nice solution for the naming as well 😍
This PR updates our
require.resolve()
package resolution to work with GOV.UK Frontend v4As a workaround for #3755 packageTypeToPath() can resolve paths via the
main
ormodule
fields insteadRollup stats for old releases
Package stats can now be built for
govuk-frontend@4
as shown on branchpackage-resolver-v4
Note: It's necessary to bump our workspace
govuk-frontend
to v5.0.0 to avoid conflict