|
8 | 8 | const querystring = require("querystring"); |
9 | 9 | const { |
10 | 10 | AsyncSeriesBailHook, |
| 11 | + AsyncSeriesWaterfallHook, |
11 | 12 | HookMap, |
12 | 13 | SyncHook, |
13 | 14 | SyncWaterfallHook |
@@ -184,7 +185,9 @@ const recordSideEffectsBailout = (mod, moduleGraph, dep) => { |
184 | 185 | .getOptimizationBailout(mod) |
185 | 186 | .push( |
186 | 187 | () => |
187 | | - `Dependency (${dep.type}) with side effects at ${formatLocation(dep.loc)}` |
| 188 | + `Dependency (${dep.type}) with side effects at ${formatLocation( |
| 189 | + dep.loc |
| 190 | + )}` |
188 | 191 | ); |
189 | 192 | }; |
190 | 193 |
|
@@ -546,6 +549,13 @@ const createCompilationHooks = () => { |
546 | 549 | * @since 5.99.0 |
547 | 550 | */ |
548 | 551 | processResult: new SyncWaterfallHook(["result", "module"]), |
| 552 | + /** |
| 553 | + * The same, for a tap that has to await work of its own — minifying an |
| 554 | + * asset, say, which before only a loader could do. Skipped when unused. |
| 555 | + * @type {AsyncSeriesWaterfallHook<[Result, NormalModule]>} |
| 556 | + * @since 5.110.0 |
| 557 | + */ |
| 558 | + processResultAsync: new AsyncSeriesWaterfallHook(["result", "module"]), |
549 | 559 | /** |
550 | 560 | * @type {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} |
551 | 561 | * @since 5.49.0 |
@@ -1052,7 +1062,9 @@ class NormalModule extends Module { |
1052 | 1062 | (parseJson(options)); |
1053 | 1063 | } catch (err) { |
1054 | 1064 | throw new Error( |
1055 | | - `Cannot parse string options: ${/** @type {Error} */ (err).message}`, |
| 1065 | + `Cannot parse string options: ${ |
| 1066 | + /** @type {Error} */ (err).message |
| 1067 | + }`, |
1056 | 1068 | { cause: err } |
1057 | 1069 | ); |
1058 | 1070 | } |
@@ -1441,7 +1453,9 @@ class NormalModule extends Module { |
1441 | 1453 | }) |
1442 | 1454 | ).catch((err) => { |
1443 | 1455 | throw new Error( |
1444 | | - `Failed to parse source map. ${/** @type {Error} */ (err).message}` |
| 1456 | + `Failed to parse source map. ${ |
| 1457 | + /** @type {Error} */ (err).message |
| 1458 | + }` |
1445 | 1459 | ); |
1446 | 1460 | }) |
1447 | 1461 | ); |
@@ -1503,7 +1517,34 @@ class NormalModule extends Module { |
1503 | 1517 | if (result.notCacheableReasons.length > 0) { |
1504 | 1518 | buildInfo.notCacheableReasons = result.notCacheableReasons; |
1505 | 1519 | } |
1506 | | - processResult(err, result.result); |
| 1520 | + // Unused, nothing can observe it: call straight through, so a build |
| 1521 | + // without it keeps the synchronous path and the stack depth |
| 1522 | + // anything thrown below is reported at. `isUsed` rather than |
| 1523 | + // `taps`, so an interceptor alone still gets its `call`. |
| 1524 | + if (!hooks.processResultAsync.isUsed()) { |
| 1525 | + return processResult(err, result.result); |
| 1526 | + } |
| 1527 | + |
| 1528 | + hooks.processResultAsync.callAsync( |
| 1529 | + /** @type {Result} */ |
| 1530 | + (result.result), |
| 1531 | + this, |
| 1532 | + (hookErr, asyncResult) => { |
| 1533 | + if (hookErr) { |
| 1534 | + // Named, so a failure here is not read as a loader's. |
| 1535 | + return callback( |
| 1536 | + new (getModuleBuildError())( |
| 1537 | + hookErr instanceof Error |
| 1538 | + ? hookErr |
| 1539 | + : new (getNonErrorEmittedError())(hookErr), |
| 1540 | + { from: "processResultAsync hook" } |
| 1541 | + ) |
| 1542 | + ); |
| 1543 | + } |
| 1544 | + |
| 1545 | + processResult(null, /** @type {Result} */ (asyncResult)); |
| 1546 | + } |
| 1547 | + ); |
1507 | 1548 | } |
1508 | 1549 | ); |
1509 | 1550 | } |
|
0 commit comments