Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use npm bin from deps instead of global #270

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/add-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const execa = require('execa');
const getRegistry = require('./get-registry');
const getChannel = require('./get-channel');
const getReleaseInfo = require('./get-release-info');
const getNpm = require('./get-npm');

module.exports = async (npmrc, {npmPublish}, pkg, context) => {
const {
Expand All @@ -19,7 +20,7 @@ module.exports = async (npmrc, {npmPublish}, pkg, context) => {

logger.log(`Adding version ${version} to npm registry on dist-tag ${distTag}`);
const result = execa(
'npm',
getNpm(),
['dist-tag', 'add', `${pkg.name}@${version}`, distTag, '--userconfig', npmrc, '--registry', registry],
{
cwd,
Expand Down
8 changes: 8 additions & 0 deletions lib/get-npm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const {resolve} = require('path');
const isWindows = () => /^(msys|cygwin)$/.test(process.env.OSTYPE) || process.platform === 'win32';

module.exports = () => {
const cmd = isWindows() ? 'npm.cmd' : 'npm';

return resolve(require.resolve('npm'), '../../../.bin', cmd);
};
3 changes: 2 additions & 1 deletion lib/prepare.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const path = require('path');
const {move} = require('fs-extra');
const execa = require('execa');
const getNpm = require('./get-npm');

module.exports = async (npmrc, {tarballDir, pkgRoot}, {cwd, env, stdout, stderr, nextRelease: {version}, logger}) => {
const basePath = pkgRoot ? path.resolve(cwd, pkgRoot) : cwd;

logger.log('Write version %s to package.json in %s', version, basePath);

const versionResult = execa(
'npm',
getNpm(),
['version', version, '--userconfig', npmrc, '--no-git-tag-version', '--allow-same-version'],
{
cwd: basePath,
Expand Down
11 changes: 6 additions & 5 deletions lib/publish.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const execa = require('execa');
const getNpm = require('./get-npm');
const getRegistry = require('./get-registry');
const getChannel = require('./get-channel');
const getReleaseInfo = require('./get-release-info');
Expand All @@ -18,13 +19,13 @@ module.exports = async (npmrc, {npmPublish, pkgRoot}, pkg, context) => {
const basePath = pkgRoot ? path.resolve(cwd, pkgRoot) : cwd;
const registry = getRegistry(pkg, context);
const distTag = getChannel(channel);
const npm = getNpm();

logger.log(`Publishing version ${version} to npm registry on dist-tag ${distTag}`);
const result = execa(
'npm',
['publish', basePath, '--userconfig', npmrc, '--tag', distTag, '--registry', registry],
{cwd, env}
);
const result = execa(npm, ['publish', basePath, '--userconfig', npmrc, '--tag', distTag, '--registry', registry], {
cwd,
env,
});
result.stdout.pipe(stdout, {end: false});
result.stderr.pipe(stderr, {end: false});
await result;
Expand Down
3 changes: 2 additions & 1 deletion lib/verify-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const normalizeUrl = require('normalize-url');
const AggregateError = require('aggregate-error');
const getError = require('./get-error');
const getRegistry = require('./get-registry');
const getNpm = require('./get-npm');
const setNpmrcAuth = require('./set-npmrc-auth');

module.exports = async (npmrc, pkg, context) => {
Expand All @@ -18,7 +19,7 @@ module.exports = async (npmrc, pkg, context) => {

if (normalizeUrl(registry) === normalizeUrl(DEFAULT_NPM_REGISTRY)) {
try {
const whoamiResult = execa('npm', ['whoami', '--userconfig', npmrc, '--registry', registry], {cwd, env});
const whoamiResult = execa(getNpm(), ['whoami', '--userconfig', npmrc, '--registry', registry], {cwd, env});
whoamiResult.stdout.pipe(stdout, {end: false});
whoamiResult.stderr.pipe(stderr, {end: false});
await whoamiResult;
Expand Down
23 changes: 23 additions & 0 deletions test/get-npm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const {resolve} = require('path');
const test = require('ava');
const getNpm = require('../lib/get-npm');

let ostype;

test.before(() => {
ostype = process.env.OSTYPE;
});

test.after(() => {
process.env.OSTYPE = ostype;
});

test.serial('Get npm cmd for linux', (t) => {
process.env.OSTYPE = 'linux';
t.is(getNpm(), resolve(__dirname, '../node_modules/.bin/npm'));
});

test.serial('Get npm cmd for windows', (t) => {
process.env.OSTYPE = 'msys';
t.is(getNpm(), resolve(__dirname, '../node_modules/.bin/npm.cmd'));
});