Skip to content

Commit 13682f1

Browse files
macabeusHerringtonDarkholme
authored andcommitted
update template
1 parent 306444d commit 13682f1

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

scripts/create-lang/template/index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
const path = require('node:path')
2-
const libPath = path.join(__dirname, 'parser.so')
2+
3+
function getLibPath() {
4+
const prebuild = resolvePrebuild(__dirname)
5+
if (prebuild) {
6+
return prebuild;
7+
}
8+
9+
const native = path.join(__dirname, 'parser.so');
10+
if (fs.existsSync(native)) {
11+
return native;
12+
}
13+
14+
throw new Error('No parser found. Please ensure the parser is built or a prebuild is available.');
15+
}
16+
17+
let libPath;
318

419
module.exports = {
5-
libraryPath: libPath,
20+
get libraryPath() {
21+
if (!libPath) {
22+
libPath = getLibPath();
23+
}
24+
return libPath;
25+
},
626
extensions: $$EXTENSIONS$$,
727
languageSymbol: 'tree_sitter_$$NAME$$',
828
expandoChar: '$$EXPANDO_CHAR$$',

0 commit comments

Comments
 (0)