Skip to content

Commit

Permalink
fix: exit on undefined behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed Nov 22, 2023
1 parent edc6b56 commit 6d93622
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 102 deletions.
56 changes: 11 additions & 45 deletions packages/serve/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ class ServeCommand {
const loadDevServerOptions = () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const devServer = require(WEBPACK_DEV_SERVER_PACKAGE);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const options: Record<string, any> = cli.webpack.cli.getArguments(devServer.schema);

// New options format
// { flag1: {}, flag2: {} }
return Object.keys(options).map((key) => {
Expand Down Expand Up @@ -69,7 +67,6 @@ class ServeCommand {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const processors: Array<(opts: Record<string, any>) => void> = [];

for (const optionName in options) {
const kebabedOption = cli.toKebabCase(optionName);
const isBuiltInOption = builtInOptions.find(
Expand All @@ -93,7 +90,6 @@ class ServeCommand {
devServerCLIOptions[optionName] = options[optionName];
}
}

for (const processor of processors) {
processor(devServerCLIOptions);
}
Expand All @@ -108,13 +104,11 @@ class ServeCommand {
};

webpackCLIOptions.isWatchingLikeCommand = true;

const compiler = await cli.createCompiler(webpackCLIOptions);

if (!compiler) {
return;
}

const servers: (typeof DevServer)[] = [];

if (cli.needWatchStdin(compiler)) {
Expand Down Expand Up @@ -152,7 +146,16 @@ class ServeCommand {
const usedPorts: number[] = [];

for (const compilerForDevServer of compilersForDevServer) {
let devServerOptions: devServerOptionsType | false;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const args = devServerFlags.reduce((accumulator: Record<string, any>, flag: any) => {
accumulator[flag.name] = flag;

return accumulator;
}, {});
const values = Object.keys(devServerCLIOptions).reduce(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(accumulator: Record<string, any>, name: string) => {
const kebabName = cli.toKebabCase(name);

if (args[kebabName]) {
accumulator[kebabName] = options[name];
Expand Down Expand Up @@ -201,44 +204,7 @@ class ServeCommand {
process.exit(2);
}

if (devServerOptions === false) {
continue;
}

// TODO remove in the next major release
if (!isDevServer4) {
const getPublicPathOption = (): string => {
const normalizePublicPath = (publicPath): string =>
typeof publicPath === "undefined" || publicPath === "auto" ? "/" : publicPath;

if (options.outputPublicPath) {
return normalizePublicPath(compilerForDevServer.options.output.publicPath);
}

if (devServerOptions !== false && devServerOptions.publicPath) {
return normalizePublicPath(devServerOptions.publicPath);
}

return normalizePublicPath(compilerForDevServer.options.output.publicPath);
};
const getStatsOption = (): string | boolean => {
if (options.stats) {
return options.stats;
}

if (devServerOptions !== false && devServerOptions.stats) {
return devServerOptions.stats;
}

return compilerForDevServer.options.stats;
};

devServerOptions.host = devServerOptions.host || "localhost";
devServerOptions.port = devServerOptions.port || 8080;
devServerOptions.stats = getStatsOption();
devServerOptions.publicPath = getPublicPathOption();
}

const devServerOptions: WebpackDevServerOptions = result as WebpackDevServerOptions;
if (devServerOptions.port) {
const portNumber = Number(devServerOptions.port);

Expand Down
7 changes: 5 additions & 2 deletions packages/webpack-cli/src/webpack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2378,10 +2378,13 @@ class WebpackCLI implements IWebpackCLI {
} else if (typeof options.nodeEnv === "string") {
process.env.NODE_ENV = options.nodeEnv;
}

let config = await this.loadConfig(options);
config = await this.buildConfig(config, options);

const { devServer } = config.options as boolean | WebpackDevServerOptions["options"];
const devServerIsFalse = devServer !== undefined && devServer === false;
if (devServerIsFalse && options.argv && options.argv.env && options.argv.env.WEBPACK_SERVE) {
process.exit(0);
}
let compiler: WebpackCompiler;
try {
compiler = this.webpack(
Expand Down
113 changes: 58 additions & 55 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3173,77 +3173,80 @@
"@typescript-eslint/types" "5.62.0"
eslint-visitor-keys "^3.3.0"

"@typescript-eslint/[email protected]":
version "4.31.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.31.0.tgz#9be33aed4e9901db753803ba233b70d79a87fc3e"
integrity sha512-LJ+xtl34W76JMRLjbaQorhR0hfRAlp3Lscdiz9NeI/8i+q0hdBZ7BsiYieLoYWqy+AnRigaD3hUwPFugSzdocg==
dependencies:
"@typescript-eslint/types" "4.31.0"
"@typescript-eslint/visitor-keys" "4.31.0"

"@typescript-eslint/[email protected]":
version "4.31.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.31.0.tgz#9a7c86fcc1620189567dc4e46cad7efa07ee8dce"
integrity sha512-9XR5q9mk7DCXgXLS7REIVs+BaAswfdHhx91XqlJklmqWpTALGjygWVIb/UnLh4NWhfwhR5wNe1yTyCInxVhLqQ==

"@typescript-eslint/[email protected]":
version "4.31.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.31.0.tgz#4da4cb6274a7ef3b21d53f9e7147cc76f278a078"
integrity sha512-QHl2014t3ptg+xpmOSSPn5hm4mY8D4s97ftzyk9BZ8RxYQ3j73XcwuijnJ9cMa6DO4aLXeo8XS3z1omT9LA/Eg==
dependencies:
"@typescript-eslint/types" "4.31.0"
"@typescript-eslint/visitor-keys" "4.31.0"
debug "^4.3.1"
globby "^11.0.3"
is-glob "^4.0.1"
semver "^7.3.5"
tsutils "^3.21.0"
"@ungap/structured-clone@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406"
integrity sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==

"@typescript-eslint/[email protected]":
version "4.31.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.31.0.tgz#4e87b7761cb4e0e627dc2047021aa693fc76ea2b"
integrity sha512-HUcRp2a9I+P21+O21yu3ezv3GEPGjyGiXoEUQwZXjR8UxRApGeLyWH4ZIIUSalE28aG4YsV6GjtaAVB3QKOu0w==
"@webassemblyjs/[email protected]":
version "1.11.5"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.5.tgz#6e818036b94548c1fb53b754b5cae3c9b208281c"
integrity sha512-LHY/GSAZZRpsNQH+/oHqhRQ5FT7eoULcBqgfyTB5nQHogFnK3/7QoN7dLnwSE/JkUAF0SrRuclT7ODqMFtWxxQ==
dependencies:
"@typescript-eslint/types" "4.31.0"
eslint-visitor-keys "^2.0.0"
"@webassemblyjs/helper-numbers" "1.11.5"
"@webassemblyjs/helper-wasm-bytecode" "1.11.5"

"@webassemblyjs/[email protected].1":
version "1.11.1"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7"
integrity sha512-ukBh14qFLjxTQNTXocdyksN5QdM28S1CxHt2rdskFyL+xFV7VremuBLVbmCePj+URalXBENx/9Lm7lnhihtCSw==
"@webassemblyjs/ast@^1.11.5":
version "1.11.6"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.6.tgz#db046555d3c413f8966ca50a95176a0e2c642e24"
integrity sha512-IN1xI7PwOvLPgjcf180gC1bqn3q/QaOCwYUahIOhbYUu8KA/3tw2RT/T0Gidi1l7Hhj5D/INhJxiICObqpMu4Q==
dependencies:
"@webassemblyjs/helper-numbers" "1.11.1"
"@webassemblyjs/helper-wasm-bytecode" "1.11.1"
"@webassemblyjs/helper-numbers" "1.11.6"
"@webassemblyjs/helper-wasm-bytecode" "1.11.6"

"@webassemblyjs/[email protected]":
version "1.11.5"
resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.5.tgz#e85dfdb01cad16b812ff166b96806c050555f1b4"
integrity sha512-1j1zTIC5EZOtCplMBG/IEwLtUojtwFVwdyVMbL/hwWqbzlQoJsWCOavrdnLkemwNoC/EOwtUFch3fuo+cbcXYQ==

"@webassemblyjs/[email protected].1":
version "1.11.1"
resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.1.tgz#f6c61a705f0fd7a6aecaa4e8198f23d9dc179e4f"
integrity sha512-iGRfyc5Bq+NnNuX8b5hwBrRjzf0ocrJPI6GWFodBFzmFnyvrQ83SHKhmilCU/8Jv67i4GJZBMhEzltxzcNagtQ==
"@webassemblyjs/[email protected].6":
version "1.11.6"
resolved "https://registry.yarnpkg.com/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.6.tgz#dacbcb95aff135c8260f77fa3b4c5fea600a6431"
integrity sha512-ejAj9hfRJ2XMsNHk/v6Fu2dGS+i4UaXBXGemOfQ/JfQ6mdQg/WXtwleQRLLS4OvfDhv8rYnVwH27YJLMyYsxhw==

"@webassemblyjs/[email protected].1":
version "1.11.1"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.1.tgz#1a63192d8788e5c012800ba6a7a46c705288fd16"
integrity sha512-RlhS8CBCXfRUR/cwo2ho9bkheSXG0+NwooXcc3PAILALf2QLdFyj7KGsKRbVc95hZnhnERon4kW/D3SZpp6Tcg==
"@webassemblyjs/[email protected].5":
version "1.11.5"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.5.tgz#1e82fa7958c681ddcf4eabef756ce09d49d442d1"
integrity sha512-L65bDPmfpY0+yFrsgz8b6LhXmbbs38OnwDCf6NpnMUYqa+ENfE5Dq9E42ny0qz/PdR0LJyq/T5YijPnU8AXEpA==

"@webassemblyjs/helper-buffer@1.11.1":
version "1.11.1"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.1.tgz#832a900eb444884cde9a7cad467f81500f5e5ab5"
integrity sha512-gwikF65aDNeeXa8JxXa2BAk+REjSyhrNC9ZwdT0f8jc4dQQeDQ7G4m0f2QCLPJiMTTO6wfDmRmj/pW0PsUvIcA==
"@webassemblyjs/helper-api-error@1.11.6":
version "1.11.6"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.6.tgz#6132f68c4acd59dcd141c44b18cbebbd9f2fa768"
integrity sha512-o0YkoP4pVu4rN8aTJgAyj9hC2Sv5UlkzCHhxqWj8butaLvnpdc2jOwh4ewE6CX0txSfLn/UYaV/pheS2Txg//Q==

"@webassemblyjs/[email protected]":
version "1.11.1"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.1.tgz#64d81da219fbbba1e3bd1bfc74f6e8c4e10a62ae"
integrity sha512-vDkbxiB8zfnPdNK9Rajcey5C0w+QJugEglN0of+kmO8l7lDb77AnlKYQF7aarZuCrv+l0UvqL+68gSDr3k9LPQ==
"@webassemblyjs/[email protected]":
version "1.11.5"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-buffer/-/helper-buffer-1.11.5.tgz#91381652ea95bb38bbfd270702351c0c89d69fba"
integrity sha512-fDKo1gstwFFSfacIeH5KfwzjykIE6ldh1iH9Y/8YkAZrhmu4TctqYjSh7t0K2VyDSXOZJ1MLhht/k9IvYGcIxg==

"@webassemblyjs/[email protected]":
version "1.11.5"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.5.tgz#23380c910d56764957292839006fecbe05e135a9"
integrity sha512-DhykHXM0ZABqfIGYNv93A5KKDw/+ywBFnuWybZZWcuzWHfbp21wUfRkbtz7dMGwGgT4iXjWuhRMA2Mzod6W4WA==
dependencies:
"@webassemblyjs/floating-point-hex-parser" "1.11.5"
"@webassemblyjs/helper-api-error" "1.11.5"
"@xtuc/long" "4.2.2"

"@webassemblyjs/[email protected]":
version "1.11.6"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.6.tgz#cbce5e7e0c1bd32cf4905ae444ef64cea919f1b5"
integrity sha512-vUIhZ8LZoIWHBohiEObxVm6hwP034jwmc9kuq5GdHZH0wiLVLIPcMCdpJzG4C11cHoQ25TFIQj9kaVADVX7N3g==
dependencies:
"@webassemblyjs/floating-point-hex-parser" "1.11.1"
"@webassemblyjs/helper-api-error" "1.11.1"
"@webassemblyjs/floating-point-hex-parser" "1.11.6"
"@webassemblyjs/helper-api-error" "1.11.6"
"@xtuc/long" "4.2.2"

"@webassemblyjs/[email protected]":
version "1.11.5"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.5.tgz#e258a25251bc69a52ef817da3001863cc1c24b9f"
integrity sha512-oC4Qa0bNcqnjAowFn7MPCETQgDYytpsfvz4ujZz63Zu/a/v71HeCAAmZsgZ3YVKec3zSPYytG3/PrRCqbtcAvA==

"@webassemblyjs/[email protected]":
version "1.11.6"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.6.tgz#bb2ebdb3b83aa26d9baad4c46d4315283acd51e9"
integrity sha512-sFFHKwcmBprO9e7Icf0+gddyWYDViL8bpPjJJl0WHxCdETktXdmtWLGVzoHbqUcY4Be1LkNfwTmXOJUFZYSJdA==

"@webassemblyjs/[email protected]":
version "1.11.5"
resolved "https://registry.yarnpkg.com/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.11.5.tgz#966e855a6fae04d5570ad4ec87fbcf29b42ba78e"
Expand Down

0 comments on commit 6d93622

Please sign in to comment.