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

fix(align-deps): cache "vigilant" mode profiles #1959

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/brown-clouds-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
25 changes: 24 additions & 1 deletion packages/align-deps/src/commands/vigilant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,29 @@ export function buildManifestProfile(
};
}

/**
* Cached version of {@link buildManifestProfile}.
*
* In monorepositories with many packages, this can save a lot of time.
*
* @param manifestPath The path to the package manifest
* @param config Configuration from `package.json` or "generated" from command line flags
* @returns A package manifest containing all capabilities
*/
const buildManifestProfileCached = ((): typeof buildManifestProfile => {
const profileCache: Record<string, ManifestProfile> = {};
return (manifestPath, config) => {
const { kitType, alignDeps } = config;
const key = `${kitType}:${JSON.stringify(alignDeps)}`;
if (!profileCache[key]) {
const result = buildManifestProfile(manifestPath, config);
profileCache[key] = result;
}

return profileCache[key];
};
})();

/**
* Compares the package manifest with the desired profile and returns all
* dependencies that are misaligned.
Expand Down Expand Up @@ -157,7 +180,7 @@ export function checkPackageManifestUnconfigured(
return "success";
}

const manifestProfile = buildManifestProfile(manifestPath, config);
const manifestProfile = buildManifestProfileCached(manifestPath, config);
const { manifest } = config;
const changes = inspect(manifest, manifestProfile, write);
if (changes.length > 0) {
Expand Down