diff --git a/common/changes/@microsoft/rush/fix-edge-case_2024-07-18-06-38.json b/common/changes/@microsoft/rush/fix-edge-case_2024-07-18-06-38.json new file mode 100644 index 00000000000..bc263e1bd1f --- /dev/null +++ b/common/changes/@microsoft/rush/fix-edge-case_2024-07-18-06-38.json @@ -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" +} \ No newline at end of file diff --git a/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts b/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts index e8cb02740c0..c2515f93904 100644 --- a/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts +++ b/libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts @@ -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 ); @@ -960,6 +960,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { ); const importerDependencies: Set = new Set(Object.keys(importer.dependencies ?? {})); const importerDevDependencies: Set = new Set(Object.keys(importer.devDependencies ?? {})); + const importerDependenciesMeta: Set = new Set(Object.keys(importer.dependenciesMeta ?? {})); for (const { dependencyType, name, version } of allDependencies) { let isOptional: boolean = false; @@ -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; }