Skip to content

Commit

Permalink
Merge pull request #3817 from alphagov/node-require-v4
Browse files Browse the repository at this point in the history
Fix package resolution in Node.js 17+ for `support/4.x`
  • Loading branch information
colinrotherham authored Jun 22, 2023
2 parents 73c9579 + 4e49b4c commit b68f58b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
49 changes: 49 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,55 @@ jobs:
- name: Run verify task
run: ${{ matrix.task.run }}

package:
name: Export ${{ matrix.conditions }}, Node.js ${{ matrix.node-version }}
runs-on: ${{ github.event.inputs.runner || 'ubuntu-latest' }}
needs: [install]

# Skip when scheduled or run manually
if: ${{ !inputs.runner }}

strategy:
fail-fast: false

matrix:
node-version:
- 12.18 # Node.js 12.18 uses package exports with trailing slashes
- 12 # But Node.js 12.20+ uses package exports with subpath patterns
- 18

conditions:
- require
- import

exclude:
- conditions: import
node-version: 12.18

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Restore dependencies
uses: ./.github/workflows/actions/install-node

- name: Change Node.js version
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- 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/govuk/i18n.js'))"${{ env.FLAGS }}
node --eval "console.log(require.resolve('govuk-frontend/govuk-esm/i18n.mjs'))"${{ env.FLAGS }}
regression:
name: Percy
needs: [install, build]
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

### Fixes

We’ve made fixes to GOV.UK Frontend in the following pull requests:

- [#3817: Fix package resolution in Node.js 17+](https://github.com/alphagov/govuk-frontend/pull/3817)

## 4.6.0 (Feature release)

### New features
Expand Down
4 changes: 3 additions & 1 deletion package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
"version": "4.6.0",
"main": "govuk/all.js",
"module": "govuk-esm/all.mjs",
"sass": "govuk/all.scss",
"exports": {
".": {
"sass": "./govuk/all.scss",
"import": "./govuk-esm/all.mjs",
"require": "./govuk/all.js"
},
"./govuk/": "./govuk/",
"./govuk/*": "./govuk/*",
"./govuk-esm/": "./govuk-esm/",
"./govuk-esm/*": "./govuk-esm/*",
"./package.json": "./package.json"
},
"sideEffects": [
"govuk-esm/vendor/**"
],
"sass": "govuk/all.scss",
"engines": {
"node": ">= 4.2.0"
},
Expand Down

0 comments on commit b68f58b

Please sign in to comment.