This commit is contained in:
2022-04-07 18:09:31 +05:30
parent 36ea86d8e6
commit 1c779ef816
14095 changed files with 1769361 additions and 47 deletions
+27
View File
@@ -0,0 +1,27 @@
# webpack-cli configtest
[![NPM Downloads][downloads]][downloads-url]
## Description
This package validates a webpack configuration.
## Installation
```bash
#npm
npm i -D @webpack-cli/configtest
#yarn
yarn add -D @webpack-cli/configtest
```
## Usage
```bash
npx webpack configtest [config-path]
```
[downloads]: https://img.shields.io/npm/dm/@webpack-cli/configtest.svg
[downloads-url]: https://www.npmjs.com/package/@webpack-cli/configtest
+4
View File
@@ -0,0 +1,4 @@
declare class ConfigTestCommand {
apply(cli: any): Promise<void>;
}
export default ConfigTestCommand;
+55
View File
@@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const WEBPACK_PACKAGE = process.env.WEBPACK_PACKAGE || "webpack";
class ConfigTestCommand {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
async apply(cli) {
await cli.makeCommand({
name: "configtest [config-path]",
alias: "t",
description: "Validate a webpack configuration.",
pkg: "@webpack-cli/configtest",
dependencies: [WEBPACK_PACKAGE],
}, [], async (configPath) => {
cli.webpack = await cli.loadWebpack();
const config = await cli.loadConfig(configPath ? { config: [configPath] } : {});
const configPaths = new Set();
if (Array.isArray(config.options)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
config.options.forEach((options) => {
if (config.path.get(options)) {
configPaths.add(config.path.get(options));
}
});
}
else {
if (config.path.get(config.options)) {
configPaths.add(config.path.get(config.options));
}
}
if (configPaths.size === 0) {
cli.logger.error("No configuration found.");
process.exit(2);
}
cli.logger.info(`Validate '${Array.from(configPaths).join(" ,")}'.`);
try {
const error = cli.webpack.validate(config.options);
// TODO remove this after drop webpack@4
if (error && error.length > 0) {
throw new cli.webpack.WebpackOptionsValidationError(error);
}
}
catch (error) {
if (cli.isValidationError(error)) {
cli.logger.error(error.message);
}
else {
cli.logger.error(error);
}
process.exit(2);
}
cli.logger.success("There are no validation errors in the given webpack configuration.");
});
}
}
exports.default = ConfigTestCommand;
+23
View File
@@ -0,0 +1,23 @@
{
"name": "@webpack-cli/configtest",
"version": "1.1.1",
"description": "Validate a webpack configuration.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/webpack/webpack-cli.git"
},
"homepage": "https://github.com/webpack/webpack-cli/tree/master/packages/configtest",
"files": [
"lib"
],
"peerDependencies": {
"webpack": "4.x.x || 5.x.x",
"webpack-cli": "4.x.x"
}
}
+50
View File
@@ -0,0 +1,50 @@
# webpack-cli info
[![NPM Downloads][downloads]][downloads-url]
## Description
This package returns a set of information related to the local environment.
## Installation
```bash
#npm
npm i -D @webpack-cli/info
#yarn
yarn add -D @webpack-cli/info
```
## Usage
```bash
#npx
npx webpack info [options]
#global installation
webpack info [options]
```
### Args / Flags
#### Output format
| Flag | Description | Type |
| ------------------------------------- | --------------------------------------- | ------ |
| `-o, --output < json or markdown >` | To get the output in a specified format | string |
| `-a, --additional-package <value...>` | Adds additional packages to the output | string |
_Not supported for config_
#### Options
| Flag | Description | Type |
| ----------- | ------------------------------------------ | ------- |
| `--help` | Show help | boolean |
| `--version` | Show version number of `@webpack-cli/info` | boolean |
[downloads]: https://img.shields.io/npm/dm/@webpack-cli/info.svg
[downloads-url]: https://www.npmjs.com/package/@webpack-cli/info
+4
View File
@@ -0,0 +1,4 @@
declare class InfoCommand {
apply(cli: any): Promise<void>;
}
export default InfoCommand;
+85
View File
@@ -0,0 +1,85 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const envinfo_1 = __importDefault(require("envinfo"));
class InfoCommand {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
async apply(cli) {
await cli.makeCommand({
name: "info",
alias: "i",
description: "Outputs information about your system.",
usage: "[options]",
pkg: "@webpack-cli/info",
}, [
{
name: "output",
alias: "o",
configs: [
{
type: "string",
},
],
description: "To get the output in a specified format ( accept json or markdown )",
},
{
name: "additional-package",
alias: "a",
configs: [{ type: "string" }],
multiple: true,
description: "Adds additional packages to the output",
},
], async (options) => {
let { output } = options;
const envinfoConfig = {};
if (output) {
// Remove quotes if exist
output = output.replace(/['"]+/g, "");
switch (output) {
case "markdown":
envinfoConfig["markdown"] = true;
break;
case "json":
envinfoConfig["json"] = true;
break;
default:
cli.logger.error(`'${output}' is not a valid value for output`);
process.exit(2);
}
}
const defaultInformation = {
Binaries: ["Node", "Yarn", "npm"],
Browsers: [
"Brave Browser",
"Chrome",
"Chrome Canary",
"Edge",
"Firefox",
"Firefox Developer Edition",
"Firefox Nightly",
"Internet Explorer",
"Safari",
"Safari Technology Preview",
],
Monorepos: ["Yarn Workspaces", "Lerna"],
System: ["OS", "CPU", "Memory"],
npmGlobalPackages: ["webpack", "webpack-cli", "webpack-dev-server"],
npmPackages: "{*webpack*,*loader*}",
};
let defaultPackages = ["webpack", "loader"];
if (typeof options.additionalPackage !== "undefined") {
defaultPackages = [...defaultPackages, ...options.additionalPackage];
}
defaultInformation.npmPackages = `{${defaultPackages
.map((item) => `*${item}*`)
.join(",")}}`;
let info = await envinfo_1.default.run(defaultInformation, envinfoConfig);
info = info.replace(/npmPackages/g, "Packages");
info = info.replace(/npmGlobalPackages/g, "Global Packages");
cli.logger.raw(info);
});
}
}
exports.default = InfoCommand;
+29
View File
@@ -0,0 +1,29 @@
{
"name": "@webpack-cli/info",
"version": "1.4.1",
"description": "Outputs info about system and webpack config",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/webpack/webpack-cli.git"
},
"homepage": "https://github.com/webpack/webpack-cli/tree/master/packages/info",
"files": [
"lib"
],
"dependencies": {
"envinfo": "^7.7.3"
},
"gitHead": "fb50f766851f500ca12867a2aa9de81fa6e368f9",
"peerDependencies": {
"webpack-cli": "4.x.x"
},
"devDependencies": {
"@types/envinfo": "^7.8.1"
}
}
+30
View File
@@ -0,0 +1,30 @@
# webpack-cli serve
[![NPM Downloads][downloads]][downloads-url]
**This package is used by webpack-cli under-the-hood and is not intended for installation as of v0.2.0**
## Description
This package contains the logic to run [webpack-dev-server](https://github.com/webpack/webpack-dev-server) to serve your webpack app and provide live reloading.
## Installation
```bash
npm i -D webpack-cli @webpack-cli/serve
```
## Usage
### CLI (via `webpack-cli`)
```bash
npx webpack-cli serve
```
### Options
Checkout [`SERVE-OPTIONS-v3.md`](https://github.com/webpack/webpack-cli/blob/master/SERVE-OPTIONS-v3.md) or [`SERVE-OPTIONS-v4.md`](https://github.com/webpack/webpack-cli/blob/master/SERVE-OPTIONS-v4.md) to see list of all available options for `serve` command for respective [`webpack-dev-server`](https://github.com/webpack/webpack-dev-server) version.
[downloads]: https://img.shields.io/npm/dm/@webpack-cli/serve.svg
[downloads-url]: https://www.npmjs.com/package/@webpack-cli/serve
+4
View File
@@ -0,0 +1,4 @@
declare class ServeCommand {
apply(cli: any): Promise<void>;
}
export default ServeCommand;
+280
View File
@@ -0,0 +1,280 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const WEBPACK_PACKAGE = process.env.WEBPACK_PACKAGE || "webpack";
const WEBPACK_DEV_SERVER_PACKAGE = process.env.WEBPACK_DEV_SERVER_PACKAGE || "webpack-dev-server";
class ServeCommand {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
async apply(cli) {
const loadDevServerOptions = () => {
// TODO simplify this after drop webpack v4 and webpack-dev-server v3
// eslint-disable-next-line @typescript-eslint/no-var-requires
const devServer = require(WEBPACK_DEV_SERVER_PACKAGE);
const isNewDevServerCLIAPI = typeof devServer.schema !== "undefined";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let options = {};
if (isNewDevServerCLIAPI) {
if (cli.webpack.cli && typeof cli.webpack.cli.getArguments === "function") {
options = cli.webpack.cli.getArguments(devServer.schema);
}
else {
options = devServer.cli.getArguments();
}
}
else {
options = require(`${WEBPACK_DEV_SERVER_PACKAGE}/bin/cli-flags`);
}
// Old options format
// { devServer: [{...}, {}...] }
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (options.devServer) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return options.devServer;
}
// New options format
// { flag1: {}, flag2: {} }
return Object.keys(options).map((key) => {
options[key].name = key;
return options[key];
});
};
await cli.makeCommand({
name: "serve [entries...]",
alias: ["server", "s"],
description: "Run the webpack dev server.",
usage: "[entries...] [options]",
pkg: "@webpack-cli/serve",
dependencies: [WEBPACK_PACKAGE, WEBPACK_DEV_SERVER_PACKAGE],
}, async () => {
let devServerFlags = [];
cli.webpack = await cli.loadWebpack();
try {
devServerFlags = loadDevServerOptions();
}
catch (error) {
cli.logger.error(`You need to install 'webpack-dev-server' for running 'webpack serve'.\n${error}`);
process.exit(2);
}
const builtInOptions = cli.getBuiltInOptions().filter(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(option) => option.name !== "watch");
return [...builtInOptions, ...devServerFlags];
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async (entries, options) => {
const builtInOptions = cli.getBuiltInOptions();
let devServerFlags = [];
try {
devServerFlags = loadDevServerOptions();
}
catch (error) {
// Nothing, to prevent future updates
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const webpackCLIOptions = {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const devServerCLIOptions = {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const processors = [];
for (const optionName in options) {
const kebabedOption = cli.toKebabCase(optionName);
// `webpack-dev-server` has own logic for the `--hot` option
const isBuiltInOption = kebabedOption !== "hot" &&
// eslint-disable-next-line @typescript-eslint/no-explicit-any
builtInOptions.find((builtInOption) => builtInOption.name === kebabedOption);
if (isBuiltInOption) {
webpackCLIOptions[optionName] = options[optionName];
}
else {
const needToProcess = devServerFlags.find(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(devServerOption) => devServerOption.name === kebabedOption && devServerOption.processor);
if (needToProcess) {
processors.push(needToProcess.processor);
}
devServerCLIOptions[optionName] = options[optionName];
}
}
for (const processor of processors) {
processor(devServerCLIOptions);
}
if (entries.length > 0) {
webpackCLIOptions.entry = [...entries, ...(webpackCLIOptions.entry || [])];
}
webpackCLIOptions.argv = Object.assign(Object.assign({}, options), { env: Object.assign({ WEBPACK_SERVE: true }, options.env) });
const compiler = await cli.createCompiler(webpackCLIOptions);
if (!compiler) {
return;
}
const servers = [];
if (cli.needWatchStdin(compiler) || devServerCLIOptions.stdin) {
// TODO remove in the next major release
// Compatibility with old `stdin` option for `webpack-dev-server`
// Should be removed for the next major release on both sides
if (devServerCLIOptions.stdin) {
delete devServerCLIOptions.stdin;
}
process.stdin.on("end", () => {
Promise.all(servers.map((server) => {
if (typeof server.stop === "function") {
return server.stop();
}
// TODO remove in the next major release
return new Promise((resolve) => {
server.close(() => {
resolve();
});
});
})).then(() => {
process.exit(0);
});
});
process.stdin.resume();
}
// eslint-disable-next-line @typescript-eslint/no-var-requires
const DevServer = require(WEBPACK_DEV_SERVER_PACKAGE);
const isNewDevServerCLIAPI = typeof DevServer.schema !== "undefined";
let devServerVersion;
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
devServerVersion = require(`${WEBPACK_DEV_SERVER_PACKAGE}/package.json`).version;
}
catch (err) {
cli.logger.error(`You need to install 'webpack-dev-server' for running 'webpack serve'.\n${err}`);
process.exit(2);
}
const compilers = typeof compiler.compilers !== "undefined" ? compiler.compilers : [compiler];
const possibleCompilers = compilers.filter((compiler) => compiler.options.devServer);
const compilersForDevServer = possibleCompilers.length > 0 ? possibleCompilers : [compilers[0]];
const isDevServer4 = devServerVersion.startsWith("4");
const usedPorts = [];
for (const compilerForDevServer of compilersForDevServer) {
let devServerOptions;
if (isNewDevServerCLIAPI) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const args = devServerFlags.reduce((accumulator, flag) => {
accumulator[flag.name] = flag;
return accumulator;
}, {});
const values = Object.keys(devServerCLIOptions).reduce(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(accumulator, name) => {
const kebabName = cli.toKebabCase(name);
if (args[kebabName]) {
accumulator[kebabName] = options[name];
}
return accumulator;
}, {});
const result = Object.assign({}, (compilerForDevServer.options.devServer || {}));
const problems = (cli.webpack.cli && typeof cli.webpack.cli.processArguments === "function"
? cli.webpack.cli
: DevServer.cli).processArguments(args, result, values);
if (problems) {
const groupBy = (xs, key) => {
return xs.reduce((rv, x) => {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
};
const problemsByPath = groupBy(problems, "path");
for (const path in problemsByPath) {
const problems = problemsByPath[path];
problems.forEach((problem) => {
cli.logger.error(`${cli.capitalizeFirstLetter(problem.type.replace(/-/g, " "))}${problem.value ? ` '${problem.value}'` : ""} for the '--${problem.argument}' option${problem.index ? ` by index '${problem.index}'` : ""}`);
if (problem.expected) {
cli.logger.error(`Expected: '${problem.expected}'`);
}
});
}
process.exit(2);
}
devServerOptions = result;
}
else {
// TODO remove in the next major release
const mergeOptions = (devServerOptions, devServerCliOptions) => {
// CLI options should take precedence over devServer options,
// and CLI options should have no default values included
const options = Object.assign(Object.assign({}, devServerOptions), devServerCliOptions);
if (devServerOptions.client && devServerCliOptions.client) {
// the user could set some client options in their devServer config,
// then also specify client options on the CLI
options.client = Object.assign(Object.assign({}, devServerOptions.client), devServerCliOptions.client);
}
return options;
};
devServerOptions = mergeOptions(compilerForDevServer.options.devServer || {}, devServerCLIOptions);
}
// TODO remove in the next major release
if (!isDevServer4) {
const getPublicPathOption = () => {
const normalizePublicPath = (publicPath) => typeof publicPath === "undefined" || publicPath === "auto" ? "/" : publicPath;
if (options.outputPublicPath) {
return normalizePublicPath(compilerForDevServer.options.output.publicPath);
}
if (devServerOptions.publicPath) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return normalizePublicPath(devServerOptions.publicPath);
}
return normalizePublicPath(compilerForDevServer.options.output.publicPath);
};
const getStatsOption = () => {
if (options.stats) {
return options.stats;
}
if (devServerOptions.stats) {
return devServerOptions.stats;
}
return compilerForDevServer.options.stats;
};
devServerOptions.host = devServerOptions.host || "localhost";
devServerOptions.port =
typeof devServerOptions.port !== "undefined" ? devServerOptions.port : 8080;
devServerOptions.stats = getStatsOption();
devServerOptions.publicPath = getPublicPathOption();
}
if (devServerOptions.port) {
const portNumber = Number(devServerOptions.port);
if (usedPorts.find((port) => portNumber === port)) {
throw new Error("Unique ports must be specified for each devServer option in your webpack configuration. Alternatively, run only 1 devServer config using the --config-name flag to specify your desired config.");
}
usedPorts.push(portNumber);
}
try {
let server;
// TODO: remove after dropping webpack-dev-server@v3
if (isDevServer4) {
server = new DevServer(devServerOptions, compiler);
}
else {
server = new DevServer(compiler, devServerOptions);
}
if (typeof server.start === "function") {
await server.start();
}
else {
// TODO remove in the next major release
server.listen(devServerOptions.port, devServerOptions.host, (error) => {
if (error) {
throw error;
}
});
}
servers.push(server);
}
catch (error) {
if (cli.isValidationError(error)) {
cli.logger.error(error.message);
}
else {
cli.logger.error(error);
}
process.exit(2);
}
}
});
}
}
exports.default = ServeCommand;
+91
View File
@@ -0,0 +1,91 @@
export declare type devServerOptionsType = {
allowedHosts?: string[] | allowedHostsEnum;
bonjour?: boolean | Record<string, any>;
client?: false | devServerClientOptions;
compress?: boolean;
dev?: Record<string, any>;
devMiddleware?: Record<string, any>;
firewall?: boolean | string[];
headers?: Record<string, unknown> | ((request: any, response: any, middlewareContext: any) => Record<string, any>);
historyApiFallback?: boolean | Record<string, unknown>;
host?: string | null | hostEnum;
hot?: boolean | hotOptionEnum;
http2?: boolean;
https?: boolean | Record<string, unknown>;
injectClient?: boolean | (() => void);
injectHot?: boolean | (() => void);
ipc?: string | true;
liveReload?: boolean;
onAfterSetupMiddleware?: () => void;
onBeforeSetupMiddleware?: () => void;
onListening?: () => void;
open?: string | boolean | openOptionObject;
openPage?: string | string[];
overlay?: boolean | Record<string, unknown>;
port?: number | string | null;
profile?: boolean;
progress?: boolean;
proxy?: Record<string, unknown> | (Record<string, unknown> | (() => void))[];
public?: string;
setupExitSignals?: boolean;
static?: boolean | string | Record<string, unknown> | (string | Record<string, unknown>)[];
transportMode?: Record<string, unknown> | string;
useLocalIp?: boolean;
publicPath?: string | (() => void);
stats?: string | boolean;
watchFiles?: string | Record<string, unknown>;
webSocketServer?: false | string | transportModeEnum | (() => any) | Record<string, unknown> | (Record<string, unknown> | (() => void))[];
};
declare enum hotOptionEnum {
only = "only"
}
declare enum hostEnum {
LocalIp = "local-ip",
LocalIpv4 = "local-ipv4",
LocalIpv6 = "local-ipv6"
}
declare enum allowedHostsEnum {
Auto = "auto",
All = "all"
}
declare enum transportModeEnum {
SockJS = "sockjs",
Ws = "ws"
}
declare type devServerClientOptions = {
host?: string;
path?: string;
port?: string | number | null;
needClientEntry?: boolean | (() => void);
needHotEntry?: boolean | (() => void);
logging?: devServerClientLogging;
overlay?: boolean | clientOverlay;
progress?: boolean;
webSocketTransport?: string | transportModeEnum;
webSocketURL?: string | webSocketURLOptions;
};
declare type webSocketURLOptions = {
hostname?: string;
pathname?: string;
port?: string | number;
password?: string;
protocol?: string | "auto";
username?: string;
};
declare type openOptionObject = {
target?: string;
app?: string;
};
declare type clientOverlay = {
errors?: boolean;
warnings?: boolean;
};
declare enum devServerClientLogging {
none = "none",
error = "error",
warn = "warn",
info = "info",
log = "log",
verbose = "verbose"
}
export {};
+31
View File
@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var hotOptionEnum;
(function (hotOptionEnum) {
hotOptionEnum["only"] = "only";
})(hotOptionEnum || (hotOptionEnum = {}));
var hostEnum;
(function (hostEnum) {
hostEnum["LocalIp"] = "local-ip";
hostEnum["LocalIpv4"] = "local-ipv4";
hostEnum["LocalIpv6"] = "local-ipv6";
})(hostEnum || (hostEnum = {}));
var allowedHostsEnum;
(function (allowedHostsEnum) {
allowedHostsEnum["Auto"] = "auto";
allowedHostsEnum["All"] = "all";
})(allowedHostsEnum || (allowedHostsEnum = {}));
var transportModeEnum;
(function (transportModeEnum) {
transportModeEnum["SockJS"] = "sockjs";
transportModeEnum["Ws"] = "ws";
})(transportModeEnum || (transportModeEnum = {}));
var devServerClientLogging;
(function (devServerClientLogging) {
devServerClientLogging["none"] = "none";
devServerClientLogging["error"] = "error";
devServerClientLogging["warn"] = "warn";
devServerClientLogging["info"] = "info";
devServerClientLogging["log"] = "log";
devServerClientLogging["verbose"] = "verbose";
})(devServerClientLogging || (devServerClientLogging = {}));
+29
View File
@@ -0,0 +1,29 @@
{
"name": "@webpack-cli/serve",
"version": "1.6.1",
"description": "",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"keywords": [],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/webpack/webpack-cli.git"
},
"homepage": "https://github.com/webpack/webpack-cli/tree/master/packages/serve",
"license": "MIT",
"files": [
"lib"
],
"peerDependencies": {
"webpack-cli": "4.x.x"
},
"peerDependenciesMeta": {
"webpack-dev-server": {
"optional": true
}
},
"gitHead": "fb50f766851f500ca12867a2aa9de81fa6e368f9"
}