Fix target-qualified native loader preflight - #24
Merged
Conversation
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
Target-qualified native loaders can check their original
.nodefilename before requiring it. During a build, the plugin rewrites that require to an emitted hashed asset, so the original preflight check no longer describes the runtime file and can throw first.This patch removes that throw-only preflight guard only after the plugin has resolved and rewritten the matching native-path require. It also increments the package version to
2.4.2.What This PR Does
if (!existsSync(nativePath)) throw ...guards for native path variables.require(nativePath)is rewritten to an emitted native asset.What This Improves
Target-qualified native loaders can use hashed emitted addon filenames without retaining an existence check for the original source filename.
What This Does Not Do
Important Context
The native source file must already be present for the plugin to resolve and emit it. The guard removal is tied to that successful resolution rather than to a filename pattern alone.
Code To Review Closely
src/index.ts:1552Review that the preflight guard is removed only on the same path-variable branch that has already resolved a real native file and replaced its require call.
Gotchas, Risks, And Edge Cases
existsSyncguard is removed only when its path variable has a matching successful native-module rewrite.Tests And Regression Coverage
Validation Run
pnpm test: passed — 205 tests.pnpm lint: passed — formatting, lint, and type checks.pnpm build: passed.pnpm precommit: unavailable — this repository defines noprecommitscript.Coverage Assessment
Sufficient for this transform regression: one test inspects the transformed loader, and another verifies Vite emits and references the native asset without the stale guard.
Regressions These Tests Should Catch
require(nativePath)while leaving a stale preflight throw in the output.Gaps And Recommended Follow-Up Tests
Follow-Up Work
Not applicable.