node-gyp-build performs runtime checks for figuring out where the .node file is, but those runtime checks are difficult for static analysis to figure out where the .node file is. If we can rely on the prebuild to exist, we can use a template string and Bun will inline the process.platform, process.arch, and process.versions.bun fields within --compile.
bun build --compile --format=cjs ./foo.js
Where foo.js is:
const Parser = require('tree-sitter');
const JavaScript = require('tree-sitter-javascript');
const parser = new Parser();
parser.setLanguage(JavaScript);
const sourceCode = 'let x = 1; console.log(x);';
const tree = parser.parse(sourceCode);
console.log(tree);
This unblocks using
tree-sitter
in single-file executablesnode-gyp-build
performs runtime checks for figuring out where the.node
file is, but those runtime checks are difficult for static analysis to figure out where the.node
file is. If we can rely on the prebuild to exist, we can use a template string and Bun will inline theprocess.platform
,process.arch
, andprocess.versions.bun
fields within--compile
.Where
foo.js
is:Related PRs: