Skip to content

Commit

Permalink
Merge branch 'master' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Nov 21, 2019
2 parents 851106c + c9fc3c1 commit 76b574b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 41 deletions.
10 changes: 2 additions & 8 deletions lib/add-channel.js
Expand Up @@ -26,14 +26,8 @@ module.exports = async (npmrc, {npmPublish}, pkg, context) => {
env,
}
);
result.stdout.pipe(
stdout,
{end: false}
);
result.stderr.pipe(
stderr,
{end: false}
);
result.stdout.pipe(stdout, {end: false});
result.stderr.pipe(stderr, {end: false});
await result;

logger.log(`Published ${pkg.name}@${version} on ${registry}`);
Expand Down
20 changes: 4 additions & 16 deletions lib/prepare.js
Expand Up @@ -15,28 +15,16 @@ module.exports = async (npmrc, {tarballDir, pkgRoot}, {cwd, env, stdout, stderr,
env,
}
);
versionResult.stdout.pipe(
stdout,
{end: false}
);
versionResult.stderr.pipe(
stderr,
{end: false}
);
versionResult.stdout.pipe(stdout, {end: false});
versionResult.stderr.pipe(stderr, {end: false});

await versionResult;

if (tarballDir) {
logger.log('Creating npm package version %s', version);
const packResult = execa('npm', ['pack', basePath, '--userconfig', npmrc], {cwd, env});
packResult.stdout.pipe(
stdout,
{end: false}
);
packResult.stderr.pipe(
stderr,
{end: false}
);
packResult.stdout.pipe(stdout, {end: false});
packResult.stderr.pipe(stderr, {end: false});

const tarball = (await packResult).stdout.split('\n').pop();
const tarballSource = path.resolve(cwd, tarball);
Expand Down
10 changes: 2 additions & 8 deletions lib/publish.js
Expand Up @@ -25,14 +25,8 @@ module.exports = async (npmrc, {npmPublish, pkgRoot}, pkg, context) => {
['publish', basePath, '--userconfig', npmrc, '--tag', distTag, '--registry', registry],
{cwd, env}
);
result.stdout.pipe(
stdout,
{end: false}
);
result.stderr.pipe(
stderr,
{end: false}
);
result.stdout.pipe(stdout, {end: false});
result.stderr.pipe(stderr, {end: false});
await result;

logger.log(`Published ${pkg.name}@${version} to ${registry}`);
Expand Down
15 changes: 13 additions & 2 deletions lib/set-npmrc-auth.js
Expand Up @@ -17,6 +17,11 @@ module.exports = async (
{registry: 'https://registry.npmjs.org/'},
{config: NPM_CONFIG_USERCONFIG || path.resolve(cwd, '.npmrc')}
);

if (configs) {
logger.log('Reading npm config from %s', configs.join(', '));
}

const currentConfig = configs ? (await Promise.all(configs.map(config => readFile(config)))).join('\n') : '';

if (getAuthToken(registry, {npmrc: rcConfig})) {
Expand All @@ -25,10 +30,16 @@ module.exports = async (
}

if (NPM_USERNAME && NPM_PASSWORD && NPM_EMAIL) {
await outputFile(npmrc, `${currentConfig}\n_auth = \${LEGACY_TOKEN}\nemail = \${NPM_EMAIL}`);
await outputFile(
npmrc,
`${currentConfig ? `${currentConfig}\n` : ''}_auth = \${LEGACY_TOKEN}\nemail = \${NPM_EMAIL}`
);
logger.log(`Wrote NPM_USERNAME, NPM_PASSWORD and NPM_EMAIL to ${npmrc}`);
} else if (NPM_TOKEN) {
await outputFile(npmrc, `${currentConfig}\n${nerfDart(registry)}:_authToken = \${NPM_TOKEN}`);
await outputFile(
npmrc,
`${currentConfig ? `${currentConfig}\n` : ''}${nerfDart(registry)}:_authToken = \${NPM_TOKEN}`
);
logger.log(`Wrote NPM_TOKEN to ${npmrc}`);
} else {
throw new AggregateError([getError('ENONPMTOKEN', {registry})]);
Expand Down
7 changes: 6 additions & 1 deletion lib/verify-auth.js
Expand Up @@ -9,14 +9,19 @@ module.exports = async (npmrc, pkg, context) => {
const {
cwd,
env: {DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org/', ...env},
stdout,
stderr,
} = context;
const registry = getRegistry(pkg, context);

await setNpmrcAuth(npmrc, registry, context);

if (normalizeUrl(registry) === normalizeUrl(DEFAULT_NPM_REGISTRY)) {
try {
await execa('npm', ['whoami', '--userconfig', npmrc, '--registry', registry], {cwd, env});
const whoamiResult = execa('npm', ['whoami', '--userconfig', npmrc, '--registry', registry], {cwd, env});
whoamiResult.stdout.pipe(stdout, {end: false});
whoamiResult.stderr.pipe(stderr, {end: false});
await whoamiResult;
} catch (_) {
throw new AggregateError([getError('EINVALIDNPMTOKEN', {registry})]);
}
Expand Down
26 changes: 20 additions & 6 deletions test/set-npmrc-auth.test.js
Expand Up @@ -44,7 +44,7 @@ test.serial('Set auth with "NPM_USERNAME", "NPM_PASSWORD" and "NPM_EMAIL"', asyn

await require('../lib/set-npmrc-auth')(npmrc, 'http://custom.registry.com', {cwd, env, logger: t.context.logger});

t.is((await readFile(npmrc)).toString(), `\n_auth = \${LEGACY_TOKEN}\nemail = \${NPM_EMAIL}`);
t.is((await readFile(npmrc)).toString(), `_auth = \${LEGACY_TOKEN}\nemail = \${NPM_EMAIL}`);
t.deepEqual(t.context.log.args[1], [`Wrote NPM_USERNAME, NPM_PASSWORD and NPM_EMAIL to ${npmrc}`]);
});

Expand All @@ -60,7 +60,11 @@ test.serial('Preserve home ".npmrc"', async t => {
await require('../lib/set-npmrc-auth')(npmrc, 'http://custom.registry.com', {cwd, env, logger: t.context.logger});

t.is((await readFile(npmrc)).toString(), `home_config = test\n//custom.registry.com/:_authToken = \${NPM_TOKEN}`);
t.deepEqual(t.context.log.args[1], [`Wrote NPM_TOKEN to ${npmrc}`]);
t.deepEqual(t.context.log.args[1], [
'Reading npm config from %s',
[path.resolve(process.env.HOME, '.npmrc')].join(', '),
]);
t.deepEqual(t.context.log.args[2], [`Wrote NPM_TOKEN to ${npmrc}`]);
});

test.serial('Preserve home and local ".npmrc"', async t => {
Expand All @@ -79,7 +83,11 @@ test.serial('Preserve home and local ".npmrc"', async t => {
(await readFile(npmrc)).toString(),
`home_config = test\ncwd_config = test\n//custom.registry.com/:_authToken = \${NPM_TOKEN}`
);
t.deepEqual(t.context.log.args[1], [`Wrote NPM_TOKEN to ${npmrc}`]);
t.deepEqual(t.context.log.args[1], [
'Reading npm config from %s',
[path.resolve(process.env.HOME, '.npmrc'), path.resolve(cwd, '.npmrc')].join(', '),
]);
t.deepEqual(t.context.log.args[2], [`Wrote NPM_TOKEN to ${npmrc}`]);
});

test.serial('Preserve all ".npmrc" if auth is already configured', async t => {
Expand All @@ -94,7 +102,10 @@ test.serial('Preserve all ".npmrc" if auth is already configured', async t => {
await require('../lib/set-npmrc-auth')(npmrc, 'http://custom.registry.com', {cwd, env: {}, logger: t.context.logger});

t.is((await readFile(npmrc)).toString(), `home_config = test\n//custom.registry.com/:_authToken = \${NPM_TOKEN}`);
t.is(t.context.log.callCount, 1);
t.deepEqual(t.context.log.args[1], [
'Reading npm config from %s',
[path.resolve(process.env.HOME, '.npmrc'), path.resolve(cwd, '.npmrc')].join(', '),
]);
});

test.serial('Preserve ".npmrc" if auth is already configured for a scoped package', async t => {
Expand All @@ -115,7 +126,10 @@ test.serial('Preserve ".npmrc" if auth is already configured for a scoped packag
(await readFile(npmrc)).toString(),
`home_config = test\n@scope:registry=http://custom.registry.com\n//custom.registry.com/:_authToken = \${NPM_TOKEN}`
);
t.is(t.context.log.callCount, 1);
t.deepEqual(t.context.log.args[1], [
'Reading npm config from %s',
[path.resolve(process.env.HOME, '.npmrc'), path.resolve(cwd, '.npmrc')].join(', '),
]);
});

test.serial('Throw error if "NPM_TOKEN" is missing', async t => {
Expand Down Expand Up @@ -148,7 +162,7 @@ test.serial('Emulate npm config resolution if "NPM_CONFIG_USERCONFIG" is set', a
});

t.is((await readFile(npmrc)).toString(), `//custom.registry.com/:_authToken = \${NPM_TOKEN}`);
t.is(t.context.log.callCount, 1);
t.deepEqual(t.context.log.args[1], ['Reading npm config from %s', [path.resolve(cwd, '.custom-npmrc')].join(', ')]);
});

test.serial('Throw error if "NPM_USERNAME" is missing', async t => {
Expand Down

0 comments on commit 76b574b

Please sign in to comment.