Skip to content

[rush] Fix an issue where usage of custom fields in dependenciesMeta caused rush install to think that shrinkwrap file is outdated#4992

Open
witcher112 wants to merge 7 commits into
microsoft:mainfrom
witcher112:fix-dependencies-meta-custom-fields
Open

[rush] Fix an issue where usage of custom fields in dependenciesMeta caused rush install to think that shrinkwrap file is outdated#4992
witcher112 wants to merge 7 commits into
microsoft:mainfrom
witcher112:fix-dependencies-meta-custom-fields

Conversation

@witcher112

@witcher112 witcher112 commented Nov 6, 2024

Copy link
Copy Markdown
Contributor

Summary

In our project, we're using custom fields in "dependenciesMeta" to supply additional features in our custom build chain.

As it turns out, pnpm stores those in pnpm-lock.yaml file and current Rush mechanism fails to properly compare them as it's limited to retrieving "injected" property.

Details

I've extended the mechanism to retrieve an entire object from "dependenciesMeta" and compare it instead of hardcoding "injected" field.

Aside from covering our use case, this would prepare Rush for future fields that might be introduced in "dependenciesMeta" by pnpm.

How it was tested

I've verified the fix in our repo where we use custom dependenciesMeta.

Impacted documentation

@witcher112

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Comment thread libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts Outdated
const resolutions: { [key: string]: string } = data.resolutions || {};

const dependenciesMeta: { [key: string]: { [key: string]: boolean } } = data.dependenciesMeta || {};
const dependenciesMeta: { [key: string]: object } = data.dependenciesMeta || {};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just reference IDependenciesMetaYaml? Or it probably makes more sense to define that type here and point IDependenciesMetaYaml to that (assuming that the types truly are the same).

@@ -183,7 +187,7 @@ export class PackageJsonEditor {
Object.keys(dependenciesMeta || {}).forEach((packageName: string) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update this to use Object.entries?

*/
export class PackageJsonDependencyMeta {
private _injected: boolean;
private _sourceData: object;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then use the more complete type here and in other places.

witcher112 and others added 2 commits November 15, 2024 00:35
Co-authored-by: Ian Clanton-Thuon <iclanton@users.noreply.github.com>
@witcher112

witcher112 commented Nov 14, 2024

Copy link
Copy Markdown
Contributor Author

@iclanton thanks for the review, I've pushed new changes according to your requests :)

"changes": [
{
"packageName": "@rushstack/node-core-library",
"comment": "Extend IDependenciesMetaTable interface to support custom properties in \"dependenciesMeta\" entries",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"comment": "Extend IDependenciesMetaTable interface to support custom properties in \"dependenciesMeta\" entries",
"comment": "Extend `IDependenciesMetaTable` interface to support custom properties in `"dependenciesMeta"` entries",

// @public (undocumented)
export class PackageJsonDependencyMeta {
constructor(name: string, injected: boolean, onChange: () => void);
constructor(name: string, sourceData: IPackageJsonDependencyMetaSourceData, onChange: () => void);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change. Can this be reworked to maintain compatability?

Comment on lines 70 to +71
injected?: boolean;
[key: string]: unknown;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating this in libraries/rush-lib/src/api/PackageJsonEditor.ts, can you just extract this object to its own interface and use that in rush-lib?

export interface IDependenciesMetaYaml {
injected?: boolean;
}
export type IDependenciesMetaYaml = IPackageJsonDependencyMetaSourceData;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just get rid of this and have other things reference the other type.

"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix an issue where usage of custom fields in dependenciesMeta caused rush install to think that shrinkwrap file is outdated",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"comment": "Fix an issue where usage of custom fields in dependenciesMeta caused rush install to think that shrinkwrap file is outdated",
"comment": "Fix an issue where usage of custom fields in `dependenciesMeta` caused `rush install` to think that the lockfile is outdated",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants