How to use @yarnpkg/pnp - 3 common examples

To help you get started, we’ve selected a few @yarnpkg/pnp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yarnpkg / berry / packages / plugin-pnp / sources / PnpLinker.ts View on Github external
const pnpPath = getPnpPath(this.opts.project);
    const pnpDataPath = this.opts.project.configuration.get(`pnpDataPath`);

    const pnpSettings: PnpSettings = {
      blacklistedLocations,
      dependencyTreeRoots,
      enableTopLevelFallback,
      fallbackExclusionList,
      ignorePattern,
      packageRegistry,
      shebang,
    };

    if (this.opts.project.configuration.get(`pnpEnableInlining`)) {
      const loaderFile = generateInlinedScript(pnpSettings);

      await xfs.changeFilePromise(pnpPath, loaderFile);
      await xfs.chmodPromise(pnpPath, 0o755);

      await xfs.removePromise(pnpDataPath);
    } else {
      const dataLocation = ppath.relative(ppath.dirname(pnpPath), pnpDataPath);
      const {dataFile, loaderFile} = generateSplitScript({...pnpSettings, dataLocation});

      await xfs.changeFilePromise(pnpPath, loaderFile);
      await xfs.chmodPromise(pnpPath, 0o755);

      await xfs.changeFilePromise(pnpDataPath, dataFile);
      await xfs.chmodPromise(pnpDataPath, 0o644);
    }
github yarnpkg / berry / packages / plugin-pnp / sources / PnpLinker.ts View on Github external
fallbackExclusionList,
      ignorePattern,
      packageRegistry,
      shebang,
    };

    if (this.opts.project.configuration.get(`pnpEnableInlining`)) {
      const loaderFile = generateInlinedScript(pnpSettings);

      await xfs.changeFilePromise(pnpPath, loaderFile);
      await xfs.chmodPromise(pnpPath, 0o755);

      await xfs.removePromise(pnpDataPath);
    } else {
      const dataLocation = ppath.relative(ppath.dirname(pnpPath), pnpDataPath);
      const {dataFile, loaderFile} = generateSplitScript({...pnpSettings, dataLocation});

      await xfs.changeFilePromise(pnpPath, loaderFile);
      await xfs.chmodPromise(pnpPath, 0o755);

      await xfs.changeFilePromise(pnpDataPath, dataFile);
      await xfs.chmodPromise(pnpDataPath, 0o644);
    }

    const pnpUnpluggedFolder = this.opts.project.configuration.get(`pnpUnpluggedFolder`);
    if (this.unpluggedPaths.size === 0) {
      await xfs.removePromise(pnpUnpluggedFolder);
    } else {
      for (const entry of await xfs.readdirPromise(pnpUnpluggedFolder)) {
        const unpluggedPath = ppath.resolve(pnpUnpluggedFolder, entry);
        if (!this.unpluggedPaths.has(unpluggedPath)) {
          await xfs.removePromise(unpluggedPath);
github yarnpkg / berry / packages / plugin-node-modules / sources / NodeModulesLinker.ts View on Github external
const baseFs = new ZipOpenFS({
      baseFs: nodeFs,
      maxOpenFiles: 80,
      readOnlyArchives: true,
    });
    const defaultFsLayer: FakeFS = new VirtualFS({baseFs});

    const rootPath = this.opts.project.cwd;
    let prevLocatorMap: NodeModulesLocatorMap;
    try {
      prevLocatorMap = await readLocatorState(ppath.join(rootPath, NODE_MODULES, LOCATOR_STATE_FILE));
    } catch (e) {
      prevLocatorMap = new Map();
    }

    const pnp = makeRuntimeApi(pnpSettings, rootPath, defaultFsLayer);
    const nmTree = buildNodeModulesTree(pnp, {
      optimizeSizeOnDisk: true,
      knownLocatorWeights: new Map(Array.from(prevLocatorMap).map(([key, val]) => [key, val.size])),
      pnpifyFs: false,
    });
    const locatorMap = buildLocatorMap(rootPath, nmTree);
    await persistNodeModules(rootPath, prevLocatorMap, locatorMap, baseFs, this.opts.report);
  }

@yarnpkg/pnp

BSD-2-Clause
Latest version published 1 month ago

Package Health Score

98 / 100
Full package analysis

Similar packages