From be2f3b6ad0f1ec45ec59471de8e3414f114403f4 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Fri, 15 Mar 2024 09:57:18 +0100 Subject: [PATCH] Output types for ESM and CJS separately --- .github/workflows/build-lint-test.yml | 1 + constraints.pro | 13 +- package.json | 29 ++- scripts/prepack.sh | 2 +- tsconfig.build.json | 24 --- tsup.config.ts | 2 + yarn.lock | 243 +++++++++++++++++++++++++- 7 files changed, 271 insertions(+), 43 deletions(-) delete mode 100644 tsconfig.build.json diff --git a/.github/workflows/build-lint-test.yml b/.github/workflows/build-lint-test.yml index 9a1ecd5fc..ea44fce93 100644 --- a/.github/workflows/build-lint-test.yml +++ b/.github/workflows/build-lint-test.yml @@ -62,6 +62,7 @@ jobs: cache: 'yarn' - run: yarn --immutable --immutable-cache - run: yarn lint + - run: yarn lint:types - name: Validate RC changelog if: ${{ startsWith(github.head_ref, 'release/') }} run: yarn auto-changelog validate --rc diff --git a/constraints.pro b/constraints.pro index a49f04b98..16e96e446 100644 --- a/constraints.pro +++ b/constraints.pro @@ -65,17 +65,18 @@ gen_enforced_field(WorkspaceCwd, 'repository.url', 'https://github.com/MetaMask/ % The license for the package must be specified. gen_enforced_field(WorkspaceCwd, 'license'). -% The type definitions entrypoint the package must be `./dist/types/index.d.ts`. -gen_enforced_field(WorkspaceCwd, 'types', './dist/types/index.d.ts'). -gen_enforced_field(WorkspaceCwd, 'exports["."].types', './dist/types/index.d.ts'). +% The type definitions entrypoint the package must be `./dist/index.d.ts`. +gen_enforced_field(WorkspaceCwd, 'types', './dist/index.d.ts'). % The entrypoint for the package must be `./dist/index.js`. gen_enforced_field(WorkspaceCwd, 'main', './dist/index.js'). -gen_enforced_field(WorkspaceCwd, 'exports["."].require', './dist/index.js'). +gen_enforced_field(WorkspaceCwd, 'exports["."].require.types', './dist/index.d.ts'). +gen_enforced_field(WorkspaceCwd, 'exports["."].require.default', './dist/index.js'). -% The module entrypoint for the package must be `./dist/esm/index.js`. +% The module entrypoint for the package must be `./dist/index.js`. gen_enforced_field(WorkspaceCwd, 'module', './dist/index.mjs'). -gen_enforced_field(WorkspaceCwd, 'exports["."].import', './dist/index.mjs'). +gen_enforced_field(WorkspaceCwd, 'exports["."].import.types', './dist/index.d.mts'). +gen_enforced_field(WorkspaceCwd, 'exports["."].import.default', './dist/index.mjs'). gen_enforced_field(WorkspaceCwd, 'exports["./package.json"]', './package.json'). diff --git a/package.json b/package.json index 72beda3ce..1ce9864e2 100644 --- a/package.json +++ b/package.json @@ -14,27 +14,36 @@ "sideEffects": false, "exports": { ".": { - "import": "./dist/index.mjs", - "require": "./dist/index.js", - "types": "./dist/types/index.d.ts" + "import": { + "types": "./dist/index.d.mts", + "default": "./dist/index.mjs" + }, + "require": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } }, "./node": { - "import": "./dist/node.mjs", - "require": "./dist/node.js", - "types": "./dist/types/node.d.ts" + "import": { + "types": "./dist/node.d.mts", + "default": "./dist/node.mjs" + }, + "require": { + "types": "./dist/node.d.ts", + "default": "./dist/node.js" + } }, "./package.json": "./package.json" }, "main": "./dist/index.js", "module": "./dist/index.mjs", - "types": "./dist/types/index.d.ts", + "types": "./dist/index.d.ts", "files": [ "dist" ], "scripts": { - "build": "tsup && yarn build:types", + "build": "tsup --clean", "build:docs": "typedoc", - "build:types": "tsc --project tsconfig.build.json", "lint": "yarn lint:eslint && yarn lint:constraints && yarn lint:misc --check && yarn lint:dependencies --check && yarn lint:changelog", "lint:changelog": "auto-changelog validate", "lint:constraints": "yarn constraints", @@ -42,6 +51,7 @@ "lint:eslint": "eslint . --cache --ext js,ts", "lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog", "lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern", + "lint:types": "yarn pack && attw package.tgz", "prepack": "./scripts/prepack.sh", "test": "yarn test:source && yarn test:types", "test:source": "jest && jest-it-up", @@ -62,6 +72,7 @@ "superstruct": "^1.0.3" }, "devDependencies": { + "@arethetypeswrong/cli": "^0.15.0", "@lavamoat/allow-scripts": "^2.3.1", "@lavamoat/preinstall-always-fail": "^1.0.0", "@metamask/auto-changelog": "^3.1.0", diff --git a/scripts/prepack.sh b/scripts/prepack.sh index d14605d4d..ad99af58d 100755 --- a/scripts/prepack.sh +++ b/scripts/prepack.sh @@ -8,4 +8,4 @@ if [[ -n $SKIP_PREPACK ]]; then exit 0 fi -yarn build:clean +yarn build diff --git a/tsconfig.build.json b/tsconfig.build.json deleted file mode 100644 index 514d6fe82..000000000 --- a/tsconfig.build.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "declaration": true, - "declarationMap": true, - "emitDeclarationOnly": true, - "inlineSources": true, - "noEmit": false, - "outDir": "dist/types", - "rootDir": "src", - "sourceMap": true - }, - "include": ["./src/**/*.ts"], - "exclude": [ - "./src/**/__fixtures__/**/*", - "./src/**/__mocks__/**/*", - "./src/**/__test__/**/*", - "./src/**/__tests__/**/*", - "./src/**/__snapshots__/**/*", - "./src/**/*.test.ts", - "./src/**/*.test-d.ts", - "./src/**/*.test.*.ts" - ] -} diff --git a/tsup.config.ts b/tsup.config.ts index 618e99217..3de596d0e 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -30,6 +30,8 @@ export default defineConfig({ // https://tsup.egoist.dev/#inject-cjs-and-esm-shims shims: true, + dts: true, + // Hide unnecessary logs from the console. Warnings and errors will still be // shown. silent: true, diff --git a/yarn.lock b/yarn.lock index ef60623db..f8edf1530 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22,6 +22,44 @@ __metadata: languageName: node linkType: hard +"@andrewbranch/untar.js@npm:^1.0.3": + version: 1.0.3 + resolution: "@andrewbranch/untar.js@npm:1.0.3" + checksum: 02555d90423b2ef8a9ce00e6c4254d70dc3214361e702b638c167d228fc0e75d55d0ff0b7f35a4b49ce48072536e503fb5d9bd8cfd1f4f10d5102e42c9f64e76 + languageName: node + linkType: hard + +"@arethetypeswrong/cli@npm:^0.15.0": + version: 0.15.0 + resolution: "@arethetypeswrong/cli@npm:0.15.0" + dependencies: + "@arethetypeswrong/core": 0.15.0 + chalk: ^4.1.2 + cli-table3: ^0.6.3 + commander: ^10.0.1 + marked: ^9.1.2 + marked-terminal: ^6.0.0 + semver: ^7.5.4 + bin: + attw: dist/index.js + checksum: c6948fd30d792e8928d8e1cce162d0c31eee67a1f091c0aed6d767991c94c188cdfdf931fc6a6841b1ba97c033117c9f26672d8d603a3d2cec9ef6fc8240e03a + languageName: node + linkType: hard + +"@arethetypeswrong/core@npm:0.15.0": + version: 0.15.0 + resolution: "@arethetypeswrong/core@npm:0.15.0" + dependencies: + "@andrewbranch/untar.js": ^1.0.3 + fflate: ^0.8.2 + semver: ^7.5.4 + ts-expose-internals-conditionally: 1.0.0-empty.0 + typescript: 5.3.3 + validate-npm-package-name: ^5.0.0 + checksum: 15a48bd011c62e0582075a50c9f2c1db5a00dbafdf828ec8b757e1502acc5b174d00f9954b31326b8239159cf22429173a44ae2635f4293cdd681dc026173cd2 + languageName: node + linkType: hard + "@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.12.13, @babel/code-frame@npm:^7.18.6, @babel/code-frame@npm:^7.22.13": version: 7.22.13 resolution: "@babel/code-frame@npm:7.22.13" @@ -417,6 +455,13 @@ __metadata: languageName: node linkType: hard +"@colors/colors@npm:1.5.0": + version: 1.5.0 + resolution: "@colors/colors@npm:1.5.0" + checksum: d64d5260bed1d5012ae3fc617d38d1afc0329fec05342f4e6b838f46998855ba56e0a73833f4a80fa8378c84810da254f76a8a19c39d038260dc06dc4e007425 + languageName: node + linkType: hard + "@cspotcode/source-map-support@npm:^0.8.0": version: 0.8.1 resolution: "@cspotcode/source-map-support@npm:0.8.1" @@ -1212,6 +1257,7 @@ __metadata: version: 0.0.0-use.local resolution: "@metamask/utils@workspace:." dependencies: + "@arethetypeswrong/cli": ^0.15.0 "@ethereumjs/tx": ^4.2.0 "@lavamoat/allow-scripts": ^2.3.1 "@lavamoat/preinstall-always-fail": ^1.0.0 @@ -1420,6 +1466,13 @@ __metadata: languageName: node linkType: hard +"@sindresorhus/is@npm:^4.6.0": + version: 4.6.0 + resolution: "@sindresorhus/is@npm:4.6.0" + checksum: 83839f13da2c29d55c97abc3bc2c55b250d33a0447554997a85c539e058e57b8da092da396e252b11ec24a0279a0bed1f537fa26302209327060643e327f81d2 + languageName: node + linkType: hard + "@sinonjs/commons@npm:^1.7.0": version: 1.8.3 resolution: "@sinonjs/commons@npm:1.8.3" @@ -1991,6 +2044,15 @@ __metadata: languageName: node linkType: hard +"ansi-escapes@npm:^6.2.0": + version: 6.2.0 + resolution: "ansi-escapes@npm:6.2.0" + dependencies: + type-fest: ^3.0.0 + checksum: f0bc667d5f1ededc3ea89b73c34f0cba95473525b07e1290ddfd3fc868c94614e95f3549f5c4fd0c05424af7d3fd298101fb3d9a52a597d3782508b340783bd7 + languageName: node + linkType: hard + "ansi-regex@npm:^5.0.1": version: 5.0.1 resolution: "ansi-regex@npm:5.0.1" @@ -2044,6 +2106,13 @@ __metadata: languageName: node linkType: hard +"ansicolors@npm:~0.3.2": + version: 0.3.2 + resolution: "ansicolors@npm:0.3.2" + checksum: e84fae7ebc27ac96d9dbb57f35f078cd6dde1b7046b0f03f73dcefc9fbb1f2e82e3685d083466aded8faf038f9fa9ebb408d215282bcd7aaa301d5ac3c486815 + languageName: node + linkType: hard + "any-promise@npm:^1.0.0": version: 1.3.0 resolution: "any-promise@npm:1.3.0" @@ -2366,7 +2435,7 @@ __metadata: languageName: node linkType: hard -"builtins@npm:^5.0.1": +"builtins@npm:^5.0.0, builtins@npm:^5.0.1": version: 5.0.1 resolution: "builtins@npm:5.0.1" dependencies: @@ -2495,6 +2564,18 @@ __metadata: languageName: node linkType: hard +"cardinal@npm:^2.1.1": + version: 2.1.1 + resolution: "cardinal@npm:2.1.1" + dependencies: + ansicolors: ~0.3.2 + redeyed: ~2.1.0 + bin: + cdl: ./bin/cdl.js + checksum: e8d4ae46439cf8fed481c0efd267711ee91e199aa7821a9143e784ed94a6495accd01a0b36d84d377e8ee2cc9928a6c9c123b03be761c60b805f2c026b8a99ad + languageName: node + linkType: hard + "chalk@npm:^2.4.2": version: 2.4.2 resolution: "chalk@npm:2.4.2" @@ -2506,7 +2587,7 @@ __metadata: languageName: node linkType: hard -"chalk@npm:^4.0.0, chalk@npm:^4.1.0, chalk@npm:^4.1.1": +"chalk@npm:^4.0.0, chalk@npm:^4.1.0, chalk@npm:^4.1.1, chalk@npm:^4.1.2": version: 4.1.2 resolution: "chalk@npm:4.1.2" dependencies: @@ -2516,6 +2597,13 @@ __metadata: languageName: node linkType: hard +"chalk@npm:^5.3.0": + version: 5.3.0 + resolution: "chalk@npm:5.3.0" + checksum: 623922e077b7d1e9dedaea6f8b9e9352921f8ae3afe739132e0e00c275971bdd331268183b2628cf4ab1727c45ea1f28d7e24ac23ce1db1eb653c414ca8a5a80 + languageName: node + linkType: hard + "char-regex@npm:^1.0.2": version: 1.0.2 resolution: "char-regex@npm:1.0.2" @@ -2577,6 +2665,19 @@ __metadata: languageName: node linkType: hard +"cli-table3@npm:^0.6.3": + version: 0.6.3 + resolution: "cli-table3@npm:0.6.3" + dependencies: + "@colors/colors": 1.5.0 + string-width: ^4.2.0 + dependenciesMeta: + "@colors/colors": + optional: true + checksum: 09897f68467973f827c04e7eaadf13b55f8aec49ecd6647cc276386ea660059322e2dd8020a8b6b84d422dbdd619597046fa89cbbbdc95b2cea149a2df7c096c + languageName: node + linkType: hard + "cli-width@npm:^3.0.0": version: 3.0.0 resolution: "cli-width@npm:3.0.0" @@ -2668,6 +2769,13 @@ __metadata: languageName: node linkType: hard +"commander@npm:^10.0.1": + version: 10.0.1 + resolution: "commander@npm:10.0.1" + checksum: 436901d64a818295803c1996cd856621a74f30b9f9e28a588e726b2b1670665bccd7c1a77007ebf328729f0139838a88a19265858a0fa7a8728c4656796db948 + languageName: node + linkType: hard + "commander@npm:^4.0.0": version: 4.1.1 resolution: "commander@npm:4.1.1" @@ -3000,6 +3108,13 @@ __metadata: languageName: node linkType: hard +"emojilib@npm:^2.4.0": + version: 2.4.0 + resolution: "emojilib@npm:2.4.0" + checksum: ea241c342abda5a86ffd3a15d8f4871a616d485f700e03daea38c6ce38205847cea9f6ff8d5e962c00516b004949cc96c6e37b05559ea71a0a496faba53b56da + languageName: node + linkType: hard + "encoding@npm:^0.1.13": version: 0.1.13 resolution: "encoding@npm:0.1.13" @@ -3505,7 +3620,7 @@ __metadata: languageName: node linkType: hard -"esprima@npm:^4.0.0": +"esprima@npm:^4.0.0, esprima@npm:~4.0.0": version: 4.0.1 resolution: "esprima@npm:4.0.1" bin: @@ -3698,6 +3813,13 @@ __metadata: languageName: node linkType: hard +"fflate@npm:^0.8.2": + version: 0.8.2 + resolution: "fflate@npm:0.8.2" + checksum: 29470337b85d3831826758e78f370e15cda3169c5cd4477c9b5eea2402261a74b2975bae816afabe1c15d21d98591e0d30a574f7103aa117bff60756fa3035d4 + languageName: node + linkType: hard + "file-entry-cache@npm:^6.0.1": version: 6.0.1 resolution: "file-entry-cache@npm:6.0.1" @@ -5573,6 +5695,22 @@ __metadata: languageName: node linkType: hard +"marked-terminal@npm:^6.0.0": + version: 6.2.0 + resolution: "marked-terminal@npm:6.2.0" + dependencies: + ansi-escapes: ^6.2.0 + cardinal: ^2.1.1 + chalk: ^5.3.0 + cli-table3: ^0.6.3 + node-emoji: ^2.1.3 + supports-hyperlinks: ^3.0.0 + peerDependencies: + marked: ">=1 <12" + checksum: d57b695822a4935e8cbde7fbb2fc1430ec76833d25e8dff5ce531a4cde615ebc4d47cbb5ee46a5acffdb19a53a37a673d7e893e07cae3cc37ff1f37b68ce6fbe + languageName: node + linkType: hard + "marked@npm:^4.2.12": version: 4.3.0 resolution: "marked@npm:4.3.0" @@ -5582,6 +5720,15 @@ __metadata: languageName: node linkType: hard +"marked@npm:^9.1.2": + version: 9.1.6 + resolution: "marked@npm:9.1.6" + bin: + marked: bin/marked.js + checksum: fc8db42e993d0b97a6f12b8edd93635fa30259ef7088982c714b1c0f54b16946dda54f1bb8a80ab1bd6914647a7217a4f482eda96eb7049bf67437c79e75a609 + languageName: node + linkType: hard + "meow@npm:^9.0.0": version: 9.0.0 resolution: "meow@npm:9.0.0" @@ -5884,6 +6031,18 @@ __metadata: languageName: node linkType: hard +"node-emoji@npm:^2.1.3": + version: 2.1.3 + resolution: "node-emoji@npm:2.1.3" + dependencies: + "@sindresorhus/is": ^4.6.0 + char-regex: ^1.0.2 + emojilib: ^2.4.0 + skin-tone: ^2.0.0 + checksum: 9ae5a1fb12fd5ce6885f251f345986115de4bb82e7d06fdc943845fb19260d89d0aaaccbaf85cae39fe7aaa1fc391640558865ba690c9bb8a7236c3ac10bbab0 + languageName: node + linkType: hard + "node-gyp@npm:^9.0.0": version: 9.4.0 resolution: "node-gyp@npm:9.4.0" @@ -6504,6 +6663,15 @@ __metadata: languageName: node linkType: hard +"redeyed@npm:~2.1.0": + version: 2.1.1 + resolution: "redeyed@npm:2.1.1" + dependencies: + esprima: ~4.0.0 + checksum: 39a1426e377727cfb47a0e24e95c1cf78d969fbc388dc1e0fa1e2ef8a8756450cefb8b0c2598f63b85f1a331986fca7604c0db798427a5775a1dbdb9c1291979 + languageName: node + linkType: hard + "regexp.prototype.flags@npm:^1.5.0": version: 1.5.0 resolution: "regexp.prototype.flags@npm:1.5.0" @@ -6804,6 +6972,15 @@ __metadata: languageName: node linkType: hard +"skin-tone@npm:^2.0.0": + version: 2.0.0 + resolution: "skin-tone@npm:2.0.0" + dependencies: + unicode-emoji-modifier-base: ^1.0.0 + checksum: 19de157586b8019cacc55eb25d9d640f00fc02415761f3e41a4527142970fd4e7f6af0333bc90e879858766c20a976107bb386ffd4c812289c01d51f2c8d182c + languageName: node + linkType: hard + "slash@npm:^3.0.0": version: 3.0.0 resolution: "slash@npm:3.0.0" @@ -7168,6 +7345,16 @@ __metadata: languageName: node linkType: hard +"supports-hyperlinks@npm:^3.0.0": + version: 3.0.0 + resolution: "supports-hyperlinks@npm:3.0.0" + dependencies: + has-flag: ^4.0.0 + supports-color: ^7.0.0 + checksum: 41021305de5255b10d821bf93c7a781f783e1693d0faec293d7fc7ccf17011b90bde84b0295fa92ba75c6c390351fe84fdd18848cad4bf656e464a958243c3e7 + languageName: node + linkType: hard + "supports-preserve-symlinks-flag@npm:^1.0.0": version: 1.0.0 resolution: "supports-preserve-symlinks-flag@npm:1.0.0" @@ -7293,6 +7480,13 @@ __metadata: languageName: node linkType: hard +"ts-expose-internals-conditionally@npm:1.0.0-empty.0": + version: 1.0.0-empty.0 + resolution: "ts-expose-internals-conditionally@npm:1.0.0-empty.0" + checksum: 6b4f546fc59f04f68d579f1bc0704541ec17521f84d32a15b45bef5dbc7a787143a065e19541cc5b64ff494f16f223bce59f3f5bf10ec538e5739e23c0efb878 + languageName: node + linkType: hard + "ts-interface-checker@npm:^0.1.9": version: 0.1.13 resolution: "ts-interface-checker@npm:0.1.13" @@ -7512,6 +7706,13 @@ __metadata: languageName: node linkType: hard +"type-fest@npm:^3.0.0": + version: 3.13.1 + resolution: "type-fest@npm:3.13.1" + checksum: c06b0901d54391dc46de3802375f5579868949d71f93b425ce564e19a428a0d411ae8d8cb0e300d330071d86152c3ea86e744c3f2860a42a79585b6ec2fdae8e + languageName: node + linkType: hard + "typed-array-buffer@npm:^1.0.0": version: 1.0.0 resolution: "typed-array-buffer@npm:1.0.0" @@ -7575,6 +7776,16 @@ __metadata: languageName: node linkType: hard +"typescript@npm:5.3.3": + version: 5.3.3 + resolution: "typescript@npm:5.3.3" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 2007ccb6e51bbbf6fde0a78099efe04dc1c3dfbdff04ca3b6a8bc717991862b39fd6126c0c3ebf2d2d98ac5e960bcaa873826bb2bb241f14277034148f41f6a2 + languageName: node + linkType: hard + "typescript@npm:~4.8.4": version: 4.8.4 resolution: "typescript@npm:4.8.4" @@ -7585,6 +7796,16 @@ __metadata: languageName: node linkType: hard +"typescript@patch:typescript@5.3.3#~builtin": + version: 5.3.3 + resolution: "typescript@patch:typescript@npm%3A5.3.3#~builtin::version=5.3.3&hash=a1c5e5" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: f61375590b3162599f0f0d5b8737877ac0a7bc52761dbb585d67e7b8753a3a4c42d9a554c4cc929f591ffcf3a2b0602f65ae3ce74714fd5652623a816862b610 + languageName: node + linkType: hard + "typescript@patch:typescript@~4.8.4#~builtin": version: 4.8.4 resolution: "typescript@patch:typescript@npm%3A4.8.4#~builtin::version=4.8.4&hash=a1c5e5" @@ -7607,6 +7828,13 @@ __metadata: languageName: node linkType: hard +"unicode-emoji-modifier-base@npm:^1.0.0": + version: 1.0.0 + resolution: "unicode-emoji-modifier-base@npm:1.0.0" + checksum: 6e1521d35fa69493207eb8b41f8edb95985d8b3faf07c01d820a1830b5e8403e20002563e2f84683e8e962a49beccae789f0879356bf92a4ec7a4dd8e2d16fdb + languageName: node + linkType: hard + "unique-filename@npm:^2.0.0": version: 2.0.1 resolution: "unique-filename@npm:2.0.1" @@ -7701,6 +7929,15 @@ __metadata: languageName: node linkType: hard +"validate-npm-package-name@npm:^5.0.0": + version: 5.0.0 + resolution: "validate-npm-package-name@npm:5.0.0" + dependencies: + builtins: ^5.0.0 + checksum: 5342a994986199b3c28e53a8452a14b2bb5085727691ea7aa0d284a6606b127c371e0925ae99b3f1ef7cc7d2c9de75f52eb61a3d1cc45e39bca1e3a9444cbb4e + languageName: node + linkType: hard + "vscode-oniguruma@npm:^1.7.0": version: 1.7.0 resolution: "vscode-oniguruma@npm:1.7.0"