From 6c66d4834bf1feb192d6b2b5a29b77cc5e6a34f3 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Wed, 17 Nov 2021 10:30:12 -0800 Subject: [PATCH] fix npm init flag handling in create-astro (#1862) * fix npm init flag handling * Update index.ts * Update real-cats-act.md --- .changeset/real-cats-act.md | 5 +++++ packages/create-astro/src/index.ts | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/real-cats-act.md diff --git a/.changeset/real-cats-act.md b/.changeset/real-cats-act.md new file mode 100644 index 000000000..611d314b1 --- /dev/null +++ b/.changeset/real-cats-act.md @@ -0,0 +1,5 @@ +--- +'create-astro': patch +--- + +Fix issue with v7.x+ versions of npm init, which changed default flag handling diff --git a/packages/create-astro/src/index.ts b/packages/create-astro/src/index.ts index 3b61333e0..9f09722d1 100644 --- a/packages/create-astro/src/index.ts +++ b/packages/create-astro/src/index.ts @@ -8,7 +8,13 @@ import yargs from 'yargs-parser'; import { FRAMEWORKS, COUNTER_COMPONENTS } from './frameworks.js'; import { TEMPLATES } from './templates.js'; import { createConfig } from './config.js'; -const args = yargs(process.argv); + +// NOTE: In the v7.x version of npm, the default behavior of `npm init` was changed +// to no longer require `--` to pass args and instead pass `--` directly to us. This +// broke our arg parser, since `--` is a special kind of flag. Filtering for `--` here +// fixes the issue so that create-astro now works on all npm version. +const cleanArgv = process.argv.filter(arg => arg !== '--') +const args = yargs(cleanArgv); prompts.override(args); export function mkdirp(dir: string) {