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

Support Node16 ESM resolution #140

Merged
merged 5 commits into from
Sep 6, 2024
Merged

Support Node16 ESM resolution #140

merged 5 commits into from
Sep 6, 2024

Conversation

cometkim
Copy link
Contributor

@cometkim cometkim commented Feb 7, 2023

This is re-trying PR from #137

Tested on Node v16 with TypeScript v3.8, both CommonJS and ESM

node index.mjs test: OK

import {Command, Option, runExit} from 'clipanion';
 
runExit(class MainCommand extends Command {
  name = Option.String();
 
  async execute() {
    this.context.stdout.write(`Hello ${this.name}!\n`);
  }
})

node index.cjs test OK

const {Command, Option, runExit} = require('clipanion');
 
runExit(class MainCommand extends Command {
  name = Option.String();
 
  async execute() {
    this.context.stdout.write(`Hello ${this.name}!\n`);
  }
})

Note this PR will drop support for Node v14

@cometkim
Copy link
Contributor Author

cometkim commented Feb 7, 2023

Also it should closes #113

@cometkim cometkim marked this pull request as draft February 7, 2023 15:28
@cometkim
Copy link
Contributor Author

cometkim commented Feb 7, 2023

mocha's ESM Resolver doesn't seem to respect exports correctly
It does, but it doesn't correctly resolve source in TypeScript

@cometkim
Copy link
Contributor Author

cometkim commented Feb 7, 2023

Note: multi-input bundle output is broken on rollup@v3

@cometkim cometkim marked this pull request as ready for review February 7, 2023 16:43
tsconfig.json Outdated Show resolved Hide resolved
@cometkim cometkim force-pushed the exports branch 2 times, most recently from decb0da to 075edb7 Compare February 7, 2023 17:19
@cometkim

This comment was marked as outdated.

@cometkim cometkim requested a review from arcanis February 7, 2023 17:46
@cometkim
Copy link
Contributor Author

cometkim commented Mar 1, 2023

Any chance of getting merged? maybe it should be the next major?

@cometkim cometkim force-pushed the exports branch 4 times, most recently from 4ea96b9 to 9b0501b Compare March 17, 2023 15:51
@cometkim

This comment was marked as outdated.

@niieani
Copy link

niieani commented Sep 7, 2023

Looks good! Would also help with #147.

@cometkim
Copy link
Contributor Author

@arcanis cleaned up to be minimal changeset to support NodeJS/TypeScript ESM

@cometkim cometkim force-pushed the exports branch 2 times, most recently from 6a501e6 to aea3797 Compare January 24, 2024 13:20
@cometkim cometkim changed the title use Node16 style subpath exports Support Node16 ESM resolution Jan 24, 2024
Comment on lines +80 to +91
"./platform": {
"node": {
"types": "./lib/platform/node.d.ts",
"require": "./lib/platform/node.js",
"import": "./lib/platform/node.mjs"
},
"browser": {
"types": "./lib/platform/browser.d.ts",
"require": "./lib/platform/browser.js",
"import": "./lib/platform/browser.mjs"
}
},
Copy link
Contributor

@merceyz merceyz Jan 24, 2024

Choose a reason for hiding this comment

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

It's not supposed to be exposed to consumers and bundlers should follow the browser field if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The browser field exists for some legacy bundlers and is not supported by the whole ecosystem widely. eg. TypeScript

@@ -1,10 +1,10 @@
import * as platform from 'clipanion/platform';
Copy link
Contributor

Choose a reason for hiding this comment

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

This change shouldn't be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the node's native way, compatible with the whole ecosystem, including Node, TS, and modern bundlers

"@types/jest": "^29.5.9",
"@types/lodash": "^4.14.179",
"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"@types/rollup": "^0.54.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Rollup includes its own types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's rollup v2

@cometkim
Copy link
Contributor Author

I added e2e.test.ts for ensure Node ESM import and TypeScript configuration work, which is failed without those changes. I tried to make as few changes as possible to fix it.

This is currently the only configuration that is compatible with node, tsc, and @rollup/plugin-node-resolve.

@arcanis arcanis merged commit df01de5 into arcanis:master Sep 6, 2024
6 checks passed
@cometkim cometkim deleted the exports branch October 15, 2024 09:50
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.

4 participants