🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

webpack-cli

Package Overview
Dependencies
Maintainers
3
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-cli - npm Package Compare versions

Comparing version

to
4.10.0

lib/bootstrap.d.ts

43

bin/cli.js
#!/usr/bin/env node
'use strict';
"use strict";
const Module = require('module');
const importLocal = require("import-local");
const runCLI = require("../lib/bootstrap");
const originalModuleCompile = Module.prototype._compile;
require('v8-compile-cache');
const importLocal = require('import-local');
const runCLI = require('../lib/bootstrap');
const utils = require('../lib/utils');
if (!process.env.WEBPACK_CLI_SKIP_IMPORT_LOCAL) {
// Prefer the local installation of `webpack-cli`
if (importLocal(__filename)) {
return;
}
// Prefer the local installation of `webpack-cli`
if (importLocal(__filename)) {
return;
}
}
process.title = 'webpack';
process.title = "webpack";
if (utils.packageExists('webpack')) {
runCLI(process.argv, originalModuleCompile);
} else {
const { promptInstallation, logger, colors } = utils;
promptInstallation('webpack', () => {
utils.logger.error(`It looks like ${colors.bold('webpack')} is not installed.`);
})
.then(() => {
logger.success(`${colors.bold('webpack')} was installed successfully.`);
runCLI(process.argv, originalModuleCompile);
})
.catch(() => {
logger.error(`Action Interrupted, Please try once again or install ${colors.bold('webpack')} manually.`);
process.exit(2);
});
}
runCLI(process.argv);

@@ -1,18 +0,16 @@

