Skip to content

Offer both ESM & CommonJS versions of the Javascript client #2240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/integration_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('FullRequest', () => {

const list = await k8sApi.listNamespacedPod({ namespace: 'default' });

return deepEqual(list, result);
deepEqual(list, result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the return here unnecessary? I'm guessing that deepEqual will throw and fail the test if these two object don't match?

Copy link
Author

@lucavb lucavb Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that return was superfluous. The return type is simply void and so it kinda makes no difference.

Here is the method's signature:

function deepEqual(actual: unknown, expected: unknown, message?: string | Error): void;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to a separate PR.

});
});
});
10 changes: 10 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -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/**/*"]
}
8 changes: 8 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "dist/mjs"
},
"exclude": ["node_modules", "src/*_test.ts", "src/test", "dist"],
"extends": "./tsconfig.json",
"include": ["*.ts", "src/**/*"]
}
33 changes: 22 additions & 11 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can argue here about consistency for the tsconfig.json file names if you want.

},
{
"path": "tsconfig.mjs.json"
},
{
"path": "tsconfig-with-tests.json"
}
]
}