From 3fe99cee603007726ecce4be8ae57bd32962d35c Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Thu, 6 Jul 2023 09:20:57 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Ensure=20package=20export=20Node.js=20v12.1?= =?UTF-8?q?8=20test=20doesn=E2=80=99t=20use=20`--conditions`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’re likely to add more package export matrix combinations in future But the flag `--conditions` was only added in Node.js v12.19.0 So rather than do the hard job to “opt out” Node.js 12.18.0 from _every_ incompatible matrix combination, let’s just “opt in” to the package export tests we know will run --- .github/workflows/tests.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6855af4b45..9e5498e176 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -241,17 +241,16 @@ jobs: 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 + - 12 # Node.js 12.20+ uses package exports with subpath patterns + - 18 # Node.js 17+ cannot use package exports with trailing slashes conditions: - require - import - exclude: - - conditions: import - node-version: 12.18 + include: + - conditions: require + node-version: 12.18 # Node.js 12.18 uses package exports with trailing slashes env: # Node.js conditions override from "require" to "import" etc From b0211992c1b1ed9026ec759a15e960ed040877f1 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Thu, 6 Jul 2023 09:24:00 +0100 Subject: [PATCH 2/3] Ensure package export tests can support multiple conditions We may want to add `[browser]` and `[browser, import]` to differentiate exports for Browserify and webpack v4 in future --- .github/workflows/tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9e5498e176..2cfbd54f4a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -232,7 +232,7 @@ jobs: run: ${{ matrix.task.run }} package: - name: Export ${{ matrix.conditions }}, Node.js ${{ matrix.node-version }} + name: Export ${{ join(matrix.conditions, ' ') || 'require' }}, Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest needs: [install, build] @@ -245,17 +245,17 @@ jobs: - 18 # Node.js 17+ cannot use package exports with trailing slashes conditions: - - require - - import + - [require] + - [import] include: - - conditions: require + - conditions: [] node-version: 12.18 # Node.js 12.18 uses package exports with trailing slashes 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) || '' }} + FLAGS: ${{ matrix.conditions[0] != null && format(' --conditions {0}', join(matrix.conditions, ' --conditions ')) || '' }} steps: - name: Checkout From 71b4813ce53e3ec675617631989955b316529828 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Wed, 5 Jul 2023 14:44:58 +0100 Subject: [PATCH 3/3] Add bundled-only package exports for `"browser"` condition Update package exports and add `[browser]` and `[browser, import]` conditions to differentiate exports for Browserify and webpack v4 --- .github/workflows/tests.yml | 2 ++ packages/govuk-frontend/package.json | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2cfbd54f4a..eb920e060a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -247,6 +247,8 @@ jobs: conditions: - [require] - [import] + - [browser, require] + - [browser, import] include: - conditions: [] diff --git a/packages/govuk-frontend/package.json b/packages/govuk-frontend/package.json index 5ccbe51678..d527c4a5a2 100644 --- a/packages/govuk-frontend/package.json +++ b/packages/govuk-frontend/package.json @@ -13,6 +13,12 @@ ], "exports": { ".": { + "browser": { + "sass": "./dist/govuk/all.scss", + "import": "./dist/govuk/all.bundle.mjs", + "require": "./dist/govuk/all.bundle.js", + "default": "./dist/govuk/all.bundle.js" + }, "sass": "./dist/govuk/all.scss", "import": "./dist/govuk/all.mjs", "require": "./dist/govuk/all.bundle.js",