Upgrade node_modules for web build

This commit is contained in:
John Colvin committed 2021-10-10 12:01:07 -05:00
1 parent 6a53c8c587
commit 5d2136faee
55430 files changed
+4714852 -3372773

No files matched your search

+970
View File
@@ -0,0 +1,970 @@
"use strict";
module.exports = {
"allowed-hosts": {
configs: [
{
type: "string",
multiple: true,
description:
"Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto').",
path: "allowedHosts[]",
},
{
description:
"Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto').",
multiple: false,
path: "allowedHosts",
type: "enum",
values: ["auto", "all"],
},
],
description:
"Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto').",
multiple: true,
simpleType: "string",
},
"allowed-hosts-reset": {
configs: [
{
type: "reset",
multiple: false,
description:
"Clear all items provided in 'allowedHosts' configuration. Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto').",
path: "allowedHosts",
},
],
description:
"Clear all items provided in 'allowedHosts' configuration. Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto').",
simpleType: "boolean",
multiple: false,
},
bonjour: {
configs: [
{
type: "boolean",
multiple: false,
description:
"Allows to broadcasts dev server via ZeroConf networking on start.",
path: "bonjour",
},
],
description:
"Allows to broadcasts dev server via ZeroConf networking on start.",
negatedDescription:
"Disallows to broadcasts dev server via ZeroConf networking on start.",
simpleType: "boolean",
multiple: false,
},
"client-web-socket-transport": {
configs: [
{
type: "enum",
values: ["sockjs", "ws"],
multiple: false,
description:
"Allows to set custom web socket transport to communicate with dev server.",
path: "client.webSocketTransport",
},
{
type: "string",
multiple: false,
description:
"Allows to set custom web socket transport to communicate with dev server.",
path: "client.webSocketTransport",
},
],
description:
"Allows to set custom web socket transport to communicate with dev server.",
simpleType: "string",
multiple: false,
},
client: {
configs: [
{
description:
"Allows to specify options for client script in the browser or disable client script.",
multiple: false,
path: "client",
type: "enum",
values: [false],
},
],
description:
"Allows to specify options for client script in the browser or disable client script.",
multiple: false,
simpleType: "boolean",
},
"client-logging": {
configs: [
{
type: "enum",
values: ["none", "error", "warn", "info", "log", "verbose"],
multiple: false,
description:
"Allows to specify options for client script in the browser or disable client script.",
path: "client.logging",
},
],
description:
"Allows to specify options for client script in the browser or disable client script.",
simpleType: "string",
multiple: false,
},
"client-progress": {
configs: [
{
type: "boolean",
multiple: false,
description:
"Prints compilation progress in percentage in the browser.",
path: "client.progress",
},
],
description: "Prints compilation progress in percentage in the browser.",
negatedDescription:
"Does not print compilation progress in percentage in the browser.",
simpleType: "boolean",
multiple: false,
},
"client-overlay": {
configs: [
{
type: "boolean",
multiple: false,
description:
"Enables a full-screen overlay in the browser when there are compiler errors or warnings.",
path: "client.overlay",
},
],
description:
"Enables a full-screen overlay in the browser when there are compiler errors or warnings.",
negatedDescription:
"Disables a full-screen overlay in the browser when there are compiler errors or warnings.",
simpleType: "boolean",
multiple: false,
},
"client-overlay-errors": {
configs: [
{
type: "boolean",
multiple: false,
description:
"Enables a full-screen overlay in the browser when there are compiler errors.",
path: "client.overlay.errors",
},
],
description:
"Enables a full-screen overlay in the browser when there are compiler errors.",
simpleType: "boolean",
multiple: false,
},
"client-overlay-warnings": {
configs: [
{
type: "boolean",
multiple: false,
description:
"Enables a full-screen overlay in the browser when there are compiler warnings.",
path: "client.overlay.warnings",
},
],
description:
"Enables a full-screen overlay in the browser when there are compiler warnings.",
simpleType: "boolean",
multiple: false,
},
"client-web-socket-url": {
configs: [
{
type: "string",
multiple: false,
description:
"Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).",
path: "client.webSocketURL",
},
],
description:
"Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).",
simpleType: "string",
multiple: false,
},
"client-web-socket-url-hostname": {
configs: [
{
type: "string",
multiple: false,
description:
"Tells clients connected to devServer to use the provided hostname.",
path: "client.webSocketURL.hostname",
},
],
description:
"Tells clients connected to devServer to use the provided hostname.",
simpleType: "string",
multiple: false,
},
"client-web-socket-url-port": {
configs: [
{
type: "number",
multiple: false,
description:
"Tells clients connected to devServer to use the provided port.",
path: "client.webSocketURL.port",
},
{
description:
"Tells clients connected to devServer to use the provided port.",
multiple: false,
path: "client.webSocketURL.port",
type: "string",
},
],
description:
"Tells clients connected to devServer to use the provided port.",
simpleType: "string",
multiple: false,
},
"client-web-socket-url-pathname": {
configs: [
{
type: "string",
multiple: false,
description:
"Tells clients connected to devServer to use the provided path to connect.",
path: "client.webSocketURL.pathname",
},
],
description:
"Tells clients connected to devServer to use the provided path to connect.",
simpleType: "string",
multiple: false,
},
"client-web-socket-url-protocol": {
configs: [
{
description:
"Tells clients connected to devServer to use the provided protocol.",
multiple: false,
path: "client.webSocketURL.protocol",
type: "enum",
values: ["auto"],
},
{
description:
"Tells clients connected to devServer to use the provided protocol.",
multiple: false,
path: "client.webSocketURL.protocol",
type: "string",
},
],
description:
"Tells clients connected to devServer to use the provided protocol.",
multiple: false,
simpleType: "string",
},
"client-web-socket-url-username": {
configs: [
{
type: "string",
multiple: false,
description:
"Tells clients connected to devServer to use the provided username to authenticate.",
path: "client.webSocketURL.username",
},
],
description:
"Tells clients connected to devServer to use the provided username to authenticate.",
simpleType: "string",
multiple: false,
},
"client-web-socket-url-password": {
configs: [
{
type: "string",
multiple: false,
description:
"Tells clients connected to devServer to use the provided password to authenticate.",
path: "client.webSocketURL.password",
},
],
description:
"Tells clients connected to devServer to use the provided password to authenticate.",
simpleType: "string",
multiple: false,
},
"web-socket-server": {
configs: [
{
type: "enum",
values: [false, "sockjs", "ws"],
multiple: false,
description:
"Allows to set web socket server and options (by default 'ws').",
path: "webSocketServer",
},
{
type: "string",
multiple: false,
description:
"Allows to set web socket server and options (by default 'ws').",
path: "webSocketServer",
},
],
description:
"Allows to set web socket server and options (by default 'ws').",
simpleType: "string",
multiple: false,
},
compress: {
configs: [
{
type: "boolean",
multiple: false,
description: "Enables gzip compression for everything served.",
path: "compress",
},
],
description: "Enables gzip compression for everything served.",
negatedDescription: "Disables gzip compression for everything served.",
simpleType: "boolean",
multiple: false,
},
"history-api-fallback": {
configs: [
{
type: "boolean",
multiple: false,
description:
"Allows to proxy requests through a specified index page (by default 'index.html'), useful for Single Page Applications that utilise the HTML5 History API.",
path: "historyApiFallback",
},
],
description:
"Allows to proxy requests through a specified index page (by default 'index.html'), useful for Single Page Applications that utilise the HTML5 History API.",
simpleType: "boolean",
multiple: false,
},
host: {
configs: [
{
description: "Allows to specify a hostname to use.",
multiple: false,
path: "host",
type: "enum",
values: ["local-ip", "local-ipv4", "local-ipv6"],
},
{
description: "Allows to specify a hostname to use.",
multiple: false,
path: "host",
type: "string",
},
],
description: "Allows to specify a hostname to use.",
simpleType: "string",
multiple: false,
},
hot: {
configs: [
{
type: "boolean",
multiple: false,
description: "Enables Hot Module Replacement.",
path: "hot",
},
{
type: "enum",
values: ["only"],
multiple: false,
description: "Enables Hot Module Replacement.",
path: "hot",
},
],
description: "Enables Hot Module Replacement.",
negatedDescription: "Disables Hot Module Replacement.",
simpleType: "string",
multiple: false,
},
http2: {
configs: [
{
type: "boolean",
multiple: false,
description: "Allows to serve over HTTP/2 using SPDY.",
path: "http2",
},
],
description: "Allows to serve over HTTP/2 using SPDY.",
negatedDescription: "Does not serve over HTTP/2 using SPDY.",
simpleType: "boolean",
multiple: false,
},
https: {
configs: [
{
type: "boolean",
multiple: false,
description:
"Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).",
path: "https",
},
],
description:
"Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).",
negatedDescription:
"Disallows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).",
simpleType: "boolean",
multiple: false,
},
"https-passphrase": {
configs: [
{
type: "string",
multiple: false,
description: "Passphrase for a pfx file.",
path: "https.passphrase",
},
],
description: "Passphrase for a pfx file.",
simpleType: "string",
multiple: false,
},
"https-request-cert": {
configs: [
{
type: "boolean",
multiple: false,
description: "Request for an SSL certificate.",
path: "https.requestCert",
},
],
description: "Request for an SSL certificate.",
negatedDescription: "Does not request for an SSL certificate.",
simpleType: "boolean",
multiple: false,
},
"https-ca": {
configs: [
{
type: "string",
multiple: true,
description:
"Path to an SSL CA certificate or content of an SSL CA certificate.",
path: "https.ca[]",
},
],
description:
"Path to an SSL CA certificate or content of an SSL CA certificate.",
simpleType: "string",
multiple: true,
},
"https-ca-reset": {
configs: [
{
description:
"Clear all items provided in 'https.ca' configuration. Path to an SSL CA certificate or content of an SSL CA certificate.",
multiple: false,
path: "https.ca",
type: "reset",
},
],
description:
"Clear all items provided in 'https.ca' configuration. Path to an SSL CA certificate or content of an SSL CA certificate.",
multiple: false,
simpleType: "boolean",
},
"https-cacert": {
configs: [
{
type: "string",
multiple: true,
description:
"Path to an SSL CA certificate or content of an SSL CA certificate.",
path: "https.cacert[]",
},
],
description:
"Path to an SSL CA certificate or content of an SSL CA certificate.",
simpleType: "string",
multiple: true,
},
"https-cacert-reset": {
configs: [
{
description:
"Clear all items provided in 'https.cacert' configuration. Path to an SSL CA certificate or content of an SSL CA certificate.",
multiple: false,
path: "https.cacert",
type: "reset",
},
],
description:
"Clear all items provided in 'https.cacert' configuration. Path to an SSL CA certificate or content of an SSL CA certificate.",
multiple: false,
simpleType: "boolean",
},
"https-key": {
configs: [
{
type: "string",
multiple: true,
description: "Path to an SSL key or content of an SSL key.",
path: "https.key[]",
},
],
description: "Path to an SSL key or content of an SSL key.",
simpleType: "string",
multiple: true,
},
"https-key-reset": {
configs: [
{
description:
"Clear all items provided in 'https.key' configuration. Path to an SSL key or content of an SSL key.",
multiple: false,
path: "https.key",
type: "reset",
},
],
description:
"Clear all items provided in 'https.key' configuration. Path to an SSL key or content of an SSL key.",
multiple: false,
simpleType: "boolean",
},
"https-pfx": {
configs: [
{
type: "string",
multiple: true,
description: "Path to an SSL pfx file or content of an SSL pfx file.",
path: "https.pfx[]",
},
],
description: "Path to an SSL pfx file or content of an SSL pfx file.",
simpleType: "string",
multiple: true,
},
"https-pfx-reset": {
configs: [
{
description:
"Clear all items provided in 'https.pfx' configuration. Path to an SSL pfx file or content of an SSL pfx file.",
multiple: false,
path: "https.pfx",
type: "reset",
},
],
description:
"Clear all items provided in 'https.pfx' configuration. Path to an SSL pfx file or content of an SSL pfx file.",
multiple: false,
simpleType: "boolean",
},
"https-cert": {
configs: [
{
type: "string",
multiple: true,
description:
"Path to an SSL certificate or content of an SSL certificate.",
path: "https.cert[]",
},
],
description: "Path to an SSL certificate or content of an SSL certificate.",
simpleType: "string",
multiple: true,
},
"https-cert-reset": {
configs: [
{
description:
"Clear all items provided in 'https.cert' configuration. Path to an SSL certificate or content of an SSL certificate.",
multiple: false,
path: "https.cert",
type: "reset",
},
],
description:
"Clear all items provided in 'https.cert' configuration. Path to an SSL certificate or content of an SSL certificate.",
multiple: false,
simpleType: "boolean",
},
"https-crl": {
configs: [
{
description:
"Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists).",
multiple: true,
path: "https.crl[]",
type: "string",
},
],
description:
"Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists).",
multiple: true,
simpleType: "string",
},
"https-crl-reset": {
configs: [
{
description:
"Clear all items provided in 'https.crl' configuration. Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists).",
multiple: false,
path: "https.crl",
type: "reset",
},
],
description:
"Clear all items provided in 'https.crl' configuration. Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists).",
multiple: false,
simpleType: "boolean",
},
ipc: {
configs: [
{
type: "string",
multiple: false,
description: "Listen to a unix socket.",
path: "ipc",
},
{
type: "enum",
values: [true],
multiple: false,
description: "Listen to a unix socket.",
path: "ipc",
},
],
description: "Listen to a unix socket.",
simpleType: "string",
multiple: false,
},
"live-reload": {
configs: [
{
type: "boolean",
multiple: false,
description:
"Enables reload/refresh the page(s) when file changes are detected (enabled by default).",
path: "liveReload",
},
],
description:
"Enables reload/refresh the page(s) when file changes are detected (enabled by default).",
negatedDescription:
"Disables reload/refresh the page(s) when file changes are detected (enabled by default)",
simpleType: "boolean",
multiple: false,
},
"magic-html": {
configs: [
{
type: "boolean",
multiple: false,
description:
"Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').",
path: "magicHtml",
},
],
description:
"Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').",
negatedDescription:
"Disables magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').",
simpleType: "boolean",
multiple: false,
},
open: {
configs: [
{
type: "string",
multiple: true,
description:
"Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).",
path: "open[]",
},
{
type: "boolean",
multiple: false,
description:
"Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).",
path: "open",
},
],
description:
"Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).",
negatedDescription: "Does not open the default browser.",
simpleType: "string",
multiple: true,
},
"open-target": {
configs: [
{
type: "string",
multiple: true,
description: "Opens specified page in browser.",
path: "open[].target",
},
{
type: "string",
multiple: true,
description: "Opens specified page in browser.",
path: "open.target[]",
},
],
description: "Opens specified page in browser.",
negatedDescription: "Does not open specified page in browser.",
simpleType: "string",
multiple: true,
},
"open-app-name": {
configs: [
{
type: "string",
multiple: true,
description: "Open specified browser.",
path: "open[].app.name",
},
{
type: "string",
multiple: true,
description: "Open specified browser.",
path: "open.app.name[]",
},
],
description: "Open specified browser.",
simpleType: "string",
multiple: true,
},
"open-app": {
configs: [
{
type: "string",
multiple: true,
description: "Open specified browser.",
path: "open[].app",
},
],
description: "Open specified browser.",
simpleType: "string",
multiple: true,
},
"open-reset": {
configs: [
{
type: "reset",
multiple: false,
description:
"Clear all items provided in 'open' configuration. Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).",
path: "open",
},
],
description:
"Clear all items provided in 'open' configuration. Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).",
simpleType: "boolean",
multiple: false,
},
"open-target-reset": {
configs: [
{
type: "reset",
multiple: false,
description:
"Clear all items provided in 'open.target' configuration. Opens specified page in browser.",
path: "open.target",
},
],
description:
"Clear all items provided in 'open.target' configuration. Opens specified page in browser.",
simpleType: "boolean",
multiple: false,
},
"open-app-name-reset": {
configs: [
{
type: "reset",
multiple: false,
description:
"Clear all items provided in 'open.app.name' configuration. Open specified browser.",
path: "open.app.name",
},
],
description:
"Clear all items provided in 'open.app.name' configuration. Open specified browser.",
simpleType: "boolean",
multiple: false,
},
port: {
configs: [
{
type: "number",
multiple: false,
description: "Allows to specify a port to use.",
path: "port",
},
{
type: "string",
multiple: false,
description: "Allows to specify a port to use.",
path: "port",
},
{
type: "enum",
values: ["auto"],
multiple: false,
description: "Allows to specify a port to use.",
path: "port",
},
],
description: "Allows to specify a port to use.",
simpleType: "string",
multiple: false,
},
static: {
configs: [
{
type: "string",
multiple: true,
description:
"Allows to configure options for serving static files from directory (by default 'public' directory).",
path: "static[]",
},
{
type: "boolean",
multiple: false,
description:
"Allows to configure options for serving static files from directory (by default 'public' directory).",
path: "static",
},
],
description:
"Allows to configure options for serving static files from directory (by default 'public' directory).",
simpleType: "string",
multiple: true,
},
"static-directory": {
configs: [
{
type: "string",
multiple: true,
description: "Directory for static contents.",
path: "static[].directory",
},
],
description: "Directory for static contents.",
simpleType: "string",
multiple: true,
},
"static-public-path": {
configs: [
{
type: "string",
multiple: true,
description:
"The static files will be available in the browser under this public path.",
path: "static[].publicPath",
},
{
type: "string",
multiple: true,
description:
"The static files will be available in the browser under this public path.",
path: "static.publicPath[]",
},
],
description:
"The static files will be available in the browser under this public path.",
simpleType: "string",
multiple: true,
},
"static-serve-index": {
configs: [
{
type: "boolean",
multiple: true,
description:
"Tells dev server to use serveIndex middleware when enabled.",
path: "static[].serveIndex",
},
],
description: "Tells dev server to use serveIndex middleware when enabled.",
negatedDescription:
"Does not tell dev server to use serveIndex middleware.",
simpleType: "boolean",
multiple: true,
},
"static-watch": {
configs: [
{
type: "boolean",
multiple: true,
description: "Watches for files in static content directory.",
path: "static[].watch",
},
],
description: "Watches for files in static content directory.",
negatedDescription: "Does not watch for files in static content directory.",
simpleType: "boolean",
multiple: true,
},
"static-reset": {
configs: [
{
type: "reset",
multiple: false,
description:
"Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public' directory).",
path: "static",
},
],
description:
"Clear all items provided in 'static' configuration. Allows to configure options for serving static files from directory (by default 'public' directory).",
simpleType: "boolean",
multiple: false,
},
"static-public-path-reset": {
configs: [
{
type: "reset",
multiple: false,
description:
"Clear all items provided in 'static.publicPath' configuration. The static files will be available in the browser under this public path.",
path: "static.publicPath",
},
],
description:
"Clear all items provided in 'static.publicPath' configuration. The static files will be available in the browser under this public path.",
simpleType: "boolean",
multiple: false,
},
"watch-files": {
configs: [
{
type: "string",
multiple: true,
description:
"Allows to configure list of globs/directories/files to watch for file changes.",
path: "watchFiles[]",
},
],
description:
"Allows to configure list of globs/directories/files to watch for file changes.",
simpleType: "string",
multiple: true,
},
"watch-files-reset": {
configs: [
{
type: "reset",
multiple: false,
description:
"Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes.",
path: "watchFiles",
},
],
description:
"Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes.",
simpleType: "boolean",
multiple: false,
},
};
+332
View File
@@ -0,0 +1,332 @@
"use strict";
const path = require("path");
// Based on https://github.com/webpack/webpack/blob/master/lib/cli.js
// Please do not modify it
const cliAddedItems = new WeakMap();
const getObjectAndProperty = (config, schemaPath, index = 0) => {
if (!schemaPath) {
return { value: config };
}
const parts = schemaPath.split(".");
const property = parts.pop();
let current = config;
let i = 0;
for (const part of parts) {
const isArray = part.endsWith("[]");
const name = isArray ? part.slice(0, -2) : part;
let value = current[name];
if (isArray) {
// eslint-disable-next-line no-undefined
if (value === undefined) {
value = {};
current[name] = [...Array.from({ length: index }), value];
cliAddedItems.set(current[name], index + 1);
} else if (!Array.isArray(value)) {
return {
problem: {
type: "unexpected-non-array-in-path",
path: parts.slice(0, i).join("."),
},
};
} else {
let addedItems = cliAddedItems.get(value) || 0;
while (addedItems <= index) {
// eslint-disable-next-line no-undefined
value.push(undefined);
// eslint-disable-next-line no-plusplus
addedItems++;
}
cliAddedItems.set(value, addedItems);
const x = value.length - addedItems + index;
// eslint-disable-next-line no-undefined
if (value[x] === undefined) {
value[x] = {};
} else if (value[x] === null || typeof value[x] !== "object") {
return {
problem: {
type: "unexpected-non-object-in-path",
path: parts.slice(0, i).join("."),
},
};
}
value = value[x];
}
// eslint-disable-next-line no-undefined
} else if (value === undefined) {
// eslint-disable-next-line no-multi-assign
value = current[name] = {};
} else if (value === null || typeof value !== "object") {
return {
problem: {
type: "unexpected-non-object-in-path",
path: parts.slice(0, i).join("."),
},
};
}
current = value;
// eslint-disable-next-line no-plusplus
i++;
}
const value = current[property];
if (property.endsWith("[]")) {
const name = property.slice(0, -2);
// eslint-disable-next-line no-shadow
const value = current[name];
// eslint-disable-next-line no-undefined
if (value === undefined) {
// eslint-disable-next-line no-undefined
current[name] = [...Array.from({ length: index }), undefined];
cliAddedItems.set(current[name], index + 1);
// eslint-disable-next-line no-undefined
return { object: current[name], property: index, value: undefined };
} else if (!Array.isArray(value)) {
// eslint-disable-next-line no-undefined
current[name] = [value, ...Array.from({ length: index }), undefined];
cliAddedItems.set(current[name], index + 1);
// eslint-disable-next-line no-undefined
return { object: current[name], property: index + 1, value: undefined };
}
let addedItems = cliAddedItems.get(value) || 0;
while (addedItems <= index) {
// eslint-disable-next-line no-undefined
value.push(undefined);
// eslint-disable-next-line no-plusplus
addedItems++;
}
cliAddedItems.set(value, addedItems);
const x = value.length - addedItems + index;
// eslint-disable-next-line no-undefined
if (value[x] === undefined) {
value[x] = {};
} else if (value[x] === null || typeof value[x] !== "object") {
return {
problem: {
type: "unexpected-non-object-in-path",
path: schemaPath,
},
};
}
return {
object: value,
property: x,
value: value[x],
};
}
return { object: current, property, value };
};
const parseValueForArgumentConfig = (argConfig, value) => {
// eslint-disable-next-line default-case
switch (argConfig.type) {
case "string":
if (typeof value === "string") {
return value;
}
break;
case "path":
if (typeof value === "string") {
return path.resolve(value);
}
break;
case "number":
if (typeof value === "number") {
return value;
}
if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) {
const n = +value;
if (!isNaN(n)) return n;
}
break;
case "boolean":
if (typeof value === "boolean") {
return value;
}
if (value === "true") {
return true;
}
if (value === "false") {
return false;
}
break;
case "RegExp":
if (value instanceof RegExp) {
return value;
}
if (typeof value === "string") {
// cspell:word yugi
const match = /^\/(.*)\/([yugi]*)$/.exec(value);
if (match && !/[^\\]\//.test(match[1])) {
return new RegExp(match[1], match[2]);
}
}
break;
case "enum":
if (argConfig.values.includes(value)) {
return value;
}
for (const item of argConfig.values) {
if (`${item}` === value) return item;
}
break;
case "reset":
if (value === true) {
return [];
}
break;
}
};
const getExpectedValue = (argConfig) => {
switch (argConfig.type) {
default:
return argConfig.type;
case "boolean":
return "true | false";
case "RegExp":
return "regular expression (example: /ab?c*/)";
case "enum":
return argConfig.values.map((v) => `${v}`).join(" | ");
case "reset":
return "true (will reset the previous value to an empty array)";
}
};
const setValue = (config, schemaPath, value, index) => {
const { problem, object, property } = getObjectAndProperty(
config,
schemaPath,
index
);
if (problem) {
return problem;
}
object[property] = value;
return null;
};
const processArgumentConfig = (argConfig, config, value, index) => {
// eslint-disable-next-line no-undefined
if (index !== undefined && !argConfig.multiple) {
return {
type: "multiple-values-unexpected",
path: argConfig.path,
};
}
const parsed = parseValueForArgumentConfig(argConfig, value);
// eslint-disable-next-line no-undefined
if (parsed === undefined) {
return {
type: "invalid-value",
path: argConfig.path,
expected: getExpectedValue(argConfig),
};
}
const problem = setValue(config, argConfig.path, parsed, index);
if (problem) {
return problem;
}
return null;
};
const processArguments = (args, config, values) => {
const problems = [];
for (const key of Object.keys(values)) {
const arg = args[key];
if (!arg) {
problems.push({
type: "unknown-argument",
path: "",
argument: key,
});
// eslint-disable-next-line no-continue
continue;
}
const processValue = (value, i) => {
const currentProblems = [];
for (const argConfig of arg.configs) {
const problem = processArgumentConfig(argConfig, config, value, i);
if (!problem) {
return;
}
currentProblems.push({
...problem,
argument: key,
value,
index: i,
});
}
problems.push(...currentProblems);
};
const value = values[key];
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
processValue(value[i], i);
}
} else {
// eslint-disable-next-line no-undefined
processValue(value, undefined);
}
}
if (problems.length === 0) {
return null;
}
return problems;
};
module.exports = processArguments;
+174
View File
@@ -0,0 +1,174 @@
#!/usr/bin/env node
/* Based on webpack/bin/webpack.js */
/* eslint-disable no-console */
"use strict";
/**
* @param {string} command process to run
* @param {string[]} args command line arguments
* @returns {Promise<void>} promise
*/
const runCommand = (command, args) => {
const cp = require("child_process");
return new Promise((resolve, reject) => {
const executedCommand = cp.spawn(command, args, {
stdio: "inherit",
shell: true,
});
executedCommand.on("error", (error) => {
reject(error);
});
executedCommand.on("exit", (code) => {
if (code === 0) {
resolve();
} else {
reject();
}
});
});
};
/**
* @param {string} packageName name of the package
* @returns {boolean} is the package installed?
*/
const isInstalled = (packageName) => {
if (process.versions.pnp) {
return true;
}
const path = require("path");
const fs = require("graceful-fs");
let dir = __dirname;
do {
try {
if (
fs.statSync(path.join(dir, "node_modules", packageName)).isDirectory()
) {
return true;
}
} catch (_error) {
// Nothing
}
// eslint-disable-next-line no-cond-assign
} while (dir !== (dir = path.dirname(dir)));
return false;
};
/**
* @param {CliOption} cli options
* @returns {void}
*/
const runCli = (cli) => {
if (cli.preprocess) {
cli.preprocess();
}
const path = require("path");
const pkgPath = require.resolve(`${cli.package}/package.json`);
// eslint-disable-next-line import/no-dynamic-require
const pkg = require(pkgPath);
// eslint-disable-next-line import/no-dynamic-require
require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
};
/**
* @typedef {Object} CliOption
* @property {string} name display name
* @property {string} package npm package name
* @property {string} binName name of the executable file
* @property {boolean} installed currently installed?
* @property {string} url homepage
* @property {function} preprocess preprocessor
*/
/** @type {CliOption} */
const cli = {
name: "webpack-cli",
package: "webpack-cli",
binName: "webpack-cli",
installed: isInstalled("webpack-cli"),
url: "https://github.com/webpack/webpack-cli",
preprocess() {
process.argv.splice(2, 0, "serve");
},
};
if (!cli.installed) {
const path = require("path");
const fs = require("graceful-fs");
const readLine = require("readline");
const notify = `CLI for webpack must be installed.\n ${cli.name} (${cli.url})\n`;
console.error(notify);
let packageManager;
if (fs.existsSync(path.resolve(process.cwd(), "yarn.lock"))) {
packageManager = "yarn";
} else if (fs.existsSync(path.resolve(process.cwd(), "pnpm-lock.yaml"))) {
packageManager = "pnpm";
} else {
packageManager = "npm";
}
const installOptions = [packageManager === "yarn" ? "add" : "install", "-D"];
console.error(
`We will use "${packageManager}" to install the CLI via "${packageManager} ${installOptions.join(
" "
)} ${cli.package}".`
);
const question = `Do you want to install 'webpack-cli' (yes/no): `;
const questionInterface = readLine.createInterface({
input: process.stdin,
output: process.stderr,
});
// In certain scenarios (e.g. when STDIN is not in terminal mode), the callback function will not be
// executed. Setting the exit code here to ensure the script exits correctly in those cases. The callback
// function is responsible for clearing the exit code if the user wishes to install webpack-cli.
process.exitCode = 1;
questionInterface.question(question, (answer) => {
questionInterface.close();
const normalizedAnswer = answer.toLowerCase().startsWith("y");
if (!normalizedAnswer) {
console.error(
"You need to install 'webpack-cli' to use webpack via CLI.\n" +
"You can also install the CLI manually."
);
return;
}
process.exitCode = 0;
console.log(
`Installing '${
cli.package
}' (running '${packageManager} ${installOptions.join(" ")} ${
cli.package
}')...`
);
runCommand(packageManager, installOptions.concat(cli.package))
.then(() => {
runCli(cli);
})
.catch((error) => {
console.error(error);
process.exitCode = 1;
});
});
} else {
runCli(cli);
}