Baseline: tree as shared

This commit is contained in:
alexm committed 2026-10-05 03:03:38 +00:00
commit 31f2fb8a5a
1679 files changed
+1024562

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
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' });
Vendored Executable
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# Rebuilds src/vendor/codemirror.js (one ES module) and src/vendor/cm-types/ (its
# declarations) from the CodeMirror packages' own sources on GitHub.
#
# Programming+ ships no bundler and no runtime dependency; CodeMirror is
# vendored the way the pseudo and asm86 engines are, as a built file checked
# into the repository. Rerun this to move to newer CodeMirror releases:
#
# scripts/vendor/codemirror.sh # the packages' main branches
# scripts/vendor/codemirror.sh @6.5.0 ... # (edit PINS below for exact tags)
#
# Needs: git, node >= 20, esbuild on the PATH or in ESBUILD, and tsc.
set -euo pipefail
here="$(cd "$(dirname "$0")" && pwd)"
root="$(cd "$here/../.." && pwd)"
work="${CM_WORK:-$(mktemp -d)}"
ESBUILD="${ESBUILD:-$(command -v esbuild || true)}"
[ -n "$ESBUILD" ] || { echo "esbuild not found: npm i -g esbuild, or ESBUILD=/path/to/esbuild"; exit 1; }
# repo -> directory name the build script expects
PINS=(
"codemirror/state state" "codemirror/view view" "codemirror/language language" "codemirror/commands commands" "codemirror/search search"
"marijnh/style-mod style-mod" "marijnh/w3c-keyname w3c-keyname" "marijnh/crelt crelt" "marijnh/find-cluster-break find-cluster-break"
"lezer-parser/common common" "lezer-parser/highlight highlight" "lezer-parser/lr lr"
)
cd "$work"
for pin in "${PINS[@]}"; do
set -- $pin
[ -d "$2" ] || git clone -q --depth 1 "https://github.com/$1" "$2"
done
# two packages have no src/index.ts of their own
printf 'export * from "./commands"\nexport * from "./history"\nexport * from "./comment"\n' > commands/src/index.ts
printf 'export * from "./search"\nexport * from "./cursor"\nexport * from "./regexp"\nexport * from "./goto-line"\nexport * from "./selection-match"\n' > search/src/index.ts
cp "$here/entry.ts" "$here/build.mjs" "$here/relink.mjs" "$here/tsconfig.cm.json" .
mv tsconfig.cm.json tsconfig.json
ESBUILD_LIB="$(node -e "console.log(require.resolve('esbuild', { paths: [process.cwd(), '$(dirname "$ESBUILD")/..', '$(npm root -g)'] }))")" node build.mjs
rm -rf types && (tsc -p tsconfig.json || true) # the packages' own sources have a few strict-mode complaints; the declarations still emit
node relink.mjs
rm -rf "$root/src/vendor/cm-types"
cp codemirror.js "$root/src/vendor/codemirror.js"
cp -r types "$root/src/vendor/cm-types"
rm "$root/src/vendor/cm-types/entry.d.ts"
sed 's#"\./#"./cm-types/#g' types/entry.d.ts > "$root/src/vendor/codemirror.d.ts"
cp state/LICENSE "$root/src/vendor/CODEMIRROR-LICENSE"
echo "vendored into $root/src/vendor from $work"
+6
View File
@@ -0,0 +1,6 @@
// Programming+'s CodeMirror 6 bundle: the parts the editor uses, in one ES module.
export * from '@codemirror/state';
export * from '@codemirror/view';
export { history, historyKeymap, undo, redo, defaultKeymap, indentWithTab, insertNewlineAndIndent, toggleComment, selectAll, indentMore, indentLess } from '@codemirror/commands';
export { search, searchKeymap, highlightSelectionMatches, openSearchPanel, closeSearchPanel, gotoLine } from '@codemirror/search';
export { indentUnit, bracketMatching, foldGutter, foldKeymap, codeFolding, foldService, indentService, StreamLanguage, LanguageSupport, syntaxHighlighting, HighlightStyle, defaultHighlightStyle } from '@codemirror/language';
+24
View File
@@ -0,0 +1,24 @@
import fs from 'node:fs'; import path from 'node:path';
const root = path.resolve('types');
const map = {
'@codemirror/state': 'state/src/index.d.ts', '@codemirror/view': 'view/src/index.d.ts', '@codemirror/language': 'language/src/index.d.ts',
'@codemirror/commands': 'commands/src/index.d.ts', '@codemirror/search': 'search/src/index.d.ts',
'@lezer/common': 'common/src/index.d.ts', '@lezer/highlight': 'highlight/src/highlight.d.ts', '@lezer/lr': 'lr/src/index.d.ts',
'style-mod': 'style-mod/src/style-mod.d.ts', 'w3c-keyname': 'w3c-keyname/index.d.ts', 'crelt': 'crelt/index.d.ts', '@marijn/find-cluster-break': 'find-cluster-break/src/index.d.ts',
};
// the plain-JS deps' hand-written d.ts files were not emitted by tsc; copy them in
for (const [k, v] of Object.entries(map)) { const dst = path.join(root, v); if (!fs.existsSync(dst)) { fs.mkdirSync(path.dirname(dst), { recursive: true }); fs.copyFileSync(path.join(k === '@marijn/find-cluster-break' ? 'find-cluster-break/src/index.d.ts' : v), dst); } }
const walk = (d) => fs.readdirSync(d, { withFileTypes: true }).flatMap((e) => e.isDirectory() ? walk(path.join(d, e.name)) : e.name.endsWith('.d.ts') ? [path.join(d, e.name)] : []);
let n = 0;
for (const f of walk(root)) {
let s = fs.readFileSync(f, 'utf8');
const before = s;
s = s.replace(/from ["']([^"']+)["']/g, (m, spec) => {
if (!map[spec]) return m;
let rel = path.relative(path.dirname(f), path.join(root, map[spec])).replace(/\\/g, '/').replace(/\.d\.ts$/, '.js');
if (!rel.startsWith('.')) rel = './' + rel;
return `from "${rel}"`;
});
if (s !== before) { fs.writeFileSync(f, s); n++; }
}
console.log('relinked', n, 'files');
+64
View File
@@ -0,0 +1,64 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
"lib": [
"ES2022",
"DOM",
"DOM.Iterable"
],
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "types",
"rootDir": ".",
"strict": false,
"skipLibCheck": true,
"allowJs": true,
"stripInternal": true,
"types": [],
"baseUrl": ".",
"ignoreDeprecations": "6.0",
"paths": {
"@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.d.ts"
],
"w3c-keyname": [
"w3c-keyname/index.d.ts"
],
"crelt": [
"crelt/index.d.ts"
],
"@marijn/find-cluster-break": [
"find-cluster-break/src/index.d.ts"
]
}
},
"files": [
"entry.ts"
]
}