How to use @yarnpkg/cli - 10 common examples

To help you get started, we’ve selected a few @yarnpkg/cli 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-npm-cli / sources / commands / npm / publish.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);

    if (workspace.manifest.private)
      throw new UsageError(`Private workspaces cannot be published`);
    if (workspace.manifest.name === null || workspace.manifest.version === null)
      throw new UsageError(`Workspaces must have valid names and versions to be published on an external registry`);

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

    // We store it so that TS knows that it's non-null
    const ident = workspace.manifest.name;
    const version = workspace.manifest.version;

    const registry = npmConfigUtils.getPublishRegistry(workspace.manifest, {configuration});
github yarnpkg / berry / packages / plugin-essentials / sources / commands / install.ts View on Github external
}, async report => {
        if (await autofixMergeConflicts(configuration, immutable)) {
          report.reportInfo(MessageName.AUTOMERGE_SUCCESS, `Automatically fixed merge conflicts 👍`);
        }
      });

      if (fixReport.hasErrors()) {
        return fixReport.exitCode();
      }
    }

    const {project, workspace} = await Project.find(configuration, this.context.cwd);
    const cache = await Cache.find(configuration, {immutable: this.immutableCache, check: this.checkCache});

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

    // Important: Because other commands also need to run installs, if you
    // get in a situation where you need to change this file in order to
    // customize the install it's very likely you're doing something wrong.
    // This file should stay super super simple, and the configuration and
    // install logic should be implemented elsewhere (probably in either of
    // the Configuration and Install classes). Feel free to open an issue
    // in order to ask for design feedback before writing features.

    const report = await StreamReport.start({
      configuration,
      json: this.json,
      stdout: this.context.stdout,
      includeLogs: true,
    }, async (report: StreamReport) => {
      await project.install({cache, report, immutable});
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;

    const strategies = this.interactive ? [
      suggestUtils.Strategy.KEEP,
      suggestUtils.Strategy.REUSE,
github yarnpkg / berry / packages / plugin-npm-cli / sources / commands / npm / login.ts View on Github external
async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);

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

    let registry: string;
    if (this.scope && this.publish)
      registry = npmConfigUtils.getScopeRegistry(this.scope, {configuration, type: npmConfigUtils.RegistryType.PUBLISH_REGISTRY});
    else if (this.scope)
      registry = npmConfigUtils.getScopeRegistry(this.scope, {configuration});
    else if (this.publish)
      registry = npmConfigUtils.getPublishRegistry((await openWorkspace(configuration, this.context.cwd)).manifest, {configuration});
    else
      registry = npmConfigUtils.getDefaultRegistry({configuration});

    const report = await StreamReport.start({
      configuration,
      stdout: this.context.stdout,
    }, async report => {
      const credentials = await getCredentials(prompt);
      const url = `/-/user/org.couchdb.user:${encodeURIComponent(credentials.name)}`;

      try {
        const response = await npmHttpUtils.put(url, credentials, {
          configuration,
          registry,
          json: true,
          authType: npmHttpUtils.AuthType.NO_AUTH,
github yarnpkg / berry / packages / plugin-essentials / sources / commands / link.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);

    const absoluteDestination = ppath.resolve(this.context.cwd, NodeFS.toPortablePath(this.destination));

    const configuration2 = await Configuration.find(absoluteDestination, this.context.plugins);
    const {project: project2, workspace: workspace2} = await Project.find(configuration2, absoluteDestination);

    if (!workspace2)
      throw new WorkspaceRequiredError(absoluteDestination);

    const topLevelWorkspace = project.topLevelWorkspace;
    const linkedWorkspaces = [];

    if (this.all) {
      for (const workspace of project2.workspaces)
        if (workspace.manifest.name && (!workspace.manifest.private || this.private))
          linkedWorkspaces.push(workspace);

      if (linkedWorkspaces.length === 0) {
        throw new UsageError(`No workspace found to be linked in the target project`);
      }
    } else {
      if (!workspace2.manifest.name)
        throw new UsageError(`The target workspace doesn't have a name and thus cannot be linked`);
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;

    const status = await fetchWorkspacesStatus(workspaces, {root, base: base.hash});
    if (status.undecided.length === 0)
github yarnpkg / berry / packages / plugin-workspace-tools / sources / commands / foreach.ts View on Github external
async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
    const {project, workspace: cwdWorkspace} = await Project.find(configuration, this.context.cwd);

    if (!this.all && !cwdWorkspace)
      throw new WorkspaceRequiredError(this.context.cwd);

    const command = this.cli.process([this.commandName, ...this.args]) as {path: string[], scriptName?: string};
    const scriptName = command.path.length === 1 && command.path[0] === `run` && typeof command.scriptName !== `undefined`
      ? command.scriptName
      : null;

    if (command.path.length === 0)
      throw new UsageError(`Invalid subcommand name for iteration - use the 'run' keyword if you wish to execute a script`);

    const rootWorkspace = this.all
      ? project.topLevelWorkspace
      : cwdWorkspace!;

    const candidates = [rootWorkspace, ...getWorkspaceChildrenRecursive(rootWorkspace, project)];
    const workspaces: Array = [];
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,
      };

      const maxKeyLength = keys.reduce((max, key) => {
        return Math.max(max, key.length);
      }, 0);
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-pnp / sources / commands / unplug.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);

    const topLevelWorkspace = project.topLevelWorkspace;

    for (const pattern of this.patterns) {
      const descriptor = structUtils.parseDescriptor(pattern);
      const dependencyMeta = topLevelWorkspace.manifest.ensureDependencyMeta(descriptor);

      dependencyMeta.unplugged = true;0;
    }

    await topLevelWorkspace.persistManifest();

    const report = await StreamReport.start({
      configuration,
      stdout: this.context.stdout,
    }, async report => {

@yarnpkg/cli

BSD-2-Clause
Latest version published 14 days ago

Package Health Score

89 / 100
Full package analysis

Similar packages