Skip to content
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

Generator emits cjs #1138

Merged
merged 4 commits into from
Jan 29, 2025
Merged

Generator emits cjs #1138

merged 4 commits into from
Jan 29, 2025

Conversation

ericanderson
Copy link
Member

@ericanderson ericanderson commented Jan 28, 2025

PR is broken into 3 commits and I recommend you review them by commit.

  1. Actually update the generator to produce valid cjs
  2. All generated code to just use .js extensions everywhere
  3. Tests that node10, node16-esm, and node16-cjs can compile

@ericanderson ericanderson force-pushed the ea.generate-cjs branch 2 times, most recently from 3dcf0ea to cd1f78b Compare January 28, 2025 21:29
target: ScriptTarget.ES2020,
moduleResolution: ModuleResolutionKind.NodeNext,
resolvePackageJsonExports: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

So you have to explicitly set this now because you're not specifying moduleResolution anymore?

More concretely, if module is CommonJS, then moduleResolution becomes node10, in which case, it wont look at exports by default. But if its ES2022, then technically you don't need to explicitly set that line right cuz it'll default on?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. So I want to be sure we are generating in a way that will work with Node16 so I turn this on.

@@ -521,567 +521,567 @@ describe("generator", () => {
expect(
tweakedFilesForSnapshotConsistency(helper.getFiles()),
).toMatchInlineSnapshot(`
{
Copy link
Contributor

Choose a reason for hiding this comment

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

is the main change here that now all the imports and exports have .js?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it just simplified things and I wrote a test project to be sure it didn't matter

@@ -42,21 +42,29 @@ export async function generatePackageJson(options: {
const packageJson = {
name: options.packageName,
version: options.packageVersion,
main: "./index.js",
types: "./index.d.ts",
main: "./cjs/index.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

So are these two fields cjs now because node10 default looks at the main field?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

@@ -68,7 +68,7 @@ jobs:

build:
name: Build and Test
timeout-minutes: 15
timeout-minutes: 20
Copy link
Contributor

Choose a reason for hiding this comment

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

Dang our tests taking long now

Copy link
Contributor

@ssanjay1 ssanjay1 left a comment

Choose a reason for hiding this comment

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

Left some questions above, but approving to unblock

@ericanderson ericanderson merged commit 908c8f6 into main Jan 29, 2025
8 checks passed
@ericanderson ericanderson deleted the ea.generate-cjs branch January 29, 2025 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants