refactor: modernize to ES6+ (Node 10) with perf improvements#86
Merged
alexander-akait merged 3 commits intomainfrom Apr 23, 2026
Merged
refactor: modernize to ES6+ (Node 10) with perf improvements#86alexander-akait merged 3 commits intomainfrom
alexander-akait merged 3 commits intomainfrom
Conversation
Bump engines.node to >=10.13.0 and modernize the loader runner:
- Replace `arguments`/`Array.prototype.slice.call` and `.apply(null, arguments)`
with rest parameters and spread calls across `runSyncOrAsync`,
`iterateNormalLoaders`, `iteratePitchingLoaders`, and `processResource`.
- Convert the normal/pitching iteration from recursion to iterative while
loops so chains of already-executed or pitch-less loaders no longer grow
the call stack and no longer allocate closures per skipped loader.
- Add `escapeHash`, a short-circuiting `#`-escape helper, so the `request`
and `resource` getters skip the regex scan when the input contains no `#`.
- Replace `.slice().map().concat().join("!")` request composition with a
single `joinRequests` loop (and a dedicated small loop for
`previousRequest`), avoiding the intermediate arrays.
- Destructure the object-form `request` assignment, collapse the
`null`/`undefined` options branch, and clean up the getters with arrow
helpers and `.slice()` for dependency getters.
- In `loadLoader.js`, drop the legacy `process.nextTick` EMFILE fallback
and use `setImmediate(loadLoader, loader, callback)` directly, and
remove the obsolete eslint-disable for `pathToFileURL`.
- Drop the `Error.captureStackTrace` shim in `LoaderLoadingError` since
Node 10+ captures stack traces correctly for subclassed Errors.
- `utf8BufferToString` detects the UTF-8 BOM (EF BB BF) on the Buffer
directly and passes an offset to `toString("utf8", 3)`, avoiding the
need to decode then `slice(1)` a JS string for BOM-prefixed inputs.
- Replace `args.some(predicate)` in the pitch callback with a tight
for-loop so we don't allocate an arrow closure per pitched loader.
- Use a direct `args[0]` read in `processResource` instead of array
destructuring when assigning `resourceBuffer`.
- Drop the now-dead `Object.preventExtensions` guards (always present
on Node 10+).
- Drop the `|| ""` coalesces and the redundant `remainingRequest`
short-circuit: `loaderContext.resource` is always a string, and
`joinRequests` naturally returns `""` when start >= end with an
empty resource, so the extra branches only added overhead.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #86 +/- ##
==========================================
+ Coverage 92.74% 94.31% +1.57%
==========================================
Files 3 3
Lines 262 264 +2
==========================================
+ Hits 243 249 +6
+ Misses 19 15 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
refactor: rewrite code to more modern