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: move init command to separate package #1950

Merged
merged 1 commit into from
Oct 15, 2020
Merged
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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