-
Notifications
You must be signed in to change notification settings - Fork 532
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
src: convert project from CJS to ESM #2062
Conversation
Thanks for doing this. We do need to make the changes for upstream code in the upstream generator here: Because otherwise we'll overwrite these changes next time we regenerate. |
Oh, it looks like this might already be supported upstream: OpenAPITools/openapi-generator#15440 |
Ah, cool, then we just need to update here: https://github.com/kubernetes-client/gen/blob/master/openapi/typescript-fetch.xml#L26 To add that configuration. |
I ran the generator locally with the diff --cc src/gen/http/http.ts
index 748aa4a2,cc9bdfbb..00000000
--- a/src/gen/http/http.ts
+++ b/src/gen/http/http.ts
@@@ -1,8 -1,8 +1,15 @@@
// TODO: evaluate if we can easily get rid of this library
++<<<<<<< HEAD
+import FormData from "form-data";
+import { URL, URLSearchParams } from 'url';
+import * as http from 'http';
+import * as https from 'https';
++=======
+ import FormData from "form-data.js";
+ import { URL, URLSearchParams } from 'url.js';
+ import * as http from 'http.js';
+ import * as https from 'https.js';
++>>>>>>> 9f3cdd59... gen: generate with importFileExtension option
import { Observable, from } from '../rxjsStub.js';
export * from './isomorphic-fetch.js'; Looking at the generator source code, these lines appear to be incorrect and should not have the extension. So we will need an upstream patch after all - just a much smaller one. |
FWIW, I opened OpenAPITools/openapi-generator#20194. I have no idea what the PR process there is like, or how long it might be until it's available in this repo. We could enable the |
They're usually pretty good about merging PRs fast. Let's give it a couple of days (maybe more because of the holiday) and then go the patch route if it isn't merged by sometime next week. We're going to wait for Kubernetes 1.32 to release (12/11/24) before we cut the 1.0.0 anyway. |
The PR to the generator landed. cjihrig@8973e71 is what updating Is that something that should be PR'ed to this repo? |
Yes we would need this an then regenerate the code with the applied changes. |
OK. Here it is: #2085 |
This commit updates the TypeScript generator options to include importFileExtension. This is done in order to support ESM in the JavaScript client, as ESM requires explicit extensions. Refs: kubernetes-client/javascript#2062
PR to update the XML config in the gen repo: kubernetes-client/gen#275 |
This is necessary for ESM support. Refs: kubernetes-client#2062 Refs: kubernetes-client/gen#275
This commit updates the TypeScript generator options to include importFileExtension. This is done in order to support ESM in the JavaScript client, as ESM requires explicit extensions. Refs: kubernetes-client/javascript#2062
/lgtm |
Looks like there are CI failures related to the script/test we use to make sure that package.json and package-lock.json are in-sync. |
Pushed up a fix for the script. The formatter did some extra work, but this is what I actually added: import { createRequire } from 'node:module';
const require = createRequire(import.meta.url); |
/lgtm |
This is a substantial change that moves the release-1.x branch from CommonJS to ESM as discussed in kubernetes-client#2014. Please review/test carefully. This commit does the following things: - Updates the tsconfig to generate ESM code. The formatter also automatically formatted this file. - Add `"type": "module"` to the `package.json` so that consumers treat this as ESM instead of CJS. - Updates all of the imports to be valid ESM imports. ESM requires that file extensions are provided. TypeScript is smart enough to handle the `.js` extensions, but TypeScript does not support adding the extensions at build time. See microsoft/TypeScript#16577 for more details about this. The `tsc-esm-fix` utility on npm was used to automatically add the extensions. The code generator probably needs to add support for this too if it doesn't already. - Fixup the `jsonpath` imports, as this module does not have a default ESM export. This just means adding `* as` to the existing imports. - Remove the `AbortError` export originating from `node-fetch`. Apparently this is not actually there. I was able to successfully import the transpiled code using `import * as k8s from './dist/index.js';`. This should hopefully unblock running tests against the transpiled code as well (it currently does not work because the openid-client and chai dependencies have both moved to ESM only).
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brendandburns, cjihrig, mstruebing The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This is a substantial change that moves the release-1.x branch from CommonJS to ESM as discussed in
#2014. Please review/test carefully.
This commit does the following things:
"type": "module"
to thepackage.json
so that consumers treat this as ESM instead of CJS..js
extensions, but TypeScript does not support adding the extensions at build time. See Provide a way to add the '.js' file extension to the end of module specifiers microsoft/TypeScript#16577 for more details about this. Thetsc-esm-fix
utility on npm was used to automatically add the extensions. The code generator probably needs to add support for this too if it doesn't already.jsonpath
imports, as this module does not have a default ESM export. This just means adding* as
to the existing imports.AbortError
export originating fromnode-fetch
. Apparently this is not actually there.I was able to successfully import the transpiled code using
import * as k8s from './dist/index.js';
. This should hopefully unblock running tests against the transpiled code as well (it currently does not work because the openid-client and chai dependencies have both moved to ESM only).