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

Fixes yarn version apply #4336

Merged
merged 2 commits into from
Apr 7, 2022
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
23 changes: 23 additions & 0 deletions .yarn/versions/4704a5d3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/plugin-version": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
2 changes: 1 addition & 1 deletion packages/plugin-version/sources/commands/version/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class VersionApplyCommand extends BaseCommand {
if (this.all) {
await versionUtils.clearVersionFiles(project);
} else {
await versionUtils.updateVersionFiles(project);
await versionUtils.updateVersionFiles(project, [...filteredReleases.keys()]);
}
}

Expand Down
26 changes: 16 additions & 10 deletions packages/plugin-version/sources/versionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function resolveVersionFiles(project: Project, {prerelease = null}:

const deferredVersionFolder = project.configuration.get(`deferredVersionFolder`);
if (!xfs.existsSync(deferredVersionFolder))
return new Map();
return candidateReleases;

const deferredVersionFiles = await xfs.readdirPromise(deferredVersionFolder);

Expand Down Expand Up @@ -133,7 +133,9 @@ export async function clearVersionFiles(project: Project) {
await xfs.removePromise(deferredVersionFolder);
}

export async function updateVersionFiles(project: Project) {
export async function updateVersionFiles(project: Project, workspaces: Array<Workspace>) {
const workspaceSet = new Set(workspaces);

const deferredVersionFolder = project.configuration.get(`deferredVersionFolder`);
if (!xfs.existsSync(deferredVersionFolder))
return;
Expand All @@ -153,19 +155,23 @@ export async function updateVersionFiles(project: Project) {
continue;

for (const locatorStr of Object.keys(releases)) {
const locator = structUtils.parseLocator(locatorStr);
const workspace = project.tryWorkspaceByLocator(locator);
const ident = structUtils.parseIdent(locatorStr);
const workspace = project.tryWorkspaceByIdent(ident);

if (workspace === null) {
if (workspace === null || workspaceSet.has(workspace)) {
delete versionData.releases[locatorStr];
}
}

await xfs.changeFilePromise(versionPath, stringifySyml(
new stringifySyml.PreserveOrdering(
versionData,
),
));
if (Object.keys(versionData.releases).length > 0) {
await xfs.changeFilePromise(versionPath, stringifySyml(
new stringifySyml.PreserveOrdering(
versionData,
),
));
} else {
await xfs.unlinkPromise(versionPath);
}
}
}

Expand Down