Skip to content

Commit

Permalink
fix: compatibility with experiments.buildHttp (#4585)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Sep 27, 2022
1 parent b857e6f commit 5b846cb
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 49 deletions.
55 changes: 41 additions & 14 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,45 @@ class Server {
return path.resolve(dir, "node_modules/.cache/webpack-dev-server");
}

/**
* @private
* @param {Compiler} compiler
* @returns bool
*/
static isWebTarget(compiler) {
// TODO improve for the next major version - we should store `web` and other targets in `compiler.options.environment`
if (
compiler.options.externalsPresets &&
compiler.options.externalsPresets.web
) {
return true;
}

if (
compiler.options.resolve.conditionNames &&
compiler.options.resolve.conditionNames.includes("browser")
) {
return true;
}

const webTargets = [
"web",
"webworker",
"electron-preload",
"electron-renderer",
"node-webkit",
// eslint-disable-next-line no-undefined
undefined,
null,
];

if (Array.isArray(compiler.options.target)) {
return compiler.options.target.some((r) => webTargets.includes(r));
}

return webTargets.includes(/** @type {string} */ (compiler.options.target));
}

/**
* @private
* @param {Compiler} compiler
Expand All @@ -460,21 +499,9 @@ class Server {
* @type {string[]}
*/
const additionalEntries = [];
const isWebTarget = Server.isWebTarget(compiler);

const isWebTarget = compiler.options.externalsPresets
? compiler.options.externalsPresets.web
: [
"web",
"webworker",
"electron-preload",
"electron-renderer",
"node-webkit",
// eslint-disable-next-line no-undefined
undefined,
null,
].includes(/** @type {string} */ (compiler.options.target));

// TODO maybe empty empty client
// TODO maybe empty client
if (this.options.client && isWebTarget) {
let webSocketURLStr = "";

Expand Down
71 changes: 36 additions & 35 deletions types/lib/Server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,6 @@ declare class Server {
"https-ca-reset": {
configs: {
description: string;
/**
* @type {string[]}
*/
multiple: boolean;
path: string;
type: string;
Expand Down Expand Up @@ -764,7 +761,7 @@ declare class Server {
type: string;
multiple: boolean;
description: string;
path: string;
path: string /** @type {string} */;
}[];
description: string;
simpleType: string;
Expand Down Expand Up @@ -799,7 +796,7 @@ declare class Server {
path: string;
type: string;
}[];
description: string;
/** @type {number | string} */ description: string;
multiple: boolean;
simpleType: string;
};
Expand All @@ -821,7 +818,7 @@ declare class Server {
path: string;
type: string;
}[];
description: string;
/** @type {string} */ description: string;
multiple: boolean;
simpleType: string;
};
Expand Down Expand Up @@ -865,12 +862,6 @@ declare class Server {
description: string;
negatedDescription: string;
path: string;
/**
* prependEntry Method for webpack 4
* @param {any} originalEntry
* @param {any} newAdditionalEntries
* @returns {any}
*/
}[];
description: string;
simpleType: string;
Expand All @@ -895,6 +886,12 @@ declare class Server {
description: string;
simpleType: string;
multiple: boolean;
/**
* prependEntry Method for webpack 4
* @param {any} originalEntry
* @param {any} newAdditionalEntries
* @returns {any}
*/
};
"live-reload": {
configs: {
Expand Down Expand Up @@ -925,7 +922,7 @@ declare class Server {
| {
type: string;
multiple: boolean;
/** @type {MultiCompiler} */ description: string;
description: string;
path: string;
}
| {
Expand Down Expand Up @@ -961,17 +958,13 @@ declare class Server {
description: string;
simpleType: string;
multiple: boolean;
/**
* @param {WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} watchOptions
* @returns {WatchOptions}
*/
};
"open-app-name-reset": {
configs: {
type: string;
multiple: boolean;
description: string;
path: string;
path: string /** @type {Compiler} */;
}[];
description: string;
simpleType: string;
Expand Down Expand Up @@ -1195,7 +1188,7 @@ declare class Server {
}[];
description: string;
multiple: boolean;
simpleType: string /** @type {ServerOptions} */;
simpleType: string;
};
static: {
configs: (
Expand All @@ -1208,26 +1201,22 @@ declare class Server {
| {
type: string;
multiple: boolean;
/** @type {ServerOptions} */ description: string;
description: string;
negatedDescription: string;
path: string;
}
)[];
description: string;
simpleType: string;
/** @type {ServerOptions} */ description: string;
/** @type {Array<keyof ServerOptions>} */ simpleType: string;
multiple: boolean;
};
"static-directory": {
configs: {
type: string;
/** @type {any} */ multiple: boolean;
multiple: boolean;
description: string;
path: string;
}[];
/**
* @param {string | Buffer | undefined} item
* @returns {string | Buffer | undefined}
*/
description: string;
simpleType: string;
multiple: boolean;
Expand All @@ -1240,7 +1229,7 @@ declare class Server {
path: string;
}[];
description: string;
/** @type {any} */ simpleType: string;
simpleType: string;
multiple: boolean;
};
"static-public-path-reset": {
Expand Down Expand Up @@ -1352,12 +1341,13 @@ declare class Server {
description: string;
multiple: boolean;
path: string;
type: string /** @type {ServerOptions & { cacert?: ServerOptions["ca"] }} */;
type: string;
}
)[];
/** @type {ServerOptions & { cacert?: ServerOptions["ca"] }} */
description: string;
simpleType: string;
multiple: boolean /** @type {ServerOptions} */;
multiple: boolean;
};
};
readonly processArguments: (
Expand Down Expand Up @@ -2221,7 +2211,7 @@ declare class Server {
}
)[];
description: string;
link: string /** @type {WebSocketURL} */;
link: string;
};
HistoryApiFallback: {
anyOf: (
Expand All @@ -2237,7 +2227,6 @@ declare class Server {
type: string;
description: string;
link: string;
/** @type {string} */
cli?: undefined /** @typedef {import("express").Request} Request */;
}
)[];
Expand Down Expand Up @@ -2351,6 +2340,7 @@ declare class Server {
negatedDescription: string;
};
};
/** @type {ClientConfiguration} */
OpenObject: {
type: string;
additionalProperties: boolean;
Expand Down Expand Up @@ -2481,6 +2471,7 @@ declare class Server {
anyOf: {
$ref: string;
}[];
/** @type {any} */
link: string;
description: string;
};
Expand All @@ -2502,14 +2493,15 @@ declare class Server {
};
ServerObject: {
type: string;
/** @type {string} */
properties: {
type: {
anyOf: {
$ref: string;
}[];
};
options: {
$ref: string;
$ref: string /** @type {MultiCompiler} */;
};
};
additionalProperties: boolean;
Expand All @@ -2522,6 +2514,7 @@ declare class Server {
type: string;
description: string;
};
/** @type {MultiCompiler} */
requestCert: {
type: string;
description: string;
Expand Down Expand Up @@ -2922,10 +2915,10 @@ declare class Server {
anyOf: (
| {
enum: boolean[];
/** @type {ServerOptions} */ cli: {
cli: {
negatedDescription: string;
};
/** @type {ServerOptions} */ $ref?: undefined;
$ref?: undefined;
}
| {
$ref: string;
Expand All @@ -2950,6 +2943,7 @@ declare class Server {
};
options: {
type: string;
/** @type {Array<keyof ServerOptions>} */
additionalProperties: boolean;
cli: {
exclude: boolean;
Expand Down Expand Up @@ -2986,6 +2980,7 @@ declare class Server {
historyApiFallback: {
$ref: string;
};
/** @type {ServerOptions} */
host: {
$ref: string;
};
Expand Down Expand Up @@ -3080,6 +3075,12 @@ declare class Server {
* @returns {string}
*/
static findCacheDir(): string;
/**
* @private
* @param {Compiler} compiler
* @returns bool
*/
private static isWebTarget;
/**
* @param {Configuration | Compiler | MultiCompiler} options
* @param {Compiler | MultiCompiler | Configuration} compiler
Expand Down

0 comments on commit 5b846cb

Please sign in to comment.