webpack 5.69.1 → 5.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (41) hide show
  1. package/lib/BannerPlugin.js +10 -4
  2. package/lib/CleanPlugin.js +64 -18
  3. package/lib/Compilation.js +41 -17
  4. package/lib/ContextModule.js +90 -26
  5. package/lib/ContextModuleFactory.js +65 -21
  6. package/lib/EntryOptionPlugin.js +1 -0
  7. package/lib/Generator.js +1 -0
  8. package/lib/ModuleHashingError.js +29 -0
  9. package/lib/NodeStuffPlugin.js +10 -0
  10. package/lib/NormalModule.js +21 -16
  11. package/lib/NormalModuleFactory.js +15 -8
  12. package/lib/ProgressPlugin.js +3 -4
  13. package/lib/RuntimeTemplate.js +1 -0
  14. package/lib/WebpackOptionsApply.js +2 -0
  15. package/lib/asset/AssetGenerator.js +119 -31
  16. package/lib/cache/ResolverCachePlugin.js +89 -28
  17. package/lib/config/browserslistTargetHandler.js +3 -5
  18. package/lib/config/normalization.js +1 -0
  19. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  20. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  21. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  22. package/lib/dependencies/ImportContextDependency.js +0 -2
  23. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  24. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  25. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  26. package/lib/dependencies/LoaderPlugin.js +2 -0
  27. package/lib/dependencies/RequireContextDependency.js +0 -16
  28. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +24 -8
  29. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -7
  30. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -7
  31. package/lib/schemes/HttpUriPlugin.js +44 -3
  32. package/lib/util/internalSerializables.js +2 -0
  33. package/lib/web/JsonpChunkLoadingRuntimeModule.js +15 -5
  34. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -20
  35. package/module.d.ts +15 -0
  36. package/package.json +2 -2
  37. package/schemas/WebpackOptions.check.js +1 -1
  38. package/schemas/WebpackOptions.json +17 -1
  39. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  40. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  41. package/types.d.ts +164 -73
