diff --git a/cli/codegen/commands.ts b/cli/codegen/commands.ts index 33983d71..2bdba2a0 100644 --- a/cli/codegen/commands.ts +++ b/cli/codegen/commands.ts @@ -103,12 +103,6 @@ const NEW_OPTIONS: CommandSchema = { description: 'Whether to run the command in dry-run mode', default: false, }, - { - name: 'esm', - type: 'boolean', - description: 'Whether enable ESM support', - default: false, - }, ], } diff --git a/cli/docs/new.md b/cli/docs/new.md index c4341923..ad17bfdb 100644 --- a/cli/docs/new.md +++ b/cli/docs/new.md @@ -35,4 +35,3 @@ new NapiCli().new({ | enableTypeDef | --enable-type-def | boolean | false | true | Whether enable the `type-def` feature for typescript definitions auto-generation | | enableGithubActions | --enable-github-actions | boolean | false | true | Whether generate preconfigured GitHub Actions workflow | | dryRun | --dry-run | boolean | false | false | Whether to run the command in dry-run mode | -| esm | --esm | boolean | false | false | Whether enable ESM support | diff --git a/cli/src/api/build.ts b/cli/src/api/build.ts index 11133ae6..06cecaf2 100644 --- a/cli/src/api/build.ts +++ b/cli/src/api/build.ts @@ -149,6 +149,7 @@ class Builder { const controller = new AbortController() + const watch = this.options.watch const buildTask = new Promise((resolve, reject) => { const command = process.env.CARGO ?? (this.options.useCross ? 'cross' : 'cargo') @@ -157,7 +158,7 @@ class Builder { ...process.env, ...this.envs, }, - stdio: 'inherit', + stdio: watch ? ['inherit', 'inherit', 'pipe'] : 'inherit', cwd: this.cwd, signal: controller.signal, }) @@ -178,6 +179,15 @@ class Builder { }), ) }) + + // watch mode only, they are piped through stderr + buildProcess.stderr?.on('data', (data) => { + const output = data.toString() + console.error(output) + if (/Finished\s(dev|release)/.test(output)) { + this.postBuild().catch(() => {}) + } + }) }) return { @@ -207,6 +217,7 @@ class Builder { this.crateDir, '--', 'cargo', + 'build', ) set = true } diff --git a/cli/src/api/new.ts b/cli/src/api/new.ts index 185ffbd8..667226c1 100644 --- a/cli/src/api/new.ts +++ b/cli/src/api/new.ts @@ -146,7 +146,6 @@ function generatePackageJson(options: NewOptions): Output { license: options.license, engineRequirement: napiEngineRequirement(options.minNodeApiVersion), cliVersion: CLI_VERSION, - esm: options.esm, }), } } diff --git a/cli/src/api/templates/package.json.ts b/cli/src/api/templates/package.json.ts index ea29a607..0d3a9aa6 100644 --- a/cli/src/api/templates/package.json.ts +++ b/cli/src/api/templates/package.json.ts @@ -7,7 +7,6 @@ export const createPackageJson = ({ license, engineRequirement, cliVersion, - esm, }: { name: string binaryName: string @@ -15,7 +14,6 @@ export const createPackageJson = ({ license: string engineRequirement: string cliVersion: string - esm: boolean }) => { const content: CommonPackageJsonFields = { name, @@ -46,23 +44,5 @@ export const createPackageJson = ({ }, } - if (esm) { - content.type = 'module' - content.main = 'index.cjs' - content.module = 'index.js' - content.exports = { - '.': { - import: { - default: './index.js', - types: './index.d.ts', - }, - require: { - default: './index.cjs', - types: './index.d.ts', - }, - }, - } - } - return JSON.stringify(content, null, 2) } diff --git a/cli/src/commands/new.ts b/cli/src/commands/new.ts index 0bb2ec1e..d27beabd 100644 --- a/cli/src/commands/new.ts +++ b/cli/src/commands/new.ts @@ -40,7 +40,6 @@ export class NewCommand extends BaseNewCommand { return { ...cmdOptions, name: await this.fetchName(path.parse(cmdOptions.path).base), - esm: await this.fetchEnableEsm(), minNodeApiVersion: await this.fetchNapiVersion(), targets: await this.fetchTargets(), license: await this.fetchLicense(), @@ -132,15 +131,4 @@ export class NewCommand extends BaseNewCommand { return enableGithubActions } - - private async fetchEnableEsm(): Promise { - const { esm } = await inquirer.prompt({ - name: 'esm', - type: 'confirm', - message: 'Enable ESM support', - default: this.esm, - }) - - return esm - } } diff --git a/cli/src/def/new.ts b/cli/src/def/new.ts index d9ff01f2..387eb050 100644 --- a/cli/src/def/new.ts +++ b/cli/src/def/new.ts @@ -51,10 +51,6 @@ export abstract class BaseNewCommand extends Command { description: 'Whether to run the command in dry-run mode', }) - esm = Option.Boolean('--esm', false, { - description: 'Whether enable ESM support', - }) - getOptions() { return { path: this.$$path, @@ -67,7 +63,6 @@ export abstract class BaseNewCommand extends Command { enableTypeDef: this.enableTypeDef, enableGithubActions: this.enableGithubActions, dryRun: this.dryRun, - esm: this.esm, } } } @@ -132,12 +127,6 @@ export interface NewOptions { * @default false */ dryRun?: boolean - /** - * Whether enable ESM support - * - * @default false - */ - esm?: boolean } export function applyDefaultNewOptions(options: NewOptions) { @@ -150,7 +139,6 @@ export function applyDefaultNewOptions(options: NewOptions) { enableTypeDef: true, enableGithubActions: true, dryRun: false, - esm: false, ...options, } }