arcanis / clipanion

Type-safe CLI library / framework with no runtime dependencies
https://mael.dev/clipanion/
1.11k stars 64 forks source link

Support Node16 ESM resolution #140

Closed cometkim closed 1 month ago

cometkim commented 1 year ago

This is re-trying PR from https://github.com/arcanis/clipanion/pull/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 commented 1 year ago

Also it should closes #113

cometkim commented 1 year ago

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

cometkim commented 1 year ago

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

cometkim commented 1 year ago

Hmm, PnP doesn't work with TS 4.9?

cometkim commented 1 year ago

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

cometkim commented 1 year ago

Failed to test on TS v5 and Yarn 3.5.0 :/

niieani commented 1 year ago

Looks good! Would also help with #147.

cometkim commented 9 months ago

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

cometkim commented 9 months ago

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.