Skip to content

Commit ab2e835

Browse files
Mrtenzmetamaskbot
andauthored
Replace tsup with ts-bridge (#2682)
This replaces `tsup` with `ts-bridge`, which fixes several issues we've found in `tsup`. Related to MetaMask/metamask-module-template#247, MetaMask/utils#182. --------- Co-authored-by: MetaMask Bot <[email protected]>
1 parent 338e790 commit ab2e835

File tree

112 files changed

+533
-1415
lines changed

Some content is hidden

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

112 files changed

+533
-1415
lines changed

.github/workflows/build-lint-test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ jobs:
6060
- run: yarn --immutable --immutable-cache
6161
- name: Build
6262
run: yarn build:ci
63-
- name: Build types
64-
run: yarn build:types
6563
- name: Cache build files
6664
uses: actions/cache@v4
6765
with:

.yarn/patches/tsup-npm-8.0.2-86e40f68a7.patch

Lines changed: 0 additions & 13 deletions
This file was deleted.

constraints.pro

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,32 +152,40 @@ gen_enforced_field(WorkspaceCwd, 'sideEffects', 'false') :-
152152
\+ workspace_field(WorkspaceCwd, 'private', true),
153153
WorkspaceCwd \= '.'.
154154

155-
% The type definitions entrypoint for the dependency must be `./dist/types/index.d.ts`.
156-
gen_enforced_field(WorkspaceCwd, 'types', './dist/types/index.d.ts') :-
155+
% The type definitions entrypoint for the dependency must be `./dist/index.d.cts`.
156+
gen_enforced_field(WorkspaceCwd, 'types', './dist/index.d.cts') :-
157157
\+ is_example(WorkspaceCwd),
158158
\+ workspace_field(WorkspaceCwd, 'private', true),
159159
WorkspaceCwd \= '.'.
160-
gen_enforced_field(WorkspaceCwd, 'exports["."].types', './dist/types/index.d.ts') :-
160+
gen_enforced_field(WorkspaceCwd, 'exports["."].types', null) :-
161161
\+ is_example(WorkspaceCwd),
162162
\+ workspace_field(WorkspaceCwd, 'private', true),
163163
WorkspaceCwd \= '.'.
164164

165-
% The entrypoint for the dependency must be `./dist/cjs/index.js`.
166-
gen_enforced_field(WorkspaceCwd, 'main', './dist/index.js') :-
165+
% The entrypoint for the dependency must be `./dist/index.cjs`.
166+
gen_enforced_field(WorkspaceCwd, 'main', './dist/index.cjs') :-
167167
\+ is_example(WorkspaceCwd),
168168
\+ workspace_field(WorkspaceCwd, 'private', true),
169169
WorkspaceCwd \= '.'.
170-
gen_enforced_field(WorkspaceCwd, 'exports["."].require', './dist/index.js') :-
170+
gen_enforced_field(WorkspaceCwd, 'exports["."].require.types', './dist/index.d.cts') :-
171+
\+ is_example(WorkspaceCwd),
172+
\+ workspace_field(WorkspaceCwd, 'private', true),
173+
WorkspaceCwd \= '.'.
174+
gen_enforced_field(WorkspaceCwd, 'exports["."].require.default', './dist/index.cjs') :-
171175
\+ is_example(WorkspaceCwd),
172176
\+ workspace_field(WorkspaceCwd, 'private', true),
173177
WorkspaceCwd \= '.'.
174178

175-
% The module entrypoint for the dependency must be `./dist/esm/index.js`.
179+
% The module entrypoint for the dependency must be `./dist/index.mjs`.
176180
gen_enforced_field(WorkspaceCwd, 'module', './dist/index.mjs') :-
177181
\+ is_example(WorkspaceCwd),
178182
\+ workspace_field(WorkspaceCwd, 'private', true),
179183
WorkspaceCwd \= '.'.
180-
gen_enforced_field(WorkspaceCwd, 'exports["."].import', './dist/index.mjs') :-
184+
gen_enforced_field(WorkspaceCwd, 'exports["."].import.types', './dist/index.d.mts') :-
185+
\+ is_example(WorkspaceCwd),
186+
\+ workspace_field(WorkspaceCwd, 'private', true),
187+
WorkspaceCwd \= '.'.
188+
gen_enforced_field(WorkspaceCwd, 'exports["."].import.default', './dist/index.mjs') :-
181189
\+ is_example(WorkspaceCwd),
182190
\+ workspace_field(WorkspaceCwd, 'private', true),
183191
WorkspaceCwd \= '.'.
@@ -202,22 +210,17 @@ gen_enforced_field(WorkspaceCwd, 'files', ['dist', 'jest-preset.js']) :-
202210
WorkspaceCwd = 'packages/snaps-jest'.
203211

204212
% Dependencies must have a build script.
205-
gen_enforced_field(WorkspaceCwd, 'scripts.build', 'tsup --clean && yarn build:types') :-
213+
gen_enforced_field(WorkspaceCwd, 'scripts.build', 'ts-bridge --project tsconfig.build.json --verbose --no-references') :-
206214
\+ is_example(WorkspaceCwd),
207215
\+ workspace_field(WorkspaceCwd, 'private', true),
208216
WorkspaceCwd \= '.',
209217
WorkspaceCwd \= 'packages/snaps-simulator',
210218
WorkspaceCwd \= 'packages/snaps-cli',
211219
WorkspaceCwd \= 'packages/snaps-execution-environments'.
212-
gen_enforced_field(WorkspaceCwd, 'scripts.build:types', 'tsc --project tsconfig.build.json') :-
220+
gen_enforced_field(WorkspaceCwd, 'scripts.build:types', null) :-
213221
\+ is_example(WorkspaceCwd),
214222
\+ workspace_field(WorkspaceCwd, 'private', true),
215223
WorkspaceCwd \= '.'.
216-
gen_enforced_field(WorkspaceCwd, 'scripts.build:ci', 'tsup --clean') :-
217-
\+ is_example(WorkspaceCwd),
218-
\+ workspace_field(WorkspaceCwd, 'private', true),
219-
WorkspaceCwd \= '.',
220-
WorkspaceCwd \= 'packages/snaps-simulator'.
221224

222225
% Dependencies must have preview scripts.
223226
gen_enforced_field(WorkspaceCwd, 'scripts.publish:preview', 'yarn npm publish --tag preview') :-

package.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@
1919
"lint": "yarn workspaces foreach --all --parallel run lint:eslint && yarn lint:misc --check && yarn lint:tsconfig && yarn constraints && yarn lint:dependencies",
2020
"lint:fix": "yarn workspaces foreach --all --parallel run lint:eslint --fix && yarn lint:misc --write && yarn lint:tsconfig && yarn constraints --fix && yarn dedupe",
2121
"lint:ci": "yarn lint:eslint && yarn lint:misc --check && yarn lint:tsconfig && yarn constraints && yarn lint:dependencies",
22-
"build": "yarn build:source && yarn build:types",
23-
"build:ci": "yarn workspaces filter --include \"packages/*\" --parallel --topological --no-private run build:ci",
24-
"build:clean": "yarn clean && yarn build",
25-
"build:source": "yarn workspaces filter --parallel --topological --exclude \"{packages/examples,packages/examples/packages/invoke-snap}\" run build",
26-
"build:types": "tsc --build tsconfig.build.json",
22+
"build": "ts-bridge --project tsconfig.build.json --verbose && yarn build:examples",
23+
"build:ci": "ts-bridge --project tsconfig.build.json --verbose --clean",
2724
"build:examples": "yarn workspace @metamask/example-snaps build",
2825
"clean": "yarn workspaces foreach --all --parallel --verbose run clean",
2926
"test": "yarn workspaces foreach --all --parallel --verbose run test",
@@ -65,8 +62,7 @@
6562
"luxon@^3.2.1": "patch:luxon@npm%3A3.3.0#./.yarn/patches/luxon-npm-3.3.0-bdbae9bfd5.patch",
6663
"tsconfig-paths@^3.11.0": "patch:tsconfig-paths@npm%3A3.14.2#./.yarn/patches/tsconfig-paths-npm-3.14.2-90ce75420d.patch",
6764
"tsconfig-paths@^3.14.1": "patch:tsconfig-paths@npm%3A3.14.2#./.yarn/patches/tsconfig-paths-npm-3.14.2-90ce75420d.patch",
68-
"tsconfig-paths@^4.1.2": "patch:tsconfig-paths@npm%3A3.14.2#./.yarn/patches/tsconfig-paths-npm-3.14.2-90ce75420d.patch",
69-
"tsup@^8.0.1": "patch:tsup@npm%3A8.0.2#./.yarn/patches/tsup-npm-8.0.2-86e40f68a7.patch"
65+
"tsconfig-paths@^4.1.2": "patch:tsconfig-paths@npm%3A3.14.2#./.yarn/patches/tsconfig-paths-npm-3.14.2-90ce75420d.patch"
7066
},
7167
"devDependencies": {
7268
"@lavamoat/allow-scripts": "^3.0.4",
@@ -78,6 +74,7 @@
7874
"@metamask/eslint-config-typescript": "^12.1.0",
7975
"@metamask/utils": "^9.2.1",
8076
"@swc/core": "1.3.78",
77+
"@ts-bridge/cli": "^0.4.4",
8178
"@types/jest": "^27.5.1",
8279
"@types/node": "18.14.2",
8380
"@typescript-eslint/eslint-plugin": "^5.42.1",
@@ -104,7 +101,6 @@
104101
"semver": "^7.5.4",
105102
"simple-git-hooks": "^2.7.0",
106103
"ts-node": "^10.9.1",
107-
"tsup": "^8.0.1",
108104
"typescript": "~5.3.3",
109105
"vite": "^4.3.9"
110106
},
@@ -122,7 +118,6 @@
122118
"ts-node>@swc/core": true,
123119
"@swc/core": true,
124120
"favicons>sharp": true,
125-
"tsup>esbuild": true,
126121
"vite>esbuild": true
127122
}
128123
},