@@ -0,0 +1,35 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const makeSerializable = require("../util/makeSerializable");
9
+ const ContextDependency = require("./ContextDependency");
10
+ const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
11
+
12
+ class ImportMetaContextDependency extends ContextDependency {
13
+ constructor(options, range) {
14
+ super(options);
15
+
16
+ this.range = range;
17
+ }
18
+
19
+ get category() {
20
+ return "esm";
21
+ }
22
+
23
+ get type() {
24
+ return `import.meta.webpackContext ${this.options.mode}`;
25
+ }
26
+ }
27
+
28
+ makeSerializable(
29
+ ImportMetaContextDependency,
30
+ "webpack/lib/dependencies/ImportMetaContextDependency"
31
+ );
32
+
33
+ ImportMetaContextDependency.Template = ModuleDependencyTemplateAsRequireId;
34
+
35
+ module.exports = ImportMetaContextDependency;
@@ -0,0 +1,252 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const WebpackError = require("../WebpackError");
9
+ const {
10
+ evaluateToIdentifier
11
+ } = require("../javascript/JavascriptParserHelpers");
12
+ const ImportMetaContextDependency = require("./ImportMetaContextDependency");
13
+
14
+ /** @typedef {import("estree").Expression} ExpressionNode */
15
+ /** @typedef {import("estree").ObjectExpression} ObjectExpressionNode */
16
+ /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
17
+ /** @typedef {import("../ContextModule").ContextModuleOptions} ContextModuleOptions */
18
+ /** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
19
+ /** @typedef {Pick<ContextModuleOptions, 'mode'|'recursive'|'regExp'|'include'|'exclude'|'chunkName'>&{groupOptions: RawChunkGroupOptions, exports?: ContextModuleOptions["referencedExports"]}} ImportMetaContextOptions */
20
+
21
+ function createPropertyParseError(prop, expect) {
22
+ return createError(
23
+ `Parsing import.meta.webpackContext options failed. Unknown value for property ${JSON.stringify(
24
+ prop.key.name
25
+ )}, expected type ${expect}.`,
26
+ prop.value.loc
27
+ );
28
+ }
29
+
30
+ function createError(msg, loc) {
31
+ const error = new WebpackError(msg);
32
+ error.name = "ImportMetaContextError";
33
+ error.loc = loc;
34
+ return error;
35
+ }
36
+
37
+ module.exports = class ImportMetaContextDependencyParserPlugin {
38
+ apply(parser) {
39
+ parser.hooks.evaluateIdentifier
40
+ .for("import.meta.webpackContext")
41
+ .tap("HotModuleReplacementPlugin", expr => {
42
+ return evaluateToIdentifier(
43
+ "import.meta.webpackContext",
44
+ "import.meta",
45
+ () => ["webpackContext"],
46
+ true
47
+ )(expr);
48
+ });
49
+ parser.hooks.call
50
+ .for("import.meta.webpackContext")
51
+ .tap("ImportMetaContextDependencyParserPlugin", expr => {
52
+ if (expr.arguments.length < 1 || expr.arguments.length > 2) return;
53
+ const [directoryNode, optionsNode] = expr.arguments;
54
+ if (optionsNode && optionsNode.type !== "ObjectExpression") return;
55
+ const requestExpr = parser.evaluateExpression(directoryNode);
56
+ if (!requestExpr.isString()) return;
57
+ const request = requestExpr.string;
58
+ const errors = [];
59
+ let regExp = /^\.\/.*$/;
60
+ let recursive = true;
61
+ /** @type {ContextModuleOptions["mode"]} */
62
+ let mode = "sync";
63
+ /** @type {ContextModuleOptions["include"]} */
64
+ let include;
65
+ /** @type {ContextModuleOptions["exclude"]} */
66
+ let exclude;
67
+ /** @type {RawChunkGroupOptions} */
68
+ const groupOptions = {};
69
+ /** @type {ContextModuleOptions["chunkName"]} */
70
+ let chunkName;
71
+ /** @type {ContextModuleOptions["referencedExports"]} */
72
+ let exports;
73
+ if (optionsNode) {
74
+ for (const prop of optionsNode.properties) {
75
+ if (prop.type !== "Property" || prop.key.type !== "Identifier") {
76
+ errors.push(
77
+ createError(
78
+ "Parsing import.meta.webpackContext options failed.",
79
+ optionsNode.loc
80
+ )
81
+ );
82
+ break;
83
+ }
84
+ switch (prop.key.name) {
85
+ case "regExp": {
86
+ const regExpExpr = parser.evaluateExpression(
87
+ /** @type {ExpressionNode} */ (prop.value)
88
+ );
89
+ if (!regExpExpr.isRegExp()) {
90
+ errors.push(createPropertyParseError(prop, "RegExp"));
91
+ } else {
92
+ regExp = regExpExpr.regExp;
93
+ }
94
+ break;
95
+ }
96
+ case "include": {
97
+ const regExpExpr = parser.evaluateExpression(
98
+ /** @type {ExpressionNode} */ (prop.value)
99
+ );
100
+ if (!regExpExpr.isRegExp()) {
101
+ errors.push(createPropertyParseError(prop, "RegExp"));
102
+ } else {
103
+ include = regExpExpr.regExp;
104
+ }
105
+ break;
106
+ }
107
+ case "exclude": {
108
+ const regExpExpr = parser.evaluateExpression(
109
+ /** @type {ExpressionNode} */ (prop.value)
110
+ );
111
+ if (!regExpExpr.isRegExp()) {
112
+ errors.push(createPropertyParseError(prop, "RegExp"));
113
+ } else {
114
+ exclude = regExpExpr.regExp;
115
+ }
116
+ break;
117
+ }
118
+ case "mode": {
119
+ const modeExpr = parser.evaluateExpression(
120
+ /** @type {ExpressionNode} */ (prop.value)
121
+ );
122
+ if (!modeExpr.isString()) {
123
+ errors.push(createPropertyParseError(prop, "string"));
124
+ } else {
125
+ mode = /** @type {ContextModuleOptions["mode"]} */ (
126
+ modeExpr.string
127
+ );
128
+ }
129
+ break;
130
+ }
131
+ case "chunkName": {
132
+ const expr = parser.evaluateExpression(
133
+ /** @type {ExpressionNode} */ (prop.value)
134
+ );
135
+ if (!expr.isString()) {
136
+ errors.push(createPropertyParseError(prop, "string"));
137
+ } else {
138
+ chunkName = expr.string;
139
+ }
140
+ break;
141
+ }
142
+ case "exports": {
143
+ const expr = parser.evaluateExpression(
144
+ /** @type {ExpressionNode} */ (prop.value)
145
+ );
146
+ if (expr.isString()) {
147
+ exports = [[expr.string]];
148
+ } else if (expr.isArray()) {
149
+ const items = expr.items;
150
+ if (
151
+ items.every(i => {
152
+ if (!i.isArray()) return false;
153
+ const innerItems = i.items;
154
+ return innerItems.every(i => i.isString());
155
+ })
156
+ ) {
157
+ exports = [];
158
+ for (const i1 of items) {
159
+ const export_ = [];
160
+ for (const i2 of i1.items) {
161
+ export_.push(i2.string);
162
+ }
163
+ exports.push(export_);
164
+ }
165
+ } else {
166
+ errors.push(
167
+ createPropertyParseError(prop, "string|string[][]")
168
+ );
169
+ }
170
+ } else {
171
+ errors.push(
172
+ createPropertyParseError(prop, "string|string[][]")
173
+ );
174
+ }
175
+ break;
176
+ }
177
+ case "prefetch": {
178
+ const expr = parser.evaluateExpression(
179
+ /** @type {ExpressionNode} */ (prop.value)
180
+ );
181
+ if (expr.isBoolean()) {
182
+ groupOptions.prefetchOrder = 0;
183
+ } else if (expr.isNumber()) {
184
+ groupOptions.prefetchOrder = expr.number;
185
+ } else {
186
+ errors.push(createPropertyParseError(prop, "boolean|number"));
187
+ }
188
+ break;
189
+ }
190
+ case "preload": {
191
+ const expr = parser.evaluateExpression(
192
+ /** @type {ExpressionNode} */ (prop.value)
193
+ );
194
+ if (expr.isBoolean()) {
195
+ groupOptions.preloadOrder = 0;
196
+ } else if (expr.isNumber()) {
197
+ groupOptions.preloadOrder = expr.number;
198
+ } else {
199
+ errors.push(createPropertyParseError(prop, "boolean|number"));
200
+ }
201
+ break;
202
+ }
203
+ case "recursive": {
204
+ const recursiveExpr = parser.evaluateExpression(
205
+ /** @type {ExpressionNode} */ (prop.value)
206
+ );
207
+ if (!recursiveExpr.isBoolean()) {
208
+ errors.push(createPropertyParseError(prop, "boolean"));
209
+ } else {
210
+ recursive = recursiveExpr.bool;
211
+ }
212
+ break;
213
+ }
214
+ default:
215
+ errors.push(
216
+ createError(
217
+ `Parsing import.meta.webpackContext options failed. Unknown property ${JSON.stringify(
218
+ prop.key.name
219
+ )}.`,
220
+ optionsNode.loc
221
+ )
222
+ );
223
+ }
224
+ }
225
+ }
226
+ if (errors.length) {
227
+ for (const error of errors) parser.state.current.addError(error);
228
+ return;
229
+ }
230
+
231
+ const dep = new ImportMetaContextDependency(
232
+ {
233
+ request,
234
+ include,
235
+ exclude,
236
+ recursive,
237
+ regExp,
238
+ groupOptions,
239
+ chunkName,
240
+ referencedExports: exports,
241
+ mode,
242
+ category: "esm"
243
+ },
244
+ expr.range
245
+ );
246
+ dep.loc = expr.loc;
247
+ dep.optional = !!parser.scope.inTry;
248
+ parser.state.current.addDependency(dep);
249
+ return true;
250
+ });
251
+ }
252
+ };
@@ -0,0 +1,59 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Ivan Kopeykin @vankop
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const ContextElementDependency = require("./ContextElementDependency");
9
+ const ImportMetaContextDependency = require("./ImportMetaContextDependency");
10
+ const ImportMetaContextDependencyParserPlugin = require("./ImportMetaContextDependencyParserPlugin");
11
+
12
+ /** @typedef {import("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
13
+ /** @typedef {import("../Compiler")} Compiler */
14
+
15
+ class ImportMetaContextPlugin {
16
+ /**
17
+ * Apply the plugin
18
+ * @param {Compiler} compiler the compiler instance
19
+ * @returns {void}
20
+ */
21
+ apply(compiler) {
22
+ compiler.hooks.compilation.tap(
23
+ "RequireContextPlugin",
24
+ (compilation, { contextModuleFactory, normalModuleFactory }) => {
25
+ compilation.dependencyFactories.set(
26
+ ImportMetaContextDependency,
27
+ contextModuleFactory
28
+ );
29
+ compilation.dependencyTemplates.set(
30
+ ImportMetaContextDependency,
31
+ new ImportMetaContextDependency.Template()
32
+ );
33
+ compilation.dependencyFactories.set(
34
+ ContextElementDependency,
35
+ normalModuleFactory
36
+ );
37
+
38
+ const handler = (parser, parserOptions) => {
39
+ if (
40
+ parserOptions.importMetaContext !== undefined &&
41
+ !parserOptions.importMetaContext
42
+ )
43
+ return;
44
+
45
+ new ImportMetaContextDependencyParserPlugin().apply(parser);
46
+ };
47
+
48
+ normalModuleFactory.hooks.parser
49
+ .for("javascript/auto")
50
+ .tap("ImportMetaContextPlugin", handler);
51
+ normalModuleFactory.hooks.parser
52
+ .for("javascript/esm")
53
+ .tap("ImportMetaContextPlugin", handler);
54
+ }
55
+ );
56
+ }
57
+ }
58
+
59
+ module.exports = ImportMetaContextPlugin;
@@ -32,6 +32,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
32
32
  * @typedef {Object} ImportModuleOptions
