mirror of
https://github.com/rmccorkl/TubeSage.git
synced 2026-07-22 06:45:31 +00:00
Replace @langchain/core's tiktoken helper with a network-free stub via an esbuild onLoad plugin. The upstream module lazy-fetches tokenizer data from https://tiktoken.pages.dev; TubeSage never counts tokens, so that path was unreachable, but the URL still sat in the bundle and showed up as an external domain on the Obsidian plugin scorecard. The stub removes it from main.js entirely. - esbuild.config.mjs: add the stub-langchain-tiktoken onLoad plugin - README.md: drop the tiktoken.pages.dev disclosure (no longer contacted) - bump manifest.json / package.json / package-lock.json to 1.3.1 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
74 lines
2.1 KiB
JavaScript
74 lines
2.1 KiB
JavaScript
import esbuild from "esbuild";
|
|
import process from "process";
|
|
import { builtinModules } from "module";
|
|
|
|
const banner =
|
|
`/*
|
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
if you want to view the source, please visit the github repository of this plugin
|
|
*/
|
|
`;
|
|
|
|
const prod = process.argv[2] === "production";
|
|
|
|
// Replace @langchain/core's tiktoken helper with a network-free stub.
|
|
// The upstream module lazy-fetches tokenizer data from
|
|
// https://tiktoken.pages.dev at runtime. TubeSage never counts tokens, so
|
|
// that code path is unreachable; stubbing it keeps the URL (and the implied
|
|
// external request) out of the bundle entirely.
|
|
const stubLangchainTiktoken = {
|
|
name: "stub-langchain-tiktoken",
|
|
setup(build) {
|
|
build.onLoad(
|
|
{ filter: /[\\/]@langchain[\\/]core[\\/]dist[\\/]utils[\\/]tiktoken\.[cm]?js$/ },
|
|
() => ({
|
|
contents:
|
|
'export async function getEncoding(){throw new Error("tiktoken token-counting is not bundled in TubeSage");}\n' +
|
|
'export async function encodingForModel(){throw new Error("tiktoken token-counting is not bundled in TubeSage");}\n',
|
|
loader: "js",
|
|
}),
|
|
);
|
|
},
|
|
};
|
|
|
|
const context = await esbuild.context({
|
|
banner: {
|
|
js: banner,
|
|
},
|
|
entryPoints: ["main.ts"],
|
|
bundle: true,
|
|
external: [
|
|
"obsidian",
|
|
"electron",
|
|
"@codemirror/autocomplete",
|
|
"@codemirror/collab",
|
|
"@codemirror/commands",
|
|
"@codemirror/language",
|
|
"@codemirror/lint",
|
|
"@codemirror/search",
|
|
"@codemirror/state",
|
|
"@codemirror/view",
|
|
"@lezer/common",
|
|
"@lezer/highlight",
|
|
"@lezer/lr",
|
|
...builtinModules,
|
|
],
|
|
format: "cjs",
|
|
target: "es2018",
|
|
logLevel: "info",
|
|
sourcemap: prod ? false : "inline",
|
|
treeShaking: true,
|
|
outfile: "main.js",
|
|
loader: {
|
|
'.css': 'text',
|
|
'.wasm': 'file'
|
|
},
|
|
plugins: [stubLangchainTiktoken],
|
|
});
|
|
|
|
if (prod) {
|
|
await context.rebuild();
|
|
process.exit(0);
|
|
} else {
|
|
await context.watch();
|
|
}
|