Skip to content

Commit

Permalink
feat(node): update bindings when necessary
Browse files Browse the repository at this point in the history
(cherry picked from commit ac4595e)
  • Loading branch information
amaanq committed Nov 10, 2024
1 parent d25a5e4 commit 2507aab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions cli/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,18 @@ pub fn generate_grammar_files(
// Generate Node bindings
if tree_sitter_config.bindings.node {
missing_path(bindings_dir.join("node"), create_dir)?.apply(|path| {
missing_path(path.join("index.js"), |path| {
generate_file(path, INDEX_JS_TEMPLATE, language_name, &generate_opts)
})?;
missing_path_else(
path.join("index.js"),
allow_update,
|path| generate_file(path, INDEX_JS_TEMPLATE, language_name, &generate_opts),
|path| {
let contents = fs::read_to_string(path)?;
if !contents.contains("bun") {
generate_file(path, INDEX_JS_TEMPLATE, language_name, &generate_opts)?;
}
Ok(())
},
)?;

missing_path(path.join("index.d.ts"), |path| {
generate_file(path, INDEX_D_TS_TEMPLATE, language_name, &generate_opts)
Expand Down
2 changes: 1 addition & 1 deletion cli/src/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const root = require("path").join(__dirname, "..", "..");
module.exports =
typeof process.versions.bun === "string"
// Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time
? require(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-typescript.node`)
? require(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-PARSER_NAME.node`)
: require("node-gyp-build")(root);

try {
Expand Down

0 comments on commit 2507aab

Please sign in to comment.