Repository navigation
refactor: make the loader an async function (speculative) - #1724
Closed
johnnyreilly wants to merge 1 commit into
Closed
johnnyreilly wants to merge 1 commit into
johnnyreilly wants to merge 1 commit into
Conversation
Replace the callback-threading (`successLoader` / `makeSourceMapAndFinish`)
with a single `async compile()` that returns `{ output, sourceMap }` or
throws, and convert `mapToInputSourceMap` to async/await.
`this.async()` is still called once: webpack only forwards `content` from
a loader's returned promise, so returning would drop the source map.
Comparison snapshots updated for the renamed stack frames only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Benchmark (Ubuntu)
PR branch = |
Benchmark (macOS)
PR branch = |
Benchmark (Windows)
PR branch = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Speculative: converts ts-loader to the
async functionloader style, as far as webpack allows.The catch:
this.async()can't go away entirelyWhen a loader returns a promise, webpack's loader-runner does:
Only
contentis forwarded, so a loader that justreturns its output loses its source map. ts-loader always produces one, so a "pure" async loader isn't an option without dropping source maps. You also can't mix the two: if anawaithappens before callingthis.callback, loader-runner has already taken the returned promise as the result.So
loaderis now anasync functionthat callsthis.async()once at the top and hands the result to it once at the end:What changed
successLoader+makeSourceMapAndFinish(which passedcallbackaround) are replaced by oneasync compile()that returns{ output, sourceMap }or throws.mapToInputSourceMapuses async/await withtry/finallyfor thedestroy()calls, instead of a hand-builtnew Promise.nodeModulesMeaningfulErrorWhenImportingTs,tsconfigInvalid,validateLoaderOptionNames):successLoader/makeSourceMapAndFinish→compile.loader's own frame on purpose, to match classic ts-loader's singleat Object.loaderframe. It now showsat compilethenat Object.loader. Easy to restore if we care.Testing
npm run lint,npm run comparison-tests,npm run execution-testsall pass locally (macOS).🤖 Generated with Claude Code