refactor(web): rename tree-sitter.js to web-tree-sitter.js

This is not breaking for consumers of the web bindings, nor the
playground as both filenames will be kept in the .github.io repo
This commit is contained in:
Amaan Qureshi 2025-02-08 13:06:44 -05:00
parent 74d7ca8582
commit a40265cbeb
19 changed files with 853 additions and 374 deletions

View file

@ -4,7 +4,7 @@ import path from 'path';
const format = process.env.CJS ? 'cjs' : 'esm';
const debug = process.argv.includes('--debug');
const outfile = `${debug ? 'debug/' : ''}tree-sitter.${format === 'esm' ? 'js' : 'cjs'}`;
const outfile = `${debug ? 'debug/' : ''}web-tree-sitter.${format === 'esm' ? 'js' : 'cjs'}`;
// Copy source files to lib directory - we'll map the wasm's sourecmap to these files.
async function copySourceFiles() {
@ -33,11 +33,13 @@ async function processWasmSourceMap(inputPath, outputPath) {
})
.map(source => {
if (source.includes('../../src/')) {
return source.replace('../../src/', 'lib/');
return source.replace('../../src/', debug ? '../lib/' : 'lib/');
} else if (source === 'tree-sitter.c') {
return debug ? '../lib/tree-sitter.c' : 'lib/tree-sitter.c';
} else {
return source;
}
return source;
});
await fs.writeFile(outputPath, JSON.stringify(sourceMap, null, 2));
}
@ -57,11 +59,11 @@ async function build() {
});
// Copy the WASM files to the appropriate spot, as esbuild doesn't "bundle" WASM files
const outputWasmName = `${debug ? 'debug/' : ''}tree-sitter.wasm`;
await fs.copyFile('lib/tree-sitter.wasm', outputWasmName);
const outputWasmName = `${debug ? 'debug/' : ''}web-tree-sitter.wasm`;
await fs.copyFile('lib/web-tree-sitter.wasm', outputWasmName);
await copySourceFiles();
await processWasmSourceMap('lib/tree-sitter.wasm.map', `${outputWasmName}.map`);
await processWasmSourceMap('lib/web-tree-sitter.wasm.map', `${outputWasmName}.map`);
}
build().catch(console.error);

View file

@ -23,7 +23,7 @@ const inputFiles = [
...listFiles('../../src'),
];
const outputFiles = ['../tree-sitter.js', '../tree-sitter.wasm'];
const outputFiles = ['../web-tree-sitter.js', '../web-tree-sitter.wasm'];
const outputMtime = Math.min(...outputFiles.map(getMtime));
for (const inputFile of inputFiles) {