const WebpackCLI = require('./webpack-cli');
const utils = require('./utils');
const runCLI = async (args, originalModuleCompile) => {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// eslint-disable-next-line @typescript-eslint/no-var-requires
const WebpackCLI = require("./webpack-cli");
const runCLI = async (args) => {
// Create a new instance of the CLI object
const cli = new WebpackCLI();
try {
// Create a new instance of the CLI object
const cli = new WebpackCLI();
cli._originalModuleCompile = originalModuleCompile;
await cli.run(args);
} catch (error) {
utils.logger.error(error);
}
catch (error) {
cli.logger.error(error);
process.exit(2);
}
};
module.exports = runCLI;

@@ -1,5 +0,22 @@

const CLI = require('./webpack-cli');
const utils = require('./utils');
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./types"), exports);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const CLI = require("./webpack-cli");
module.exports = CLI;
module.exports.utils = utils;
// TODO remove after drop `@webpack-cli/migrate`
module.exports.utils = { logger: console };

@@ -0,1 +1,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CLIPlugin = void 0;
class CLIPlugin {

@@ -5,7 +8,5 @@ constructor(options) {

}
setupHotPlugin(compiler) {
const { HotModuleReplacementPlugin } = compiler.webpack || require('webpack');
const { HotModuleReplacementPlugin } = compiler.webpack || require("webpack");
const hotModuleReplacementPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof HotModuleReplacementPlugin));
if (!hotModuleReplacementPlugin) {

@@ -15,14 +16,10 @@ new HotModuleReplacementPlugin().apply(compiler);

}
setupPrefetchPlugin(compiler) {
const { PrefetchPlugin } = compiler.webpack || require('webpack');
const { PrefetchPlugin } = compiler.webpack || require("webpack");
new PrefetchPlugin(null, this.options.prefetch).apply(compiler);
}
async setupBundleAnalyzerPlugin(compiler) {
// eslint-disable-next-line node/no-extraneous-require
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
// eslint-disable-next-line node/no-extraneous-require,@typescript-eslint/no-var-requires
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const bundleAnalyzerPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof BundleAnalyzerPlugin));
if (!bundleAnalyzerPlugin) {

@@ -32,59 +29,52 @@ new BundleAnalyzerPlugin().apply(compiler);

}
setupProgressPlugin(compiler) {
const { ProgressPlugin } = compiler.webpack || require('webpack');
const { ProgressPlugin } = compiler.webpack || require("webpack");
const progressPlugin = Boolean(compiler.options.plugins.find((plugin) => plugin instanceof ProgressPlugin));
if (!progressPlugin) {
new ProgressPlugin({ profile: this.options.progress === 'profile' }).apply(compiler);
new ProgressPlugin({
profile: this.options.progress === "profile",
}).apply(compiler);
}
}
setupHelpfulOutput(compiler) {
const pluginName = 'webpack-cli';
const getCompilationName = () => (compiler.name ? `'${compiler.name}'` : '');
const pluginName = "webpack-cli";
const getCompilationName = () => (compiler.name ? `'${compiler.name}'` : "");
const logCompilation = (message) => {
if (process.env.WEBPACK_CLI_START_FINISH_FORCE_LOG) {
process.stderr.write(message);
}
else {
this.logger.log(message);
}
};
const { configPath } = this.options;
compiler.hooks.run.tap(pluginName, () => {
const name = getCompilationName();
this.logger.log(`Compiler${name ? ` ${name}` : ''} starting...`);
logCompilation(`Compiler${name ? ` ${name}` : ""} starting... `);
if (configPath) {
this.logger.log(`Compiler${name ? ` ${name}` : ''} is using config: '${configPath}'`);
this.logger.log(`Compiler${name ? ` ${name}` : ""} is using config: '${configPath}'`);
}
});
compiler.hooks.watchRun.tap(pluginName, (compiler) => {
const { bail, watch } = compiler.options;
if (bail && watch) {
this.logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
}
const name = getCompilationName();
this.logger.log(`Compiler${name ? ` ${name}` : ''} starting...`);
logCompilation(`Compiler${name ? ` ${name}` : ""} starting... `);
if (configPath) {
this.logger.log(`Compiler${name ? ` ${name}` : ''} is using config: '${configPath}'`);
this.logger.log(`Compiler${name ? ` ${name}` : ""} is using config: '${configPath}'`);
}
});
compiler.hooks.invalid.tap(pluginName, (filename, changeTime) => {
const date = new Date(changeTime * 1000);
const date = new Date(changeTime);
this.logger.log(`File '${filename}' was modified`);
this.logger.log(`Changed time is ${date} (timestamp is ${changeTime})`);
});
(compiler.webpack ? compiler.hooks.afterDone : compiler.hooks.done).tap(pluginName, () => {
const name = getCompilationName();
this.logger.log(`Compiler${name ? ` ${name}` : ''} finished`);
logCompilation(`Compiler${name ? ` ${name}` : ""} finished`);
process.nextTick(() => {
if (compiler.watchMode) {
this.logger.log(`Compiler${name ? `${name}` : ''} is watching files for updates...`);
this.logger.log(`Compiler${name ? `${name}` : ""} is watching files for updates...`);
}

@@ -94,26 +84,20 @@ });

}
apply(compiler) {
this.logger = compiler.getInfrastructureLogger('webpack-cli');
this.logger = compiler.getInfrastructureLogger("webpack-cli");
if (this.options.progress) {
this.setupProgressPlugin(compiler);
}
if (this.options.hot) {
this.setupHotPlugin(compiler);
}
if (this.options.prefetch) {
this.setupPrefetchPlugin(compiler);
}
if (this.options.analyze) {
this.setupBundleAnalyzerPlugin(compiler);
}
this.setupHelpfulOutput(compiler);
}
}
exports.CLIPlugin = CLIPlugin;
module.exports = CLIPlugin;

@@ -0,13 +1,13 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function dynamicImportLoader() {
let importESM;
try {
importESM = new Function('id', 'return import(id);');
} catch (e) {
importESM = new Function("id", "return import(id);");
}
catch (e) {
importESM = null;
}
return importESM;
}
module.exports = dynamicImportLoader;
{
"name": "webpack-cli",
"version": "4.6.0",
"version": "4.10.0",
"description": "CLI for webpack & friends",

@@ -10,2 +10,8 @@ "license": "MIT",

},
"homepage": "https://github.com/webpack/webpack-cli/tree/master/packages/webpack-cli",
"bugs": "https://github.com/webpack/webpack-cli/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/webpack"
},
"bin": {

@@ -33,9 +39,8 @@ "webpack-cli": "./bin/cli.js"

"@discoveryjs/json-ext": "^0.5.0",
"@webpack-cli/configtest": "^1.0.2",
"@webpack-cli/info": "^1.2.3",
"@webpack-cli/serve": "^1.3.1",
"colorette": "^1.2.1",
"@webpack-cli/configtest": "^1.2.0",
"@webpack-cli/info": "^1.5.0",
"@webpack-cli/serve": "^1.7.0",
"colorette": "^2.0.14",
"commander": "^7.0.0",
"enquirer": "^2.3.6",
"execa": "^5.0.0",
"cross-spawn": "^7.0.3",
"fastest-levenshtein": "^1.0.12",

@@ -45,3 +50,2 @@ "import-local": "^3.0.2",

"rechoir": "^0.7.0",
"v8-compile-cache": "^2.2.0",
"webpack-merge": "^5.7.3"

@@ -66,3 +70,3 @@ },

},
"gitHead": "fb50f766851f500ca12867a2aa9de81fa6e368f9"
"gitHead": "20882d463450d010bb76e0824fe555e9785e9561"
}

