How to use the @yarnpkg/core.Project.find function in @yarnpkg/core

To help you get started, we’ve selected a few @yarnpkg/core 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-essentials / sources / commands / add.ts View on Github external
async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {project, workspace} = await Project.find(configuration, this.context.cwd);
    const cache = await Cache.find(configuration);

    if (!workspace)
      throw new WorkspaceRequiredError(this.context.cwd);

    // @ts-ignore
    const prompt = inquirer.createPromptModule({
      input: this.context.stdin,
      output: this.context.stdout,
    });

    const modifier = this.exact
      ? suggestUtils.Modifier.EXACT
      : this.tilde
        ? suggestUtils.Modifier.TILDE
        : suggestUtils.Modifier.CARET;
github yarnpkg / berry / packages / plugin-essentials / sources / commands / up.ts View on Github external
async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {project, workspace} = await Project.find(configuration, this.context.cwd);
    const cache = await Cache.find(configuration);

    if (!workspace)
      throw new WorkspaceRequiredError(this.context.cwd);

    // @ts-ignore
    const prompt = inquirer.createPromptModule({
      input: this.context.stdin,
      output: this.context.stdout,
    });

    const modifier = this.exact
      ? suggestUtils.Modifier.EXACT
      : this.tilde
        ? suggestUtils.Modifier.TILDE
        : suggestUtils.Modifier.CARET;
github yarnpkg / berry / packages / plugin-essentials / sources / commands / runIndex.ts View on Github external
async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {workspace} = await Project.find(configuration, this.context.cwd);

    if (!workspace)
      throw new WorkspaceRequiredError(this.context.cwd);

    const report = await StreamReport.start({
      configuration,
      stdout: this.context.stdout,
    }, async report => {
      const scripts = workspace!.manifest.scripts;
      const keys = miscUtils.sortMap(scripts.keys(), key => key);
      const inspectConfig = {
        breakLength: Infinity,
        colors: configuration.get(`enableColors`),
        maxArrayLength: 2,
      };
github yarnpkg / berry / packages / plugin-essentials / sources / commands / set / version.ts View on Github external
async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {project} = await Project.find(configuration, this.context.cwd);

    const report = await StreamReport.start({
      configuration,
      stdout: this.context.stdout,
    }, async (report: StreamReport) => {
      if (this.range === `latest`)
        this.range = `*`;

      let candidates: Array = [];

      let bundleUrl: string;
      let bundleVersion: string;

      if (BERRY_RANGES.has(this.range)) {
        bundleUrl = `https://github.com/yarnpkg/berry/raw/master/packages/yarnpkg-cli/bin/yarn.js`;
        bundleVersion = `rc`;
github yarnpkg / berry / packages / plugin-essentials / sources / commands / node.ts View on Github external
async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {project} = await Project.find(configuration, this.context.cwd);

    const {code} = await execUtils.pipevp(`node`, this.args, {
      cwd: this.context.cwd,
      stdin: this.context.stdin,
      stdout: this.context.stdout,
      stderr: this.context.stderr,
      env: await scriptUtils.makeScriptEnv(project),
    });

    return code;
  }
}
github yarnpkg / berry / packages / plugin-essentials / sources / commands / why.ts View on Github external
async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {project, workspace} = await Project.find(configuration, this.context.cwd);

    if (!workspace)
      throw new WorkspaceRequiredError(this.context.cwd);

    const identHash = structUtils.parseIdent(this.package).identHash;

    const whyTree = this.recursive
      ? whyRecursive(project, identHash, {configuration, peers: this.peers})
      : whySimple(project, identHash, {configuration, peers: this.peers});

    printTree(this.context.stdout, whyTree);
  }
}
github yarnpkg / berry / packages / plugin-dlx / sources / commands / dlx.ts View on Github external
const pkgs = typeof this.pkg !== `undefined`
        ? [this.pkg]
        : [this.command];

      const command = structUtils.parseDescriptor(this.command).name;

      const addExitCode = await this.cli.run([`add`, `--`, ...pkgs], {cwd: tmpDir, quiet: this.quiet});
      if (addExitCode !== 0)
        return addExitCode;

      if (!this.quiet)
        this.context.stdout.write(`\n`);

      const configuration = await Configuration.find(tmpDir, this.context.plugins);
      const {workspace} = await Project.find(configuration, tmpDir);

      if (workspace === null)
        throw new WorkspaceRequiredError(tmpDir);

      return await scriptUtils.executeWorkspaceAccessibleBinary(workspace, command, this.args, {
        cwd: this.context.cwd,
        stdin: this.context.stdin,
        stdout: this.context.stdout,
        stderr: this.context.stderr,
      });
    } finally {
      await xfs.removePromise(tmpDir);
    }
  }
}
github yarnpkg / berry / packages / plugin-version / sources / commands / version / check.tsx View on Github external
async executeInteractive() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {project, workspace} = await Project.find(configuration, this.context.cwd);

    if (!workspace)
      throw new WorkspaceRequiredError(this.context.cwd);

    await project.resolveEverything({
      lockfileOnly: true,
      report: new ThrowReport(),
    });

    const root = await fetchRoot(this.context.cwd);
    const base = await fetchBase(root);

    const files = await fetchChangedFiles(root, {base: base.hash});
    const workspaces = [...new Set(files.map(file => project.getWorkspaceByFilePath(file)))];
    if (workspaces.length === 0)
      return;
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);
github yarnpkg / berry / packages / plugin-constraints / sources / commands / constraints.ts View on Github external
async execute() {
    for (let t = 0; t < 10; ++t) {
      const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
      const {project} = await Project.find(configuration, this.context.cwd);
      const constraints = await Constraints.find(project);

      const toSave = new Set();

      const report = await StreamReport.start({
        configuration,
        stdout: this.context.stdout,
      }, async report => {
        const result = await constraints.process();

        await processDependencyConstraints(toSave, result.enforcedDependencies, {
          fix: this.fix,
          configuration,
          report,
        });