diff --git a/.yarn/versions/0b00790b.yml b/.yarn/versions/0b00790b.yml new file mode 100644 index 000000000000..e7282ca57601 --- /dev/null +++ b/.yarn/versions/0b00790b.yml @@ -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" diff --git a/packages/plugin-node-modules/sources/NodeModulesLinker.ts b/packages/plugin-node-modules/sources/NodeModulesLinker.ts index d3b319b6a7cd..4166249a7577 100644 --- a/packages/plugin-node-modules/sources/NodeModulesLinker.ts +++ b/packages/plugin-node-modules/sources/NodeModulesLinker.ts @@ -24,6 +24,8 @@ type BinSymlinkMap = Map>; type LoadManifest = (locator: LocatorKey, installLocation: PortablePath) => Promise>; export class NodeModulesLinker implements Linker { + private installStateCache: Map> = new Map(); + supportsPackage(pkg: Package, opts: MinimalLinkOptions) { return opts.project.configuration.get(`nodeLinker`) === `node-modules`; } @@ -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)`); @@ -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;