diff --git a/package.json b/package.json index aff86a6852..fe044f1493 100644 --- a/package.json +++ b/package.json @@ -8,17 +8,29 @@ "url": "https://github.com/kubernetes-client/javascript.git" }, "files": [ - "dist/**/*.ts", - "dist/**/*.js", - "dist/**/*.map" + "dist/{mjs,cjs}/*.js", + "dist/{mjs,cjs}/*.map", + "dist/{mjs,cjs}/*.ts", + "dist/{mjs,cjs}/gen/**/*.js", + "dist/{mjs,cjs}/gen/**/*.map", + "dist/{mjs,cjs}/gen/**/*.ts", + "dist/{mjs,cjs}/gen/*.js", + "dist/{mjs,cjs}/gen/*.map", + "dist/{mjs,cjs}/gen/*.ts" ], - "main": "dist/index.js", - "types": "dist/index.d.ts", + "main": "dist/mjs/index.js", + "types": "dist/mjs/index.d.ts", + "exports": { + ".": { + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js" + } + }, "scripts": { "format": "prettier --log-level error --write \"./src/**/*.ts\"", "lint": "eslint \".\" && prettier --check \"./src/**/*.ts\"", "clean": "rm -Rf node_modules/ dist/", - "build": "tsc", + "build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json", "build-with-tests": "tsc --project tsconfig-with-tests.json && cp 'src/test/echo space.js' dist/test", "generate": "./generate-client.sh", "watch": "tsc --watch", diff --git a/src/integration_test.ts b/src/integration_test.ts index 9749c75dc3..6a60cafa57 100644 --- a/src/integration_test.ts +++ b/src/integration_test.ts @@ -40,7 +40,7 @@ describe('FullRequest', () => { const list = await k8sApi.listNamespacedPod({ namespace: 'default' }); - return deepEqual(list, result); + deepEqual(list, result); }); }); }); diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000000..5a64efd5c8 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "module": "CommonJS", + "moduleResolution": "node", + "outDir": "dist/cjs" + }, + "exclude": ["node_modules", "src/*_test.ts", "src/test", "dist"], + "extends": "./tsconfig.json", + "include": ["*.ts", "src/**/*"] +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000000..d498d20773 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "outDir": "dist/mjs" + }, + "exclude": ["node_modules", "src/*_test.ts", "src/test", "dist"], + "extends": "./tsconfig.json", + "include": ["*.ts", "src/**/*"] +} diff --git a/tsconfig.json b/tsconfig.json index 5991d85b48..314445dde2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,24 +1,35 @@ { "compilerOptions": { - "module": "nodenext", - "noImplicitAny": false, - "target": "es2019", + "declaration": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "importHelpers": true, "lib": ["es2023"], + "module": "nodenext", "moduleResolution": "nodenext", - "removeComments": false, - "sourceMap": true, + "noImplicitAny": false, "noLib": false, - "declaration": true, "outDir": "dist", + "removeComments": false, "rootDir": "src", - "strict": true, - "forceConsistentCasingInFileNames": true, - "importHelpers": true, "skipLibCheck": true, - "esModuleInterop": true + "sourceMap": true, + "strict": true, + "target": "es2019" // enable this in the future // "declarationMap": true }, "exclude": ["node_modules", "src/*_test.ts", "src/test", "dist"], - "include": ["*.ts", "src/**/*"] + "include": ["*.ts", "src/**/*"], + "reference": [ + { + "path": "tsconfig.cjs.json" + }, + { + "path": "tsconfig.mjs.json" + }, + { + "path": "tsconfig-with-tests.json" + } + ] }