How to use registry-url - 6 common examples

To help you get started, we’ve selected a few registry-url 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 intuit / auto / plugins / npm / src / set-npm-token.ts View on Github external
const rc = path.join(userHome, '.npmrc');
  let contents = '';

  try {
    contents = (await readFile(rc)).toString();
  } catch (error) {
    // No ~/.npmrc set up
  }

  let registry;

  if (publishConfig.registry) {
    registry = publishConfig.registry;
  } else if (name?.startsWith('@')) {
    const scope = name.split(`/`)[0];
    registry = registryUrl(scope);
  } else {
    registry = registryUrl();
  }

  logger.verbose.note(`Using ${registry} registry for package`);

  const url = registry.replace(/^https?:/, ``);
  // eslint-disable-next-line no-template-curly-in-string
  const authTokenString = urlJoin(url, ':_authToken=${NPM_TOKEN}');

  logger.verbose.info(`Will set authentication token string in ${rc}`);

  if (contents.indexOf(authTokenString) !== -1) {
    logger.verbose.success(`npmrc file, ${rc}, is already setup correctly`);
    return;
  }
github intuit / auto / plugins / npm / src / set-npm-token.ts View on Github external
try {
    contents = (await readFile(rc)).toString();
  } catch (error) {
    // No ~/.npmrc set up
  }

  let registry;

  if (publishConfig.registry) {
    registry = publishConfig.registry;
  } else if (name?.startsWith('@')) {
    const scope = name.split(`/`)[0];
    registry = registryUrl(scope);
  } else {
    registry = registryUrl();
  }

  logger.verbose.note(`Using ${registry} registry for package`);

  const url = registry.replace(/^https?:/, ``);
  // eslint-disable-next-line no-template-curly-in-string
  const authTokenString = urlJoin(url, ':_authToken=${NPM_TOKEN}');

  logger.verbose.info(`Will set authentication token string in ${rc}`);

  if (contents.indexOf(authTokenString) !== -1) {
    logger.verbose.success(`npmrc file, ${rc}, is already setup correctly`);
    return;
  }

  logger.verbose.info(
github Autodesk / hig / packages / vanilla / scripts / validate-version / fetchPublishedVersion.js View on Github external
import registryUrl from 'registry-url';
import fetch from 'node-fetch';
import url from 'url';
import localPackageJson from '../../package.json';

const remotePackageUrl = url.resolve(registryUrl(), localPackageJson.name);

// Get the package.json version published to NPM
async function fetchPublishedVersion() {
  return fetch(remotePackageUrl)
    .then(res => res.json())
    .then(pkg => pkg['dist-tags'].latest);
}

export default fetchPublishedVersion;
github zeit / hyper / cli / api.ts View on Github external
import fs from 'fs';
import os from 'os';
import got from 'got';
import registryUrlModule from 'registry-url';
const registryUrl = registryUrlModule();
import pify from 'pify';
import * as recast from 'recast';
import path from 'path';

// If the user defines XDG_CONFIG_HOME they definitely want their config there,
// otherwise use the home directory in linux/mac and userdata in windows
const applicationDirectory =
  process.env.XDG_CONFIG_HOME !== undefined
    ? path.join(process.env.XDG_CONFIG_HOME, 'hyper')
    : process.platform == 'win32'
    ? path.join(process.env.APPDATA!, 'Hyper')
    : os.homedir();

const devConfigFileName = path.join(__dirname, `../.hyper.js`);

const fileName =
github intuit / auto / src / utils / github-token.ts View on Github external
import fs from 'fs';
import path from 'path';
import registryUrl from 'registry-url';
import { promisify } from 'util';
import settingsUrl from './settings-url';

const readFile = promisify(fs.readFile);
const registry = registryUrl();
// tslint:disable-next-line
const normalizedRegistry = registry.replace('http:', '').replace('https:', '');

export default async function getGitHubToken(
  apiUrl = 'https://api.github.com'
): Promise {
  if (process.env.GH_TOKEN) {
    return process.env.GH_TOKEN;
  }

  const helpText = `Try setting an access token up ${settingsUrl(apiUrl)}`;

  if (!process.env.HOME) {
    throw new Error(`Can't find the GH_TOKEN and no HOME defined. ${helpText}`);
  }
github cncjs / cncjs / src / server / api / api.version.js View on Github external
export const getLatestVersion = (req, res) => {
    const scope = pkgName.split('/')[0];
    const regUrl = registryUrl(scope);
    const pkgUrl = url.resolve(regUrl, encodeURIComponent(pkgName).replace(/^%40/, '@'));
    const authInfo = registryAuthToken(regUrl);
    const headers = {};

    if (authInfo) {
        headers.Authorization = `${authInfo.type} ${authInfo.token}`;
    }

    request
        .get(pkgUrl)
        .set(headers)
        .end((err, _res) => {
            if (err) {
                res.status(ERR_INTERNAL_SERVER_ERROR).send({
                    msg: `Failed to connect to ${pkgUrl}: code=${err.code}`
                });

registry-url

Get the set npm registry URL

MIT
Latest version published 2 years ago

Package Health Score

70 / 100
Full package analysis

Popular registry-url functions