Skip to content

Commit

Permalink
[rush-lib] Fix edge cases where Rush does not update the lockfile (#4839
Browse files Browse the repository at this point in the history
)

* fix: edge cases where Rush does not update the lockfile

* rush change

* Rush change.

---------

Co-authored-by: qun <L-Qun@users.noreply.github.com>
Co-authored-by: Ian Clanton-Thuon <iclanton@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 22, 2024
1 parent 7bc9d0d commit 0e14ced
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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 an issue where Rush does not detect an outdated lockfile if the `dependenciesMeta` `package.json` field is edited.",
"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

0 comments on commit 0e14ced

Please sign in to comment.