How to use the @yarnpkg/fslib.xfs.existsSync 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-cli / sources / main.ts View on Github external
async function exec(cli: Cli): Promise {
    // Since we only care about a few very specific settings (yarn-path and ignore-path) we tolerate extra configuration key.
    // If we didn't, we wouldn't even be able to run `yarn config` (which is recommended in the invalid config error message)
    const configuration = await Configuration.find(npath.toPortablePath(process.cwd()), pluginConfiguration, {
      strict: false,
    });

    const yarnPath: PortablePath = configuration.get(`yarnPath`);
    const ignorePath = configuration.get(`ignorePath`);

    if (yarnPath !== null && !ignorePath) {
      if (!xfs.existsSync(yarnPath)) {
        process.stdout.write(cli.error(new Error(`The "yarn-path" option has been set (in ${configuration.sources.get(`yarnPath`)}), but the specified location doesn't exist (${yarnPath}).`)));
        process.exitCode = 1;
      } else {
        try {
          runBinary(yarnPath);
        } catch (error) {
          process.exitCode = error.code || 1;
        }
      }
    } else {
      if (ignorePath)
        delete process.env.YARN_IGNORE_PATH;

      for (const plugin of configuration.plugins.values())
        for (const command of plugin.commands || [])
          cli.register(command);
github yarnpkg / berry / packages / yarnpkg-core / sources / Project.ts View on Github external
private async setupResolutions() {
    this.storedResolutions = new Map();

    this.storedDescriptors = new Map();
    this.storedPackages = new Map();

    const lockfilePath = ppath.join(this.cwd, this.configuration.get(`lockfileFilename`));
    const defaultLanguageName = this.configuration.get(`defaultLanguageName`);

    if (xfs.existsSync(lockfilePath)) {
      const content = await xfs.readFilePromise(lockfilePath, `utf8`);
      const parsed: any = parseSyml(content);

      // Protects against v1 lockfiles
      if (parsed.__metadata) {
        const lockfileVersion = parsed.__metadata.version;

        for (const key of Object.keys(parsed)) {
          if (key === `__metadata`)
            continue;

          const data = parsed[key];
          const locator = structUtils.parseLocator(data.resolution, true);

          const manifest = new Manifest();
          manifest.load(data);
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;
  }
github yarnpkg / berry / packages / plugin-init / sources / commands / init.ts View on Github external
async executeProxy(configuration: Configuration) {
    if (configuration.get(`yarnPath`) !== null)
      throw new UsageError(`Cannot use the --install flag when the current directory already uses yarnPath (from ${configuration.sources.get(`yarnPath`)})`);

    if (configuration.projectCwd !== null)
      throw new UsageError(`Cannot use the --install flag when the current directory is already part of a project`);

    if (!xfs.existsSync(this.context.cwd))
      await xfs.mkdirpPromise(this.context.cwd);

    const lockfilePath = ppath.join(this.context.cwd, configuration.get(`lockfileFilename`));
    if (!xfs.existsSync(lockfilePath))
      await xfs.writeFilePromise(lockfilePath, ``);

    const versionExitCode = await this.cli.run([`set`, `version`, this.install!]);
    if (versionExitCode !== 0)
      return versionExitCode;

    this.context.stdout.write(`\n`);

    const args: Array = [];
    if (this.private)
      args.push(`-p`);
    if (this.yes)
      args.push(`-y`);

    const {code} = await execUtils.pipevp(`yarn`, [`init`, ...args], {
      cwd: this.context.cwd,
github yarnpkg / berry / packages / plugin-init / sources / commands / init.ts View on Github external
async executeRegular(configuration: Configuration) {
    if (!xfs.existsSync(this.context.cwd))
      await xfs.mkdirpPromise(this.context.cwd);

    const manifest = new Manifest();
    manifest.name = structUtils.makeIdent(configuration.get(`initScope`), ppath.basename(this.context.cwd));
    manifest.version = configuration.get(`initVersion`);
    manifest.private = this.private;
    manifest.license = configuration.get(`initLicense`);

    await updateAndSave(ppath.join(this.context.cwd, Manifest.fileName), (tracker: Object) => {
      manifest.exportTo(tracker);
    });

    const inspectable: any = {};
    manifest.exportTo(inspectable);

    this.context.stdout.write(`${inspect(inspectable, {
github yarnpkg / berry / packages / plugin-essentials / sources / commands / set / version / sources.ts View on Github external
try {
              await execUtils.execvp(fileName, args, {
                cwd: target,
                strict: true,
              });
            } catch (error) {
              this.context.stdout.write(error.stdout || error.stack);
              throw error;
            }
          }
        }
      };

      let ready = false;

      if (!this.force && xfs.existsSync(ppath.join(target, `.git` as Filename))) {
        report.reportInfo(MessageName.UNNAMED, `Fetching the latest commits`);
        report.reportSeparator();

        try {
          await runWorkflow(UPDATE_WORKFLOW(this));
          ready = true;
        } catch (error) {
          report.reportSeparator();
          report.reportWarning(MessageName.UNNAMED, `Repository update failed; we'll try to regenerate it`);
        }
      }

      if (!ready) {
        report.reportInfo(MessageName.UNNAMED, `Cloning the remote repository`);
        report.reportSeparator();
github yarnpkg / berry / packages / plugin-init / sources / commands / init.ts View on Github external
async execute() {
    if (xfs.existsSync(ppath.join(this.context.cwd, Manifest.fileName)))
      throw new UsageError(`A package.json already exists in the specified directory`);

    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);

    if (typeof this.install !== `undefined`) {
      return await this.executeProxy(configuration);
    } else {
      return await this.executeRegular(configuration);
    }
  }
github yarnpkg / berry / packages / plugin-pnp / sources / PnpLinker.ts View on Github external
async findPackageLocation(locator: Locator, opts: LinkOptions) {
    const pnpPath = getPnpPath(opts.project);
    if (!xfs.existsSync(pnpPath))
      throw new UsageError(`The project in ${opts.project.cwd}/package.json doesn't seem to have been installed - running an install there might help`);

    const pnpFile = miscUtils.dynamicRequireNoCache(pnpPath);

    const packageLocator = {name: structUtils.requirableIdent(locator), reference: locator.reference};
    const packageInformation = pnpFile.getPackageInformation(packageLocator);

    if (!packageInformation)
      throw new UsageError(`Couldn't find ${structUtils.prettyLocator(opts.project.configuration, locator)} in the currently installed PnP map - running an install might help`);

    return npath.toPortablePath(packageInformation.packageLocation);
  }
github yarnpkg / berry / packages / plugin-constraints / sources / Constraints.ts View on Github external
constructor(project: Project) {
    this.project = project;

    if (xfs.existsSync(ppath.join(project.cwd, toFilename(`constraints.pro`)))) {
      this.source = xfs.readFileSync(ppath.join(project.cwd, toFilename(`constraints.pro`)), `utf8`);
    }
  }