From f4c1950e6f05d28756a2567bd27f5136f9d29f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Mon, 13 Nov 2023 08:37:45 -0500 Subject: [PATCH] fix(js): filtering of local dependencies when running `nx release version` (#19995) (cherry picked from commit b90e3007c407fc4a1afff12484cbeb2155ed3a3a) --- .../release-version/release-version.spec.ts | 62 +++++++++++++++++++ .../release-version/release-version.ts | 11 ++-- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/packages/js/src/generators/release-version/release-version.spec.ts b/packages/js/src/generators/release-version/release-version.spec.ts index 2edade0ba0e5b..6a411fb31bc76 100644 --- a/packages/js/src/generators/release-version/release-version.spec.ts +++ b/packages/js/src/generators/release-version/release-version.spec.ts @@ -164,6 +164,68 @@ To fix this you will either need to add a package.json file at that location, or outputSpy.mockRestore(); }); }); + + describe('package with mixed "prod" and "dev" dependencies', () => { + beforeEach(() => { + projectGraph = createWorkspaceWithPackageDependencies(tree, { + 'my-app': { + projectRoot: 'libs/my-app', + packageName: 'my-app', + version: '0.0.1', + packageJsonPath: 'libs/my-app/package.json', + localDependencies: [ + { + projectName: 'my-lib-1', + dependencyCollection: 'dependencies', + version: '0.0.1', + }, + { + projectName: 'my-lib-2', + dependencyCollection: 'devDependencies', + version: '0.0.1', + }, + ], + }, + 'my-lib-1': { + projectRoot: 'libs/my-lib-1', + packageName: 'my-lib-1', + version: '0.0.1', + packageJsonPath: 'libs/my-lib-1/package.json', + localDependencies: [], + }, + 'my-lib-2': { + projectRoot: 'libs/my-lib-2', + packageName: 'my-lib-2', + version: '0.0.1', + packageJsonPath: 'libs/my-lib-2/package.json', + localDependencies: [], + }, + }); + }); + + it('updates local dependencies only where it needs to', async () => { + await releaseVersionGenerator(tree, { + projects: Object.values(projectGraph.nodes), // version all projects + projectGraph, + specifier: 'major', + currentVersionResolver: 'disk', + releaseGroup: createReleaseGroup(), + }); + + expect(readJson(tree, 'libs/my-app/package.json')).toMatchInlineSnapshot(` + { + "dependencies": { + "my-lib-1": "1.0.0", + }, + "devDependencies": { + "my-lib-2": "1.0.0", + }, + "name": "my-app", + "version": "1.0.0", + } + `); + }); + }); }); function createReleaseGroup( diff --git a/packages/js/src/generators/release-version/release-version.ts b/packages/js/src/generators/release-version/release-version.ts index 32244e5b6336f..5e24a5139cad9 100644 --- a/packages/js/src/generators/release-version/release-version.ts +++ b/packages/js/src/generators/release-version/release-version.ts @@ -270,13 +270,10 @@ To fix this you will either need to add a package.json file at that location, or ); const dependentProjects = Object.values(localPackageDependencies) - .filter((localPackageDependencies) => { - return localPackageDependencies.some( - (localPackageDependency) => - localPackageDependency.target === project.name - ); - }) - .flat(); + .flat() + .filter((localPackageDependency) => { + return localPackageDependency.target === project.name; + }); if (dependentProjects.length > 0) { log(