Skip to content

Commit 4b223fe

Browse files
Merge pull request #7436 from afurm/af/fix-bun-lockfile-cleanup
Fix modern Bun lockfile cleanup in app templates
2 parents 9b80a4f + ae1aa0a commit 4b223fe

5 files changed

Lines changed: 34 additions & 16 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@shopify/app': patch
3+
'@shopify/cli-kit': patch
4+
---
5+
6+
Handle modern Bun `bun.lock` files when cleaning up app templates so non-Bun projects do not keep stale Bun lockfiles or `.gitignore` entries.

packages/app/src/cli/services/init/template/cleanup.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ describe('cleanup', () => {
6868
await writeFile(joinPath(tmpDir, 'package-lock.json'), '{}')
6969
await writeFile(joinPath(tmpDir, 'yarn.lock'), '{}')
7070
await writeFile(joinPath(tmpDir, 'pnpm-lock.yaml'), '{}')
71+
await writeFile(joinPath(tmpDir, 'bun.lock'), '{}')
7172
await writeFile(joinPath(tmpDir, 'bun.lockb'), '{}')
7273

7374
// When
@@ -77,6 +78,7 @@ describe('cleanup', () => {
7778
await expect(fileExists(joinPath(tmpDir, 'package-lock.json'))).resolves.toBe(packageManager === 'npm')
7879
await expect(fileExists(joinPath(tmpDir, 'yarn.lock'))).resolves.toBe(packageManager === 'yarn')
7980
await expect(fileExists(joinPath(tmpDir, 'pnpm-lock.yaml'))).resolves.toBe(packageManager === 'pnpm')
81+
await expect(fileExists(joinPath(tmpDir, 'bun.lock'))).resolves.toBe(packageManager === 'bun')
8082
await expect(fileExists(joinPath(tmpDir, 'bun.lockb'))).resolves.toBe(packageManager === 'bun')
8183
})
8284
})
@@ -87,6 +89,7 @@ describe('cleanup', () => {
8789
await writeFile(joinPath(tmpDir, 'package-lock.json'), '{}')
8890
await writeFile(joinPath(tmpDir, 'yarn.lock'), '{}')
8991
await writeFile(joinPath(tmpDir, 'pnpm-lock.yaml'), '{}')
92+
await writeFile(joinPath(tmpDir, 'bun.lock'), '{}')
9093
await writeFile(joinPath(tmpDir, 'bun.lockb'), '{}')
9194

9295
// When
@@ -96,6 +99,7 @@ describe('cleanup', () => {
9699
await expect(fileExists(joinPath(tmpDir, 'package-lock.json'))).resolves.toBe(false)
97100
await expect(fileExists(joinPath(tmpDir, 'yarn.lock'))).resolves.toBe(false)
98101
await expect(fileExists(joinPath(tmpDir, 'pnpm-lock.yaml'))).resolves.toBe(false)
102+
await expect(fileExists(joinPath(tmpDir, 'bun.lock'))).resolves.toBe(false)
99103
await expect(fileExists(joinPath(tmpDir, 'bun.lockb'))).resolves.toBe(false)
100104
})
101105
})

packages/app/src/cli/services/init/template/cleanup.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {rmdir, glob, fileExistsSync, unlinkFile} from '@shopify/cli-kit/node/fs'
2-
import {Lockfile, lockfilesByManager, PackageManager} from '@shopify/cli-kit/node/node-package-manager'
2+
import {lockfiles, lockfilesByManager, PackageManager} from '@shopify/cli-kit/node/node-package-manager'
33
import {joinPath} from '@shopify/cli-kit/node/path'
44

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

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

26-
const lockfilePromises = Object.entries(lockfilesByManager)
27-
.filter(([manager, lockfile]) => manager !== packageManager && lockfile)
28-
.map(([_, lockfile]) => {
29-
const path = joinPath(webOutputDirectory, lockfile as Lockfile)
26+
const lockfilesToKeep = new Set(lockfilesByManager[packageManager])
27+
const lockfilePromises = lockfiles
28+
.filter((lockfile) => !lockfilesToKeep.has(lockfile))
29+
.map((lockfile) => {
30+
const path = joinPath(webOutputDirectory, lockfile)
3031
if (fileExistsSync(path)) return unlinkFile(path)
31-
}, [])
32+
})
3233

3334
return Promise.all([...gitPathPromises, ...lockfilePromises])
3435
}

packages/cli-kit/src/public/node/node-package-manager.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
inferPackageManager,
2323
PackageManager,
2424
npmLockfile,
25+
lockfilesByManager,
2526
} from './node-package-manager.js'
2627
import {captureOutput, exec} from './system.js'
2728
import {inTemporaryDirectory, mkdir, touchFile, writeFile} from './fs.js'
@@ -132,6 +133,12 @@ describe('install', () => {
132133
})
133134
})
134135

136+
describe('lockfilesByManager', () => {
137+
test('maps Bun to both lockfile names', () => {
138+
expect(lockfilesByManager.bun).toEqual(['bun.lockb', 'bun.lock'])
139+
})
140+
})
141+
135142
describe('getPackageName', () => {
136143
test('returns package name', async () => {
137144
await inTemporaryDirectory(async (tmpDir) => {

packages/cli-kit/src/public/node/node-package-manager.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ const modernBunLockfile = 'bun.lock'
2929
export const pnpmWorkspaceFile = 'pnpm-workspace.yaml'
3030

3131
/** An array containing the lockfiles from all the package managers */
32-
export const lockfiles: Lockfile[] = [yarnLockfile, pnpmLockfile, npmLockfile, bunLockfile]
33-
export const lockfilesByManager: Record<PackageManager, Lockfile | undefined> = {
34-
yarn: yarnLockfile,
35-
npm: npmLockfile,
36-
pnpm: pnpmLockfile,
37-
bun: bunLockfile,
38-
homebrew: undefined,
39-
unknown: undefined,
40-
}
41-
export type Lockfile = 'yarn.lock' | 'package-lock.json' | 'pnpm-lock.yaml' | 'bun.lockb'
32+
export const lockfiles: Lockfile[] = [yarnLockfile, pnpmLockfile, npmLockfile, bunLockfile, modernBunLockfile]
33+
export const lockfilesByManager: Record<PackageManager, Lockfile[]> = {
34+
yarn: [yarnLockfile],
35+
npm: [npmLockfile],
36+
pnpm: [pnpmLockfile],
37+
bun: [bunLockfile, modernBunLockfile],
38+
homebrew: [],
39+
unknown: [],
40+
}
41+
export type Lockfile = 'yarn.lock' | 'package-lock.json' | 'pnpm-lock.yaml' | 'bun.lockb' | 'bun.lock'
4242

4343
/**
4444
* A union type that represents the type of dependencies in the package.json

0 commit comments

Comments
 (0)