How to use the @yarnpkg/fslib.ppath.relative 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 findPackageLocator(location: PortablePath): PackageLocator | null {
    let relativeLocation = normalizePath(ppath.relative(runtimeState.basePath, location));

    if (!relativeLocation.match(isStrictRegExp))
      relativeLocation = `./${relativeLocation}` as PortablePath;

    if (location.match(isDirRegExp) && !relativeLocation.endsWith(`/`))
      relativeLocation = `${relativeLocation}/` as PortablePath;

    let from = 0;

    // If someone wants to use a binary search to go from O(n) to O(log n), be my guest
    while (from < packageLocationLengths.length && packageLocationLengths[from] > relativeLocation.length)
      from += 1;

    for (let t = from; t < packageLocationLengths.length; ++t) {
      const locator = packageLocatorsByLocations.get(relativeLocation.substr(0, packageLocationLengths[t]) as PortablePath);
      if (typeof locator === `undefined`)
github yarnpkg / berry / packages / plugin-pack / sources / packUtils.ts View on Github external
maybeRejectPath(configuration.get(`bstatePath`));
  maybeRejectPath(configuration.get(`cacheFolder`));
  maybeRejectPath(configuration.get(`globalFolder`));
  maybeRejectPath(configuration.get(`virtualFolder`));
  maybeRejectPath(configuration.get(`yarnPath`));

  await configuration.triggerHook((hooks: StageHooks) => {
    return hooks.populateYarnPaths;
  }, project, (path: PortablePath | null) => {
    maybeRejectPath(path);
  });

  // All child workspaces are ignored
  for (const otherWorkspace of project.workspaces) {
    const rel = ppath.relative(workspace.cwd, otherWorkspace.cwd);
    if (rel !== `` && !rel.match(/^(\.\.)?\//)) {
      globalList.reject.push(`/${rel}`);
    }
  }

  const ignoreList: IgnoreList = {
    accept: [],
    reject: [],
  };

  if (workspace.manifest.publishConfig && workspace.manifest.publishConfig.main)
    ignoreList.accept.push(ppath.resolve(PortablePath.root, workspace.manifest.publishConfig.main));
  else if (workspace.manifest.main)
    ignoreList.accept.push(ppath.resolve(PortablePath.root, workspace.manifest.main));

  if (workspace.manifest.publishConfig && workspace.manifest.publishConfig.module)
github yarnpkg / berry / packages / plugin-node-modules / sources / NodeModulesLinker.ts View on Github external
private normalizeDirectoryPath(folder: PortablePath) {
    let relativeFolder = ppath.relative(this.opts.project.cwd, folder);

    if (!relativeFolder.match(/^\.{0,2}\//))
      // Don't use ppath.join here, it ignores the `.`
      relativeFolder = `./${relativeFolder}` as PortablePath;

    return relativeFolder.replace(/\/?$/, '/')  as PortablePath;
  }
}
github yarnpkg / berry / packages / yarnpkg-core / sources / Workspace.ts View on Github external
async setup() {
    // @ts-ignore: It's ok to initialize it now
    this.manifest = xfs.existsSync(ppath.join(this.cwd, Manifest.fileName))
      ? await Manifest.find(this.cwd)
      : new Manifest();

    // We use ppath.relative to guarantee that the default hash will be consistent even if the project is installed on different OS / path
    // @ts-ignore: It's ok to initialize it now, even if it's readonly (setup is called right after construction)
    this.relativeCwd = ppath.relative(this.project.cwd, this.cwd) || PortablePath.dot;

    const ident = this.manifest.name ? this.manifest.name : structUtils.makeIdent(null, `${this.computeCandidateName()}-${hashUtils.makeHash(this.relativeCwd).substr(0, 6)}`);
    const reference = this.manifest.version ? this.manifest.version : `0.0.0`;

    // @ts-ignore: It's ok to initialize it now, even if it's readonly (setup is called right after construction)
    this.locator = structUtils.makeLocator(ident, reference);

    // @ts-ignore: It's ok to initialize it now, even if it's readonly (setup is called right after construction)
    this.anchoredDescriptor = structUtils.makeDescriptor(this.locator, `${WorkspaceResolver.protocol}${this.relativeCwd}`);

    // @ts-ignore: It's ok to initialize it now, even if it's readonly (setup is called right after construction)
    this.anchoredLocator = structUtils.makeLocator(this.locator, `${WorkspaceResolver.protocol}${this.relativeCwd}`);

    for (const definition of this.manifest.workspaceDefinitions) {
      const relativeCwds = await globby(definition.pattern, {
        absolute: true,
github yarnpkg / berry / packages / plugin-pnp / sources / PnpLinker.ts View on Github external
private normalizeDirectoryPath(folder: PortablePath) {
    let relativeFolder = ppath.relative(this.opts.project.cwd, folder);

    if (!relativeFolder.match(/^\.{0,2}\//))
      // Don't use ppath.join here, it ignores the `.`
      relativeFolder = `./${relativeFolder}` as PortablePath;

    return relativeFolder.replace(/\/?$/, '/')  as PortablePath;
  }
github yarnpkg / berry / packages / plugin-version / sources / commands / version / check.ts View on Github external
async function fetchPreviousNonce(workspace: Workspace, {root, base}: {root: PortablePath, base: string}) {
  const {code, stdout} = await execUtils.execvp(`git`, [`show`, `${base}:${fromPortablePath(ppath.relative(root, ppath.join(workspace.cwd, `package.json` as Filename)))}`], {cwd: workspace.cwd});

  if (code === 0) {
    return getNonce(Manifest.fromText(stdout));
  } else {
    return null;
  }
}
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)))});
};