Skip to content

Commit

Permalink
Support auth for private npm packages (#1146)
Browse files Browse the repository at this point in the history
Sends the auth token for scoped packages, which may be private. Fixes #1134 and #521.
  • Loading branch information
devongovett authored and cpojer committed Oct 17, 2016
1 parent c091ac4 commit 50aae7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/registries/npm-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {ConfigRegistries} from './index.js';
import * as fs from '../util/fs.js';
import NpmResolver from '../resolvers/registries/npm-resolver.js';
import Registry from './base-registry.js';
import {addSuffix} from '../util/misc';
import {addSuffix, removePrefix} from '../util/misc';

const defaults = require('defaults');
const userHome = require('user-home');
Expand Down Expand Up @@ -53,7 +53,8 @@ export default class NpmRegistry extends Registry {
const registry = addSuffix(this.getRegistry(pathname), '/');
const requestUrl = url.resolve(registry, pathname);
const alwaysAuth = this.getScopedOption(registry.replace(/^https?:/, ''), 'always-auth')
|| this.getOption('always-auth');
|| this.getOption('always-auth')
|| removePrefix(requestUrl, registry)[0] === '@';

const headers = {};
if (this.token || (alwaysAuth && requestUrl.startsWith(registry))) {
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/registries/npm-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default class NpmResolver extends RegistryResolver {
info._remote = {
resolved: `${this.cleanRegistry(dist.tarball)}#${dist.shasum}`,
type: 'tarball',
reference: dist.tarball,
reference: this.cleanRegistry(dist.tarball),
hash: dist.shasum,
registry: 'npm',
};
Expand Down

0 comments on commit 50aae7d

Please sign in to comment.