diff --git a/cli/src/init.rs b/cli/src/init.rs index 6d1e7b35..0db4b5d9 100644 --- a/cli/src/init.rs +++ b/cli/src/init.rs @@ -480,9 +480,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) diff --git a/cli/src/templates/index.js b/cli/src/templates/index.js index a269e6da..88437495 100644 --- a/cli/src/templates/index.js +++ b/cli/src/templates/index.js @@ -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 {