33
33
  * @property {string=} layer the target layer
34
34
  * @property {string=} publicPath the target public path
35
+ * @property {string=} baseUri target base uri
35
36
  */
36
37
 
37
38
  class LoaderPlugin {
@@ -199,6 +200,7 @@ class LoaderPlugin {
199
200
  referencedModule,
200
201
  {
201
202
  entryOptions: {
203
+ baseUri: options.baseUri,
202
204
  publicPath: options.publicPath
203
205
  }
204
206
  },
@@ -19,22 +19,6 @@ class RequireContextDependency extends ContextDependency {
19
19
  get type() {
20
20
  return "require.context";
21
21
  }
22
-
23
- serialize(context) {
24
- const { write } = context;
25
-
26
- write(this.range);
27
-
28
- super.serialize(context);
29
- }
30
-
31
- deserialize(context) {
32
- const { read } = context;
33
-
34
- this.range = read();
35
-
36
- super.deserialize(context);
37
- }
38
22
  }
39
23
 
40
24
  makeSerializable(
@@ -55,15 +55,35 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
55
55
  this._runtimeRequirements = runtimeRequirements;
56
56
  }
57
57
 
58
+ /**
59
+ * @private
60
+ * @param {Chunk} chunk chunk
61
+ * @param {string} rootOutputDir root output directory
62
+ * @returns {string} generated code
63
+ */
64
+ _generateBaseUri(chunk, rootOutputDir) {
65
+ const options = chunk.getEntryOptions();
66
+ if (options && options.baseUri) {
67
+ return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
68
+ }
69
+ const {
70
+ compilation: {
71
+ outputOptions: { importMetaName }
72
+ }
73
+ } = this;
74
+ return `${RuntimeGlobals.baseURI} = new URL(${JSON.stringify(
75
+ rootOutputDir
76
+ )}, ${importMetaName}.url);`;
77
+ }
78
+
58
79
  /**
59
80
  * @returns {string} runtime code
60
81
  */
61
82
  generate() {
62
- const { compilation, chunk } = this;
83
+ const { compilation, chunk, chunkGraph } = this;
63
84
  const {
64
85
  runtimeTemplate,
65
- chunkGraph,
66
- outputOptions: { importFunctionName, importMetaName }
86
+ outputOptions: { importFunctionName }
67
87
  } = compilation;
68
88
  const fn = RuntimeGlobals.ensureChunkHandlers;
69
89
  const withBaseURI = this._runtimeRequirements.has(RuntimeGlobals.baseURI);
@@ -102,11 +122,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
102
122
 
103
123
  return Template.asString([
104
124
  withBaseURI
105
- ? Template.asString([
106
- `${RuntimeGlobals.baseURI} = new URL(${JSON.stringify(
107
- rootOutputDir
108
- )}, ${importMetaName}.url);`
109
- ])
125
+ ? this._generateBaseUri(chunk, rootOutputDir)
110
126
  : "// no baseURI",
111
127
  "",
112
128
  "// object to store loaded and loading chunks",
@@ -15,12 +15,33 @@ const { getInitialChunkIds } = require("../javascript/StartupHelpers");
15
15
  const compileBooleanMatcher = require("../util/compileBooleanMatcher");
16
16
  const { getUndoPath } = require("../util/identifier");
17
17
 
18
+ /** @typedef {import("../Chunk")} Chunk */
19
+
18
20
  class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
19
21
  constructor(runtimeRequirements) {
20
22
  super("readFile chunk loading", RuntimeModule.STAGE_ATTACH);
21
23
  this.runtimeRequirements = runtimeRequirements;
22
24
  }
23
25
 
26
+ /**
27
+ * @private
28
+ * @param {Chunk} chunk chunk
29
+ * @param {string} rootOutputDir root output directory
30
+ * @returns {string} generated code
31
+ */
32
+ _generateBaseUri(chunk, rootOutputDir) {
33
+ const options = chunk.getEntryOptions();
34
+ if (options && options.baseUri) {
35
+ return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
36
+ }
37
+
38
+ return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
39
+ rootOutputDir
40
+ ? `__dirname + ${JSON.stringify("/" + rootOutputDir)}`
41
+ : "__filename"
42
+ });`;
43
+ }
44
+
24
45
  /**
25
46
  * @returns {string} runtime code
26
47
  */
@@ -67,13 +88,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
67
88
 
68
89
  return Template.asString([
69
90
  withBaseURI
70
- ? Template.asString([
71
- `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
72
- rootOutputDir
73
- ? `__dirname + ${JSON.stringify("/" + rootOutputDir)}`
74
- : "__filename"
75
- });`
76
- ])
91
+ ? this._generateBaseUri(chunk, rootOutputDir)
77
92
  : "// no baseURI",
78
93
  "",
79
94
  "// object to store loaded chunks",
@@ -15,12 +15,33 @@ const { getInitialChunkIds } = require("../javascript/StartupHelpers");
15
15
  const compileBooleanMatcher = require("../util/compileBooleanMatcher");
16
16
  const { getUndoPath } = require("../util/identifier");
17
17
 
18
+ /** @typedef {import("../Chunk")} Chunk */
19
+
18
20
  class RequireChunkLoadingRuntimeModule extends RuntimeModule {
19
21
  constructor(runtimeRequirements) {
20
22
  super("require chunk loading", RuntimeModule.STAGE_ATTACH);
21
23
  this.runtimeRequirements = runtimeRequirements;
22
24
  }
23
25
 
26
+ /**
27
+ * @private
28
+ * @param {Chunk} chunk chunk
29
+ * @param {string} rootOutputDir root output directory
30
+ * @returns {string} generated code
31
+ */
32
+ _generateBaseUri(chunk, rootOutputDir) {
33
+ const options = chunk.getEntryOptions();
34
+ if (options && options.baseUri) {
35
+ return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
36
+ }
37
+
38
+ return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
39
+ rootOutputDir !== "./"
40
+ ? `__dirname + ${JSON.stringify("/" + rootOutputDir)}`
41
+ : "__filename"
42
+ });`;
43
+ }
44
+
24
45
  /**
25
46
  * @returns {string} runtime code
26
47
  */
@@ -67,13 +88,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
67
88
 
68
89
  return Template.asString([
69
90
  withBaseURI
70
- ? Template.asString([
71
- `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
72
- rootOutputDir !== "./"
73
- ? `__dirname + ${JSON.stringify("/" + rootOutputDir)}`
74
- : "__filename"
75
- });`
76
- ])
91
+ ? this._generateBaseUri(chunk, rootOutputDir)
77
92
  : "// no baseURI",
78
93
  "",
79
94
  "// object to store loaded chunks",
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const EventEmitter = require("events");
8
9
  const { extname, basename } = require("path");
9
10
  const { URL } = require("url");
10
11
  const { createGunzip, createBrotliDecompress, createInflate } = require("zlib");
@@ -19,6 +20,44 @@ const memoize = require("../util/memoize");
19
20
 
20
21
  const getHttp = memoize(() => require("http"));
21
22
  const getHttps = memoize(() => require("https"));
23
+ const proxyFetch = (request, proxy) => (url, options, callback) => {
24
+ const eventEmitter = new EventEmitter();
25
+ const doRequest = socket =>
26
+ request
27
+ .get(url, { ...options, ...(socket && { socket }) }, callback)
28
+ .on("error", eventEmitter.emit.bind(eventEmitter, "error"));
29
+
30
+ if (proxy) {
31
+ const { hostname: host, port } = new URL(proxy);
32
+
33
+ getHttp()
34
+ .request({
35
+ host, // IP address of proxy server
36
+ port, // port of proxy server
37
+ method: "CONNECT",
38
+ path: url.host
39
+ })
40
+ .on("connect", (res, socket) => {
41
+ if (res.statusCode === 200) {
42
+ // connected to proxy server
43
+ doRequest(socket);
44
+ }
45
+ })
46
+ .on("error", err => {
47
+ eventEmitter.emit(
48
+ "error",
49
+ new Error(
50
+ `Failed to connect to proxy server "${proxy}": ${err.message}`
51
+ )
52
+ );
53
+ })
54
+ .end();
55
+ } else {
56
+ doRequest();
57
+ }
58
+
59
+ return eventEmitter;
60
+ };
22
61
 
23
62
  /** @type {(() => void)[] | undefined} */
24
63
  let inProgressWrite = undefined;
@@ -274,6 +313,7 @@ class HttpUriPlugin {
274
313
  this._upgrade = options.upgrade;
275
314
  this._frozen = options.frozen;
276
315
  this._allowedUris = options.allowedUris;
316
+ this._proxy = options.proxy;
277
317
  }
278
318
 
279
319
  /**
@@ -282,15 +322,16 @@ class HttpUriPlugin {
282
322
  * @returns {void}
283
323
  */
284
324
  apply(compiler) {
325
+ const proxy =
326
+ this._proxy || process.env["http_proxy"] || process.env["HTTP_PROXY"];
285
327
  const schemes = [
286
328
  {
287
329
  scheme: "http",
288
- fetch: (url, options, callback) => getHttp().get(url, options, callback)
330
+ fetch: proxyFetch(getHttp(), proxy)
289
331
  },
290
332
  {
291
333
  scheme: "https",
292
- fetch: (url, options, callback) =>
293
- getHttps().get(url, options, callback)
334
+ fetch: proxyFetch(getHttps(), proxy)
294
335
  }
295
336
  ];
296
337
  let lockfileCache;
@@ -126,6 +126,8 @@ module.exports = {
126
126
  require("../dependencies/ImportMetaHotAcceptDependency"),
127
127
  "dependencies/ImportMetaHotDeclineDependency": () =>
128
128
  require("../dependencies/ImportMetaHotDeclineDependency"),
129
+ "dependencies/ImportMetaContextDependency": () =>
130
+ require("../dependencies/ImportMetaContextDependency"),
129
131
  "dependencies/ProvidedDependency": () =>
130
132
  require("../dependencies/ProvidedDependency"),
131
133
  "dependencies/PureExpressionDependency": () =>
@@ -51,6 +51,20 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
51
51
  this._runtimeRequirements = runtimeRequirements;
52
52
  }
53
53
 
54
+ /**
55
+ * @private
56
+ * @param {Chunk} chunk chunk
57
+ * @returns {string} generated code
58
+ */
59
+ _generateBaseUri(chunk) {
60
+ const options = chunk.getEntryOptions();
61
+ if (options && options.baseUri) {
62
+ return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
63
+ } else {
64
+ return `${RuntimeGlobals.baseURI} = document.baseURI || self.location.href;`;
65
+ }
66
+ }
67
+
54
68
  /**
55
69
  * @returns {string} runtime code
56
70
  */
@@ -103,11 +117,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
103
117
  : undefined;
104
118
 
105
119
  return Template.asString([
106
- withBaseURI
107
- ? Template.asString([
108
- `${RuntimeGlobals.baseURI} = document.baseURI || self.location.href;`
109
- ])
110
- : "// no baseURI",
120
+ withBaseURI ? this._generateBaseUri(chunk) : "// no baseURI",
111
121
  "",
112
122
  "// object to store loaded and loading chunks",
113
123
  "// undefined = chunk not loaded, null = chunk preloaded/prefetched",