Skip to content

Commit ae1aa0a

Browse files
committed
Apply lockfile mapping review suggestion
1 parent a7d448b commit ae1aa0a

3 files changed

Lines changed: 13 additions & 20 deletions

File tree

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

Lines changed: 2 additions & 2 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 {lockfiles, lockfilesForPackageManager, 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,7 +23,7 @@ export default async function cleanup(webOutputDirectory: string, packageManager
2323

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

26-
const lockfilesToKeep = new Set(lockfilesForPackageManager(packageManager))
26+
const lockfilesToKeep = new Set(lockfilesByManager[packageManager])
2727
const lockfilePromises = lockfiles
2828
.filter((lockfile) => !lockfilesToKeep.has(lockfile))
2929
.map((lockfile) => {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
inferPackageManager,
2323
PackageManager,
2424
npmLockfile,
25-
lockfilesForPackageManager,
25+
lockfilesByManager,
2626
} from './node-package-manager.js'
2727
import {captureOutput, exec} from './system.js'
2828
import {inTemporaryDirectory, mkdir, touchFile, writeFile} from './fs.js'
@@ -133,9 +133,9 @@ describe('install', () => {
133133
})
134134
})
135135

136-
describe('lockfilesForPackageManager', () => {
137-
test('returns both Bun lockfile names', () => {
138-
expect(lockfilesForPackageManager('bun')).toEqual(['bun.lockb', 'bun.lock'])
136+
describe('lockfilesByManager', () => {
137+
test('maps Bun to both lockfile names', () => {
138+
expect(lockfilesByManager.bun).toEqual(['bun.lockb', 'bun.lock'])
139139
})
140140
})
141141

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ export const pnpmWorkspaceFile = 'pnpm-workspace.yaml'
3030

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

@@ -55,13 +55,6 @@ export const packageManager = ['yarn', 'npm', 'pnpm', 'bun', 'homebrew', 'unknow
5555
export type PackageManager = (typeof packageManager)[number]
5656
type ProjectPackageManager = Extract<PackageManager, 'yarn' | 'npm' | 'pnpm' | 'bun'>
5757

58-
export function lockfilesForPackageManager(packageManager: PackageManager): Lockfile[] {
59-
if (packageManager === 'bun') return [bunLockfile, modernBunLockfile]
60-
61-
const lockfile = lockfilesByManager[packageManager]
62-
return lockfile ? [lockfile] : []
63-
}
64-
6558
/**
6659
* Returns an abort error that's thrown when the package manager can't be determined.
6760
* @returns An abort error.

0 commit comments

Comments
 (0)