From 2f5349503312fddd8337bfb78c9cd0b618c08c08 Mon Sep 17 00:00:00 2001 From: Percy Ma Date: Fri, 11 Nov 2022 18:13:52 +0800 Subject: [PATCH] feat(nuxi): auto-generate `.npmrc` and setting for pnpm (#7407) Co-authored-by: Pooya Parsa --- docs/content/1.getting-started/2.installation.md | 6 +++++- packages/nuxi/src/commands/init.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/content/1.getting-started/2.installation.md b/docs/content/1.getting-started/2.installation.md index 78e2cea61a..63153014fd 100644 --- a/docs/content/1.getting-started/2.installation.md +++ b/docs/content/1.getting-started/2.installation.md @@ -74,11 +74,15 @@ npm install ``` ```bash [pnpm] -pnpm install --shamefully-hoist +pnpm install ``` :: +::alert +**Note:** If using **pnpm**, make sure to have `.npmrc` with `shamefully-hoist=true` inside it before `pnpm install`. +:: + ## Development Server Now you'll be able to start your Nuxt app in development mode: diff --git a/packages/nuxi/src/commands/init.ts b/packages/nuxi/src/commands/init.ts index acc6a98e89..fee448cfea 100644 --- a/packages/nuxi/src/commands/init.ts +++ b/packages/nuxi/src/commands/init.ts @@ -1,3 +1,4 @@ +import { writeFile } from 'node:fs/promises' import { downloadTemplate, startShell } from 'giget' import { relative } from 'pathe' import consola from 'consola' @@ -27,9 +28,16 @@ export default defineNuxtCommand({ // Show next steps const relativeDist = rpath(t.dir) + + // Write .nuxtrc with `shamefully-hoist=true` for pnpm + const usingPnpm = (process.env.npm_config_user_agent || '').includes('pnpm') + if (usingPnpm) { + await writeFile(`${relativeDist}/.npmrc`, 'shamefully-hoist=true') + } + const nextSteps = [ !args.shell && relativeDist.length > 1 && `\`cd ${relativeDist}\``, - 'Install dependencies with `npm install` or `yarn install` or `pnpm install --shamefully-hoist`', + 'Install dependencies with `npm install` or `yarn install` or `pnpm install`', 'Start development server with `npm run dev` or `yarn dev` or `pnpm run dev`' ].filter(Boolean)