From 20f5a8a4d7274050be4a2c1b23d817c23a2c63db Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Mon, 27 May 2024 15:00:35 +0100 Subject: [PATCH] fix(core): add missing bun PM support (#26084) This fix add support for bun PM in daemon and affected changes. Helps towards #26053 fix (cherry picked from commit 4cbb0f098876a90c3242c38f8deba87f77b4e315) --- docs/shared/getting-started/installation.md | 14 ++++ packages/devkit/src/utils/replace-package.ts | 1 + packages/nx/src/daemon/server/server.ts | 1 + .../affected/lock-file-changes.spec.ts | 66 ++++++++++--------- .../affected/lock-file-changes.ts | 1 + 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/docs/shared/getting-started/installation.md b/docs/shared/getting-started/installation.md index 0a0df0c6a742a..6d3eb50d3693e 100644 --- a/docs/shared/getting-started/installation.md +++ b/docs/shared/getting-started/installation.md @@ -23,6 +23,13 @@ npx create-nx-workspace --pm yarn npx create-nx-workspace --pm pnpm ``` +{% /tab %} +{% tab label="Bun" %} + +```shell +bunx create-nx-workspace --pm bun +``` + {% /tab %} {% /tabs %} @@ -85,6 +92,13 @@ yarn global add nx@latest pnpm add --global nx@latest ``` +{% /tab %} +{% tab label="Bun" %} + +```shell +bun install --global nx@latest +``` + {% /tab %} {% /tabs %} diff --git a/packages/devkit/src/utils/replace-package.ts b/packages/devkit/src/utils/replace-package.ts index 5871fed491b2b..4e8f656193bab 100644 --- a/packages/devkit/src/utils/replace-package.ts +++ b/packages/devkit/src/utils/replace-package.ts @@ -161,6 +161,7 @@ function replaceMentions( 'yarn.lock', 'package-lock.json', 'pnpm-lock.yaml', + 'bun.lockb', '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 0aa1766158478..c648f0d1cf838 100644 --- a/packages/nx/src/daemon/server/server.ts +++ b/packages/nx/src/daemon/server/server.ts @@ -258,6 +258,7 @@ function lockFileHashChanged(): boolean { join(workspaceRoot, 'package-lock.json'), join(workspaceRoot, 'yarn.lock'), join(workspaceRoot, 'pnpm-lock.yaml'), + join(workspaceRoot, 'bun.lockb'), ] .filter((file) => existsSync(file)) .map((file) => hashFile(file)); 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 4807ac603180b..69ff822601f54 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 @@ -36,37 +36,41 @@ describe('getTouchedProjectsFromLockFile', () => { allNodes = Object.keys(graph.nodes); }); - ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'pnpm-lock.yml'].forEach( - (lockFile) => { - describe(`"${lockFile}"`, () => { - it(`should not return changes when "${lockFile}" is not touched`, () => { - const result = getTouchedProjectsFromLockFile( - [ - { - file: 'source.ts', - hash: 'some-hash', - getChanges: () => [new WholeFileChange()], - }, - ], - graph.nodes - ); - expect(result).toEqual([]); - }); + [ + 'package-lock.json', + 'yarn.lock', + 'pnpm-lock.yaml', + 'pnpm-lock.yml', + 'bun.lockb', + ].forEach((lockFile) => { + describe(`"${lockFile}"`, () => { + it(`should not return changes when "${lockFile}" is not touched`, () => { + const result = getTouchedProjectsFromLockFile( + [ + { + file: 'source.ts', + hash: 'some-hash', + getChanges: () => [new WholeFileChange()], + }, + ], + graph.nodes + ); + expect(result).toEqual([]); + }); - it(`should return all nodes when "${lockFile}" is touched`, () => { - const result = getTouchedProjectsFromLockFile( - [ - { - file: lockFile, - hash: 'some-hash', - getChanges: () => [new WholeFileChange()], - }, - ], - graph.nodes - ); - expect(result).toEqual(allNodes); - }); + it(`should return all nodes when "${lockFile}" is touched`, () => { + const result = getTouchedProjectsFromLockFile( + [ + { + file: lockFile, + hash: 'some-hash', + getChanges: () => [new WholeFileChange()], + }, + ], + graph.nodes + ); + expect(result).toEqual(allNodes); }); - } - ); + }); + }); }); 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 7e6827b3a4b47..f6c8c8be72146 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 @@ -10,6 +10,7 @@ export const getTouchedProjectsFromLockFile: TouchedProjectLocator< 'yarn.lock', 'pnpm-lock.yaml', 'pnpm-lock.yml', + 'bun.lockb', ]; if (fileChanges.some((f) => lockFiles.includes(f.file))) {