How to use the @yarnpkg/fslib.xfs.existsPromise 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-version / sources / commands / version / check.tsx View on Github external
async function fetchRoot(initialCwd: PortablePath) {
  // Note: We can't just use `git rev-parse --show-toplevel`, because on Windows
  // it may return long paths even when the cwd uses short paths, and we have no
  // way to detect it from Node (not even realpath).

  let match: PortablePath | null = null;

  let cwd: PortablePath;
  let nextCwd = initialCwd;
  do {
    cwd = nextCwd;
    if (await xfs.existsPromise(ppath.join(cwd, `.git` as Filename)))
      match = cwd;
    nextCwd = ppath.dirname(cwd);
  } while (match === null && nextCwd !== cwd);

  if (match === null)
    throw new UsageError(`This command can only be run from within a Git repository`);

  return match;
}
github yarnpkg / berry / packages / plugin-version / sources / commands / version / check.ts View on Github external
async function fetchRoot(initialCwd: PortablePath) {
  // Note: We can't just use `git rev-parse --show-toplevel`, because on Windows
  // it may return long paths even when the cwd uses short paths, and we have no
  // way to detect it from Node (not even realpath).

  let match: PortablePath | null = null;

  let cwd: PortablePath;
  let nextCwd = initialCwd;
  do {
    cwd = nextCwd;
    if (await xfs.existsPromise(ppath.join(cwd, `.git` as Filename)))
      match = cwd;
    nextCwd = ppath.dirname(cwd);
  } while (match === null && nextCwd !== cwd);

  if (match === null)
    throw new UsageError(`This command can only be run from within a Git repository`);

  return match;
}
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 {
    parsedLeft = parseSyml(left);
github yarnpkg / berry / packages / yarnpkg-core / sources / Cache.ts View on Github external
async setup() {
    if (!this.configuration.get(`enableGlobalCache`)) {
      await xfs.mkdirpPromise(this.cwd);

      const gitignorePath = ppath.resolve(this.cwd, toFilename(`.gitignore`));
      const gitignoreExists = await xfs.existsPromise(gitignorePath);

      if (!gitignoreExists) {
        await xfs.writeFilePromise(gitignorePath, `/.gitignore\n*.lock\n`);
      }
    }
  }
github yarnpkg / berry / packages / plugin-essentials / sources / commands / plugin / import.ts View on Github external
}, async report => {
      const {project} = await Project.find(configuration, this.context.cwd);

      const name = this.name!;
      const candidatePath = ppath.resolve(this.context.cwd, NodeFS.toPortablePath(name));

      let pluginBuffer;

      if (await xfs.existsPromise(candidatePath)) {
        report.reportInfo(MessageName.UNNAMED, `Reading ${configuration.format(candidatePath, `green`)}`);
        pluginBuffer = await xfs.readFilePromise(candidatePath);
      } else {
        const ident = structUtils.tryParseIdent(name);

        let pluginUrl;
        if (ident) {
          const key = structUtils.stringifyIdent(ident);
          const data = await getAvailablePlugins(configuration);

          if (!Object.prototype.hasOwnProperty.call(data, key))
            throw new ReportError(MessageName.PLUGIN_NAME_NOT_FOUND, `Couldn't find a plugin named "${key}" on the remote registry. Note that only the plugins referenced on our website (https://github.com/yarnpkg/berry/blob/master/plugins.yml) can be referenced by their name; any other plugin will have to be referenced through its public url (for example https://github.com/yarnpkg/berry/raw/master/packages/plugin-typescript/bin/%40yarnpkg/plugin-typescript.js).`);

          pluginUrl = data[key].url;
        } else {
          try {