mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 14:10:37 -07:00
Inline tree-sitter wasm and add runtime fallback (#11157)
This commit is contained in:
@@ -8,6 +8,7 @@ import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { createRequire } from 'node:module';
|
||||
import { writeFileSync } from 'node:fs';
|
||||
import { wasmLoader } from 'esbuild-plugin-wasm';
|
||||
|
||||
let esbuild;
|
||||
try {
|
||||
@@ -22,6 +23,37 @@ const __dirname = path.dirname(__filename);
|
||||
const require = createRequire(import.meta.url);
|
||||
const pkg = require(path.resolve(__dirname, 'package.json'));
|
||||
|
||||
function createWasmPlugins() {
|
||||
const wasmBinaryPlugin = {
|
||||
name: 'wasm-binary',
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /\.wasm\?binary$/ }, (args) => {
|
||||
const specifier = args.path.replace(/\?binary$/, '');
|
||||
const resolveDir = args.resolveDir || '';
|
||||
const isBareSpecifier =
|
||||
!path.isAbsolute(specifier) &&
|
||||
!specifier.startsWith('./') &&
|
||||
!specifier.startsWith('../');
|
||||
|
||||
let resolvedPath;
|
||||
if (isBareSpecifier) {
|
||||
resolvedPath = require.resolve(specifier, {
|
||||
paths: resolveDir ? [resolveDir, __dirname] : [__dirname],
|
||||
});
|
||||
} else {
|
||||
resolvedPath = path.isAbsolute(specifier)
|
||||
? specifier
|
||||
: path.join(resolveDir, specifier);
|
||||
}
|
||||
|
||||
return { path: resolvedPath, namespace: 'wasm-embedded' };
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
return [wasmBinaryPlugin, wasmLoader({ mode: 'embedded' })];
|
||||
}
|
||||
|
||||
const external = [
|
||||
'@lydell/node-pty',
|
||||
'node-pty',
|
||||
@@ -51,6 +83,7 @@ const cliConfig = {
|
||||
define: {
|
||||
'process.env.CLI_VERSION': JSON.stringify(pkg.version),
|
||||
},
|
||||
plugins: createWasmPlugins(),
|
||||
alias: {
|
||||
'is-in-ci': path.resolve(__dirname, 'packages/cli/src/patches/is-in-ci.ts'),
|
||||
},
|
||||
@@ -67,6 +100,7 @@ const a2aServerConfig = {
|
||||
define: {
|
||||
'process.env.CLI_VERSION': JSON.stringify(pkg.version),
|
||||
},
|
||||
plugins: createWasmPlugins(),
|
||||
};
|
||||
|
||||
Promise.allSettled([
|
||||
|
||||
Reference in New Issue
Block a user