Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: move init command to separate package (#1950)
  • Loading branch information
evilebottnawi committed Oct 15, 2020
1 parent 6f77162 commit 92ad475
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
Expand Up @@ -2,7 +2,7 @@ jest.setMock('../prompt-installation', {
promptInstallation: jest.fn(),
});

const ExternalCommand = require('../../commands/resolveCommand');
const ExternalCommand = require('../resolve-command');
const { packageExists } = require('../package-exists');
const { promptInstallation } = require('../prompt-installation');

Expand Down
4 changes: 3 additions & 1 deletion packages/webpack-cli/lib/utils/arg-parser.js
Expand Up @@ -28,8 +28,10 @@ const argParser = (options, args, argsOnly = false, name = '') => {
.allowUnknownOption(true)
.action(async () => {
const cliArgs = args.slice(args.indexOf(cmd.name) + 1 || args.indexOf(cmd.alias) + 1);
return await require('../commands/resolveCommand')(defaultCommands[cmd.name], ...cliArgs);

return await require('./resolve-command')(defaultCommands[cmd.name], ...cliArgs);
});

return parser;
}, parser);

Expand Down
@@ -1,13 +1,15 @@
const { yellow, cyan } = require('colorette');
const logger = require('../utils/logger');
const { packageExists } = require('../utils/package-exists');
const { promptInstallation } = require('../utils/prompt-installation');
const logger = require('./logger');
const { packageExists } = require('./package-exists');
const { promptInstallation } = require('./prompt-installation');

const packagePrefix = '@webpack-cli';

const run = async (name, ...args) => {
const scopeName = packagePrefix + '/' + name;

let pkgLoc = packageExists(scopeName);

if (!pkgLoc) {
try {
pkgLoc = await promptInstallation(`${scopeName}`, () => {
Expand All @@ -17,7 +19,18 @@ const run = async (name, ...args) => {
logger.error(`Action Interrupted, use ${cyan('webpack-cli help')} to see possible commands.`);
}
}
return pkgLoc ? require(scopeName).default(...args) : null;

if (!pkgLoc) {
return;
}

let mod = require(scopeName);

if (mod.default) {
mod = mod.default;
}

return mod(...args);
};

module.exports = run;
4 changes: 3 additions & 1 deletion packages/webpack-cli/package.json
Expand Up @@ -28,7 +28,6 @@
],
"dependencies": {
"@webpack-cli/info": "^1.0.1",
"@webpack-cli/init": "^1.0.1",
"@webpack-cli/serve": "^1.0.1",
"ansi-escapes": "^4.3.1",
"colorette": "^1.2.1",
Expand All @@ -46,6 +45,9 @@
"webpack": "4.x.x || 5.x.x"
},
"peerDependenciesMeta": {
"@webpack-cli/init": {
"optional": true
},
"@webpack-cli/generate-loader": {
"optional": true
},
Expand Down

0 comments on commit 92ad475

Please sign in to comment.