Skip to content

Commit 5b846cb

Browse files
authoredSep 27, 2022
fix: compatibility with experiments.buildHttp (#4585)
1 parent b857e6f commit 5b846cb

File tree

2 files changed

+77
-49
lines changed

2 files changed

+77
-49
lines changed
 

‎lib/Server.js

+41-14
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,45 @@ class Server {
451451
return path.resolve(dir, "node_modules/.cache/webpack-dev-server");
452452
}
453453

454+
/**
455+
* @private
456+
* @param {Compiler} compiler
457+
* @returns bool
458+
*/
459+
static isWebTarget(compiler) {
460+
// TODO improve for the next major version - we should store `web` and other targets in `compiler.options.environment`
461+
if (
462+
compiler.options.externalsPresets &&
463+
compiler.options.externalsPresets.web
464+
) {
465+
return true;
466+
}
467+
468+
if (
469+
compiler.options.resolve.conditionNames &&
470+
compiler.options.resolve.conditionNames.includes("browser")
471+
) {
472+
return true;
473+
}
474+
475+
const webTargets = [
476+
"web",
477+
"webworker",
478+
"electron-preload",
479+
"electron-renderer",
480+
"node-webkit",
481+
// eslint-disable-next-line no-undefined
482+
undefined,
483+
null,
484+
];
485+
486+
if (Array.isArray(compiler.options.target)) {
487+
return compiler.options.target.some((r) => webTargets.includes(r));
488+
}
489+
490+
return webTargets.includes(/** @type {string} */ (compiler.options.target));
491+
}
492+
454493
/**
455494
* @private
456495
* @param {Compiler} compiler
@@ -460,21 +499,9 @@ class Server {
460499
* @type {string[]}
461500
*/
462501
const additionalEntries = [];
502+
const isWebTarget = Server.isWebTarget(compiler);
463503

464-
const isWebTarget = compiler.options.externalsPresets
465-
? compiler.options.externalsPresets.web
466-
: [
467-
"web",
468-
"webworker",
469-
"electron-preload",
470-
"electron-renderer",
471-
"node-webkit",
472-
// eslint-disable-next-line no-undefined
473-
undefined,
474-
null,
475-
].includes(/** @type {string} */ (compiler.options.target));
476-
477-
// TODO maybe empty empty client
504+
// TODO maybe empty client
478505
if (this.options.client && isWebTarget) {
479506
let webSocketURLStr = "";
480507

‎types/lib/Server.d.ts

+36-35
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,6 @@ declare class Server {
726726
"https-ca-reset": {
727727
configs: {
728728
description: string;
729-
/**
730-
* @type {string[]}
731-
*/
732729
multiple: boolean;
733730
path: string;
734731
type: string;
@@ -764,7 +761,7 @@ declare class Server {
764761
type: string;
765762
multiple: boolean;
766763
description: string;
767-
path: string;
764+
path: string /** @type {string} */;
768765
}[];
769766
description: string;
770767
simpleType: string;
@@ -799,7 +796,7 @@ declare class Server {
799796
path: string;
800797
type: string;
801798
}[];
802-
description: string;
799+
/** @type {number | string} */ description: string;
803800
multiple: boolean;
804801
simpleType: string;
805802
};
@@ -821,7 +818,7 @@ declare class Server {
821818
path: string;
822819
type: string;
823820
}[];
824-
description: string;
821+
/** @type {string} */ description: string;
825822
multiple: boolean;
826823
simpleType: string;
827824
};
@@ -865,12 +862,6 @@ declare class Server {
865862
description: string;
866863
negatedDescription: string;
867864
path: string;
868-
/**
869-
* prependEntry Method for webpack 4
870-
* @param {any} originalEntry
871-
* @param {any} newAdditionalEntries
872-
* @returns {any}
873-
*/
874865
}[];
875866
description: string;
876867
simpleType: string;
@@ -895,6 +886,12 @@ declare class Server {
895886
description: string;
896887
simpleType: string;
897888
multiple: boolean;
889+
/**
890+
* prependEntry Method for webpack 4
891+
* @param {any} originalEntry
892+
* @param {any} newAdditionalEntries
893+
* @returns {any}
894+
*/
898895
};
899896
"live-reload": {
900897
configs: {
@@ -925,7 +922,7 @@ declare class Server {
925922
| {
926923
type: string;
927924
multiple: boolean;
928-
/** @type {MultiCompiler} */ description: string;
925+
description: string;
929926
path: string;
930927
}
931928
| {
@@ -961,17 +958,13 @@ declare class Server {
961958
description: string;
962959
simpleType: string;
963960
multiple: boolean;
964-
/**
965-
* @param {WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} watchOptions
966-
* @returns {WatchOptions}
967-
*/
968961
};
969962
"open-app-name-reset": {
970963
configs: {
971964
type: string;
972965
multiple: boolean;
973966
description: string;
974-
path: string;
967+
path: string /** @type {Compiler} */;
975968
}[];
976969
description: string;
977970
simpleType: string;
@@ -1195,7 +1188,7 @@ declare class Server {
11951188
}[];
11961189
description: string;
11971190
multiple: boolean;
1198-
simpleType: string /** @type {ServerOptions} */;
1191+
simpleType: string;
11991192
};
12001193
static: {
12011194
configs: (
@@ -1208,26 +1201,22 @@ declare class Server {
12081201
| {
12091202
type: string;
12101203
multiple: boolean;
1211-
/** @type {ServerOptions} */ description: string;
1204+
description: string;
12121205
negatedDescription: string;
12131206
path: string;
12141207
}
12151208
)[];
1216-
description: string;
1217-
simpleType: string;
1209+
/** @type {ServerOptions} */ description: string;
1210+
/** @type {Array<keyof ServerOptions>} */ simpleType: string;
12181211
multiple: boolean;
12191212
};
12201213
"static-directory": {
12211214
configs: {
12221215
type: string;
1223-
/** @type {any} */ multiple: boolean;
1216+
multiple: boolean;
12241217
description: string;
12251218
path: string;
12261219
}[];
1227-
/**
1228-
* @param {string | Buffer | undefined} item
1229-
* @returns {string | Buffer | undefined}
1230-
*/
12311220
description: string;
12321221
simpleType: string;
12331222
multiple: boolean;
@@ -1240,7 +1229,7 @@ declare class Server {
12401229
path: string;
12411230
}[];
12421231
description: string;
1243-
/** @type {any} */ simpleType: string;
1232+
simpleType: string;
12441233
multiple: boolean;
12451234
};
12461235
"static-public-path-reset": {
@@ -1352,12 +1341,13 @@ declare class Server {
13521341
description: string;
13531342
multiple: boolean;
13541343
path: string;
1355-
type: string /** @type {ServerOptions & { cacert?: ServerOptions["ca"] }} */;
1344+
type: string;
13561345
}
13571346
)[];
1347+
/** @type {ServerOptions & { cacert?: ServerOptions["ca"] }} */
13581348
description: string;
13591349
simpleType: string;
1360-
multiple: boolean /** @type {ServerOptions} */;
1350+
multiple: boolean;
13611351
};
13621352
};
13631353
readonly processArguments: (
@@ -2221,7 +2211,7 @@ declare class Server {
22212211
}
22222212
)[];
22232213
description: string;
2224-
link: string /** @type {WebSocketURL} */;
2214+
link: string;
22252215
};
22262216
HistoryApiFallback: {
22272217
anyOf: (
@@ -2237,7 +2227,6 @@ declare class Server {
22372227
type: string;
22382228
description: string;
22392229
link: string;
2240-
/** @type {string} */
22412230
cli?: undefined /** @typedef {import("express").Request} Request */;
22422231
}
22432232
)[];
@@ -2351,6 +2340,7 @@ declare class Server {
23512340
negatedDescription: string;
23522341
};
23532342
};
2343+
/** @type {ClientConfiguration} */
23542344
OpenObject: {
23552345
type: string;
23562346
additionalProperties: boolean;
@@ -2481,6 +2471,7 @@ declare class Server {
24812471
anyOf: {
24822472
$ref: string;
24832473
}[];
2474+
/** @type {any} */
24842475
link: string;
24852476
description: string;
24862477
};
@@ -2502,14 +2493,15 @@ declare class Server {
25022493
};
25032494
ServerObject: {
25042495
type: string;
2496+
/** @type {string} */
25052497
properties: {
25062498
type: {
25072499
anyOf: {
25082500
$ref: string;
25092501
}[];
25102502
};
25112503
options: {
2512-
$ref: string;
2504+
$ref: string /** @type {MultiCompiler} */;
25132505
};
25142506
};
25152507
additionalProperties: boolean;
@@ -2522,6 +2514,7 @@ declare class Server {
25222514
type: string;
25232515
description: string;
25242516
};
2517+
/** @type {MultiCompiler} */
25252518
requestCert: {
25262519
type: string;
25272520
description: string;
@@ -2922,10 +2915,10 @@ declare class Server {
29222915
anyOf: (
29232916
| {
29242917
enum: boolean[];
2925-
/** @type {ServerOptions} */ cli: {
2918+
cli: {
29262919
negatedDescription: string;
29272920
};
2928-
/** @type {ServerOptions} */ $ref?: undefined;
2921+
$ref?: undefined;
29292922
}
29302923
| {
29312924
$ref: string;
@@ -2950,6 +2943,7 @@ declare class Server {
29502943
};
29512944
options: {
29522945
type: string;
2946+
/** @type {Array<keyof ServerOptions>} */
29532947
additionalProperties: boolean;
29542948
cli: {
29552949
exclude: boolean;
@@ -2986,6 +2980,7 @@ declare class Server {
29862980
historyApiFallback: {
29872981
$ref: string;
29882982
};
2983+
/** @type {ServerOptions} */
29892984
host: {
29902985
$ref: string;
29912986
};
@@ -3080,6 +3075,12 @@ declare class Server {
30803075
* @returns {string}
30813076
*/
30823077
static findCacheDir(): string;
3078+
/**
3079+
* @private
3080+
* @param {Compiler} compiler
3081+
* @returns bool
3082+
*/
3083+
private static isWebTarget;
30833084
/**
30843085
* @param {Configuration | Compiler | MultiCompiler} options
30853086
* @param {Compiler | MultiCompiler | Configuration} compiler

0 commit comments

Comments
 (0)
Please sign in to comment.