Skip to content

Commit

Permalink
feat: Add support for bun.lock plain text lock file (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-hariti authored and onurtemizkan committed Jan 13, 2025
1 parent 1ecb66f commit 7c3d91f
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/utils/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { getPackageDotJson, updatePackageDotJson } from './clack-utils';
export interface PackageManager {
name: string;
label: string;
lockFile: string;
installCommand: string;
buildCommand: string;
/* The command that the package manager uses to run a script from package.json */
Expand All @@ -22,12 +21,14 @@ export interface PackageManager {
export const BUN: PackageManager = {
name: 'bun',
label: 'Bun',
lockFile: 'bun.lockb',
installCommand: 'bun add',
buildCommand: 'bun run build',
runScriptCommand: 'bun run',
flags: '',
detect: () => fs.existsSync(path.join(process.cwd(), BUN.lockFile)),
detect: () =>
['bun.lockb', 'bun.lock'].some((lockFile) =>
fs.existsSync(path.join(process.cwd(), lockFile)),
),
addOverride: async (pkgName, pkgVersion): Promise<void> => {
const packageDotJson = await getPackageDotJson();
const overrides = packageDotJson.overrides || {};
Expand All @@ -44,15 +45,14 @@ export const BUN: PackageManager = {
export const YARN_V1: PackageManager = {
name: 'yarn',
label: 'Yarn V1',
lockFile: 'yarn.lock',
installCommand: 'yarn add',
buildCommand: 'yarn build',
runScriptCommand: 'yarn',
flags: '--ignore-workspace-root-check',
detect: () => {
try {
return fs
.readFileSync(path.join(process.cwd(), YARN_V1.lockFile), 'utf-8')
.readFileSync(path.join(process.cwd(), 'yarn.lock'), 'utf-8')
.slice(0, 500)
.includes('yarn lockfile v1');
} catch (e) {
Expand All @@ -76,15 +76,14 @@ export const YARN_V1: PackageManager = {
export const YARN_V2: PackageManager = {
name: 'yarn',
label: 'Yarn V2/3/4',
lockFile: 'yarn.lock',
installCommand: 'yarn add',
buildCommand: 'yarn build',
runScriptCommand: 'yarn',
flags: '',
detect: () => {
try {
return fs
.readFileSync(path.join(process.cwd(), YARN_V2.lockFile), 'utf-8')
.readFileSync(path.join(process.cwd(), 'yarn.lock'), 'utf-8')
.slice(0, 500)
.includes('__metadata');
} catch (e) {
Expand All @@ -107,12 +106,11 @@ export const YARN_V2: PackageManager = {
export const PNPM: PackageManager = {
name: 'pnpm',
label: 'PNPM',
lockFile: 'pnpm-lock.yaml',
installCommand: 'pnpm add',
buildCommand: 'pnpm build',
runScriptCommand: 'pnpm',
flags: '--ignore-workspace-root-check',
detect: () => fs.existsSync(path.join(process.cwd(), PNPM.lockFile)),
detect: () => fs.existsSync(path.join(process.cwd(), 'pnpm-lock.yaml')),
addOverride: async (pkgName, pkgVersion): Promise<void> => {
const packageDotJson = await getPackageDotJson();
const pnpm = packageDotJson.pnpm || {};
Expand All @@ -133,12 +131,11 @@ export const PNPM: PackageManager = {
export const NPM: PackageManager = {
name: 'npm',
label: 'NPM',
lockFile: 'package-lock.json',
installCommand: 'npm add',
buildCommand: 'npm run build',
runScriptCommand: 'npm run',
flags: '',
detect: () => fs.existsSync(path.join(process.cwd(), NPM.lockFile)),
detect: () => fs.existsSync(path.join(process.cwd(), 'package-lock.json')),
addOverride: async (pkgName, pkgVersion): Promise<void> => {
const packageDotJson = await getPackageDotJson();
const overrides = packageDotJson.overrides || {};
Expand Down

0 comments on commit 7c3d91f

Please sign in to comment.