Skip to content

Commit

Permalink
Improves yarn run performances (#2564)
Browse files Browse the repository at this point in the history
* Improves yarn run performances

* Versions
  • Loading branch information
arcanis committed Mar 5, 2021
1 parent 3fef40f commit c8bc1d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
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

0 comments on commit c8bc1d5

Please sign in to comment.