Skip to content

Commit 87a661d

Browse files
authored
BREAKING: Build packages with tsup (#3998)
## Explanation This changes the build system to build all packages with `tsup`, instead of `tsc`. `tsc` is still used for generating the declaration files and type checking, and `tsup` is used for building the `.js` and (new) `.mjs` files. The benefit of this is that we now have a ESM build as well as a CJS build. ## References See MetaMask/utils#144. ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/accounts-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/address-book-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/announcement-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/approval-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/assets-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/base-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/build-utils` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/composable-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/controller-utils` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/ens-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/eth-json-rpc-provider` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/gas-fee-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/json-rpc-engine` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/json-rpc-middleware-stream` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/keyring-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/logging-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/message-manager` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/name-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/network-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/notification-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/permission-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/permission-log-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/phishing-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/polling-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/preferences-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/queued-request-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/rate-limit-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/selected-network-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/signature-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/transaction-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ### `@metamask/user-operation-controller` - **BREAKING**: Add ESM build. - It's no longer possible to import files from `./dist` directly. ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've highlighted breaking changes using the "BREAKING" category above as appropriate
1 parent 964e389 commit 87a661d

File tree

74 files changed

+1156
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1156
-70
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/dist/index.js b/dist/index.js
2+
index 4500c4e43c3bbd24aa60b7d4cf95aa3fee8eb185..9c442bc216f99b7cfadb5ac62cb98d3ae9ce2f56 100644
3+
--- a/dist/index.js
4+
+++ b/dist/index.js
5+
@@ -1813,6 +1813,8 @@ var cjsSplitting = () => {
6+
}
7+
const { transform: transform3 } = await Promise.resolve().then(() => require("sucrase"));
8+
const result = transform3(code, {
9+
+ // https://github.com/egoist/tsup/issues/1087
10+
+ disableESTransforms: true,
11+
filePath: info.path,
12+
transforms: ["imports"],
13+
sourceMapOptions: this.options.sourcemap ? {

constraints.pro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,27 @@ gen_enforced_field(WorkspaceCwd, 'types', './dist/index.d.ts') :-
244244
gen_enforced_field(WorkspaceCwd, 'types', null) :-
245245
workspace_field(WorkspaceCwd, 'private', true).
246246

247+
% The exports for all published packages must be the same.
248+
gen_enforced_field(WorkspaceCwd, 'exports["."].import', './dist/index.mjs') :-
249+
\+ workspace_field(WorkspaceCwd, 'private', true).
250+
gen_enforced_field(WorkspaceCwd, 'exports["."].require', './dist/index.js') :-
251+
\+ workspace_field(WorkspaceCwd, 'private', true).
252+
gen_enforced_field(WorkspaceCwd, 'exports["."].types', './dist/types/index.d.ts') :-
253+
\+ workspace_field(WorkspaceCwd, 'private', true).
254+
gen_enforced_field(WorkspaceCwd, 'exports["./package.json"]', './package.json') :-
255+
\+ workspace_field(WorkspaceCwd, 'private', true).
256+
% Non-published packages must not specify exports.
257+
gen_enforced_field(WorkspaceCwd, 'exports', null) :-
258+
workspace_field(WorkspaceCwd, 'private', true).
259+
260+
% Published packages must not have side effects.
261+
gen_enforced_field(WorkspaceCwd, 'sideEffects', false) :-
262+
\+ workspace_field(WorkspaceCwd, 'private', true),
263+
WorkspaceCwd \= 'packages/base-controller'.
264+
% Non-published packages must not specify side effects.
265+
gen_enforced_field(WorkspaceCwd, 'sideEffects', null) :-
266+
workspace_field(WorkspaceCwd, 'private', true).
267+
247268
% The list of files included in published packages must only include files
248269
% generated during the build step.
249270
gen_enforced_field(WorkspaceCwd, 'files', ['dist/']) :-
@@ -254,6 +275,10 @@ gen_enforced_field(WorkspaceCwd, 'files', ['dist/']) :-
254275
gen_enforced_field(WorkspaceCwd, 'files', []) :-
255276
WorkspaceCwd = '.'.
256277

278+
% All non-root packages must have the same "build" script.
279+
gen_enforced_field(WorkspaceCwd, 'scripts.build', 'tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean') :-
280+
WorkspaceCwd \= '.'.
281+
257282
% All non-root packages must have the same "build:docs" script.
258283
gen_enforced_field(WorkspaceCwd, 'scripts.build:docs', 'typedoc') :-
259284
WorkspaceCwd \= '.'.

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
"packages/*"
1313
],
1414
"scripts": {
15-
"build": "tsc --build tsconfig.build.json --verbose",
15+
"build": "yarn run build:source && yarn run build:types",
1616
"build:clean": "rimraf dist '**/*.tsbuildinfo' && yarn build",
1717
"build:docs": "yarn workspaces foreach --parallel --interlaced --verbose run build:docs",
18+
"build:source": "yarn workspaces foreach --exclude @metamask/core-monorepo --parallel --interlaced --verbose run build",
19+
"build:types": "tsc --build tsconfig.build.json --verbose",
1820
"build:watch": "yarn run build --watch",
1921
"changelog:update": "yarn workspaces foreach --parallel --interlaced --verbose run changelog:update",
2022
"changelog:validate": "yarn workspaces foreach --parallel --interlaced --verbose run changelog:validate",
@@ -40,6 +42,9 @@
4042
"simple-git-hooks": {
4143
"pre-push": "yarn lint"
4244
},
45+
"resolutions": {
46+
"tsup@^8.0.2": "patch:tsup@npm%3A8.0.2#./.yarn/patches/tsup-npm-8.0.2-86e40f68a7.patch"
47+
},
4348
"devDependencies": {
4449
"@babel/core": "^7.23.5",
4550
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
@@ -77,9 +82,9 @@
7782
"nock": "^13.3.1",
7883
"prettier": "^2.7.1",
7984
"prettier-plugin-packagejson": "^2.4.5",
80-
"rimraf": "^3.0.2",
8185
"simple-git-hooks": "^2.8.0",
8286
"ts-node": "^10.9.1",
87+
"tsup": "^8.0.2",
8388
"typescript": "~4.8.4",
8489
"yargs": "^17.7.2"
8590
},
@@ -92,7 +97,8 @@
9297
"@lavamoat/preinstall-always-fail": false,
9398
"@keystonehq/bc-ur-registry-eth>hdkey>secp256k1": true,
9499
"babel-runtime>core-js": false,
95-
"simple-git-hooks": false
100+
"simple-git-hooks": false,
101+
"tsup>esbuild": true
96102
}
97103
}
98104
}

packages/accounts-controller/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@
1515
"url": "https://github.com/MetaMask/core.git"
1616
},
1717
"license": "MIT",
18+
"sideEffects": false,
19+
"exports": {
20+
".": {
21+
"import": "./dist/index.mjs",
22+
"require": "./dist/index.js",
23+
"types": "./dist/types/index.d.ts"
24+
},
25+
"./package.json": "./package.json"
26+
},
1827
"main": "./dist/index.js",
1928
"types": "./dist/index.d.ts",
2029
"files": [
2130
"dist/"
2231
],
2332
"scripts": {
33+
"build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean",
2434
"build:docs": "typedoc",
2535
"changelog:update": "../../scripts/update-changelog.sh @metamask/accounts-controller",
2636
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/accounts-controller",

packages/accounts-controller/tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "../../tsconfig.packages.build.json",
33
"compilerOptions": {
44
"baseUrl": "./",
5-
"outDir": "./dist",
5+
"outDir": "./dist/types",
66
"rootDir": "./src",
77
"skipLibCheck": true
88
},

packages/address-book-controller/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@
1515
"url": "https://github.com/MetaMask/core.git"
1616
},
1717
"license": "MIT",
18+
"sideEffects": false,
19+
"exports": {
20+
".": {
21+
"import": "./dist/index.mjs",
22+
"require": "./dist/index.js",
23+
"types": "./dist/types/index.d.ts"
24+
},
25+
"./package.json": "./package.json"
26+
},
1827
"main": "./dist/index.js",
1928
"types": "./dist/index.d.ts",
2029
"files": [
2130
"dist/"
2231
],
2332
"scripts": {
33+
"build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean",
2434
"build:docs": "typedoc",
2535
"changelog:update": "../../scripts/update-changelog.sh @metamask/address-book-controller",
2636
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/address-book-controller",

packages/address-book-controller/tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "../../tsconfig.packages.build.json",
33
"compilerOptions": {
44
"baseUrl": "./",
5-
"outDir": "./dist",
5+
"outDir": "./dist/types",
66
"rootDir": "./src"
77
},
88
"references": [

packages/announcement-controller/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@
1515
"url": "https://github.com/MetaMask/core.git"
1616
},
1717
"license": "MIT",
18+
"sideEffects": false,
19+
"exports": {
20+
".": {
21+
"import": "./dist/index.mjs",
22+
"require": "./dist/index.js",
23+
"types": "./dist/types/index.d.ts"
24+
},
25+
"./package.json": "./package.json"
26+
},
1827
"main": "./dist/index.js",
1928
"types": "./dist/index.d.ts",
2029
"files": [
2130
"dist/"
2231
],
2332
"scripts": {
33+
"build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean",
2434
"build:docs": "typedoc",
2535
"changelog:update": "../../scripts/update-changelog.sh @metamask/announcement-controller",
2636
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/announcement-controller",

packages/announcement-controller/tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "../../tsconfig.packages.build.json",
33
"compilerOptions": {
44
"baseUrl": "./",
5-
"outDir": "./dist",
5+
"outDir": "./dist/types",
66
"rootDir": "./src"
77
},
88
"references": [{ "path": "../base-controller/tsconfig.build.json" }],

packages/approval-controller/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@
1515
"url": "https://github.com/MetaMask/core.git"
1616
},
1717
"license": "MIT",
18+
"sideEffects": false,
19+
"exports": {
20+
".": {
21+
"import": "./dist/index.mjs",
22+
"require": "./dist/index.js",
23+
"types": "./dist/types/index.d.ts"
24+
},
25+
"./package.json": "./package.json"
26+
},
1827
"main": "./dist/index.js",
1928
"types": "./dist/index.d.ts",
2029
"files": [
2130
"dist/"
2231
],
2332
"scripts": {
33+
"build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean",
2434
"build:docs": "typedoc",
2535
"changelog:update": "../../scripts/update-changelog.sh @metamask/approval-controller",
2636
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/approval-controller",

0 commit comments

Comments
 (0)