From 3168f63836a436ee381400c205f5497052654314 Mon Sep 17 00:00:00 2001 From: heyli Date: Thu, 29 Jun 2017 22:37:05 -0500 Subject: [PATCH] feat: support custom npm clients (`options.npm`) (#113) --- README.md | 2 ++ src/installer.js | 9 +++++++-- src/plugin.js | 2 +- test/plugin.test.js | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4cae2f5..da30d4a 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ plugins: [ peerDependencies: true, // Reduce amount of console logging quiet: false, + // npm command used inside company, yarn is not supported yet + npm: 'tnpm' }); ], ``` diff --git a/src/installer.js b/src/installer.js index c753555..4f44877 100644 --- a/src/installer.js +++ b/src/installer.js @@ -7,7 +7,12 @@ var util = require("util"); var EXTERNAL = /^\w[a-z\-0-9\.]+$/; // Match "react", "path", "fs", "lodash.random", etc. var PEERS = /UNMET PEER DEPENDENCY ([a-z\-0-9\.]+)@(.+)/gm; -var defaultOptions = { dev: false, peerDependencies: true, quiet: false }; +var defaultOptions = { + dev: false, + peerDependencies: true, + quiet: false, + npm: 'npm', +}; var erroneous = []; function normalizeBabelPlugin(plugin, prefix) { @@ -145,7 +150,7 @@ module.exports.install = function install(deps, options) { }); // Ignore input, capture output, show errors - var output = spawn.sync("npm", args, { + var output = spawn.sync(options.npm, args, { stdio: ["ignore", "pipe", "inherit"] }); diff --git a/src/plugin.js b/src/plugin.js index 35b2747..f57f6c4 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -136,7 +136,7 @@ NpmInstallPlugin.prototype.resolve = function(resolver, result, callback) { ); } - if (major === "2") { + if (major === "2" || major === "3") { return this.compiler.resolvers[resolver].resolve( result.context || {}, result.path, diff --git a/test/plugin.test.js b/test/plugin.test.js index 19782c6..721f200 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -41,6 +41,7 @@ describe("plugin", function() { dev: false, peerDependencies: true, quiet: false, + npm: 'npm', }; this.plugin = new Plugin(this.options);