Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'registry-url' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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;
}
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(
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;
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 =
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}`);
}
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}`
});