Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fix-bun-lockfile-cleanup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/app': patch
'@shopify/cli-kit': patch
---

Handle modern Bun `bun.lock` files when cleaning up app templates so non-Bun projects do not keep stale Bun lockfiles or `.gitignore` entries.
4 changes: 4 additions & 0 deletions packages/app/src/cli/services/init/template/cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('cleanup', () => {
await writeFile(joinPath(tmpDir, 'package-lock.json'), '{}')
await writeFile(joinPath(tmpDir, 'yarn.lock'), '{}')
await writeFile(joinPath(tmpDir, 'pnpm-lock.yaml'), '{}')
await writeFile(joinPath(tmpDir, 'bun.lock'), '{}')
await writeFile(joinPath(tmpDir, 'bun.lockb'), '{}')

// When
Expand All @@ -77,6 +78,7 @@ describe('cleanup', () => {
await expect(fileExists(joinPath(tmpDir, 'package-lock.json'))).resolves.toBe(packageManager === 'npm')
await expect(fileExists(joinPath(tmpDir, 'yarn.lock'))).resolves.toBe(packageManager === 'yarn')
await expect(fileExists(joinPath(tmpDir, 'pnpm-lock.yaml'))).resolves.toBe(packageManager === 'pnpm')
await expect(fileExists(joinPath(tmpDir, 'bun.lock'))).resolves.toBe(packageManager === 'bun')
await expect(fileExists(joinPath(tmpDir, 'bun.lockb'))).resolves.toBe(packageManager === 'bun')
})
})
Expand All @@ -87,6 +89,7 @@ describe('cleanup', () => {
await writeFile(joinPath(tmpDir, 'package-lock.json'), '{}')
await writeFile(joinPath(tmpDir, 'yarn.lock'), '{}')
await writeFile(joinPath(tmpDir, 'pnpm-lock.yaml'), '{}')
await writeFile(joinPath(tmpDir, 'bun.lock'), '{}')
await writeFile(joinPath(tmpDir, 'bun.lockb'), '{}')

// When
Expand All @@ -96,6 +99,7 @@ describe('cleanup', () => {
await expect(fileExists(joinPath(tmpDir, 'package-lock.json'))).resolves.toBe(false)
await expect(fileExists(joinPath(tmpDir, 'yarn.lock'))).resolves.toBe(false)
await expect(fileExists(joinPath(tmpDir, 'pnpm-lock.yaml'))).resolves.toBe(false)
await expect(fileExists(joinPath(tmpDir, 'bun.lock'))).resolves.toBe(false)
await expect(fileExists(joinPath(tmpDir, 'bun.lockb'))).resolves.toBe(false)
})
})
Expand Down
13 changes: 7 additions & 6 deletions packages/app/src/cli/services/init/template/cleanup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {rmdir, glob, fileExistsSync, unlinkFile} from '@shopify/cli-kit/node/fs'
import {Lockfile, lockfilesByManager, PackageManager} from '@shopify/cli-kit/node/node-package-manager'
import {lockfiles, lockfilesByManager, PackageManager} from '@shopify/cli-kit/node/node-package-manager'
import {joinPath} from '@shopify/cli-kit/node/path'

export default async function cleanup(webOutputDirectory: string, packageManager: PackageManager) {
Expand All @@ -23,12 +23,13 @@ export default async function cleanup(webOutputDirectory: string, packageManager

const gitPathPromises = gitPaths.map((path) => rmdir(path, {force: true}))

const lockfilePromises = Object.entries(lockfilesByManager)
.filter(([manager, lockfile]) => manager !== packageManager && lockfile)
.map(([_, lockfile]) => {
const path = joinPath(webOutputDirectory, lockfile as Lockfile)
const lockfilesToKeep = new Set(lockfilesByManager[packageManager])
const lockfilePromises = lockfiles
.filter((lockfile) => !lockfilesToKeep.has(lockfile))
.map((lockfile) => {
const path = joinPath(webOutputDirectory, lockfile)
if (fileExistsSync(path)) return unlinkFile(path)
}, [])
})

return Promise.all([...gitPathPromises, ...lockfilePromises])
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
inferPackageManager,
PackageManager,
npmLockfile,
lockfilesByManager,
} from './node-package-manager.js'
import {captureOutput, exec} from './system.js'
import {inTemporaryDirectory, mkdir, touchFile, writeFile} from './fs.js'
Expand Down Expand Up @@ -132,6 +133,12 @@ describe('install', () => {
})
})

describe('lockfilesByManager', () => {
test('maps Bun to both lockfile names', () => {
expect(lockfilesByManager.bun).toEqual(['bun.lockb', 'bun.lock'])
})
})

describe('getPackageName', () => {
test('returns package name', async () => {
await inTemporaryDirectory(async (tmpDir) => {
Expand Down
20 changes: 10 additions & 10 deletions packages/cli-kit/src/public/node/node-package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ const modernBunLockfile = 'bun.lock'
export const pnpmWorkspaceFile = 'pnpm-workspace.yaml'

/** An array containing the lockfiles from all the package managers */
export const lockfiles: Lockfile[] = [yarnLockfile, pnpmLockfile, npmLockfile, bunLockfile]
export const lockfilesByManager: Record<PackageManager, Lockfile | undefined> = {
yarn: yarnLockfile,
npm: npmLockfile,
pnpm: pnpmLockfile,
bun: bunLockfile,
homebrew: undefined,
unknown: undefined,
}
export type Lockfile = 'yarn.lock' | 'package-lock.json' | 'pnpm-lock.yaml' | 'bun.lockb'
export const lockfiles: Lockfile[] = [yarnLockfile, pnpmLockfile, npmLockfile, bunLockfile, modernBunLockfile]
export const lockfilesByManager: Record<PackageManager, Lockfile[]> = {
yarn: [yarnLockfile],
npm: [npmLockfile],
pnpm: [pnpmLockfile],
bun: [bunLockfile, modernBunLockfile],
homebrew: [],
unknown: [],
}
export type Lockfile = 'yarn.lock' | 'package-lock.json' | 'pnpm-lock.yaml' | 'bun.lockb' | 'bun.lock'

/**
* A union type that represents the type of dependencies in the package.json
Expand Down
Loading