AI-native design editor. Open-source Figma alternative.
fix(tools): exclude dependencies from type shape scans
Danila Poyarkov9fd1e0992a4c
diff --git a/tools/type-shapes/package.json b/tools/type-shapes/package.jsonindex 0365037c7..9e1ad7718 100644--- a/tools/type-shapes/package.json+++ b/tools/type-shapes/package.json@@ -1,5 +1,8 @@{"name": "@open-pencil/type-shapes-tools","private": true,- "type": "module"+ "type": "module",+ "scripts": {+ "test": "bun test tests"+ }}diff --git a/tools/type-shapes/src/files.ts b/tools/type-shapes/src/files.tsnew file mode 100644index 000000000..ae81ecfa2--- /dev/null+++ b/tools/type-shapes/src/files.ts@@ -0,0 +1,30 @@+export const TYPE_SHAPE_ROOTS = [+ 'src',+ 'packages/core/src',+ 'packages/vue/src',+ 'packages/cli/src',+ 'packages/mcp/src',+ 'tests',+ 'scripts',+ 'tools'+] as const++const EXCLUDED_DIRECTORIES = new Set(['node_modules', 'dist', 'coverage', '.worktrees'])++export function isTypeShapeSourcePath(path: string): boolean {+ if (path.endsWith('.d.ts')) return false+ return path.split(/[\\/]/).every((segment) => !EXCLUDED_DIRECTORIES.has(segment))+}++export async function discoverTypeShapeFiles(+ roots: readonly string[] = TYPE_SHAPE_ROOTS+): Promise<string[]> {+ const files: string[] = []+ for (const root of roots) {+ for await (const path of new Bun.Glob('**/*.{ts,tsx}').scan(root)) {+ if (!isTypeShapeSourcePath(path)) continue+ files.push(`${root}/${path}`)+ }+ }+ return files.sort()+}diff --git a/tools/type-shapes/src/index.ts b/tools/type-shapes/src/index.tsindex 13c93aa09..e11cc4d45 100644--- a/tools/type-shapes/src/index.ts+++ b/tools/type-shapes/src/index.ts@@ -1,25 +1,10 @@import ts from 'typescript'-const roots = [- 'src',- 'packages/core/src',- 'packages/vue/src',- 'packages/cli/src',- 'packages/mcp/src',- 'tests',- 'scripts',- 'tools'-]+import { discoverTypeShapeFiles } from './files'-type ShapeLocation = { file: string; line: number; name: string }+const files = await discoverTypeShapeFiles()-const files: string[] = []-for (const root of roots) {- for await (const path of new Bun.Glob('**/*.{ts,tsx}').scan(root)) {- if (path.endsWith('.d.ts')) continue- files.push(`${root}/${path}`)- }-}+type ShapeLocation = { file: string; line: number; name: string }function entityNameText(name: ts.EntityName): string {return ts.isIdentifier(name) ? name.text : `${entityNameText(name.left)}.${name.right.text}`diff --git a/tools/type-shapes/tests/files.test.ts b/tools/type-shapes/tests/files.test.tsnew file mode 100644index 000000000..e67b698c8--- /dev/null+++ b/tools/type-shapes/tests/files.test.ts@@ -0,0 +1,46 @@+import { describe, expect, test } from 'bun:test'+import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises'+import { tmpdir } from 'node:os'+import { join } from 'node:path'++import { discoverTypeShapeFiles, isTypeShapeSourcePath } from '../src/files'++describe('type shape source discovery', () => {+ test('accepts canonical TypeScript source paths', () => {+ expect(isTypeShapeSourcePath('src/app/types.ts')).toBe(true)+ expect(isTypeShapeSourcePath('packages/core/src/tool.tsx')).toBe(true)+ })++ test('excludes declarations, dependencies, and generated output on every platform', () => {+ expect(isTypeShapeSourcePath('src/global.d.ts')).toBe(false)+ expect(isTypeShapeSourcePath('tools/docs/node_modules/zod/src/types.ts')).toBe(false)+ expect(isTypeShapeSourcePath('tools\\docs\\node_modules\\zod\\src\\types.ts')).toBe(false)+ expect(isTypeShapeSourcePath('packages/mcp/dist/generated.ts')).toBe(false)+ expect(isTypeShapeSourcePath('coverage/report.ts')).toBe(false)+ expect(isTypeShapeSourcePath('.worktrees/review/src/types.ts')).toBe(false)+ })++ test('does not discover installed or generated TypeScript sources', async () => {+ const root = await mkdtemp(join(tmpdir(), 'open-pencil-type-shapes-'))+ try {+ await Promise.all([+ mkdir(join(root, 'src'), { recursive: true }),+ mkdir(join(root, 'node_modules', 'dependency'), { recursive: true }),+ mkdir(join(root, 'dist'), { recursive: true })+ ])+ await Promise.all([+ writeFile(join(root, 'src', 'local.ts'), 'export interface Local { a: string; b: string }'),+ writeFile(+ join(root, 'node_modules', 'dependency', 'source.ts'),+ 'export interface Dependency { a: string; b: string }'+ ),+ writeFile(join(root, 'dist', 'generated.ts'), 'export interface Generated { a: 1; b: 2 }'),+ writeFile(join(root, 'src', 'ambient.d.ts'), 'interface Ambient { a: string; b: string }')+ ])++ expect(await discoverTypeShapeFiles([root])).toEqual([`${root}/src/local.ts`])+ } finally {+ await rm(root, { recursive: true, force: true })+ }+ })+})