Skip to content

Commit 566ed56

Browse files
committed
include commonjs version in bundled package
Added support for both ESM and CommonJS module formats in the @kubernetes/client-node package. Created tsconfig.cjs.json and tsconfig.esm.json to manage outputs. This change optimizes performance for testing frameworks such as jest that still rely on commonjs
1 parent 87aca92 commit 566ed56

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

package.json

+15-9
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,27 @@
88
"url": "https://github.com/kubernetes-client/javascript.git"
99
},
1010
"files": [
11-
"dist/*.ts",
12-
"dist/*.js",
13-
"dist/gen/*.ts",
14-
"dist/gen/*.js",
15-
"dist/gen/**/*.ts",
16-
"dist/gen/**/*.js",
11+
"dist/{mjs,cjs}/*.ts",
12+
"dist/{mjs,cjs}/*.js",
13+
"dist/{mjs,cjs}/gen/*.ts",
14+
"dist/{mjs,cjs}/gen/*.js",
15+
"dist/{mjs,cjs}/gen/**/*.ts",
16+
"dist/{mjs,cjs}/gen/**/*.js",
1717
"README.md"
1818
],
19-
"main": "dist/index.js",
20-
"types": "dist/index.d.ts",
19+
"main": "dist/mjs/index.js",
20+
"types": "dist/mjs/index.d.ts",
21+
"exports": {
22+
".": {
23+
"require": "./dist/cjs/index.js",
24+
"import": "./dist/esm/index.js"
25+
}
26+
},
2127
"scripts": {
2228
"format": "prettier --log-level error --write \"./src/**/*.ts\"",
2329
"lint": "eslint \".\" && prettier --check \"./src/**/*.ts\"",
2430
"clean": "rm -Rf node_modules/ dist/",
25-
"build": "tsc",
31+
"build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json",
2632
"build-with-tests": "tsc --project tsconfig-with-tests.json && cp 'src/test/echo space.js' dist/test",
2733
"generate": "./generate-client.sh",
2834
"watch": "tsc --watch",

tsconfig.cjs.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"module": "CommonJS",
4+
"moduleResolution": "node",
5+
"outDir": "dist/cjs"
6+
},
7+
"exclude": ["node_modules", "src/*_test.ts", "src/test", "dist"],
8+
"extends": "./tsconfig.json",
9+
"include": ["*.ts", "src/**/*"]
10+
}

tsconfig.esm.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "dist/mjs"
4+
},
5+
"exclude": ["node_modules", "src/*_test.ts", "src/test", "dist"],
6+
"extends": "./tsconfig.json",
7+
"include": ["*.ts", "src/**/*"]
8+
}

tsconfig.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,16 @@
2020
// "declarationMap": true
2121
},
2222
"exclude": ["node_modules", "src/*_test.ts", "src/test", "dist"],
23-
"include": ["*.ts", "src/**/*"]
23+
"include": ["*.ts", "src/**/*"],
24+
"reference": [
25+
{
26+
"path": "tsconfig.cjs.json"
27+
},
28+
{
29+
"path": "tsconfig.mjs.json"
30+
},
31+
{
32+
"path": "tsconfig-with-tests.json"
33+
}
34+
]
2435
}

0 commit comments

Comments
 (0)