char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

char/aliceai-t5-moe
1.6 KiB51 linesraw
1import { build } from 'esbuild';
2import { dirname, resolve } from 'path';
3import { fileURLToPath } from 'url';
4import type { Plugin } from 'vite';
5
6const __dirname = dirname(fileURLToPath(import.meta.url));
7const VENDORS_DIR = resolve(__dirname, '../src/lib/vendors');
8const VIRTUAL_ID = 'virtual:nerdamer';
9const RESOLVED_ID = '\0' + VIRTUAL_ID;
10
11/**
12 * Bundle the vendored nerdamer-prime source into a minified IIFE string,
13 * exposed as the `virtual:nerdamer` module. Flags mirror the upstream
14 * build (esbuild --bundle --minify --format=iife --global-name=nerdamer),
15 * so only human readable source lives in the repo and minification is a
16 * build artifact. Vendored under src/lib/vendors/, upstream snapshot:
17 * https://github.com/together-science/nerdamer-prime/commit/1936145f8af306ec0d883b9bfd7730aedd175c24
18 */
19export function nerdamerPlugin(): Plugin {
20	let bundled: string | null = null;
21
22	return {
23		async load(id) {
24			if (id !== RESOLVED_ID) return undefined;
25
26			if (bundled === null) {
27				const result = await build({
28					alias: {
29						'big-integer': resolve(VENDORS_DIR, 'big-integer/BigInteger.js'),
30						'decimal.js': resolve(VENDORS_DIR, 'decimal.js/decimal.js')
31					},
32					bundle: true,
33					entryPoints: [resolve(VENDORS_DIR, 'nerdamer-prime/all.js')],
34					format: 'iife',
35					globalName: 'nerdamer',
36					logLevel: 'silent',
37					minify: true,
38					write: false
39				});
40
41				bundled = result.outputFiles[0].text;
42			}
43
44			return `export default ${JSON.stringify(bundled)};`;
45		},
46		name: 'llamacpp:nerdamer',
47		resolveId(id) {
48			return id === VIRTUAL_ID ? RESOLVED_ID : undefined;
49		}
50	};
51}