Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js): filtering of local dependencies when running nx release version #19995

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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