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

[rush-lib] Fix edge cases where Rush does not update the lockfile #4839

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions common/changes/@microsoft/rush/fix-edge-case_2024-07-18-06-38.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix edge cases where Rush does not update the lockfile",
iclanton marked this conversation as resolved.
Show resolved Hide resolved
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
12 changes: 10 additions & 2 deletions libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {

// Use a new PackageJsonEditor since it will classify each dependency type, making tracking the
// found versions much simpler.
const { dependencyList, devDependencyList } = PackageJsonEditor.fromObject(
const { dependencyList, devDependencyList, dependencyMetaList } = PackageJsonEditor.fromObject(
this._pnpmfileConfiguration.transform(transformedPackageJson),
project.packageJsonEditor.filePath
);
Expand Down Expand Up @@ -960,6 +960,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
);
const importerDependencies: Set<string> = new Set(Object.keys(importer.dependencies ?? {}));
const importerDevDependencies: Set<string> = new Set(Object.keys(importer.devDependencies ?? {}));
const importerDependenciesMeta: Set<string> = new Set(Object.keys(importer.dependenciesMeta ?? {}));

for (const { dependencyType, name, version } of allDependencies) {
let isOptional: boolean = false;
Expand Down Expand Up @@ -1019,11 +1020,18 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
}
}

for (const { name, injected } of dependencyMetaList) {
if (importer.dependenciesMeta?.[name]?.injected === injected) {
importerDependenciesMeta.delete(name);
}
}

// Finally, validate that all values in the importer are also present in the dependency list.
if (
importerOptionalDependencies.size > 0 ||
importerDependencies.size > 0 ||
importerDevDependencies.size > 0
importerDevDependencies.size > 0 ||
importerDependenciesMeta.size > 0
) {
return true;
}
Expand Down
Loading