Skip to content

Commit 6b715ff

Browse files
authored
feat(release)!: version.generatorOptions.updateDependents is "auto" by default (#28231)
BREAKING CHANGE In Nx v19, `release.version.generatorOptions.updateDependents` is "never" by default, meaning dependents are not automatically patched when their dependencies change (applicable to independent projects). In Nx v20, `release.version.generatorOptions.updateDependents` is "auto" by default, meaning dependents are automatically patched when their dependencies change (applicable to independent projects).
1 parent 69e9bb9 commit 6b715ff

File tree

6 files changed

+27
-82
lines changed

6 files changed

+27
-82
lines changed

e2e/release/src/circular-dependencies.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ describe('nx release circular dependencies', () => {
684684
{project-name} 📄 Using the provided version specifier "major".
685685
{project-name} ⚠️ Warning, the following packages depend on "{project-name}" but have been filtered out via --projects, and therefore will not be updated:
686686
- {project-name}
687-
=> You can adjust this behavior by setting \`version.generatorOptions.updateDependents\` to "auto"
687+
=> You can adjust this behavior by removing the usage of \`version.generatorOptions.updateDependents\` with "never"
688688
{project-name} ✍️ New version 2.0.0 written to {project-name}/package.json
689689
690690

e2e/release/src/independent-projects.test.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ describe('nx release - independent projects', () => {
190190
{project-name} 🔍 Reading data for package "@proj/{project-name}" from {project-name}/package.json
191191
{project-name} 📄 Resolved the current version as 0.0.0 from {project-name}/package.json
192192
{project-name} 📄 Using the provided version specifier "999.9.9-package.3".
193-
{project-name} ⚠️ Warning, the following packages depend on "{project-name}" but have been filtered out via --projects, and therefore will not be updated:
194-
- {project-name}
195-
=> You can adjust this behavior by setting \`version.generatorOptions.updateDependents\` to "auto"
196193
{project-name} ✍️ New version 999.9.9-package.3 written to {project-name}/package.json
197194
198195
@@ -202,6 +199,17 @@ describe('nx release - independent projects', () => {
202199
"scripts": {
203200
204201
202+
"name": "@proj/{project-name}",
203+
- "version": "999.9.9-package.2",
204+
+ "version": "999.9.9",
205+
"scripts": {
206+
207+
"dependencies": {
208+
- "@proj/{project-name}": "0.0.0"
209+
+ "@proj/{project-name}": "999.9.9-package.3"
210+
}
211+
212+
205213
NX Staging changed files with git
206214
207215
@@ -316,7 +324,7 @@ describe('nx release - independent projects', () => {
316324
NX Running release version for project: {project-name}
317325
318326
{project-name} 🔍 Reading data for package "@proj/{project-name}" from {project-name}/package.json
319-
{project-name} 📄 Resolved the current version as 999.9.9-package.2 from {project-name}/package.json
327+
{project-name} 📄 Resolved the current version as 999.9.9 from {project-name}/package.json
320328
{project-name} 📄 Using the provided version specifier "999.9.9-version-git-operations-test.3".
321329
{project-name} ✍️ New version 999.9.9-version-git-operations-test.3 written to {project-name}/package.json
322330
@@ -335,7 +343,7 @@ describe('nx release - independent projects', () => {
335343
336344
337345
"name": "@proj/{project-name}",
338-
- "version": "999.9.9-package.2",
346+
- "version": "999.9.9",
339347
+ "version": "999.9.9-version-git-operations-test.3",
340348
"scripts": {
341349

e2e/release/src/release.test.ts

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { NxJsonConfiguration } from '@nx/devkit';
1+
import type { NxJsonConfiguration } from '@nx/devkit';
22
import {
33
cleanupProject,
44
createFile,
55
exists,
66
killProcessAndPorts,
77
newProject,
88
readFile,
9-
readJson,
109
runCLI,
1110
runCommandAsync,
1211
runCommandUntil,
@@ -92,9 +91,6 @@ describe('nx release', () => {
9291
`git remote add origin https://github.com/nrwl/fake-repo.git`
9392
);
9493

95-
const pkg1ContentsBeforeVersioning = readFile(`${pkg1}/package.json`);
96-
const pkg2ContentsBeforeVersioning = readFile(`${pkg2}/package.json`);
97-
9894
const versionOutput = runCLI(`release version 999.9.9`);
9995

10096
/**
@@ -122,50 +118,6 @@ describe('nx release', () => {
122118
).length
123119
).toEqual(3);
124120

125-
// Only one dependency relationship exists, so this log should only match once
126-
const dependencyRelationshipLogMatch = versionOutput.match(
127-
/Applying new version 999.9.9 to 1 package which depends on my-pkg-\d*/g
128-
);
129-
if (
130-
!dependencyRelationshipLogMatch ||
131-
dependencyRelationshipLogMatch.length !== 1
132-
) {
133-
const projectGraphDependencies = readJson(
134-
'.nx/cache/project-graph.json'
135-
).dependencies;
136-
const firstPartyProjectGraphDependencies = JSON.stringify(
137-
Object.fromEntries(
138-
Object.entries(projectGraphDependencies).filter(
139-
([key]) => !key.startsWith('npm:')
140-
)
141-
)
142-
);
143-
144-
// From JamesHenry: explicit warning to assist troubleshooting NXC-143.
145-
console.warn(
146-
`
147-
WARNING: Expected to find exactly one dependency relationship log line.
148-
149-
If you are seeing this message then you have been impacted by some flakiness in the test.
150-
151-
${JSON.stringify(
152-
{
153-
versionOutput,
154-
pkg1Name: pkg1,
155-
pkg2Name: pkg2,
156-
pkg1ContentsBeforeVersioning,
157-
pkg2ContentsBeforeVersioning,
158-
pkg2ContentsAfterVersioning: readFile(`${pkg2}/package.json`),
159-
firstPartyProjectGraphDependencies,
160-
},
161-
null,
162-
2
163-
)}`
164-
);
165-
}
166-
// TODO: re-enable this assertion once the flakiness documented in NXC-143 is resolved
167-
// expect(dependencyRelationshipLogMatch.length).toEqual(1);
168-
169121
// Generate a changelog for the new version
170122
expect(exists('CHANGELOG.md')).toEqual(false);
171123

@@ -377,14 +329,6 @@ ${JSON.stringify(
377329
).length
378330
).toEqual(3);
379331

380-
// TODO: Also impacted by NXC-143
381-
// Only one dependency relationship exists, so this log should only match once
382-
// expect(
383-
// versionOutput2.match(
384-
// /Applying new version 1000.0.0-next.0 to 1 package which depends on my-pkg-\d*/g
385-
// ).length
386-
// ).toEqual(1);
387-
388332
// Perform an initial dry-run of the publish to the custom registry (not e2e registry), and a custom dist tag of "next"
389333
const publishToNext = `release publish --registry=${customRegistryUrl} --tag=next`;
390334
const publishOutput2 = runCLI(`${publishToNext} --dry-run`);
@@ -847,14 +791,6 @@ ${JSON.stringify(
847791
).length
848792
).toEqual(3);
849793

850-
// TODO: Also impacted by NXC-143
851-
// Only one dependency relationship exists, so this log should only match once
852-
// expect(
853-
// versionOutput3.match(
854-
// /Applying new version 1100.1.0 to 1 package which depends on my-pkg-\d*/g
855-
// ).length
856-
// ).toEqual(1);
857-
858794
createFile(
859795
`${pkg1}/my-file.txt`,
860796
'update for conventional-commits testing'

packages/js/src/generators/release-version/release-version.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ To fix this you will either need to add a package.json file at that location, or
454454
});
455455

