diff --git a/src/cli.ts b/src/cli.ts index 3d4a093920..9f8b6378ef 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -187,14 +187,12 @@ export async function importPath( filepath: string, origin = filepath ): Promise { - const ext = path.extname(filepath) - const base = path.basename(filepath) - const dir = path.dirname(filepath) + const { ext, base, dir } = path.parse(filepath) if (ext === '') { - const tmpFilename = fs.existsSync(`${filepath}.mjs`) - ? `${base}-${randomId()}.mjs` - : `${base}.mjs` + const tmpFilename = fs.existsSync(filepath + EXT) + ? base + '-' + randomId() + EXT + : base + EXT return writeAndImport( await fs.readFile(filepath), @@ -205,7 +203,7 @@ export async function importPath( if (ext === '.md') { return writeAndImport( transformMarkdown(await fs.readFile(filepath)), - path.join(dir, base + '.mjs'), + path.join(dir, base + EXT), origin ) } diff --git a/src/util.ts b/src/util.ts index 9fb4fc211e..1c42eaf4d5 100644 --- a/src/util.ts +++ b/src/util.ts @@ -101,7 +101,7 @@ export function preferLocalBin( // } export function quote(arg: string): string { - if (/^[a-z0-9/_.\-@:=]+$/i.test(arg) || arg === '') { + if (/^[\w/.-@:=]+$/.test(arg) || arg === '') { return arg } return ( @@ -120,7 +120,7 @@ export function quote(arg: string): string { } export function quotePowerShell(arg: string): string { - if (/^[a-z0-9/_.\-]+$/i.test(arg) || arg === '') { + if (/^[\w/.-]+$/.test(arg) || arg === '') { return arg } return `'` + arg.replace(/'/g, "''") + `'`