How to use @yarnpkg/plugin-npm - 10 common examples

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

    const report = await StreamReport.start({
      configuration,
      stdout: this.context.stdout,
    }, async report => {
      // Not an error if --tolerate-republish is set
      if (this.tolerateRepublish) {
        try {
          const registryData = await npmHttpUtils.get(npmHttpUtils.getIdentUrl(ident), {
            configuration,
            registry,
            ident,
            json: true,
          });

          if (!Object.prototype.hasOwnProperty.call(registryData, `versions`))
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, {
github yarnpkg / berry / packages / plugin-npm-cli / sources / commands / npm / login.ts View on Github external
// @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-npm-cli / sources / commands / npm / login.ts View on Github external
}, 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,
        });

        // @ts-ignore
        await setAuthToken(registry, response.token, {configuration});

        return report.reportInfo(MessageName.UNNAMED, `Successfully logged in`);
      } catch (error) {
        return report.reportError(MessageName.AUTHENTICATION_INVALID, `Invalid Authentication`);
      }
    });
github yarnpkg / berry / packages / plugin-npm-cli / sources / commands / npm / publish.ts View on Github external
}, async report => {
      // Not an error if --tolerate-republish is set
      if (this.tolerateRepublish) {
        try {
          const registryData = await npmHttpUtils.get(npmHttpUtils.getIdentUrl(ident), {
            configuration,
            registry,
            ident,
            json: true,
          });

          if (!Object.prototype.hasOwnProperty.call(registryData, `versions`))
            throw new ReportError(MessageName.REMOTE_INVALID, `Registry returned invalid data for - missing "versions" field`);

          if (Object.prototype.hasOwnProperty.call(registryData.versions, version)) {
            report.reportWarning(MessageName.UNNAMED, `Registry already knows about version ${version}; skipping.`);
            return;
          }
        } catch (error) {
          if (error.name !== `HTTPError`) {
            throw error;
github yarnpkg / berry / packages / plugin-npm-cli / sources / commands / npm / login.ts View on Github external
}, 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,
        });

        // @ts-ignore
        await setAuthToken(registry, response.token, {configuration});

        return report.reportInfo(MessageName.UNNAMED, `Successfully logged in`);
      } catch (error) {
        return report.reportError(MessageName.AUTHENTICATION_INVALID, `Invalid Authentication`);
      }
    });
github yarnpkg / berry / packages / plugin-npm-cli / sources / commands / npm / whoami.ts View on Github external
async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);

    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 => {
      try {
        const response = await npmHttpUtils.get(`/-/whoami`, {
          configuration,
          registry,
          authType: npmHttpUtils.AuthType.ALWAYS_AUTH,
          json: true,
        });

        report.reportInfo(MessageName.UNNAMED, response.username);
github yarnpkg / berry / packages / plugin-npm-cli / sources / commands / npm / whoami.ts View on Github external
async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);

    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 => {
      try {
        const response = await npmHttpUtils.get(`/-/whoami`, {
          configuration,
          registry,
          authType: npmHttpUtils.AuthType.ALWAYS_AUTH,
github yarnpkg / berry / packages / plugin-npm-cli / sources / commands / npm / whoami.ts View on Github external
async execute() {
    const configuration = await Configuration.find(this.context.cwd, this.context.plugins);

    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 => {
      try {
        const response = await npmHttpUtils.get(`/-/whoami`, {
          configuration,
          registry,
          authType: npmHttpUtils.AuthType.ALWAYS_AUTH,
          json: true,
        });

        report.reportInfo(MessageName.UNNAMED, response.username);
      } catch (err) {
        if (err.name !== `HTTPError`) {