@@ -66,13 +66,13 @@ <div align="center">

```
build|bundle|b [entries...] [options] Run webpack (default command, can be omitted).
configtest|t [config-path] Validate a webpack configuration.
help|h [command] [option] Display help for commands and options.
info|i [options] Outputs information about your system.
init|c [generation-path] [options] Initialize a new webpack project.
loader|l [output-path] Scaffold a loader.
migrate|m <config-path> [new-config-path] Migrate a configuration to a new version.
plugin|p [output-path] Scaffold a plugin.
serve|s [entries...] [options] Run the webpack dev server.
version|v [commands...] Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
watch|w [entries...] [options] Run webpack and watch for files changes.
build|bundle|b [entries...] [options] Run webpack (default command, can be omitted).
configtest|t [config-path] Validate a webpack configuration.
help|h [command] [option] Display help for commands and options.
info|i [options] Outputs information about your system.
init|create|new|c|n [generation-path] [options] Initialize a new webpack project.
loader|l [output-path] [options] Scaffold a loader.
migrate|m <config-path> [new-config-path] Migrate a configuration to a new version.
plugin|p [output-path] [options] Scaffold a plugin.
serve|server|s [entries...] [options] Run the webpack dev server.
version|v [commands...] Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.
watch|w [entries...] [options] Run webpack and watch for files changes.
```

@@ -118,2 +118,32 @@

Checkout [`OPTIONS.md`](../../OPTIONS.md) to see list of all available options.
Checkout [`OPTIONS.md`](https://github.com/webpack/webpack-cli/blob/master/OPTIONS.md) to see list of all available options.
## Exit codes and their meanings
| Exit Code | Description |
| --------- | -------------------------------------------------- |
| `0` | Success |
| `1` | Errors from webpack |
| `2` | Configuration/options problem or an internal error |
## CLI Environment Variables
| Environment Variable | Description |
| ----------------------------------- | ------------------------------------------------------------------- |
| `WEBPACK_CLI_SKIP_IMPORT_LOCAL` | when `true` it will skip using the local instance of `webpack-cli`. |
| `WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG` | when `true` it will force load the ESM config. |
| `WEBPACK_PACKAGE` | Use a custom webpack version in CLI. |
| `WEBPACK_DEV_SERVER_PACKAGE` | Use a custom webpack-dev-server version in CLI. |
| `WEBPACK_CLI_HELP_WIDTH` | Use custom width for help output. |
## Configuration Environment Variables
You can use the following environment variables inside your webpack configuration:
| Environment Variable | Description |
| -------------------- | -------------------------------------------- |
| `WEBPACK_SERVE` | `true` if `serve\|s` is being used. |
| `WEBPACK_BUILD` | `true` if `build\|bundle\|b` is being used. |
| `WEBPACK_WATCH` | `true` if `--watch\|watch\|w` is being used. |
Checkout [webpack.js.org](https://webpack.js.org/api/cli/) for more detailed documentation of `webpack-cli`.

Sorry, the diff of this file is too big to display