Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support compiling single-file executables via bun build --compile #230

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

Jarred-Sumner
Copy link
Contributor

@Jarred-Sumner Jarred-Sumner commented Nov 1, 2024

This unblocks using tree-sitter in single-file executables

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);
rm -rf node_modules
./foo

Related PRs:

@amaanq
Copy link
Member

amaanq commented Nov 1, 2024

thanks!

@amaanq amaanq merged commit 6b9e725 into tree-sitter:master Nov 1, 2024
9 checks passed
@ObserverOfTime
Copy link
Member

If we can rely on the prebuild to exist

If we could, we wouldn't need node-gyp-build in the first place.

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.

3 participants