@fragments-sdk/cli 0.10.0 → 0.10.1
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/dist/bin.js +8 -8
- package/dist/{chunk-ZDA3PLQ6.js → chunk-5G3VZH43.js} +2 -2
- package/dist/{chunk-566BNPQZ.js → chunk-HRFUSSZI.js} +25 -6
- package/dist/chunk-HRFUSSZI.js.map +1 -0
- package/dist/{chunk-CAMXG5HJ.js → chunk-ZM4ZQZWZ.js} +2 -2
- package/dist/{generate-BGKTKO6E.js → generate-FBHSXR3D.js} +2 -2
- package/dist/index.js +2 -2
- package/dist/{init-Q53R5Q2T.js → init-NDQXUWDU.js} +3 -3
- package/dist/{scan-OQU7M4GH.js → scan-CJF2DOQW.js} +3 -3
- package/dist/{scan-generate-T5QNUG7N.js → scan-generate-SJAN5MVI.js} +2 -2
- package/dist/{test-2CSOSS3B.js → test-Z5LVO724.js} +2 -2
- package/dist/{tokens-DXEGYTOJ.js → tokens-CE46OTMD.js} +2 -2
- package/dist/{viewer-DBEPYM3G.js → viewer-DNMNC5VS.js} +2 -2
- package/package.json +1 -1
- package/src/core/loader.ts +38 -8
- package/src/viewer/assets/fragments_logo.png +0 -0
- package/src/viewer/vendor/shared/src/VariantPreviewCard.tsx +4 -1
- package/dist/chunk-566BNPQZ.js.map +0 -1
- /package/dist/{chunk-ZDA3PLQ6.js.map → chunk-5G3VZH43.js.map} +0 -0
- /package/dist/{chunk-CAMXG5HJ.js.map → chunk-ZM4ZQZWZ.js.map} +0 -0
- /package/dist/{generate-BGKTKO6E.js.map → generate-FBHSXR3D.js.map} +0 -0
- /package/dist/{init-Q53R5Q2T.js.map → init-NDQXUWDU.js.map} +0 -0
- /package/dist/{scan-OQU7M4GH.js.map → scan-CJF2DOQW.js.map} +0 -0
- /package/dist/{scan-generate-T5QNUG7N.js.map → scan-generate-SJAN5MVI.js.map} +0 -0
- /package/dist/{test-2CSOSS3B.js.map → test-Z5LVO724.js.map} +0 -0
- /package/dist/{tokens-DXEGYTOJ.js.map → tokens-CE46OTMD.js.map} +0 -0
- /package/dist/{viewer-DBEPYM3G.js.map → viewer-DNMNC5VS.js.map} +0 -0
package/dist/bin.js
CHANGED
|
@@ -12,14 +12,14 @@ import {
|
|
|
12
12
|
validateCoverage,
|
|
13
13
|
validateSchema,
|
|
14
14
|
validateSnippets
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-5G3VZH43.js";
|
|
16
16
|
import {
|
|
17
17
|
scan
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-ZM4ZQZWZ.js";
|
|
19
19
|
import {
|
|
20
20
|
loadConfig,
|
|
21
21
|
loadFragmentFile
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-HRFUSSZI.js";
|
|
23
23
|
import {
|
|
24
24
|
discoverFragmentFiles
|
|
25
25
|
} from "./chunk-WXSR2II7.js";
|
|
@@ -1858,7 +1858,7 @@ ${BRAND.name} Dev Server
|
|
|
1858
1858
|
}
|
|
1859
1859
|
}
|
|
1860
1860
|
}
|
|
1861
|
-
const { createDevServer } = await import("./viewer-
|
|
1861
|
+
const { createDevServer } = await import("./viewer-DNMNC5VS.js");
|
|
1862
1862
|
console.log(pc7.dim("\nStarting dev server..."));
|
|
1863
1863
|
const parsedPort = typeof port === "string" ? parseInt(port, 10) : port;
|
|
1864
1864
|
try {
|
|
@@ -6573,7 +6573,7 @@ program.command("setup").description("Configure @fragments-sdk/ui in a consumer
|
|
|
6573
6573
|
});
|
|
6574
6574
|
program.command("init").description("Initialize fragments in a project (interactive by default)").option("--force", "Overwrite existing config").option("-y, --yes", "Non-interactive mode - auto-detect and use defaults").option("--scan <path>", "Scan a TypeScript component directory and generate fragment files").action(async (options) => {
|
|
6575
6575
|
try {
|
|
6576
|
-
const { init } = await import("./init-
|
|
6576
|
+
const { init } = await import("./init-NDQXUWDU.js");
|
|
6577
6577
|
const result = await init({
|
|
6578
6578
|
projectRoot: process.cwd(),
|
|
6579
6579
|
force: options.force,
|
|
@@ -6594,7 +6594,7 @@ program.command("init").description("Initialize fragments in a project (interact
|
|
|
6594
6594
|
});
|
|
6595
6595
|
program.command("tokens").description("Discover and list design tokens from CSS/SCSS files").option("-c, --config <path>", "Path to config file").option("--json", "Output as JSON").option("--categories", "Group tokens by category").option("--theme <theme>", "Filter by theme name").option("--category <category>", "Filter by category (color, spacing, typography, etc.)").option("--verbose", "Show all tokens (no truncation)").action(async (options) => {
|
|
6596
6596
|
try {
|
|
6597
|
-
const { tokens } = await import("./tokens-
|
|
6597
|
+
const { tokens } = await import("./tokens-CE46OTMD.js");
|
|
6598
6598
|
const result = await tokens({
|
|
6599
6599
|
config: options.config,
|
|
6600
6600
|
json: options.json,
|
|
@@ -6613,7 +6613,7 @@ program.command("tokens").description("Discover and list design tokens from CSS/
|
|
|
6613
6613
|
});
|
|
6614
6614
|
program.command("generate").description("Generate fragment files from component source code").argument("[component]", "Specific component name to generate (optional)").option("--force", "Overwrite existing fragment files").option("--pattern <glob>", "Pattern for component files", "src/components/**/*.tsx").action(async (component, options) => {
|
|
6615
6615
|
try {
|
|
6616
|
-
const { generate } = await import("./generate-
|
|
6616
|
+
const { generate } = await import("./generate-FBHSXR3D.js");
|
|
6617
6617
|
const result = await generate({
|
|
6618
6618
|
projectRoot: process.cwd(),
|
|
6619
6619
|
component,
|
|
@@ -6658,7 +6658,7 @@ program.command("perf").description("Profile component bundle sizes and performa
|
|
|
6658
6658
|
program.command("test").description("Run interaction tests for fragments with play functions").option("-c, --config <path>", "Path to config file").option("--component <name>", "Filter by component name").option("--tags <tags>", "Filter by tags (comma-separated)").option("--grep <pattern>", "Filter by variant name pattern").option("--exclude <pattern>", "Exclude tests matching pattern").option("--parallel <count>", "Number of parallel browser contexts", parseInt, 4).option("--timeout <ms>", "Timeout per test in milliseconds", parseInt, 3e4).option("--retries <count>", "Number of retries for failed tests", parseInt, 0).option("--bail", "Stop on first failure").option("--browser <name>", "Browser to use (chromium, firefox, webkit)", "chromium").option("--headed", "Run in headed mode (show browser)").option("--a11y", "Run accessibility checks with axe-core").option("--visual", "Capture screenshots for visual regression").option("--update-snapshots", "Update visual snapshots").option("--watch", "Watch mode - re-run on file changes").option("--reporters <names>", "Reporters to use (console, junit, json)", "console").option("-o, --output <dir>", "Output directory for results", "./test-results").option("--server-url <url>", "URL of running dev server (skips starting server)").option("-p, --port <port>", "Port for dev server", parseInt, 6006).option("--ci", "CI mode - non-interactive, exit with code 1 on failure").option("--list", "List available tests without running them").action(async (options) => {
|
|
6659
6659
|
try {
|
|
6660
6660
|
const { config, configDir } = await loadConfig(options.config);
|
|
6661
|
-
const { runTestCommand, listTests } = await import("./test-
|
|
6661
|
+
const { runTestCommand, listTests } = await import("./test-Z5LVO724.js");
|
|
6662
6662
|
if (options.list) {
|
|
6663
6663
|
await listTests(config, configDir, {
|
|
6664
6664
|
component: options.component,
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
generateRegistry,
|
|
5
5
|
loadFragmentFile,
|
|
6
6
|
parseFragmentFile
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-HRFUSSZI.js";
|
|
8
8
|
import {
|
|
9
9
|
discoverBlockFiles,
|
|
10
10
|
discoverComponentFiles,
|
|
@@ -2520,4 +2520,4 @@ export {
|
|
|
2520
2520
|
runDiffCommand,
|
|
2521
2521
|
runAnalyzeCommand
|
|
2522
2522
|
};
|
|
2523
|
-
//# sourceMappingURL=chunk-
|
|
2523
|
+
//# sourceMappingURL=chunk-5G3VZH43.js.map
|
|
@@ -835,23 +835,42 @@ function createFragmentsCoreShimPlugin() {
|
|
|
835
835
|
};
|
|
836
836
|
}
|
|
837
837
|
async function loadFragmentFile(absolutePath) {
|
|
838
|
+
const unwrapFragmentExport = (value) => {
|
|
839
|
+
if (!value) return null;
|
|
840
|
+
const asObject = (v) => v && typeof v === "object" ? v : null;
|
|
841
|
+
const isFragmentLike = (v) => {
|
|
842
|
+
const obj = asObject(v);
|
|
843
|
+
return !!obj && ("component" in obj || "meta" in obj || "variants" in obj);
|
|
844
|
+
};
|
|
845
|
+
if (isFragmentLike(value)) {
|
|
846
|
+
return value;
|
|
847
|
+
}
|
|
848
|
+
const first = asObject(value)?.default;
|
|
849
|
+
if (isFragmentLike(first)) {
|
|
850
|
+
return first;
|
|
851
|
+
}
|
|
852
|
+
const second = asObject(first)?.default;
|
|
853
|
+
if (isFragmentLike(second)) {
|
|
854
|
+
return second;
|
|
855
|
+
}
|
|
856
|
+
return value ?? null;
|
|
857
|
+
};
|
|
838
858
|
const ext = absolutePath.split(".").pop()?.toLowerCase();
|
|
839
859
|
const needsTransform = ext === "tsx" || ext === "ts" || ext === "jsx";
|
|
840
860
|
if (!needsTransform) {
|
|
841
861
|
const fileUrl = pathToFileURL(absolutePath).href;
|
|
842
862
|
const module = await import(fileUrl);
|
|
843
|
-
return module.default ?? null;
|
|
863
|
+
return unwrapFragmentExport(module.default ?? null);
|
|
844
864
|
}
|
|
845
865
|
const sourceDir = dirname3(absolutePath);
|
|
846
866
|
const baseName = basename2(absolutePath, `.${ext}`);
|
|
847
|
-
const tempFile = join2(sourceDir, `.${baseName}.fragments-temp-${Date.now()}.
|
|
867
|
+
const tempFile = join2(sourceDir, `.${baseName}.fragments-temp-${Date.now()}.mjs`);
|
|
848
868
|
try {
|
|
849
869
|
await build({
|
|
850
870
|
entryPoints: [absolutePath],
|
|
851
871
|
outfile: tempFile,
|
|
852
872
|
bundle: true,
|
|
853
|
-
format: "
|
|
854
|
-
// Use CommonJS to avoid ESM issues with lodash, etc.
|
|
873
|
+
format: "esm",
|
|
855
874
|
target: "es2022",
|
|
856
875
|
jsx: "automatic",
|
|
857
876
|
platform: "node",
|
|
@@ -887,7 +906,7 @@ async function loadFragmentFile(absolutePath) {
|
|
|
887
906
|
});
|
|
888
907
|
const fileUrl = pathToFileURL(tempFile).href;
|
|
889
908
|
const module = await import(fileUrl);
|
|
890
|
-
return module.default ?? null;
|
|
909
|
+
return unwrapFragmentExport(module.default ?? null);
|
|
891
910
|
} finally {
|
|
892
911
|
try {
|
|
893
912
|
await unlink(tempFile);
|
|
@@ -1390,4 +1409,4 @@ export {
|
|
|
1390
1409
|
generateRegistry,
|
|
1391
1410
|
generateContextMd
|
|
1392
1411
|
};
|
|
1393
|
-
//# sourceMappingURL=chunk-
|
|
1412
|
+
//# sourceMappingURL=chunk-HRFUSSZI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/config.ts","../src/core/generators/typescript-extractor.ts","../src/core/generators/registry.ts","../src/core/generators/context.ts","../src/core/loader.ts","../src/core/parser.ts","../src/core/previewLoader.ts","../src/core/importAnalyzer.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { resolve, dirname } from 'node:path';\nimport { createJiti } from 'jiti';\nimport { BRAND, fragmentsConfigSchema } from '@fragments-sdk/core';\nimport type { FragmentsConfig, StorybookFilterConfig } from '@fragments-sdk/core';\n\nconst STORYBOOK_FILTER_DEFAULTS: StorybookFilterConfig = {\n excludeDeprecated: true,\n excludeTests: true,\n excludeSvgIcons: true,\n excludeSubComponents: true,\n};\n\nconst DEFAULT_CONFIG: FragmentsConfig = {\n include: [\n `src/**/*${BRAND.fileExtension}`, // *.fragment.tsx files\n 'src/**/*.stories.tsx', // Storybook stories (auto-converted)\n ],\n exclude: ['**/node_modules/**'],\n components: ['src/**/index.tsx', 'src/**/*.tsx'],\n framework: 'react',\n storybook: STORYBOOK_FILTER_DEFAULTS,\n snippets: {\n mode: 'warn',\n scope: 'snippet+render',\n requireFullSnippet: true,\n allowedExternalModules: ['@phosphor-icons/react', 'recharts', 'react-day-picker'],\n },\n};\n\n/**\n * Find the config file in the current directory or parent directories.\n * Checks for both the current config file name and the legacy name.\n */\nexport function findConfigFile(startDir: string = process.cwd()): string | null {\n let currentDir = startDir;\n\n while (currentDir !== dirname(currentDir)) {\n // Check for current config file name first\n const configPath = resolve(currentDir, BRAND.configFile);\n if (existsSync(configPath)) {\n return configPath;\n }\n // Also check for legacy config file name\n const legacyConfigPath = resolve(currentDir, BRAND.legacyConfigFile);\n if (existsSync(legacyConfigPath)) {\n return legacyConfigPath;\n }\n currentDir = dirname(currentDir);\n }\n\n return null;\n}\n\n/**\n * Load and validate the config file\n */\nexport async function loadConfig(configPath?: string): Promise<{\n config: FragmentsConfig;\n configDir: string;\n}> {\n const resolvedPath = configPath ?? findConfigFile();\n\n if (!resolvedPath) {\n return {\n config: DEFAULT_CONFIG,\n configDir: process.cwd(),\n };\n }\n\n try {\n // Use jiti to load TypeScript config files\n const jiti = createJiti(import.meta.url, {\n interopDefault: true,\n });\n const rawConfig = await jiti.import(resolvedPath);\n\n const result = fragmentsConfigSchema.safeParse(rawConfig);\n\n if (!result.success) {\n const errors = result.error.errors\n .map((e) => ` - ${e.path.join('.')}: ${e.message}`)\n .join('\\n');\n throw new Error(`Invalid config in ${resolvedPath}:\\n${errors}`);\n }\n\n const merged: FragmentsConfig = { ...DEFAULT_CONFIG, ...result.data };\n\n // Deep-merge storybook filter defaults so consumers only override what they need\n merged.storybook = { ...STORYBOOK_FILTER_DEFAULTS, ...result.data?.storybook };\n\n return {\n config: merged,\n configDir: dirname(resolvedPath),\n };\n } catch (error) {\n if (error instanceof Error && error.message.includes('Invalid config')) {\n throw error;\n }\n throw new Error(`Failed to load config from ${resolvedPath}: ${error}`);\n }\n}\n","/**\n * TypeScript Props Extractor\n * Extracts prop types, default values, and JSDoc comments from React component files\n */\n\nimport ts from \"typescript\";\nimport { readFileSync } from \"node:fs\";\nimport type { RegistryPropEntry } from '@fragments-sdk/core';\n\n/**\n * Result of extracting props from a component file\n */\nexport interface ExtractedProps {\n /** Component name */\n componentName: string;\n /** Whether the component uses export default */\n isDefaultExport?: boolean;\n /** Props interface name (e.g., \"ButtonProps\") */\n propsInterfaceName?: string;\n /** Extracted props */\n props: Record<string, RegistryPropEntry>;\n /** Named exports from the file */\n exports: string[];\n /** Import statements (for dependency tracking) */\n imports: string[];\n}\n\n/**\n * Extract props from a TypeScript/TSX component file\n */\nexport function extractPropsFromFile(filePath: string): ExtractedProps | null {\n const sourceText = readFileSync(filePath, \"utf-8\");\n return extractPropsFromSource(sourceText, filePath);\n}\n\n/**\n * Extract props from TypeScript source code\n */\nexport function extractPropsFromSource(\n sourceText: string,\n fileName = \"component.tsx\"\n): ExtractedProps | null {\n const sourceFile = ts.createSourceFile(\n fileName,\n sourceText,\n ts.ScriptTarget.Latest,\n true,\n fileName.endsWith(\".tsx\") ? ts.ScriptKind.TSX : ts.ScriptKind.TS\n );\n\n const result: ExtractedProps = {\n componentName: \"\",\n props: {},\n exports: [],\n imports: [],\n };\n\n // Find all exports and props interfaces\n const propsInterfaces = new Map<string, ts.InterfaceDeclaration | ts.TypeAliasDeclaration>();\n const componentExports: string[] = [];\n const defaultExports = new Set<string>();\n const importedModules: string[] = [];\n\n ts.forEachChild(sourceFile, (node) => {\n // Track imports\n if (ts.isImportDeclaration(node)) {\n const moduleSpecifier = node.moduleSpecifier;\n if (ts.isStringLiteral(moduleSpecifier)) {\n importedModules.push(moduleSpecifier.text);\n }\n }\n\n // Find interface declarations (e.g., interface ButtonProps { ... })\n if (ts.isInterfaceDeclaration(node)) {\n const name = node.name.text;\n if (name.endsWith(\"Props\")) {\n propsInterfaces.set(name, node);\n }\n }\n\n // Find type alias declarations (e.g., type ButtonProps = { ... })\n if (ts.isTypeAliasDeclaration(node)) {\n const name = node.name.text;\n if (name.endsWith(\"Props\")) {\n propsInterfaces.set(name, node);\n }\n }\n\n // Find exported functions/components\n if (ts.isFunctionDeclaration(node) && node.name) {\n const hasExport = node.modifiers?.some(\n (m) => m.kind === ts.SyntaxKind.ExportKeyword\n );\n const hasDefault = node.modifiers?.some(\n (m) => m.kind === ts.SyntaxKind.DefaultKeyword\n );\n if (hasExport) {\n componentExports.push(node.name.text);\n if (hasDefault) {\n defaultExports.add(node.name.text);\n }\n }\n }\n\n // Find exported variable declarations (e.g., export const Button = ...)\n if (ts.isVariableStatement(node)) {\n const hasExport = node.modifiers?.some(\n (m) => m.kind === ts.SyntaxKind.ExportKeyword\n );\n if (hasExport) {\n for (const decl of node.declarationList.declarations) {\n if (ts.isIdentifier(decl.name)) {\n componentExports.push(decl.name.text);\n }\n }\n }\n }\n\n // Find export declarations (e.g., export { Button })\n if (ts.isExportDeclaration(node) && node.exportClause) {\n if (ts.isNamedExports(node.exportClause)) {\n for (const element of node.exportClause.elements) {\n componentExports.push(element.name.text);\n }\n }\n }\n });\n\n result.exports = componentExports;\n result.imports = importedModules;\n\n // Find the main component (first PascalCase export)\n const mainComponent = componentExports.find(\n (name) => /^[A-Z]/.test(name) && !name.endsWith(\"Props\")\n );\n\n if (!mainComponent) {\n return null;\n }\n\n result.componentName = mainComponent;\n result.isDefaultExport = defaultExports.has(mainComponent);\n\n // Find matching props interface\n const propsInterfaceName = `${mainComponent}Props`;\n const propsInterface = propsInterfaces.get(propsInterfaceName);\n\n if (propsInterface) {\n result.propsInterfaceName = propsInterfaceName;\n result.props = extractPropsFromInterface(propsInterface, sourceFile);\n }\n\n return result;\n}\n\n/**\n * Extract props from an interface or type alias declaration\n */\nfunction extractPropsFromInterface(\n node: ts.InterfaceDeclaration | ts.TypeAliasDeclaration,\n sourceFile: ts.SourceFile\n): Record<string, RegistryPropEntry> {\n const props: Record<string, RegistryPropEntry> = {};\n\n // Handle interface declaration\n if (ts.isInterfaceDeclaration(node)) {\n for (const member of node.members) {\n if (ts.isPropertySignature(member) && member.name) {\n const propName = member.name.getText(sourceFile);\n const prop = extractPropFromMember(member, sourceFile);\n if (prop) {\n props[propName] = prop;\n }\n }\n }\n }\n\n // Handle type alias declaration\n if (ts.isTypeAliasDeclaration(node)) {\n const typeNode = node.type;\n if (ts.isTypeLiteralNode(typeNode)) {\n for (const member of typeNode.members) {\n if (ts.isPropertySignature(member) && member.name) {\n const propName = member.name.getText(sourceFile);\n const prop = extractPropFromMember(member, sourceFile);\n if (prop) {\n props[propName] = prop;\n }\n }\n }\n }\n }\n\n return props;\n}\n\n/**\n * Extract prop info from a property signature\n */\nfunction extractPropFromMember(\n member: ts.PropertySignature,\n sourceFile: ts.SourceFile\n): RegistryPropEntry | null {\n const entry: RegistryPropEntry = {};\n\n // Check if required\n entry.required = !member.questionToken;\n\n // Get type\n if (member.type) {\n const typeInfo = parseTypeNode(member.type, sourceFile);\n entry.type = typeInfo.type;\n entry.typeKind = typeInfo.typeKind;\n if (typeInfo.options) {\n entry.options = typeInfo.options;\n }\n }\n\n // Get JSDoc comment\n const jsDocComment = getJSDocComment(member);\n if (jsDocComment) {\n entry.description = jsDocComment;\n }\n\n // Get default value from JSDoc @default tag\n const defaultValue = getJSDocDefault(member);\n if (defaultValue !== undefined) {\n entry.default = defaultValue;\n }\n\n return entry;\n}\n\n/**\n * Parse a TypeScript type node into a simplified representation\n */\nfunction parseTypeNode(\n typeNode: ts.TypeNode,\n sourceFile: ts.SourceFile\n): { type: string; typeKind: RegistryPropEntry[\"typeKind\"]; options?: string[] } {\n // String\n if (typeNode.kind === ts.SyntaxKind.StringKeyword) {\n return { type: \"string\", typeKind: \"string\" };\n }\n\n // Number\n if (typeNode.kind === ts.SyntaxKind.NumberKeyword) {\n return { type: \"number\", typeKind: \"number\" };\n }\n\n // Boolean\n if (typeNode.kind === ts.SyntaxKind.BooleanKeyword) {\n return { type: \"boolean\", typeKind: \"boolean\" };\n }\n\n // Union type (string literal union for enums)\n if (ts.isUnionTypeNode(typeNode)) {\n const options: string[] = [];\n let allLiterals = true;\n\n for (const subType of typeNode.types) {\n if (ts.isLiteralTypeNode(subType)) {\n if (ts.isStringLiteral(subType.literal)) {\n options.push(subType.literal.text);\n } else if (subType.literal.kind === ts.SyntaxKind.TrueKeyword) {\n options.push(\"true\");\n } else if (subType.literal.kind === ts.SyntaxKind.FalseKeyword) {\n options.push(\"false\");\n } else {\n allLiterals = false;\n }\n } else {\n allLiterals = false;\n }\n }\n\n if (allLiterals && options.length > 0) {\n return {\n type: options.map((o) => `\"${o}\"`).join(\" | \"),\n typeKind: \"enum\",\n options,\n };\n }\n\n return {\n type: typeNode.getText(sourceFile),\n typeKind: \"union\",\n };\n }\n\n // Function type\n if (ts.isFunctionTypeNode(typeNode)) {\n return {\n type: typeNode.getText(sourceFile),\n typeKind: \"function\",\n };\n }\n\n // Array type\n if (ts.isArrayTypeNode(typeNode)) {\n return {\n type: typeNode.getText(sourceFile),\n typeKind: \"array\",\n };\n }\n\n // Type reference (e.g., ReactNode, React.ReactElement)\n if (ts.isTypeReferenceNode(typeNode)) {\n const typeName = typeNode.typeName.getText(sourceFile);\n\n // React types\n if (typeName === \"ReactNode\" || typeName === \"React.ReactNode\") {\n return { type: \"ReactNode\", typeKind: \"node\" };\n }\n if (typeName === \"ReactElement\" || typeName === \"React.ReactElement\") {\n return { type: \"ReactElement\", typeKind: \"element\" };\n }\n if (typeName === \"JSX.Element\") {\n return { type: \"JSX.Element\", typeKind: \"element\" };\n }\n\n return {\n type: typeNode.getText(sourceFile),\n typeKind: \"object\",\n };\n }\n\n // Object type literal\n if (ts.isTypeLiteralNode(typeNode)) {\n return {\n type: typeNode.getText(sourceFile),\n typeKind: \"object\",\n };\n }\n\n // Default: unknown\n return {\n type: typeNode.getText(sourceFile),\n typeKind: \"unknown\",\n };\n}\n\n/**\n * Get JSDoc comment from a node\n */\nfunction getJSDocComment(node: ts.Node): string | undefined {\n const jsDocTags = ts.getJSDocTags(node);\n const jsDoc = (node as unknown as { jsDoc?: ts.JSDoc[] }).jsDoc;\n\n if (jsDoc && jsDoc.length > 0) {\n const comment = jsDoc[0].comment;\n if (typeof comment === \"string\") {\n return comment;\n }\n if (Array.isArray(comment)) {\n return comment.map((c) => (typeof c === \"string\" ? c : c.text)).join(\"\");\n }\n }\n\n return undefined;\n}\n\n/**\n * Get @default value from JSDoc\n */\nfunction getJSDocDefault(node: ts.Node): unknown | undefined {\n const jsDocTags = ts.getJSDocTags(node);\n\n for (const tag of jsDocTags) {\n if (tag.tagName.text === \"default\") {\n const comment = tag.comment;\n if (typeof comment === \"string\") {\n // Try to parse as JSON\n try {\n return JSON.parse(comment);\n } catch {\n return comment;\n }\n }\n }\n }\n\n return undefined;\n}\n","/**\n * Registry Generator\n * Generates .fragments/registry.json and .fragments/index.json\n *\n * Philosophy: Generate only what AI agents and humans can't easily get from source.\n * - Props: AI can read TypeScript directly (skip by default)\n * - Paths: Essential for file navigation (always include)\n * - Enrichment: Human knowledge that doesn't exist elsewhere (include references)\n */\n\nimport { readFileSync, existsSync } from \"node:fs\";\nimport { relative, dirname, basename, join } from \"node:path\";\nimport fg from \"fast-glob\";\nimport { BRAND } from '@fragments-sdk/core';\nimport type {\n Fragment,\n FragmentRegistry,\n FragmentIndex,\n RegistryComponentEntry,\n RegistryOptions,\n} from '@fragments-sdk/core';\nimport { extractPropsFromFile } from \"./typescript-extractor.js\";\n\n/**\n * Options for registry generation\n */\nexport interface RegistryGeneratorOptions {\n /** Project root directory */\n projectRoot: string;\n /** Glob patterns for component files */\n componentPatterns?: string[];\n /** Glob patterns for story files */\n storyPatterns?: string[];\n /** Path to .fragments directory */\n fragmentsDir?: string;\n /** Registry options from config */\n registryOptions?: RegistryOptions;\n}\n\n/**\n * Result of registry generation\n */\nexport interface RegistryGeneratorResult {\n /** Generated registry (full metadata) */\n registry: FragmentRegistry;\n /** Generated index (minimal name -> path) */\n index: FragmentIndex;\n /** Errors encountered during generation */\n errors: Array<{ file: string; error: string }>;\n /** Warnings */\n warnings: Array<{ file: string; warning: string }>;\n}\n\n/**\n * Generate a fragment registry and index by scanning the project\n */\nexport async function generateRegistry(\n options: RegistryGeneratorOptions\n): Promise<RegistryGeneratorResult> {\n const {\n projectRoot,\n componentPatterns = [\"src/**/*.tsx\", \"src/**/*.ts\"],\n storyPatterns = [\"src/**/*.stories.tsx\", \"src/**/*.stories.ts\"],\n fragmentsDir = join(projectRoot, BRAND.dataDir),\n registryOptions = {},\n } = options;\n\n const {\n requireStory = false,\n publicOnly = false,\n categoryDepth = 1,\n includeProps = false,\n embedFragments = false,\n } = registryOptions;\n\n const errors: Array<{ file: string; error: string }> = [];\n const warnings: Array<{ file: string; warning: string }> = [];\n\n // Find all story files first (for requireStory filtering)\n const storyFiles = await fg(storyPatterns, {\n cwd: projectRoot,\n ignore: [\"**/node_modules/**\"],\n absolute: true,\n });\n\n // Build a map of story files by component directory and base name\n const storyMap = new Map<string, string>();\n for (const storyPath of storyFiles) {\n const storyDir = dirname(storyPath);\n const storyBase = basename(storyPath).replace(/\\.stories\\.(tsx?|jsx?)$/, \"\");\n storyMap.set(`${storyDir}/${storyBase}`, storyPath);\n }\n\n // Find all component files\n const componentFiles = await fg(componentPatterns, {\n cwd: projectRoot,\n ignore: [\n \"**/node_modules/**\",\n \"**/*.stories.*\",\n \"**/*.test.*\",\n \"**/*.spec.*\",\n \"**/*.d.ts\",\n ],\n absolute: true,\n });\n\n // Find all fragment files\n const fragmentPattern = join(\n BRAND.dataDir,\n BRAND.componentsDir,\n `*${BRAND.fileExtension}`\n );\n const fragmentFiles = await fg(fragmentPattern, {\n cwd: projectRoot,\n absolute: true,\n });\n\n // Build fragment lookup map\n const fragmentMap = new Map<string, { path: string; fragment: Fragment }>();\n for (const fragmentPath of fragmentFiles) {\n const fragmentName = basename(fragmentPath).replace(BRAND.fileExtension, \"\");\n try {\n const content = readFileSync(fragmentPath, \"utf-8\");\n const fragment = JSON.parse(content) as Fragment;\n fragmentMap.set(fragmentName, {\n path: relative(projectRoot, fragmentPath),\n fragment,\n });\n } catch (e) {\n errors.push({\n file: fragmentPath,\n error: `Failed to parse fragment: ${e instanceof Error ? e.message : String(e)}`,\n });\n }\n }\n\n // Build component index\n const components: Record<string, RegistryComponentEntry> = {};\n const indexComponents: Record<string, string> = {};\n const categories: Record<string, string[]> = {};\n\n // Process component files\n for (const filePath of componentFiles) {\n try {\n const extracted = extractPropsFromFile(filePath);\n if (!extracted || !extracted.componentName) {\n continue;\n }\n\n const componentName = extracted.componentName;\n const relativePath = relative(projectRoot, filePath);\n\n // Check if component is exported (for publicOnly filter)\n if (publicOnly && !extracted.exports.includes(componentName)) {\n continue;\n }\n\n // Find matching story file\n const componentDir = dirname(filePath);\n const baseNameWithoutExt = basename(filePath).replace(/\\.(tsx?|jsx?)$/, \"\");\n const storyPath = storyMap.get(`${componentDir}/${baseNameWithoutExt}`);\n\n // Apply requireStory filter\n if (requireStory && !storyPath) {\n continue;\n }\n\n // Get fragment data if exists\n const fragmentData = fragmentMap.get(componentName);\n\n // Determine category from directory structure\n const category = fragmentData?.fragment?.meta?.status\n ? undefined // Don't use status as category\n : getCategoryFromPath(relativePath, categoryDepth);\n\n // Check if fragment has meaningful enrichment (not just a skeleton)\n const hasEnrichment = fragmentData\n ? hasRealEnrichment(fragmentData.fragment)\n : false;\n\n // Build minimal component entry\n const entry: RegistryComponentEntry = {\n path: relativePath,\n };\n\n // Add optional fields only if present\n if (storyPath) {\n entry.storyPath = relative(projectRoot, storyPath);\n }\n\n if (fragmentData) {\n entry.fragmentPath = fragmentData.path;\n if (hasEnrichment) {\n entry.hasEnrichment = true;\n }\n if (fragmentData.fragment.description) {\n entry.description = fragmentData.fragment.description;\n }\n if (fragmentData.fragment.meta?.status) {\n entry.status = fragmentData.fragment.meta.status;\n }\n // Only embed full fragment if explicitly requested\n if (embedFragments) {\n entry.fragment = fragmentData.fragment;\n }\n }\n\n if (category) {\n entry.category = category;\n // Add to categories index\n if (!categories[category]) {\n categories[category] = [];\n }\n categories[category].push(componentName);\n }\n\n // Only include props if explicitly requested\n if (includeProps && extracted.props) {\n entry.props = extracted.props;\n }\n\n // Only include exports if multiple exports\n if (extracted.exports.length > 1) {\n entry.exports = extracted.exports;\n }\n\n components[componentName] = entry;\n indexComponents[componentName] = relativePath;\n } catch (e) {\n errors.push({\n file: filePath,\n error: `Failed to extract component: ${e instanceof Error ? e.message : String(e)}`,\n });\n }\n }\n\n const componentCount = Object.keys(components).length;\n\n // Build registry\n const registry: FragmentRegistry = {\n $schema: \"https://fragments.dev/schema/registry-v1.json\",\n version: \"1.0\",\n generatedAt: new Date().toISOString(),\n componentCount,\n components,\n categories,\n };\n\n // Build minimal index\n const index: FragmentIndex = {\n version: \"1.0\",\n generatedAt: registry.generatedAt,\n components: indexComponents,\n categories,\n };\n\n return { registry, index, errors, warnings };\n}\n\n/**\n * Get category from file path based on directory structure\n *\n * Examples:\n * - src/components/buttons/Button.tsx -> \"buttons\"\n * - src/components/forms/inputs/TextInput.tsx -> \"forms\" (depth 1) or \"forms/inputs\" (depth 2)\n * - src/components/Button/Button.tsx -> \"Button\" (component folder)\n */\nfunction getCategoryFromPath(relativePath: string, depth: number = 1): string | undefined {\n const parts = relativePath.split(\"/\");\n const componentsIndex = parts.findIndex((p) => p === \"components\");\n\n if (componentsIndex === -1) {\n return undefined;\n }\n\n // Get the parts after \"components/\"\n const afterComponents = parts.slice(componentsIndex + 1);\n\n // If it's just components/Button.tsx, no category\n if (afterComponents.length <= 1) {\n return undefined;\n }\n\n // If it's components/Button/Button.tsx (component folder pattern), no category\n const folderName = afterComponents[0];\n const fileName = afterComponents[afterComponents.length - 1].replace(/\\.(tsx?|jsx?)$/, \"\");\n if (afterComponents.length === 2 && folderName === fileName) {\n return undefined;\n }\n\n // Get category parts based on depth\n const categoryParts = afterComponents.slice(0, Math.min(depth, afterComponents.length - 1));\n\n // Filter out component folders (where folder name matches file name)\n const lastCategoryPart = categoryParts[categoryParts.length - 1];\n if (lastCategoryPart === fileName) {\n categoryParts.pop();\n }\n\n if (categoryParts.length === 0) {\n return undefined;\n }\n\n return categoryParts.join(\"/\");\n}\n\n/**\n * Check if a fragment has meaningful enrichment beyond a skeleton\n */\nfunction hasRealEnrichment(fragment: Fragment): boolean {\n // Has description beyond just the name\n if (fragment.description && fragment.description.length > 20) {\n return true;\n }\n\n // Has usage guidelines\n if (fragment.usage?.when && fragment.usage.when.length > 0) {\n return true;\n }\n if (fragment.usage?.doNot && fragment.usage.doNot.length > 0) {\n return true;\n }\n if (fragment.usage?.patterns && fragment.usage.patterns.length > 0) {\n return true;\n }\n\n // Has accessibility info\n if (fragment.accessibility?.requirements && fragment.accessibility.requirements.length > 0) {\n return true;\n }\n\n // Has figma links\n if (fragment.figma?.nodeId || fragment.figma?.variants) {\n return true;\n }\n\n // Has related components\n if (fragment.related?.similar && fragment.related.similar.length > 0) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Resolve component name to path using registry\n */\nexport function resolveComponentPath(\n componentName: string,\n registry: FragmentRegistry\n): string | undefined {\n const entry = registry.components[componentName];\n return entry?.path;\n}\n\n/**\n * Get all components by category\n */\nexport function getComponentsByCategory(\n category: string,\n registry: FragmentRegistry\n): string[] {\n return registry.categories?.[category] || [];\n}\n","/**\n * Context.md Generator\n * Generates a consolidated AI-ready context file from the fragment registry\n *\n * Philosophy: Focus on human-authored semantic knowledge that AI can't get from source.\n * - Usage guidelines: When to use, when not to use\n * - Relationships: Similar components, alternatives\n * - Accessibility: Requirements and keyboard patterns\n * - DO NOT: Duplicate prop types (AI can read TypeScript directly)\n */\n\nimport type {\n FragmentRegistry,\n RegistryComponentEntry,\n RegistryPropEntry,\n FragmentDoNotItem,\n FragmentContextOptions,\n} from '@fragments-sdk/core';\n\n/**\n * Result of context generation\n */\nexport interface ContextGeneratorResult {\n /** Generated markdown content */\n content: string;\n /** Estimated token count */\n tokenEstimate: number;\n /** Component count */\n componentCount: number;\n}\n\n/**\n * Generate context.md from a fragment registry\n */\nexport function generateContextMd(\n registry: FragmentRegistry,\n options: FragmentContextOptions = {}\n): ContextGeneratorResult {\n const {\n format = \"markdown\",\n compact = false,\n include = { props: true, relations: true, code: false },\n } = options;\n\n if (format === \"json\") {\n return generateJsonContext(registry, include, compact);\n }\n\n return generateMarkdownContext(registry, include, compact);\n}\n\n/**\n * Generate markdown context\n */\nfunction generateMarkdownContext(\n registry: FragmentRegistry,\n include: { props?: boolean; relations?: boolean; code?: boolean },\n compact: boolean\n): ContextGeneratorResult {\n const lines: string[] = [];\n const componentNames = Object.keys(registry.components).sort();\n const componentCount = componentNames.length;\n\n // Header\n lines.push(\"# Component Library Context\");\n lines.push(`Generated: ${new Date().toISOString().split(\"T\")[0]} | Components: ${componentCount}`);\n lines.push(\"\");\n\n // Quick reference table\n lines.push(\"## Quick Reference\");\n lines.push(\"\");\n lines.push(\"| Component | Path | Category | Status |\");\n lines.push(\"|-----------|------|----------|--------|\");\n\n for (const name of componentNames) {\n const entry = registry.components[name];\n const status = entry.status || \"stable\";\n const category = entry.category || \"-\";\n lines.push(`| ${name} | ${entry.path} | ${category} | ${status} |`);\n }\n\n lines.push(\"\");\n\n // In compact mode, stop here\n if (compact) {\n const content = lines.join(\"\\n\");\n return {\n content,\n tokenEstimate: estimateTokens(content),\n componentCount,\n };\n }\n\n // Full documentation for each component\n lines.push(\"---\");\n lines.push(\"\");\n\n for (const name of componentNames) {\n const entry = registry.components[name];\n const fragment = entry.fragment;\n\n lines.push(`## ${name}`);\n lines.push(`**Path:** \\`${entry.path}\\``);\n\n if (entry.category) {\n lines.push(`**Category:** ${entry.category} | **Status:** ${entry.status || \"stable\"}`);\n }\n lines.push(\"\");\n\n // Description\n if (entry.description || fragment?.description) {\n lines.push(\"### Description\");\n lines.push(entry.description || fragment?.description || \"\");\n lines.push(\"\");\n }\n\n // Usage guidelines\n if (fragment?.usage) {\n if (fragment.usage.when && fragment.usage.when.length > 0) {\n lines.push(\"### When to Use\");\n for (const when of fragment.usage.when) {\n lines.push(`- ${when}`);\n }\n lines.push(\"\");\n }\n\n if (fragment.usage.doNot && fragment.usage.doNot.length > 0) {\n lines.push(\"### Do Not\");\n for (const doNotItem of fragment.usage.doNot) {\n if (typeof doNotItem === \"string\") {\n lines.push(`- ${doNotItem}`);\n } else {\n const item = doNotItem as FragmentDoNotItem;\n if (item.instead) {\n // Resolve component path\n const alternativePath = resolveComponentPath(item.instead, registry);\n if (alternativePath) {\n lines.push(`- ${item.text} → use **${item.instead}** (\\`${alternativePath}\\`)`);\n } else {\n lines.push(`- ${item.text} → use **${item.instead}**`);\n }\n } else {\n lines.push(`- ${item.text}`);\n }\n }\n }\n lines.push(\"\");\n }\n\n if (include.code && fragment.usage.patterns && fragment.usage.patterns.length > 0) {\n lines.push(\"### Patterns\");\n for (const pattern of fragment.usage.patterns) {\n lines.push(`**${pattern.name}**`);\n if (pattern.description) {\n lines.push(pattern.description);\n }\n lines.push(\"```tsx\");\n lines.push(pattern.code);\n lines.push(\"```\");\n lines.push(\"\");\n }\n }\n }\n\n // Props\n if (include.props && entry.props && Object.keys(entry.props).length > 0) {\n lines.push(\"### Props\");\n lines.push(\"| Prop | Type | Default | Description |\");\n lines.push(\"|------|------|---------|-------------|\");\n\n for (const [propName, prop] of Object.entries(entry.props)) {\n const type = formatPropType(prop);\n const defaultVal = prop.default !== undefined ? `\\`${JSON.stringify(prop.default)}\\`` : \"-\";\n const desc = prop.description || \"-\";\n const required = prop.required ? \" (required)\" : \"\";\n lines.push(`| ${propName}${required} | ${type} | ${defaultVal} | ${desc} |`);\n }\n lines.push(\"\");\n }\n\n // Accessibility\n if (fragment?.accessibility) {\n lines.push(\"### Accessibility\");\n if (fragment.accessibility.role) {\n lines.push(`**Role:** ${fragment.accessibility.role}`);\n }\n if (fragment.accessibility.requirements && fragment.accessibility.requirements.length > 0) {\n for (const req of fragment.accessibility.requirements) {\n lines.push(`- ${req}`);\n }\n }\n if (fragment.accessibility.keyboard) {\n lines.push(\"\");\n lines.push(\"**Keyboard:**\");\n for (const [key, action] of Object.entries(fragment.accessibility.keyboard)) {\n lines.push(`- \\`${key}\\`: ${action}`);\n }\n }\n lines.push(\"\");\n }\n\n // Related components\n if (include.relations && fragment?.related) {\n lines.push(\"### Related\");\n if (fragment.related.similar && fragment.related.similar.length > 0) {\n const resolved = fragment.related.similar.map((comp) => {\n const path = resolveComponentPath(comp, registry);\n return path ? `${comp} (\\`${path}\\`)` : comp;\n });\n lines.push(`- **Similar:** ${resolved.join(\", \")}`);\n }\n if (fragment.related.composedWith && fragment.related.composedWith.length > 0) {\n const resolved = fragment.related.composedWith.map((comp) => {\n const path = resolveComponentPath(comp, registry);\n return path ? `${comp} (\\`${path}\\`)` : comp;\n });\n lines.push(`- **Composed with:** ${resolved.join(\", \")}`);\n }\n if (fragment.related.usedIn && fragment.related.usedIn.length > 0) {\n const resolved = fragment.related.usedIn.map((comp) => {\n const path = resolveComponentPath(comp, registry);\n return path ? `${comp} (\\`${path}\\`)` : comp;\n });\n lines.push(`- **Used in:** ${resolved.join(\", \")}`);\n }\n lines.push(\"\");\n }\n\n lines.push(\"---\");\n lines.push(\"\");\n }\n\n const content = lines.join(\"\\n\");\n return {\n content,\n tokenEstimate: estimateTokens(content),\n componentCount,\n };\n}\n\n/**\n * Generate JSON context\n */\nfunction generateJsonContext(\n registry: FragmentRegistry,\n include: { props?: boolean; relations?: boolean; code?: boolean },\n compact: boolean\n): ContextGeneratorResult {\n const componentNames = Object.keys(registry.components).sort();\n const componentCount = componentNames.length;\n\n interface JsonComponent {\n path: string;\n category?: string;\n status?: string;\n description?: string;\n whenToUse?: string[];\n doNot?: Array<{ text: string; instead?: string; insteadPath?: string }>;\n props?: Record<string, {\n type: string;\n required?: boolean;\n default?: unknown;\n description?: string;\n }>;\n related?: {\n similar?: Array<{ name: string; path?: string }>;\n composedWith?: Array<{ name: string; path?: string }>;\n usedIn?: Array<{ name: string; path?: string }>;\n };\n }\n\n const components: Record<string, JsonComponent> = {};\n\n for (const name of componentNames) {\n const entry = registry.components[name];\n const fragment = entry.fragment;\n\n const component: JsonComponent = {\n path: entry.path,\n };\n\n if (entry.category) component.category = entry.category;\n if (entry.status) component.status = entry.status;\n if (entry.description || fragment?.description) {\n component.description = entry.description || fragment?.description;\n }\n\n if (!compact && fragment?.usage) {\n if (fragment.usage.when && fragment.usage.when.length > 0) {\n component.whenToUse = fragment.usage.when;\n }\n\n if (fragment.usage.doNot && fragment.usage.doNot.length > 0) {\n component.doNot = fragment.usage.doNot.map((item) => {\n if (typeof item === \"string\") {\n return { text: item };\n }\n const doNotItem = item as FragmentDoNotItem;\n const result: { text: string; instead?: string; insteadPath?: string } = {\n text: doNotItem.text,\n };\n if (doNotItem.instead) {\n result.instead = doNotItem.instead;\n result.insteadPath = resolveComponentPath(doNotItem.instead, registry);\n }\n return result;\n });\n }\n }\n\n if (!compact && include.props && entry.props) {\n component.props = {};\n for (const [propName, prop] of Object.entries(entry.props)) {\n component.props[propName] = {\n type: formatPropType(prop),\n };\n if (prop.required) component.props[propName].required = true;\n if (prop.default !== undefined) component.props[propName].default = prop.default;\n if (prop.description) component.props[propName].description = prop.description;\n }\n }\n\n if (!compact && include.relations && fragment?.related) {\n component.related = {};\n if (fragment.related.similar) {\n component.related.similar = fragment.related.similar.map((name) => ({\n name,\n path: resolveComponentPath(name, registry),\n }));\n }\n if (fragment.related.composedWith) {\n component.related.composedWith = fragment.related.composedWith.map((name) => ({\n name,\n path: resolveComponentPath(name, registry),\n }));\n }\n if (fragment.related.usedIn) {\n component.related.usedIn = fragment.related.usedIn.map((name) => ({\n name,\n path: resolveComponentPath(name, registry),\n }));\n }\n }\n\n components[name] = component;\n }\n\n const output = {\n version: \"1.0\",\n generatedAt: registry.generatedAt,\n componentCount,\n categories: registry.categories,\n components,\n };\n\n const content = JSON.stringify(output, null, 2);\n return {\n content,\n tokenEstimate: estimateTokens(content),\n componentCount,\n };\n}\n\n/**\n * Resolve component name to path\n */\nfunction resolveComponentPath(\n componentName: string,\n registry: FragmentRegistry\n): string | undefined {\n return registry.components[componentName]?.path;\n}\n\n/**\n * Format prop type for display\n */\nfunction formatPropType(prop: RegistryPropEntry): string {\n if (prop.options && prop.options.length > 0) {\n return prop.options.map((o) => `\"${o}\"`).join(\" \\\\| \");\n }\n return prop.type || \"unknown\";\n}\n\n/**\n * Estimate token count (rough: ~4 chars per token)\n */\nfunction estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n","import { writeFile, unlink } from 'node:fs/promises';\nimport { dirname, basename, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { build, type Plugin } from 'esbuild';\nimport { BRAND } from '@fragments-sdk/core';\nimport type { FragmentDefinition } from '@fragments-sdk/core';\n\n// Inline implementation of defineFragment that will be injected into bundled files\n// This allows fragment files to work without @fragments/core being installed\nconst DEFINE_FRAGMENT_SHIM = `\nexport function defineFragment(def) {\n return def;\n}\nexport function defineBlock(def) {\n return def;\n}\nexport function defineRecipe(def) {\n return def;\n}\n`;\n\n/**\n * Creates an esbuild plugin that replaces @fragments/core imports with an inline shim.\n * This allows fragment files to be loaded without @fragments/core being installed in the target project.\n */\nfunction createFragmentsCoreShimPlugin(): Plugin {\n return {\n name: BRAND.vitePluginNamespace,\n setup(build) {\n // Intercept @fragments-sdk/cli/core imports\n build.onResolve({ filter: /^@fragments-sdk\\/cli\\/core$/ }, (args) => {\n return {\n path: args.path,\n namespace: BRAND.vitePluginNamespace,\n };\n });\n\n // Return the shim content\n build.onLoad({ filter: /.*/, namespace: BRAND.vitePluginNamespace }, () => {\n return {\n contents: DEFINE_FRAGMENT_SHIM,\n loader: 'js',\n };\n });\n },\n };\n}\n\n/**\n * Load a fragment file, handling TSX/TS transformation automatically.\n * Uses esbuild to bundle and transform TypeScript/JSX before importing.\n */\nexport async function loadFragmentFile(\n absolutePath: string\n): Promise<FragmentDefinition | null> {\n const unwrapFragmentExport = (\n value: unknown\n ): FragmentDefinition | null => {\n if (!value) return null;\n\n // Some CJS/ESM interop paths produce { default: fragment } wrappers.\n // Prefer a shape that actually looks like a fragment definition.\n const asObject = (v: unknown): Record<string, unknown> | null =>\n v && typeof v === 'object' ? (v as Record<string, unknown>) : null;\n const isFragmentLike = (v: unknown): boolean => {\n const obj = asObject(v);\n return !!obj && ('component' in obj || 'meta' in obj || 'variants' in obj);\n };\n\n if (isFragmentLike(value)) {\n return value as FragmentDefinition;\n }\n\n const first = asObject(value)?.default;\n if (isFragmentLike(first)) {\n return first as FragmentDefinition;\n }\n\n const second = asObject(first)?.default;\n if (isFragmentLike(second)) {\n return second as FragmentDefinition;\n }\n\n return (value as FragmentDefinition) ?? null;\n };\n\n const ext = absolutePath.split('.').pop()?.toLowerCase();\n const needsTransform = ext === 'tsx' || ext === 'ts' || ext === 'jsx';\n\n if (!needsTransform) {\n // Plain JS file, import directly\n const fileUrl = pathToFileURL(absolutePath).href;\n const module = await import(fileUrl);\n return unwrapFragmentExport(module.default ?? null);\n }\n\n // Bundle the file with all its local dependencies\n const sourceDir = dirname(absolutePath);\n const baseName = basename(absolutePath, `.${ext}`);\n // Use .mjs and ESM output for compatibility with ESM-only dependencies.\n const tempFile = join(sourceDir, `.${baseName}.fragments-temp-${Date.now()}.mjs`);\n\n try {\n // Use esbuild to bundle the fragment file.\n // We inject a shim for @fragments-sdk/cli/core so it doesn't need to be installed.\n await build({\n entryPoints: [absolutePath],\n outfile: tempFile,\n bundle: true,\n format: 'esm',\n target: 'es2022',\n jsx: 'automatic',\n platform: 'node',\n plugins: [createFragmentsCoreShimPlugin()],\n // Externalize all node_modules - we only need fragment metadata, not component code\n packages: 'external',\n // Also explicitly list patterns for nested imports\n external: [\n // React and its subpaths\n 'react',\n 'react-dom',\n 'react/*',\n 'react-dom/*',\n ],\n // Don't emit sourcemaps for temp files\n sourcemap: false,\n // Suppress warnings\n logLevel: 'silent',\n // Use loader to ignore style imports\n loader: {\n '.scss': 'empty',\n '.css': 'empty',\n '.svg': 'empty',\n '.png': 'empty',\n '.jpg': 'empty',\n '.jpeg': 'empty',\n '.gif': 'empty',\n '.woff': 'empty',\n '.woff2': 'empty',\n '.ttf': 'empty',\n '.eot': 'empty',\n },\n });\n\n const fileUrl = pathToFileURL(tempFile).href;\n const module = await import(fileUrl);\n return unwrapFragmentExport(module.default ?? null);\n } finally {\n // Clean up temp file\n try {\n await unlink(tempFile);\n } catch {\n // Ignore cleanup errors\n }\n }\n}\n\n/**\n * Load multiple fragment files in parallel with error handling.\n */\nexport async function loadFragmentFiles(\n absolutePaths: string[]\n): Promise<Map<string, FragmentDefinition | Error>> {\n const results = new Map<string, FragmentDefinition | Error>();\n\n await Promise.all(\n absolutePaths.map(async (path) => {\n try {\n const fragment = await loadFragmentFile(path);\n if (fragment) {\n results.set(path, fragment);\n } else {\n results.set(path, new Error('No default export found'));\n }\n } catch (error) {\n results.set(\n path,\n error instanceof Error ? error : new Error(String(error))\n );\n }\n })\n );\n\n return results;\n}\n","/**\n * AST-Based Fragment Parser\n *\n * Extracts fragment metadata from .fragment.tsx files WITHOUT executing them.\n * This allows `fragments build` to work without any project dependencies.\n *\n * Uses TypeScript's compiler API to parse and analyze the AST.\n */\n\nimport ts from \"typescript\";\nimport type { FragmentMeta, FragmentUsage, PropDefinition, AIMetadata, FragmentContract } from '@fragments-sdk/core';\n\n/**\n * Parsed fragment metadata (extracted statically from AST)\n */\nexport interface ParsedFragmentMetadata {\n /** Component import path (e.g., \"./Button\" or \"@/components/Button\") */\n componentImport: string | null;\n\n /** Component name as used in the file */\n componentName: string | null;\n\n /** Component metadata */\n meta: Partial<FragmentMeta>;\n\n /** Usage guidelines */\n usage: Partial<FragmentUsage>;\n\n /** Props documentation */\n props: Record<string, Partial<PropDefinition>>;\n\n /** Variant definitions */\n variants: Array<{\n name: string;\n description: string;\n code?: string;\n figma?: string;\n args?: Record<string, unknown>;\n }>;\n\n /** Related components */\n relations: Array<{\n component: string;\n relationship: string;\n note: string;\n }>;\n\n /** AI-specific metadata for playground context generation */\n ai?: AIMetadata;\n\n /** Agent-optimized contract metadata */\n contract?: FragmentContract;\n\n /** Parse warnings */\n warnings: string[];\n}\n\n/**\n * Parse a fragment file and extract metadata without executing it.\n */\nexport function parseFragmentFile(\n fileContent: string,\n filePath?: string\n): ParsedFragmentMetadata {\n const warnings: string[] = [];\n\n // Parse the file\n const sourceFile = ts.createSourceFile(\n filePath ?? \"fragment.tsx\",\n fileContent,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TSX\n );\n\n // Find imports\n const imports = extractImports(sourceFile);\n\n // Find the defineFragment call\n const defineFragmentCall = findDefineFragmentCall(sourceFile);\n\n if (!defineFragmentCall) {\n warnings.push(\"No defineFragment() call found\");\n return {\n componentImport: null,\n componentName: null,\n meta: {},\n usage: { when: [], whenNot: [] },\n props: {},\n variants: [],\n relations: [],\n warnings,\n };\n }\n\n // Extract the argument (object literal)\n const arg = defineFragmentCall.arguments[0];\n if (!arg || !ts.isObjectLiteralExpression(arg)) {\n warnings.push(\"defineFragment() argument is not an object literal\");\n return {\n componentImport: null,\n componentName: null,\n meta: {},\n usage: { when: [], whenNot: [] },\n props: {},\n variants: [],\n relations: [],\n warnings,\n };\n }\n\n // Extract component reference\n const componentProp = findProperty(arg, \"component\");\n let componentName: string | null = null;\n let componentImport: string | null = null;\n\n if (componentProp && ts.isIdentifier(componentProp)) {\n componentName = componentProp.text;\n // Find the import for this component\n componentImport = imports.get(componentName) ?? null;\n }\n\n // Extract meta\n const meta = extractMeta(arg, warnings);\n\n // Extract usage\n const usage = extractUsage(arg, warnings);\n\n // Extract props\n const props = extractProps(arg, warnings);\n\n // Extract variants\n const variants = extractVariants(arg, sourceFile, warnings);\n\n // Extract relations\n const relations = extractRelations(arg, warnings);\n\n // Extract AI metadata\n const ai = extractAIMetadata(arg, warnings);\n\n // Extract contract metadata\n const contract = extractContractMetadata(arg);\n\n return {\n componentImport,\n componentName,\n meta,\n usage,\n props,\n variants,\n relations,\n ai,\n contract,\n warnings,\n };\n}\n\n/**\n * Extract all imports from the source file.\n * Returns a map of imported name -> module path\n */\nfunction extractImports(sourceFile: ts.SourceFile): Map<string, string> {\n const imports = new Map<string, string>();\n\n ts.forEachChild(sourceFile, (node) => {\n if (ts.isImportDeclaration(node)) {\n const moduleSpecifier = node.moduleSpecifier;\n if (ts.isStringLiteral(moduleSpecifier)) {\n const modulePath = moduleSpecifier.text;\n\n // Handle named imports\n const importClause = node.importClause;\n if (importClause) {\n // Default import\n if (importClause.name) {\n imports.set(importClause.name.text, modulePath);\n }\n\n // Named imports\n const namedBindings = importClause.namedBindings;\n if (namedBindings && ts.isNamedImports(namedBindings)) {\n for (const element of namedBindings.elements) {\n imports.set(element.name.text, modulePath);\n }\n }\n }\n }\n }\n });\n\n return imports;\n}\n\n/**\n * Find the defineFragment() call in the source file.\n */\nfunction findDefineFragmentCall(\n sourceFile: ts.SourceFile\n): ts.CallExpression | null {\n let result: ts.CallExpression | null = null;\n\n function visit(node: ts.Node): void {\n if (ts.isCallExpression(node)) {\n const expression = node.expression;\n if (ts.isIdentifier(expression) && expression.text === \"defineFragment\") {\n result = node;\n return;\n }\n }\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return result;\n}\n\n/**\n * Find a property in an object literal by name.\n */\nfunction findProperty(\n obj: ts.ObjectLiteralExpression,\n name: string\n): ts.Expression | null {\n for (const prop of obj.properties) {\n if (ts.isPropertyAssignment(prop)) {\n const propName = prop.name;\n if (ts.isIdentifier(propName) && propName.text === name) {\n return prop.initializer;\n }\n }\n }\n return null;\n}\n\n/**\n * Extract meta object from defineFragment call.\n */\nfunction extractMeta(\n arg: ts.ObjectLiteralExpression,\n warnings: string[]\n): Partial<FragmentMeta> {\n const metaProp = findProperty(arg, \"meta\");\n if (!metaProp || !ts.isObjectLiteralExpression(metaProp)) {\n warnings.push(\"No meta object found\");\n return {};\n }\n\n const meta: Partial<FragmentMeta> = {};\n\n // Extract string properties\n const name = extractStringProperty(metaProp, \"name\");\n if (name) meta.name = name;\n\n const description = extractStringProperty(metaProp, \"description\");\n if (description) meta.description = description;\n\n const category = extractStringProperty(metaProp, \"category\");\n if (category) meta.category = category;\n\n const status = extractStringProperty(metaProp, \"status\") as FragmentMeta[\"status\"];\n if (status) meta.status = status;\n\n const since = extractStringProperty(metaProp, \"since\");\n if (since) meta.since = since;\n\n // Extract figma URL\n const figma = extractStringProperty(metaProp, \"figma\");\n if (figma) meta.figma = figma;\n\n // Extract tags array\n const tags = extractStringArray(metaProp, \"tags\");\n if (tags.length > 0) meta.tags = tags;\n\n // Extract dependencies array\n const depsProp = findProperty(metaProp, \"dependencies\");\n if (depsProp && ts.isArrayLiteralExpression(depsProp)) {\n const deps = extractLiteralValue(depsProp) as Array<{ name: string; version: string; reason?: string }>;\n if (Array.isArray(deps) && deps.length > 0) {\n meta.dependencies = deps;\n }\n }\n\n return meta;\n}\n\n/**\n * Extract usage object from defineFragment call.\n */\nfunction extractUsage(\n arg: ts.ObjectLiteralExpression,\n warnings: string[]\n): Partial<FragmentUsage> {\n const usageProp = findProperty(arg, \"usage\");\n if (!usageProp || !ts.isObjectLiteralExpression(usageProp)) {\n return { when: [], whenNot: [] };\n }\n\n return {\n when: extractStringArray(usageProp, \"when\"),\n whenNot: extractStringArray(usageProp, \"whenNot\"),\n guidelines: extractStringArray(usageProp, \"guidelines\"),\n accessibility: extractStringArray(usageProp, \"accessibility\"),\n };\n}\n\n/**\n * Extract props object from defineFragment call.\n */\nfunction extractProps(\n arg: ts.ObjectLiteralExpression,\n warnings: string[]\n): Record<string, Partial<PropDefinition>> {\n const propsProp = findProperty(arg, \"props\");\n if (!propsProp || !ts.isObjectLiteralExpression(propsProp)) {\n return {};\n }\n\n const props: Record<string, Partial<PropDefinition>> = {};\n\n for (const prop of propsProp.properties) {\n if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {\n const propName = prop.name.text;\n const propValue = prop.initializer;\n\n if (ts.isObjectLiteralExpression(propValue)) {\n props[propName] = extractPropDefinition(propValue);\n }\n }\n }\n\n return props;\n}\n\n/**\n * Extract a single prop definition.\n */\nfunction extractPropDefinition(\n obj: ts.ObjectLiteralExpression\n): Partial<PropDefinition> {\n const def: Partial<PropDefinition> = {};\n\n const type = extractStringProperty(obj, \"type\");\n if (type) def.type = type as PropDefinition[\"type\"];\n\n const description = extractStringProperty(obj, \"description\");\n if (description) def.description = description;\n\n const values = extractStringArray(obj, \"values\");\n if (values.length > 0) def.values = values;\n\n const required = extractBooleanProperty(obj, \"required\");\n if (required !== null) def.required = required;\n\n // Default value - try to extract as literal\n const defaultProp = findProperty(obj, \"default\");\n if (defaultProp) {\n def.default = extractLiteralValue(defaultProp);\n }\n\n const constraints = extractStringArray(obj, \"constraints\");\n if (constraints.length > 0) def.constraints = constraints;\n\n return def;\n}\n\n/**\n * Extract variants array from defineFragment call.\n */\nfunction extractVariants(\n arg: ts.ObjectLiteralExpression,\n sourceFile: ts.SourceFile,\n warnings: string[]\n): Array<{ name: string; description: string; code?: string; figma?: string; args?: Record<string, unknown> }> {\n const variantsProp = findProperty(arg, \"variants\");\n if (!variantsProp || !ts.isArrayLiteralExpression(variantsProp)) {\n return [];\n }\n\n const variants: Array<{ name: string; description: string; code?: string; figma?: string; args?: Record<string, unknown> }> = [];\n\n for (const element of variantsProp.elements) {\n if (ts.isObjectLiteralExpression(element)) {\n const name = extractStringProperty(element, \"name\");\n const description = extractStringProperty(element, \"description\");\n\n if (name) {\n const variant: { name: string; description: string; code?: string; figma?: string; args?: Record<string, unknown> } = {\n name,\n description: description ?? \"\",\n };\n\n // Try to extract code property if present\n const codeProp = findProperty(element, \"code\");\n if (codeProp && (ts.isStringLiteral(codeProp) || ts.isNoSubstitutionTemplateLiteral(codeProp))) {\n variant.code = codeProp.text;\n }\n\n // Try to extract render function and convert to code string\n const renderProp = findProperty(element, \"render\");\n if (renderProp && !variant.code) {\n variant.code = extractRenderCode(renderProp, sourceFile);\n }\n\n // Extract figma URL for variant\n const figma = extractStringProperty(element, \"figma\");\n if (figma) {\n variant.figma = figma;\n }\n\n // Extract args object for code generation\n const argsProp = findProperty(element, \"args\");\n if (argsProp && ts.isObjectLiteralExpression(argsProp)) {\n const argsValue = extractLiteralValue(argsProp);\n if (argsValue && typeof argsValue === 'object' && !Array.isArray(argsValue)) {\n variant.args = argsValue as Record<string, unknown>;\n }\n }\n\n variants.push(variant);\n }\n }\n }\n\n return variants;\n}\n\n/**\n * Remove common leading whitespace from all lines (dedent).\n * This handles template literals and JSX that have extra indentation from code formatting.\n *\n * Special handling: If the first line has no indentation (common after .trim()),\n * we calculate minimum indent from subsequent lines only.\n */\nfunction dedent(str: string): string {\n const lines = str.split('\\n');\n\n if (lines.length <= 1) {\n return str;\n }\n\n // Check if first line has no indentation\n const firstLineIndent = lines[0].match(/^(\\s*)/)?.[1].length ?? 0;\n const startIndex = firstLineIndent === 0 ? 1 : 0;\n\n // Find the minimum indentation (ignoring empty lines)\n let minIndent = Infinity;\n for (let i = startIndex; i < lines.length; i++) {\n const line = lines[i];\n if (line.trim() === '') continue;\n const match = line.match(/^(\\s*)/);\n if (match) {\n minIndent = Math.min(minIndent, match[1].length);\n }\n }\n\n // If no indentation found, return as-is\n if (minIndent === Infinity || minIndent === 0) {\n return str;\n }\n\n // Remove the common indentation from all lines (except first if it had no indent)\n return lines\n .map((line, index) => {\n if (index === 0 && firstLineIndent === 0) {\n return line; // Keep first line as-is\n }\n return line.slice(minIndent);\n })\n .join('\\n');\n}\n\n/**\n * Extract the code from a render function.\n */\nfunction extractRenderCode(\n renderProp: ts.Expression,\n sourceFile: ts.SourceFile\n): string | undefined {\n // Handle arrow function: () => <Component />\n if (ts.isArrowFunction(renderProp)) {\n const body = renderProp.body;\n // Get the source text of the body\n const start = body.getStart(sourceFile);\n const end = body.getEnd();\n let code = sourceFile.text.substring(start, end).trim();\n\n // Remove parentheses if present\n if (code.startsWith(\"(\") && code.endsWith(\")\")) {\n code = code.slice(1, -1).trim();\n }\n\n // Dedent the code to remove common leading whitespace\n code = dedent(code);\n\n return code;\n }\n\n return undefined;\n}\n\n/**\n * Extract relations array from defineFragment call.\n */\nfunction extractRelations(\n arg: ts.ObjectLiteralExpression,\n warnings: string[]\n): Array<{ component: string; relationship: string; note: string }> {\n const relationsProp = findProperty(arg, \"relations\");\n if (!relationsProp || !ts.isArrayLiteralExpression(relationsProp)) {\n return [];\n }\n\n const relations: Array<{ component: string; relationship: string; note: string }> = [];\n\n for (const element of relationsProp.elements) {\n if (ts.isObjectLiteralExpression(element)) {\n const component = extractStringProperty(element, \"component\");\n const relationship = extractStringProperty(element, \"relationship\");\n const note = extractStringProperty(element, \"note\");\n\n if (component && relationship) {\n relations.push({\n component,\n relationship,\n note: note ?? \"\",\n });\n }\n }\n }\n\n return relations;\n}\n\n/**\n * Extract AI metadata from defineFragment call.\n */\nfunction extractAIMetadata(\n arg: ts.ObjectLiteralExpression,\n warnings: string[]\n): AIMetadata | undefined {\n const aiProp = findProperty(arg, \"ai\");\n if (!aiProp || !ts.isObjectLiteralExpression(aiProp)) {\n return undefined;\n }\n\n const ai: AIMetadata = {};\n\n // Extract compositionPattern\n const compositionPattern = extractStringProperty(aiProp, \"compositionPattern\");\n if (compositionPattern && ['compound', 'simple', 'controlled'].includes(compositionPattern)) {\n ai.compositionPattern = compositionPattern as AIMetadata['compositionPattern'];\n }\n\n // Extract subComponents array\n const subComponents = extractStringArray(aiProp, \"subComponents\");\n if (subComponents.length > 0) {\n ai.subComponents = subComponents;\n }\n\n // Extract requiredChildren array\n const requiredChildren = extractStringArray(aiProp, \"requiredChildren\");\n if (requiredChildren.length > 0) {\n ai.requiredChildren = requiredChildren;\n }\n\n // Extract commonPatterns array\n const commonPatterns = extractStringArray(aiProp, \"commonPatterns\");\n if (commonPatterns.length > 0) {\n ai.commonPatterns = commonPatterns;\n }\n\n // Only return if we have any fields\n if (Object.keys(ai).length > 0) {\n return ai;\n }\n\n return undefined;\n}\n\n/**\n * Extract contract metadata from defineFragment call.\n */\nfunction extractContractMetadata(\n arg: ts.ObjectLiteralExpression,\n): FragmentContract | undefined {\n const contractProp = findProperty(arg, \"contract\");\n if (!contractProp || !ts.isObjectLiteralExpression(contractProp)) {\n return undefined;\n }\n\n const contract: FragmentContract = {};\n\n // Extract propsSummary array\n const propsSummary = extractStringArray(contractProp, \"propsSummary\");\n if (propsSummary.length > 0) {\n contract.propsSummary = propsSummary;\n }\n\n // Extract a11yRules array\n const a11yRules = extractStringArray(contractProp, \"a11yRules\");\n if (a11yRules.length > 0) {\n contract.a11yRules = a11yRules;\n }\n\n // Only return if we have any fields\n if (Object.keys(contract).length > 0) {\n return contract;\n }\n\n return undefined;\n}\n\n/**\n * Extract a string property from an object literal.\n */\nfunction extractStringProperty(\n obj: ts.ObjectLiteralExpression,\n name: string\n): string | null {\n const prop = findProperty(obj, name);\n if (prop && ts.isStringLiteral(prop)) {\n return prop.text;\n }\n // Handle template literals without expressions\n if (prop && ts.isNoSubstitutionTemplateLiteral(prop)) {\n return prop.text;\n }\n return null;\n}\n\n/**\n * Extract a boolean property from an object literal.\n */\nfunction extractBooleanProperty(\n obj: ts.ObjectLiteralExpression,\n name: string\n): boolean | null {\n const prop = findProperty(obj, name);\n if (prop) {\n if (prop.kind === ts.SyntaxKind.TrueKeyword) return true;\n if (prop.kind === ts.SyntaxKind.FalseKeyword) return false;\n }\n return null;\n}\n\n/**\n * Extract a string array from an object literal.\n */\nfunction extractStringArray(\n obj: ts.ObjectLiteralExpression,\n name: string\n): string[] {\n const prop = findProperty(obj, name);\n if (!prop || !ts.isArrayLiteralExpression(prop)) {\n return [];\n }\n\n const result: string[] = [];\n for (const element of prop.elements) {\n if (ts.isStringLiteral(element)) {\n result.push(element.text);\n } else if (ts.isNoSubstitutionTemplateLiteral(element)) {\n result.push(element.text);\n }\n }\n return result;\n}\n\n/**\n * Extract a literal value from an expression.\n */\nfunction extractLiteralValue(expr: ts.Expression): unknown {\n if (ts.isStringLiteral(expr)) {\n return expr.text;\n }\n if (ts.isNumericLiteral(expr)) {\n return Number(expr.text);\n }\n if (expr.kind === ts.SyntaxKind.TrueKeyword) {\n return true;\n }\n if (expr.kind === ts.SyntaxKind.FalseKeyword) {\n return false;\n }\n if (expr.kind === ts.SyntaxKind.NullKeyword) {\n return null;\n }\n if (ts.isArrayLiteralExpression(expr)) {\n return expr.elements.map(extractLiteralValue);\n }\n if (ts.isObjectLiteralExpression(expr)) {\n const obj: Record<string, unknown> = {};\n for (const prop of expr.properties) {\n if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {\n obj[prop.name.text] = extractLiteralValue(prop.initializer);\n }\n }\n return obj;\n }\n return undefined;\n}\n","/**\n * Loader for Storybook .storybook/preview.{tsx,ts,jsx,js} configuration.\n *\n * This module detects and loads Storybook preview configuration to extract:\n * - decorators: Global decorators applied to all stories\n * - parameters: Global parameters for all stories\n * - globalTypes: Global type definitions (e.g., for toolbar controls)\n * - args: Default args for all stories\n * - argTypes: Default argTypes for all stories\n * - loaders: Global loaders for all stories\n */\n\nimport { existsSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport type { PreviewConfig } from '@fragments-sdk/core';\n\n/**\n * Possible file extensions and names for preview config\n */\nconst PREVIEW_FILES = [\n \"preview.tsx\",\n \"preview.ts\",\n \"preview.jsx\",\n \"preview.js\",\n];\n\n/**\n * Find the preview config file in a .storybook directory\n *\n * @param storybookDir - Path to the .storybook directory\n * @returns The full path to the preview file, or null if not found\n */\nexport function findPreviewConfigPath(storybookDir: string): string | null {\n for (const fileName of PREVIEW_FILES) {\n const filePath = join(storybookDir, fileName);\n if (existsSync(filePath)) {\n return filePath;\n }\n }\n return null;\n}\n\n/**\n * Find the .storybook directory starting from a project root.\n * Checks common locations.\n *\n * @param projectRoot - The project root directory\n * @returns The path to the .storybook directory, or null if not found\n */\nexport function findStorybookDir(projectRoot: string): string | null {\n const possiblePaths = [\n join(projectRoot, \".storybook\"),\n join(projectRoot, \"storybook\"),\n ];\n\n for (const dir of possiblePaths) {\n if (existsSync(dir)) {\n return dir;\n }\n }\n return null;\n}\n\n/**\n * Load and parse the Storybook preview configuration.\n *\n * This function dynamically imports the preview file and extracts\n * the relevant configuration exports.\n *\n * @param previewPath - Full path to the preview config file\n * @returns The parsed preview configuration\n */\nexport async function loadPreviewConfig(\n previewPath: string\n): Promise<PreviewConfig> {\n try {\n // Dynamic import with file:// URL for ESM compatibility\n const fileUrl = new URL(`file://${resolve(previewPath)}`);\n const module = await import(fileUrl.href);\n\n // Extract configuration from the module\n const config: PreviewConfig = {\n decorators: module.decorators ?? module.default?.decorators ?? [],\n parameters: module.parameters ?? module.default?.parameters ?? {},\n globalTypes: module.globalTypes ?? module.default?.globalTypes ?? {},\n args: module.args ?? module.default?.args ?? {},\n argTypes: module.argTypes ?? module.default?.argTypes ?? {},\n loaders: module.loaders ?? module.default?.loaders ?? [],\n };\n\n return config;\n } catch (error) {\n console.warn(\n `[Fragments] Failed to load preview config from ${previewPath}:`,\n error instanceof Error ? error.message : error\n );\n return {};\n }\n}\n\n/**\n * Auto-detect and load preview configuration from a project.\n *\n * @param projectRoot - The project root directory\n * @returns The preview configuration, or empty config if not found\n */\nexport async function autoLoadPreviewConfig(\n projectRoot: string\n): Promise<PreviewConfig> {\n const storybookDir = findStorybookDir(projectRoot);\n if (!storybookDir) {\n return {};\n }\n\n const previewPath = findPreviewConfigPath(storybookDir);\n if (!previewPath) {\n return {};\n }\n\n return loadPreviewConfig(previewPath);\n}\n\n/**\n * Generate a virtual module that imports and re-exports preview config.\n * This is used in the Vite plugin to make preview config available at runtime.\n *\n * @param previewPath - Full path to the preview config file, or null\n * @returns JavaScript code for the virtual module\n */\nexport function generatePreviewModule(previewPath: string | null): string {\n if (!previewPath) {\n // No preview config found - export empty defaults\n return `\nexport const decorators = [];\nexport const parameters = {};\nexport const globalTypes = {};\nexport const args = {};\nexport const argTypes = {};\nexport const loaders = [];\n\nexport default {\n decorators,\n parameters,\n globalTypes,\n args,\n argTypes,\n loaders,\n};\n`;\n }\n\n // Import from the actual preview file and re-export\n return `\nimport * as preview from \"${previewPath}\";\n\nexport const decorators = preview.decorators ?? preview.default?.decorators ?? [];\nexport const parameters = preview.parameters ?? preview.default?.parameters ?? {};\nexport const globalTypes = preview.globalTypes ?? preview.default?.globalTypes ?? {};\nexport const args = preview.args ?? preview.default?.args ?? {};\nexport const argTypes = preview.argTypes ?? preview.default?.argTypes ?? {};\nexport const loaders = preview.loaders ?? preview.default?.loaders ?? [];\n\nexport default {\n decorators,\n parameters,\n globalTypes,\n args,\n argTypes,\n loaders,\n};\n`;\n}\n","/**\n * AST-based import analysis for detecting component relationships\n *\n * Analyzes TypeScript/JavaScript files to find which components import others,\n * providing accurate \"used by\" relationships for the component graph.\n *\n * @deprecated Import analysis is now handled by graph-extractor.ts which provides\n * richer edge-typed relationships via the ComponentGraph. These functions are\n * maintained for backward compatibility. For new code, use\n * `buildComponentGraph()` from `./graph-extractor.js` instead.\n */\n\nimport ts from 'typescript';\nimport { readFileSync } from 'node:fs';\nimport { resolve, dirname, basename } from 'node:path';\n\nexport interface ComponentImport {\n /** Name of the imported component */\n name: string;\n /** Import path (relative or package) */\n path: string;\n /** Whether this is a default import */\n isDefault: boolean;\n /** Whether this is a namespace import */\n isNamespace: boolean;\n}\n\nexport interface ImportAnalysisResult {\n /** Source file path */\n filePath: string;\n /** Component name extracted from file */\n componentName: string;\n /** List of component imports found */\n imports: ComponentImport[];\n}\n\n/**\n * Extract component name from a file path\n */\nfunction extractComponentNameFromPath(filePath: string): string {\n const fileName = basename(filePath);\n\n // Handle index.tsx files - use parent directory name\n if (fileName === 'index.tsx' || fileName === 'index.ts' || fileName === 'index.jsx' || fileName === 'index.js') {\n const parentDir = basename(dirname(filePath));\n return parentDir;\n }\n\n // Remove extension and common suffixes\n return fileName\n .replace(/\\.(tsx?|jsx?)$/, '')\n .replace(/\\.stories$/, '')\n .replace(/\\.fragment$/, '')\n .replace(/\\.fragment$/, '');\n}\n\n/**\n * Check if an import path looks like a component import (not a utility/library)\n */\nfunction isComponentImportPath(importPath: string): boolean {\n // Skip node_modules packages\n if (!importPath.startsWith('.') && !importPath.startsWith('/')) {\n return false;\n }\n\n // Skip common utility/hook patterns\n const skipPatterns = [\n /\\/hooks\\//,\n /\\/utils\\//,\n /\\/helpers\\//,\n /\\/lib\\//,\n /\\/types\\//,\n /\\/constants\\//,\n /\\/styles\\//,\n /\\/context\\//,\n /\\.css$/,\n /\\.scss$/,\n /\\.less$/,\n /\\.json$/,\n ];\n\n for (const pattern of skipPatterns) {\n if (pattern.test(importPath)) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Check if an imported name looks like a React component (PascalCase)\n */\nfunction isPascalCase(name: string): boolean {\n return /^[A-Z][a-zA-Z0-9]*$/.test(name);\n}\n\n/**\n * Analyze a single file for component imports\n */\nexport function analyzeFileImports(filePath: string): ImportAnalysisResult {\n const componentName = extractComponentNameFromPath(filePath);\n const imports: ComponentImport[] = [];\n\n let sourceText: string;\n try {\n sourceText = readFileSync(filePath, 'utf-8');\n } catch {\n return { filePath, componentName, imports };\n }\n\n const sourceFile = ts.createSourceFile(\n filePath,\n sourceText,\n ts.ScriptTarget.Latest,\n true,\n filePath.endsWith('.tsx') || filePath.endsWith('.jsx')\n ? ts.ScriptKind.TSX\n : ts.ScriptKind.TS\n );\n\n ts.forEachChild(sourceFile, (node) => {\n if (ts.isImportDeclaration(node)) {\n const moduleSpecifier = node.moduleSpecifier;\n if (!ts.isStringLiteral(moduleSpecifier)) return;\n\n const importPath = moduleSpecifier.text;\n\n // Skip non-component imports\n if (!isComponentImportPath(importPath)) return;\n\n const importClause = node.importClause;\n if (!importClause) return;\n\n // Default import: import Button from './Button'\n if (importClause.name) {\n const name = importClause.name.text;\n if (isPascalCase(name)) {\n imports.push({\n name,\n path: importPath,\n isDefault: true,\n isNamespace: false,\n });\n }\n }\n\n // Named imports: import { Button, Icon } from './components'\n const namedBindings = importClause.namedBindings;\n if (namedBindings) {\n if (ts.isNamedImports(namedBindings)) {\n for (const element of namedBindings.elements) {\n const name = element.name.text;\n if (isPascalCase(name)) {\n imports.push({\n name,\n path: importPath,\n isDefault: false,\n isNamespace: false,\n });\n }\n }\n } else if (ts.isNamespaceImport(namedBindings)) {\n // Namespace import: import * as Components from './components'\n // We can't reliably know what components are used without more analysis\n const name = namedBindings.name.text;\n imports.push({\n name,\n path: importPath,\n isDefault: false,\n isNamespace: true,\n });\n }\n }\n }\n });\n\n return { filePath, componentName, imports };\n}\n\n/**\n * Build a map of which components are imported by which files\n */\nexport function buildImportGraph(\n filePaths: string[]\n): Map<string, string[]> {\n // Map from component name -> list of component names that import it\n const importedBy = new Map<string, string[]>();\n\n for (const filePath of filePaths) {\n const result = analyzeFileImports(filePath);\n\n for (const imp of result.imports) {\n // Skip namespace imports for now\n if (imp.isNamespace) continue;\n\n const importedComponent = imp.name;\n const importingComponent = result.componentName;\n\n // Don't add self-references\n if (importedComponent === importingComponent) continue;\n\n const existing = importedBy.get(importedComponent) || [];\n if (!existing.includes(importingComponent)) {\n existing.push(importingComponent);\n importedBy.set(importedComponent, existing);\n }\n }\n }\n\n return importedBy;\n}\n\n/**\n * Get components that import a specific component\n */\nexport function getImportedBy(\n componentName: string,\n importGraph: Map<string, string[]>\n): string[] {\n return importGraph.get(componentName) || [];\n}\n"],"mappings":";;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,SAAS,eAAe;AACjC,SAAS,kBAAkB;AAI3B,IAAM,4BAAmD;AAAA,EACvD,mBAAmB;AAAA,EACnB,cAAc;AAAA,EACd,iBAAiB;AAAA,EACjB,sBAAsB;AACxB;AAEA,IAAM,iBAAkC;AAAA,EACtC,SAAS;AAAA,IACP,WAAW,MAAM,aAAa;AAAA;AAAA,IAC9B;AAAA;AAAA,EACF;AAAA,EACA,SAAS,CAAC,oBAAoB;AAAA,EAC9B,YAAY,CAAC,oBAAoB,cAAc;AAAA,EAC/C,WAAW;AAAA,EACX,WAAW;AAAA,EACX,UAAU;AAAA,IACR,MAAM;AAAA,IACN,OAAO;AAAA,IACP,oBAAoB;AAAA,IACpB,wBAAwB,CAAC,yBAAyB,YAAY,kBAAkB;AAAA,EAClF;AACF;AAMO,SAAS,eAAe,WAAmB,QAAQ,IAAI,GAAkB;AAC9E,MAAI,aAAa;AAEjB,SAAO,eAAe,QAAQ,UAAU,GAAG;AAEzC,UAAM,aAAa,QAAQ,YAAY,MAAM,UAAU;AACvD,QAAI,WAAW,UAAU,GAAG;AAC1B,aAAO;AAAA,IACT;AAEA,UAAM,mBAAmB,QAAQ,YAAY,MAAM,gBAAgB;AACnE,QAAI,WAAW,gBAAgB,GAAG;AAChC,aAAO;AAAA,IACT;AACA,iBAAa,QAAQ,UAAU;AAAA,EACjC;AAEA,SAAO;AACT;AAKA,eAAsB,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BAAgB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAQO,SAAS,sBAAsB,cAAqC;AACzE,aAAW,YAAY,eAAe;AACpC,UAAM,WAAWD,MAAK,cAAc,QAAQ;AAC5C,QAAID,YAAW,QAAQ,GAAG;AACxB,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AASO,SAAS,iBAAiB,aAAoC;AACnE,QAAM,gBAAgB;AAAA,IACpBC,MAAK,aAAa,YAAY;AAAA,IAC9BA,MAAK,aAAa,WAAW;AAAA,EAC/B;AAEA,aAAW,OAAO,eAAe;AAC/B,QAAID,YAAW,GAAG,GAAG;AACnB,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAoEO,SAAS,sBAAsB,aAAoC;AACxE,MAAI,CAAC,aAAa;AAEhB,WAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBT;AAGA,SAAO;AAAA,4BACmB,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBvC;;;AC/JA,OAAOG,SAAQ;AACf,SAAS,gBAAAC,qBAAoB;AAC7B,SAAkB,WAAAC,UAAS,YAAAC,iBAAgB;","names":["readFileSync","dirname","dirname","readFileSync","content","name","dirname","basename","join","build","dirname","basename","join","ts","existsSync","join","resolve","ts","readFileSync","dirname","basename"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __banner_createRequire } from 'module'; const require = __banner_createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
loadConfig
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HRFUSSZI.js";
|
|
5
5
|
import {
|
|
6
6
|
discoverAllComponents
|
|
7
7
|
} from "./chunk-WXSR2II7.js";
|
|
@@ -368,4 +368,4 @@ function calculateConfidence(props, usageAnalysis, storyFile) {
|
|
|
368
368
|
export {
|
|
369
369
|
scan
|
|
370
370
|
};
|
|
371
|
-
//# sourceMappingURL=chunk-
|
|
371
|
+
//# sourceMappingURL=chunk-ZM4ZQZWZ.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __banner_createRequire } from 'module'; const require = __banner_createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
extractPropsFromFile
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HRFUSSZI.js";
|
|
5
5
|
import "./chunk-WXSR2II7.js";
|
|
6
6
|
import "./chunk-D2CDBRNU.js";
|
|
7
7
|
import {
|
|
@@ -456,4 +456,4 @@ function inferStatus(filePath) {
|
|
|
456
456
|
export {
|
|
457
457
|
generate
|
|
458
458
|
};
|
|
459
|
-
//# sourceMappingURL=generate-
|
|
459
|
+
//# sourceMappingURL=generate-FBHSXR3D.js.map
|
package/dist/index.js
CHANGED
|
@@ -12,11 +12,11 @@ import {
|
|
|
12
12
|
validateCoverage,
|
|
13
13
|
validateSchema,
|
|
14
14
|
validateSnippets
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-5G3VZH43.js";
|
|
16
16
|
import {
|
|
17
17
|
findConfigFile,
|
|
18
18
|
loadConfig
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-HRFUSSZI.js";
|
|
20
20
|
import {
|
|
21
21
|
discoverComponentFiles,
|
|
22
22
|
discoverFragmentFiles,
|
|
@@ -567,7 +567,7 @@ Scan path not found: ${scanPath}
|
|
|
567
567
|
errors: [`Scan path not found: ${scanPath}`]
|
|
568
568
|
};
|
|
569
569
|
}
|
|
570
|
-
const { scanGenerate } = await import("./scan-generate-
|
|
570
|
+
const { scanGenerate } = await import("./scan-generate-SJAN5MVI.js");
|
|
571
571
|
const scanResult = await scanGenerate({
|
|
572
572
|
scanPath,
|
|
573
573
|
force: options.force,
|
|
@@ -729,7 +729,7 @@ Keeping existing configuration. Run \`${BRAND.cliCommand} dev\` to start.
|
|
|
729
729
|
if (runScan) {
|
|
730
730
|
console.log(pc2.dim("\nScanning source code for documentation...\n"));
|
|
731
731
|
try {
|
|
732
|
-
const { scan } = await import("./scan-
|
|
732
|
+
const { scan } = await import("./scan-CJF2DOQW.js");
|
|
733
733
|
await scan({
|
|
734
734
|
config: configPath,
|
|
735
735
|
verbose: false
|
|
@@ -793,4 +793,4 @@ Keeping existing configuration. Run \`${BRAND.cliCommand} dev\` to start.
|
|
|
793
793
|
export {
|
|
794
794
|
init
|
|
795
795
|
};
|
|
796
|
-
//# sourceMappingURL=init-
|
|
796
|
+
//# sourceMappingURL=init-NDQXUWDU.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire as __banner_createRequire } from 'module'; const require = __banner_createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
scan
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-ZM4ZQZWZ.js";
|
|
5
|
+
import "./chunk-HRFUSSZI.js";
|
|
6
6
|
import "./chunk-WXSR2II7.js";
|
|
7
7
|
import "./chunk-D5PYOXEI.js";
|
|
8
8
|
import "./chunk-D2CDBRNU.js";
|
|
@@ -11,4 +11,4 @@ import "./chunk-Z7EY4VHE.js";
|
|
|
11
11
|
export {
|
|
12
12
|
scan
|
|
13
13
|
};
|
|
14
|
-
//# sourceMappingURL=scan-
|
|
14
|
+
//# sourceMappingURL=scan-CJF2DOQW.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __banner_createRequire } from 'module'; const require = __banner_createRequire(import.meta.url);
|
|
2
|
-
import "./chunk-
|
|
2
|
+
import "./chunk-HRFUSSZI.js";
|
|
3
3
|
import {
|
|
4
4
|
discoverAllComponents
|
|
5
5
|
} from "./chunk-WXSR2II7.js";
|
|
@@ -688,4 +688,4 @@ export {
|
|
|
688
688
|
extractComponentJSDocFromSource,
|
|
689
689
|
scanGenerate
|
|
690
690
|
};
|
|
691
|
-
//# sourceMappingURL=scan-generate-
|
|
691
|
+
//# sourceMappingURL=scan-generate-SJAN5MVI.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __banner_createRequire } from 'module'; const require = __banner_createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
parseFragmentFile
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HRFUSSZI.js";
|
|
5
5
|
import {
|
|
6
6
|
discoverFragmentFiles
|
|
7
7
|
} from "./chunk-WXSR2II7.js";
|
|
@@ -1071,4 +1071,4 @@ export {
|
|
|
1071
1071
|
listTests,
|
|
1072
1072
|
runTestCommand
|
|
1073
1073
|
};
|
|
1074
|
-
//# sourceMappingURL=test-
|
|
1074
|
+
//# sourceMappingURL=test-Z5LVO724.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __banner_createRequire } from 'module'; const require = __banner_createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
loadConfig
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HRFUSSZI.js";
|
|
5
5
|
import "./chunk-WXSR2II7.js";
|
|
6
6
|
import {
|
|
7
7
|
parseTokenFiles
|
|
@@ -172,4 +172,4 @@ export {
|
|
|
172
172
|
tokens_default as default,
|
|
173
173
|
tokens
|
|
174
174
|
};
|
|
175
|
-
//# sourceMappingURL=tokens-
|
|
175
|
+
//# sourceMappingURL=tokens-CE46OTMD.js.map
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
generatePreviewModule,
|
|
6
6
|
loadConfig,
|
|
7
7
|
parseFragmentFile
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-HRFUSSZI.js";
|
|
9
9
|
import {
|
|
10
10
|
discoverFragmentFiles,
|
|
11
11
|
discoverInstalledFragments
|
|
@@ -2705,4 +2705,4 @@ export {
|
|
|
2705
2705
|
createDevServer,
|
|
2706
2706
|
fragmentsPlugin
|
|
2707
2707
|
};
|
|
2708
|
-
//# sourceMappingURL=viewer-
|
|
2708
|
+
//# sourceMappingURL=viewer-DNMNC5VS.js.map
|
package/package.json
CHANGED
package/src/core/loader.ts
CHANGED
|
@@ -53,6 +53,37 @@ function createFragmentsCoreShimPlugin(): Plugin {
|
|
|
53
53
|
export async function loadFragmentFile(
|
|
54
54
|
absolutePath: string
|
|
55
55
|
): Promise<FragmentDefinition | null> {
|
|
56
|
+
const unwrapFragmentExport = (
|
|
57
|
+
value: unknown
|
|
58
|
+
): FragmentDefinition | null => {
|
|
59
|
+
if (!value) return null;
|
|
60
|
+
|
|
61
|
+
// Some CJS/ESM interop paths produce { default: fragment } wrappers.
|
|
62
|
+
// Prefer a shape that actually looks like a fragment definition.
|
|
63
|
+
const asObject = (v: unknown): Record<string, unknown> | null =>
|
|
64
|
+
v && typeof v === 'object' ? (v as Record<string, unknown>) : null;
|
|
65
|
+
const isFragmentLike = (v: unknown): boolean => {
|
|
66
|
+
const obj = asObject(v);
|
|
67
|
+
return !!obj && ('component' in obj || 'meta' in obj || 'variants' in obj);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
if (isFragmentLike(value)) {
|
|
71
|
+
return value as FragmentDefinition;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const first = asObject(value)?.default;
|
|
75
|
+
if (isFragmentLike(first)) {
|
|
76
|
+
return first as FragmentDefinition;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const second = asObject(first)?.default;
|
|
80
|
+
if (isFragmentLike(second)) {
|
|
81
|
+
return second as FragmentDefinition;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return (value as FragmentDefinition) ?? null;
|
|
85
|
+
};
|
|
86
|
+
|
|
56
87
|
const ext = absolutePath.split('.').pop()?.toLowerCase();
|
|
57
88
|
const needsTransform = ext === 'tsx' || ext === 'ts' || ext === 'jsx';
|
|
58
89
|
|
|
@@ -60,24 +91,23 @@ export async function loadFragmentFile(
|
|
|
60
91
|
// Plain JS file, import directly
|
|
61
92
|
const fileUrl = pathToFileURL(absolutePath).href;
|
|
62
93
|
const module = await import(fileUrl);
|
|
63
|
-
return module.default ?? null;
|
|
94
|
+
return unwrapFragmentExport(module.default ?? null);
|
|
64
95
|
}
|
|
65
96
|
|
|
66
97
|
// Bundle the file with all its local dependencies
|
|
67
98
|
const sourceDir = dirname(absolutePath);
|
|
68
99
|
const baseName = basename(absolutePath, `.${ext}`);
|
|
69
|
-
// Use .
|
|
70
|
-
const tempFile = join(sourceDir, `.${baseName}.fragments-temp-${Date.now()}.
|
|
100
|
+
// Use .mjs and ESM output for compatibility with ESM-only dependencies.
|
|
101
|
+
const tempFile = join(sourceDir, `.${baseName}.fragments-temp-${Date.now()}.mjs`);
|
|
71
102
|
|
|
72
103
|
try {
|
|
73
|
-
// Use esbuild to bundle the fragment file
|
|
74
|
-
// We inject a shim for @fragments-sdk/cli/core so it doesn't need to be installed
|
|
75
|
-
// Using CommonJS format to avoid ESM/CJS interop issues with node_modules
|
|
104
|
+
// Use esbuild to bundle the fragment file.
|
|
105
|
+
// We inject a shim for @fragments-sdk/cli/core so it doesn't need to be installed.
|
|
76
106
|
await build({
|
|
77
107
|
entryPoints: [absolutePath],
|
|
78
108
|
outfile: tempFile,
|
|
79
109
|
bundle: true,
|
|
80
|
-
format: '
|
|
110
|
+
format: 'esm',
|
|
81
111
|
target: 'es2022',
|
|
82
112
|
jsx: 'automatic',
|
|
83
113
|
platform: 'node',
|
|
@@ -114,7 +144,7 @@ export async function loadFragmentFile(
|
|
|
114
144
|
|
|
115
145
|
const fileUrl = pathToFileURL(tempFile).href;
|
|
116
146
|
const module = await import(fileUrl);
|
|
117
|
-
return module.default ?? null;
|
|
147
|
+
return unwrapFragmentExport(module.default ?? null);
|
|
118
148
|
} finally {
|
|
119
149
|
// Clean up temp file
|
|
120
150
|
try {
|
|
Binary file
|
|
@@ -52,7 +52,10 @@ export function VariantPreviewCard({
|
|
|
52
52
|
.filter(Boolean)
|
|
53
53
|
.join(' ');
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
// Use defaultTab as a signal: when 'preview' is requested, a preview IS expected
|
|
56
|
+
// even if children/isLoading haven't arrived yet (async hook still settling).
|
|
57
|
+
// Always use tabbed layout so code stays hidden in its tab.
|
|
58
|
+
const hasPreview = !!children || !!isLoading || defaultTab === 'preview';
|
|
56
59
|
const hasCode = typeof code === 'string' && code.length > 0;
|
|
57
60
|
|
|
58
61
|
// No preview, code only — render without tabs
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/config.ts","../src/core/generators/typescript-extractor.ts","../src/core/generators/registry.ts","../src/core/generators/context.ts","../src/core/loader.ts","../src/core/parser.ts","../src/core/previewLoader.ts","../src/core/importAnalyzer.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { resolve, dirname } from 'node:path';\nimport { createJiti } from 'jiti';\nimport { BRAND, fragmentsConfigSchema } from '@fragments-sdk/core';\nimport type { FragmentsConfig, StorybookFilterConfig } from '@fragments-sdk/core';\n\nconst STORYBOOK_FILTER_DEFAULTS: StorybookFilterConfig = {\n excludeDeprecated: true,\n excludeTests: true,\n excludeSvgIcons: true,\n excludeSubComponents: true,\n};\n\nconst DEFAULT_CONFIG: FragmentsConfig = {\n include: [\n `src/**/*${BRAND.fileExtension}`, // *.fragment.tsx files\n 'src/**/*.stories.tsx', // Storybook stories (auto-converted)\n ],\n exclude: ['**/node_modules/**'],\n components: ['src/**/index.tsx', 'src/**/*.tsx'],\n framework: 'react',\n storybook: STORYBOOK_FILTER_DEFAULTS,\n snippets: {\n mode: 'warn',\n scope: 'snippet+render',\n requireFullSnippet: true,\n allowedExternalModules: ['@phosphor-icons/react', 'recharts', 'react-day-picker'],\n },\n};\n\n/**\n * Find the config file in the current directory or parent directories.\n * Checks for both the current config file name and the legacy name.\n */\nexport function findConfigFile(startDir: string = process.cwd()): string | null {\n let currentDir = startDir;\n\n while (currentDir !== dirname(currentDir)) {\n // Check for current config file name first\n const configPath = resolve(currentDir, BRAND.configFile);\n if (existsSync(configPath)) {\n return configPath;\n }\n // Also check for legacy config file name\n const legacyConfigPath = resolve(currentDir, BRAND.legacyConfigFile);\n if (existsSync(legacyConfigPath)) {\n return legacyConfigPath;\n }\n currentDir = dirname(currentDir);\n }\n\n return null;\n}\n\n/**\n * Load and validate the config file\n */\nexport async function loadConfig(configPath?: string): Promise<{\n config: FragmentsConfig;\n configDir: string;\n}> {\n const resolvedPath = configPath ?? findConfigFile();\n\n if (!resolvedPath) {\n return {\n config: DEFAULT_CONFIG,\n configDir: process.cwd(),\n };\n }\n\n try {\n // Use jiti to load TypeScript config files\n const jiti = createJiti(import.meta.url, {\n interopDefault: true,\n });\n const rawConfig = await jiti.import(resolvedPath);\n\n const result = fragmentsConfigSchema.safeParse(rawConfig);\n\n if (!result.success) {\n const errors = result.error.errors\n .map((e) => ` - ${e.path.join('.')}: ${e.message}`)\n .join('\\n');\n throw new Error(`Invalid config in ${resolvedPath}:\\n${errors}`);\n }\n\n const merged: FragmentsConfig = { ...DEFAULT_CONFIG, ...result.data };\n\n // Deep-merge storybook filter defaults so consumers only override what they need\n merged.storybook = { ...STORYBOOK_FILTER_DEFAULTS, ...result.data?.storybook };\n\n return {\n config: merged,\n configDir: dirname(resolvedPath),\n };\n } catch (error) {\n if (error instanceof Error && error.message.includes('Invalid config')) {\n throw error;\n }\n throw new Error(`Failed to load config from ${resolvedPath}: ${error}`);\n }\n}\n","/**\n * TypeScript Props Extractor\n * Extracts prop types, default values, and JSDoc comments from React component files\n */\n\nimport ts from \"typescript\";\nimport { readFileSync } from \"node:fs\";\nimport type { RegistryPropEntry } from '@fragments-sdk/core';\n\n/**\n * Result of extracting props from a component file\n */\nexport interface ExtractedProps {\n /** Component name */\n componentName: string;\n /** Whether the component uses export default */\n isDefaultExport?: boolean;\n /** Props interface name (e.g., \"ButtonProps\") */\n propsInterfaceName?: string;\n /** Extracted props */\n props: Record<string, RegistryPropEntry>;\n /** Named exports from the file */\n exports: string[];\n /** Import statements (for dependency tracking) */\n imports: string[];\n}\n\n/**\n * Extract props from a TypeScript/TSX component file\n */\nexport function extractPropsFromFile(filePath: string): ExtractedProps | null {\n const sourceText = readFileSync(filePath, \"utf-8\");\n return extractPropsFromSource(sourceText, filePath);\n}\n\n/**\n * Extract props from TypeScript source code\n */\nexport function extractPropsFromSource(\n sourceText: string,\n fileName = \"component.tsx\"\n): ExtractedProps | null {\n const sourceFile = ts.createSourceFile(\n fileName,\n sourceText,\n ts.ScriptTarget.Latest,\n true,\n fileName.endsWith(\".tsx\") ? ts.ScriptKind.TSX : ts.ScriptKind.TS\n );\n\n const result: ExtractedProps = {\n componentName: \"\",\n props: {},\n exports: [],\n imports: [],\n };\n\n // Find all exports and props interfaces\n const propsInterfaces = new Map<string, ts.InterfaceDeclaration | ts.TypeAliasDeclaration>();\n const componentExports: string[] = [];\n const defaultExports = new Set<string>();\n const importedModules: string[] = [];\n\n ts.forEachChild(sourceFile, (node) => {\n // Track imports\n if (ts.isImportDeclaration(node)) {\n const moduleSpecifier = node.moduleSpecifier;\n if (ts.isStringLiteral(moduleSpecifier)) {\n importedModules.push(moduleSpecifier.text);\n }\n }\n\n // Find interface declarations (e.g., interface ButtonProps { ... })\n if (ts.isInterfaceDeclaration(node)) {\n const name = node.name.text;\n if (name.endsWith(\"Props\")) {\n propsInterfaces.set(name, node);\n }\n }\n\n // Find type alias declarations (e.g., type ButtonProps = { ... })\n if (ts.isTypeAliasDeclaration(node)) {\n const name = node.name.text;\n if (name.endsWith(\"Props\")) {\n propsInterfaces.set(name, node);\n }\n }\n\n // Find exported functions/components\n if (ts.isFunctionDeclaration(node) && node.name) {\n const hasExport = node.modifiers?.some(\n (m) => m.kind === ts.SyntaxKind.ExportKeyword\n );\n const hasDefault = node.modifiers?.some(\n (m) => m.kind === ts.SyntaxKind.DefaultKeyword\n );\n if (hasExport) {\n componentExports.push(node.name.text);\n if (hasDefault) {\n defaultExports.add(node.name.text);\n }\n }\n }\n\n // Find exported variable declarations (e.g., export const Button = ...)\n if (ts.isVariableStatement(node)) {\n const hasExport = node.modifiers?.some(\n (m) => m.kind === ts.SyntaxKind.ExportKeyword\n );\n if (hasExport) {\n for (const decl of node.declarationList.declarations) {\n if (ts.isIdentifier(decl.name)) {\n componentExports.push(decl.name.text);\n }\n }\n }\n }\n\n // Find export declarations (e.g., export { Button })\n if (ts.isExportDeclaration(node) && node.exportClause) {\n if (ts.isNamedExports(node.exportClause)) {\n for (const element of node.exportClause.elements) {\n componentExports.push(element.name.text);\n }\n }\n }\n });\n\n result.exports = componentExports;\n result.imports = importedModules;\n\n // Find the main component (first PascalCase export)\n const mainComponent = componentExports.find(\n (name) => /^[A-Z]/.test(name) && !name.endsWith(\"Props\")\n );\n\n if (!mainComponent) {\n return null;\n }\n\n result.componentName = mainComponent;\n result.isDefaultExport = defaultExports.has(mainComponent);\n\n // Find matching props interface\n const propsInterfaceName = `${mainComponent}Props`;\n const propsInterface = propsInterfaces.get(propsInterfaceName);\n\n if (propsInterface) {\n result.propsInterfaceName = propsInterfaceName;\n result.props = extractPropsFromInterface(propsInterface, sourceFile);\n }\n\n return result;\n}\n\n/**\n * Extract props from an interface or type alias declaration\n */\nfunction extractPropsFromInterface(\n node: ts.InterfaceDeclaration | ts.TypeAliasDeclaration,\n sourceFile: ts.SourceFile\n): Record<string, RegistryPropEntry> {\n const props: Record<string, RegistryPropEntry> = {};\n\n // Handle interface declaration\n if (ts.isInterfaceDeclaration(node)) {\n for (const member of node.members) {\n if (ts.isPropertySignature(member) && member.name) {\n const propName = member.name.getText(sourceFile);\n const prop = extractPropFromMember(member, sourceFile);\n if (prop) {\n props[propName] = prop;\n }\n }\n }\n }\n\n // Handle type alias declaration\n if (ts.isTypeAliasDeclaration(node)) {\n const typeNode = node.type;\n if (ts.isTypeLiteralNode(typeNode)) {\n for (const member of typeNode.members) {\n if (ts.isPropertySignature(member) && member.name) {\n const propName = member.name.getText(sourceFile);\n const prop = extractPropFromMember(member, sourceFile);\n if (prop) {\n props[propName] = prop;\n }\n }\n }\n }\n }\n\n return props;\n}\n\n/**\n * Extract prop info from a property signature\n */\nfunction extractPropFromMember(\n member: ts.PropertySignature,\n sourceFile: ts.SourceFile\n): RegistryPropEntry | null {\n const entry: RegistryPropEntry = {};\n\n // Check if required\n entry.required = !member.questionToken;\n\n // Get type\n if (member.type) {\n const typeInfo = parseTypeNode(member.type, sourceFile);\n entry.type = typeInfo.type;\n entry.typeKind = typeInfo.typeKind;\n if (typeInfo.options) {\n entry.options = typeInfo.options;\n }\n }\n\n // Get JSDoc comment\n const jsDocComment = getJSDocComment(member);\n if (jsDocComment) {\n entry.description = jsDocComment;\n }\n\n // Get default value from JSDoc @default tag\n const defaultValue = getJSDocDefault(member);\n if (defaultValue !== undefined) {\n entry.default = defaultValue;\n }\n\n return entry;\n}\n\n/**\n * Parse a TypeScript type node into a simplified representation\n */\nfunction parseTypeNode(\n typeNode: ts.TypeNode,\n sourceFile: ts.SourceFile\n): { type: string; typeKind: RegistryPropEntry[\"typeKind\"]; options?: string[] } {\n // String\n if (typeNode.kind === ts.SyntaxKind.StringKeyword) {\n return { type: \"string\", typeKind: \"string\" };\n }\n\n // Number\n if (typeNode.kind === ts.SyntaxKind.NumberKeyword) {\n return { type: \"number\", typeKind: \"number\" };\n }\n\n // Boolean\n if (typeNode.kind === ts.SyntaxKind.BooleanKeyword) {\n return { type: \"boolean\", typeKind: \"boolean\" };\n }\n\n // Union type (string literal union for enums)\n if (ts.isUnionTypeNode(typeNode)) {\n const options: string[] = [];\n let allLiterals = true;\n\n for (const subType of typeNode.types) {\n if (ts.isLiteralTypeNode(subType)) {\n if (ts.isStringLiteral(subType.literal)) {\n options.push(subType.literal.text);\n } else if (subType.literal.kind === ts.SyntaxKind.TrueKeyword) {\n options.push(\"true\");\n } else if (subType.literal.kind === ts.SyntaxKind.FalseKeyword) {\n options.push(\"false\");\n } else {\n allLiterals = false;\n }\n } else {\n allLiterals = false;\n }\n }\n\n if (allLiterals && options.length > 0) {\n return {\n type: options.map((o) => `\"${o}\"`).join(\" | \"),\n typeKind: \"enum\",\n options,\n };\n }\n\n return {\n type: typeNode.getText(sourceFile),\n typeKind: \"union\",\n };\n }\n\n // Function type\n if (ts.isFunctionTypeNode(typeNode)) {\n return {\n type: typeNode.getText(sourceFile),\n typeKind: \"function\",\n };\n }\n\n // Array type\n if (ts.isArrayTypeNode(typeNode)) {\n return {\n type: typeNode.getText(sourceFile),\n typeKind: \"array\",\n };\n }\n\n // Type reference (e.g., ReactNode, React.ReactElement)\n if (ts.isTypeReferenceNode(typeNode)) {\n const typeName = typeNode.typeName.getText(sourceFile);\n\n // React types\n if (typeName === \"ReactNode\" || typeName === \"React.ReactNode\") {\n return { type: \"ReactNode\", typeKind: \"node\" };\n }\n if (typeName === \"ReactElement\" || typeName === \"React.ReactElement\") {\n return { type: \"ReactElement\", typeKind: \"element\" };\n }\n if (typeName === \"JSX.Element\") {\n return { type: \"JSX.Element\", typeKind: \"element\" };\n }\n\n return {\n type: typeNode.getText(sourceFile),\n typeKind: \"object\",\n };\n }\n\n // Object type literal\n if (ts.isTypeLiteralNode(typeNode)) {\n return {\n type: typeNode.getText(sourceFile),\n typeKind: \"object\",\n };\n }\n\n // Default: unknown\n return {\n type: typeNode.getText(sourceFile),\n typeKind: \"unknown\",\n };\n}\n\n/**\n * Get JSDoc comment from a node\n */\nfunction getJSDocComment(node: ts.Node): string | undefined {\n const jsDocTags = ts.getJSDocTags(node);\n const jsDoc = (node as unknown as { jsDoc?: ts.JSDoc[] }).jsDoc;\n\n if (jsDoc && jsDoc.length > 0) {\n const comment = jsDoc[0].comment;\n if (typeof comment === \"string\") {\n return comment;\n }\n if (Array.isArray(comment)) {\n return comment.map((c) => (typeof c === \"string\" ? c : c.text)).join(\"\");\n }\n }\n\n return undefined;\n}\n\n/**\n * Get @default value from JSDoc\n */\nfunction getJSDocDefault(node: ts.Node): unknown | undefined {\n const jsDocTags = ts.getJSDocTags(node);\n\n for (const tag of jsDocTags) {\n if (tag.tagName.text === \"default\") {\n const comment = tag.comment;\n if (typeof comment === \"string\") {\n // Try to parse as JSON\n try {\n return JSON.parse(comment);\n } catch {\n return comment;\n }\n }\n }\n }\n\n return undefined;\n}\n","/**\n * Registry Generator\n * Generates .fragments/registry.json and .fragments/index.json\n *\n * Philosophy: Generate only what AI agents and humans can't easily get from source.\n * - Props: AI can read TypeScript directly (skip by default)\n * - Paths: Essential for file navigation (always include)\n * - Enrichment: Human knowledge that doesn't exist elsewhere (include references)\n */\n\nimport { readFileSync, existsSync } from \"node:fs\";\nimport { relative, dirname, basename, join } from \"node:path\";\nimport fg from \"fast-glob\";\nimport { BRAND } from '@fragments-sdk/core';\nimport type {\n Fragment,\n FragmentRegistry,\n FragmentIndex,\n RegistryComponentEntry,\n RegistryOptions,\n} from '@fragments-sdk/core';\nimport { extractPropsFromFile } from \"./typescript-extractor.js\";\n\n/**\n * Options for registry generation\n */\nexport interface RegistryGeneratorOptions {\n /** Project root directory */\n projectRoot: string;\n /** Glob patterns for component files */\n componentPatterns?: string[];\n /** Glob patterns for story files */\n storyPatterns?: string[];\n /** Path to .fragments directory */\n fragmentsDir?: string;\n /** Registry options from config */\n registryOptions?: RegistryOptions;\n}\n\n/**\n * Result of registry generation\n */\nexport interface RegistryGeneratorResult {\n /** Generated registry (full metadata) */\n registry: FragmentRegistry;\n /** Generated index (minimal name -> path) */\n index: FragmentIndex;\n /** Errors encountered during generation */\n errors: Array<{ file: string; error: string }>;\n /** Warnings */\n warnings: Array<{ file: string; warning: string }>;\n}\n\n/**\n * Generate a fragment registry and index by scanning the project\n */\nexport async function generateRegistry(\n options: RegistryGeneratorOptions\n): Promise<RegistryGeneratorResult> {\n const {\n projectRoot,\n componentPatterns = [\"src/**/*.tsx\", \"src/**/*.ts\"],\n storyPatterns = [\"src/**/*.stories.tsx\", \"src/**/*.stories.ts\"],\n fragmentsDir = join(projectRoot, BRAND.dataDir),\n registryOptions = {},\n } = options;\n\n const {\n requireStory = false,\n publicOnly = false,\n categoryDepth = 1,\n includeProps = false,\n embedFragments = false,\n } = registryOptions;\n\n const errors: Array<{ file: string; error: string }> = [];\n const warnings: Array<{ file: string; warning: string }> = [];\n\n // Find all story files first (for requireStory filtering)\n const storyFiles = await fg(storyPatterns, {\n cwd: projectRoot,\n ignore: [\"**/node_modules/**\"],\n absolute: true,\n });\n\n // Build a map of story files by component directory and base name\n const storyMap = new Map<string, string>();\n for (const storyPath of storyFiles) {\n const storyDir = dirname(storyPath);\n const storyBase = basename(storyPath).replace(/\\.stories\\.(tsx?|jsx?)$/, \"\");\n storyMap.set(`${storyDir}/${storyBase}`, storyPath);\n }\n\n // Find all component files\n const componentFiles = await fg(componentPatterns, {\n cwd: projectRoot,\n ignore: [\n \"**/node_modules/**\",\n \"**/*.stories.*\",\n \"**/*.test.*\",\n \"**/*.spec.*\",\n \"**/*.d.ts\",\n ],\n absolute: true,\n });\n\n // Find all fragment files\n const fragmentPattern = join(\n BRAND.dataDir,\n BRAND.componentsDir,\n `*${BRAND.fileExtension}`\n );\n const fragmentFiles = await fg(fragmentPattern, {\n cwd: projectRoot,\n absolute: true,\n });\n\n // Build fragment lookup map\n const fragmentMap = new Map<string, { path: string; fragment: Fragment }>();\n for (const fragmentPath of fragmentFiles) {\n const fragmentName = basename(fragmentPath).replace(BRAND.fileExtension, \"\");\n try {\n const content = readFileSync(fragmentPath, \"utf-8\");\n const fragment = JSON.parse(content) as Fragment;\n fragmentMap.set(fragmentName, {\n path: relative(projectRoot, fragmentPath),\n fragment,\n });\n } catch (e) {\n errors.push({\n file: fragmentPath,\n error: `Failed to parse fragment: ${e instanceof Error ? e.message : String(e)}`,\n });\n }\n }\n\n // Build component index\n const components: Record<string, RegistryComponentEntry> = {};\n const indexComponents: Record<string, string> = {};\n const categories: Record<string, string[]> = {};\n\n // Process component files\n for (const filePath of componentFiles) {\n try {\n const extracted = extractPropsFromFile(filePath);\n if (!extracted || !extracted.componentName) {\n continue;\n }\n\n const componentName = extracted.componentName;\n const relativePath = relative(projectRoot, filePath);\n\n // Check if component is exported (for publicOnly filter)\n if (publicOnly && !extracted.exports.includes(componentName)) {\n continue;\n }\n\n // Find matching story file\n const componentDir = dirname(filePath);\n const baseNameWithoutExt = basename(filePath).replace(/\\.(tsx?|jsx?)$/, \"\");\n const storyPath = storyMap.get(`${componentDir}/${baseNameWithoutExt}`);\n\n // Apply requireStory filter\n if (requireStory && !storyPath) {\n continue;\n }\n\n // Get fragment data if exists\n const fragmentData = fragmentMap.get(componentName);\n\n // Determine category from directory structure\n const category = fragmentData?.fragment?.meta?.status\n ? undefined // Don't use status as category\n : getCategoryFromPath(relativePath, categoryDepth);\n\n // Check if fragment has meaningful enrichment (not just a skeleton)\n const hasEnrichment = fragmentData\n ? hasRealEnrichment(fragmentData.fragment)\n : false;\n\n // Build minimal component entry\n const entry: RegistryComponentEntry = {\n path: relativePath,\n };\n\n // Add optional fields only if present\n if (storyPath) {\n entry.storyPath = relative(projectRoot, storyPath);\n }\n\n if (fragmentData) {\n entry.fragmentPath = fragmentData.path;\n if (hasEnrichment) {\n entry.hasEnrichment = true;\n }\n if (fragmentData.fragment.description) {\n entry.description = fragmentData.fragment.description;\n }\n if (fragmentData.fragment.meta?.status) {\n entry.status = fragmentData.fragment.meta.status;\n }\n // Only embed full fragment if explicitly requested\n if (embedFragments) {\n entry.fragment = fragmentData.fragment;\n }\n }\n\n if (category) {\n entry.category = category;\n // Add to categories index\n if (!categories[category]) {\n categories[category] = [];\n }\n categories[category].push(componentName);\n }\n\n // Only include props if explicitly requested\n if (includeProps && extracted.props) {\n entry.props = extracted.props;\n }\n\n // Only include exports if multiple exports\n if (extracted.exports.length > 1) {\n entry.exports = extracted.exports;\n }\n\n components[componentName] = entry;\n indexComponents[componentName] = relativePath;\n } catch (e) {\n errors.push({\n file: filePath,\n error: `Failed to extract component: ${e instanceof Error ? e.message : String(e)}`,\n });\n }\n }\n\n const componentCount = Object.keys(components).length;\n\n // Build registry\n const registry: FragmentRegistry = {\n $schema: \"https://fragments.dev/schema/registry-v1.json\",\n version: \"1.0\",\n generatedAt: new Date().toISOString(),\n componentCount,\n components,\n categories,\n };\n\n // Build minimal index\n const index: FragmentIndex = {\n version: \"1.0\",\n generatedAt: registry.generatedAt,\n components: indexComponents,\n categories,\n };\n\n return { registry, index, errors, warnings };\n}\n\n/**\n * Get category from file path based on directory structure\n *\n * Examples:\n * - src/components/buttons/Button.tsx -> \"buttons\"\n * - src/components/forms/inputs/TextInput.tsx -> \"forms\" (depth 1) or \"forms/inputs\" (depth 2)\n * - src/components/Button/Button.tsx -> \"Button\" (component folder)\n */\nfunction getCategoryFromPath(relativePath: string, depth: number = 1): string | undefined {\n const parts = relativePath.split(\"/\");\n const componentsIndex = parts.findIndex((p) => p === \"components\");\n\n if (componentsIndex === -1) {\n return undefined;\n }\n\n // Get the parts after \"components/\"\n const afterComponents = parts.slice(componentsIndex + 1);\n\n // If it's just components/Button.tsx, no category\n if (afterComponents.length <= 1) {\n return undefined;\n }\n\n // If it's components/Button/Button.tsx (component folder pattern), no category\n const folderName = afterComponents[0];\n const fileName = afterComponents[afterComponents.length - 1].replace(/\\.(tsx?|jsx?)$/, \"\");\n if (afterComponents.length === 2 && folderName === fileName) {\n return undefined;\n }\n\n // Get category parts based on depth\n const categoryParts = afterComponents.slice(0, Math.min(depth, afterComponents.length - 1));\n\n // Filter out component folders (where folder name matches file name)\n const lastCategoryPart = categoryParts[categoryParts.length - 1];\n if (lastCategoryPart === fileName) {\n categoryParts.pop();\n }\n\n if (categoryParts.length === 0) {\n return undefined;\n }\n\n return categoryParts.join(\"/\");\n}\n\n/**\n * Check if a fragment has meaningful enrichment beyond a skeleton\n */\nfunction hasRealEnrichment(fragment: Fragment): boolean {\n // Has description beyond just the name\n if (fragment.description && fragment.description.length > 20) {\n return true;\n }\n\n // Has usage guidelines\n if (fragment.usage?.when && fragment.usage.when.length > 0) {\n return true;\n }\n if (fragment.usage?.doNot && fragment.usage.doNot.length > 0) {\n return true;\n }\n if (fragment.usage?.patterns && fragment.usage.patterns.length > 0) {\n return true;\n }\n\n // Has accessibility info\n if (fragment.accessibility?.requirements && fragment.accessibility.requirements.length > 0) {\n return true;\n }\n\n // Has figma links\n if (fragment.figma?.nodeId || fragment.figma?.variants) {\n return true;\n }\n\n // Has related components\n if (fragment.related?.similar && fragment.related.similar.length > 0) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Resolve component name to path using registry\n */\nexport function resolveComponentPath(\n componentName: string,\n registry: FragmentRegistry\n): string | undefined {\n const entry = registry.components[componentName];\n return entry?.path;\n}\n\n/**\n * Get all components by category\n */\nexport function getComponentsByCategory(\n category: string,\n registry: FragmentRegistry\n): string[] {\n return registry.categories?.[category] || [];\n}\n","/**\n * Context.md Generator\n * Generates a consolidated AI-ready context file from the fragment registry\n *\n * Philosophy: Focus on human-authored semantic knowledge that AI can't get from source.\n * - Usage guidelines: When to use, when not to use\n * - Relationships: Similar components, alternatives\n * - Accessibility: Requirements and keyboard patterns\n * - DO NOT: Duplicate prop types (AI can read TypeScript directly)\n */\n\nimport type {\n FragmentRegistry,\n RegistryComponentEntry,\n RegistryPropEntry,\n FragmentDoNotItem,\n FragmentContextOptions,\n} from '@fragments-sdk/core';\n\n/**\n * Result of context generation\n */\nexport interface ContextGeneratorResult {\n /** Generated markdown content */\n content: string;\n /** Estimated token count */\n tokenEstimate: number;\n /** Component count */\n componentCount: number;\n}\n\n/**\n * Generate context.md from a fragment registry\n */\nexport function generateContextMd(\n registry: FragmentRegistry,\n options: FragmentContextOptions = {}\n): ContextGeneratorResult {\n const {\n format = \"markdown\",\n compact = false,\n include = { props: true, relations: true, code: false },\n } = options;\n\n if (format === \"json\") {\n return generateJsonContext(registry, include, compact);\n }\n\n return generateMarkdownContext(registry, include, compact);\n}\n\n/**\n * Generate markdown context\n */\nfunction generateMarkdownContext(\n registry: FragmentRegistry,\n include: { props?: boolean; relations?: boolean; code?: boolean },\n compact: boolean\n): ContextGeneratorResult {\n const lines: string[] = [];\n const componentNames = Object.keys(registry.components).sort();\n const componentCount = componentNames.length;\n\n // Header\n lines.push(\"# Component Library Context\");\n lines.push(`Generated: ${new Date().toISOString().split(\"T\")[0]} | Components: ${componentCount}`);\n lines.push(\"\");\n\n // Quick reference table\n lines.push(\"## Quick Reference\");\n lines.push(\"\");\n lines.push(\"| Component | Path | Category | Status |\");\n lines.push(\"|-----------|------|----------|--------|\");\n\n for (const name of componentNames) {\n const entry = registry.components[name];\n const status = entry.status || \"stable\";\n const category = entry.category || \"-\";\n lines.push(`| ${name} | ${entry.path} | ${category} | ${status} |`);\n }\n\n lines.push(\"\");\n\n // In compact mode, stop here\n if (compact) {\n const content = lines.join(\"\\n\");\n return {\n content,\n tokenEstimate: estimateTokens(content),\n componentCount,\n };\n }\n\n // Full documentation for each component\n lines.push(\"---\");\n lines.push(\"\");\n\n for (const name of componentNames) {\n const entry = registry.components[name];\n const fragment = entry.fragment;\n\n lines.push(`## ${name}`);\n lines.push(`**Path:** \\`${entry.path}\\``);\n\n if (entry.category) {\n lines.push(`**Category:** ${entry.category} | **Status:** ${entry.status || \"stable\"}`);\n }\n lines.push(\"\");\n\n // Description\n if (entry.description || fragment?.description) {\n lines.push(\"### Description\");\n lines.push(entry.description || fragment?.description || \"\");\n lines.push(\"\");\n }\n\n // Usage guidelines\n if (fragment?.usage) {\n if (fragment.usage.when && fragment.usage.when.length > 0) {\n lines.push(\"### When to Use\");\n for (const when of fragment.usage.when) {\n lines.push(`- ${when}`);\n }\n lines.push(\"\");\n }\n\n if (fragment.usage.doNot && fragment.usage.doNot.length > 0) {\n lines.push(\"### Do Not\");\n for (const doNotItem of fragment.usage.doNot) {\n if (typeof doNotItem === \"string\") {\n lines.push(`- ${doNotItem}`);\n } else {\n const item = doNotItem as FragmentDoNotItem;\n if (item.instead) {\n // Resolve component path\n const alternativePath = resolveComponentPath(item.instead, registry);\n if (alternativePath) {\n lines.push(`- ${item.text} → use **${item.instead}** (\\`${alternativePath}\\`)`);\n } else {\n lines.push(`- ${item.text} → use **${item.instead}**`);\n }\n } else {\n lines.push(`- ${item.text}`);\n }\n }\n }\n lines.push(\"\");\n }\n\n if (include.code && fragment.usage.patterns && fragment.usage.patterns.length > 0) {\n lines.push(\"### Patterns\");\n for (const pattern of fragment.usage.patterns) {\n lines.push(`**${pattern.name}**`);\n if (pattern.description) {\n lines.push(pattern.description);\n }\n lines.push(\"```tsx\");\n lines.push(pattern.code);\n lines.push(\"```\");\n lines.push(\"\");\n }\n }\n }\n\n // Props\n if (include.props && entry.props && Object.keys(entry.props).length > 0) {\n lines.push(\"### Props\");\n lines.push(\"| Prop | Type | Default | Description |\");\n lines.push(\"|------|------|---------|-------------|\");\n\n for (const [propName, prop] of Object.entries(entry.props)) {\n const type = formatPropType(prop);\n const defaultVal = prop.default !== undefined ? `\\`${JSON.stringify(prop.default)}\\`` : \"-\";\n const desc = prop.description || \"-\";\n const required = prop.required ? \" (required)\" : \"\";\n lines.push(`| ${propName}${required} | ${type} | ${defaultVal} | ${desc} |`);\n }\n lines.push(\"\");\n }\n\n // Accessibility\n if (fragment?.accessibility) {\n lines.push(\"### Accessibility\");\n if (fragment.accessibility.role) {\n lines.push(`**Role:** ${fragment.accessibility.role}`);\n }\n if (fragment.accessibility.requirements && fragment.accessibility.requirements.length > 0) {\n for (const req of fragment.accessibility.requirements) {\n lines.push(`- ${req}`);\n }\n }\n if (fragment.accessibility.keyboard) {\n lines.push(\"\");\n lines.push(\"**Keyboard:**\");\n for (const [key, action] of Object.entries(fragment.accessibility.keyboard)) {\n lines.push(`- \\`${key}\\`: ${action}`);\n }\n }\n lines.push(\"\");\n }\n\n // Related components\n if (include.relations && fragment?.related) {\n lines.push(\"### Related\");\n if (fragment.related.similar && fragment.related.similar.length > 0) {\n const resolved = fragment.related.similar.map((comp) => {\n const path = resolveComponentPath(comp, registry);\n return path ? `${comp} (\\`${path}\\`)` : comp;\n });\n lines.push(`- **Similar:** ${resolved.join(\", \")}`);\n }\n if (fragment.related.composedWith && fragment.related.composedWith.length > 0) {\n const resolved = fragment.related.composedWith.map((comp) => {\n const path = resolveComponentPath(comp, registry);\n return path ? `${comp} (\\`${path}\\`)` : comp;\n });\n lines.push(`- **Composed with:** ${resolved.join(\", \")}`);\n }\n if (fragment.related.usedIn && fragment.related.usedIn.length > 0) {\n const resolved = fragment.related.usedIn.map((comp) => {\n const path = resolveComponentPath(comp, registry);\n return path ? `${comp} (\\`${path}\\`)` : comp;\n });\n lines.push(`- **Used in:** ${resolved.join(\", \")}`);\n }\n lines.push(\"\");\n }\n\n lines.push(\"---\");\n lines.push(\"\");\n }\n\n const content = lines.join(\"\\n\");\n return {\n content,\n tokenEstimate: estimateTokens(content),\n componentCount,\n };\n}\n\n/**\n * Generate JSON context\n */\nfunction generateJsonContext(\n registry: FragmentRegistry,\n include: { props?: boolean; relations?: boolean; code?: boolean },\n compact: boolean\n): ContextGeneratorResult {\n const componentNames = Object.keys(registry.components).sort();\n const componentCount = componentNames.length;\n\n interface JsonComponent {\n path: string;\n category?: string;\n status?: string;\n description?: string;\n whenToUse?: string[];\n doNot?: Array<{ text: string; instead?: string; insteadPath?: string }>;\n props?: Record<string, {\n type: string;\n required?: boolean;\n default?: unknown;\n description?: string;\n }>;\n related?: {\n similar?: Array<{ name: string; path?: string }>;\n composedWith?: Array<{ name: string; path?: string }>;\n usedIn?: Array<{ name: string; path?: string }>;\n };\n }\n\n const components: Record<string, JsonComponent> = {};\n\n for (const name of componentNames) {\n const entry = registry.components[name];\n const fragment = entry.fragment;\n\n const component: JsonComponent = {\n path: entry.path,\n };\n\n if (entry.category) component.category = entry.category;\n if (entry.status) component.status = entry.status;\n if (entry.description || fragment?.description) {\n component.description = entry.description || fragment?.description;\n }\n\n if (!compact && fragment?.usage) {\n if (fragment.usage.when && fragment.usage.when.length > 0) {\n component.whenToUse = fragment.usage.when;\n }\n\n if (fragment.usage.doNot && fragment.usage.doNot.length > 0) {\n component.doNot = fragment.usage.doNot.map((item) => {\n if (typeof item === \"string\") {\n return { text: item };\n }\n const doNotItem = item as FragmentDoNotItem;\n const result: { text: string; instead?: string; insteadPath?: string } = {\n text: doNotItem.text,\n };\n if (doNotItem.instead) {\n result.instead = doNotItem.instead;\n result.insteadPath = resolveComponentPath(doNotItem.instead, registry);\n }\n return result;\n });\n }\n }\n\n if (!compact && include.props && entry.props) {\n component.props = {};\n for (const [propName, prop] of Object.entries(entry.props)) {\n component.props[propName] = {\n type: formatPropType(prop),\n };\n if (prop.required) component.props[propName].required = true;\n if (prop.default !== undefined) component.props[propName].default = prop.default;\n if (prop.description) component.props[propName].description = prop.description;\n }\n }\n\n if (!compact && include.relations && fragment?.related) {\n component.related = {};\n if (fragment.related.similar) {\n component.related.similar = fragment.related.similar.map((name) => ({\n name,\n path: resolveComponentPath(name, registry),\n }));\n }\n if (fragment.related.composedWith) {\n component.related.composedWith = fragment.related.composedWith.map((name) => ({\n name,\n path: resolveComponentPath(name, registry),\n }));\n }\n if (fragment.related.usedIn) {\n component.related.usedIn = fragment.related.usedIn.map((name) => ({\n name,\n path: resolveComponentPath(name, registry),\n }));\n }\n }\n\n components[name] = component;\n }\n\n const output = {\n version: \"1.0\",\n generatedAt: registry.generatedAt,\n componentCount,\n categories: registry.categories,\n components,\n };\n\n const content = JSON.stringify(output, null, 2);\n return {\n content,\n tokenEstimate: estimateTokens(content),\n componentCount,\n };\n}\n\n/**\n * Resolve component name to path\n */\nfunction resolveComponentPath(\n componentName: string,\n registry: FragmentRegistry\n): string | undefined {\n return registry.components[componentName]?.path;\n}\n\n/**\n * Format prop type for display\n */\nfunction formatPropType(prop: RegistryPropEntry): string {\n if (prop.options && prop.options.length > 0) {\n return prop.options.map((o) => `\"${o}\"`).join(\" \\\\| \");\n }\n return prop.type || \"unknown\";\n}\n\n/**\n * Estimate token count (rough: ~4 chars per token)\n */\nfunction estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n","import { writeFile, unlink } from 'node:fs/promises';\nimport { dirname, basename, join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { build, type Plugin } from 'esbuild';\nimport { BRAND } from '@fragments-sdk/core';\nimport type { FragmentDefinition } from '@fragments-sdk/core';\n\n// Inline implementation of defineFragment that will be injected into bundled files\n// This allows fragment files to work without @fragments/core being installed\nconst DEFINE_FRAGMENT_SHIM = `\nexport function defineFragment(def) {\n return def;\n}\nexport function defineBlock(def) {\n return def;\n}\nexport function defineRecipe(def) {\n return def;\n}\n`;\n\n/**\n * Creates an esbuild plugin that replaces @fragments/core imports with an inline shim.\n * This allows fragment files to be loaded without @fragments/core being installed in the target project.\n */\nfunction createFragmentsCoreShimPlugin(): Plugin {\n return {\n name: BRAND.vitePluginNamespace,\n setup(build) {\n // Intercept @fragments-sdk/cli/core imports\n build.onResolve({ filter: /^@fragments-sdk\\/cli\\/core$/ }, (args) => {\n return {\n path: args.path,\n namespace: BRAND.vitePluginNamespace,\n };\n });\n\n // Return the shim content\n build.onLoad({ filter: /.*/, namespace: BRAND.vitePluginNamespace }, () => {\n return {\n contents: DEFINE_FRAGMENT_SHIM,\n loader: 'js',\n };\n });\n },\n };\n}\n\n/**\n * Load a fragment file, handling TSX/TS transformation automatically.\n * Uses esbuild to bundle and transform TypeScript/JSX before importing.\n */\nexport async function loadFragmentFile(\n absolutePath: string\n): Promise<FragmentDefinition | null> {\n const ext = absolutePath.split('.').pop()?.toLowerCase();\n const needsTransform = ext === 'tsx' || ext === 'ts' || ext === 'jsx';\n\n if (!needsTransform) {\n // Plain JS file, import directly\n const fileUrl = pathToFileURL(absolutePath).href;\n const module = await import(fileUrl);\n return module.default ?? null;\n }\n\n // Bundle the file with all its local dependencies\n const sourceDir = dirname(absolutePath);\n const baseName = basename(absolutePath, `.${ext}`);\n // Use .cjs extension to ensure CommonJS evaluation\n const tempFile = join(sourceDir, `.${baseName}.fragments-temp-${Date.now()}.cjs`);\n\n try {\n // Use esbuild to bundle the fragment file\n // We inject a shim for @fragments-sdk/cli/core so it doesn't need to be installed\n // Using CommonJS format to avoid ESM/CJS interop issues with node_modules\n await build({\n entryPoints: [absolutePath],\n outfile: tempFile,\n bundle: true,\n format: 'cjs', // Use CommonJS to avoid ESM issues with lodash, etc.\n target: 'es2022',\n jsx: 'automatic',\n platform: 'node',\n plugins: [createFragmentsCoreShimPlugin()],\n // Externalize all node_modules - we only need fragment metadata, not component code\n packages: 'external',\n // Also explicitly list patterns for nested imports\n external: [\n // React and its subpaths\n 'react',\n 'react-dom',\n 'react/*',\n 'react-dom/*',\n ],\n // Don't emit sourcemaps for temp files\n sourcemap: false,\n // Suppress warnings\n logLevel: 'silent',\n // Use loader to ignore style imports\n loader: {\n '.scss': 'empty',\n '.css': 'empty',\n '.svg': 'empty',\n '.png': 'empty',\n '.jpg': 'empty',\n '.jpeg': 'empty',\n '.gif': 'empty',\n '.woff': 'empty',\n '.woff2': 'empty',\n '.ttf': 'empty',\n '.eot': 'empty',\n },\n });\n\n const fileUrl = pathToFileURL(tempFile).href;\n const module = await import(fileUrl);\n return module.default ?? null;\n } finally {\n // Clean up temp file\n try {\n await unlink(tempFile);\n } catch {\n // Ignore cleanup errors\n }\n }\n}\n\n/**\n * Load multiple fragment files in parallel with error handling.\n */\nexport async function loadFragmentFiles(\n absolutePaths: string[]\n): Promise<Map<string, FragmentDefinition | Error>> {\n const results = new Map<string, FragmentDefinition | Error>();\n\n await Promise.all(\n absolutePaths.map(async (path) => {\n try {\n const fragment = await loadFragmentFile(path);\n if (fragment) {\n results.set(path, fragment);\n } else {\n results.set(path, new Error('No default export found'));\n }\n } catch (error) {\n results.set(\n path,\n error instanceof Error ? error : new Error(String(error))\n );\n }\n })\n );\n\n return results;\n}\n","/**\n * AST-Based Fragment Parser\n *\n * Extracts fragment metadata from .fragment.tsx files WITHOUT executing them.\n * This allows `fragments build` to work without any project dependencies.\n *\n * Uses TypeScript's compiler API to parse and analyze the AST.\n */\n\nimport ts from \"typescript\";\nimport type { FragmentMeta, FragmentUsage, PropDefinition, AIMetadata, FragmentContract } from '@fragments-sdk/core';\n\n/**\n * Parsed fragment metadata (extracted statically from AST)\n */\nexport interface ParsedFragmentMetadata {\n /** Component import path (e.g., \"./Button\" or \"@/components/Button\") */\n componentImport: string | null;\n\n /** Component name as used in the file */\n componentName: string | null;\n\n /** Component metadata */\n meta: Partial<FragmentMeta>;\n\n /** Usage guidelines */\n usage: Partial<FragmentUsage>;\n\n /** Props documentation */\n props: Record<string, Partial<PropDefinition>>;\n\n /** Variant definitions */\n variants: Array<{\n name: string;\n description: string;\n code?: string;\n figma?: string;\n args?: Record<string, unknown>;\n }>;\n\n /** Related components */\n relations: Array<{\n component: string;\n relationship: string;\n note: string;\n }>;\n\n /** AI-specific metadata for playground context generation */\n ai?: AIMetadata;\n\n /** Agent-optimized contract metadata */\n contract?: FragmentContract;\n\n /** Parse warnings */\n warnings: string[];\n}\n\n/**\n * Parse a fragment file and extract metadata without executing it.\n */\nexport function parseFragmentFile(\n fileContent: string,\n filePath?: string\n): ParsedFragmentMetadata {\n const warnings: string[] = [];\n\n // Parse the file\n const sourceFile = ts.createSourceFile(\n filePath ?? \"fragment.tsx\",\n fileContent,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TSX\n );\n\n // Find imports\n const imports = extractImports(sourceFile);\n\n // Find the defineFragment call\n const defineFragmentCall = findDefineFragmentCall(sourceFile);\n\n if (!defineFragmentCall) {\n warnings.push(\"No defineFragment() call found\");\n return {\n componentImport: null,\n componentName: null,\n meta: {},\n usage: { when: [], whenNot: [] },\n props: {},\n variants: [],\n relations: [],\n warnings,\n };\n }\n\n // Extract the argument (object literal)\n const arg = defineFragmentCall.arguments[0];\n if (!arg || !ts.isObjectLiteralExpression(arg)) {\n warnings.push(\"defineFragment() argument is not an object literal\");\n return {\n componentImport: null,\n componentName: null,\n meta: {},\n usage: { when: [], whenNot: [] },\n props: {},\n variants: [],\n relations: [],\n warnings,\n };\n }\n\n // Extract component reference\n const componentProp = findProperty(arg, \"component\");\n let componentName: string | null = null;\n let componentImport: string | null = null;\n\n if (componentProp && ts.isIdentifier(componentProp)) {\n componentName = componentProp.text;\n // Find the import for this component\n componentImport = imports.get(componentName) ?? null;\n }\n\n // Extract meta\n const meta = extractMeta(arg, warnings);\n\n // Extract usage\n const usage = extractUsage(arg, warnings);\n\n // Extract props\n const props = extractProps(arg, warnings);\n\n // Extract variants\n const variants = extractVariants(arg, sourceFile, warnings);\n\n // Extract relations\n const relations = extractRelations(arg, warnings);\n\n // Extract AI metadata\n const ai = extractAIMetadata(arg, warnings);\n\n // Extract contract metadata\n const contract = extractContractMetadata(arg);\n\n return {\n componentImport,\n componentName,\n meta,\n usage,\n props,\n variants,\n relations,\n ai,\n contract,\n warnings,\n };\n}\n\n/**\n * Extract all imports from the source file.\n * Returns a map of imported name -> module path\n */\nfunction extractImports(sourceFile: ts.SourceFile): Map<string, string> {\n const imports = new Map<string, string>();\n\n ts.forEachChild(sourceFile, (node) => {\n if (ts.isImportDeclaration(node)) {\n const moduleSpecifier = node.moduleSpecifier;\n if (ts.isStringLiteral(moduleSpecifier)) {\n const modulePath = moduleSpecifier.text;\n\n // Handle named imports\n const importClause = node.importClause;\n if (importClause) {\n // Default import\n if (importClause.name) {\n imports.set(importClause.name.text, modulePath);\n }\n\n // Named imports\n const namedBindings = importClause.namedBindings;\n if (namedBindings && ts.isNamedImports(namedBindings)) {\n for (const element of namedBindings.elements) {\n imports.set(element.name.text, modulePath);\n }\n }\n }\n }\n }\n });\n\n return imports;\n}\n\n/**\n * Find the defineFragment() call in the source file.\n */\nfunction findDefineFragmentCall(\n sourceFile: ts.SourceFile\n): ts.CallExpression | null {\n let result: ts.CallExpression | null = null;\n\n function visit(node: ts.Node): void {\n if (ts.isCallExpression(node)) {\n const expression = node.expression;\n if (ts.isIdentifier(expression) && expression.text === \"defineFragment\") {\n result = node;\n return;\n }\n }\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return result;\n}\n\n/**\n * Find a property in an object literal by name.\n */\nfunction findProperty(\n obj: ts.ObjectLiteralExpression,\n name: string\n): ts.Expression | null {\n for (const prop of obj.properties) {\n if (ts.isPropertyAssignment(prop)) {\n const propName = prop.name;\n if (ts.isIdentifier(propName) && propName.text === name) {\n return prop.initializer;\n }\n }\n }\n return null;\n}\n\n/**\n * Extract meta object from defineFragment call.\n */\nfunction extractMeta(\n arg: ts.ObjectLiteralExpression,\n warnings: string[]\n): Partial<FragmentMeta> {\n const metaProp = findProperty(arg, \"meta\");\n if (!metaProp || !ts.isObjectLiteralExpression(metaProp)) {\n warnings.push(\"No meta object found\");\n return {};\n }\n\n const meta: Partial<FragmentMeta> = {};\n\n // Extract string properties\n const name = extractStringProperty(metaProp, \"name\");\n if (name) meta.name = name;\n\n const description = extractStringProperty(metaProp, \"description\");\n if (description) meta.description = description;\n\n const category = extractStringProperty(metaProp, \"category\");\n if (category) meta.category = category;\n\n const status = extractStringProperty(metaProp, \"status\") as FragmentMeta[\"status\"];\n if (status) meta.status = status;\n\n const since = extractStringProperty(metaProp, \"since\");\n if (since) meta.since = since;\n\n // Extract figma URL\n const figma = extractStringProperty(metaProp, \"figma\");\n if (figma) meta.figma = figma;\n\n // Extract tags array\n const tags = extractStringArray(metaProp, \"tags\");\n if (tags.length > 0) meta.tags = tags;\n\n // Extract dependencies array\n const depsProp = findProperty(metaProp, \"dependencies\");\n if (depsProp && ts.isArrayLiteralExpression(depsProp)) {\n const deps = extractLiteralValue(depsProp) as Array<{ name: string; version: string; reason?: string }>;\n if (Array.isArray(deps) && deps.length > 0) {\n meta.dependencies = deps;\n }\n }\n\n return meta;\n}\n\n/**\n * Extract usage object from defineFragment call.\n */\nfunction extractUsage(\n arg: ts.ObjectLiteralExpression,\n warnings: string[]\n): Partial<FragmentUsage> {\n const usageProp = findProperty(arg, \"usage\");\n if (!usageProp || !ts.isObjectLiteralExpression(usageProp)) {\n return { when: [], whenNot: [] };\n }\n\n return {\n when: extractStringArray(usageProp, \"when\"),\n whenNot: extractStringArray(usageProp, \"whenNot\"),\n guidelines: extractStringArray(usageProp, \"guidelines\"),\n accessibility: extractStringArray(usageProp, \"accessibility\"),\n };\n}\n\n/**\n * Extract props object from defineFragment call.\n */\nfunction extractProps(\n arg: ts.ObjectLiteralExpression,\n warnings: string[]\n): Record<string, Partial<PropDefinition>> {\n const propsProp = findProperty(arg, \"props\");\n if (!propsProp || !ts.isObjectLiteralExpression(propsProp)) {\n return {};\n }\n\n const props: Record<string, Partial<PropDefinition>> = {};\n\n for (const prop of propsProp.properties) {\n if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {\n const propName = prop.name.text;\n const propValue = prop.initializer;\n\n if (ts.isObjectLiteralExpression(propValue)) {\n props[propName] = extractPropDefinition(propValue);\n }\n }\n }\n\n return props;\n}\n\n/**\n * Extract a single prop definition.\n */\nfunction extractPropDefinition(\n obj: ts.ObjectLiteralExpression\n): Partial<PropDefinition> {\n const def: Partial<PropDefinition> = {};\n\n const type = extractStringProperty(obj, \"type\");\n if (type) def.type = type as PropDefinition[\"type\"];\n\n const description = extractStringProperty(obj, \"description\");\n if (description) def.description = description;\n\n const values = extractStringArray(obj, \"values\");\n if (values.length > 0) def.values = values;\n\n const required = extractBooleanProperty(obj, \"required\");\n if (required !== null) def.required = required;\n\n // Default value - try to extract as literal\n const defaultProp = findProperty(obj, \"default\");\n if (defaultProp) {\n def.default = extractLiteralValue(defaultProp);\n }\n\n const constraints = extractStringArray(obj, \"constraints\");\n if (constraints.length > 0) def.constraints = constraints;\n\n return def;\n}\n\n/**\n * Extract variants array from defineFragment call.\n */\nfunction extractVariants(\n arg: ts.ObjectLiteralExpression,\n sourceFile: ts.SourceFile,\n warnings: string[]\n): Array<{ name: string; description: string; code?: string; figma?: string; args?: Record<string, unknown> }> {\n const variantsProp = findProperty(arg, \"variants\");\n if (!variantsProp || !ts.isArrayLiteralExpression(variantsProp)) {\n return [];\n }\n\n const variants: Array<{ name: string; description: string; code?: string; figma?: string; args?: Record<string, unknown> }> = [];\n\n for (const element of variantsProp.elements) {\n if (ts.isObjectLiteralExpression(element)) {\n const name = extractStringProperty(element, \"name\");\n const description = extractStringProperty(element, \"description\");\n\n if (name) {\n const variant: { name: string; description: string; code?: string; figma?: string; args?: Record<string, unknown> } = {\n name,\n description: description ?? \"\",\n };\n\n // Try to extract code property if present\n const codeProp = findProperty(element, \"code\");\n if (codeProp && (ts.isStringLiteral(codeProp) || ts.isNoSubstitutionTemplateLiteral(codeProp))) {\n variant.code = codeProp.text;\n }\n\n // Try to extract render function and convert to code string\n const renderProp = findProperty(element, \"render\");\n if (renderProp && !variant.code) {\n variant.code = extractRenderCode(renderProp, sourceFile);\n }\n\n // Extract figma URL for variant\n const figma = extractStringProperty(element, \"figma\");\n if (figma) {\n variant.figma = figma;\n }\n\n // Extract args object for code generation\n const argsProp = findProperty(element, \"args\");\n if (argsProp && ts.isObjectLiteralExpression(argsProp)) {\n const argsValue = extractLiteralValue(argsProp);\n if (argsValue && typeof argsValue === 'object' && !Array.isArray(argsValue)) {\n variant.args = argsValue as Record<string, unknown>;\n }\n }\n\n variants.push(variant);\n }\n }\n }\n\n return variants;\n}\n\n/**\n * Remove common leading whitespace from all lines (dedent).\n * This handles template literals and JSX that have extra indentation from code formatting.\n *\n * Special handling: If the first line has no indentation (common after .trim()),\n * we calculate minimum indent from subsequent lines only.\n */\nfunction dedent(str: string): string {\n const lines = str.split('\\n');\n\n if (lines.length <= 1) {\n return str;\n }\n\n // Check if first line has no indentation\n const firstLineIndent = lines[0].match(/^(\\s*)/)?.[1].length ?? 0;\n const startIndex = firstLineIndent === 0 ? 1 : 0;\n\n // Find the minimum indentation (ignoring empty lines)\n let minIndent = Infinity;\n for (let i = startIndex; i < lines.length; i++) {\n const line = lines[i];\n if (line.trim() === '') continue;\n const match = line.match(/^(\\s*)/);\n if (match) {\n minIndent = Math.min(minIndent, match[1].length);\n }\n }\n\n // If no indentation found, return as-is\n if (minIndent === Infinity || minIndent === 0) {\n return str;\n }\n\n // Remove the common indentation from all lines (except first if it had no indent)\n return lines\n .map((line, index) => {\n if (index === 0 && firstLineIndent === 0) {\n return line; // Keep first line as-is\n }\n return line.slice(minIndent);\n })\n .join('\\n');\n}\n\n/**\n * Extract the code from a render function.\n */\nfunction extractRenderCode(\n renderProp: ts.Expression,\n sourceFile: ts.SourceFile\n): string | undefined {\n // Handle arrow function: () => <Component />\n if (ts.isArrowFunction(renderProp)) {\n const body = renderProp.body;\n // Get the source text of the body\n const start = body.getStart(sourceFile);\n const end = body.getEnd();\n let code = sourceFile.text.substring(start, end).trim();\n\n // Remove parentheses if present\n if (code.startsWith(\"(\") && code.endsWith(\")\")) {\n code = code.slice(1, -1).trim();\n }\n\n // Dedent the code to remove common leading whitespace\n code = dedent(code);\n\n return code;\n }\n\n return undefined;\n}\n\n/**\n * Extract relations array from defineFragment call.\n */\nfunction extractRelations(\n arg: ts.ObjectLiteralExpression,\n warnings: string[]\n): Array<{ component: string; relationship: string; note: string }> {\n const relationsProp = findProperty(arg, \"relations\");\n if (!relationsProp || !ts.isArrayLiteralExpression(relationsProp)) {\n return [];\n }\n\n const relations: Array<{ component: string; relationship: string; note: string }> = [];\n\n for (const element of relationsProp.elements) {\n if (ts.isObjectLiteralExpression(element)) {\n const component = extractStringProperty(element, \"component\");\n const relationship = extractStringProperty(element, \"relationship\");\n const note = extractStringProperty(element, \"note\");\n\n if (component && relationship) {\n relations.push({\n component,\n relationship,\n note: note ?? \"\",\n });\n }\n }\n }\n\n return relations;\n}\n\n/**\n * Extract AI metadata from defineFragment call.\n */\nfunction extractAIMetadata(\n arg: ts.ObjectLiteralExpression,\n warnings: string[]\n): AIMetadata | undefined {\n const aiProp = findProperty(arg, \"ai\");\n if (!aiProp || !ts.isObjectLiteralExpression(aiProp)) {\n return undefined;\n }\n\n const ai: AIMetadata = {};\n\n // Extract compositionPattern\n const compositionPattern = extractStringProperty(aiProp, \"compositionPattern\");\n if (compositionPattern && ['compound', 'simple', 'controlled'].includes(compositionPattern)) {\n ai.compositionPattern = compositionPattern as AIMetadata['compositionPattern'];\n }\n\n // Extract subComponents array\n const subComponents = extractStringArray(aiProp, \"subComponents\");\n if (subComponents.length > 0) {\n ai.subComponents = subComponents;\n }\n\n // Extract requiredChildren array\n const requiredChildren = extractStringArray(aiProp, \"requiredChildren\");\n if (requiredChildren.length > 0) {\n ai.requiredChildren = requiredChildren;\n }\n\n // Extract commonPatterns array\n const commonPatterns = extractStringArray(aiProp, \"commonPatterns\");\n if (commonPatterns.length > 0) {\n ai.commonPatterns = commonPatterns;\n }\n\n // Only return if we have any fields\n if (Object.keys(ai).length > 0) {\n return ai;\n }\n\n return undefined;\n}\n\n/**\n * Extract contract metadata from defineFragment call.\n */\nfunction extractContractMetadata(\n arg: ts.ObjectLiteralExpression,\n): FragmentContract | undefined {\n const contractProp = findProperty(arg, \"contract\");\n if (!contractProp || !ts.isObjectLiteralExpression(contractProp)) {\n return undefined;\n }\n\n const contract: FragmentContract = {};\n\n // Extract propsSummary array\n const propsSummary = extractStringArray(contractProp, \"propsSummary\");\n if (propsSummary.length > 0) {\n contract.propsSummary = propsSummary;\n }\n\n // Extract a11yRules array\n const a11yRules = extractStringArray(contractProp, \"a11yRules\");\n if (a11yRules.length > 0) {\n contract.a11yRules = a11yRules;\n }\n\n // Only return if we have any fields\n if (Object.keys(contract).length > 0) {\n return contract;\n }\n\n return undefined;\n}\n\n/**\n * Extract a string property from an object literal.\n */\nfunction extractStringProperty(\n obj: ts.ObjectLiteralExpression,\n name: string\n): string | null {\n const prop = findProperty(obj, name);\n if (prop && ts.isStringLiteral(prop)) {\n return prop.text;\n }\n // Handle template literals without expressions\n if (prop && ts.isNoSubstitutionTemplateLiteral(prop)) {\n return prop.text;\n }\n return null;\n}\n\n/**\n * Extract a boolean property from an object literal.\n */\nfunction extractBooleanProperty(\n obj: ts.ObjectLiteralExpression,\n name: string\n): boolean | null {\n const prop = findProperty(obj, name);\n if (prop) {\n if (prop.kind === ts.SyntaxKind.TrueKeyword) return true;\n if (prop.kind === ts.SyntaxKind.FalseKeyword) return false;\n }\n return null;\n}\n\n/**\n * Extract a string array from an object literal.\n */\nfunction extractStringArray(\n obj: ts.ObjectLiteralExpression,\n name: string\n): string[] {\n const prop = findProperty(obj, name);\n if (!prop || !ts.isArrayLiteralExpression(prop)) {\n return [];\n }\n\n const result: string[] = [];\n for (const element of prop.elements) {\n if (ts.isStringLiteral(element)) {\n result.push(element.text);\n } else if (ts.isNoSubstitutionTemplateLiteral(element)) {\n result.push(element.text);\n }\n }\n return result;\n}\n\n/**\n * Extract a literal value from an expression.\n */\nfunction extractLiteralValue(expr: ts.Expression): unknown {\n if (ts.isStringLiteral(expr)) {\n return expr.text;\n }\n if (ts.isNumericLiteral(expr)) {\n return Number(expr.text);\n }\n if (expr.kind === ts.SyntaxKind.TrueKeyword) {\n return true;\n }\n if (expr.kind === ts.SyntaxKind.FalseKeyword) {\n return false;\n }\n if (expr.kind === ts.SyntaxKind.NullKeyword) {\n return null;\n }\n if (ts.isArrayLiteralExpression(expr)) {\n return expr.elements.map(extractLiteralValue);\n }\n if (ts.isObjectLiteralExpression(expr)) {\n const obj: Record<string, unknown> = {};\n for (const prop of expr.properties) {\n if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name)) {\n obj[prop.name.text] = extractLiteralValue(prop.initializer);\n }\n }\n return obj;\n }\n return undefined;\n}\n","/**\n * Loader for Storybook .storybook/preview.{tsx,ts,jsx,js} configuration.\n *\n * This module detects and loads Storybook preview configuration to extract:\n * - decorators: Global decorators applied to all stories\n * - parameters: Global parameters for all stories\n * - globalTypes: Global type definitions (e.g., for toolbar controls)\n * - args: Default args for all stories\n * - argTypes: Default argTypes for all stories\n * - loaders: Global loaders for all stories\n */\n\nimport { existsSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\nimport type { PreviewConfig } from '@fragments-sdk/core';\n\n/**\n * Possible file extensions and names for preview config\n */\nconst PREVIEW_FILES = [\n \"preview.tsx\",\n \"preview.ts\",\n \"preview.jsx\",\n \"preview.js\",\n];\n\n/**\n * Find the preview config file in a .storybook directory\n *\n * @param storybookDir - Path to the .storybook directory\n * @returns The full path to the preview file, or null if not found\n */\nexport function findPreviewConfigPath(storybookDir: string): string | null {\n for (const fileName of PREVIEW_FILES) {\n const filePath = join(storybookDir, fileName);\n if (existsSync(filePath)) {\n return filePath;\n }\n }\n return null;\n}\n\n/**\n * Find the .storybook directory starting from a project root.\n * Checks common locations.\n *\n * @param projectRoot - The project root directory\n * @returns The path to the .storybook directory, or null if not found\n */\nexport function findStorybookDir(projectRoot: string): string | null {\n const possiblePaths = [\n join(projectRoot, \".storybook\"),\n join(projectRoot, \"storybook\"),\n ];\n\n for (const dir of possiblePaths) {\n if (existsSync(dir)) {\n return dir;\n }\n }\n return null;\n}\n\n/**\n * Load and parse the Storybook preview configuration.\n *\n * This function dynamically imports the preview file and extracts\n * the relevant configuration exports.\n *\n * @param previewPath - Full path to the preview config file\n * @returns The parsed preview configuration\n */\nexport async function loadPreviewConfig(\n previewPath: string\n): Promise<PreviewConfig> {\n try {\n // Dynamic import with file:// URL for ESM compatibility\n const fileUrl = new URL(`file://${resolve(previewPath)}`);\n const module = await import(fileUrl.href);\n\n // Extract configuration from the module\n const config: PreviewConfig = {\n decorators: module.decorators ?? module.default?.decorators ?? [],\n parameters: module.parameters ?? module.default?.parameters ?? {},\n globalTypes: module.globalTypes ?? module.default?.globalTypes ?? {},\n args: module.args ?? module.default?.args ?? {},\n argTypes: module.argTypes ?? module.default?.argTypes ?? {},\n loaders: module.loaders ?? module.default?.loaders ?? [],\n };\n\n return config;\n } catch (error) {\n console.warn(\n `[Fragments] Failed to load preview config from ${previewPath}:`,\n error instanceof Error ? error.message : error\n );\n return {};\n }\n}\n\n/**\n * Auto-detect and load preview configuration from a project.\n *\n * @param projectRoot - The project root directory\n * @returns The preview configuration, or empty config if not found\n */\nexport async function autoLoadPreviewConfig(\n projectRoot: string\n): Promise<PreviewConfig> {\n const storybookDir = findStorybookDir(projectRoot);\n if (!storybookDir) {\n return {};\n }\n\n const previewPath = findPreviewConfigPath(storybookDir);\n if (!previewPath) {\n return {};\n }\n\n return loadPreviewConfig(previewPath);\n}\n\n/**\n * Generate a virtual module that imports and re-exports preview config.\n * This is used in the Vite plugin to make preview config available at runtime.\n *\n * @param previewPath - Full path to the preview config file, or null\n * @returns JavaScript code for the virtual module\n */\nexport function generatePreviewModule(previewPath: string | null): string {\n if (!previewPath) {\n // No preview config found - export empty defaults\n return `\nexport const decorators = [];\nexport const parameters = {};\nexport const globalTypes = {};\nexport const args = {};\nexport const argTypes = {};\nexport const loaders = [];\n\nexport default {\n decorators,\n parameters,\n globalTypes,\n args,\n argTypes,\n loaders,\n};\n`;\n }\n\n // Import from the actual preview file and re-export\n return `\nimport * as preview from \"${previewPath}\";\n\nexport const decorators = preview.decorators ?? preview.default?.decorators ?? [];\nexport const parameters = preview.parameters ?? preview.default?.parameters ?? {};\nexport const globalTypes = preview.globalTypes ?? preview.default?.globalTypes ?? {};\nexport const args = preview.args ?? preview.default?.args ?? {};\nexport const argTypes = preview.argTypes ?? preview.default?.argTypes ?? {};\nexport const loaders = preview.loaders ?? preview.default?.loaders ?? [];\n\nexport default {\n decorators,\n parameters,\n globalTypes,\n args,\n argTypes,\n loaders,\n};\n`;\n}\n","/**\n * AST-based import analysis for detecting component relationships\n *\n * Analyzes TypeScript/JavaScript files to find which components import others,\n * providing accurate \"used by\" relationships for the component graph.\n *\n * @deprecated Import analysis is now handled by graph-extractor.ts which provides\n * richer edge-typed relationships via the ComponentGraph. These functions are\n * maintained for backward compatibility. For new code, use\n * `buildComponentGraph()` from `./graph-extractor.js` instead.\n */\n\nimport ts from 'typescript';\nimport { readFileSync } from 'node:fs';\nimport { resolve, dirname, basename } from 'node:path';\n\nexport interface ComponentImport {\n /** Name of the imported component */\n name: string;\n /** Import path (relative or package) */\n path: string;\n /** Whether this is a default import */\n isDefault: boolean;\n /** Whether this is a namespace import */\n isNamespace: boolean;\n}\n\nexport interface ImportAnalysisResult {\n /** Source file path */\n filePath: string;\n /** Component name extracted from file */\n componentName: string;\n /** List of component imports found */\n imports: ComponentImport[];\n}\n\n/**\n * Extract component name from a file path\n */\nfunction extractComponentNameFromPath(filePath: string): string {\n const fileName = basename(filePath);\n\n // Handle index.tsx files - use parent directory name\n if (fileName === 'index.tsx' || fileName === 'index.ts' || fileName === 'index.jsx' || fileName === 'index.js') {\n const parentDir = basename(dirname(filePath));\n return parentDir;\n }\n\n // Remove extension and common suffixes\n return fileName\n .replace(/\\.(tsx?|jsx?)$/, '')\n .replace(/\\.stories$/, '')\n .replace(/\\.fragment$/, '')\n .replace(/\\.fragment$/, '');\n}\n\n/**\n * Check if an import path looks like a component import (not a utility/library)\n */\nfunction isComponentImportPath(importPath: string): boolean {\n // Skip node_modules packages\n if (!importPath.startsWith('.') && !importPath.startsWith('/')) {\n return false;\n }\n\n // Skip common utility/hook patterns\n const skipPatterns = [\n /\\/hooks\\//,\n /\\/utils\\//,\n /\\/helpers\\//,\n /\\/lib\\//,\n /\\/types\\//,\n /\\/constants\\//,\n /\\/styles\\//,\n /\\/context\\//,\n /\\.css$/,\n /\\.scss$/,\n /\\.less$/,\n /\\.json$/,\n ];\n\n for (const pattern of skipPatterns) {\n if (pattern.test(importPath)) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Check if an imported name looks like a React component (PascalCase)\n */\nfunction isPascalCase(name: string): boolean {\n return /^[A-Z][a-zA-Z0-9]*$/.test(name);\n}\n\n/**\n * Analyze a single file for component imports\n */\nexport function analyzeFileImports(filePath: string): ImportAnalysisResult {\n const componentName = extractComponentNameFromPath(filePath);\n const imports: ComponentImport[] = [];\n\n let sourceText: string;\n try {\n sourceText = readFileSync(filePath, 'utf-8');\n } catch {\n return { filePath, componentName, imports };\n }\n\n const sourceFile = ts.createSourceFile(\n filePath,\n sourceText,\n ts.ScriptTarget.Latest,\n true,\n filePath.endsWith('.tsx') || filePath.endsWith('.jsx')\n ? ts.ScriptKind.TSX\n : ts.ScriptKind.TS\n );\n\n ts.forEachChild(sourceFile, (node) => {\n if (ts.isImportDeclaration(node)) {\n const moduleSpecifier = node.moduleSpecifier;\n if (!ts.isStringLiteral(moduleSpecifier)) return;\n\n const importPath = moduleSpecifier.text;\n\n // Skip non-component imports\n if (!isComponentImportPath(importPath)) return;\n\n const importClause = node.importClause;\n if (!importClause) return;\n\n // Default import: import Button from './Button'\n if (importClause.name) {\n const name = importClause.name.text;\n if (isPascalCase(name)) {\n imports.push({\n name,\n path: importPath,\n isDefault: true,\n isNamespace: false,\n });\n }\n }\n\n // Named imports: import { Button, Icon } from './components'\n const namedBindings = importClause.namedBindings;\n if (namedBindings) {\n if (ts.isNamedImports(namedBindings)) {\n for (const element of namedBindings.elements) {\n const name = element.name.text;\n if (isPascalCase(name)) {\n imports.push({\n name,\n path: importPath,\n isDefault: false,\n isNamespace: false,\n });\n }\n }\n } else if (ts.isNamespaceImport(namedBindings)) {\n // Namespace import: import * as Components from './components'\n // We can't reliably know what components are used without more analysis\n const name = namedBindings.name.text;\n imports.push({\n name,\n path: importPath,\n isDefault: false,\n isNamespace: true,\n });\n }\n }\n }\n });\n\n return { filePath, componentName, imports };\n}\n\n/**\n * Build a map of which components are imported by which files\n */\nexport function buildImportGraph(\n filePaths: string[]\n): Map<string, string[]> {\n // Map from component name -> list of component names that import it\n const importedBy = new Map<string, string[]>();\n\n for (const filePath of filePaths) {\n const result = analyzeFileImports(filePath);\n\n for (const imp of result.imports) {\n // Skip namespace imports for now\n if (imp.isNamespace) continue;\n\n const importedComponent = imp.name;\n const importingComponent = result.componentName;\n\n // Don't add self-references\n if (importedComponent === importingComponent) continue;\n\n const existing = importedBy.get(importedComponent) || [];\n if (!existing.includes(importingComponent)) {\n existing.push(importingComponent);\n importedBy.set(importedComponent, existing);\n }\n }\n }\n\n return importedBy;\n}\n\n/**\n * Get components that import a specific component\n */\nexport function getImportedBy(\n componentName: string,\n importGraph: Map<string, string[]>\n): string[] {\n return importGraph.get(componentName) || [];\n}\n"],"mappings":";;;;;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readFileSync","content","name","dirname","basename","join","build","dirname","basename","join","ts","existsSync","join","resolve","ts","readFileSync","dirname","basename"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|