diff --git a/apps/cli/src/__tests__/helpers/fake-npm.ts b/apps/cli/src/__tests__/helpers/fake-npm.ts index af5cfba1e..e773a79df 100644 --- a/apps/cli/src/__tests__/helpers/fake-npm.ts +++ b/apps/cli/src/__tests__/helpers/fake-npm.ts @@ -45,6 +45,13 @@ if (args[0] === "view") { process.exit(0); } +if (process.env.BB_TEST_NPM_INSTALL === "fail") { + process.stderr.write( + "npm error code EPERM\\nnpm error syscall open\\nnpm error Your cache folder contains root-owned files\\n", + ); + process.exit(1); +} + // npm treats NODE_ENV=production as omit=dev; a command-line --include=dev // outranks it. BB_TEST_NPM_ALWAYS_OMIT_DEV forces the omission to stand in for // an install that silently drops packages. diff --git a/apps/cli/src/__tests__/plugin-new.test.ts b/apps/cli/src/__tests__/plugin-new.test.ts index d2a9e2a32..33ada3493 100644 --- a/apps/cli/src/__tests__/plugin-new.test.ts +++ b/apps/cli/src/__tests__/plugin-new.test.ts @@ -201,6 +201,17 @@ describe.sequential("bb plugin new dependency install", () => { expect(warned.join("\n")).not.toContain("was not found on npm"); }); + it("issue 2548: shows npm's reason when scaffold installation fails", async () => { + vi.stubEnv("BB_TEST_NPM_INSTALL", "fail"); + + await runPluginNew(["npm-broken"]); + + const warnings = warned.join("\n"); + expect(warnings).toContain("Could not run npm install"); + expect(warnings).toContain("npm error code EPERM"); + expect(warnings).toContain("Your cache folder contains root-owned files"); + }); + it("falls back to the manual step when npm is not on PATH", async () => { vi.stubEnv("PATH", join(workDir, "empty-bin"));