Skip to content

Commit

Permalink
fix(js): filtering of local dependencies when running `nx release ver…
Browse files Browse the repository at this point in the history
…sion` (#19995)

(cherry picked from commit b90e300)
  • Loading branch information
kraenhansen authored and FrozenPandaz committed Nov 13, 2023
1 parent 6ee8bcc commit f4c1950
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 7 deletions.
62 changes: 62 additions & 0 deletions packages/js/src/generators/release-version/release-version.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 4 additions & 7 deletions packages/js/src/generators/release-version/release-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f4c1950

Please sign in to comment.