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(release): use prepatch version for pre-release dependent package updates #29123

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 @@ -696,6 +696,70 @@ To fix this you will either need to add a package.json file at that location, or
}
`);
});

it('should update dependents with a prepatch when creating a pre-release version', async () => {
expect(readJson(tree, 'libs/my-lib/package.json').version).toEqual(
'0.0.1'
);
expect(
readJson(
tree,
'libs/project-with-dependency-on-my-pkg/package.json'
).version
).toEqual('0.0.1');
expect(
readJson(
tree,
'libs/project-with-devDependency-on-my-pkg/package.json'
).version
).toEqual('0.0.1');

await releaseVersionGenerator(tree, {
projects: Object.values(projectGraph.nodes), // version all projects
projectGraph,
currentVersionResolver: 'disk',
specifier: 'prepatch',
preid: 'alpha',
releaseGroup: createReleaseGroup('independent'),
});

expect(readJson(tree, 'libs/my-lib/package.json'))
.toMatchInlineSnapshot(`
{
"name": "my-lib",
"version": "0.0.2-alpha.0",
}
`);

expect(
readJson(
tree,
'libs/project-with-dependency-on-my-pkg/package.json'
)
).toMatchInlineSnapshot(`
{
"dependencies": {
"my-lib": "0.0.2-alpha.0",
},
"name": "project-with-dependency-on-my-pkg",
"version": "0.0.2-alpha.0",
}
`);
expect(
readJson(
tree,
'libs/project-with-devDependency-on-my-pkg/package.json'
)
).toMatchInlineSnapshot(`
{
"devDependencies": {
"my-lib": "0.0.2-alpha.0",
},
"name": "project-with-devDependency-on-my-pkg",
"version": "0.0.2-alpha.0",
}
`);
});
});
});
});
Expand Down
25 changes: 21 additions & 4 deletions packages/js/src/generators/release-version/release-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ import {
import { sortProjectsTopologically } from './utils/sort-projects-topologically';
import { updateLockFile } from './utils/update-lock-file';

function resolvePreIdSpecifier(currentSpecifier: string, preid?: string) {
if (!currentSpecifier.startsWith('pre') && preid) {
return `pre${currentSpecifier}`;
}

return currentSpecifier;
}

export async function releaseVersionGenerator(
tree: Tree,
options: ReleaseVersionGeneratorSchema
Expand Down Expand Up @@ -89,7 +97,10 @@ Valid values are: ${validReleaseVersionPrefixes

// Set default for updateDependents
const updateDependents = options.updateDependents ?? 'auto';
const updateDependentsBump = 'patch';
const updateDependentsBump = resolvePreIdSpecifier(
'patch',
options.preid
) as ReleaseType;

// Sort the projects topologically if update dependents is enabled
// TODO: maybe move this sorting to the command level?
Expand Down Expand Up @@ -445,8 +456,13 @@ To fix this you will either need to add a package.json file at that location, or
);
} else {
let extraText = '';
if (options.preid && !specifier.startsWith('pre')) {
specifier = `pre${specifier}`;
const prereleaseSpecifier = resolvePreIdSpecifier(
specifier,
options.preid
);

if (prereleaseSpecifier !== specifier) {
specifier = prereleaseSpecifier;
extraText = `, combined with your given preid "${options.preid}"`;
}
logger.buffer(
Expand Down Expand Up @@ -598,6 +614,7 @@ To fix this you will either need to add a package.json file at that location, or
options.releaseGroup.projectsRelationship === 'independent'
);

// list of projects that depend on the current package
const allDependentProjects = Object.values(localPackageDependencies)
.flat()
.filter((localPackageDependency) => {
Expand Down Expand Up @@ -765,7 +782,7 @@ To fix this you will either need to add a package.json file at that location, or
dependentProject: LocalPackageDependency;
dependencyPackageName: string;
newDependencyVersion: string;
forceVersionBump: 'major' | 'minor' | 'patch' | false;
forceVersionBump: ReleaseType | false;
}) => {
const updatedFilePath = joinPathFragments(
projectNameToPackageRootMap.get(dependentProject.source),
Expand Down
Loading