From 3b638f0bcfb9bf81e19ee90148d4a5a1db195e5f Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 1 Dec 2026 04:53:41 -0400 Subject: [PATCH] fix(create): report add-on dependency install failures --- packages/create/src/add-to-app.ts | 20 ++++++++--- packages/create/tests/add-to-app.test.ts | 42 ++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/packages/create/src/add-to-app.ts b/packages/create/src/add-to-app.ts index 10feaf91e..79c0c331d 100644 --- a/packages/create/src/add-to-app.ts +++ b/packages/create/src/add-to-app.ts @@ -427,15 +427,21 @@ export async function addToApp( }) const s = environment.spinner() s.start(`Installing dependencies via ${newOptions.packageManager}...`) - await packageManagerInstall( + const installResult = await packageManagerInstall( environment, newOptions.targetDir, newOptions.packageManager, undefined, { updateLockfile: true }, ) - s.stop(`Installed dependencies`) - environment.finishStep('install-dependencies', 'Dependencies installed') + const installMessage = installResult.failed + ? `Failed to install dependencies via ${newOptions.packageManager}` + : 'Installed dependencies' + s.stop(installMessage) + environment.finishStep( + 'install-dependencies', + installResult.failed ? installMessage : 'Dependencies installed', + ) // Run any post-init special steps for the new add-ons const postInitSpecialSteps = new Set([]) @@ -470,5 +476,11 @@ export async function addToApp( writeConfigFileToEnvironment(environment, newOptions) environment.finishStep('write-config-file', 'Config file written') - environment.outro(`Add-ons ${addOns.join(', ')} added!`) + const errors = environment.getErrors() + const summary = `Add-ons ${addOns.join(', ')} added!` + environment.outro( + errors.length + ? `${summary}\n\nErrors were encountered while adding add-ons:\n\n${errors.join('\n')}` + : summary, + ) } diff --git a/packages/create/tests/add-to-app.test.ts b/packages/create/tests/add-to-app.test.ts index 84365d643..0ffd603ff 100644 --- a/packages/create/tests/add-to-app.test.ts +++ b/packages/create/tests/add-to-app.test.ts @@ -477,9 +477,13 @@ describe('addToApp', () => { 2, ), ) + const stop = vi.fn() + environment.spinner = () => ({ start: vi.fn(), stop }) await addToApp(environment, ['test'], '/foo', { forced: true, + intent: false, }) + expect(stop).toHaveBeenCalledWith('Installed dependencies') environment.finishRun() expect(output.files).toEqual({ 'jack.txt': 'foo', @@ -499,6 +503,44 @@ describe('addToApp', () => { }) }) + it('reports dependency installation failure and records the add-on', async () => { + const { environment } = createMemoryEnvironment('/foo') + environment.startRun() + environment.writeFile('/foo/.cta.json', JSON.stringify(fakeCTAJSON)) + environment.writeFile('/foo/package.json', JSON.stringify({ name: 'test' })) + + const installError = + 'Command "npm install" did not run successfully. Please run this manually in your project.' + const execute = environment.execute + environment.execute = async (command, args, cwd) => { + if (command === 'npm' && args[0] === 'install') { + environment.getErrors().push(installError) + return { stdout: '', failed: true } + } + return execute(command, args, cwd) + } + const stop = vi.fn() + environment.spinner = () => ({ start: vi.fn(), stop }) + const finishStep = vi.spyOn(environment, 'finishStep') + const outro = vi.spyOn(environment, 'outro') + + await addToApp(environment, ['test'], '/foo', { + forced: true, + intent: false, + }) + + expect(stop).toHaveBeenCalledWith('Failed to install dependencies via npm') + expect(stop).not.toHaveBeenCalledWith('Installed dependencies') + expect(finishStep).toHaveBeenCalledWith( + 'install-dependencies', + 'Failed to install dependencies via npm', + ) + expect(outro).toHaveBeenCalledWith(expect.stringContaining(installError)) + expect(JSON.parse(await environment.readFile('/foo/.cta.json'))).toMatchObject({ + chosenAddOns: ['test'], + }) + }) + it('enables Tailwind when an add-on requires it', async () => { const { environment } = createMemoryEnvironment('/foo') environment.startRun()