{"version":3,"file":"plugins.cjs","names":["TreeNode","path","createFile","getRelativePath","#options","onProcessExit","TreeNode","Root","#renderPromise","clack"],"sources":["../src/plugins/definePlugin.ts","../src/plugins/barrelPlugin.ts","../src/plugins/fsPlugin.ts","../src/plugins/fsxPlugin/Runtime.ts","../src/plugins/fsxPlugin/fsxPlugin.ts","../src/plugins/loggerPlugin.ts"],"sourcesContent":["import type { Plugin, UserPlugin } from './types.ts'\n\n/**\n * Defines a Fabric plugin with type safety.\n *\n * Use this function to create plugins that hook into Fabric's lifecycle\n * events and extend its functionality.\n *\n * @param plugin - The plugin configuration object\n * @returns A typed plugin ready to use with Fabric\n *\n * @example\n * ```ts\n * import { definePlugin } from '@kubb/fabric-core'\n *\n * export const myPlugin = definePlugin({\n *   name: 'my-plugin',\n *   async setup(fabric) {\n *     fabric.context.on('write:start', (files) => {\n *       console.log(`Writing ${files.length} files`)\n *     })\n *   }\n * })\n * ```\n */\nexport function definePlugin<Options = unknown, TAppExtension extends Record<string, any> = {}>(\n  plugin: UserPlugin<Options, TAppExtension>,\n): Plugin<Options, TAppExtension> {\n  return {\n    type: 'plugin',\n    ...plugin,\n  }\n}\n","/** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */\n\nimport path from 'node:path'\nimport { createFile } from '../createFile.ts'\nimport type * as KubbFile from '../FabricFile.ts'\nimport { getRelativePath } from '../utils/getRelativePath.ts'\nimport { TreeNode } from '../utils/TreeNode.ts'\nimport { definePlugin } from './definePlugin.ts'\n\ntype Mode = 'all' | 'named' | 'propagate' | false\n\ntype Options = {\n  root: string\n  mode: Mode\n  dryRun?: boolean\n}\n\ntype WriteEntryOptions = {\n  root: string\n  mode: Mode\n}\n\ntype ExtendOptions = {\n  /**\n   * `fabric.writeEntry` should be called before `fabric.write`\n   */\n  writeEntry(options: WriteEntryOptions): Promise<void>\n}\n\ndeclare global {\n  namespace Kubb {\n    interface Fabric {\n      /**\n       * `fabric.writeEntry` should be called before `fabric.write`\n       */\n      writeEntry(options: WriteEntryOptions): Promise<void>\n    }\n  }\n}\n\ntype GetBarrelFilesOptions = {\n  files: KubbFile.File[]\n  root: string\n  mode: Mode\n}\n\nexport function getBarrelFiles({ files, root, mode }: GetBarrelFilesOptions): Array<KubbFile.File> {\n  // Do not generate when propagating or disabled\n  if (mode === 'propagate' || mode === false) {\n    return []\n  }\n\n  const indexableSourcesMap = new Map<KubbFile.File, Array<KubbFile.Source>>()\n\n  for (const file of files) {\n    const indexableSources: Array<KubbFile.Source> = []\n    for (const source of file.sources || []) {\n      if (source.isIndexable && source.name) {\n        indexableSources.push(source)\n      }\n    }\n    if (indexableSources.length > 0) {\n      indexableSourcesMap.set(file, indexableSources)\n    }\n  }\n\n  const cachedFiles = new Map<KubbFile.Path, KubbFile.File>()\n  const dedupe = new Map<KubbFile.Path, Set<string>>()\n\n  const treeNode = TreeNode.fromFiles(files, root)\n\n  if (!treeNode) {\n    return []\n  }\n\n  treeNode.forEach((node) => {\n    // Only create a barrel for directory-like nodes that have a parent with a path\n    if (!node?.children || !node.parent?.data.path) {\n      return\n    }\n\n    const parentPath = node.parent.data.path as KubbFile.Path\n    const barrelPath = path.join(parentPath, 'index.ts') as KubbFile.Path\n\n    let barrelFile = cachedFiles.get(barrelPath)\n    if (!barrelFile) {\n      barrelFile = createFile({\n        path: barrelPath,\n        baseName: 'index.ts',\n        imports: [],\n        exports: [],\n        sources: [],\n      })\n      cachedFiles.set(barrelPath, barrelFile)\n      dedupe.set(barrelPath, new Set<string>())\n    }\n\n    const seen = dedupe.get(barrelPath)!\n\n    for (const leaf of node.leaves) {\n      const file = leaf.data.file\n      if (!file?.path) {\n        continue\n      }\n\n      const indexableSources = indexableSourcesMap.get(file)\n      if (!indexableSources) {\n        continue\n      }\n\n      for (const source of indexableSources) {\n        const key = `${source.name}|${source.isTypeOnly ? '1' : '0'}`\n        if (seen.has(key)) {\n          continue\n        }\n        seen.add(key)\n\n        // Always compute relative path from the parent directory to the file path\n        barrelFile.exports!.push({\n          name: [source.name!],\n          path: getRelativePath(parentPath, file.path),\n          isTypeOnly: source.isTypeOnly,\n        })\n\n        barrelFile!.sources.push({\n          name: source.name!,\n          isTypeOnly: source.isTypeOnly,\n          value: '', // TODO use parser to generate import\n          isExportable: mode === 'all' || mode === 'named',\n          isIndexable: mode === 'all' || mode === 'named',\n        })\n      }\n    }\n  })\n\n  const result = [...cachedFiles.values()]\n\n  if (mode === 'all') {\n    return result.map((file) => ({\n      ...file,\n      exports: file.exports?.map((e) => ({ ...e, name: undefined })),\n    }))\n  }\n\n  return result\n}\n\nexport const barrelPlugin = definePlugin<Options, ExtendOptions>({\n  name: 'barrel',\n  install(ctx, options) {\n    if (!options) {\n      throw new Error('Barrel plugin requires options.root and options.mode')\n    }\n\n    if (!options.mode) {\n      return undefined\n    }\n\n    ctx.on('files:writing:start', async (files) => {\n      const root = options.root\n      const barrelFiles = getBarrelFiles({ files, root, mode: options.mode })\n\n      await ctx.fileManager.add(...barrelFiles)\n    })\n  },\n  inject(ctx, options) {\n    if (!options) {\n      throw new Error('Barrel plugin requires options.root and options.mode')\n    }\n\n    return {\n      async writeEntry({ root, mode }) {\n        if (!mode || mode === 'propagate') {\n          return undefined\n        }\n\n        const rootPath = path.resolve(root, 'index.ts')\n\n        const barrelFiles: Array<KubbFile.ResolvedFile> = []\n        for (const file of ctx.files) {\n          for (const source of file.sources) {\n            if (source.isIndexable) {\n              barrelFiles.push(file)\n\n              break\n            }\n          }\n        }\n\n        const fileTypeCache = new Map<KubbFile.ResolvedFile, boolean>()\n        for (const file of barrelFiles) {\n          fileTypeCache.set(\n            file,\n            file.sources.every((source) => source.isTypeOnly),\n          )\n        }\n\n        const exports: Array<KubbFile.Export> = []\n        for (const file of barrelFiles) {\n          const containsOnlyTypes = fileTypeCache.get(file) ?? false\n\n          for (const source of file.sources) {\n            if (!file.path || !source.isIndexable) {\n              continue\n            }\n\n            exports.push({\n              name: mode === 'all' ? undefined : [source.name],\n              path: getRelativePath(rootPath, file.path),\n              isTypeOnly: mode === 'all' ? containsOnlyTypes : source.isTypeOnly,\n            } as KubbFile.Export)\n          }\n        }\n\n        const entryFile = createFile({\n          path: rootPath,\n          baseName: 'index.ts',\n          imports: [],\n          exports,\n          sources: [],\n        })\n\n        await ctx.addFile(entryFile)\n\n        await ctx.fileManager.write({\n          mode: ctx.config.mode,\n          dryRun: options.dryRun,\n          parsers: ctx.installedParsers,\n        })\n      },\n    }\n  },\n})\n","import { rmSync } from 'node:fs'\nimport { mkdir, readFile, writeFile } from 'node:fs/promises'\nimport { dirname, resolve } from 'node:path'\nimport type * as KubbFile from '../FabricFile.ts'\nimport { definePlugin } from './definePlugin.ts'\n\ntype WriteOptions = {\n  extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n  dryRun?: boolean\n  /**\n   * Optional callback that is invoked whenever a file is written by the plugin.\n   * Useful for tests to observe write operations without spying on internal functions.\n   */\n  onBeforeWrite?: (path: string, data: string | undefined) => void | Promise<void>\n  clean?: {\n    path: string\n  }\n}\n\ntype ExtendOptions = {\n  write(options?: WriteOptions): Promise<void>\n}\n\nexport async function write(path: string, data: string | undefined, options: { sanity?: boolean } = {}): Promise<string | undefined> {\n  if (typeof Bun !== 'undefined') {\n    if (!data || data?.trim() === '') {\n      return undefined\n    }\n\n    await Bun.write(resolve(path), data.trim())\n\n    if (options?.sanity) {\n      const file = Bun.file(resolve(path))\n      const savedData = await file.text()\n\n      if (savedData?.toString() !== data?.toString()) {\n        throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n      }\n\n      return savedData\n    }\n\n    return data\n  }\n\n  if (!data || data?.trim() === '') {\n    return undefined\n  }\n\n  try {\n    const oldContent = await readFile(resolve(path), {\n      encoding: 'utf-8',\n    })\n    if (oldContent?.toString() === data?.toString()) {\n      return\n    }\n  } catch (_err) {\n    /* empty */\n  }\n\n  await mkdir(dirname(resolve(path)), { recursive: true })\n  await writeFile(resolve(path), data.trim(), { encoding: 'utf-8' })\n\n  if (options?.sanity) {\n    const savedData = await readFile(resolve(path), {\n      encoding: 'utf-8',\n    })\n\n    if (savedData?.toString() !== data?.toString()) {\n      throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n    }\n\n    return savedData\n  }\n\n  return data\n}\n\ndeclare global {\n  namespace Kubb {\n    interface Fabric {\n      write(options?: WriteOptions): Promise<void>\n    }\n  }\n}\n\nexport const fsPlugin = definePlugin<Options, ExtendOptions>({\n  name: 'fs',\n  install(ctx, options = {}) {\n    if (options.clean) {\n      rmSync(options.clean.path, { recursive: true, force: true })\n    }\n\n    ctx.on('file:processing:update', async ({ file, source }) => {\n      if (options.onBeforeWrite) {\n        await options.onBeforeWrite(file.path, source)\n      }\n      await write(file.path, source, { sanity: false })\n    })\n  },\n  inject(ctx, { dryRun } = {}) {\n    return {\n      async write(\n        options = {\n          extension: { '.ts': '.ts' },\n        },\n      ) {\n        await ctx.fileManager.write({\n          mode: ctx.config.mode,\n          extension: options.extension,\n          dryRun,\n          parsers: ctx.installedParsers,\n        })\n\n        await ctx.emit('lifecycle:end')\n      },\n    }\n  },\n})\n","import { Root } from '../../components/Root.ts'\nimport type { ComponentNode } from '../../composables/useNodeTree.ts'\nimport type { FabricElement } from '../../Fabric.ts'\nimport type { FileManager } from '../../FileManager.ts'\nimport { onProcessExit } from '../../utils/onProcessExit.ts'\nimport { TreeNode } from '../../utils/TreeNode.ts'\n\ntype Options = {\n  fileManager: FileManager\n  treeNode?: TreeNode<ComponentNode>\n  debug?: boolean\n}\n\nexport class Runtime {\n  readonly #options: Options\n  exitPromise?: Promise<void>\n\n  constructor(options: Options) {\n    this.#options = options\n\n    // Unmount when process exits\n    this.unsubscribeExit = onProcessExit((code) => {\n      this.unmount(code)\n    })\n  }\n\n  get fileManager() {\n    return this.#options.fileManager\n  }\n\n  #renderPromise: Promise<void> = Promise.resolve()\n  resolveExitPromise: () => void = () => {}\n  rejectExitPromise: (reason?: Error) => void = () => {}\n  unsubscribeExit: () => void = () => {}\n\n  onError(error: Error): void {\n    throw error\n  }\n\n  onExit(error?: Error): void {\n    setTimeout(() => {\n      this.unmount(error)\n    }, 0)\n  }\n\n  async render(node: FabricElement): Promise<string> {\n    const treeNode = this.#options.treeNode || new TreeNode<ComponentNode>({ type: 'Root', props: {} })\n\n    const props = {\n      fileManager: this.fileManager,\n      treeNode,\n      onExit: this.onExit.bind(this),\n      onError: this.onError.bind(this),\n    }\n\n    try {\n      treeNode.data.props = props\n\n      const element = Root({ ...props, children: node })\n\n      await this.#renderPromise\n\n      return element()?.toString() || ''\n    } catch (e) {\n      props.onError(e as Error)\n      return ''\n    }\n  }\n\n  unmount(error?: Error | number | null): void {\n    if (this.#options?.debug) {\n      console.log('Unmount', error)\n    }\n\n    this.unsubscribeExit()\n\n    if (error instanceof Error) {\n      this.rejectExitPromise(error)\n      return\n    }\n\n    this.resolveExitPromise()\n  }\n\n  async waitUntilExit(): Promise<void> {\n    if (!this.exitPromise) {\n      this.exitPromise = new Promise((resolve, reject) => {\n        this.resolveExitPromise = resolve\n        this.rejectExitPromise = reject\n      })\n    }\n\n    return this.exitPromise\n  }\n}\n","import type { ComponentNode } from '../../composables/useNodeTree.ts'\nimport type { FabricElement } from '../../Fabric.ts'\nimport { definePlugin } from '../../plugins/definePlugin.ts'\nimport type { TreeNode } from '../../utils/TreeNode.ts'\nimport { Runtime } from './Runtime.ts'\n\nexport type Options = {\n  treeNode?: TreeNode<ComponentNode>\n  /**\n   * Set this to true to always see the result of the render in the console(line per render)\n   */\n  debug?: boolean\n}\n\ntype ExtendOptions = {\n  render(Fabric: FabricElement<any>): Promise<string>\n  waitUntilExit(): Promise<void>\n}\n\ndeclare global {\n  namespace Kubb {\n    interface Fabric {\n      render(Fabric: FabricElement<any>): Promise<string>\n      waitUntilExit(): Promise<void>\n    }\n  }\n}\n\nexport const fsxPlugin = definePlugin<Options, ExtendOptions>({\n  name: 'fsx',\n  install() {},\n  inject(ctx, options = {}) {\n    const runtime = new Runtime({ fileManager: ctx.fileManager, ...options })\n\n    return {\n      async render(Fabric) {\n        await ctx.emit('lifecycle:start')\n        return runtime.render(Fabric)\n      },\n      async waitUntilExit() {\n        await runtime.waitUntilExit()\n      },\n    }\n  },\n})\n","import { relative } from 'node:path'\nimport { styleText } from 'node:util'\nimport * as clack from '@clack/prompts'\nimport { definePlugin } from './definePlugin.ts'\n\ntype Options = {\n  /**\n   * Toggle progress bar output.\n   * @default true\n   */\n  progress?: boolean\n}\n\nfunction pluralize(word: string, count: number) {\n  return `${count} ${word}${count === 1 ? '' : 's'}`\n}\n\nconst DEFAULT_PROGRESS_BAR_SIZE = 30\n\nexport const loggerPlugin = definePlugin<Options>({\n  name: 'logger',\n  install(ctx, options = {}) {\n    const { progress = true } = options\n\n    const state = {\n      spinner: clack.spinner(),\n      isSpinning: false,\n      progressBar: undefined as ReturnType<typeof clack.progress> | undefined,\n    }\n\n    function formatPath(path: string) {\n      return relative(process.cwd(), path)\n    }\n\n    ctx.on('lifecycle:start', async () => {\n      clack.intro(`${styleText('blue', 'Fabric')} ${styleText('dim', 'Starting run')}`)\n    })\n\n    ctx.on('lifecycle:render', async () => {\n      clack.log.info(`${styleText('blue', 'ℹ')} Rendering application graph`)\n    })\n\n    ctx.on('files:added', async (files) => {\n      if (!files.length) {\n        return\n      }\n\n      clack.log.info(`${styleText('blue', 'ℹ')} Queued ${pluralize('file', files.length)}`)\n    })\n\n    ctx.on('file:resolve:path', async (file) => {\n      clack.log.step(`Resolving path for ${styleText('dim', formatPath(file.path))}`)\n    })\n\n    ctx.on('file:resolve:name', async (file) => {\n      clack.log.step(`Resolving name for ${styleText('dim', formatPath(file.path))}`)\n    })\n\n    ctx.on('files:processing:start', async (files) => {\n      clack.log.step(`Processing ${styleText('green', pluralize('file', files.length))}`)\n\n      if (progress) {\n        state.progressBar = clack.progress({\n          style: 'block',\n          max: files.length,\n          size: DEFAULT_PROGRESS_BAR_SIZE,\n        })\n        state.progressBar.start(`Processing ${files.length} files`)\n      }\n    })\n\n    ctx.on('file:processing:start', async (file, index, total) => {\n      if (!state.progressBar) {\n        clack.log.step(`Processing ${styleText('dim', `[${index + 1}/${total}]`)} ${formatPath(file.path)}`)\n      }\n    })\n\n    ctx.on('file:processing:update', async ({ processed, total, percentage, file }) => {\n      if (state.progressBar) {\n        // undefined = auto-increment by 1\n        state.progressBar.advance(undefined, `Writing ${formatPath(file.path)}`)\n      } else {\n        const formattedPercentage = Number.isFinite(percentage) ? percentage.toFixed(1) : '0.0'\n        clack.log.step(`Progress ${styleText('green', `${formattedPercentage}%`)} ${styleText('dim', `(${processed}/${total})`)} → ${formatPath(file.path)}`)\n      }\n    })\n\n    ctx.on('file:processing:end', async (file, index, total) => {\n      if (state.progressBar) {\n        state.progressBar.message(`${styleText('green', '✓')} Finished ${styleText('dim', `[${index + 1}/${total}]`)} ${formatPath(file.path)}`)\n      } else {\n        clack.log.success(`${styleText('green', '✓')} Finished ${styleText('dim', `[${index + 1}/${total}]`)} ${formatPath(file.path)}`)\n      }\n    })\n\n    ctx.on('files:processing:end', async (files) => {\n      if (state.progressBar) {\n        state.progressBar.stop(`${styleText('green', '✓')} Processed ${pluralize('file', files.length)}`)\n        state.progressBar = undefined\n      } else {\n        clack.log.success(`${styleText('green', '✓')} Processed ${pluralize('file', files.length)}`)\n      }\n    })\n\n    ctx.on('lifecycle:end', async () => {\n      if (state.progressBar) {\n        state.progressBar.stop()\n        state.progressBar = undefined\n      }\n\n      clack.outro(`${styleText('blue', 'Fabric')} ${styleText('dim', 'completed')}`)\n    })\n  },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,aACd,QACgC;AAChC,QAAO;EACL,MAAM;EACN,GAAG;EACJ;;;;;ACeH,SAAgB,eAAe,EAAE,OAAO,MAAM,QAAqD;AAEjG,KAAI,SAAS,eAAe,SAAS,MACnC,Q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