Repository navigation
perf(core): check a CommonJS result's source before reading the file again - #830
Merged
Merged
Conversation
…again Since #822, transform_output compared a commonjs result's source with the file — a read — and then load_commonjs_esm read it once more to check its syntax, so a CommonJS-package file with ES module syntax was read twice more than v0.1.6 for no benefit: the flip only depends on the source in hand. load_commonjs_esm and reject_cts_module_syntax now take an optional source and read the file only when given none, and transform_output runs the syntax check first and compares bytes only for a file that stays CommonJS. .cts keeps the byte compare before the check so hook-supplied source keeps its error ordering. Fixes #827
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Summary
Fixes #827. Since #822, a file in a CommonJS package that uses ES module syntax was read from disk twice more before being transformed on the
registerHooks()path: once bysource_matches_file's byte compare and once byload_commonjs_esm's syntax check — yet the answer for such a file only depends on the sourcedefaultLoadSyncalready handed the hook.load_commonjs_esmandreject_cts_module_syntaxnow take anOption<&str>and only touch the disk when the caller has no source.transform_outputchecks the in-hand source's syntax first and runssource_matches_fileonly for a file that stays CommonJS:.ctsstill compares bytes before the syntax check, so a hook-supplied.ctssource keeps the error ordering it had before this reorder.load_commonjs_esm'sModule::Esmtransform (matching themodule.register()path) instead ofPreserve; documented in the block comment, along with the parse-twice cost for the narrow differing-source-stays-CJS case.Test plan
open()interpose (repro script) went from 3 opens per ESM-syntax.tsfile to 1 on Node 26.11 — parity with thetype: "module"control..ctswithexportstill rejected with the same error;.ctsCommonJS entry still defers;data:/custom-scheme sources still keep their source.pnpm test,vp check,cargo clippypass; fixtures verified on Node 24.21 (module.register()) and 26.11 (registerHooks()).