Skip to content

Commit

Permalink
Build packages with tsup (#2120)
Browse files Browse the repository at this point in the history
This changes all packages to be built with `tsup`, instead of SWC.
`tsup` uses `esbuild` under the hood, so performance should be
comparable.

More context here: MetaMask/utils#144.
  • Loading branch information
Mrtenz authored and naugtur committed Mar 28, 2024
1 parent 51a1d04 commit ab1e622
Show file tree
Hide file tree
Showing 34 changed files with 182 additions and 248 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ jobs:
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: yarn
Expand Down
8 changes: 3 additions & 5 deletions constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ gen_enforced_field(WorkspaceCwd, 'files', ['dist']) :-
\+ is_example(WorkspaceCwd),
\+ workspace_field(WorkspaceCwd, 'private', true),
WorkspaceCwd \= '.',
WorkspaceCwd \= 'packages/snaps-jest',
WorkspaceCwd \= 'packages/snaps-cli'.
WorkspaceCwd \= 'packages/snaps-jest'.
gen_enforced_field(WorkspaceCwd, 'files', ['dist', 'jest-preset.js']) :-
WorkspaceCwd = 'packages/snaps-jest'.

Expand All @@ -205,9 +204,8 @@ gen_enforced_field(WorkspaceCwd, 'scripts.build', 'tsup --clean && yarn build:ty
\+ workspace_field(WorkspaceCwd, 'private', true),
WorkspaceCwd \= '.',
WorkspaceCwd \= 'packages/snaps-simulator',
WorkspaceCwd \= 'packages/snaps-cli',
WorkspaceCwd \= 'packages/snaps-execution-environments'.
gen_enforced_field(WorkspaceCwd, 'scripts.build:types', 'tsc --project tsconfig.build.json') :-
WorkspaceCwd \= 'packages/snaps-cli'.
gen_enforced_field(WorkspaceCwd, 'build:types', 'tsc --project tsconfig.build.json') :-
\+ is_example(WorkspaceCwd),
\+ workspace_field(WorkspaceCwd, 'private', true),
WorkspaceCwd \= '.'.
Expand Down
2 changes: 0 additions & 2 deletions packages/create-snap/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const { default: baseConfig } = require('../../tsup.config');

const config: Options = {
name: packageJson.name,
external: ['@metamask/create-snap'],
platform: 'node',
};

export default deepmerge<Options>(baseConfig, config);
2 changes: 1 addition & 1 deletion packages/examples/packages/bip32/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "NVydltk67wE3e1uAxlmal62P2EcP+cMfsNZ66EyJ7O4=",
"shasum": "AaLbshZePKcSV2NORnmd5AjzkX5vNQToD3PaE4YpUUQ=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/bip44/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "cGgUQlMw+WDBaoWHvG4s/xaZO47vBrEp9sa+4DhBmTA=",
"shasum": "q5WeZJXrE5mgP2Z6Fo/aJrVuspPsQgsUn3/SmHuwsGY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/browserify/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "8pImYekIrQ0oaGuxf8Lta25MPIq2td4KPEVQ8jWgos8=",
"shasum": "anrkssxnQgvz6naNxnXCSIHGLkc2FoDcKx0BeDoWR/k=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/cronjobs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "J8ekYCK9+rqN9d6qBw85RomNqdXMbkB9s1eHnQkaABs=",
"shasum": "wXAAi/QR4BT1Gp6OiSqCpq+3U7pyRtMQ/LP9LeWwEPk=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/dialogs/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "2omN9u/lT2cXPZ3O6j4wG3W3HBn/6No9JxH4ncqUG6M=",
"shasum": "EepV6igtZ0ZCX579Ws6f9u0/kYnp65+6OK1SgzCm9Dg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/ethers-js/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "dHiE+9mYVkqNRma5GsZprTawv/bDUzcdbeciRzCmkhQ=",
"shasum": "AjzlrjmJQTKwGM77EXcpEzjF9bsKK7up36BSA4qhasU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/get-entropy/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "dTL+fLvEFKI0vtcRZ0ZGxU2menzmWl3rPuOwnsqNMIQ=",
"shasum": "9jRaEw4/0RCp3b3oAI+PK2zcgwupdOnBhaL4zX4pKRg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/home-page/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "+RC3pwNreHxiMjByPmX0vglQye6wRfdfqC3/Y20tnc8=",
"shasum": "4LSF+30bmPlizM/wYBrq4dp72wkcca9rwYyqkz7ZPvY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/images/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "SxUO9T9xJ/R+jHURdjaLvy0Wfq+6+7CkovvO0CB0wxY=",
"shasum": "v2cJ3d1fomwpUzSR+XZCLF88e5k0NOm5aVo8dftKKSU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "opdcmTNMX2T252PmyJIM5ctTJvFr2OzddoIHYXMBgew=",
"shasum": "sKqHlIDCKGyzDhV7wlJTv7RR6m6lrJF4KgyoTacwYao=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "p2DDVeRmZ1peIJOSFP/mkzIX+8TUj8R0Rrh+6cgB1bA=",
"shasum": "ojUZu1+nqCNBVoWHAaDkNRqWx+JVQfaKTOcyGDFD2Wg=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "BXlcBtRno7GhLlq0cqal08ALFJa9G+DP/a1Ad7cTUKY=",
"shasum": "cyr+aslb2DLAQOj2fs5pBwp3l1WKZU6muxrmhsbAtks=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/packages/manage-state/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "f9PoXGMUUbGJtHHvKt715/pvWiHR3KogkfWAV07itaM=",
"shasum": "bTGiQYMk4+EtULq0PhJ3qru/EhL+2gW7G2SPh8mz4XY=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "MV7VAvTwHITNDAKVY71bURgbuwxSegyMd/mTAwrjiSg=",
"shasum": "vR6A7OJh/69dD8OisLbtz+PPHEd2oK+cS6h01E0K+/U=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "8vwJeiNQLkL9YZxlLrfL6tK7Vd3cITEax5aSm6xiDlU=",
"shasum": "cn53UKSOkd/fFq93Nwl2DBkMartFXwyyeoArG9Zxp8w=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/snaps.git"
},
"source": {
"shasum": "76NEiG+oW2yBCnvjY9TAjkitGYBfZ9hipf+i2l2e8uE=",
"shasum": "fT6pbcejyNwb8cjgHPXgFWhpzCNYFuWUIrkuqLP70vU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
6 changes: 2 additions & 4 deletions packages/snaps-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"require": "./dist/index.js",
"types": "./dist/types/index.d.ts"
},
"./package.json": "./package.json",
"./browserslistrc": "./.browserslistrc"
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand All @@ -24,8 +23,7 @@
"mm-snap": "./dist/main.js"
},
"files": [
"dist",
".browserslistrc"
"dist"
],
"scripts": {
"build": "tsup --clean && yarn build:types && yarn build:chmod && yarn build:readme",
Expand Down
1 change: 0 additions & 1 deletion packages/snaps-cli/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const { default: baseConfig } = require('../../tsup.config');
const config: Options = {
name: packageJson.name,
external: ['@metamask/snaps-cli'],
platform: 'node',
};

export default deepmerge<Options>(baseConfig, config);
16 changes: 6 additions & 10 deletions packages/snaps-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@
"require": "./dist/index.js",
"types": "./dist/types/index.d.ts"
},
"./node": {
"import": "./dist/node.mjs",
"require": "./dist/node.js",
"types": "./dist/types/node.d.ts"
},
"./react-native": {
"import": "./dist/react-native.mjs",
"require": "./dist/react-native.js",
"types": "./dist/types/react-native.d.ts"
},
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"browser": {
"./dist/cjs/services": "./dist/cjs/services/browser.js",
"./dist/esm/services": "./dist/esm/services/browser.js"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/types/index.d.ts",
"files": [
"dist"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@
"depcheck>semver>lru-cache>yallist": true
}
},
"depcheck>semver>lru-cache": {
"packages": {
"depcheck>semver>lru-cache>yallist": true
}
},
"readable-stream": {
"packages": {
"browserify>browser-resolve": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@
"depcheck>semver>lru-cache>yallist": true
}
},
"depcheck>semver>lru-cache": {
"packages": {
"depcheck>semver>lru-cache>yallist": true
}
},
"istanbul-lib-report>supports-color>has-flag": {
"globals": {
"process.argv": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@
"depcheck>semver>lru-cache>yallist": true
}
},
"depcheck>semver>lru-cache": {
"packages": {
"depcheck>semver>lru-cache>yallist": true
}
},
"istanbul-lib-report>supports-color>has-flag": {
"globals": {
"process.argv": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@
"depcheck>semver>lru-cache>yallist": true
}
},
"depcheck>semver>lru-cache": {
"packages": {
"depcheck>semver>lru-cache>yallist": true
}
},
"readable-stream": {
"packages": {
"browserify>browser-resolve": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@
"depcheck>semver>lru-cache>yallist": true
}
},
"depcheck>semver>lru-cache": {
"packages": {
"depcheck>semver>lru-cache>yallist": true
}
},
"readable-stream": {
"packages": {
"browserify>browser-resolve": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@
"depcheck>semver>lru-cache>yallist": true
}
},
"depcheck>semver>lru-cache": {
"packages": {
"depcheck>semver>lru-cache>yallist": true
}
},
"readable-stream": {
"packages": {
"browserify>browser-resolve": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/snaps-execution-environments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"lint:changelog": "../../scripts/validate-changelog.sh @metamask/snaps-execution-environments",
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog && yarn lint:dependencies",
"clean": "rimraf '*.tsbuildinfo' 'dist' 'src/__GENERATED__/' 'coverage/*' '__test__/*'",
"build": "tsup --clean && yarn build:types && yarn build:lavamoat",
"build": "tsup --clean && yarn build:types",
"build:types": "tsc --project tsconfig.build.json",
"build:lavamoat": "lavamoat scripts/build.js --policy lavamoat/build-system/policy.json --policyOverride lavamoat/build-system/policy-override.json",
"build:lavamoat:policy": "yarn build:lavamoat --writeAutoPolicy && node scripts/build.js --writeAutoPolicy",
Expand Down
2 changes: 1 addition & 1 deletion packages/snaps-rpc-methods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^12.1.0",
"@metamask/json-rpc-engine": "^8.0.1",
"@metamask/json-rpc-engine": "^7.3.2",
"@swc/core": "1.3.78",
"@swc/jest": "^0.2.26",
"@types/node": "18.14.2",
Expand Down
8 changes: 0 additions & 8 deletions packages/snaps-sdk/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,8 @@ import packageJson from './package.json';
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
const { default: baseConfig } = require('../../tsup.config');

delete baseConfig.entry;

const config: Options = {
name: packageJson.name,
entry: ['src/index.ts'],

// Esbuild is not deterministic when code splitting is enabled. This is
// problematic for building the example Snaps in this repository, so we
// disable code splitting here.
splitting: false,
};

export default deepmerge<Options>(baseConfig, config);
15 changes: 10 additions & 5 deletions packages/snaps-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
"sideEffects": false,
"exports": {
".": {
"browser": {
"import": "./dist/index.browser.mjs",
"require": "./dist/index.browser.js"
},
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/types/index.d.ts"
},
"./node": {
"import": "./dist/node.mjs",
"require": "./dist/node.js",
"types": "./dist/types/node.d.ts"
},
"./test-utils": {
"import": "./dist/test-utils/index.mjs",
"require": "./dist/test-utils/index.js",
Expand All @@ -26,6 +25,12 @@
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"browser": {
"./dist/index.js": "./dist/index.browser.js",
"./dist/index.mjs": "./dist/index.browser.mjs"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/types/index.d.ts",
"files": [
"dist"
Expand Down
Loading

0 comments on commit ab1e622

Please sign in to comment.