diff --git a/e2e/utils/get-env-info.ts b/e2e/utils/get-env-info.ts index a8938352937a0..5201999bc41cc 100644 --- a/e2e/utils/get-env-info.ts +++ b/e2e/utils/get-env-info.ts @@ -23,7 +23,8 @@ export function getPublishedVersion(): string { } export function detectPackageManager(dir: string = ''): PackageManager { - return existsSync(join(dir, 'bun.lockb')) + return existsSync(join(dir, 'bun.lockb')) || + existsSync(join(dir, 'bun.lock')) ? 'bun' : existsSync(join(dir, 'yarn.lock')) ? 'yarn' diff --git a/packages/create-nx-workspace/src/utils/package-manager.ts b/packages/create-nx-workspace/src/utils/package-manager.ts index e8c23674f8191..bf4e9c2241e50 100644 --- a/packages/create-nx-workspace/src/utils/package-manager.ts +++ b/packages/create-nx-workspace/src/utils/package-manager.ts @@ -12,7 +12,8 @@ export const packageManagerList = ['pnpm', 'yarn', 'npm', 'bun'] as const; export type PackageManager = (typeof packageManagerList)[number]; export function detectPackageManager(dir: string = ''): PackageManager { - return existsSync(join(dir, 'bun.lockb')) + return existsSync(join(dir, 'bun.lockb')) || + existsSync(join(dir, 'bun.lock')) ? 'bun' : existsSync(join(dir, 'yarn.lock')) ? 'yarn' diff --git a/packages/devkit/src/utils/replace-package.ts b/packages/devkit/src/utils/replace-package.ts index 4e8f656193bab..9cad8c216a960 100644 --- a/packages/devkit/src/utils/replace-package.ts +++ b/packages/devkit/src/utils/replace-package.ts @@ -162,6 +162,7 @@ function replaceMentions( 'package-lock.json', 'pnpm-lock.yaml', 'bun.lockb', + 'bun.lock', 'CHANGELOG.md', ]; if (ignoredFiles.includes(basename(path))) { diff --git a/packages/nx/src/daemon/server/server.ts b/packages/nx/src/daemon/server/server.ts index 03a176a658987..ad3d7e2e5aec9 100644 --- a/packages/nx/src/daemon/server/server.ts +++ b/packages/nx/src/daemon/server/server.ts @@ -383,6 +383,7 @@ function lockFileHashChanged(): boolean { join(workspaceRoot, 'yarn.lock'), join(workspaceRoot, 'pnpm-lock.yaml'), join(workspaceRoot, 'bun.lockb'), + join(workspaceRoot, 'bun.lock'), ] .filter((file) => existsSync(file)) .map((file) => hashFile(file)); diff --git a/packages/nx/src/plugins/js/lock-file/lock-file.ts b/packages/nx/src/plugins/js/lock-file/lock-file.ts index 4575cf83b4cfe..500b3fae8cf3d 100644 --- a/packages/nx/src/plugins/js/lock-file/lock-file.ts +++ b/packages/nx/src/plugins/js/lock-file/lock-file.ts @@ -46,17 +46,20 @@ const YARN_LOCK_FILE = 'yarn.lock'; const NPM_LOCK_FILE = 'package-lock.json'; const PNPM_LOCK_FILE = 'pnpm-lock.yaml'; const BUN_LOCK_FILE = 'bun.lockb'; +const BUN_TEXT_LOCK_FILE = 'bun.lock'; export const LOCKFILES = [ YARN_LOCK_FILE, NPM_LOCK_FILE, PNPM_LOCK_FILE, BUN_LOCK_FILE, + BUN_TEXT_LOCK_FILE, ]; const YARN_LOCK_PATH = join(workspaceRoot, YARN_LOCK_FILE); const NPM_LOCK_PATH = join(workspaceRoot, NPM_LOCK_FILE); const PNPM_LOCK_PATH = join(workspaceRoot, PNPM_LOCK_FILE); const BUN_LOCK_PATH = join(workspaceRoot, BUN_LOCK_FILE); +const BUN_TEXT_LOCK_PATH = join(workspaceRoot, BUN_TEXT_LOCK_FILE); /** * Parses lock file and maps dependencies and metadata to {@link LockFileGraph} @@ -143,7 +146,7 @@ export function lockFileExists(packageManager: PackageManager): boolean { return existsSync(NPM_LOCK_PATH); } if (packageManager === 'bun') { - return existsSync(BUN_LOCK_PATH); + return existsSync(BUN_LOCK_PATH) || existsSync(BUN_TEXT_LOCK_PATH); } throw new Error( `Unknown package manager ${packageManager} or lock file missing` @@ -182,7 +185,7 @@ function getLockFilePath(packageManager: PackageManager): string { return NPM_LOCK_PATH; } if (packageManager === 'bun') { - return BUN_LOCK_PATH; + return BUN_LOCK_PATH; // defaulting to binary lockfile } throw new Error(`Unknown package manager: ${packageManager}`); } diff --git a/packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.spec.ts b/packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.spec.ts index 69ff822601f54..6de0781a51a0e 100644 --- a/packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.spec.ts +++ b/packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.spec.ts @@ -42,6 +42,7 @@ describe('getTouchedProjectsFromLockFile', () => { 'pnpm-lock.yaml', 'pnpm-lock.yml', 'bun.lockb', + 'bun.lock', ].forEach((lockFile) => { describe(`"${lockFile}"`, () => { it(`should not return changes when "${lockFile}" is not touched`, () => { diff --git a/packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.ts b/packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.ts index 8f4c4e393ae3c..c430cd7928224 100644 --- a/packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.ts +++ b/packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.ts @@ -26,6 +26,7 @@ export const getTouchedProjectsFromLockFile: TouchedProjectLocator< 'pnpm-lock.yaml', 'pnpm-lock.yml', 'bun.lockb', + 'bun.lock', ]; if (fileChanges.some((f) => lockFiles.includes(f.file))) { diff --git a/packages/nx/src/utils/package-manager.spec.ts b/packages/nx/src/utils/package-manager.spec.ts index 454afbcd7a9d0..e82e9ef92b903 100644 --- a/packages/nx/src/utils/package-manager.spec.ts +++ b/packages/nx/src/utils/package-manager.spec.ts @@ -45,6 +45,8 @@ describe('package-manager', () => { return false; case 'bun.lockb': return false; + case 'bun.lock': + return false; default: return jest.requireActual('fs').existsSync(p); } @@ -66,6 +68,8 @@ describe('package-manager', () => { return false; case 'bun.lockb': return false; + case 'bun.lock': + return false; default: return jest.requireActual('fs').existsSync(p); } @@ -96,6 +100,27 @@ describe('package-manager', () => { expect(fs.existsSync).toHaveBeenCalledTimes(1); }); + it('should detect bun package manager from bun.lock', () => { + jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({}); + jest.spyOn(fs, 'existsSync').mockImplementation((p) => { + switch (p) { + case 'yarn.lock': + return false; + case 'pnpm-lock.yaml': + return false; + case 'package-lock.json': + return false; + case 'bun.lock': + return true; + default: + return jest.requireActual('fs').existsSync(p); + } + }); + const packageManager = detectPackageManager(); + expect(packageManager).toEqual('bun'); + expect(fs.existsSync).toHaveBeenCalledTimes(1); + }); + it('should use npm package manager as default', () => { jest.spyOn(configModule, 'readNxJson').mockReturnValueOnce({}); jest.spyOn(fs, 'existsSync').mockImplementation((p) => { diff --git a/packages/nx/src/utils/package-manager.ts b/packages/nx/src/utils/package-manager.ts index da88ac1edb959..821b88ac09696 100644 --- a/packages/nx/src/utils/package-manager.ts +++ b/packages/nx/src/utils/package-manager.ts @@ -53,7 +53,8 @@ export function detectPackageManager(dir: string = ''): PackageManager { const nxJson = readNxJson(); return ( nxJson.cli?.packageManager ?? - (existsSync(join(dir, 'bun.lockb')) + existsSync(join(dir, 'bun.lockb')) || + existsSync(join(dir, 'bun.lock')) ? 'bun' : existsSync(join(dir, 'yarn.lock')) ? 'yarn' diff --git a/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts b/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts index 8c8bbea665e61..fde82375bf1c9 100644 --- a/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts +++ b/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts @@ -38,7 +38,8 @@ jest.mock('fs', () => { existsSync: (p) => p.endsWith('yarn.lock') || p.endsWith('pnpm-lock.yaml') || - p.endsWith('bun.lockb') + p.endsWith('bun.lockb') || + p.endsWith('bun.lock') ? memFs.existsSync(p) : actualFs.existsSync(p), }; diff --git a/scripts/check-lock-files.js b/scripts/check-lock-files.js index e4584d82d54ea..1802daaaed6da 100644 --- a/scripts/check-lock-files.js +++ b/scripts/check-lock-files.js @@ -12,6 +12,11 @@ function checkLockFiles() { 'Invalid occurence of "bun.lockb" file. Please remove it and use only "pnpm-lock.yaml"' ); } + if (fs.existsSync('bun.lock')) { + errors.push( + 'Invalid occurence of "bun.lockb" file. Please remove it and use only "pnpm-lock.yaml"' + ); + } if (fs.existsSync('yarn.lock')) { errors.push( 'Invalid occurence of "yarn.lock" file. Please remove it and use only "pnpm-lock.yaml"'