-
Notifications
You must be signed in to change notification settings - Fork 262
Fix #245 CJS resolution failure #346
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
Fix #245 CJS resolution failure #346
Conversation
Quick thought - noticed Just to better understand the trajectory here, would there be breakage we’d expect for projects that: rely on Also re: exports, with .js now CJS and .mjs ESM, will each package’s exports map (incl. subpaths like ./realtime, ./utils, ./_shims/*) be updated to route import -> *.mjs and require -> CJS *.js? And we won’t keep "type":"module" in packages where .js is CJS? For comparison, counterpart Apologies for the many questions, I’m happy to rebase #333 as I draft it on top of #346 - just wanted to clarify these |
"scripts": { | ||
"start:cjs": "node index.cjs", | ||
"start:esm": "node index.mjs" | ||
"start:cjs": "node --no-experimental-require-module index.cjs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this option is necessary to turn the esmodule interop option off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it! sounds good :)
cwd: './integration-tests/node', | ||
env: { | ||
...process.env, | ||
NODE_OPTIONS: '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove all the pre-set node options too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, makes sense ..will prevent hidden loader/interop from leaking in
@@ -1,6 +1,6 @@ | |||
{ | |||
"targets": [ | |||
{ "extname": ".js", "module": "es2022", "moduleResolution": "node" }, | |||
{ "extname": ".js", "module": "commonjs", "moduleResolution": "node" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*.js files are CJS compat; *.mjs are ESModule compat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the .js ---> CJS / .mjs --> ESM flip is clear. wondering if will we align each packages/*
exports (incl. subpaths) so import
--> *.mjs
, require
--> *.js
, and drop "type":"module"
where .js
is CJS? If top-level only is intended, all good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. I've revised package.json files to be simpler and clearer to use "require" and "import". Verified the behavior with the integration tests, plus did additional manual tests with a simple project too.
@@ -1,6 +1,6 @@ | |||
{ | |||
"targets": [ | |||
{ "extname": ".js", "module": "es2022", "moduleResolution": "node" }, | |||
{ "extname": ".js", "module": "commonjs", "moduleResolution": "node" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. I've revised package.json files to be simpler and clearer to use "require" and "import". Verified the behavior with the integration tests, plus did additional manual tests with a simple project too.
@@ -14,67 +14,49 @@ | |||
}, | |||
"exports": { | |||
".": { | |||
"require": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to repeat types and default under require; simplified much
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.mjs" | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"default" works too but "import" works with clearer intention with ESModule
}, | ||
"types": "./dist/shims/shims-node.d.ts", | ||
"default": "./dist/shims/shims-node.mjs" | ||
"types": "./dist/shims/shims.d.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shims/shims is just a reference to shims/shims-node, but there is no downside of this change
Yes, you're right.
We basically do not support deep-imports. When a user needs some additional exports, we're happy to add exports of sub directories and/or export those modules under existing exports.
Yes, this is correct.
I don't see the necessity to have dist and dist-cjs. However, if there is anything to add on top of this PR, I am happy to check your PRs! |
@seratch --thanks so much for the detailed explanation and context here, all sounds great :) |
|
Did more tests and this should work well for both CJS and ESModule projects |
This pull request adds the integration test correction on top of @CharlieGreenman's amazing contribution #258; it resolves #245
You can verify this PR resolves the CJS issue by the following steps:
Step 1: Before merging the changes in this PR; follow the steps at https://github.com/openai/openai-agents-js/blob/main/integration-tests/README.md the test fails this way:
Step 2: With the changes in this PR, all the integration tests pass.