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

Improves yarn run performances #2564

Merged
merged 2 commits into from
Mar 5, 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/a1a1cf29.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/plugin-pnp": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-node-modules"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
13 changes: 10 additions & 3 deletions packages/plugin-pnp/sources/PnpLinker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {miscUtils, structUtils, formatUtils, Descriptor, LocatorHash}
import {FetchResult, Locator, Package} from '@yarnpkg/core';
import {Linker, LinkOptions, MinimalLinkOptions, Manifest, MessageName, DependencyMeta, LinkType, Installer} from '@yarnpkg/core';
import {CwdFS, PortablePath, VirtualFS, npath, ppath, xfs, Filename} from '@yarnpkg/fslib';
import {generateInlinedScript, generateSplitScript, PackageRegistry, PnpSettings} from '@yarnpkg/pnp';
import {generateInlinedScript, generateSplitScript, PackageRegistry, PnpApi, PnpSettings} from '@yarnpkg/pnp';
import {UsageError} from 'clipanion';

import {getPnpPath} from './index';
Expand All @@ -22,6 +22,8 @@ const FORCED_UNPLUG_PACKAGES = new Set([
export class PnpLinker implements Linker {
protected mode = `strict`;

private pnpCache: Map<string, PnpApi> = new Map();

supportsPackage(pkg: Package, opts: MinimalLinkOptions) {
if (opts.project.configuration.get(`nodeLinker`) !== `pnp`)
return false;
Expand All @@ -37,7 +39,9 @@ export class PnpLinker implements Linker {
if (!xfs.existsSync(pnpPath))
throw new UsageError(`The project in ${formatUtils.pretty(opts.project.configuration, `${opts.project.cwd}/package.json`, formatUtils.Type.PATH)} doesn't seem to have been installed - running an install there might help`);

const pnpFile = miscUtils.dynamicRequireNoCache(pnpPath);
const pnpFile = miscUtils.getFactoryWithDefault(this.pnpCache, pnpPath, () => {
return miscUtils.dynamicRequireNoCache(pnpPath);
});

const packageLocator = {name: structUtils.stringifyIdent(locator), reference: locator.reference};
const packageInformation = pnpFile.getPackageInformation(packageLocator);
Expand All @@ -53,7 +57,10 @@ export class PnpLinker implements Linker {
if (!xfs.existsSync(pnpPath))
return null;

const pnpFile = miscUtils.dynamicRequireNoCache(pnpPath);
const pnpFile = miscUtils.getFactoryWithDefault(this.pnpCache, pnpPath, () => {
return miscUtils.dynamicRequireNoCache(pnpPath);
});

const locator = pnpFile.findPackageLocator(npath.fromPortablePath(location));
if (!locator)
return null;
Expand Down