456456
describe('updateDependentsOptions', () => {
457-
it(`should not update dependents when filtering to a subset of projects by default`, async () => {
457+
it(`should update dependents even when filtering to a subset of projects which do not include those dependents, by default`, async () => {
458458
expect(readJson(tree, 'libs/my-lib/package.json').version).toEqual(
459459
'0.0.1'
460460
);
@@ -494,6 +494,7 @@ To fix this you will either need to add a package.json file at that location, or
494494
currentVersionResolver: 'disk',
495495
specifierSource: 'prompt',
496496
releaseGroup: createReleaseGroup('independent'),
497+
// No value for updateDependents, should default to 'auto'
497498
});
498499

499500
expect(readJson(tree, 'libs/my-lib/package.json'))
@@ -512,10 +513,10 @@ To fix this you will either need to add a package.json file at that location, or
512513
).toMatchInlineSnapshot(`
513514
{
514515
"dependencies": {
515-
"my-lib": "0.0.1",
516+
"my-lib": "9.9.9",
516517
},
517518
"name": "project-with-dependency-on-my-pkg",
518-
"version": "0.0.1",
519+
"version": "0.0.2",
519520
}
520521
`);
521522
expect(
@@ -526,10 +527,10 @@ To fix this you will either need to add a package.json file at that location, or
526527
).toMatchInlineSnapshot(`
527528
{
528529
"devDependencies": {
529-
"my-lib": "0.0.1",
530+
"my-lib": "9.9.9",
530531
},
531532
"name": "project-with-devDependency-on-my-pkg",
532-
"version": "0.0.1",
533+
"version": "0.0.2",
533534
}
534535
`);
535536
});

packages/js/src/generators/release-version/release-version.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Valid values are: ${validReleaseVersionPrefixes
8888
}
8989

9090
// Set default for updateDependents
91-
const updateDependents = options.updateDependents ?? 'never';
91+
const updateDependents = options.updateDependents ?? 'auto';
9292
const updateDependentsBump = 'patch';
9393

9494
// Sort the projects topologically if update dependents is enabled
@@ -601,7 +601,7 @@ To fix this you will either need to add a package.json file at that location, or
601601
return localPackageDependency.target === project.name;
602602
});
603603

