-
-
Notifications
You must be signed in to change notification settings - Fork 302
feat!: replace hybrid CJS/ESM build with ESM-only #9536
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
Changes from all commits
cbec808
8ad8497
27cd674
46d5dc8
dd7cc08
b2866be
d98c991
95d9950
7952c06
a9224fc
2ff2e01
b2724b8
c8b45d8
b27fe5a
87055dc
d547328
cae7015
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,11 @@ module.exports = { | |
| '<rootDir>/../../node_modules/@metamask/$1', | ||
| ], | ||
| '^uuid$': require.resolve('uuid'), | ||
| // The sources import `lodash-es`, because `lodash` is CommonJS and its | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good work figuring this out 👏🏻 |
||
| // named exports cannot be imported from an ES module. The tests compile to | ||
| // CommonJS, where the reverse is true, so they are pointed back at | ||
| // `lodash`. The two have the same API. | ||
| '^lodash-es$': require.resolve('lodash'), | ||
| }, | ||
|
|
||
| // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader | ||
|
|
@@ -190,7 +195,22 @@ module.exports = { | |
| // testURL: "http://localhost", | ||
|
|
||
| // A map from regular expressions to paths to transformers | ||
| // transform: undefined, | ||
| // The packages are ESM, but Jest runs the tests as CommonJS: Jest only | ||
| // treats TypeScript as ESM when the extension is listed in | ||
| // `extensionsToTreatAsEsm`, so overriding the module settings here compiles | ||
| // the sources to CommonJS for tests without affecting the published build. | ||
| transform: { | ||
| '^.+\\.tsx?$': [ | ||
| 'ts-jest', | ||
| { | ||
| tsconfig: { | ||
| module: 'CommonJS', | ||
| moduleResolution: 'Node', | ||
| verbatimModuleSyntax: false, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
| // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation | ||
| // transformIgnorePatterns: undefined | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,15 @@ module.exports = { | |
|
|
||
| preset: 'ts-jest', | ||
|
|
||
| // Unlike the packages, the scripts use `import.meta`, which has no CommonJS | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. I wonder if we can clean this up in the future so we don't have to make these overrides. Or maybe this is just how it has to work from now on until we switch to Vitest...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should just start migrating to Vitest at some point. Cleaning this up otherwise would likely mean migrating all Jest tests to ESM. |
||
| // equivalent, so their tests run as ESM. Jest only treats TypeScript as ESM | ||
| // when the extension is listed here. | ||
| extensionsToTreatAsEsm: ['.ts', '.mts'], | ||
|
|
||
| transform: { | ||
| '^.+\\.m?tsx?$': ['ts-jest', { useESM: true }], | ||
| }, | ||
|
|
||
| // "resetMocks" resets all mocks, including mocked modules, to jest.fn(), | ||
| // between each test case. | ||
| resetMocks: true, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,12 @@ | |
| "packages/*" | ||
| ], | ||
| "files": [], | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "yarn ts-bridge --project tsconfig.build.json --verbose", | ||
| "build": "yarn tsc --build tsconfig.build.json --verbose", | ||
| "build:clean": "yarn build:only-clean && yarn build", | ||
| "build:docs": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run build:docs", | ||
| "build:only-clean": "rimraf -g 'packages/*/dist'", | ||
| "build:only-clean": "rimraf -g 'packages/*/dist' 'packages/*/tsconfig.build.tsbuildinfo'", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, I had always meant to add this but never did 🤦🏻
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be useless anyway for |
||
| "build:types": "tsc --build tsconfig.build.json --verbose", | ||
| "changelog:update": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:update", | ||
| "changelog:validate": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:validate", | ||
|
|
@@ -53,14 +54,15 @@ | |
| "test": "yarn test:scripts --silent --collectCoverage=false --reporters=jest-silent-reporter && yarn test:scripts:shell && yarn test:packages", | ||
| "test:clean": "yarn workspaces foreach --all --parallel --verbose run test:clean && yarn test", | ||
| "test:packages": "yarn test:verbose --silent --collectCoverage=false --reporters=jest-silent-reporter", | ||
| "test:scripts": "NODE_OPTIONS=--experimental-vm-modules yarn jest --config ./jest.config.scripts.js --silent", | ||
| "test:scripts": "NODE_OPTIONS=--experimental-vm-modules yarn jest --config ./jest.config.scripts.cjs --silent", | ||
| "test:scripts:shell": "node_modules/bats/bin/bats scripts/*.bats", | ||
| "test:verbose": "yarn workspaces foreach --all --parallel --verbose run test:verbose", | ||
| "workspaces:list-versions": "./scripts/list-workspace-versions.sh" | ||
| }, | ||
| "devDependencies": { | ||
| "@actions/core": "^3.0.1", | ||
| "@actions/github": "^9.1.1", | ||
| "@jest/globals": "^30.4.1", | ||
| "@lavamoat/allow-scripts": "^3.0.4", | ||
| "@lavamoat/preinstall-always-fail": "^2.1.0", | ||
| "@metamask/create-release-branch": "^4.2.2", | ||
|
|
@@ -74,7 +76,6 @@ | |
| "@metamask/network-controller": "^36.0.0", | ||
| "@metamask/skills": "^0.1.0", | ||
| "@metamask/utils": "^11.11.0", | ||
| "@ts-bridge/cli": "^0.6.4", | ||
| "@types/jest": "^30.0.0", | ||
| "@types/lodash": "^4.14.191", | ||
| "@types/node": "^22.13.14", | ||
|
|
@@ -109,6 +110,7 @@ | |
| "rimraf": "^5.0.5", | ||
| "semver": "^7.6.3", | ||
| "simple-git-hooks": "^2.8.0", | ||
| "ts-jest": "^29.4.11", | ||
| "tsx": "^4.20.5", | ||
| "typescript": "~5.3.3", | ||
| "typescript-eslint": "^8.48.0", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,19 +18,12 @@ | |
| "files": [ | ||
| "dist/" | ||
| ], | ||
| "type": "module", | ||
| "sideEffects": false, | ||
| "main": "./dist/index.cjs", | ||
| "types": "./dist/index.d.cts", | ||
| "exports": { | ||
| ".": { | ||
| "import": { | ||
| "types": "./dist/index.d.mts", | ||
| "default": "./dist/index.mjs" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| }, | ||
|
Comment on lines
24
to
27
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
| "./package.json": "./package.json" | ||
| }, | ||
|
|
@@ -39,8 +32,8 @@ | |
| "registry": "https://registry.npmjs.org/" | ||
| }, | ||
| "scripts": { | ||
| "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references", | ||
| "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean", | ||
| "build": "tsc --project tsconfig.build.json", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, we can add a |
||
| "build:all": "tsc --build tsconfig.build.json --verbose", | ||
| "build:docs": "typedoc", | ||
| "changelog:update": "../../scripts/update-changelog.sh @metamask/account-tree-controller", | ||
| "changelog:validate": "../../scripts/validate-changelog.sh @metamask/account-tree-controller", | ||
|
|
@@ -68,14 +61,13 @@ | |
| "@metamask/superstruct": "^3.4.1", | ||
| "@metamask/utils": "^11.11.0", | ||
| "fast-deep-equal": "^3.1.3", | ||
| "lodash": "^4.17.21" | ||
| "lodash-es": "^4.17.21" | ||
| }, | ||
| "devDependencies": { | ||
| "@metamask/account-api": "^2.0.0", | ||
| "@metamask/auto-changelog": "^6.1.0", | ||
| "@metamask/eth-hd-keyring": "^15.0.0", | ||
| "@metamask/providers": "^22.1.0", | ||
| "@ts-bridge/cli": "^0.6.4", | ||
| "@types/jest": "^30.0.0", | ||
| "deepmerge": "^4.2.2", | ||
| "jest": "^30.4.2", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ import type { NetworkClientId } from '@metamask/network-controller'; | |
| import { isCaipChainId } from '@metamask/utils'; | ||
| import type { CaipChainId } from '@metamask/utils'; | ||
| import type { WritableDraft } from 'immer/dist/internal.js'; | ||
| import { cloneDeep } from 'lodash'; | ||
| import { cloneDeep } from 'lodash-es'; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| import { AccountsControllerMethodActions } from './AccountsController-method-action-types.js'; | ||
| import { projectLogger as log } from './logger.js'; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.