How to use the @yarnpkg/fslib.PortablePath.root 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 / plugin-exec / sources / ExecFetcher.ts View on Github external
private async fetchFromDisk(locator: Locator, opts: FetchOptions) {
    const {parentLocator, path} = structUtils.parseFileStyleRange(locator.reference, {protocol: PROTOCOL});

    // If the file target is an absolute path we can directly access it via its
    // location on the disk. Otherwise we must go through the package fs.
    const parentFetch = ppath.isAbsolute(path)
      ? {packageFs: new NodeFS(), prefixPath: PortablePath.root, localPath: PortablePath.root}
      : await opts.fetcher.fetch(parentLocator, opts);

    // If the package fs publicized its "original location" (for example like
    // in the case of "file:" packages), we use it to derive the real location.
    const effectiveParentFetch = parentFetch.localPath
      ? {packageFs: new NodeFS(), prefixPath: parentFetch.localPath}
      : parentFetch;

    // Discard the parent fs unless we really need it to access the files
    if (parentFetch !== effectiveParentFetch && parentFetch.releaseFs)
      parentFetch.releaseFs();

    const generatorFs = effectiveParentFetch.packageFs;
    const generatorPath = ppath.resolve(ppath.resolve(generatorFs.getRealPath(), effectiveParentFetch.prefixPath), path);

    // Execute the specified script in the temporary directory
github yarnpkg / berry / packages / acceptance-tests / pkg-tests-core / sources / utils / fs.ts View on Github external
map: header => {
      header.name = NodeFS.toPortablePath(header.name);

      if (true) {
        header.name = ppath.resolve(PortablePath.root, header.name);
        header.name = ppath.relative(PortablePath.root, header.name);
      }

      if (virtualPath) {
        header.name = ppath.resolve(PortablePath.root, virtualPath, header.name);
        header.name = ppath.relative(PortablePath.root, header.name);
      }

      return header;
    },
  });
github yarnpkg / berry / packages / plugin-pack / sources / packUtils.ts View on Github external
: hasGitIgnore
          ? await loadIgnoreList(cwdFs, cwd, toFilename(`.gitignore`))
          : null;

      let nextIgnoreLists = localIgnoreList !== null
        ? [localIgnoreList].concat(ignoreLists)
        : ignoreLists;

      if (isIgnored(cwd, {globalList, ignoreLists}))
        nextIgnoreLists = [...ignoreLists, {accept: [], reject: [`**/*`]}];

      for (const entry of entries) {
        cwdList.push([ppath.resolve(cwd, entry), nextIgnoreLists]);
      }
    } else {
      list.push(ppath.relative(PortablePath.root, cwd));
    }
  }

  return list.sort();
}
github yarnpkg / berry / packages / plugin-pack / sources / packUtils.ts View on Github external
const maybeRejectPath = (path: PortablePath | null) => {
    if (path === null || !path.startsWith(`${workspace.cwd}/`))
      return;

    const workspaceRelativePath = ppath.relative(workspace.cwd, path);
    const workspaceAbsolutePath = ppath.resolve(PortablePath.root, workspaceRelativePath);

    globalList.reject.push(workspaceAbsolutePath);
  };
github yarnpkg / berry / packages / plugin-pnp / sources / PnpLinker.ts View on Github external
if (buildScripts.length > 0 && dependencyMeta && dependencyMeta.built === false) {
      this.opts.report.reportInfoOnce(MessageName.BUILD_DISABLED, `${structUtils.prettyLocator(this.opts.project.configuration, pkg)} lists build scripts, but its build has been explicitly disabled through configuration.`);
      buildScripts.length = 0;
    }

    const hasVirtualInstances =
      pkg.peerDependencies.size > 0 &&
      !structUtils.isVirtualLocator(pkg) &&
      !this.opts.project.tryWorkspaceByLocator(pkg);

    const packageFs = !hasVirtualInstances && pkg.linkType !== LinkType.SOFT && (buildScripts.length > 0 || this.isUnplugged(pkg, dependencyMeta))
      ? await this.unplugPackage(pkg, fetchResult.packageFs)
      : fetchResult.packageFs;

    const packageRawLocation = ppath.resolve(packageFs.getRealPath(), ppath.relative(PortablePath.root, fetchResult.prefixPath));

    const packageLocation = this.normalizeDirectoryPath(packageRawLocation);
    const packageDependencies = new Map();
    const packagePeers = new Set();

    for (const descriptor of pkg.peerDependencies.values()) {
      packageDependencies.set(structUtils.requirableIdent(descriptor), null);
      packagePeers.add(descriptor.name);
    }

    const packageStore = this.getPackageStore(key1);
    packageStore.set(key2, {packageLocation, packageDependencies, packagePeers, linkType: pkg.linkType});

    if (hasVirtualInstances)
      this.blacklistedPaths.add(packageLocation);
github yarnpkg / berry / packages / plugin-pack / sources / packUtils.ts View on Github external
const cwdList: Array<[PortablePath, Array]> = [[PortablePath.root, [ignoreList]]];

  while (cwdList.length > 0) {
    const [cwd, ignoreLists] = cwdList.pop()!;
    const stat = await cwdFs.lstatPromise(cwd);

    if (isIgnored(cwd, {globalList, ignoreLists: stat.isDirectory() ? null : ignoreLists}))
      continue;

    if (stat.isDirectory()) {
      const entries = await cwdFs.readdirPromise(cwd);

      let hasGitIgnore = false;
      let hasNpmIgnore = false;

      if (!hasExplicitFileList || cwd !== PortablePath.root) {
        for (const entry of entries) {
          hasGitIgnore = hasGitIgnore || entry === `.gitignore`;
          hasNpmIgnore = hasNpmIgnore || entry === `.npmignore`;
        }
      }

      const localIgnoreList = hasNpmIgnore
        ? await loadIgnoreList(cwdFs, cwd, toFilename(`.npmignore`))
        : hasGitIgnore
          ? await loadIgnoreList(cwdFs, cwd, toFilename(`.gitignore`))
          : null;

      let nextIgnoreLists = localIgnoreList !== null
        ? [localIgnoreList].concat(ignoreLists)
        : ignoreLists;
github yarnpkg / berry / packages / yarnpkg-core / sources / WorkspaceFetcher.ts View on Github external
async fetch(locator: Locator, opts: FetchOptions) {
    const sourcePath = this.getWorkspace(locator, opts).cwd;

    return {packageFs: new JailFS(sourcePath), prefixPath: PortablePath.root, localPath: sourcePath};
  }
github yarnpkg / berry / packages / yarnpkg-pnp / sources / loader / applyPatch.ts View on Github external
function findApiPathFor(modulePath: NativePath) {
    let curr: PortablePath;
    let next = npath.toPortablePath(modulePath);

    do {
      curr = next;

      const candidate = ppath.join(curr, `.pnp.js` as Filename);
      if (xfs.existsSync(candidate) && xfs.statSync(candidate).isFile())
        return candidate;

      next = ppath.dirname(curr);
    } while (curr !== PortablePath.root);

    return null;
  }