/
githubmirror
/
tldraw
Обзор
Документация
Войти
/
githubmirror
/
tldraw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
internal/scripts/api-check.ts
101 строка
3 KB
Jessica Claire Edwards
feat: commenting (#9471)
30 июл 2026, 14:08
Не верифицирован
30 июл 2026, 14:08
584d9b1
Код
Авторство
О чём код?
import { readFileSync, writeFileSync } from 'fs' import { join, resolve } from 'path' import { exec } from './lib/exec' import { readFileIfExists } from './lib/file' import { nicelog } from './lib/nicelog' import { getAllWorkspacePackages } from './lib/workspace' const packagesOurTypesCanDependOn = [ '@types/lodash.throttle', '@types/lodash.uniq', '@types/lodash.isequal', '@types/lodash.isequalwith', '@types/react', '@types/react-dom', 'eventemitter3', 'nanoevents', 'react', 'react-dom', ] // These packages use subpath exports which require moduleResolution: "bundler". // We pin to the workspace's resolved versions to avoid installing broken releases. const pinnedPackages = [ '@tiptap/core', '@tiptap/extension-mention', '@tiptap/pm', '@tiptap/react', '@tiptap/starter-kit', '@tiptap/suggestion', ] function getPinnedVersions(): string[] { return pinnedPackages.map((pkg) => { const pkgJsonPath = resolve(`./node_modules/${pkg}/package.json`) const { version } = JSON.parse(readFileSync(pkgJsonPath, 'utf8')) return `${pkg}@${version}` }) } function getTempDeclarationFilename(packageName: string): string { // Keep filenames unique across similarly named packages like `tldraw` and `@tldraw/tldraw`. return ( packageName .replace(/^@/, '') .replace(/\//g, '__') .replace(/[^a-zA-Z0-9_.-]/g, '_') + '.d.ts' ) } main() async function main() { const tsconfig: any = { compilerOptions: { lib: ['esnext', 'dom'], strict: true, module: 'esnext', moduleResolution: 'bundler', rootDir: '.', paths: {}, esModuleInterop: true, }, files: [], } const tempDir = (await exec('mktemp', ['-d'])).trim() nicelog(`Working in ${tempDir}`) const packages = (await getAllWorkspacePackages()) .filter(({ packageJson }) => !packageJson.private) .sort((a, b) => a.name.localeCompare(b.name)) nicelog( 'Checking packages:', packages.map(({ packageJson }) => packageJson.name) ) for (const { name, relativePath } of packages) { const declarationFilename = getTempDeclarationFilename(name) const dtsFile = await readFileIfExists(join(relativePath, 'api', 'public.d.ts')) if (!dtsFile) { nicelog(`No public.d.ts for ${name}, skipping`) continue } writeFileSync(join(tempDir, declarationFilename), dtsFile, 'utf8') tsconfig.compilerOptions.paths[name] = [`./${declarationFilename}`] tsconfig.files.push(`./${declarationFilename}`) } nicelog('Checking with tsconfig:', tsconfig) writeFileSync(`${tempDir}/tsconfig.json`, JSON.stringify(tsconfig, null, '\t'), 'utf8') writeFileSync(`${tempDir}/package.json`, JSON.stringify({ dependencies: {} }, null, '\t'), 'utf8') await exec('npm', ['install', ...packagesOurTypesCanDependOn, ...getPinnedVersions()], { pwd: tempDir, }) await exec(resolve('./node_modules/.bin/tsc'), [], { pwd: tempDir }) await exec('rm', ['-rf', tempDir]) }