diff --git a/build/cli.js b/build/cli.js old mode 100644 new mode 100755 diff --git a/build/core.cjs b/build/core.cjs index 73b9335efe..e6376a61eb 100644 --- a/build/core.cjs +++ b/build/core.cjs @@ -387,7 +387,7 @@ function formatCmd(cmd) { } } cap(); - return out.replaceAll("\n", import_vendor_core.chalk.reset("\n> ")) + "\n"; + return out.replace(/\n/g, import_vendor_core.chalk.reset("\n> ")) + "\n"; } // src/core.ts diff --git a/src/cli.ts b/src/cli.ts index 5b8783c7a0..84ceb39eba 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -193,7 +193,9 @@ function linkNodeModules(cwd: string, external: string): string { function lstat(p: string) { try { return fs.lstatSync(p) - } catch {} + } catch (e) { + if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e + } } async function readScript() { @@ -279,10 +281,10 @@ export function normalizeExt(ext?: string): string | undefined { // prettier-ignore function getFilepath(cwd = '.', name = 'zx', _ext?: string): string { const ext = _ext || argv.ext || EXT - return [ - name + ext, - name + '-' + randomId() + ext, - ] - .map(f => path.resolve(process.cwd(), cwd, f)) - .find(f => !fs.existsSync(f))! + const basePath = path.resolve(process.cwd(), cwd, name) + let filepath = basePath + ext + while (fs.existsSync(filepath)) { + filepath = basePath + '-' + randomId() + ext + } + return filepath } diff --git a/src/core.ts b/src/core.ts index 94acee83cb..870eb417f6 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1059,14 +1059,19 @@ export async function kill( for (const p of await ps.tree({ pid, recursive: true })) { try { process.kill(+p.pid, signal) - } catch (e) {} + } catch (e) { + // Ignore if process is already dead + } } try { process.kill(-pid, signal) } catch (e) { + // Ignore if process group is already dead try { process.kill(+pid, signal) - } catch (e) {} + } catch (e) { + // Ignore if process is already dead + } } } diff --git a/src/log.ts b/src/log.ts index 0eaf5e6321..cb61d32175 100644 --- a/src/log.ts +++ b/src/log.ts @@ -218,5 +218,5 @@ export function formatCmd(cmd: string): string { } } cap() - return out.replaceAll('\n', chalk.reset('\n> ')) + '\n' + return out.replace(/\n/g, chalk.reset('\n> ')) + '\n' }