summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Nate Moore <natemoo-re@users.noreply.github.com> 2023-08-14 10:50:49 -0500
committerGravatar GitHub <noreply@github.com> 2023-08-14 10:50:49 -0500
commit3e46634fd540e5b967d2e5c9abd6235452cee2f2 (patch)
treeb4a697c0d6b44d0e6b91953cd43aa19b5cb68c2a
parentd1f7143f9caf2ffa0e87cc55c0e05339d3501db3 (diff)
downloadastro-3e46634fd540e5b967d2e5c9abd6235452cee2f2.tar.gz
astro-3e46634fd540e5b967d2e5c9abd6235452cee2f2.tar.zst
astro-3e46634fd540e5b967d2e5c9abd6235452cee2f2.zip
Support flags for `astro add` (#8032)
* astro add cli pass down arguments to install cmd * add changeset * feat: pass common flags down to install command * Update .changeset/soft-colts-heal.md --------- Co-authored-by: Elod Tobak <tobakelod@gmail.com>
-rw-r--r--.changeset/soft-colts-heal.md5
-rw-r--r--packages/astro/src/cli/add/index.ts26
2 files changed, 29 insertions, 2 deletions
diff --git a/.changeset/soft-colts-heal.md b/.changeset/soft-colts-heal.md
new file mode 100644
index 000000000..4ceaf2a9b
--- /dev/null
+++ b/.changeset/soft-colts-heal.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+`astro add` now passes down `--save-prod`, `--save-dev`, `--save-exact`, and `--no-save` flags for installation
diff --git a/packages/astro/src/cli/add/index.ts b/packages/astro/src/cli/add/index.ts
index 6ef96561d..1af3e7633 100644
--- a/packages/astro/src/cli/add/index.ts
+++ b/packages/astro/src/cli/add/index.ts
@@ -634,6 +634,15 @@ async function getInstallIntegrationsCommand({
}
}
+// Allow forwarding of standard `npm install` flags
+// See https://docs.npmjs.com/cli/v8/commands/npm-install#description
+const INHERITED_FLAGS = new Set<string>([
+ "P", "save-prod",
+ "D", "save-dev",
+ "E", "save-exact",
+ "no-save",
+])
+
async function tryToInstallIntegrations({
integrations,
cwd,
@@ -647,12 +656,24 @@ async function tryToInstallIntegrations({
}): Promise<UpdateResult> {
const installCommand = await getInstallIntegrationsCommand({ integrations, cwd });
+ const inheritedFlags = Object.entries(flags)
+ .map(([flag]) => {
+ if (flag == '_') return;
+ if (INHERITED_FLAGS.has(flag)) {
+ if (flag.length === 1) return `-${flag}`;
+ return `--${flag}`;
+ }
+ })
+ .filter(Boolean)
+ .flat() as string[];
+
if (installCommand === null) {
return UpdateResult.none;
} else {
const coloredOutput = `${bold(installCommand.pm)} ${installCommand.command}${[
'',
...installCommand.flags,
+ ...inheritedFlags
].join(' ')} ${cyan(installCommand.dependencies.join(' '))}`;
const message = `\n${boxen(coloredOutput, {
margin: 0.5,
@@ -672,14 +693,15 @@ async function tryToInstallIntegrations({
try {
await execa(
installCommand.pm,
- [installCommand.command, ...installCommand.flags, ...installCommand.dependencies],
+ [installCommand.command, ...installCommand.flags, ...inheritedFlags, ...installCommand.dependencies],
{ cwd }
);
spinner.succeed();
return UpdateResult.updated;
} catch (err) {
- debug('add', 'Error installing dependencies', err);
spinner.fail();
+ debug('add', 'Error installing dependencies', err);
+ console.error('\n', (err as any).stdout, '\n');
return UpdateResult.failure;
}
} else {