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] Fix an issue where usage of custom fields in dependenciesMeta caused rush install to think that shrinkwrap file is outdated #4992

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

witcher112
Copy link
Contributor

@witcher112 witcher112 commented Nov 6, 2024

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
Contributor Author

@microsoft-github-policy-service agree

libraries/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts Outdated Show resolved Hide resolved
@@ -107,7 +111,7 @@ export class PackageJsonEditor {
const devDependencies: { [key: string]: string } = data.devDependencies || {};
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
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
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?

@@ -50,19 +50,23 @@ export class PackageJsonDependency {
* @public
*/
export class PackageJsonDependencyMeta {
private _injected: boolean;
private _sourceData: object;
Copy link
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
Copy link
Contributor Author

witcher112 commented Nov 14, 2024

@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
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",

@@ -1005,11 +1013,13 @@ export class PackageJsonDependency {

// @public (undocumented)
export class PackageJsonDependencyMeta {
constructor(name: string, injected: boolean, onChange: () => void);
constructor(name: string, sourceData: IPackageJsonDependencyMetaSourceData, onChange: () => void);
Copy link
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
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
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
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