mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
// The native-addon trap fixture: a napi-style binding package requiring
|
|
// its .node lazily (rolldown/oxc/keyring's shape). The compiled binary
|
|
// embeds a throwing ERR_DLOPEN_FAILED stub instead of the addon's machine
|
|
// code; Node dlopens the (garbage) file and fails with its own platform
|
|
// message — so the probes report SHAPE (instanceof, code), never message
|
|
// text, and the one message probe is asserted scriptc-only (divergent).
|
|
"use strict";
|
|
|
|
function shape(fn) {
|
|
try {
|
|
fn();
|
|
return "loaded";
|
|
} catch (e) {
|
|
return "caught:" + (e instanceof Error) + ":" + e.code;
|
|
}
|
|
}
|
|
|
|
exports.probeAddon = () => shape(() => require("./addon.node"));
|
|
// Retry semantics: a throwing module leaves no cache entry, so the
|
|
// second call throws again (never an empty exports object).
|
|
exports.probeAddonAgain = () => shape(() => require("./addon.node"));
|
|
// Extensionless require probing the .node candidate (Node's require
|
|
// extension list), through a directory hop.
|
|
exports.probeExtensionless = () => shape(() => require("./binding"));
|
|
exports.probeMessage = () => {
|
|
try {
|
|
require("./addon.node");
|
|
return "loaded";
|
|
} catch (e) {
|
|
return e.message;
|
|
}
|
|
};
|