Files
pplus-web/scripts/vendor/build.mjs
T
2026-10-05 03:03:38 +00:00

16 lines
1.6 KiB
JavaScript

const esbuild = await import(process.env.ESBUILD_LIB || 'esbuild');
import path from 'node:path';
import fs from 'node:fs';
const here = path.dirname(new URL(import.meta.url).pathname);
const map = {
'@codemirror/state': 'state/src/index.ts', '@codemirror/view': 'view/src/index.ts', '@codemirror/language': 'language/src/index.ts',
'@codemirror/commands': 'commands/src/index.ts', '@codemirror/search': 'search/src/index.ts',
'@lezer/common': 'common/src/index.ts', '@lezer/highlight': 'highlight/src/highlight.ts', '@lezer/lr': 'lr/src/index.ts',
'style-mod': 'style-mod/src/style-mod.js', 'w3c-keyname': 'w3c-keyname/index.js', 'crelt': 'crelt/index.js', '@marijn/find-cluster-break': 'find-cluster-break/src/index.js',
};
const alias = { name: 'alias', setup(b) { b.onResolve({ filter: /^(@codemirror|@lezer|@marijn)\/|^(style-mod|w3c-keyname|crelt)$/ }, (a) => ({ path: path.join(here, map[a.path]) })); } };
const versions = Object.entries(map).map(([k, v]) => `${k}@${JSON.parse(fs.readFileSync(path.join(here, v.split('/')[0], 'package.json'), 'utf8')).version}`);
const banner = `/* CodeMirror 6, bundled for Programming+ from the packages' sources (MIT; see CODEMIRROR-LICENSE next to this file).\n * ${versions.join(' ')}\n * Rebuild with scripts/vendor/codemirror.sh; do not edit by hand. */`;
await esbuild.build({ entryPoints: [path.join(here, 'entry.ts')], bundle: true, format: 'esm', outfile: path.join(here, 'codemirror.js'), plugins: [alias], target: 'es2022', minifyWhitespace: true, minifySyntax: true, legalComments: 'none', banner: { js: banner }, logLevel: 'info' });