"ng update" doesn't support private repos such as FontAwesome 5 Pro
Versions
Angular CLI: 6.0.0
Node: 9.11.1
OS: darwin x64
Angular: 6.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.0
@angular-devkit/build-angular 0.6.0
@angular-devkit/build-optimizer 0.6.0
@angular-devkit/core 0.6.0
@angular-devkit/schematics 0.6.0
@ngtools/webpack 6.0.0
@schematics/angular 0.6.0
@schematics/update 0.6.0
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
Repro steps
- Add dependency on a private repo such as FontAwesome 5 Pro
- Run ng update @angular/core
Observed behavior
Not found : @fortawesome/pro-regular-svg-icons
Mention any other details that might be useful (optional)
This works fine using npm directly because the private repo has already been registered with npm
Really angular team...still no fix for this?! Stop developing any new stuff and fix this issue. I have same issue, except I don't use private packages, nexus is used as a proxy for ALL npm repositories. So removing .npmrc doesn't solve anything (npm requests must go through the nexus proxy or they don't leave the network), and there is no "private dependencies" to remove, because they are all legit packages ...like angular stuff...
Looks like I found a solution, at least for Nexus repository. I already filed this as a pull request, however it would be really good to have some feedback from you guys. Especially would be cool to have some Artifactory users' feedback.
How to try it right now: replace the your_project/node_modules/@schematics/update/update/npm.js with the following content
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
const fs_1 = require("fs");
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const url = require("url");
const RegistryClient = require('npm-registry-client');
const npmPackageJsonCache = new Map();
const npmConfigOptionCache = new Map();
function _readNpmRc() {
return new rxjs_1.Observable(subject => {
// TODO: have a way to read options without using fs directly.
const path = require('path');
const fs = require('fs');
const perProjectNpmrc = path.resolve('.npmrc');
let npmrc = '';
if (fs.existsSync(perProjectNpmrc)) {
npmrc = fs.readFileSync(perProjectNpmrc).toString('utf-8');
}
else {
if (process.platform === 'win32') {
if (process.env.LOCALAPPDATA) {
npmrc = fs.readFileSync(path.join(process.env.LOCALAPPDATA, '.npmrc')).toString('utf-8');
}
}
else {
if (process.env.HOME) {
npmrc = fs.readFileSync(path.join(process.env.HOME, '.npmrc')).toString('utf-8');
}
}
}
const allOptionsArr = npmrc.split(/\r?\n/).map(x => x.trim());
const allOptions = {};
allOptionsArr.forEach(x => {
const delimiter = '=';
const split = x.split(delimiter);
const key = split[0].trim();
allOptions[key] = split.slice(1).join('=').trim();
});
subject.next(allOptions);
subject.complete();
}).pipe(operators_1.catchError(() => rxjs_1.of({})), operators_1.shareReplay());
}
function getOptionFromNpmRc(option) {
return _readNpmRc().pipe(operators_1.map(options => options[option]));
}
function getOptionFromNpmCli(option) {
return new rxjs_1.Observable(subject => {
child_process_1.exec(`npm get ${option}`, (error, data) => {
if (error) {
throw error;
}
else {
data = data.trim();
if (!data || data === 'undefined' || data === 'null') {
subject.next();
}
else {
subject.next(data);
}
}
subject.complete();
});
}).pipe(operators_1.catchError(() => rxjs_1.of(undefined)), operators_1.shareReplay());
}
function getNpmConfigOption(option, scope, tryWithoutScope) {
if (scope && tryWithoutScope) {
return rxjs_1.concat(getNpmConfigOption(option, scope), getNpmConfigOption(option)).pipe(operators_1.filter(result => !!result), operators_1.defaultIfEmpty(), operators_1.first());
}
const fullOption = `${scope ? scope + ':' : ''}${option}`;
let value = npmConfigOptionCache.get(fullOption);
if (value) {
return value;
}
value = option.startsWith('_')
? getOptionFromNpmRc(fullOption)
: getOptionFromNpmCli(fullOption);
npmConfigOptionCache.set(fullOption, value);
return value;
}
function getNpmClientSslOptions(strictSsl, cafile) {
const sslOptions = {};
if (strictSsl === 'false') {
sslOptions.strict = false;
}
else if (strictSsl === 'true') {
sslOptions.strict = true;
}
if (cafile) {
sslOptions.ca = fs_1.readFileSync(cafile);
}
return sslOptions;
}
/**
* Get the NPM repository's package.json for a package. This is p
* @param {string} packageName The package name to fetch.
* @param {string} registryUrl The NPM Registry URL to use.
* @param {LoggerApi} logger A logger instance to log debug information.
* @returns An observable that will put the pacakge.json content.
* @private
*/
function getNpmPackageJson(packageName, registryUrl, logger) {
const scope = packageName.startsWith('@') ? packageName.split('/')[0] : undefined;
return (registryUrl ? rxjs_1.of(registryUrl) : getNpmConfigOption('registry', scope, true)).pipe(operators_1.map(partialUrl => {
if (!partialUrl) {
partialUrl = 'https://registry.npmjs.org/';
}
const partial = url.parse(partialUrl);
let fullUrl = new url.URL(`http://${partial.host}/${packageName.replace(/\//g, '%2F')}`);
try {
const registry = new url.URL(partialUrl);
registry.pathname = (registry.pathname || '')
.replace(/\/?$/, '/' + packageName.replace(/\//g, '%2F'));
fullUrl = new url.URL(url.format(registry));
}
catch (_a) { }
logger.debug(`Getting package.json from '${packageName}' (url: ${JSON.stringify(fullUrl)})...`);
return fullUrl;
}), operators_1.concatMap(fullUrl => {
let maybeRequest = npmPackageJsonCache.get(fullUrl.toString());
if (maybeRequest) {
return maybeRequest;
}
const registryKey = `//${fullUrl.host}/`;
return rxjs_1.concat(getNpmConfigOption('proxy'), getNpmConfigOption('https-proxy'), getNpmConfigOption('strict-ssl'), getNpmConfigOption('cafile'), getNpmConfigOption('_auth'), getNpmConfigOption('_authToken', registryKey), getNpmConfigOption('username', registryKey, true), getNpmConfigOption('password', registryKey, true), getNpmConfigOption('email', registryKey, true), getNpmConfigOption('always-auth', registryKey, true)).pipe(operators_1.toArray(), operators_1.concatMap(options => {
const [http, https, strictSsl, cafile, token, authToken, username, password, email, alwaysAuth,] = options;
const subject = new rxjs_1.ReplaySubject(1);
const sslOptions = getNpmClientSslOptions(strictSsl, cafile);
const auth = {};
if (alwaysAuth !== undefined) {
auth.alwaysAuth = alwaysAuth === 'false' ? false : !!alwaysAuth;
}
if (email) {
auth.email = email;
}
if (authToken) {
auth.token = authToken;
}
else if (token) {
try {
// attempt to parse "username:password" from base64 token
// to enable Artifactory / Nexus-like repositories support
const delimiter = ':';
const parsedToken = Buffer.from(token, 'base64').toString('ascii');
const [extractedUsername, ...passwordArr] = parsedToken.split(delimiter);
const extractedPassword = passwordArr.join(delimiter);
if (extractedUsername && extractedPassword) {
auth.username = extractedUsername;
auth.password = extractedPassword;
}
else {
throw new Error('Unable to extract username and password from _auth token');
}
}
catch (ex) {
auth.token = token;
}
}
else if (username) {
auth.username = username;
auth.password = password;
}
const client = new RegistryClient({
proxy: { http, https },
ssl: sslOptions,
});
client.log.level = 'silent';
const params = {
timeout: 30000,
auth,
};
client.get(fullUrl.toString(), params, (error, data) => {
if (error) {
subject.error(error);
}
subject.next(data);
subject.complete();
});
maybeRequest = subject.asObservable();
npmPackageJsonCache.set(fullUrl.toString(), maybeRequest);
return maybeRequest;
}));
}));
}
exports.getNpmPackageJson = getNpmPackageJson;
After that the ng update should start working.
Be careful: after you
ng update @angular/clithe file will be overwritten, so don't forget to replace the content again. Otherwise you will see the lovely 401 :)
Still having issue with @angular/cli 6.2.2
@dkabul the fix is not merged yet
@smnbbrv
Tested your npm.js with Artifactory, and it gets past the initial error, which was:
> ng update <package in artifactory>
Unable to authenticate, need: Basic realm="Artifactory Realm"
But now presents a new error:
> ng update <package in artifactory>
This request requires auth credentials. Run `npm login` and repeat the request.
The contents of my .npmrc are:
registry = <url to artifactory>/api/npm/<repo>
_auth = xxxx
always-auth = true
email = xxxx
npm install resolves the same package from Artifactory without issue using the same .npmrc.
Thanks
$ ng update --registry <url-to-private-registry>
Doesn#t that work?
$ ng update --registry <url-to-private-registry>Doesn#t that work?
Not when private registry requires credentials.
@mrmaxsteel could you please check the following:
- where is located your npmrc? Project-level or home directory?
- does your password contain symbol ':'? If yes, try the updated script at https://github.com/angular/angular-cli/issues/10624#issuecomment-421564909
- could you remove the spaces around '=' (it looks like current script does not work with spaces yet)? So it should look like this:
registry=<url to artifactory>/api/npm/<repo>
_auth=xxxx
always-auth=true
email=xxxx
Thanks for collaborating! 👍
@smnbbrv yes! It works without whitespace between _auth = token as mentioned here: https://github.com/angular/angular-cli/pull/12284#issuecomment-422011350
It would be great if you could ensure support for whitespaces before your PR is merged, as officially the .npmrc should support whitespaces (https://docs.npmjs.com/files/npmrc)
done and updated the script at https://github.com/angular/angular-cli/issues/10624#issuecomment-421564909
Tested updated script from comment above, works 👍Nice one @smnbbrv!
@hansl any idea when this will be released?
I'm experiencing the same with Angular CLI 6.2.2 and private bitbucket repo like git+ssh://[email protected]:<org>/<package>.
@arm1n did you try https://github.com/angular/angular-cli/issues/10624#issuecomment-421564909 ?
@smnbbrv No I didn't - I'm expecting that it work without patching code from node_modules ;) But I will do it so that you know if it's working for that case too - is your patch supposed to land in one of the next versions?
@arm1n I am outside of Angular release cycle scope, but if it works with your case too then it is more likely to be pushed further. If it does not, could you post your npmrc (of course with masked credentials)
Wanted to upgrade from '@angular/[email protected]' with ng update @angular/cli.
Just recently added the FontAwesome PRO reference.
The .npmrc ...
@XXXXXXXX:registry=https://artifactory.XXXXXXXXX:443/artifactory/api/npm/npm-virtual/
@fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
depth=0
loglevel=warn
package-lock=false
progress=false
I cannot have ng serve running without choking on file changes. I have to update to a specific version to get the fix. And I cannot "update" using a simple command. Because I happened to use font-awesome. So I cannot develop, I cannot upgrade. Do you guys see the problem ?
I was really hoping this was resolved before v7.0 dropped. Now I am once again butting against this issue.
The fix by @smnbbrv did not work for me, I still got 401 Unauthorized when running ng update @angular/cli @angular/core.
My .npmrc is really simple:
@fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=SOME_TOKEN_HERE
I had to remove the .npmrc file and all private packages in package.json to run ng update. 😦
@SV-efi You can probably just change the @angular/... packages to a newer 6.X.X version and run npm install to fix your issue.