Skip to content

Commit 50f02c7

Browse files
feat(DefinePlugin): resolve an async runtimeValue before parsing (#22210)
* feat(DefinePlugin): resolve an async runtimeValue before parsing An async runtimeValue generator (or a promise-returning one with `async: true`) now resolves in NormalModule's beforeParse hook, before the parser needs it, and is served synchronously at parse time. The synchronous path is unchanged. A promise returned without `async` throws a clear error instead of emitting broken code. The beforeParse hook becomes an AsyncSeriesHook; existing synchronous taps keep working. closes #16629 * fix(DefinePlugin): annotate an async runtimeValue rejection once, by name `annotateEvaluationError` read a RuntimeValue through `JSON.stringify`, which drops the generator and leaves `{"options":{},"async":true}` where the message should name what failed. It also re-prefixed the error it mutates, so one rejection reaching several modules carried the key once per module. A rejection is now kept as it is until a module consumes it, annotated only then, and the key is prefixed onto it once however many modules share the instance. Types the `beforeParse` tap's `_ast` read, which `lint:code` rejected, and covers `module.parser.javascript.parse`. Co-authored-by: Eshiv Pandey <[email protected]> * chore: keep the changeset entry under 80 characters * test: cover the beforeParse error path and two DefinePlugin arms `beforeParse` failing is what the hook's move to `AsyncSeriesHook` changed, and nothing exercised it: a case now fails one module from a `tap` and another from a `tapPromise`, which covers every line the move added to `NormalModule` and holds both to the module error the synchronous hook gave. Two more cases reach an unparsable string define and a code point above the Unicode maximum. Co-authored-by: Eshiv Pandey <[email protected]> --------- Co-authored-by: Eshiv Pandey <[email protected]>
1 parent 005ec95 commit 50f02c7

52 files changed

Lines changed: 1096 additions & 59 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": minor
3+
---
4+
5+
Resolve an async `DefinePlugin.runtimeValue` over an async `beforeParse` hook.

0 commit comments

Comments
 (0)