Baseline: tree as shared
This commit is contained in:
1679 files changed
+1024562
No files matched your search
Vendored
+24
@@ -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');
|
||||
Reference in new issue
Block a user