How to use the @yarnpkg/fslib.ppath.join function in @yarnpkg/fslib

To help you get started, we’ve selected a few @yarnpkg/fslib 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 / yarnpkg-pnp / sources / loader / makeApi.ts View on Github external
function callNativeResolution(request: PortablePath, issuer: PortablePath): NativePath | false {
    if (issuer.endsWith(`/`))
      issuer = ppath.join(issuer, toFilename(`internal.js`));

    // Since we would need to create a fake module anyway (to call _resolveLookupPath that
    // would give us the paths to give to _resolveFilename), we can as well not use
    // the {paths} option at all, since it internally makes _resolveFilename create another
    // fake module anyway.
    return Module._resolveFilename(request, makeFakeModule(npath.fromPortablePath(issuer)), false, {plugnplay: false});
  }
github yarnpkg / berry / packages / plugin-node-modules / sources / NodeModulesLinker.ts View on Github external
}
      }
    }
  }

  // Add new locations
  for (const [locator, {locations}] of locatorMap.entries()) {
    for (const location of locations) {
      const {locationRoot, segments} = parseLocation(location);
      let prevTreeNode = prevLocationTree.get(locationRoot);
      let node = locationTree.get(locationRoot);
      let curLocation = locationRoot;

      const info = locatorMap.get(locator)!;
      const srcDir = info.target;
      const dstDir = ppath.join(rootPath, location);
      const linkType = info.linkType;

      for (const segment of segments)
        node = node!.children.get(segment);

      if (!prevTreeNode) {
        addList.push({srcDir, dstDir, linkType, keepNodeModules: node!.children.size > 0});
      } else {
        for (const segment of segments) {
          curLocation = ppath.join(curLocation, segment);
          prevTreeNode = prevTreeNode.children.get(segment);
          if (!prevTreeNode) {
            addList.push({srcDir, dstDir, linkType, keepNodeModules: node!.children.size > 0});
            break;
          }
        }
github yarnpkg / berry / packages / plugin-node-modules / sources / NodeModulesLinker.ts View on Github external
const persistNodeModules = async (rootPath: PortablePath, prevLocatorMap: NodeModulesLocatorMap, locatorMap: NodeModulesLocatorMap, baseFs: FakeFS, report: Report) => {
  const rootNmDirPath = ppath.join(rootPath, NODE_MODULES);
  const locatorStatePath = ppath.join(rootNmDirPath, LOCATOR_STATE_FILE);

  const prevLocationTree = buildLocationTree(prevLocatorMap);
  const locationTree = buildLocationTree(locatorMap);

  const addQueue: Promise[] = [];
  const addModule = async ({srcDir, dstDir, linkType, keepNodeModules}: {srcDir: PortablePath, dstDir: PortablePath, linkType: LinkType, keepNodeModules: boolean}) => {
    const promise: Promise = (async () => {
      try {
        await removeDir(dstDir, {excludeNodeModules: keepNodeModules});
        if (linkType === LinkType.SOFT) {
          await xfs.mkdirpPromise(ppath.dirname(dstDir));
          await xfs.symlinkPromise(srcDir, dstDir);
        } else {
          const archivePath = getArchivePath(srcDir);
          if (archivePath) {
            const prefixInsideArchive = srcDir.substring(archivePath.length);
github yarnpkg / berry / packages / yarnpkg-core / sources / Configuration.ts View on Github external
static async findProjectCwd(startingCwd: PortablePath, lockfileFilename: Filename | null) {
    let projectCwd = null;

    let nextCwd = startingCwd;
    let currentCwd = null;

    while (nextCwd !== currentCwd) {
      currentCwd = nextCwd;

      if (xfs.existsSync(ppath.join(currentCwd, toFilename(`package.json`))))
        projectCwd = currentCwd;

      if (lockfileFilename !== null) {
        if (xfs.existsSync(ppath.join(currentCwd, lockfileFilename))) {
          projectCwd = currentCwd;
          break;
        }
      } else {
        if (projectCwd !== null) {
          break;
        }
      }

      nextCwd = ppath.dirname(currentCwd);
    }

    return projectCwd;
  }
github yarnpkg / berry / packages / plugin-essentials / sources / commands / install.ts View on Github external
async function autofixMergeConflicts(configuration: Configuration, immutable: boolean) {
  if (!configuration.projectCwd)
    return false;

  const lockfilePath = ppath.join(configuration.projectCwd, configuration.get(`lockfileFilename`));
  if (!await xfs.existsPromise(lockfilePath))
    return false;

  const file = await xfs.readFilePromise(lockfilePath, `utf8`);
  if (!file.includes(MERGE_CONFLICT_START))
    return false;

  if (immutable)
    throw new ReportError(MessageName.AUTOMERGE_IMMUTABLE, `Cannot autofix a lockfile when running an immutable install`);

  const [left, right] = getVariants(file);

  let parsedLeft;
  let parsedRight;

  try {
github yarnpkg / berry / packages / yarnpkg-check / sources / cli.ts View on Github external
async function checkForUnmetPeerDependency(workspace: Workspace, dependencyType: HardDependencies, via: Descriptor, peer: Descriptor, {configuration, report}: {configuration: Configuration, report: Report}) {
  if (dependencyType === `dependencies` && workspace.manifest.hasConsumerDependency(peer))
    return;
  if (dependencyType === `devDependencies` && workspace.manifest.hasHardDependency(peer))
    return;

  const propertyNode = await buildJsonNode(ppath.join(workspace.cwd, Manifest.fileName), [dependencyType, structUtils.stringifyIdent(via)]);
  const prettyLocation = ast.prettyNodeLocation(configuration, propertyNode);

  report.reportError(MessageName.UNNAMED, `${prettyLocation}: Unmet transitive peer dependency on ${structUtils.prettyDescriptor(configuration, peer)}, via ${structUtils.prettyDescriptor(configuration, via)}`);
}
github yarnpkg / berry / packages / plugin-patch / sources / patchUtils.ts View on Github external
export async function extractPackageToDisk(locator: Locator, {cache, project}: {cache: Cache, project: Project}) {
  const checksums = project.storedChecksums;
  const report = new ThrowReport();

  const fetcher = project.configuration.makeFetcher();
  const fetchResult = await fetcher.fetch(locator, {cache, project, fetcher, checksums, report});

  const temp = await xfs.mktempPromise();
  await xfs.copyPromise(temp, fetchResult.prefixPath, {
    baseFs: fetchResult.packageFs,
  });

  await xfs.writeJsonPromise(ppath.join(temp, `.yarn-patch.json` as Filename), {
    locator: structUtils.stringifyLocator(locator),
  });

  return temp;
}
github yarnpkg / berry / packages / yarnpkg-pnpify / sources / generateSdk.ts View on Github external
export const generateEslintWrapper = async (projectRoot: PortablePath, target: PortablePath) => {
  const eslint = ppath.join(target, `eslint` as PortablePath);
  const manifest = ppath.join(eslint, `package.json` as PortablePath);
  const api = ppath.join(eslint, `lib/api.js` as PortablePath);

  const relPnpApiPath = ppath.relative(ppath.dirname(api), ppath.join(projectRoot, `.pnp.js` as Filename));

  await xfs.mkdirpPromise(ppath.dirname(api));
  await xfs.writeFilePromise(manifest, JSON.stringify({name: 'eslint', version: `${dynamicRequire('eslint/package.json').version}-pnpify`, main: 'lib/api.js'}, null, 2));
  await xfs.writeFilePromise(api, TEMPLATE(relPnpApiPath, "eslint", {usePnpify: false}));

  await addVSCodeWorkspaceSettings(projectRoot, {'eslint.nodePath': npath.fromPortablePath(ppath.relative(projectRoot, ppath.dirname(eslint)))});
};