fix cli watch build and remove unused --esm
option (#1631)
* fix(cli): watch mode * chore(cli): remove useless option * Delete more esm option codes --------- Co-authored-by: LongYinan <lynweklm@gmail.com>
This commit is contained in:
parent
53cf696cf8
commit
8aef51a51a
7 changed files with 12 additions and 53 deletions
|
@ -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,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
|
|
@ -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 |
|
||||
|
|
|
@ -149,6 +149,7 @@ class Builder {
|
|||
|
||||
const controller = new AbortController()
|
||||
|
||||
const watch = this.options.watch
|
||||
const buildTask = new Promise<void>((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
|
||||
}
|
||||
|
|
|
@ -146,7 +146,6 @@ function generatePackageJson(options: NewOptions): Output {
|
|||
license: options.license,
|
||||
engineRequirement: napiEngineRequirement(options.minNodeApiVersion),
|
||||
cliVersion: CLI_VERSION,
|
||||
esm: options.esm,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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<boolean> {
|
||||
const { esm } = await inquirer.prompt({
|
||||
name: 'esm',
|
||||
type: 'confirm',
|
||||
message: 'Enable ESM support',
|
||||
default: this.esm,
|
||||
})
|
||||
|
||||
return esm
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue