Skip to content

Commit 24e4105

Browse files
authored
specify module type in compiled output (#88)
1 parent 8d9be71 commit 24e4105

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Diff for: README.md

+3
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ Install a version of [Node.js] >= 18, possibly with [Homebrew] or [nvm].
2222
npm run build-and-test
2323
```
2424

25+
Followed the advice in [Supporting CommonJS and ESM with Typescript and Node] to produce both CJS and ESM output.
26+
2527
[Homebrew]: https://brew.sh/
2628
[nvm]: https://github.com/nvm-sh/nvm
29+
[Supporting CommonJS and ESM with Typescript and Node]: https://evertpot.com/universal-commonjs-esm-typescript-packages/

Diff for: package.json

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
{
22
"name": "nflx-spectator",
3-
"version": "3.0.0-rc.5",
3+
"version": "3.0.0-rc.6",
44
"license": "Apache-2.0",
55
"homepage": "https://github.com/Netflix/spectator-js",
66
"author": "Netflix Telemetry Engineering <[email protected]>",
77
"type": "module",
88
"main": "cjs/src/index.js",
99
"types": "esm/src/index.d.ts",
1010
"exports": {
11-
"import": "./esm/src/index.js",
12-
"require": "./cjs/src/index.js"
11+
".": {
12+
"import": {
13+
"default": "./cjs/src/index.js",
14+
"types": "./cjs/src/index.d.ts"
15+
},
16+
"require": {
17+
"default": "./esm/src/index.js",
18+
"types": "./esm/src/index.d.ts"
19+
}
20+
}
1321
},
1422
"files": [
1523
"esm/src/**/*",
16-
"cjs/src/**/*.js"
24+
"cjs/src/**/*"
1725
],
1826
"engines": {
1927
"node": ">=18.0.0"
@@ -36,7 +44,9 @@
3644
},
3745
"scripts": {
3846
"clean": "rm -rf cjs coverage esm",
39-
"build": "tsc --module commonjs --outDir cjs; tsc --module es2022 --outDir esm",
47+
"build-cjs": "tsc --module commonjs --outDir cjs; echo '{\"type\": \"commonjs\"}' > cjs/package.json",
48+
"build-esm": "tsc --module es2022 --outDir esm; echo '{\"type\": \"module\"}' > esm/package.json",
49+
"build": "npm run build-cjs; npm run build-esm",
4050
"build-and-test": "npm run build; npm run test",
4151
"lint": "eslint 'src/**/*.ts' 'test/**/*.ts'",
4252
"test": "mocha 'esm/test/**/*.test.js'",

0 commit comments

Comments
 (0)