rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[rush] Rush update should update shrinkwrap when globalPackageExtension has changed

Open kenrick95 opened this issue 1 year ago • 0 comments

Summary

Similar to https://github.com/microsoft/rushstack/issues/4820

Discovered when doing https://github.com/microsoft/rushstack/pull/4898

Repro steps

  1. In a Rush repo, with PNPM as package manager, add a dependency to a file
  2. Do a rush update
  3. Then change globalPackageExtension
  4. Do a rush update

Expected result:

Rush should update the lockfile

Actual result:

Rush skips the checks and didn't update lockfile

Workaround is that we should run rush update --recheck

Details

When globalPackageExtension has been updated and libraries/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts needs to mark shrinkwrapIsUpToDate as false too.

However, package extension is represented as a checksum in the shrinkwrap file (packageExtensionsChecksum). That means we need to calculate the checksum of pnpm-config.json's globalPackageExtension and compare it wit the checksum from the shrinkwrap file.

I checked how pnpm did it (ref) and I guess we can copy the part, but what's missing is the sortKeys function. In pnpm, it is using [email protected] but not sure if we should introduce an external dependencies for this case... What do you think?

const packageExtensionsChecksum = isEmpty(opts.packageExtensions ?? {}) ? undefined : createObjectChecksum(opts.packageExtensions!)


export function createObjectChecksum (obj: Record<string, unknown>) {
  const s = JSON.stringify(sortKeys(obj, { deep: true }))
  return crypto.createHash('md5').update(s).digest('hex')
}

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/rush globally installed version? 5.132.0
rushVersion from rush.json? 5.129.7
useWorkspaces from rush.json? true
Operating system? Mac
Would you consider contributing a PR? Yes
Node.js version (node -v)? 18.20.4

kenrick95 avatar Aug 23 '24 09:08 kenrick95