Skip to content

Commit

Permalink
cli(path): resolve better
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed May 17, 2018
1 parent 062fa28 commit 7fca948
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
23 changes: 18 additions & 5 deletions bin/prompt-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ const runCommand = (command, args) => {
module.exports = function promptForInstallation(packages, ...args) {
const nameOfPackage = "@webpack-cli/" + packages;
let packageIsInstalled = false;
let pathForCmd;
try {
require.resolve(nameOfPackage);
const path = require("path");
pathForCmd = path.resolve(
process.cwd(),
"node_modules",
"@webpack-cli",
packages
);
require.resolve(pathForCmd);
packageIsInstalled = true;
} catch (err) {
packageIsInstalled = false;
}

if (!packageIsInstalled) {
const path = require("path");
const fs = require("fs");
Expand Down Expand Up @@ -71,10 +78,16 @@ module.exports = function promptForInstallation(packages, ...args) {
//eslint-disable-next-line
runCommand(packageManager, options)
.then(result => {
pathForCmd = path.resolve(
process.cwd(),
"node_modules",
"@webpack-cli",
packages
);
if (packages === "serve") {
return require(`@webpack-cli/${packages}`).serve();
return require(pathForCmd).serve();
}
return require(nameOfPackage)(...args); //eslint-disable-line
return require(pathForCmd)(...args); //eslint-disable-line
})
.catch(error => {
console.error(error);
Expand All @@ -92,6 +105,6 @@ module.exports = function promptForInstallation(packages, ...args) {
}
});
} else {
require(nameOfPackage)(...args); // eslint-disable-line
require(pathForCmd)(...args); // eslint-disable-line
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack-cli",
"version": "0.0.3-development",
"version": "0.0.4-development",
"description": "CLI for webpack & friends",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/init/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const npmPackagesExists = require("@webpack-cli/utils/npm-packages-exists");
const defaultGenerator = require("@webpack-cli/utils/generators/init-generator");
const defaultGenerator = require("@webpack-cli/generators/init-generator");
const modifyHelper = require("@webpack-cli/utils/modify-config-helper");

/**
Expand Down

0 comments on commit 7fca948

Please sign in to comment.