packages/create-snap/package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,29 @@
1010
"sideEffects": false,
1111
"exports": {
1212
".": {
13-
"import": "./dist/index.mjs",
14-
"require": "./dist/index.js",
15-
"types": "./dist/types/index.d.ts"
13+
"import": {
14+
"types": "./dist/index.d.mts",
15+
"default": "./dist/index.mjs"
16+
},
17+
"require": {
18+
"types": "./dist/index.d.cts",
19+
"default": "./dist/index.cjs"
20+
}
1621
},
1722
"./package.json": "./package.json"
1823
},
19-
"main": "./dist/index.js",
24+
"main": "./dist/index.cjs",
2025
"module": "./dist/index.mjs",
21-
"types": "./dist/types/index.d.ts",
22-
"bin": "./dist/main.js",
26+
"types": "./dist/index.d.cts",
27+
"bin": "./dist/main.cjs",
2328
"files": [
2429
"dist"
2530
],
2631
"scripts": {
27-
"build": "tsup --clean && yarn build:types",
28-
"build:types": "tsc --project tsconfig.build.json",
32+
"build": "ts-bridge --project tsconfig.build.json --verbose --no-references",
2933
"build:chmod": "chmod +x ./dist/main.mjs && chmod +x ./dist/main.js",
3034
"build:clean": "yarn clean && yarn build",
3135
"build:watch": "tsc-watch --onSuccess 'yarn build:chmod'",
32-
"clean": "rimraf '*.tsbuildinfo' 'dist'",
3336
"test": "jest && yarn posttest",
3437
"posttest": "jest-it-up",
3538
"test:watch": "yarn test --watch",
@@ -42,8 +45,7 @@
4245
"publish:package": "../../scripts/publish-package.sh",
4346
"lint:ci": "yarn lint",
4447
"publish:preview": "yarn npm publish --tag preview",
45-
"lint:dependencies": "depcheck",
46-
"build:ci": "tsup --clean"
48+
"lint:dependencies": "depcheck"
4749
},
4850
"dependencies": {
4951
"@metamask/snaps-utils": "workspace:^",
@@ -59,9 +61,9 @@
5961
"@metamask/eslint-config-typescript": "^12.1.0",
6062
"@swc/core": "1.3.78",
6163
"@swc/jest": "^0.2.26",
64+
"@ts-bridge/cli": "^0.4.4",
6265
"@types/jest": "^27.5.1",
6366
"@types/node": "18.14.2",
64-
"@types/rimraf": "^3.0.0",
6567
"@types/yargs": "^17.0.24",
6668
"@typescript-eslint/eslint-plugin": "^5.42.1",
6769
"@typescript-eslint/parser": "^6.21.0",
@@ -80,10 +82,8 @@
8082
"memfs": "^3.4.13",
8183
"prettier": "^2.7.1",
8284
"prettier-plugin-packagejson": "^2.2.11",
83-
"rimraf": "^4.1.2",
8485
"ts-node": "^10.9.1",
8586
"tsc-watch": "^4.5.0",
86-
"tsup": "^8.0.1",
8787
"typescript": "~5.3.3"
8888
},
8989
"engines": {

packages/create-snap/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/types",
5+
"outDir": "./dist",
66
"rootDir": "./src"
77
},
88
"include": ["./src"],

packages/create-snap/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"compilerOptions": {
44
"baseUrl": "./"
55
},
6-
"include": ["./src", "./src/**/*.json", "package.json", "tsup.config.ts"],
6+
"include": ["./src", "./src/**/*.json", "package.json"],
77
"references": [{ "path": "../snaps-cli" }, { "path": "../snaps-utils" }]
88
}

packages/create-snap/tsup.config.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/examples/packages/bip32/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "R8Of/lcLuLbr2AAcUsDD6e0cdbOdHHvHlwxs+BoAHtE=",
10+
"shasum": "oIth1iwHikuY19tkSxTGtl4YzdX1XAiGn2RJl+DAeCs=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/examples/packages/bip44/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snaps.git"
88
},
99
"source": {
10-
"shasum": "8Iyfr16llKRg4UoML6rvo+76L+R6KhKxg8p0GdAczts=",
10+
"shasum": "Ta9rEMnKSdYz7ecxZh++RZyMSW9JVsQVqa+zFLLO87k=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

0 commit comments

Comments
 (0)