Skip to content

Make multi-addon resolve tests independent of readdir order - #89

Open
cpruijsen wants to merge 2 commits into
prebuild:masterfrom
cpruijsen:fix/issue-83
Open

cpruijsen wants to merge 2 commits into
prebuild:masterfrom
cpruijsen:fix/issue-83

Conversation

@cpruijsen

Copy link
Copy Markdown

node-gyp-build picks the wrong .node file when build/Release holds more than one. getFirst
returns the first entry matching a generic pattern, and directory order is arbitrary, so a package
that builds several addons, or leaves an old artifact behind, can load one that is not its own.

node-gyp-build.js now collects the names the binding could legitimately have and prefers a match
among them. candidateNames reads every target_name out of binding.gyp, which is what the build
actually produces, and adds the package name normalised the way node-gyp normalises it, dashes to
underscores and any scope dropped.

Both the Release and Debug lookups take the list, so the two cannot disagree about which addon belongs
to the package.

When nothing matches, the previous first-match behaviour is what remains, so a package whose
binding.gyp cannot be read or whose output is named something else keeps loading as it did.

Fixes #83

When binding.gyp builds more than one target into build/Release or
build/Debug (e.g. an addon plus a test_extension), the first .node file
found by readdir could be the wrong one. Prefer the literal target names
declared in binding.gyp, then the normalized package name, falling back
to the first match as before.
readdir order is filesystem-defined, so a fixture can already return
the preferred .node first and the new tests pass without the production
change. Force the decoy name first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect node file matched when multiple node files in Release directory.

1 participant