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

Fix shared task styles.compile() when loadPaths don’t exist yet #4516

Merged
merged 4 commits into from
Dec 1, 2023

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Nov 29, 2023

This PR fixes a bug where a newly cloned repo can't run:

npm install
npm run build:release

I've tweaked a bit of awful Prettier formatting and added some better comments too

Problem

For our Sass loadPaths we use require.resolve() via packageResolveToPath() to locate govuk-frontend

But Node.js throws “Cannot find module” since npm run build:package hasn't been run yet

Solution

We can use the packageResolveToPath() packageTypeToPath() helper instead

This helper was added when Node.js v17 couldn't use require.resolve() in #3755

Internally we use `require.resolve()` to find GOV.UK Frontend but Node.js throws “Cannot find module” when the package hasn’t been built yet

We can use `packageTypeToPath()` instead
@colinrotherham colinrotherham added the 🐛 bug Something isn't working the way it should (including incorrect wording in documentation) label Nov 29, 2023
Copy link

github-actions bot commented Nov 29, 2023

📋 Stats

File sizes

File Size
dist/govuk-frontend-development.min.css 113.65 KiB
dist/govuk-frontend-development.min.js 38.28 KiB
packages/govuk-frontend/dist/govuk/all.bundle.js 77.78 KiB
packages/govuk-frontend/dist/govuk/all.bundle.mjs 73.09 KiB
packages/govuk-frontend/dist/govuk/all.mjs 3.86 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs 359 B
packages/govuk-frontend/dist/govuk/govuk-frontend.min.css 113.64 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.js 38.27 KiB
packages/govuk-frontend/dist/govuk/i18n.mjs 5.38 KiB

Modules

File Size
all.mjs 69.41 KiB
components/accordion/accordion.mjs 21.67 KiB
components/button/button.mjs 4.7 KiB
components/character-count/character-count.mjs 21.24 KiB
components/checkboxes/checkboxes.mjs 5.83 KiB
components/error-summary/error-summary.mjs 6.09 KiB
components/exit-this-page/exit-this-page.mjs 16.08 KiB
components/header/header.mjs 3.9 KiB
components/notification-banner/notification-banner.mjs 4.54 KiB
components/radios/radios.mjs 4.83 KiB
components/skip-link/skip-link.mjs 3.81 KiB
components/tabs/tabs.mjs 9.66 KiB

View stats and visualisations on the review app


Action run for 66080dc

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4516 November 29, 2023 11:12 Inactive
Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

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

Good spot, neat we can work around not having built yet with packageTypetoPath

function packageTypeToPath(packageName, options = {}) {
const { modulePath, moduleRoot, type = 'commonjs' } = options

// Assume package.json is always resolvable
Copy link
Member

Choose a reason for hiding this comment

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

question Can a package prevent access to its package.json? If not, can we drop the "Assume", please, to avoid confusion when we read back this code in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah sadly it can, so this is the correct comment 😔

With package exports you can quite easily lock yourself out from package.json access

So you'll often see it as a separate entry point:
https://github.com/isaacs/tshy?tab=readme-ov-file#exports

@colinrotherham colinrotherham merged commit 2e803eb into main Dec 1, 2023
45 checks passed
@colinrotherham colinrotherham deleted the release-build branch December 1, 2023 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working the way it should (including incorrect wording in documentation) tooling
Projects
Development

Successfully merging this pull request may close these issues.

3 participants