From 5ebb2eeebf6688087f850b3ce193a39550898b6c Mon Sep 17 00:00:00 2001 From: Alex Donesky Date: Wed, 2 Sep 2026 21:37:30 -0500 Subject: [PATCH 1/3] fix: emit ESM-compatible wordlist import Use a namespace import so the generated ESM bundle remains compatible with strict bundlers and add an artifact regression check. --- .github/workflows/build-lint-test.yml | 1 + package.json | 1 + scripts/test-esm-build.js | 14 ++++++++++++++ src/mnemonic.ts | 4 +++- 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 scripts/test-esm-build.js diff --git a/.github/workflows/build-lint-test.yml b/.github/workflows/build-lint-test.yml index 6ff43e28e..7fdcdd02f 100644 --- a/.github/workflows/build-lint-test.yml +++ b/.github/workflows/build-lint-test.yml @@ -32,6 +32,7 @@ jobs: is-high-risk-environment: false node-version: ${{ matrix.node-version }} - run: yarn build + - run: yarn test:build # This step is dependent on the TypeScript build output, so it's run # here, rather than in the test job. - run: yarn test:types diff --git a/package.json b/package.json index 1206bd23c..4457ac61b 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern", "prepack": "./scripts/prepack.sh", "test": "yarn test:source && yarn test:types", + "test:build": "node ./scripts/test-esm-build.js", "test:source": "jest && jest-it-up", "test:types": "tsd", "test:watch": "jest --watch" diff --git a/scripts/test-esm-build.js b/scripts/test-esm-build.js new file mode 100644 index 000000000..90df0a3dd --- /dev/null +++ b/scripts/test-esm-build.js @@ -0,0 +1,14 @@ +const assert = require('node:assert/strict'); +const { readFileSync } = require('node:fs'); +const path = require('node:path'); + +const mnemonicModule = readFileSync( + path.resolve(__dirname, '../dist/mnemonic.mjs'), + 'utf8', +); + +assert.match( + mnemonicModule, + /^import \* as \w+ from "@metamask\/scure-bip39\/dist\/wordlists\/english\.js";$/mu, + 'The ESM build must use a namespace import for the CommonJS wordlist module', +); diff --git a/src/mnemonic.ts b/src/mnemonic.ts index 16815344f..ea462964b 100644 --- a/src/mnemonic.ts +++ b/src/mnemonic.ts @@ -1,4 +1,6 @@ -import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english'; +import * as englishWordlist from '@metamask/scure-bip39/dist/wordlists/english'; + +const { wordlist } = englishWordlist; /** * Transform a typed array containing mnemonic data to the seed phrase. From e1e514913c43f13233f4224c852411a96959d30e Mon Sep 17 00:00:00 2001 From: Alex Donesky Date: Wed, 2 Sep 2026 21:38:28 -0500 Subject: [PATCH 2/3] chore: document ESM wordlist fix --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db8f785c2..02a3c7a15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix ESM compatibility for the BIP-39 mnemonic utilities ([#309](https://github.com/MetaMask/utils/pull/309)) + ## [11.12.0] ### Added From b7f81f2fb625066fd52038c7ce45bcc7c6f05627 Mon Sep 17 00:00:00 2001 From: Alex Donesky Date: Thu, 3 Sep 2026 09:23:18 -0500 Subject: [PATCH 3/3] test: remove ESM artifact check --- .github/workflows/build-lint-test.yml | 1 - package.json | 1 - scripts/test-esm-build.js | 14 -------------- 3 files changed, 16 deletions(-) delete mode 100644 scripts/test-esm-build.js diff --git a/.github/workflows/build-lint-test.yml b/.github/workflows/build-lint-test.yml index 7fdcdd02f..6ff43e28e 100644 --- a/.github/workflows/build-lint-test.yml +++ b/.github/workflows/build-lint-test.yml @@ -32,7 +32,6 @@ jobs: is-high-risk-environment: false node-version: ${{ matrix.node-version }} - run: yarn build - - run: yarn test:build # This step is dependent on the TypeScript build output, so it's run # here, rather than in the test job. - run: yarn test:types diff --git a/package.json b/package.json index 4457ac61b..1206bd23c 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern", "prepack": "./scripts/prepack.sh", "test": "yarn test:source && yarn test:types", - "test:build": "node ./scripts/test-esm-build.js", "test:source": "jest && jest-it-up", "test:types": "tsd", "test:watch": "jest --watch" diff --git a/scripts/test-esm-build.js b/scripts/test-esm-build.js deleted file mode 100644 index 90df0a3dd..000000000 --- a/scripts/test-esm-build.js +++ /dev/null @@ -1,14 +0,0 @@ -const assert = require('node:assert/strict'); -const { readFileSync } = require('node:fs'); -const path = require('node:path'); - -const mnemonicModule = readFileSync( - path.resolve(__dirname, '../dist/mnemonic.mjs'), - 'utf8', -); - -assert.match( - mnemonicModule, - /^import \* as \w+ from "@metamask\/scure-bip39\/dist\/wordlists\/english\.js";$/mu, - 'The ESM build must use a namespace import for the CommonJS wordlist module', -);