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

perf(node-modules): cache install state #2576

Merged
merged 2 commits into from
Mar 8, 2021
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
22 changes: 22 additions & 0 deletions .yarn/versions/0b00790b.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/plugin-node-modules": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
12 changes: 10 additions & 2 deletions packages/plugin-node-modules/sources/NodeModulesLinker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type BinSymlinkMap = Map<PortablePath, Map<Filename, PortablePath>>;
type LoadManifest = (locator: LocatorKey, installLocation: PortablePath) => Promise<Pick<Manifest, 'bin'>>;

export class NodeModulesLinker implements Linker {
private installStateCache: Map<string, Promise<InstallState | null>> = new Map();

supportsPackage(pkg: Package, opts: MinimalLinkOptions) {
return opts.project.configuration.get(`nodeLinker`) === `node-modules`;
}
Expand All @@ -33,7 +35,10 @@ export class NodeModulesLinker implements Linker {
if (workspace)
return workspace.cwd;

const installState = await findInstallState(opts.project, {unrollAliases: true});
const installState = await miscUtils.getFactoryWithDefault(this.installStateCache, opts.project.cwd, async () => {
return await findInstallState(opts.project, {unrollAliases: true});
});

if (installState === null)
throw new UsageError(`Couldn't find the node_modules state file - running an install might help (findPackageLocation)`);

Expand All @@ -48,7 +53,10 @@ export class NodeModulesLinker implements Linker {
}

async findPackageLocator(location: PortablePath, opts: LinkOptions) {
const installState = await findInstallState(opts.project, {unrollAliases: true});
const installState = await miscUtils.getFactoryWithDefault(this.installStateCache, opts.project.cwd, async () => {
return await findInstallState(opts.project, {unrollAliases: true});
});

if (installState === null)
return null;

Expand Down