604-
const includeTransitiveDependents = updateDependents === 'auto';
604+
const includeTransitiveDependents = updateDependents !== 'never';
605605
const transitiveLocalPackageDependents: LocalPackageDependency[] = [];
606606
if (includeTransitiveDependents) {
607607
for (const directDependent of allDependentProjects) {
@@ -674,7 +674,7 @@ To fix this you will either need to add a package.json file at that location, or
674674
logMsg += `\n${dependentProjectsOutsideCurrentBatch
675675
.map((dependentProject) => `${indent}- ${dependentProject.source}`)
676676
.join('\n')}`;
677-
logMsg += `\n${indent}=> You can adjust this behavior by setting \`version.generatorOptions.updateDependents\` to "auto"`;
677+
logMsg += `\n${indent}=> You can adjust this behavior by removing the usage of \`version.generatorOptions.updateDependents\` with "never"`;
678678
logger.buffer(logMsg);
679679
}
680680
}

packages/nx/src/command-line/release/version.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ export interface ReleaseVersionGeneratorSchema {
8686
conventionalCommitsConfig?: NxReleaseConfig['conventionalCommits'];
8787
deleteVersionPlans?: boolean;
8888
/**
89-
* 'auto' allows users to opt into dependents being updated (a patch version bump) when a dependency is versioned.
90-
* This is only applicable to independently released projects.
89+
* 'auto' is the default and will cause dependents to be updated (a patch version bump) when a dependency is versioned.
90+
* This is only applicable to independently released projects. 'never' will cause dependents to not be updated.
9191
*/
92-
updateDependents?: 'never' | 'auto';
92+
updateDependents?: 'auto' | 'never';
9393
/**
9494
* Whether or not to completely omit project logs when that project has no applicable changes. This can be useful for
9595
* large monorepos which have a large number of projects, especially when only a subset are released together.

0 commit comments

Comments
 (0)