@contentrain/mcp 2.3.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{annotations-D3tlsF38.mjs → annotations-C-tQVmot.mjs} +15 -1
- package/dist/annotations-C-tQVmot.mjs.map +1 -0
- package/dist/{apply-manager-SLCRLHN_.mjs → apply-manager-BybvnUVC.mjs} +28 -18
- package/dist/apply-manager-BybvnUVC.mjs.map +1 -0
- package/dist/{astro-parser-LNjEspnf.mjs → astro-parser-Cb9uuBpW.mjs} +3 -3
- package/dist/{astro-parser-LNjEspnf.mjs.map → astro-parser-Cb9uuBpW.mjs.map} +1 -1
- package/dist/{availability-sWWRz2W0.mjs → availability-Dgcmvv99.mjs} +1 -1
- package/dist/{availability-sWWRz2W0.mjs.map → availability-Dgcmvv99.mjs.map} +1 -1
- package/dist/{branch-lifecycle-BAfgSQBv.mjs → branch-lifecycle-B6PXZ2N7.mjs} +11 -61
- package/dist/branch-lifecycle-B6PXZ2N7.mjs.map +1 -0
- package/dist/{branch-lifecycle-D4W0WIs4.d.mts → branch-lifecycle-DhzHfzs3.d.mts} +1 -1
- package/dist/{branch-lifecycle-D4W0WIs4.d.mts.map → branch-lifecycle-DhzHfzs3.d.mts.map} +1 -1
- package/dist/{compiler-CNzm2Y2I.mjs → compiler-B6hNQeCC.mjs} +2 -2
- package/dist/{compiler-CNzm2Y2I.mjs.map → compiler-B6hNQeCC.mjs.map} +1 -1
- package/dist/{compiler-sfc.cjs-y0B0L3MH.mjs → compiler-sfc.cjs-8yY7b5bx.mjs} +2 -2
- package/dist/{compiler-sfc.cjs-y0B0L3MH.mjs.map → compiler-sfc.cjs-8yY7b5bx.mjs.map} +1 -1
- package/dist/{config-oxxgznz7.mjs → config-VlRKRwAS.mjs} +1 -1
- package/dist/{config-oxxgznz7.mjs.map → config-VlRKRwAS.mjs.map} +1 -1
- package/dist/{content-manager-DWo3G64y.d.mts → content-manager-Dn4tqDw1.d.mts} +10 -7
- package/dist/content-manager-Dn4tqDw1.d.mts.map +1 -0
- package/dist/{context-DjglDPvj.mjs → context-C3x6I3cE.mjs} +4 -4
- package/dist/{context-DjglDPvj.mjs.map → context-C3x6I3cE.mjs.map} +1 -1
- package/dist/core/apply-manager.d.mts +8 -0
- package/dist/core/apply-manager.d.mts.map +1 -1
- package/dist/core/apply-manager.mjs +10 -9
- package/dist/core/config.d.mts +1 -1
- package/dist/core/config.mjs +1 -1
- package/dist/core/content-manager.d.mts +2 -2
- package/dist/core/content-manager.mjs +2 -2
- package/dist/core/context.d.mts +1 -1
- package/dist/core/context.mjs +5 -5
- package/dist/core/contracts/index.d.mts +2 -2
- package/dist/core/doctor.mjs +7 -6
- package/dist/core/graph-builder.mjs +2 -2
- package/dist/core/meta-manager.d.mts +8 -9
- package/dist/core/meta-manager.d.mts.map +1 -1
- package/dist/core/meta-manager.mjs +2 -2
- package/dist/core/model-manager.d.mts +39 -3
- package/dist/core/model-manager.d.mts.map +1 -1
- package/dist/core/model-manager.mjs +3 -3
- package/dist/core/ops/index.d.mts +40 -3
- package/dist/core/ops/index.d.mts.map +1 -1
- package/dist/core/ops/index.mjs +4 -4
- package/dist/core/overlay-reader.d.mts +1 -1
- package/dist/core/overlay-reader.mjs +1 -1
- package/dist/core/scan-config.mjs +1 -1
- package/dist/core/scanner.mjs +3 -3
- package/dist/core/validator/index.d.mts +1 -1
- package/dist/core/validator/index.d.mts.map +1 -1
- package/dist/core/validator/index.mjs +4 -4
- package/dist/{detect-CdDU4Ew_.mjs → detect-B0oXbQaP.mjs} +1 -1
- package/dist/{detect-CdDU4Ew_.mjs.map → detect-B0oXbQaP.mjs.map} +1 -1
- package/dist/{doctor-BwJ_nmqS.mjs → doctor-DNPuGgcg.mjs} +28 -15
- package/dist/doctor-DNPuGgcg.mjs.map +1 -0
- package/dist/{errors-e0YdjooK.mjs → errors-CvBS12e7.mjs} +1 -1
- package/dist/{errors-e0YdjooK.mjs.map → errors-CvBS12e7.mjs.map} +1 -1
- package/dist/fs-DLbVB-Ek.mjs.map +1 -1
- package/dist/git/branch-lifecycle.d.mts +1 -1
- package/dist/git/branch-lifecycle.mjs +3 -2
- package/dist/git/identity.d.mts +42 -0
- package/dist/git/identity.d.mts.map +1 -0
- package/dist/git/identity.mjs +2 -0
- package/dist/git/transaction.d.mts +1 -1
- package/dist/git/transaction.d.mts.map +1 -1
- package/dist/git/transaction.mjs +9 -8
- package/dist/{graph-builder-DK4Mh8Tn.mjs → graph-builder-BEocwW13.mjs} +2 -2
- package/dist/{graph-builder-DK4Mh8Tn.mjs.map → graph-builder-BEocwW13.mjs.map} +1 -1
- package/dist/{id-DV_T9Ic8.mjs → id-BjhaIxTL.mjs} +1 -1
- package/dist/{id-DV_T9Ic8.mjs.map → id-BjhaIxTL.mjs.map} +1 -1
- package/dist/identity-D8QoGxhT.mjs +125 -0
- package/dist/identity-D8QoGxhT.mjs.map +1 -0
- package/dist/{index-w8QHThNS.d.mts → index-BWbTJlXm.d.mts} +2 -2
- package/dist/index.mjs +21 -20
- package/dist/index.mjs.map +1 -1
- package/dist/{local-8dJ5NIWL.mjs → local-Db5X9mjZ.mjs} +25 -13
- package/dist/local-Db5X9mjZ.mjs.map +1 -0
- package/dist/{meta-manager-CJUiTgP2.mjs → meta-manager-B_Se183X.mjs} +29 -5
- package/dist/meta-manager-B_Se183X.mjs.map +1 -0
- package/dist/{model-manager-DP2CZiMT.mjs → model-manager-DgyKMjLN.mjs} +169 -25
- package/dist/model-manager-DgyKMjLN.mjs.map +1 -0
- package/dist/{node-BxujauDw.mjs → node-DUGiIkv1.mjs} +1 -1
- package/dist/{node-BxujauDw.mjs.map → node-DUGiIkv1.mjs.map} +1 -1
- package/dist/{ops-CGKIKwDc.mjs → ops-BzbThweu.mjs} +165 -26
- package/dist/ops-BzbThweu.mjs.map +1 -0
- package/dist/{overlay-reader-DNaVsgiS.mjs → overlay-reader-CkU_pGXZ.mjs} +1 -1
- package/dist/{overlay-reader-DNaVsgiS.mjs.map → overlay-reader-CkU_pGXZ.mjs.map} +1 -1
- package/dist/{paths-enT2coeX.mjs → paths-CdPPWpbG.mjs} +1 -1
- package/dist/{paths-enT2coeX.mjs.map → paths-CdPPWpbG.mjs.map} +1 -1
- package/dist/providers/github/index.d.mts +1 -1
- package/dist/providers/github/index.mjs +2 -2
- package/dist/providers/gitlab/index.d.mts +1 -1
- package/dist/providers/gitlab/index.mjs +2 -2
- package/dist/providers/local/index.d.mts +7 -1
- package/dist/providers/local/index.d.mts.map +1 -1
- package/dist/providers/local/index.mjs +11 -10
- package/dist/{scan-config-BlNLRCMx.mjs → scan-config-Dx49nCqk.mjs} +1 -1
- package/dist/{scan-config-BlNLRCMx.mjs.map → scan-config-Dx49nCqk.mjs.map} +1 -1
- package/dist/{scanner-CGWhmpDz.mjs → scanner-BSvXjfkp.mjs} +6 -6
- package/dist/{scanner-CGWhmpDz.mjs.map → scanner-BSvXjfkp.mjs.map} +1 -1
- package/dist/serialization-tmgfFBOh.mjs +2 -0
- package/dist/server/http/index.d.mts +1 -1
- package/dist/server/http/index.mjs +21 -20
- package/dist/server/http/index.mjs.map +1 -1
- package/dist/{server-CUZnuHQx.mjs → server-B2ib9TkR.mjs} +313 -115
- package/dist/server-B2ib9TkR.mjs.map +1 -0
- package/dist/{server-DLauBiu2.d.mts → server-CLPNnhYL.d.mts} +2 -2
- package/dist/{server-DLauBiu2.d.mts.map → server-CLPNnhYL.d.mts.map} +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.mjs +21 -20
- package/dist/{source-map-generator-Bvbu-kM5.mjs → source-map-generator-DhjiQdV3.mjs} +1 -1
- package/dist/{source-map-generator-Bvbu-kM5.mjs.map → source-map-generator-DhjiQdV3.mjs.map} +1 -1
- package/dist/{svelte-parser-DaFK9iY0.mjs → svelte-parser-CwySu9yn.mjs} +3 -3
- package/dist/{svelte-parser-DaFK9iY0.mjs.map → svelte-parser-CwySu9yn.mjs.map} +1 -1
- package/dist/templates/index.mjs +1 -1
- package/dist/{templates-D6EllixQ.mjs → templates-CAkTIRkE.mjs} +430 -109
- package/dist/templates-CAkTIRkE.mjs.map +1 -0
- package/dist/testing/memory-provider.d.mts +52 -0
- package/dist/testing/memory-provider.d.mts.map +1 -0
- package/dist/testing/memory-provider.mjs +205 -0
- package/dist/testing/memory-provider.mjs.map +1 -0
- package/dist/tools/annotations.d.mts.map +1 -1
- package/dist/tools/annotations.mjs +1 -1
- package/dist/tools/availability.mjs +1 -1
- package/dist/{transaction-1SPznNt3.mjs → transaction-BW9ektWu.mjs} +13 -12
- package/dist/transaction-BW9ektWu.mjs.map +1 -0
- package/dist/{tsx-parser-md1N0Niu.mjs → tsx-parser-BvsK6lyG.mjs} +1 -1
- package/dist/{tsx-parser-md1N0Niu.mjs.map → tsx-parser-BvsK6lyG.mjs.map} +1 -1
- package/dist/tsx-parser-Byc7HlJ8.mjs +2 -0
- package/dist/util/detect.mjs +1 -1
- package/dist/util/fs.d.mts +1 -1
- package/dist/util/fs.d.mts.map +1 -1
- package/dist/util/id.mjs +1 -1
- package/dist/{validator-ChiYk6ap.mjs → validator-0sJ9vh1j.mjs} +65 -8
- package/dist/validator-0sJ9vh1j.mjs.map +1 -0
- package/dist/{vue-parser-CHxDohd8.mjs → vue-parser-auedZiJG.mjs} +3 -3
- package/dist/{vue-parser-CHxDohd8.mjs.map → vue-parser-auedZiJG.mjs.map} +1 -1
- package/package.json +13 -5
- package/testing/conformance/01-new-collection-entry/expected/.contentrain/meta/blog/en.json +1 -0
- package/testing/conformance/01-new-collection-entry/expected/.contentrain/models/blog.json +6 -5
- package/testing/conformance/01-new-collection-entry/setup/.contentrain/models/blog.json +6 -5
- package/testing/conformance/02-new-singleton/expected/.contentrain/meta/hero/en.json +1 -0
- package/testing/conformance/02-new-singleton/expected/.contentrain/models/hero.json +6 -5
- package/testing/conformance/02-new-singleton/setup/.contentrain/models/hero.json +6 -5
- package/testing/conformance/03-new-dictionary/expected/.contentrain/meta/ui-strings/en.json +1 -0
- package/testing/conformance/03-new-dictionary/expected/.contentrain/models/ui-strings.json +4 -3
- package/testing/conformance/03-new-dictionary/setup/.contentrain/models/ui-strings.json +4 -3
- package/dist/annotations-D3tlsF38.mjs.map +0 -1
- package/dist/apply-manager-SLCRLHN_.mjs.map +0 -1
- package/dist/branch-lifecycle-BAfgSQBv.mjs.map +0 -1
- package/dist/content-manager-DWo3G64y.d.mts.map +0 -1
- package/dist/doctor-BwJ_nmqS.mjs.map +0 -1
- package/dist/local-8dJ5NIWL.mjs.map +0 -1
- package/dist/meta-manager-CJUiTgP2.mjs.map +0 -1
- package/dist/model-manager-DP2CZiMT.mjs.map +0 -1
- package/dist/ops-CGKIKwDc.mjs.map +0 -1
- package/dist/serialization-B1CEzR4H.mjs +0 -2
- package/dist/server-CUZnuHQx.mjs.map +0 -1
- package/dist/templates-D6EllixQ.mjs.map +0 -1
- package/dist/transaction-1SPznNt3.mjs.map +0 -1
- package/dist/tsx-parser-C3XsIrwU.mjs +0 -2
- package/dist/validator-ChiYk6ap.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect-CdDU4Ew_.mjs","names":[],"sources":["../src/util/detect.ts"],"sourcesContent":["import type { StackType, Platform } from '@contentrain/types'\nimport { join, dirname } from 'node:path'\nimport { readdir } from 'node:fs/promises'\nimport { readJson, pathExists, readText } from './fs.js'\n\ninterface PackageJson {\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n workspaces?: string[] | { packages: string[] }\n}\n\nexport interface StackInfo {\n stack: StackType\n platform: Platform\n name: string\n description: string\n monorepo: boolean\n monorepoTool?: string\n features: string[]\n}\n\nconst STACK_META: Record<StackType, { name: string; description: string }> = {\n // Meta-frameworks\n nuxt: { name: 'Nuxt', description: 'Vue meta-framework with SSR/SSG' },\n next: { name: 'Next.js', description: 'React framework with SSR/SSG' },\n astro: { name: 'Astro', description: 'Content-first web framework' },\n sveltekit: { name: 'SvelteKit', description: 'Svelte meta-framework' },\n remix: { name: 'Remix', description: 'Full-stack React framework' },\n analog: { name: 'Analog', description: 'Angular meta-framework' },\n // Plain frameworks\n vue: { name: 'Vue', description: 'Progressive JavaScript framework' },\n react: { name: 'React', description: 'UI library for web and native' },\n svelte: { name: 'Svelte', description: 'Compile-time UI framework' },\n solid: { name: 'Solid', description: 'Reactive UI library' },\n angular: { name: 'Angular', description: 'Platform for web applications' },\n // Mobile\n 'react-native': { name: 'React Native', description: 'Cross-platform mobile framework' },\n expo: { name: 'Expo', description: 'React Native toolchain' },\n flutter: { name: 'Flutter', description: 'Cross-platform UI toolkit (Dart)' },\n // Backend\n node: { name: 'Node.js', description: 'Server-side JavaScript runtime' },\n express: { name: 'Express', description: 'Minimal Node.js web framework' },\n fastify: { name: 'Fastify', description: 'Fast Node.js web framework' },\n nestjs: { name: 'NestJS', description: 'Progressive Node.js framework' },\n django: { name: 'Django', description: 'Python web framework' },\n rails: { name: 'Rails', description: 'Ruby web framework' },\n laravel: { name: 'Laravel', description: 'PHP web framework' },\n go: { name: 'Go', description: 'Go programming language' },\n rust: { name: 'Rust', description: 'Rust programming language' },\n dotnet: { name: '.NET', description: 'Microsoft .NET platform' },\n // Static\n hugo: { name: 'Hugo', description: 'Go-based static site generator' },\n jekyll: { name: 'Jekyll', description: 'Ruby-based static site generator' },\n eleventy: { name: 'Eleventy', description: 'JavaScript static site generator' },\n // Desktop\n electron: { name: 'Electron', description: 'Cross-platform desktop apps' },\n tauri: { name: 'Tauri', description: 'Lightweight desktop apps (Rust)' },\n // Catch-all\n other: { name: 'Other', description: 'Unknown or unsupported framework' },\n}\n\nexport function inferPlatform(stack: StackType): Platform {\n switch (stack) {\n case 'nuxt': case 'next': case 'astro': case 'sveltekit': case 'remix': case 'analog':\n case 'vue': case 'react': case 'svelte': case 'solid': case 'angular':\n return 'web'\n case 'react-native': case 'expo': case 'flutter':\n return 'mobile'\n case 'node': case 'express': case 'fastify': case 'nestjs':\n case 'django': case 'rails': case 'laravel': case 'go': case 'rust': case 'dotnet':\n return 'api'\n case 'electron': case 'tauri':\n return 'desktop'\n case 'hugo': case 'jekyll': case 'eleventy':\n return 'static'\n default:\n return 'other'\n }\n}\n\n/** Backward-compatible: returns just the StackType string */\nexport async function detectStack(projectRoot: string): Promise<StackType> {\n const info = await detectStackInfo(projectRoot)\n return info.stack\n}\n\n/** Rich detection: stack + platform + monorepo + features */\nexport async function detectStackInfo(projectRoot: string): Promise<StackInfo> {\n let stack = await detectFromDeps(projectRoot)\n\n // Walk up for monorepo root if local didn't match\n if (stack === 'other') {\n let dir = dirname(projectRoot)\n for (let i = 0; i < 5; i++) {\n const pkg = await readJson<PackageJson>(join(dir, 'package.json'))\n if (pkg?.workspaces) {\n const rootStack = await detectFromDeps(dir)\n if (rootStack !== 'other') {\n stack = rootStack\n break\n }\n }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n }\n\n // Look DOWN into the workspaces. The walk above handles \"I am inside a\n // package, find the monorepo root\"; this handles the opposite and more\n // common case — projectRoot IS the monorepo root, whose package.json holds\n // only tooling (turbo, nx) while the frameworks live in apps/* and\n // packages/*. Without this a Next.js monorepo reports `other`, and the\n // stack is what picks the replacement conventions during normalize.\n if (stack === 'other') {\n stack = await detectFromWorkspaces(projectRoot)\n }\n\n // Non-JS detection if still 'other'\n if (stack === 'other') {\n stack = await detectNonJs(projectRoot)\n }\n\n const mono = await detectMonorepo(projectRoot)\n const features = await detectFeatures(projectRoot)\n const meta = STACK_META[stack]\n\n return {\n stack,\n platform: inferPlatform(stack),\n name: meta.name,\n description: meta.description,\n monorepo: mono.isMonorepo,\n monorepoTool: mono.tool,\n features,\n }\n}\n\nasync function detectFromDeps(dir: string): Promise<StackType> {\n const pkg = await readJson<PackageJson>(join(dir, 'package.json'))\n if (!pkg) return 'other'\n\n const allDeps = { ...pkg.dependencies, ...pkg.devDependencies }\n\n // Meta-frameworks (check BEFORE plain frameworks)\n if ('nuxt' in allDeps) return 'nuxt'\n if ('next' in allDeps) return 'next'\n if ('astro' in allDeps) return 'astro'\n if ('@sveltejs/kit' in allDeps) return 'sveltekit'\n if ('@remix-run/node' in allDeps || 'remix' in allDeps) return 'remix'\n if ('@analogjs/platform' in allDeps) return 'analog'\n\n // Mobile (check before plain react)\n if ('expo' in allDeps) return 'expo'\n if ('react-native' in allDeps) return 'react-native'\n\n // Plain frameworks\n if ('vue' in allDeps) return 'vue'\n if ('svelte' in allDeps) return 'svelte'\n if ('solid-js' in allDeps) return 'solid'\n if ('@angular/core' in allDeps) return 'angular'\n if ('react' in allDeps) return 'react'\n\n // Desktop\n if ('electron' in allDeps) return 'electron'\n if ('@tauri-apps/api' in allDeps) return 'tauri'\n\n // Backend (Node.js)\n if ('@nestjs/core' in allDeps) return 'nestjs'\n if ('fastify' in allDeps) return 'fastify'\n if ('express' in allDeps) return 'express'\n\n // Static site generators\n if ('@11ty/eleventy' in allDeps) return 'eleventy'\n\n // Generic Node.js (has package.json but no framework)\n if ('node' in (pkg.dependencies ?? {})) return 'node'\n\n return 'other'\n}\n\n/**\n * Ranked by how strongly the stack determines content conventions — a\n * meta-framework dictates the i18n setup and the replacement expression,\n * a plain UI library does not. Frequency would be the wrong tie-break: a\n * monorepo with one Next app and two React packages is a Next project.\n */\nconst STACK_PRIORITY: readonly StackType[] = [\n 'nuxt', 'next', 'astro', 'sveltekit', 'remix', 'analog',\n 'expo', 'react-native',\n 'vue', 'react', 'svelte', 'solid', 'angular',\n 'electron', 'tauri',\n 'nestjs', 'fastify', 'express',\n 'eleventy', 'node',\n]\n\n/** Cap the fan-out so a large monorepo cannot turn detection into a crawl. */\nconst MAX_WORKSPACE_DIRS = 50\n\n/**\n * Workspace globs from `pnpm-workspace.yaml` or the `workspaces` field.\n *\n * The pnpm file is parsed line by line rather than with a YAML library: we\n * need exactly one list of strings with a fixed shape, and a parser\n * dependency for that is not worth the install size.\n */\nasync function readWorkspacePatterns(root: string): Promise<string[]> {\n const pnpm = await readText(join(root, 'pnpm-workspace.yaml'))\n if (pnpm) {\n const patterns: string[] = []\n let inPackages = false\n for (const raw of pnpm.split('\\n')) {\n const line = raw.replace(/#.*$/, '').trimEnd()\n if (/^packages:\\s*$/.test(line)) { inPackages = true; continue }\n if (!inPackages) continue\n const item = /^\\s+-\\s*['\"]?([^'\"]+?)['\"]?\\s*$/.exec(line)\n if (item?.[1]) { patterns.push(item[1]); continue }\n if (line.trim() !== '') break // a new top-level key ends the list\n }\n if (patterns.length > 0) return patterns\n }\n\n const pkg = await readJson<PackageJson>(join(root, 'package.json'))\n const ws = pkg?.workspaces\n if (Array.isArray(ws)) return ws\n if (ws && Array.isArray(ws.packages)) return ws.packages\n return []\n}\n\n/**\n * Expand workspace patterns to directories. Only a trailing `*` segment is\n * expanded — that covers `apps/*` and `packages/*`, which is what real\n * workspace files use. Deeper globs and negations are skipped rather than\n * half-supported.\n */\nasync function listWorkspaceDirs(root: string): Promise<string[]> {\n const patterns = (await readWorkspacePatterns(root)).filter(p => !p.startsWith('!'))\n\n const expanded = await Promise.all(patterns.map(async (pattern) => {\n const star = pattern.indexOf('*')\n if (star === -1) return [join(root, pattern)]\n const base = join(root, pattern.slice(0, star).replace(/\\/+$/, ''))\n try {\n const entries = await readdir(base, { withFileTypes: true })\n return entries.filter(e => e.isDirectory()).map(e => join(base, e.name))\n } catch {\n return []\n }\n }))\n\n return expanded.flat().slice(0, MAX_WORKSPACE_DIRS)\n}\n\n/** Highest-priority stack across the workspace packages. */\nasync function detectFromWorkspaces(root: string): Promise<StackType> {\n const dirs = await listWorkspaceDirs(root)\n if (dirs.length === 0) return 'other'\n\n const found = new Set(await Promise.all(dirs.map(d => detectFromDeps(d))))\n return STACK_PRIORITY.find(s => found.has(s)) ?? 'other'\n}\n\nasync function detectNonJs(projectRoot: string): Promise<StackType> {\n // Go\n if (await pathExists(join(projectRoot, 'go.mod'))) return 'go'\n\n // Rust\n if (await pathExists(join(projectRoot, 'Cargo.toml'))) return 'rust'\n\n // Python\n for (const f of ['requirements.txt', 'pyproject.toml', 'setup.py']) {\n if (await pathExists(join(projectRoot, f))) {\n // Check for Django\n try {\n const content = await readText(join(projectRoot, f))\n if (content?.includes('django') || content?.includes('Django')) return 'django'\n } catch { /* ignore */ }\n return 'other' // Generic Python — no specific stack type yet\n }\n }\n\n // Ruby\n if (await pathExists(join(projectRoot, 'Gemfile'))) {\n try {\n const content = await readText(join(projectRoot, 'Gemfile'))\n if (content?.includes('rails')) return 'rails'\n } catch { /* ignore */ }\n return 'other'\n }\n\n // .NET\n const dotnetFiles = ['*.csproj', '*.sln']\n for (const pattern of dotnetFiles) {\n if (pattern === '*.csproj' && await pathExists(join(projectRoot, 'Program.cs'))) return 'dotnet'\n if (pattern === '*.sln' && await pathExists(join(projectRoot, 'Program.cs'))) return 'dotnet'\n }\n\n // PHP / Laravel\n if (await pathExists(join(projectRoot, 'composer.json'))) {\n try {\n const composer = await readJson<Record<string, unknown>>(join(projectRoot, 'composer.json'))\n const require = composer?.require as Record<string, string> | undefined\n if (require?.['laravel/framework']) return 'laravel'\n } catch { /* ignore */ }\n return 'other'\n }\n\n // Flutter (Dart)\n if (await pathExists(join(projectRoot, 'pubspec.yaml'))) return 'flutter'\n\n // Hugo\n if (await pathExists(join(projectRoot, 'hugo.toml'))) return 'hugo'\n if (await pathExists(join(projectRoot, 'config.toml'))) {\n try {\n const content = await readText(join(projectRoot, 'config.toml'))\n if (content?.includes('baseURL') || content?.includes('hugo')) return 'hugo'\n } catch { /* ignore */ }\n }\n\n // Jekyll\n if (await pathExists(join(projectRoot, '_config.yml'))) return 'jekyll'\n\n return 'other'\n}\n\nasync function detectMonorepo(projectRoot: string): Promise<{ isMonorepo: boolean; tool?: string }> {\n if (await pathExists(join(projectRoot, 'pnpm-workspace.yaml'))) return { isMonorepo: true, tool: 'pnpm workspaces' }\n if (await pathExists(join(projectRoot, 'lerna.json'))) return { isMonorepo: true, tool: 'Lerna' }\n if (await pathExists(join(projectRoot, 'nx.json'))) return { isMonorepo: true, tool: 'Nx' }\n if (await pathExists(join(projectRoot, 'turbo.json'))) return { isMonorepo: true, tool: 'Turborepo' }\n\n const pkg = await readJson<PackageJson>(join(projectRoot, 'package.json'))\n if (pkg?.workspaces) return { isMonorepo: true, tool: 'npm/yarn workspaces' }\n\n // Walk up\n let dir = dirname(projectRoot)\n for (let i = 0; i < 5; i++) {\n if (await pathExists(join(dir, 'pnpm-workspace.yaml'))) return { isMonorepo: true, tool: 'pnpm workspaces' }\n if (await pathExists(join(dir, 'lerna.json'))) return { isMonorepo: true, tool: 'Lerna' }\n if (await pathExists(join(dir, 'nx.json'))) return { isMonorepo: true, tool: 'Nx' }\n if (await pathExists(join(dir, 'turbo.json'))) return { isMonorepo: true, tool: 'Turborepo' }\n const parentPkg = await readJson<PackageJson>(join(dir, 'package.json'))\n if (parentPkg?.workspaces) return { isMonorepo: true, tool: 'npm/yarn workspaces' }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n\n return { isMonorepo: false }\n}\n\nasync function detectFeatures(projectRoot: string): Promise<string[]> {\n const features: string[] = []\n const allDeps = await collectAllDeps(projectRoot)\n\n if ('typescript' in allDeps || await pathExists(join(projectRoot, 'tsconfig.json'))) features.push('TypeScript')\n\n const i18nLibs = ['vue-i18n', '@nuxtjs/i18n', 'next-intl', 'react-intl', 'i18next', 'react-i18next']\n for (const lib of i18nLibs) {\n if (lib in allDeps) { features.push(`i18n (${lib})`); break }\n }\n\n if ('tailwindcss' in allDeps) features.push('Tailwind CSS')\n else if ('sass' in allDeps || 'scss' in allDeps) features.push('Sass/SCSS')\n\n if ('vitest' in allDeps) features.push('Vitest')\n else if ('jest' in allDeps) features.push('Jest')\n\n if ('pinia' in allDeps) features.push('Pinia')\n else if ('zustand' in allDeps) features.push('Zustand')\n else if ('@reduxjs/toolkit' in allDeps || 'redux' in allDeps) features.push('Redux')\n\n return features\n}\n\nasync function collectAllDeps(projectRoot: string): Promise<Record<string, string>> {\n const pkg = await readJson<PackageJson>(join(projectRoot, 'package.json'))\n const allDeps: Record<string, string> = { ...pkg?.dependencies, ...pkg?.devDependencies }\n\n let dir = dirname(projectRoot)\n for (let i = 0; i < 5; i++) {\n const parentPkg = await readJson<PackageJson>(join(dir, 'package.json'))\n if (parentPkg?.workspaces) {\n Object.assign(allDeps, parentPkg.dependencies, parentPkg.devDependencies)\n break\n }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n\n // Same blind spot as stack detection: at a monorepo root the interesting\n // dependencies (the i18n library above all) sit in the workspace packages,\n // not in the root manifest. Reporting \"no i18n\" for a project that has it\n // would send normalize down the wrong path.\n const workspaceDirs = await listWorkspaceDirs(projectRoot)\n if (workspaceDirs.length > 0) {\n const pkgs = await Promise.all(\n workspaceDirs.map(d => readJson<PackageJson>(join(d, 'package.json'))),\n )\n for (const wsPkg of pkgs) {\n if (wsPkg) Object.assign(allDeps, wsPkg.dependencies, wsPkg.devDependencies)\n }\n }\n\n return allDeps\n}\n"],"mappings":";;;;AAqBA,MAAM,aAAuE;CAE3E,MAAM;EAAE,MAAM;EAAQ,aAAa;EAAmC;CACtE,MAAM;EAAE,MAAM;EAAW,aAAa;EAAgC;CACtE,OAAO;EAAE,MAAM;EAAS,aAAa;EAA+B;CACpE,WAAW;EAAE,MAAM;EAAa,aAAa;EAAyB;CACtE,OAAO;EAAE,MAAM;EAAS,aAAa;EAA8B;CACnE,QAAQ;EAAE,MAAM;EAAU,aAAa;EAA0B;CAEjE,KAAK;EAAE,MAAM;EAAO,aAAa;EAAoC;CACrE,OAAO;EAAE,MAAM;EAAS,aAAa;EAAiC;CACtE,QAAQ;EAAE,MAAM;EAAU,aAAa;EAA6B;CACpE,OAAO;EAAE,MAAM;EAAS,aAAa;EAAuB;CAC5D,SAAS;EAAE,MAAM;EAAW,aAAa;EAAiC;CAE1E,gBAAgB;EAAE,MAAM;EAAgB,aAAa;EAAmC;CACxF,MAAM;EAAE,MAAM;EAAQ,aAAa;EAA0B;CAC7D,SAAS;EAAE,MAAM;EAAW,aAAa;EAAoC;CAE7E,MAAM;EAA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WAAW,UAAU,QAAS,UAAS,KAAK,YAAY;AAE3E,KAAI,YAAY,QAAS,UAAS,KAAK,SAAS;UACvC,UAAU,QAAS,UAAS,KAAK,OAAO;AAEjD,KAAI,WAAW,QAAS,UAAS,KAAK,QAAQ;UACrC,aAAa,QAAS,UAAS,KAAK,UAAU;UAC9C,sBAAsB,WAAW,WAAW,QAAS,UAAS,KAAK,QAAQ;AAEpF,QAAO;;AAGT,eAAe,eAAe,aAAsD;CAClF,MAAM,MAAM,MAAM,SAAsB,KAAK,aAAa,eAAe,CAAC;CAC1E,MAAM,UAAkC;EAAE,GAAG,KAAK;EAAc,GAAG,KAAK;EAAiB;CAEzF,IAAI,MAAM,QAAQ,YAAY;AAC9B,MAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;EAC1B,MAAM,YAAY,MAAM,SAAsB,KAAK,KAAK,eAAe,CAAC;AACxE,MAAI,WAAW,YAAY;AACzB,UAAO,OAAO,SAAS,UAAU,cAAc,UAAU,gBAAgB;AACzE;;EAEF,MAAM,SAAS,QAAQ,IAAI;AAC3B,MAAI,WAAW,IAAK;AACpB,QAAM;;CAOR,MAAM,gBAAgB,MAAM,kBAAkB,YAAY;AAC1D,KAAI,cAAc,SAAS,GAAG;EAC5B,MAAM,OAAO,MAAM,QAAQ,IACzB,cAAc,KAAI,MAAK,SAAsB,KAAK,GAAG,eAAe,CAAC,CAAC,CACvE;AACD,OAAK,MAAM,SAAS,KAClB,KAAI,MAAO,QAAO,OAAO,SAAS,MAAM,cAAc,MAAM,gBAAgB;;AAIhF,QAAO"}
|
|
1
|
+
{"version":3,"file":"detect-B0oXbQaP.mjs","names":[],"sources":["../src/util/detect.ts"],"sourcesContent":["import type { StackType, Platform } from '@contentrain/types'\nimport { join, dirname } from 'node:path'\nimport { readdir } from 'node:fs/promises'\nimport { readJson, pathExists, readText } from './fs.js'\n\ninterface PackageJson {\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n workspaces?: string[] | { packages: string[] }\n}\n\nexport interface StackInfo {\n stack: StackType\n platform: Platform\n name: string\n description: string\n monorepo: boolean\n monorepoTool?: string\n features: string[]\n}\n\nconst STACK_META: Record<StackType, { name: string; description: string }> = {\n // Meta-frameworks\n nuxt: { name: 'Nuxt', description: 'Vue meta-framework with SSR/SSG' },\n next: { name: 'Next.js', description: 'React framework with SSR/SSG' },\n astro: { name: 'Astro', description: 'Content-first web framework' },\n sveltekit: { name: 'SvelteKit', description: 'Svelte meta-framework' },\n remix: { name: 'Remix', description: 'Full-stack React framework' },\n analog: { name: 'Analog', description: 'Angular meta-framework' },\n // Plain frameworks\n vue: { name: 'Vue', description: 'Progressive JavaScript framework' },\n react: { name: 'React', description: 'UI library for web and native' },\n svelte: { name: 'Svelte', description: 'Compile-time UI framework' },\n solid: { name: 'Solid', description: 'Reactive UI library' },\n angular: { name: 'Angular', description: 'Platform for web applications' },\n // Mobile\n 'react-native': { name: 'React Native', description: 'Cross-platform mobile framework' },\n expo: { name: 'Expo', description: 'React Native toolchain' },\n flutter: { name: 'Flutter', description: 'Cross-platform UI toolkit (Dart)' },\n // Backend\n node: { name: 'Node.js', description: 'Server-side JavaScript runtime' },\n express: { name: 'Express', description: 'Minimal Node.js web framework' },\n fastify: { name: 'Fastify', description: 'Fast Node.js web framework' },\n nestjs: { name: 'NestJS', description: 'Progressive Node.js framework' },\n django: { name: 'Django', description: 'Python web framework' },\n rails: { name: 'Rails', description: 'Ruby web framework' },\n laravel: { name: 'Laravel', description: 'PHP web framework' },\n go: { name: 'Go', description: 'Go programming language' },\n rust: { name: 'Rust', description: 'Rust programming language' },\n dotnet: { name: '.NET', description: 'Microsoft .NET platform' },\n // Static\n hugo: { name: 'Hugo', description: 'Go-based static site generator' },\n jekyll: { name: 'Jekyll', description: 'Ruby-based static site generator' },\n eleventy: { name: 'Eleventy', description: 'JavaScript static site generator' },\n // Desktop\n electron: { name: 'Electron', description: 'Cross-platform desktop apps' },\n tauri: { name: 'Tauri', description: 'Lightweight desktop apps (Rust)' },\n // Catch-all\n other: { name: 'Other', description: 'Unknown or unsupported framework' },\n}\n\nexport function inferPlatform(stack: StackType): Platform {\n switch (stack) {\n case 'nuxt': case 'next': case 'astro': case 'sveltekit': case 'remix': case 'analog':\n case 'vue': case 'react': case 'svelte': case 'solid': case 'angular':\n return 'web'\n case 'react-native': case 'expo': case 'flutter':\n return 'mobile'\n case 'node': case 'express': case 'fastify': case 'nestjs':\n case 'django': case 'rails': case 'laravel': case 'go': case 'rust': case 'dotnet':\n return 'api'\n case 'electron': case 'tauri':\n return 'desktop'\n case 'hugo': case 'jekyll': case 'eleventy':\n return 'static'\n default:\n return 'other'\n }\n}\n\n/** Backward-compatible: returns just the StackType string */\nexport async function detectStack(projectRoot: string): Promise<StackType> {\n const info = await detectStackInfo(projectRoot)\n return info.stack\n}\n\n/** Rich detection: stack + platform + monorepo + features */\nexport async function detectStackInfo(projectRoot: string): Promise<StackInfo> {\n let stack = await detectFromDeps(projectRoot)\n\n // Walk up for monorepo root if local didn't match\n if (stack === 'other') {\n let dir = dirname(projectRoot)\n for (let i = 0; i < 5; i++) {\n const pkg = await readJson<PackageJson>(join(dir, 'package.json'))\n if (pkg?.workspaces) {\n const rootStack = await detectFromDeps(dir)\n if (rootStack !== 'other') {\n stack = rootStack\n break\n }\n }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n }\n\n // Look DOWN into the workspaces. The walk above handles \"I am inside a\n // package, find the monorepo root\"; this handles the opposite and more\n // common case — projectRoot IS the monorepo root, whose package.json holds\n // only tooling (turbo, nx) while the frameworks live in apps/* and\n // packages/*. Without this a Next.js monorepo reports `other`, and the\n // stack is what picks the replacement conventions during normalize.\n if (stack === 'other') {\n stack = await detectFromWorkspaces(projectRoot)\n }\n\n // Non-JS detection if still 'other'\n if (stack === 'other') {\n stack = await detectNonJs(projectRoot)\n }\n\n const mono = await detectMonorepo(projectRoot)\n const features = await detectFeatures(projectRoot)\n const meta = STACK_META[stack]\n\n return {\n stack,\n platform: inferPlatform(stack),\n name: meta.name,\n description: meta.description,\n monorepo: mono.isMonorepo,\n monorepoTool: mono.tool,\n features,\n }\n}\n\nasync function detectFromDeps(dir: string): Promise<StackType> {\n const pkg = await readJson<PackageJson>(join(dir, 'package.json'))\n if (!pkg) return 'other'\n\n const allDeps = { ...pkg.dependencies, ...pkg.devDependencies }\n\n // Meta-frameworks (check BEFORE plain frameworks)\n if ('nuxt' in allDeps) return 'nuxt'\n if ('next' in allDeps) return 'next'\n if ('astro' in allDeps) return 'astro'\n if ('@sveltejs/kit' in allDeps) return 'sveltekit'\n if ('@remix-run/node' in allDeps || 'remix' in allDeps) return 'remix'\n if ('@analogjs/platform' in allDeps) return 'analog'\n\n // Mobile (check before plain react)\n if ('expo' in allDeps) return 'expo'\n if ('react-native' in allDeps) return 'react-native'\n\n // Plain frameworks\n if ('vue' in allDeps) return 'vue'\n if ('svelte' in allDeps) return 'svelte'\n if ('solid-js' in allDeps) return 'solid'\n if ('@angular/core' in allDeps) return 'angular'\n if ('react' in allDeps) return 'react'\n\n // Desktop\n if ('electron' in allDeps) return 'electron'\n if ('@tauri-apps/api' in allDeps) return 'tauri'\n\n // Backend (Node.js)\n if ('@nestjs/core' in allDeps) return 'nestjs'\n if ('fastify' in allDeps) return 'fastify'\n if ('express' in allDeps) return 'express'\n\n // Static site generators\n if ('@11ty/eleventy' in allDeps) return 'eleventy'\n\n // Generic Node.js (has package.json but no framework)\n if ('node' in (pkg.dependencies ?? {})) return 'node'\n\n return 'other'\n}\n\n/**\n * Ranked by how strongly the stack determines content conventions — a\n * meta-framework dictates the i18n setup and the replacement expression,\n * a plain UI library does not. Frequency would be the wrong tie-break: a\n * monorepo with one Next app and two React packages is a Next project.\n */\nconst STACK_PRIORITY: readonly StackType[] = [\n 'nuxt', 'next', 'astro', 'sveltekit', 'remix', 'analog',\n 'expo', 'react-native',\n 'vue', 'react', 'svelte', 'solid', 'angular',\n 'electron', 'tauri',\n 'nestjs', 'fastify', 'express',\n 'eleventy', 'node',\n]\n\n/** Cap the fan-out so a large monorepo cannot turn detection into a crawl. */\nconst MAX_WORKSPACE_DIRS = 50\n\n/**\n * Workspace globs from `pnpm-workspace.yaml` or the `workspaces` field.\n *\n * The pnpm file is parsed line by line rather than with a YAML library: we\n * need exactly one list of strings with a fixed shape, and a parser\n * dependency for that is not worth the install size.\n */\nasync function readWorkspacePatterns(root: string): Promise<string[]> {\n const pnpm = await readText(join(root, 'pnpm-workspace.yaml'))\n if (pnpm) {\n const patterns: string[] = []\n let inPackages = false\n for (const raw of pnpm.split('\\n')) {\n const line = raw.replace(/#.*$/, '').trimEnd()\n if (/^packages:\\s*$/.test(line)) { inPackages = true; continue }\n if (!inPackages) continue\n const item = /^\\s+-\\s*['\"]?([^'\"]+?)['\"]?\\s*$/.exec(line)\n if (item?.[1]) { patterns.push(item[1]); continue }\n if (line.trim() !== '') break // a new top-level key ends the list\n }\n if (patterns.length > 0) return patterns\n }\n\n const pkg = await readJson<PackageJson>(join(root, 'package.json'))\n const ws = pkg?.workspaces\n if (Array.isArray(ws)) return ws\n if (ws && Array.isArray(ws.packages)) return ws.packages\n return []\n}\n\n/**\n * Expand workspace patterns to directories. Only a trailing `*` segment is\n * expanded — that covers `apps/*` and `packages/*`, which is what real\n * workspace files use. Deeper globs and negations are skipped rather than\n * half-supported.\n */\nasync function listWorkspaceDirs(root: string): Promise<string[]> {\n const patterns = (await readWorkspacePatterns(root)).filter(p => !p.startsWith('!'))\n\n const expanded = await Promise.all(patterns.map(async (pattern) => {\n const star = pattern.indexOf('*')\n if (star === -1) return [join(root, pattern)]\n const base = join(root, pattern.slice(0, star).replace(/\\/+$/, ''))\n try {\n const entries = await readdir(base, { withFileTypes: true })\n return entries.filter(e => e.isDirectory()).map(e => join(base, e.name))\n } catch {\n return []\n }\n }))\n\n return expanded.flat().slice(0, MAX_WORKSPACE_DIRS)\n}\n\n/** Highest-priority stack across the workspace packages. */\nasync function detectFromWorkspaces(root: string): Promise<StackType> {\n const dirs = await listWorkspaceDirs(root)\n if (dirs.length === 0) return 'other'\n\n const found = new Set(await Promise.all(dirs.map(d => detectFromDeps(d))))\n return STACK_PRIORITY.find(s => found.has(s)) ?? 'other'\n}\n\nasync function detectNonJs(projectRoot: string): Promise<StackType> {\n // Go\n if (await pathExists(join(projectRoot, 'go.mod'))) return 'go'\n\n // Rust\n if (await pathExists(join(projectRoot, 'Cargo.toml'))) return 'rust'\n\n // Python\n for (const f of ['requirements.txt', 'pyproject.toml', 'setup.py']) {\n if (await pathExists(join(projectRoot, f))) {\n // Check for Django\n try {\n const content = await readText(join(projectRoot, f))\n if (content?.includes('django') || content?.includes('Django')) return 'django'\n } catch { /* ignore */ }\n return 'other' // Generic Python — no specific stack type yet\n }\n }\n\n // Ruby\n if (await pathExists(join(projectRoot, 'Gemfile'))) {\n try {\n const content = await readText(join(projectRoot, 'Gemfile'))\n if (content?.includes('rails')) return 'rails'\n } catch { /* ignore */ }\n return 'other'\n }\n\n // .NET\n const dotnetFiles = ['*.csproj', '*.sln']\n for (const pattern of dotnetFiles) {\n if (pattern === '*.csproj' && await pathExists(join(projectRoot, 'Program.cs'))) return 'dotnet'\n if (pattern === '*.sln' && await pathExists(join(projectRoot, 'Program.cs'))) return 'dotnet'\n }\n\n // PHP / Laravel\n if (await pathExists(join(projectRoot, 'composer.json'))) {\n try {\n const composer = await readJson<Record<string, unknown>>(join(projectRoot, 'composer.json'))\n const require = composer?.require as Record<string, string> | undefined\n if (require?.['laravel/framework']) return 'laravel'\n } catch { /* ignore */ }\n return 'other'\n }\n\n // Flutter (Dart)\n if (await pathExists(join(projectRoot, 'pubspec.yaml'))) return 'flutter'\n\n // Hugo\n if (await pathExists(join(projectRoot, 'hugo.toml'))) return 'hugo'\n if (await pathExists(join(projectRoot, 'config.toml'))) {\n try {\n const content = await readText(join(projectRoot, 'config.toml'))\n if (content?.includes('baseURL') || content?.includes('hugo')) return 'hugo'\n } catch { /* ignore */ }\n }\n\n // Jekyll\n if (await pathExists(join(projectRoot, '_config.yml'))) return 'jekyll'\n\n return 'other'\n}\n\nasync function detectMonorepo(projectRoot: string): Promise<{ isMonorepo: boolean; tool?: string }> {\n if (await pathExists(join(projectRoot, 'pnpm-workspace.yaml'))) return { isMonorepo: true, tool: 'pnpm workspaces' }\n if (await pathExists(join(projectRoot, 'lerna.json'))) return { isMonorepo: true, tool: 'Lerna' }\n if (await pathExists(join(projectRoot, 'nx.json'))) return { isMonorepo: true, tool: 'Nx' }\n if (await pathExists(join(projectRoot, 'turbo.json'))) return { isMonorepo: true, tool: 'Turborepo' }\n\n const pkg = await readJson<PackageJson>(join(projectRoot, 'package.json'))\n if (pkg?.workspaces) return { isMonorepo: true, tool: 'npm/yarn workspaces' }\n\n // Walk up\n let dir = dirname(projectRoot)\n for (let i = 0; i < 5; i++) {\n if (await pathExists(join(dir, 'pnpm-workspace.yaml'))) return { isMonorepo: true, tool: 'pnpm workspaces' }\n if (await pathExists(join(dir, 'lerna.json'))) return { isMonorepo: true, tool: 'Lerna' }\n if (await pathExists(join(dir, 'nx.json'))) return { isMonorepo: true, tool: 'Nx' }\n if (await pathExists(join(dir, 'turbo.json'))) return { isMonorepo: true, tool: 'Turborepo' }\n const parentPkg = await readJson<PackageJson>(join(dir, 'package.json'))\n if (parentPkg?.workspaces) return { isMonorepo: true, tool: 'npm/yarn workspaces' }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n\n return { isMonorepo: false }\n}\n\nasync function detectFeatures(projectRoot: string): Promise<string[]> {\n const features: string[] = []\n const allDeps = await collectAllDeps(projectRoot)\n\n if ('typescript' in allDeps || await pathExists(join(projectRoot, 'tsconfig.json'))) features.push('TypeScript')\n\n const i18nLibs = ['vue-i18n', '@nuxtjs/i18n', 'next-intl', 'react-intl', 'i18next', 'react-i18next']\n for (const lib of i18nLibs) {\n if (lib in allDeps) { features.push(`i18n (${lib})`); break }\n }\n\n if ('tailwindcss' in allDeps) features.push('Tailwind CSS')\n else if ('sass' in allDeps || 'scss' in allDeps) features.push('Sass/SCSS')\n\n if ('vitest' in allDeps) features.push('Vitest')\n else if ('jest' in allDeps) features.push('Jest')\n\n if ('pinia' in allDeps) features.push('Pinia')\n else if ('zustand' in allDeps) features.push('Zustand')\n else if ('@reduxjs/toolkit' in allDeps || 'redux' in allDeps) features.push('Redux')\n\n return features\n}\n\nasync function collectAllDeps(projectRoot: string): Promise<Record<string, string>> {\n const pkg = await readJson<PackageJson>(join(projectRoot, 'package.json'))\n const allDeps: Record<string, string> = { ...pkg?.dependencies, ...pkg?.devDependencies }\n\n let dir = dirname(projectRoot)\n for (let i = 0; i < 5; i++) {\n const parentPkg = await readJson<PackageJson>(join(dir, 'package.json'))\n if (parentPkg?.workspaces) {\n Object.assign(allDeps, parentPkg.dependencies, parentPkg.devDependencies)\n break\n }\n const parent = dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n\n // Same blind spot as stack detection: at a monorepo root the interesting\n // dependencies (the i18n library above all) sit in the workspace packages,\n // not in the root manifest. Reporting \"no i18n\" for a project that has it\n // would send normalize down the wrong path.\n const workspaceDirs = await listWorkspaceDirs(projectRoot)\n if (workspaceDirs.length > 0) {\n const pkgs = await Promise.all(\n workspaceDirs.map(d => readJson<PackageJson>(join(d, 'package.json'))),\n )\n for (const wsPkg of pkgs) {\n if (wsPkg) Object.assign(allDeps, wsPkg.dependencies, wsPkg.devDependencies)\n }\n }\n\n return allDeps\n}\n"],"mappings":";;;;AAqBA,MAAM,aAAuE;CAE3E,MAAM;EAAE,MAAM;EAAQ,aAAa;EAAmC;CACtE,MAAM;EAAE,MAAM;EAAW,aAAa;EAAgC;CACtE,OAAO;EAAE,MAAM;EAAS,aAAa;EAA+B;CACpE,WAAW;EAAE,MAAM;EAAa,aAAa;EAAyB;CACtE,OAAO;EAAE,MAAM;EAAS,aAAa;EAA8B;CACnE,QAAQ;EAAE,MAAM;EAAU,aAAa;EAA0B;CAEjE,KAAK;EAAE,MAAM;EAAO,aAAa;EAAoC;CACrE,OAAO;EAAE,MAAM;EAAS,aA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cAAc,MAAM,gBAAgB;;AAIhF,QAAO"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { a as readJson, i as readDir, o as readText, r as pathExists, t as contentrainDir } from "./fs-DLbVB-Ek.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { n as checkBranchHealth, s as listRemoteCrBranches } from "./branch-lifecycle-
|
|
5
|
-
import {
|
|
2
|
+
import { r as createGit } from "./identity-D8QoGxhT.mjs";
|
|
3
|
+
import { t as readConfig } from "./config-VlRKRwAS.mjs";
|
|
4
|
+
import { n as checkBranchHealth, s as listRemoteCrBranches } from "./branch-lifecycle-B6PXZ2N7.mjs";
|
|
5
|
+
import { _ as resolveContentDir, c as listModels, d as validateModelDefinition, l as readModel, v as resolveJsonFilePath, y as resolveLocaleStrategy } from "./model-manager-DgyKMjLN.mjs";
|
|
6
|
+
import { i as autoDetectSourceDirs, o as discoverFiles } from "./scan-config-Dx49nCqk.mjs";
|
|
6
7
|
import { join } from "node:path";
|
|
7
8
|
import { readdir, stat } from "node:fs/promises";
|
|
8
|
-
import { simpleGit } from "simple-git";
|
|
9
9
|
//#region src/core/doctor.ts
|
|
10
10
|
async function runDoctor(projectRoot, options = {}) {
|
|
11
11
|
const checks = [];
|
|
12
12
|
try {
|
|
13
|
-
const version = await
|
|
13
|
+
const version = await createGit(projectRoot).version();
|
|
14
14
|
checks.push({
|
|
15
15
|
name: "Git",
|
|
16
16
|
pass: true,
|
|
@@ -67,13 +67,18 @@ async function runDoctor(projectRoot, options = {}) {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
if (hasCrDir) try {
|
|
70
|
-
const
|
|
71
|
-
const
|
|
70
|
+
const modelsDir = join(crDir, "models");
|
|
71
|
+
const files = (await readDir(modelsDir)).filter((f) => f.endsWith(".json"));
|
|
72
|
+
const parsed = await Promise.all(files.map((f) => readJson(join(modelsDir, f))));
|
|
73
|
+
const unparseable = files.filter((_, i) => parsed[i] === null);
|
|
74
|
+
const invalid = parsed.filter((m) => m !== null).filter((m) => validateModelDefinition(m).errors.length > 0).map((m) => m.id);
|
|
75
|
+
const models = parsed.filter((m) => m !== null);
|
|
76
|
+
const problems = [...unparseable.length > 0 ? [`${unparseable.length} failed to parse (${unparseable.join(", ")})`] : [], ...invalid.length > 0 ? [`${invalid.length} invalid (${invalid.join(", ")}) — run: contentrain validate --fix`] : []];
|
|
72
77
|
checks.push({
|
|
73
78
|
name: "Models",
|
|
74
|
-
pass:
|
|
75
|
-
detail: `${models.length} model(s)${
|
|
76
|
-
severity:
|
|
79
|
+
pass: problems.length === 0,
|
|
80
|
+
detail: `${models.length} model(s)${problems.length === 0 ? ", all valid" : `, ${problems.join("; ")}`}`,
|
|
81
|
+
severity: problems.length === 0 ? void 0 : "error"
|
|
77
82
|
});
|
|
78
83
|
} catch {
|
|
79
84
|
checks.push({
|
|
@@ -164,9 +169,9 @@ async function runDoctor(projectRoot, options = {}) {
|
|
|
164
169
|
missingLocaleKeys
|
|
165
170
|
};
|
|
166
171
|
checks.push({
|
|
167
|
-
name: "Unused
|
|
172
|
+
name: "Unused dictionary keys",
|
|
168
173
|
pass: unusedKeys.length === 0,
|
|
169
|
-
detail: unusedKeys.length === 0 ? "All keys referenced in source" : `${unusedKeys.length} key(s) not referenced in source code`,
|
|
174
|
+
detail: unusedKeys.length === 0 ? "All dictionary keys referenced in source" : `${unusedKeys.length} dictionary key(s) not referenced in source code`,
|
|
170
175
|
severity: unusedKeys.length === 0 ? void 0 : "warning"
|
|
171
176
|
});
|
|
172
177
|
checks.push({
|
|
@@ -266,7 +271,7 @@ async function analyzeUnusedKeys(projectRoot, config) {
|
|
|
266
271
|
const allSource = (await Promise.all(files.map(async (relPath) => {
|
|
267
272
|
return await readText(join(projectRoot, relPath)) ?? "";
|
|
268
273
|
}))).join("\n");
|
|
269
|
-
const models = await listModels(projectRoot);
|
|
274
|
+
const models = (await listModels(projectRoot)).filter((m) => m.kind === "dictionary");
|
|
270
275
|
const defaultLocale = config.locales.default;
|
|
271
276
|
const unused = [];
|
|
272
277
|
for (const m of models) {
|
|
@@ -282,6 +287,14 @@ async function analyzeUnusedKeys(projectRoot, config) {
|
|
|
282
287
|
}
|
|
283
288
|
return unused;
|
|
284
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Keys of a model that source code could plausibly reference by name.
|
|
292
|
+
*
|
|
293
|
+
* Only dictionaries have any: their keys are semantic addresses that appear
|
|
294
|
+
* verbatim in source. Every other kind is queried, so its ids and slugs are
|
|
295
|
+
* data, not identifiers, and looking for them in source finds nothing and
|
|
296
|
+
* means nothing.
|
|
297
|
+
*/
|
|
285
298
|
async function extractContentKeys(projectRoot, model, locale) {
|
|
286
299
|
const cDir = resolveContentDir(projectRoot, model);
|
|
287
300
|
if (!await pathExists(cDir)) return [];
|
|
@@ -380,4 +393,4 @@ async function analyzeMissingLocaleKeys(projectRoot, config) {
|
|
|
380
393
|
//#endregion
|
|
381
394
|
export { runDoctor as t };
|
|
382
395
|
|
|
383
|
-
//# sourceMappingURL=doctor-
|
|
396
|
+
//# sourceMappingURL=doctor-DNPuGgcg.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor-DNPuGgcg.mjs","names":[],"sources":["../src/core/doctor.ts"],"sourcesContent":["import { join } from 'node:path'\nimport { createGit } from '../git/identity.js'\nimport { readdir, stat } from 'node:fs/promises'\nimport type { Dirent } from 'node:fs'\nimport type { ContentrainConfig, ModelDefinition } from '@contentrain/types'\nimport { readConfig } from './config.js'\nimport { listModels, readModel, validateModelDefinition } from './model-manager.js'\nimport { resolveContentDir, resolveJsonFilePath, resolveLocaleStrategy } from './content-manager.js'\nimport { autoDetectSourceDirs, discoverFiles } from './scan-config.js'\nimport { checkBranchHealth, listRemoteCrBranches } from '../git/branch-lifecycle.js'\nimport { contentrainDir, pathExists, readDir, readJson, readText } from '../util/fs.js'\n\n/**\n * Doctor — project health report.\n *\n * The public entry point is `runDoctor(projectRoot, { usage? })`. It is\n * inherently local-filesystem work (Node version, git install, file\n * mtimes, orphan directory detection), so the MCP tool surface gates\n * it behind the `localWorktree` capability — same pattern as\n * `contentrain_setup` and normalize.\n *\n * The report is structured JSON so three consumers can share it:\n *\n * - The `contentrain doctor` CLI command pretty-prints the checks.\n * - The Serve UI `/api/doctor` route returns the report to the\n * Dashboard's Doctor panel.\n * - Automation (CI, Studio) gets a deterministic JSON shape it can\n * assert against.\n *\n * Usage analysis (`--usage`) is a heavier, opt-in branch — it scans\n * every source file in the repo for content-key references. Kept\n * behind the flag so the default doctor run stays fast.\n */\n\nexport type CheckSeverity = 'error' | 'warning' | 'info'\n\nexport interface DoctorCheck {\n name: string\n pass: boolean\n detail: string\n /**\n * `error` — default for failing checks. Blocks a clean bill of health.\n * `warning` — failing-but-not-blocking (e.g. pending branches above\n * threshold, stale SDK client).\n * `info` — passed check; pure informational.\n */\n severity?: CheckSeverity\n}\n\nexport interface UnusedKeyEntry {\n model: string\n kind: string\n key: string\n locale: string\n}\n\nexport interface DuplicateValueEntry {\n model: string\n locale: string\n value: string\n keys: string[]\n}\n\nexport interface MissingLocaleEntry {\n model: string\n key: string\n missingIn: string\n}\n\nexport interface DoctorUsageAnalysis {\n unusedKeys: UnusedKeyEntry[]\n duplicateValues: DuplicateValueEntry[]\n missingLocaleKeys: MissingLocaleEntry[]\n}\n\nexport interface DoctorReport {\n checks: DoctorCheck[]\n summary: {\n total: number\n passed: number\n failed: number\n warnings: number\n }\n /** Present only when `options.usage === true`. */\n usage?: DoctorUsageAnalysis\n}\n\nexport interface RunDoctorOptions {\n /** Run heavier `--usage` analysis (unused keys, duplicates, locale gaps). */\n usage?: boolean\n}\n\nexport async function runDoctor(\n projectRoot: string,\n options: RunDoctorOptions = {},\n): Promise<DoctorReport> {\n const checks: DoctorCheck[] = []\n\n // ─── 1. Git installed ───\n try {\n const git = createGit(projectRoot)\n const version = await git.version()\n checks.push({\n name: 'Git',\n pass: true,\n detail: `v${version.major}.${version.minor}.${version.patch}`,\n })\n } catch {\n checks.push({ name: 'Git', pass: false, detail: 'Not installed or not in PATH', severity: 'error' })\n }\n\n // ─── 2. Git repo initialized ───\n const hasGit = await pathExists(join(projectRoot, '.git'))\n checks.push({\n name: 'Git repository',\n pass: hasGit,\n detail: hasGit ? projectRoot : 'No .git directory found',\n severity: hasGit ? undefined : 'error',\n })\n\n // ─── 3. Node version ───\n const nodeVersion = process.versions.node\n const [major] = nodeVersion.split('.').map(Number)\n const nodePass = (major ?? 0) >= 22\n checks.push({\n name: 'Node.js',\n pass: nodePass,\n detail: `v${nodeVersion}${nodePass ? '' : ' (requires ≥22)'}`,\n severity: nodePass ? undefined : 'error',\n })\n\n // ─── 4. .contentrain/ structure ───\n const crDir = contentrainDir(projectRoot)\n const hasCrDir = await pathExists(crDir)\n const hasConfig = await pathExists(join(crDir, 'config.json'))\n const hasModels = await pathExists(join(crDir, 'models'))\n const hasContent = await pathExists(join(crDir, 'content'))\n const structurePass = hasCrDir && hasConfig && hasModels && hasContent\n\n checks.push({\n name: '.contentrain/ structure',\n pass: structurePass,\n detail: !hasCrDir\n ? 'Not initialized — run `contentrain init`'\n : [\n hasConfig ? null : 'missing config.json',\n hasModels ? null : 'missing models/',\n hasContent ? null : 'missing content/',\n ].filter(Boolean).join(', ') || 'OK',\n severity: structurePass ? undefined : 'error',\n })\n\n // ─── 5. Config parseable ───\n let config: ContentrainConfig | null = null\n if (hasConfig) {\n config = await readConfig(projectRoot)\n checks.push({\n name: 'Config',\n pass: config !== null,\n detail: config\n ? `stack: ${config.stack}, locales: ${config.locales.supported.join(', ')}`\n : 'Failed to parse config.json',\n severity: config ? undefined : 'error',\n })\n }\n\n // ─── 6. Models parse AND satisfy the schema contract ───\n //\n // This check used to report \"all valid\" on the strength of JSON.parse alone,\n // which was a claim it had not earned. Model reads are unvalidated casts, so a\n // definition can be structurally wrong — a missing title_field, a field\n // constraint that cannot hold — and still load without a word. Doctor reports;\n // `contentrain validate --fix` is what repairs.\n if (hasCrDir) {\n try {\n // Enumerate the files, not `listModels`. `listModels` drops anything that\n // fails to parse, so routing this check through it made the \"failed to\n // parse\" branch unreachable — a corrupt model file was invisible to the\n // check whose job is to find it.\n const modelsDir = join(crDir, 'models')\n const files = (await readDir(modelsDir)).filter(f => f.endsWith('.json'))\n const parsed = await Promise.all(\n files.map(f => readJson<ModelDefinition>(join(modelsDir, f))),\n )\n const unparseable = files.filter((_, i) => parsed[i] === null)\n const invalid = parsed\n .filter((m): m is ModelDefinition => m !== null)\n .filter(m => validateModelDefinition(m).errors.length > 0)\n .map(m => m.id)\n const models = parsed.filter((m): m is ModelDefinition => m !== null)\n\n const problems = [\n ...(unparseable.length > 0 ? [`${unparseable.length} failed to parse (${unparseable.join(', ')})`] : []),\n ...(invalid.length > 0 ? [`${invalid.length} invalid (${invalid.join(', ')}) — run: contentrain validate --fix`] : []),\n ]\n checks.push({\n name: 'Models',\n pass: problems.length === 0,\n detail: `${models.length} model(s)${problems.length === 0 ? ', all valid' : `, ${problems.join('; ')}`}`,\n severity: problems.length === 0 ? undefined : 'error',\n })\n } catch {\n checks.push({ name: 'Models', pass: false, detail: 'Failed to read models', severity: 'error' })\n }\n }\n\n // ─── 7. Orphan content ───\n if (hasCrDir) {\n const orphans = await findOrphanContent(projectRoot)\n checks.push({\n name: 'Orphan content',\n pass: orphans.length === 0,\n detail: orphans.length === 0 ? 'None' : `Found: ${orphans.join(', ')}`,\n severity: orphans.length === 0 ? undefined : 'warning',\n })\n }\n\n // ─── 8. Stale contentrain branches ───\n if (hasGit) {\n try {\n const health = await checkBranchHealth(projectRoot)\n checks.push({\n name: 'Pending branches',\n pass: !health.blocked && !health.warning,\n detail: health.message\n ?? (health.unmerged === 0 ? 'None' : `${health.unmerged} active cr/* branch(es)`),\n severity: health.blocked ? 'error' : health.warning ? 'warning' : undefined,\n })\n } catch {\n checks.push({ name: 'Pending branches', pass: true, detail: 'Could not check' })\n }\n\n // ─── 8b. Remote cr/* branches ───\n // Authoritative ls-remote count (local branch pressure cannot see the\n // remote pile). Best-effort: skipped entirely without a remote, and an\n // unreachable remote is informational — doctor never fails offline.\n const remoteList = await listRemoteCrBranches(projectRoot, { timeoutMs: 5000 })\n if (remoteList) {\n if (remoteList.error) {\n checks.push({\n name: 'Remote branches',\n pass: true,\n detail: `Could not check ${remoteList.remote} (offline?)`,\n severity: 'info',\n })\n } else {\n const count = remoteList.branches.length\n const warnLimit = config?.branchWarnLimit ?? 50\n const warn = count >= warnLimit\n checks.push({\n name: 'Remote branches',\n pass: !warn,\n detail: count === 0\n ? `None on ${remoteList.remote}`\n : `${count} cr/* branch(es) on ${remoteList.remote}${warn ? ' — run `contentrain prune` to remove merged leftovers' : ''}`,\n severity: warn ? 'warning' : undefined,\n })\n }\n }\n }\n\n // ─── 9. SDK client freshness ───\n const clientDir = join(crDir, 'client')\n const modelsDir = join(crDir, 'models')\n if (await pathExists(clientDir) && await pathExists(modelsDir)) {\n try {\n const [clientMtime, modelsMtime] = await Promise.all([\n newestFileMtime(clientDir),\n newestFileMtime(modelsDir),\n ])\n if (clientMtime === null || modelsMtime === null) {\n checks.push({ name: 'SDK client', pass: true, detail: 'Could not check' })\n } else {\n const fresh = clientMtime >= modelsMtime\n checks.push({\n name: 'SDK client',\n pass: fresh,\n detail: fresh ? 'Up to date' : 'Stale — run `contentrain generate`',\n severity: fresh ? undefined : 'warning',\n })\n }\n } catch {\n checks.push({ name: 'SDK client', pass: true, detail: 'Could not check' })\n }\n }\n\n // ─── 10–12. Usage analysis (optional) ───\n let usage: DoctorUsageAnalysis | undefined\n if (options.usage && hasCrDir && config) {\n const [unusedKeys, duplicateValues, missingLocaleKeys] = await Promise.all([\n analyzeUnusedKeys(projectRoot, config),\n analyzeDuplicateValues(projectRoot, config),\n analyzeMissingLocaleKeys(projectRoot, config),\n ])\n usage = { unusedKeys, duplicateValues, missingLocaleKeys }\n\n checks.push({\n name: 'Unused dictionary keys',\n pass: unusedKeys.length === 0,\n detail: unusedKeys.length === 0\n ? 'All dictionary keys referenced in source'\n : `${unusedKeys.length} dictionary key(s) not referenced in source code`,\n severity: unusedKeys.length === 0 ? undefined : 'warning',\n })\n\n checks.push({\n name: 'Duplicate dictionary values',\n pass: duplicateValues.length === 0,\n detail: duplicateValues.length === 0\n ? 'No duplicate values'\n : `${duplicateValues.length} value(s) mapped to multiple keys`,\n severity: duplicateValues.length === 0 ? undefined : 'warning',\n })\n\n checks.push({\n name: 'Locale key coverage',\n pass: missingLocaleKeys.length === 0,\n detail: missingLocaleKeys.length === 0\n ? 'All locales have matching keys'\n : `${missingLocaleKeys.length} key(s) missing in some locales`,\n severity: missingLocaleKeys.length === 0 ? undefined : 'warning',\n })\n }\n\n const passed = checks.filter(c => c.pass).length\n const failed = checks.length - passed\n const warnings = checks.filter(c => !c.pass && c.severity === 'warning').length\n\n const report: DoctorReport = {\n checks,\n summary: { total: checks.length, passed, failed, warnings },\n }\n if (usage) report.usage = usage\n return report\n}\n\n/**\n * Newest mtime among the files under `dir`, recursively — null if it holds none.\n *\n * Stat the files, never the directory. A directory's mtime only moves when an\n * entry is added, removed, or renamed inside it: `generate` rewrites the client\n * files in place, so `.contentrain/client` never moves after the first run,\n * while a selective sync recreates model files via `git checkout`, which does\n * move `.contentrain/models`. Comparing the two directories therefore reported\n * \"stale\" permanently after any model save.\n */\nasync function newestFileMtime(dir: string): Promise<number | null> {\n const entries: Dirent[] = await readdir(dir, { withFileTypes: true }).catch(() => [])\n const mtimes = await Promise.all(entries.map(async (entry) => {\n const full = join(dir, entry.name)\n if (entry.isDirectory()) return newestFileMtime(full)\n return stat(full).then(s => s.mtimeMs, () => null)\n }))\n const known = mtimes.filter((m): m is number => m !== null)\n return known.length > 0 ? Math.max(...known) : null\n}\n\nasync function findOrphanContent(projectRoot: string): Promise<string[]> {\n const crDir = contentrainDir(projectRoot)\n const models = await listModels(projectRoot)\n const orphans: string[] = []\n\n const knownContentDirs = new Set<string>()\n for (const m of models) {\n const full = await readModel(projectRoot, m.id)\n const modelForPath = full\n ? {\n ...full,\n content_path: full.content_path ?? (m as { content_path?: string }).content_path,\n }\n : {\n id: m.id,\n name: m.id,\n kind: m.kind,\n domain: m.domain,\n i18n: m.i18n,\n fields: {},\n content_path: (m as { content_path?: string }).content_path,\n }\n knownContentDirs.add(resolveContentDir(projectRoot, modelForPath))\n }\n\n const contentDir = join(crDir, 'content')\n if (await pathExists(contentDir)) {\n const domains = await readDir(contentDir)\n for (const domain of domains) {\n const domainDir = join(contentDir, domain)\n const entries = await readDir(domainDir)\n for (const entry of entries) {\n if (entry === '.gitkeep') continue\n const entryDir = join(domainDir, entry)\n if (!knownContentDirs.has(entryDir)) {\n orphans.push(`${domain}/${entry}`)\n }\n }\n }\n }\n\n for (const dir of knownContentDirs) {\n if (dir.startsWith(contentDir)) continue\n if (!await pathExists(dir)) {\n orphans.push(`(missing custom path) ${dir}`)\n continue\n }\n await readDir(dir)\n }\n\n return orphans\n}\n\nasync function analyzeUnusedKeys(\n projectRoot: string,\n config: ContentrainConfig,\n): Promise<UnusedKeyEntry[]> {\n const sourceDirs = await autoDetectSourceDirs(projectRoot)\n const files = await discoverFiles(projectRoot, { paths: sourceDirs })\n if (files.length === 0) return []\n\n const chunks = await Promise.all(\n files.map(async (relPath) => {\n const content = await readText(join(projectRoot, relPath))\n return content ?? ''\n }),\n )\n const allSource = chunks.join('\\n')\n\n // Dictionaries only.\n //\n // A dictionary key IS the reference — source code writes `t('nav.home')`, so\n // a key absent from source is genuinely dead. Collection entry IDs and\n // document slugs are not: entries are fetched by query, and a hex id like\n // `0a1b2c3d4e5f` will never appear in a source file. Checking them produced\n // a report that was mostly noise — of 134 warnings on a real project, ~120\n // were collection and document rows, and the real findings were lost among\n // them.\n const models = (await listModels(projectRoot)).filter(m => m.kind === 'dictionary')\n const defaultLocale = config.locales.default\n const unused: UnusedKeyEntry[] = []\n\n for (const m of models) {\n const fullModel = await readModel(projectRoot, m.id)\n if (!fullModel) continue\n\n const keys = await extractContentKeys(projectRoot, fullModel, defaultLocale)\n for (const key of keys) {\n if (!allSource.includes(key)) {\n unused.push({ model: m.id, kind: m.kind, key, locale: defaultLocale })\n }\n }\n }\n\n return unused\n}\n\n/**\n * Keys of a model that source code could plausibly reference by name.\n *\n * Only dictionaries have any: their keys are semantic addresses that appear\n * verbatim in source. Every other kind is queried, so its ids and slugs are\n * data, not identifiers, and looking for them in source finds nothing and\n * means nothing.\n */\nasync function extractContentKeys(\n projectRoot: string,\n model: ModelDefinition,\n locale: string,\n): Promise<string[]> {\n const cDir = resolveContentDir(projectRoot, model)\n if (!await pathExists(cDir)) return []\n\n switch (model.kind) {\n case 'dictionary': {\n const filePath = resolveJsonFilePath(cDir, model, locale)\n const data = await readJson<Record<string, string>>(filePath)\n return data ? Object.keys(data) : []\n }\n case 'collection': {\n const filePath = resolveJsonFilePath(cDir, model, locale)\n const data = await readJson<Record<string, Record<string, unknown>>>(filePath)\n return data ? Object.keys(data) : []\n }\n case 'document': {\n const strategy = resolveLocaleStrategy(model)\n const slugs: string[] = []\n if (!model.i18n) {\n const files = await readDir(cDir)\n for (const f of files) if (f.endsWith('.md')) slugs.push(f.replace('.md', ''))\n } else if (strategy === 'file') {\n const dirs = await readDir(cDir)\n for (const d of dirs) if (!d.startsWith('.')) slugs.push(d)\n } else if (strategy === 'suffix') {\n const files = await readDir(cDir)\n const suffix = `.${locale}.md`\n for (const f of files) if (f.endsWith(suffix)) slugs.push(f.slice(0, -suffix.length))\n } else if (strategy === 'directory') {\n const localeDir = join(cDir, locale)\n if (await pathExists(localeDir)) {\n const files = await readDir(localeDir)\n for (const f of files) if (f.endsWith('.md')) slugs.push(f.replace('.md', ''))\n }\n } else {\n const files = await readDir(cDir)\n for (const f of files) if (f.endsWith('.md')) slugs.push(f.replace('.md', ''))\n }\n return slugs\n }\n case 'singleton':\n return []\n default:\n return []\n }\n}\n\nasync function analyzeDuplicateValues(\n projectRoot: string,\n config: ContentrainConfig,\n): Promise<DuplicateValueEntry[]> {\n const models = await listModels(projectRoot)\n const result: DuplicateValueEntry[] = []\n\n for (const m of models) {\n if (m.kind !== 'dictionary') continue\n const fullModel = await readModel(projectRoot, m.id)\n if (!fullModel) continue\n\n const cDir = resolveContentDir(projectRoot, fullModel)\n for (const locale of config.locales.supported) {\n const filePath = resolveJsonFilePath(cDir, fullModel, locale)\n const data = await readJson<Record<string, string>>(filePath)\n if (!data) continue\n\n const valueToKeys = new Map<string, string[]>()\n for (const [key, value] of Object.entries(data)) {\n const arr = valueToKeys.get(value)\n if (arr) arr.push(key)\n else valueToKeys.set(value, [key])\n }\n\n for (const [value, keys] of valueToKeys) {\n if (keys.length > 1) {\n result.push({ model: m.id, locale, value, keys })\n }\n }\n }\n }\n\n return result\n}\n\nasync function analyzeMissingLocaleKeys(\n projectRoot: string,\n config: ContentrainConfig,\n): Promise<MissingLocaleEntry[]> {\n if (config.locales.supported.length < 2) return []\n\n const models = await listModels(projectRoot)\n const result: MissingLocaleEntry[] = []\n const defaultLocale = config.locales.default\n const otherLocales = config.locales.supported.filter(l => l !== defaultLocale)\n\n for (const m of models) {\n if (m.kind !== 'dictionary' && m.kind !== 'collection') continue\n if (!m.i18n) continue\n\n const fullModel = await readModel(projectRoot, m.id)\n if (!fullModel) continue\n\n const cDir = resolveContentDir(projectRoot, fullModel)\n const defaultPath = resolveJsonFilePath(cDir, fullModel, defaultLocale)\n const defaultData = await readJson<Record<string, unknown>>(defaultPath)\n if (!defaultData) continue\n const defaultKeys = new Set(Object.keys(defaultData))\n\n for (const locale of otherLocales) {\n const localePath = resolveJsonFilePath(cDir, fullModel, locale)\n const localeData = await readJson<Record<string, unknown>>(localePath)\n const localeKeys = localeData ? new Set(Object.keys(localeData)) : new Set<string>()\n\n for (const key of defaultKeys) {\n if (!localeKeys.has(key)) {\n result.push({ model: m.id, key, missingIn: locale })\n }\n }\n }\n }\n\n return result\n}\n"],"mappings":";;;;;;;;;AA4FA,eAAsB,UACpB,aACA,UAA4B,EAAE,EACP;CACvB,MAAM,SAAwB,EAAE;AAGhC,KAAI;EAEF,MAAM,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,MAAI,CAAC,EAAE,KAAM;EAEb,MAAM,YAAY,MAAM,UAAU,aAAa,EAAE,GAAG;AACpD,MAAI,CAAC,UAAW;EAEhB,MAAM,OAAO,kBAAkB,aAAa,UAAU;EAEtD,MAAM,cAAc,MAAM,SADN,oBAAoB,MAAM,WAAW,cAAc,CACC;AACxE,MAAI,CAAC,YAAa;EAClB,MAAM,cAAc,IAAI,IAAI,OAAO,KAAK,YAAY,CAAC;AAErD,OAAK,MAAM,UAAU,cAAc;GAEjC,MAAM,aAAa,MAAM,SADN,oBAAoB,MAAM,WAAW,OAAO,CACO;GACtE,MAAM,aAAa,aAAa,IAAI,IAAI,OAAO,KAAK,WAAW,CAAC,mBAAG,IAAI,KAAa;AAEpF,QAAK,MAAM,OAAO,YAChB,KAAI,CAAC,WAAW,IAAI,IAAI,CACtB,QAAO,KAAK;IAAE,OAAO,EAAE;IAAI;IAAK,WAAW;IAAQ,CAAC;;;AAM5D,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors-
|
|
1
|
+
{"version":3,"file":"errors-CvBS12e7.mjs","names":[],"sources":["../src/providers/shared/errors.ts"],"sourcesContent":["/**\n * Error shapes for API-backed providers, and the mapping from those shapes\n * into Contentrain's structured error envelope.\n *\n * Two common error shapes in the provider SDKs we use:\n *\n * - **Octokit** (`@octokit/rest`) — rejects with an `Error` that has a\n * top-level `.status` number set to the HTTP status code.\n * - **Gitbeaker** (`@gitbeaker/rest`) — rejects with a plain `Error` whose\n * `.cause` includes `{ response: { status } }`.\n */\n\n/**\n * HTTP status behind a provider SDK rejection, or `undefined` when the error\n * is not an HTTP failure (a local git error, a programming mistake, …).\n *\n * We deliberately do NOT fall back to substring matching on the error\n * message — that leniency can silently mask other failures (forbidden repo,\n * deleted project, rate limits) and produce the wrong answer. If either SDK\n * ever stops populating the status field, the regression surfaces in tests\n * rather than being papered over at the reader layer.\n */\nexport function extractHttpStatus(error: unknown): number | undefined {\n if (typeof error !== 'object' || error === null) return undefined\n const direct = (error as { status?: number }).status\n if (typeof direct === 'number') return direct\n const nested = (error as { cause?: { response?: { status?: number } } }).cause?.response?.status\n return typeof nested === 'number' ? nested : undefined\n}\n\n/** Unified \"is this a 404?\" helper for API-backed providers. */\nexport function isNotFoundError(error: unknown): boolean {\n return extractHttpStatus(error) === 404\n}\n\n/**\n * Provider SDK messages are written for a human reading a terminal, not for an\n * agent deciding what to do next. Octokit appends a documentation URL to most\n * messages and embeds the raw JSON response body on validation failures.\n *\n * The vendor text still carries the only specifics we have (\"Reference already\n * exists\", which field failed), so it is kept as a parenthetical detail rather\n * than discarded — but the doc links are noise for an agent, and an embedded\n * body can be arbitrarily long, so URLs are stripped and the result is capped.\n */\nfunction sanitiseDetail(error: unknown): string {\n const raw = (error as { message?: string } | undefined)?.message ?? String(error)\n const withoutUrls = raw.replace(/\\s*-?\\s*https?:\\/\\/\\S+/g, '')\n const collapsed = withoutUrls.replace(/\\s+/g, ' ').trim()\n return collapsed.length > 200 ? `${collapsed.slice(0, 197)}…` : collapsed\n}\n\n/**\n * GitHub signals rate limiting with 403 plus an exhausted remaining-quota\n * header (secondary limits use 403 too), and with 429 on some endpoints.\n * Checking the header first keeps a genuine permission 403 from being\n * reported as a rate limit.\n */\nfunction isRateLimited(error: unknown, status: number): boolean {\n if (status === 429) return true\n if (status !== 403) return false\n const headers = (error as { response?: { headers?: Record<string, unknown> } }).response?.headers\n const remaining = headers?.['x-ratelimit-remaining']\n if (remaining !== undefined) return String(remaining) === '0'\n return /\\brate limit\\b/i.test((error as { message?: string }).message ?? '')\n}\n\nexport interface ProviderErrorInfo {\n error: string\n code: string\n agent_hint: string\n developer_action?: string\n}\n\n/**\n * Map a provider SDK rejection onto the same structured envelope the local git\n * paths already produce (`code` + `agent_hint` + `developer_action`). Returns\n * `undefined` for anything that is not a recognisable provider HTTP failure,\n * so local git errors and ordinary exceptions pass through untouched.\n */\nexport function mapProviderError(error: unknown): ProviderErrorInfo | undefined {\n const status = extractHttpStatus(error)\n if (status === undefined) return undefined\n\n const detail = sanitiseDetail(error)\n const withDetail = (summary: string): string => (detail ? `${summary} (${detail})` : summary)\n\n if (isRateLimited(error, status)) {\n return {\n error: withDetail('The git provider rejected the request because the API rate limit is exhausted.'),\n code: 'PROVIDER_RATE_LIMITED',\n agent_hint: 'Do not retry immediately — the limit is time-based. Stop the current operation and report it to the developer.',\n developer_action: 'Wait for the rate-limit window to reset, or use a token with a higher quota.',\n }\n }\n\n switch (status) {\n case 401:\n return {\n error: withDetail('The git provider rejected the credentials.'),\n code: 'PROVIDER_UNAUTHORIZED',\n agent_hint: 'The token is missing, malformed, or expired. Not retryable — ask the developer to fix the credentials.',\n developer_action: 'Check the provider token configured for this Contentrain server and reissue it if it has expired.',\n }\n case 403:\n return {\n error: withDetail('The git provider denied access to this resource.'),\n code: 'PROVIDER_FORBIDDEN',\n agent_hint: 'The credentials are valid but lack permission for this operation. Not retryable — report which operation was refused.',\n developer_action: 'Grant the token write access to the repository, or check whether branch protection or SSO authorisation is blocking it.',\n }\n case 404:\n return {\n error: withDetail('The git provider could not find the requested resource.'),\n code: 'PROVIDER_NOT_FOUND',\n agent_hint: 'The repository, branch, or path does not exist — or the token cannot see it, which also returns 404. Verify the target before retrying.',\n developer_action: 'Confirm the repository and branch names in the Contentrain config, and that the token can reach a private repository.',\n }\n case 409:\n return {\n error: withDetail('The git provider reported a conflict.'),\n code: 'PROVIDER_CONFLICT',\n agent_hint: 'The branch moved between read and write. Re-read the current state and rebuild the change before retrying once.',\n developer_action: 'Usually a concurrent write to the same branch; retrying the operation normally resolves it.',\n }\n case 422:\n return {\n error: withDetail('The git provider rejected the request as invalid.'),\n code: 'PROVIDER_VALIDATION_FAILED',\n agent_hint: 'Well-formed but semantically rejected (e.g. the ref already exists, or a name is invalid). Do not retry unchanged.',\n developer_action: 'Inspect the detail above — a stale branch left over from an earlier run is the common cause.',\n }\n default:\n if (status >= 500) {\n return {\n error: withDetail('The git provider is unavailable.'),\n code: 'PROVIDER_UNAVAILABLE',\n agent_hint: 'A server-side failure on the provider. Safe to retry once after a short pause; if it persists, stop and report it.',\n developer_action: 'Check the provider status page.',\n }\n }\n return {\n error: withDetail(`The git provider returned HTTP ${status}.`),\n code: 'PROVIDER_REQUEST_FAILED',\n agent_hint: 'An unmapped provider failure. Report the status and detail to the developer rather than retrying blindly.',\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,kBAAkB,OAAoC;AACpE,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO,KAAA;CACxD,MAAM,SAAU,MAA8B;AAC9C,KAAI,OAAO,WAAW,SAAU,QAAO;CACvC,MAAM,SAAU,MAAyD,OAAO,UAAU;AAC1F,QAAO,OAAO,WAAW,WAAW,SAAS,KAAA;;;AAI/C,SAAgB,gBAAgB,OAAyB;AACvD,QAAO,kBAAkB,MAAM,KAAK;;;;;;;;;;;;AAatC,SAAS,eAAe,OAAwB;CAG9C,MAAM,aAFO,OAA4C,WAAW,OAAO,MAAM,EACzD,QAAQ,2BAA2B,GAAG,CAChC,QAAQ,QAAQ,IAAI,CAAC,MAAM;AACzD,QAAO,UAAU,SAAS,MAAM,GAAG,UAAU,MAAM,GAAG,IAAI,CAAC,KAAK;;;;;;;;AASlE,SAAS,cAAc,OAAgB,QAAyB;AAC9D,KAAI,WAAW,IAAK,QAAO;AAC3B,KAAI,WAAW,IAAK,QAAO;CAE3B,MAAM,aADW,MAA+D,UAAU,WAC9D;AAC5B,KAAI,cAAc,KAAA,EAAW,QAAO,OAAO,UAAU,KAAK;AAC1D,QAAO,kBAAkB,KAAM,MAA+B,WAAW,GAAG;;;;;;;;AAgB9E,SAAgB,iBAAiB,OAA+C;CAC9E,MAAM,SAAS,kBAAkB,MAAM;AACvC,KAAI,WAAW,KAAA,EAAW,QAAO,KAAA;CAEjC,MAAM,SAAS,eAAe,MAAM;CACpC,MAAM,cAAc,YAA6B,SAAS,GAAG,QAAQ,IAAI,OAAO,KAAK;AAErF,KAAI,cAAc,OAAO,OAAO,CAC9B,QAAO;EACL,OAAO,WAAW,iFAAiF;EACnG,MAAM;EACN,YAAY;EACZ,kBAAkB;EACnB;AAGH,SAAQ,QAAR;EACE,KAAK,IACH,QAAO;GACL,OAAO,WAAW,6CAA6C;GAC/D,MAAM;GACN,YAAY;GACZ,kBAAkB;GACnB;EACH,KAAK,IACH,QAAO;GACL,OAAO,WAAW,mDAAmD;GACrE,MAAM;GACN,YAAY;GACZ,kBAAkB;GACnB;EACH,KAAK,IACH,QAAO;GACL,OAAO,WAAW,0DAA0D;GAC5E,MAAM;GACN,YAAY;GACZ,kBAAkB;GACnB;EACH,KAAK,IACH,QAAO;GACL,OAAO,WAAW,wCAAwC;GAC1D,MAAM;GACN,YAAY;GACZ,kBAAkB;GACnB;EACH,KAAK,IACH,QAAO;GACL,OAAO,WAAW,oDAAoD;GACtE,MAAM;GACN,YAAY;GACZ,kBAAkB;GACnB;EACH;AACE,OAAI,UAAU,IACZ,QAAO;IACL,OAAO,WAAW,mCAAmC;IACrD,MAAM;IACN,YAAY;IACZ,kBAAkB;IACnB;AAEH,UAAO;IACL,OAAO,WAAW,kCAAkC,OAAO,GAAG;IAC9D,MAAM;IACN,YAAY;IACb"}
|
package/dist/fs-DLbVB-Ek.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs-DLbVB-Ek.mjs","names":[],"sources":["../src/util/fs.ts"],"sourcesContent":["import { readFile, readdir, access, writeFile, mkdir } from 'node:fs/promises'\nimport { join } from 'node:path'\nimport { canonicalStringify } from '@contentrain/types'\n\nexport async function pathExists(filePath: string): Promise<boolean> {\n try {\n await access(filePath)\n return true\n } catch {\n return false\n }\n}\n\nexport async function readJson<T>(filePath: string): Promise<T | null> {\n try {\n const raw = await readFile(filePath, 'utf-8')\n return JSON.parse(raw) as T\n } catch {\n return null\n }\n}\n\nexport async function readDir(dirPath: string): Promise<string[]> {\n try {\n return await readdir(dirPath)\n } catch {\n return []\n }\n}\n\nexport async function writeJson(filePath: string, data: unknown, fieldOrder?: string[]): Promise<void> {\n await mkdir(join(filePath, '..'), { recursive: true })\n await writeFile(filePath, canonicalStringify(data, fieldOrder), 'utf-8')\n}\n\nexport async function ensureDir(dirPath: string): Promise<void> {\n await mkdir(dirPath, { recursive: true })\n}\n\nexport async function readText(filePath: string): Promise<string | null> {\n try {\n return await readFile(filePath, 'utf-8')\n } catch {\n return null\n }\n}\n\nexport async function writeText(filePath: string, content: string): Promise<void> {\n await mkdir(join(filePath, '..'), { recursive: true })\n await writeFile(filePath, content, 'utf-8')\n}\n\nexport function contentrainDir(projectRoot: string): string {\n return join(projectRoot, '.contentrain')\n}\n"],"mappings":";;;;AAIA,eAAsB,WAAW,UAAoC;AACnE,KAAI;AACF,QAAM,OAAO,SAAS;AACtB,SAAO;SACD;AACN,SAAO;;;AAIX,eAAsB,SAAY,UAAqC;AACrE,KAAI;EACF,MAAM,MAAM,MAAM,SAAS,UAAU,QAAQ;AAC7C,SAAO,KAAK,MAAM,IAAI;SAChB;AACN,SAAO;;;AAIX,eAAsB,QAAQ,SAAoC;AAChE,KAAI;AACF,SAAO,MAAM,QAAQ,QAAQ;SACvB;AACN,SAAO,EAAE;;;AAIb,eAAsB,UAAU,UAAkB,MAAe,
|
|
1
|
+
{"version":3,"file":"fs-DLbVB-Ek.mjs","names":[],"sources":["../src/util/fs.ts"],"sourcesContent":["import { readFile, readdir, access, writeFile, mkdir } from 'node:fs/promises'\nimport { join } from 'node:path'\nimport { canonicalStringify } from '@contentrain/types'\n\nexport async function pathExists(filePath: string): Promise<boolean> {\n try {\n await access(filePath)\n return true\n } catch {\n return false\n }\n}\n\nexport async function readJson<T>(filePath: string): Promise<T | null> {\n try {\n const raw = await readFile(filePath, 'utf-8')\n return JSON.parse(raw) as T\n } catch {\n return null\n }\n}\n\nexport async function readDir(dirPath: string): Promise<string[]> {\n try {\n return await readdir(dirPath)\n } catch {\n return []\n }\n}\n\nexport async function writeJson(filePath: string, data: unknown, fieldOrder?: readonly string[]): Promise<void> {\n await mkdir(join(filePath, '..'), { recursive: true })\n await writeFile(filePath, canonicalStringify(data, fieldOrder), 'utf-8')\n}\n\nexport async function ensureDir(dirPath: string): Promise<void> {\n await mkdir(dirPath, { recursive: true })\n}\n\nexport async function readText(filePath: string): Promise<string | null> {\n try {\n return await readFile(filePath, 'utf-8')\n } catch {\n return null\n }\n}\n\nexport async function writeText(filePath: string, content: string): Promise<void> {\n await mkdir(join(filePath, '..'), { recursive: true })\n await writeFile(filePath, content, 'utf-8')\n}\n\nexport function contentrainDir(projectRoot: string): string {\n return join(projectRoot, '.contentrain')\n}\n"],"mappings":";;;;AAIA,eAAsB,WAAW,UAAoC;AACnE,KAAI;AACF,QAAM,OAAO,SAAS;AACtB,SAAO;SACD;AACN,SAAO;;;AAIX,eAAsB,SAAY,UAAqC;AACrE,KAAI;EACF,MAAM,MAAM,MAAM,SAAS,UAAU,QAAQ;AAC7C,SAAO,KAAK,MAAM,IAAI;SAChB;AACN,SAAO;;;AAIX,eAAsB,QAAQ,SAAoC;AAChE,KAAI;AACF,SAAO,MAAM,QAAQ,QAAQ;SACvB;AACN,SAAO,EAAE;;;AAIb,eAAsB,UAAU,UAAkB,MAAe,YAA+C;AAC9G,OAAM,MAAM,KAAK,UAAU,KAAK,EAAE,EAAE,WAAW,MAAM,CAAC;AACtD,OAAM,UAAU,UAAU,mBAAmB,MAAM,WAAW,EAAE,QAAQ;;AAG1E,eAAsB,UAAU,SAAgC;AAC9D,OAAM,MAAM,SAAS,EAAE,WAAW,MAAM,CAAC;;AAG3C,eAAsB,SAAS,UAA0C;AACvE,KAAI;AACF,SAAO,MAAM,SAAS,UAAU,QAAQ;SAClC;AACN,SAAO;;;AAIX,eAAsB,UAAU,UAAkB,SAAgC;AAChF,OAAM,MAAM,KAAK,UAAU,KAAK,EAAE,EAAE,WAAW,MAAM,CAAC;AACtD,OAAM,UAAU,UAAU,SAAS,QAAQ;;AAG7C,SAAgB,eAAe,aAA6B;AAC1D,QAAO,KAAK,aAAa,eAAe"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as RemoteDeleteResult, c as checkBranchHealth, d as deleteRemoteBranch, f as isRefMerged, i as RemoteBranchList, l as classifyMergedBranches, m as pruneMergedRemoteBranches, n as BranchHealthCheck, o as RemotePruneResult, p as listRemoteCrBranches, r as CleanupResult, s as branchDiff, t as BranchDiffResult, u as cleanupMergedBranches } from "../branch-lifecycle-
|
|
1
|
+
import { a as RemoteDeleteResult, c as checkBranchHealth, d as deleteRemoteBranch, f as isRefMerged, i as RemoteBranchList, l as classifyMergedBranches, m as pruneMergedRemoteBranches, n as BranchHealthCheck, o as RemotePruneResult, p as listRemoteCrBranches, r as CleanupResult, s as branchDiff, t as BranchDiffResult, u as cleanupMergedBranches } from "../branch-lifecycle-DhzHfzs3.mjs";
|
|
2
2
|
export { BranchDiffResult, BranchHealthCheck, CleanupResult, RemoteBranchList, RemoteDeleteResult, RemotePruneResult, branchDiff, checkBranchHealth, classifyMergedBranches, cleanupMergedBranches, deleteRemoteBranch, isRefMerged, listRemoteCrBranches, pruneMergedRemoteBranches };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "../fs-DLbVB-Ek.mjs";
|
|
2
|
-
import "../
|
|
3
|
-
import
|
|
2
|
+
import "../identity-D8QoGxhT.mjs";
|
|
3
|
+
import "../config-VlRKRwAS.mjs";
|
|
4
|
+
import { a as deleteRemoteBranch, c as pruneMergedRemoteBranches, i as cleanupMergedBranches, n as checkBranchHealth, o as isRefMerged, r as classifyMergedBranches, s as listRemoteCrBranches, t as branchDiff } from "../branch-lifecycle-B6PXZ2N7.mjs";
|
|
4
5
|
export { branchDiff, checkBranchHealth, classifyMergedBranches, cleanupMergedBranches, deleteRemoteBranch, isRefMerged, listRemoteCrBranches, pruneMergedRemoteBranches };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SimpleGit, SimpleGitOptions } from "simple-git";
|
|
2
|
+
|
|
3
|
+
//#region src/git/identity.d.ts
|
|
4
|
+
declare function gitBinary(): string;
|
|
5
|
+
/** Reset the cached binary. Tests only. */
|
|
6
|
+
declare function resetGitBinary(): void;
|
|
7
|
+
/**
|
|
8
|
+
* The single constructor for every `simple-git` instance in this package.
|
|
9
|
+
*
|
|
10
|
+
* Exists so the resolved binary (above) cannot be forgotten at a call site —
|
|
11
|
+
* there were 41 of them, and one that spawns by bare name silently gives back
|
|
12
|
+
* the 13× penalty for that code path only.
|
|
13
|
+
*/
|
|
14
|
+
declare function createGit(baseDir?: string, options?: Partial<SimpleGitOptions>): SimpleGit;
|
|
15
|
+
/**
|
|
16
|
+
* Commit identity as `-c` config entries for `simpleGit(dir, { config })`.
|
|
17
|
+
* Passed as arguments (not env) so the block-unsafe guard is never triggered,
|
|
18
|
+
* regardless of what the host process exports. Sets author + committer alike.
|
|
19
|
+
*/
|
|
20
|
+
declare function authorConfig(): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Guard opt-outs for network `git` instances that MUST inherit the real
|
|
23
|
+
* environment (credential askpass helpers, SSH agent, proxy) to authenticate a
|
|
24
|
+
* push/fetch. Covers every guard category reachable from an inherited env var,
|
|
25
|
+
* so the command never trips regardless of what the host (VS Code, CI) exports
|
|
26
|
+
* — while still leaving arg-injection protections (custom binaries, `ext::`
|
|
27
|
+
* protocol, `--upload-pack`) intact.
|
|
28
|
+
*/
|
|
29
|
+
declare const NETWORK_UNSAFE: {
|
|
30
|
+
allowUnsafeAskPass: boolean;
|
|
31
|
+
allowUnsafeConfigEnvCount: boolean;
|
|
32
|
+
allowUnsafeConfigPaths: boolean;
|
|
33
|
+
allowUnsafeDiffExternal: boolean;
|
|
34
|
+
allowUnsafeEditor: boolean;
|
|
35
|
+
allowUnsafeGitProxy: boolean;
|
|
36
|
+
allowUnsafePager: boolean;
|
|
37
|
+
allowUnsafeSshCommand: boolean;
|
|
38
|
+
allowUnsafeTemplateDir: boolean;
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { NETWORK_UNSAFE, authorConfig, createGit, gitBinary, resetGitBinary };
|
|
42
|
+
//# sourceMappingURL=identity.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.mts","names":[],"sources":["../../src/git/identity.ts"],"mappings":";;;iBAmDgB,SAAA,CAAA;;iBA8BA,cAAA,CAAA;;;;;;;AAqBhB;iBAVgB,SAAA,CAAU,OAAA,WAAkB,OAAA,GAAU,OAAA,CAAQ,gBAAA,IAAoB,SAAA;;;;AAwBlF;;iBAdgB,YAAA,CAAA;;;;;;;;;cAcH,cAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.mts","names":[],"sources":["../../src/git/transaction.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"transaction.d.mts","names":[],"sources":["../../src/git/transaction.ts"],"mappings":";;;;UAeiB,aAAA;EACf,IAAA;EACA,KAAA;EACA,MAAA;EACA,OAAA;AAAA;AAAA,UAGe,cAAA;EACf,QAAA;EACA,MAAA;EACA,KAAA,CAAM,QAAA,GAAW,YAAA,aAAyB,OAAA,SAAgB,OAAA;EAC1D,MAAA,CAAO,OAAA,UAAiB,aAAA,GAAgB,aAAA,GAAgB,OAAA;EACxD,QAAA,IAAY,OAAA;IAAU,MAAA;IAA0C,MAAA;IAAgB,IAAA,GAAO,UAAA;IAAY,OAAA;EAAA;EACnG,OAAA,IAAW,OAAA;AAAA;AAAA,iBAGS,mBAAA,CAAoB,WAAA,WAAsB,OAAA;AAAA,iBA4I1C,iBAAA,CACpB,WAAA,UACA,UAAA,UACA,OAAA;EAAY,gBAAA,GAAmB,YAAA;AAAA,IAC9B,OAAA,CAAQ,cAAA;AAAA,iBAuQW,WAAA,CACpB,WAAA,UACA,UAAA,WACC,OAAA;EAAU,MAAA;EAAkB,MAAA;EAAgB,IAAA,EAAM,UAAA;EAAY,MAAA,GAAS,kBAAA;AAAA;AAAA,iBAsI1D,eAAA,CAAgB,KAAA,UAAe,MAAA,UAAgB,MAAA"}
|
package/dist/git/transaction.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import "../serialization-
|
|
1
|
+
import "../serialization-tmgfFBOh.mjs";
|
|
2
2
|
import "../fs-DLbVB-Ek.mjs";
|
|
3
|
-
import "../meta-manager-
|
|
4
|
-
import "../
|
|
5
|
-
import "../
|
|
6
|
-
import "../
|
|
7
|
-
import "../
|
|
8
|
-
import "../
|
|
9
|
-
import
|
|
3
|
+
import "../meta-manager-B_Se183X.mjs";
|
|
4
|
+
import "../identity-D8QoGxhT.mjs";
|
|
5
|
+
import "../config-VlRKRwAS.mjs";
|
|
6
|
+
import "../branch-lifecycle-B6PXZ2N7.mjs";
|
|
7
|
+
import "../model-manager-DgyKMjLN.mjs";
|
|
8
|
+
import "../context-C3x6I3cE.mjs";
|
|
9
|
+
import "../id-BjhaIxTL.mjs";
|
|
10
|
+
import { i as mergeBranch, n as createTransaction, r as ensureContentBranch, t as buildBranchName } from "../transaction-BW9ektWu.mjs";
|
|
10
11
|
export { buildBranchName, createTransaction, ensureContentBranch, mergeBranch };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { o as readText, r as pathExists } from "./fs-DLbVB-Ek.mjs";
|
|
2
|
-
import { a as classifyFile, i as autoDetectSourceDirs, n as SCAN_EXTENSIONS, o as discoverFiles } from "./scan-config-
|
|
2
|
+
import { a as classifyFile, i as autoDetectSourceDirs, n as SCAN_EXTENSIONS, o as discoverFiles } from "./scan-config-Dx49nCqk.mjs";
|
|
3
3
|
import { dirname, extname, join, relative } from "node:path";
|
|
4
4
|
//#region src/core/graph-builder.ts
|
|
5
5
|
const MAX_ORPHANS = 10;
|
|
@@ -159,4 +159,4 @@ async function buildGraph(projectRoot, options) {
|
|
|
159
159
|
//#endregion
|
|
160
160
|
export { buildGraph as t };
|
|
161
161
|
|
|
162
|
-
//# sourceMappingURL=graph-builder-
|
|
162
|
+
//# sourceMappingURL=graph-builder-BEocwW13.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-builder-DK4Mh8Tn.mjs","names":[],"sources":["../src/core/graph-builder.ts"],"sourcesContent":["import type { FileCategory, GraphNode, ProjectGraph } from '@contentrain/types'\nimport { join, relative, dirname, extname } from 'node:path'\nimport { readText, pathExists } from '../util/fs.js'\nimport {\n SCAN_EXTENSIONS,\n classifyFile,\n autoDetectSourceDirs,\n discoverFiles,\n} from './scan-config.js'\n\nexport interface BuildGraphOptions {\n paths?: string[]\n include?: string[]\n exclude?: string[]\n}\n\nconst MAX_ORPHANS = 10\n\n// ---------------------------------------------------------------------------\n// Import extraction\n// ---------------------------------------------------------------------------\n\nconst IMPORT_RE = /(?:import|export)\\s+.*?from\\s+['\"]([^'\"]+)['\"]|(?:import|require)\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)/g\n\nfunction extractImportPaths(content: string): string[] {\n const paths: string[] = []\n let m: RegExpExecArray | null\n // Reset lastIndex before use since we reuse the regex\n IMPORT_RE.lastIndex = 0\n while ((m = IMPORT_RE.exec(content)) !== null) {\n const p = m[1] ?? m[2]\n if (p && isLocalImport(p)) {\n paths.push(p)\n }\n }\n return paths\n}\n\nfunction isLocalImport(p: string): boolean {\n return p.startsWith('.') || p.startsWith('/')\n}\n\n// ---------------------------------------------------------------------------\n// Component name extraction from imports\n// ---------------------------------------------------------------------------\n\nconst NAMED_IMPORT_RE = /import\\s+(?:type\\s+)?(?:(\\w+)(?:\\s*,\\s*)?)?(?:\\{([^}]*)\\})?\\s+from\\s+['\"][^'\"]+['\"]/g\nconst DEFAULT_IMPORT_RE = /import\\s+(?:type\\s+)?(\\w+)\\s+from\\s+['\"][^'\"]+['\"]/g\n\nfunction isPascalCase(name: string): boolean {\n return /^[A-Z][a-zA-Z0-9]*$/.test(name)\n}\n\nfunction extractComponentNames(content: string): string[] {\n const names = new Set<string>()\n\n // Default imports: `import Button from '...'`\n DEFAULT_IMPORT_RE.lastIndex = 0\n let m: RegExpExecArray | null\n while ((m = DEFAULT_IMPORT_RE.exec(content)) !== null) {\n const name = m[1]\n if (name && isPascalCase(name)) {\n names.add(name)\n }\n }\n\n // Named imports: `import { Button, useHook } from '...'`\n NAMED_IMPORT_RE.lastIndex = 0\n while ((m = NAMED_IMPORT_RE.exec(content)) !== null) {\n // Default part before destructuring\n const defaultName = m[1]\n if (defaultName && isPascalCase(defaultName)) {\n names.add(defaultName)\n }\n // Destructured names\n const namedPart = m[2]\n if (namedPart) {\n for (const segment of namedPart.split(',')) {\n // Handle `Foo as Bar` — take the local name (Bar)\n const parts = segment.trim().split(/\\s+as\\s+/)\n const localName = (parts[1] ?? parts[0])?.trim()\n if (localName && isPascalCase(localName)) {\n names.add(localName)\n }\n }\n }\n }\n\n return [...names]\n}\n\n// ---------------------------------------------------------------------------\n// String counting (estimate)\n// ---------------------------------------------------------------------------\n\nconst STRING_SINGLE_RE = /'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'/g\nconst STRING_DOUBLE_RE = /\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"/g\nconst STRING_TEMPLATE_RE = /`[^`\\\\]*(?:\\\\.[^`\\\\]*)*`/g\n\nfunction countStrings(content: string): number {\n // Strip import/export/require lines first so their string literals don't count\n const stripped = content.replace(/^(?:import|export)\\s+.*$/gm, '')\n .replace(/\\brequire\\s*\\([^)]*\\)/g, '')\n\n const singles = stripped.match(STRING_SINGLE_RE)?.length ?? 0\n const doubles = stripped.match(STRING_DOUBLE_RE)?.length ?? 0\n const templates = stripped.match(STRING_TEMPLATE_RE)?.length ?? 0\n\n return singles + doubles + templates\n}\n\n// ---------------------------------------------------------------------------\n// Import path resolution\n// ---------------------------------------------------------------------------\n\nconst RESOLVE_EXTENSIONS = [...SCAN_EXTENSIONS]\nconst RESOLVE_INDEX_FILES = ['index.ts', 'index.tsx', 'index.js']\n\nasync function resolveImportPath(\n importPath: string,\n importerDir: string,\n projectRoot: string,\n): Promise<string | null> {\n const base = importPath.startsWith('/')\n ? join(projectRoot, importPath)\n : join(importerDir, importPath)\n\n // If it already has an extension, check directly\n if (extname(base)) {\n if (await pathExists(base)) {\n return base\n }\n return null\n }\n\n // Try adding extensions\n for (const ext of RESOLVE_EXTENSIONS) {\n const candidate = base + ext\n if (await pathExists(candidate)) {\n return candidate\n }\n }\n\n // Try index files inside directory\n for (const idx of RESOLVE_INDEX_FILES) {\n const candidate = join(base, idx)\n if (await pathExists(candidate)) {\n return candidate\n }\n }\n\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Main\n// ---------------------------------------------------------------------------\n\ninterface FileInfo {\n relPath: string\n imports: string[]\n components: string[]\n strings: number\n category: FileCategory\n}\n\nexport async function buildGraph(\n projectRoot: string,\n options?: BuildGraphOptions,\n): Promise<ProjectGraph> {\n const scanDirs = options?.paths ?? await autoDetectSourceDirs(projectRoot)\n\n // ---- File discovery (shared with scanner) ----\n const filePaths = await discoverFiles(projectRoot, {\n paths: scanDirs,\n include: options?.include,\n exclude: options?.exclude,\n })\n\n // ---- Pass 1: Parse each file ----\n const fileMap = new Map<string, FileInfo>()\n\n const parsePromises = filePaths.map(async (relPath) => {\n const absPath = join(projectRoot, relPath)\n const content = await readText(absPath)\n if (content === null) return\n\n const imports = extractImportPaths(content)\n const components = extractComponentNames(content)\n const strings = countStrings(content)\n const category = classifyFile(relPath)\n\n fileMap.set(relPath, { relPath, imports, components, strings, category })\n })\n\n await Promise.all(parsePromises)\n\n // ---- Pass 2: Resolve imports and build reverse lookup ----\n const usedByMap = new Map<string, Set<string>>()\n\n // Initialize usedBy sets\n for (const relPath of fileMap.keys()) {\n usedByMap.set(relPath, new Set())\n }\n\n const resolvePromises: Promise<void>[] = []\n\n for (const [relPath, info] of fileMap) {\n const importerAbsDir = dirname(join(projectRoot, relPath))\n\n for (const rawImport of info.imports) {\n resolvePromises.push(\n resolveImportPath(rawImport, importerAbsDir, projectRoot).then((resolved) => {\n if (!resolved) return\n const resolvedRel = relative(projectRoot, resolved)\n const targetSet = usedByMap.get(resolvedRel)\n if (targetSet) {\n targetSet.add(relPath)\n }\n }),\n )\n }\n }\n\n await Promise.all(resolvePromises)\n\n // ---- Build nodes ----\n const pages: GraphNode[] = []\n const components: GraphNode[] = []\n const layouts: GraphNode[] = []\n const orphanCandidates: string[] = []\n\n let totalStrings = 0\n\n for (const [relPath, info] of fileMap) {\n const usedBy = [...(usedByMap.get(relPath) ?? [])].toSorted((a, b) => a.localeCompare(b))\n totalStrings += info.strings\n\n // Filter out nodes with 0 strings — not relevant for content extraction\n if (info.strings === 0 && info.category !== 'other') continue\n\n const node: GraphNode = {\n file: relPath,\n category: info.category,\n imports: info.imports,\n used_by: usedBy,\n strings: info.strings,\n }\n\n // Only attach components list for pages\n if (info.category === 'page' && info.components.length > 0) {\n node.components = info.components\n }\n\n switch (info.category) {\n case 'page':\n pages.push(node)\n break\n case 'component':\n components.push(node)\n break\n case 'layout':\n layouts.push(node)\n break\n default:\n // Orphan = \"other\" category with no inbound references and no outbound imports\n if (usedBy.length === 0 && info.imports.length === 0) {\n orphanCandidates.push(relPath)\n }\n break\n }\n }\n\n return {\n pages: pages.toSorted((a, b) => a.file.localeCompare(b.file)),\n components: components.toSorted((a, b) => a.file.localeCompare(b.file)),\n layouts: layouts.toSorted((a, b) => a.file.localeCompare(b.file)),\n orphan_files: orphanCandidates.toSorted((a, b) => a.localeCompare(b)).slice(0, MAX_ORPHANS),\n stats: {\n total_files: fileMap.size,\n total_components: components.length,\n total_pages: pages.length,\n total_strings_estimate: totalStrings,\n },\n }\n}\n"],"mappings":";;;;AAgBA,MAAM,cAAc;AAMpB,MAAM,YAAY;AAElB,SAAS,mBAAmB,SAA2B;CACrD,MAAM,QAAkB,EAAE;CAC1B,IAAI;AAEJ,WAAU,YAAY;AACtB,SAAQ,IAAI,UAAU,KAAK,QAAQ,MAAM,MAAM;EAC7C,MAAM,IAAI,EAAE,MAAM,EAAE;AACpB,MAAI,KAAK,cAAc,EAAE,CACvB,OAAM,K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E,KAAK,cAAc,EAAE,KAAK,CAAC;EACvE,SAAS,QAAQ,UAAU,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,KAAK,CAAC;EACjE,cAAc,iBAAiB,UAAU,GAAG,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC,MAAM,GAAG,YAAY;EAC3F,OAAO;GACL,aAAa,QAAQ;GACrB,kBAAkB,WAAW;GAC7B,aAAa,MAAM;GACnB,wBAAwB;GACzB;EACF"}
|
|
1
|
+
{"version":3,"file":"graph-builder-BEocwW13.mjs","names":[],"sources":["../src/core/graph-builder.ts"],"sourcesContent":["import type { FileCategory, GraphNode, ProjectGraph } from '@contentrain/types'\nimport { join, relative, dirname, extname } from 'node:path'\nimport { readText, pathExists } from '../util/fs.js'\nimport {\n SCAN_EXTENSIONS,\n classifyFile,\n autoDetectSourceDirs,\n discoverFiles,\n} from './scan-config.js'\n\nexport interface BuildGraphOptions {\n paths?: string[]\n include?: string[]\n exclude?: string[]\n}\n\nconst MAX_ORPHANS = 10\n\n// ---------------------------------------------------------------------------\n// Import extraction\n// ---------------------------------------------------------------------------\n\nconst IMPORT_RE = /(?:import|export)\\s+.*?from\\s+['\"]([^'\"]+)['\"]|(?:import|require)\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)/g\n\nfunction extractImportPaths(content: string): string[] {\n const paths: string[] = []\n let m: RegExpExecArray | null\n // Reset lastIndex before use since we reuse the regex\n IMPORT_RE.lastIndex = 0\n while ((m = IMPORT_RE.exec(content)) !== null) {\n const p = m[1] ?? m[2]\n if (p && isLocalImport(p)) {\n paths.push(p)\n }\n }\n return paths\n}\n\nfunction isLocalImport(p: string): boolean {\n return p.startsWith('.') || p.startsWith('/')\n}\n\n// ---------------------------------------------------------------------------\n// Component name extraction from imports\n// ---------------------------------------------------------------------------\n\nconst NAMED_IMPORT_RE = /import\\s+(?:type\\s+)?(?:(\\w+)(?:\\s*,\\s*)?)?(?:\\{([^}]*)\\})?\\s+from\\s+['\"][^'\"]+['\"]/g\nconst DEFAULT_IMPORT_RE = /import\\s+(?:type\\s+)?(\\w+)\\s+from\\s+['\"][^'\"]+['\"]/g\n\nfunction isPascalCase(name: string): boolean {\n return /^[A-Z][a-zA-Z0-9]*$/.test(name)\n}\n\nfunction extractComponentNames(content: string): string[] {\n const names = new Set<string>()\n\n // Default imports: `import Button from '...'`\n DEFAULT_IMPORT_RE.lastIndex = 0\n let m: RegExpExecArray | null\n while ((m = DEFAULT_IMPORT_RE.exec(content)) !== null) {\n const name = m[1]\n if (name && isPascalCase(name)) {\n names.add(name)\n }\n }\n\n // Named imports: `import { Button, useHook } from '...'`\n NAMED_IMPORT_RE.lastIndex = 0\n while ((m = NAMED_IMPORT_RE.exec(content)) !== null) {\n // Default part before destructuring\n const defaultName = m[1]\n if (defaultName && isPascalCase(defaultName)) {\n names.add(defaultName)\n }\n // Destructured names\n const namedPart = m[2]\n if (namedPart) {\n for (const segment of namedPart.split(',')) {\n // Handle `Foo as Bar` — take the local name (Bar)\n const parts = segment.trim().split(/\\s+as\\s+/)\n const localName = (parts[1] ?? parts[0])?.trim()\n if (localName && isPascalCase(localName)) {\n names.add(localName)\n }\n }\n }\n }\n\n return [...names]\n}\n\n// ---------------------------------------------------------------------------\n// String counting (estimate)\n// ---------------------------------------------------------------------------\n\nconst STRING_SINGLE_RE = /'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'/g\nconst STRING_DOUBLE_RE = /\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"/g\nconst STRING_TEMPLATE_RE = /`[^`\\\\]*(?:\\\\.[^`\\\\]*)*`/g\n\nfunction countStrings(content: string): number {\n // Strip import/export/require lines first so their string literals don't count\n const stripped = content.replace(/^(?:import|export)\\s+.*$/gm, '')\n .replace(/\\brequire\\s*\\([^)]*\\)/g, '')\n\n const singles = stripped.match(STRING_SINGLE_RE)?.length ?? 0\n const doubles = stripped.match(STRING_DOUBLE_RE)?.length ?? 0\n const templates = stripped.match(STRING_TEMPLATE_RE)?.length ?? 0\n\n return singles + doubles + templates\n}\n\n// ---------------------------------------------------------------------------\n// Import path resolution\n// ---------------------------------------------------------------------------\n\nconst RESOLVE_EXTENSIONS = [...SCAN_EXTENSIONS]\nconst RESOLVE_INDEX_FILES = ['index.ts', 'index.tsx', 'index.js']\n\nasync function resolveImportPath(\n importPath: string,\n importerDir: string,\n projectRoot: string,\n): Promise<string | null> {\n const base = importPath.startsWith('/')\n ? join(projectRoot, importPath)\n : join(importerDir, importPath)\n\n // If it already has an extension, check directly\n if (extname(base)) {\n if (await pathExists(base)) {\n return base\n }\n return null\n }\n\n // Try adding extensions\n for (const ext of RESOLVE_EXTENSIONS) {\n const candidate = base + ext\n if (await pathExists(candidate)) {\n return candidate\n }\n }\n\n // Try index files inside directory\n for (const idx of RESOLVE_INDEX_FILES) {\n const candidate = join(base, idx)\n if (await pathExists(candidate)) {\n return candidate\n }\n }\n\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Main\n// ---------------------------------------------------------------------------\n\ninterface FileInfo {\n relPath: string\n imports: string[]\n components: string[]\n strings: number\n category: FileCategory\n}\n\nexport async function buildGraph(\n projectRoot: string,\n options?: BuildGraphOptions,\n): Promise<ProjectGraph> {\n const scanDirs = options?.paths ?? await autoDetectSourceDirs(projectRoot)\n\n // ---- File discovery (shared with scanner) ----\n const filePaths = await discoverFiles(projectRoot, {\n paths: scanDirs,\n include: options?.include,\n exclude: options?.exclude,\n })\n\n // ---- Pass 1: Parse each file ----\n const fileMap = new Map<string, FileInfo>()\n\n const parsePromises = filePaths.map(async (relPath) => {\n const absPath = join(projectRoot, relPath)\n const content = await readText(absPath)\n if (content === null) return\n\n const imports = extractImportPaths(content)\n const components = extractComponentNames(content)\n const strings = countStrings(content)\n const category = classifyFile(relPath)\n\n fileMap.set(relPath, { relPath, imports, components, strings, category })\n })\n\n await Promise.all(parsePromises)\n\n // ---- Pass 2: Resolve imports and build reverse lookup ----\n const usedByMap = new Map<string, Set<string>>()\n\n // Initialize usedBy sets\n for (const relPath of fileMap.keys()) {\n usedByMap.set(relPath, new Set())\n }\n\n const resolvePromises: Promise<void>[] = []\n\n for (const [relPath, info] of fileMap) {\n const importerAbsDir = dirname(join(projectRoot, relPath))\n\n for (const rawImport of info.imports) {\n resolvePromises.push(\n resolveImportPath(rawImport, importerAbsDir, projectRoot).then((resolved) => {\n if (!resolved) return\n const resolvedRel = relative(projectRoot, resolved)\n const targetSet = usedByMap.get(resolvedRel)\n if (targetSet) {\n targetSet.add(relPath)\n }\n }),\n )\n }\n }\n\n await Promise.all(resolvePromises)\n\n // ---- Build nodes ----\n const pages: GraphNode[] = []\n const components: GraphNode[] = []\n const layouts: GraphNode[] = []\n const orphanCandidates: string[] = []\n\n let totalStrings = 0\n\n for (const [relPath, info] of fileMap) {\n const usedBy = [...(usedByMap.get(relPath) ?? [])].toSorted((a, b) => a.localeCompare(b))\n totalStrings += info.strings\n\n // Filter out nodes with 0 strings — not relevant for content extraction\n if (info.strings === 0 && info.category !== 'other') continue\n\n const node: GraphNode = {\n file: relPath,\n category: info.category,\n imports: info.imports,\n used_by: usedBy,\n strings: info.strings,\n }\n\n // Only attach components list for pages\n if (info.category === 'page' && info.components.length > 0) {\n node.components = info.components\n }\n\n switch (info.category) {\n case 'page':\n pages.push(node)\n break\n case 'component':\n components.push(node)\n break\n case 'layout':\n layouts.push(node)\n break\n default:\n // Orphan = \"other\" category with no inbound references and no outbound imports\n if (usedBy.length === 0 && info.imports.length === 0) {\n orphanCandidates.push(relPath)\n }\n break\n }\n }\n\n return {\n pages: pages.toSorted((a, b) => a.file.localeCompare(b.file)),\n components: components.toSorted((a, b) => a.file.localeCompare(b.file)),\n layouts: layouts.toSorted((a, b) => a.file.localeCompare(b.file)),\n orphan_files: orphanCandidates.toSorted((a, b) => a.localeCompare(b)).slice(0, MAX_ORPHANS),\n stats: {\n total_files: fileMap.size,\n total_components: components.length,\n total_pages: pages.length,\n total_strings_estimate: totalStrings,\n },\n }\n}\n"],"mappings":";;;;AAgBA,MA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AACH,YAAQ,KAAK,KAAK;AAClB;GACF;AAEE,QAAI,OAAO,WAAW,KAAK,KAAK,QAAQ,WAAW,EACjD,kBAAiB,KAAK,QAAQ;AAEhC;;;AAIN,QAAO;EACL,OAAO,MAAM,UAAU,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,KAAK,CAAC;EAC7D,YAAY,WAAW,UAAU,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,KAAK,CAAC;EACvE,SAAS,QAAQ,UAAU,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,KAAK,CAAC;EACjE,cAAc,iBAAiB,UAAU,GAAG,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC,MAAM,GAAG,YAAY;EAC3F,OAAO;GACL,aAAa,QAAQ;GACrB,kBAAkB,WAAW;GAC7B,aAAa,MAAM;GACnB,wBAAwB;GACzB;EACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-
|
|
1
|
+
{"version":3,"file":"id-BjhaIxTL.mjs","names":[],"sources":["../src/util/id.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto'\n\nexport function branchTimestamp(): string {\n const ts = Math.floor(Date.now() / 1000).toString()\n const suffix = randomUUID().slice(0, 4)\n return `${ts}-${suffix}`\n}\n\n// generateEntryId is now exported from @contentrain/types\nexport { generateEntryId } from '@contentrain/types'\n"],"mappings":";;;AAEA,SAAgB,kBAA0B;AAGxC,QAAO,GAFI,KAAK,MAAM,KAAK,KAAK,GAAG,IAAK,CAAC,UAAU,CAEtC,GADE,YAAY,CAAC,MAAM,GAAG,EAAE"}
|