diff --git a/packages/cli/src/commands/hydrogen/deploy.ts b/packages/cli/src/commands/hydrogen/deploy.ts index de2dfcb366..05982c1c33 100644 --- a/packages/cli/src/commands/hydrogen/deploy.ts +++ b/packages/cli/src/commands/hydrogen/deploy.ts @@ -1,6 +1,7 @@ import {Flags} from '@oclif/core'; import Command from '@shopify/cli-kit/node/base-command'; import colors from '@shopify/cli-kit/node/colors'; +import git, {type FileStatusResult} from 'simple-git'; import { outputContent, outputInfo, @@ -48,6 +49,7 @@ import {runViteBuild} from './build-vite.js'; import {getViteConfig} from '../../lib/vite-config.js'; import {prepareDiffDirectory} from '../../lib/template-diff.js'; import {hasRemixConfigFile} from '../../lib/remix-config.js'; +import {packageManagers} from '../../lib/package-managers.js'; const DEPLOY_OUTPUT_FILE_HANDLE = 'h2_deploy_log.json'; @@ -252,19 +254,39 @@ export async function runDeploy( } if (!forceOnUncommitedChanges && !isCleanGit) { - const {stdout} = await execAsync(`git status -s`); - - throw new AbortError( - `Uncommitted changes detected:\n\n${stdout}`.trimEnd(), - null, + let errorMessage = 'Uncommitted changes detected'; + const nextSteps = [ [ - [ - 'Commit your changes before deploying or use the ', - {command: '--force'}, - ' flag to deploy with uncommitted changes.', - ], + 'Commit your changes before deploying or use the', + {command: '--force'}, + 'flag to deploy with uncommitted changes.', ], - ); + ]; + + const {files} = await git({baseDir: root}).status(); + + if (files.length) { + const formattedFiles = files + .map( + ({path, index, working_dir}: FileStatusResult) => + `${index}${working_dir} ${path}`, + ) + .join('\n'); + + errorMessage += `:\n\n${formattedFiles}`; + + packageManagers.forEach(({name, lockfile, installCommand}) => { + if (formattedFiles.includes(lockfile)) { + nextSteps.push([ + `If you are using ${name}, try running`, + {command: installCommand}, + `to avoid changes to ${lockfile}.`, + ]); + } + }); + } + + throw new AbortError(errorMessage, null, nextSteps); } } diff --git a/packages/cli/src/lib/package-managers.ts b/packages/cli/src/lib/package-managers.ts index 97f6324b9b..9a9a080e6f 100644 --- a/packages/cli/src/lib/package-managers.ts +++ b/packages/cli/src/lib/package-managers.ts @@ -28,6 +28,6 @@ export const packageManagers: PackageManager[] = [ { name: 'bun', lockfile: 'bun.lockb', - installCommand: 'bun install', + installCommand: 'bun install --frozen-lockfile', }, ];