Skip to content

Commit 11fc8a0

Browse files
committed
Publish ESM+CJS; harden exports; target ES2020
Switch to `ts-bridge` so that we can publish this package in both ES module format and CommonJS module format. This is a breaking change as consumers will no longer be allowed to import subpaths. Also ensure that `tsconfig.json` and `tsconfig.build.json` are compatible with the module template. Namely, switch from a compilation target of ES2017 to ES2020. Finally, this also fixes a problem where JavaScript files were not being properly emitted in `dist/`.
1 parent 14a75c2 commit 11fc8a0

File tree

6 files changed

+71
-9
lines changed

6 files changed

+71
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- This package can now be used in ESM environments as well as CommonJS ([#469](https://github.com/MetaMask/smart-transactions-controller/pull/469))
13+
1014
### Changed
1115

1216
- **BREAKING:** Bump peer dependency on `@metamask/network-controller` to `^24.0.0` ([#519](https://github.com/MetaMask/smart-transactions-controller/pull/519))
17+
- **BREAKING:** Disallow subpath exports ([#469](https://github.com/MetaMask/smart-transactions-controller/pull/469))
18+
- **BREAKING:** Update TypeScript compilation target from ES2017 to ES2020 ([#469](https://github.com/MetaMask/smart-transactions-controller/pull/469))
1319

1420
## [16.5.0]
1521

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
coverageReporters: ['text', 'html'],
77
coverageThreshold: {
88
global: {
9-
branches: 75.52,
9+
branches: 74.65,
1010
functions: 92.5,
1111
lines: 92.52,
1212
statements: 92.51,

package.json

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,28 @@
77
"url": "https://github.com/MetaMask/smart-transactions-controller.git"
88
},
99
"license": "SEE LICENSE IN LICENSE",
10-
"main": "dist/index.js",
11-
"types": "dist/index.d.ts",
10+
"sideEffects": false,
11+
"exports": {
12+
".": {
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+
}
21+
},
22+
"./package.json": "./package.json"
23+
},
24+
"main": "./dist/index.cjs",
25+
"module": "./dist/index.mjs",
26+
"types": "./dist/index.d.cts",
1227
"files": [
13-
"dist/"
28+
"dist"
1429
],
1530
"scripts": {
16-
"build": "tsc --project tsconfig.build.json",
17-
"build:clean": "rm -rf dist && yarn build",
18-
"build:link": "yarn build && cd dist && yarn link && rm -rf node_modules && cd ..",
31+
"build": "ts-bridge --project tsconfig.build.json --clean",
1932
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog",
2033
"lint:changelog": "auto-changelog validate --prettier",
2134
"lint:eslint": "eslint . --cache --ext js,ts",
@@ -51,6 +64,7 @@
5164
"@metamask/json-rpc-engine": "^10.0.1",
5265
"@metamask/network-controller": "^24.0.0",
5366
"@metamask/transaction-controller": "^42.0.0",
67+
"@ts-bridge/cli": "^0.6.3",
5468
"@types/jest": "^26.0.24",
5569
"@types/lodash": "^4.14.194",
5670
"@types/node": "^18.19.17",

tsconfig.build.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"declaration": true,
5+
"declarationMap": true,
6+
"emitDeclarationOnly": true,
57
"inlineSources": true,
68
"noEmit": false,
79
"outDir": "dist",

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
"module": "CommonJS",
66
"moduleResolution": "node",
77
"noEmit": true,
8+
"noErrorTruncation": true,
89
"resolveJsonModule": true,
910
"skipLibCheck": true,
1011
"strict": true,
11-
"target": "es2017"
12+
"target": "es2020"
1213
},
1314
"exclude": ["./dist", "**/node_modules"]
1415
}

yarn.lock

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,7 @@ __metadata:
16761676
"@metamask/network-controller": ^24.0.0
16771677
"@metamask/polling-controller": ^12.0.0
16781678
"@metamask/transaction-controller": ^42.0.0
1679+
"@ts-bridge/cli": ^0.6.3
16791680
"@types/jest": ^26.0.24
16801681
"@types/lodash": ^4.14.194
16811682
"@types/node": ^18.19.17
@@ -2071,6 +2072,30 @@ __metadata:
20712072
languageName: node
20722073
linkType: hard
20732074

2075+
"@ts-bridge/cli@npm:^0.6.3":
2076+
version: 0.6.3
2077+
resolution: "@ts-bridge/cli@npm:0.6.3"
2078+
dependencies:
2079+
"@ts-bridge/resolver": ^0.2.0
2080+
chalk: ^5.3.0
2081+
cjs-module-lexer: ^1.3.1
2082+
yargs: ^17.7.2
2083+
peerDependencies:
2084+
typescript: ">=4.8.0"
2085+
bin:
2086+
ts-bridge: ./dist/index.js
2087+
tsbridge: ./dist/index.js
2088+
checksum: e2d9937d60bcde168937ee6d9d25a2e8343fbf2eee084cf9449ea6ec1101da9f7ab21709e118ec26d5284d3ccd6d13d3c978fce7b4d68bdc6b141e69fb125fcf
2089+
languageName: node
2090+
linkType: hard
2091+
2092+
"@ts-bridge/resolver@npm:^0.2.0":
2093+
version: 0.2.0
2094+
resolution: "@ts-bridge/resolver@npm:0.2.0"
2095+
checksum: 3d47ca4f0367a193ed6a19fe1ac36a056547e94e28377869e009a216b2f24a9e5efe90d90de22fd1cf22fa36b84e80f490f328d328cde7675795a19465bf98c4
2096+
languageName: node
2097+
linkType: hard
2098+
20742099
"@types/babel__core@npm:^7.1.14":
20752100
version: 7.20.5
20762101
resolution: "@types/babel__core@npm:7.20.5"
@@ -3036,6 +3061,13 @@ __metadata:
30363061
languageName: node
30373062
linkType: hard
30383063

3064+
"chalk@npm:^5.3.0":
3065+
version: 5.4.1
3066+
resolution: "chalk@npm:5.4.1"
3067+
checksum: 0c656f30b782fed4d99198825c0860158901f449a6b12b818b0aabad27ec970389e7e8767d0e00762175b23620c812e70c4fd92c0210e55fc2d993638b74e86e
3068+
languageName: node
3069+
linkType: hard
3070+
30393071
"char-regex@npm:^1.0.2":
30403072
version: 1.0.2
30413073
resolution: "char-regex@npm:1.0.2"
@@ -3064,6 +3096,13 @@ __metadata:
30643096
languageName: node
30653097
linkType: hard
30663098

3099+
"cjs-module-lexer@npm:^1.3.1":
3100+
version: 1.4.3
3101+
resolution: "cjs-module-lexer@npm:1.4.3"
3102+
checksum: 221a1661a9ff4944b472c85ac7cd5029b2f2dc7f6c5f4ecf887f261503611110b43a48acb6c07f8f04109c772d1637fdb20b31252bf27058f35aa97bf5ad8b12
3103+
languageName: node
3104+
linkType: hard
3105+
30673106
"clean-stack@npm:^2.0.0":
30683107
version: 2.2.0
30693108
resolution: "clean-stack@npm:2.2.0"
@@ -8266,7 +8305,7 @@ __metadata:
82668305
languageName: node
82678306
linkType: hard
82688307

8269-
"yargs@npm:17.7.2, yargs@npm:^17.0.1, yargs@npm:^17.3.1":
8308+
"yargs@npm:17.7.2, yargs@npm:^17.0.1, yargs@npm:^17.3.1, yargs@npm:^17.7.2":
82708309
version: 17.7.2
82718310
resolution: "yargs@npm:17.7.2"
82728311
dependencies:

0 commit comments

Comments
 (0)