@kubb/fabric-core 0.13.3 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/{Fabric-D4udrNnL.d.ts → Fabric-CFkgoZwY.d.ts} +2 -2
  2. package/dist/{chunk-DVipidnM.cjs → chunk-MlS0t1Af.cjs} +27 -37
  3. package/dist/{chunk-BVHe6Par.js → chunk-O_arW02_.js} +6 -11
  4. package/dist/defaultParser-D0_-Uy2Z.cjs +19 -0
  5. package/dist/{defaultParser-BK-zOanQ.cjs.map → defaultParser-D0_-Uy2Z.cjs.map} +1 -1
  6. package/dist/{defaultParser-BD_N68Bo.js → defaultParser-iCpMSYCp.js} +4 -5
  7. package/dist/{defaultParser-BD_N68Bo.js.map → defaultParser-iCpMSYCp.js.map} +1 -1
  8. package/dist/{getRelativePath-C4Au07ON.js → getRelativePath-NAm_Y-vp.js} +3 -6
  9. package/dist/{getRelativePath-C4Au07ON.js.map → getRelativePath-NAm_Y-vp.js.map} +1 -1
  10. package/dist/{getRelativePath-DpbA6qm5.cjs → getRelativePath-WX4HB169.cjs} +18 -21
  11. package/dist/{getRelativePath-DpbA6qm5.cjs.map → getRelativePath-WX4HB169.cjs.map} +1 -1
  12. package/dist/index.cjs +75 -93
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts +54 -55
  15. package/dist/index.js +71 -89
  16. package/dist/index.js.map +1 -1
  17. package/dist/{onProcessExit-BHrZkYzP.cjs → onProcessExit-C2AuepQI.cjs} +213 -227
  18. package/dist/onProcessExit-C2AuepQI.cjs.map +1 -0
  19. package/dist/{onProcessExit-CnZym153.js → onProcessExit-Cput7j2c.js} +124 -138
  20. package/dist/onProcessExit-Cput7j2c.js.map +1 -0
  21. package/dist/parsers/typescript.cjs +4 -5
  22. package/dist/parsers/typescript.cjs.map +1 -1
  23. package/dist/parsers/typescript.d.ts +2 -2
  24. package/dist/parsers/typescript.js +3 -4
  25. package/dist/parsers/typescript.js.map +1 -1
  26. package/dist/parsers.cjs +6 -7
  27. package/dist/parsers.cjs.map +1 -1
  28. package/dist/parsers.d.ts +2 -2
  29. package/dist/parsers.js +4 -5
  30. package/dist/parsers.js.map +1 -1
  31. package/dist/plugins.cjs +7 -13
  32. package/dist/plugins.cjs.map +1 -1
  33. package/dist/plugins.d.ts +6 -6
  34. package/dist/plugins.js +6 -12
  35. package/dist/plugins.js.map +1 -1
  36. package/dist/{RootContext-BEiEsH2Z.d.ts → types-BwR3_cUx.d.ts} +10 -5
  37. package/dist/types.cjs +13 -15
  38. package/dist/types.d.ts +4 -12
  39. package/dist/types.js +2 -3
  40. package/dist/{useNodeTree-CPJ6Y80N.d.ts → useNodeTree-Wc1WxA05.d.ts} +3 -3
  41. package/package.json +2 -2
  42. package/src/components/{App.ts → Fabric.ts} +8 -8
  43. package/src/composables/{useApp.ts → useFabric.ts} +4 -4
  44. package/src/contexts/{AppContext.ts → FabricContext.ts} +2 -2
  45. package/src/index.ts +4 -6
  46. package/src/plugins/fsxPlugin/fsxPlugin.ts +4 -4
  47. package/src/plugins/index.ts +1 -0
  48. package/dist/defaultParser-BK-zOanQ.cjs +0 -21
  49. package/dist/onProcessExit-BHrZkYzP.cjs.map +0 -1
  50. package/dist/onProcessExit-CnZym153.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"parsers.cjs","names":["defineParser","typescriptParser"],"sources":["../src/parsers/tsxParser.ts"],"sourcesContent":["import { defineParser } from './defineParser.ts'\nimport { typescriptParser } from './typescriptParser.ts'\n\nexport const tsxParser = defineParser({\n name: 'tsx',\n extNames: ['.tsx', '.jsx'],\n install() {},\n async parse(file, options = { extname: '.tsx' }) {\n return typescriptParser.parse(file, options)\n },\n})\n"],"mappings":";;;;;;;AAGA,MAAa,YAAYA,qCAAa;CACpC,MAAM;CACN,UAAU,CAAC,QAAQ,OAAO;CAC1B,UAAU;CACV,MAAM,MAAM,MAAM,UAAU,EAAE,SAAS,QAAQ,EAAE;AAC/C,SAAOC,4CAAiB,MAAM,MAAM,QAAQ;;CAE/C,CAAC"}
1
+ {"version":3,"file":"parsers.cjs","names":["defineParser","typescriptParser"],"sources":["../src/parsers/tsxParser.ts"],"sourcesContent":["import { defineParser } from './defineParser.ts'\nimport { typescriptParser } from './typescriptParser.ts'\n\nexport const tsxParser = defineParser({\n name: 'tsx',\n extNames: ['.tsx', '.jsx'],\n install() {},\n async parse(file, options = { extname: '.tsx' }) {\n return typescriptParser.parse(file, options)\n },\n})\n"],"mappings":";;;;;;AAGA,MAAa,YAAYA,wBAAAA,aAAa;CACpC,MAAM;CACN,UAAU,CAAC,QAAQ,OAAO;CAC1B,UAAU;CACV,MAAM,MAAM,MAAM,UAAU,EAAE,SAAS,QAAQ,EAAE;AAC/C,SAAOC,2BAAAA,iBAAiB,MAAM,MAAM,QAAQ;;CAE/C,CAAC"}
package/dist/parsers.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { n as __name } from "./chunk-BVHe6Par.js";
2
- import { C as UserParser, S as Parser } from "./Fabric-D4udrNnL.js";
1
+ import { n as __name } from "./chunk-O_arW02_.js";
2
+ import { C as UserParser, S as Parser } from "./Fabric-CFkgoZwY.js";
3
3
  import { typescriptParser } from "./parsers/typescript.js";
4
4
 
5
5
  //#region src/parsers/defaultParser.d.ts
package/dist/parsers.js CHANGED
@@ -1,8 +1,7 @@
1
- import { n as __name } from "./chunk-BVHe6Par.js";
2
- import { n as defineParser } from "./getRelativePath-C4Au07ON.js";
3
- import { t as defaultParser } from "./defaultParser-BD_N68Bo.js";
1
+ import "./chunk-O_arW02_.js";
2
+ import { n as defineParser } from "./getRelativePath-NAm_Y-vp.js";
3
+ import { t as defaultParser } from "./defaultParser-iCpMSYCp.js";
4
4
  import { typescriptParser } from "./parsers/typescript.js";
5
-
6
5
  //#region src/parsers/tsxParser.ts
7
6
  const tsxParser = defineParser({
8
7
  name: "tsx",
@@ -12,7 +11,7 @@ const tsxParser = defineParser({
12
11
  return typescriptParser.parse(file, options);
13
12
  }
14
13
  });
15
-
16
14
  //#endregion
17
15
  export { defaultParser, defineParser, tsxParser, typescriptParser };
16
+
18
17
  //# sourceMappingURL=parsers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parsers.js","names":[],"sources":["../src/parsers/tsxParser.ts"],"sourcesContent":["import { defineParser } from './defineParser.ts'\nimport { typescriptParser } from './typescriptParser.ts'\n\nexport const tsxParser = defineParser({\n name: 'tsx',\n extNames: ['.tsx', '.jsx'],\n install() {},\n async parse(file, options = { extname: '.tsx' }) {\n return typescriptParser.parse(file, options)\n },\n})\n"],"mappings":";;;;;;AAGA,MAAa,YAAY,aAAa;CACpC,MAAM;CACN,UAAU,CAAC,QAAQ,OAAO;CAC1B,UAAU;CACV,MAAM,MAAM,MAAM,UAAU,EAAE,SAAS,QAAQ,EAAE;AAC/C,SAAO,iBAAiB,MAAM,MAAM,QAAQ;;CAE/C,CAAC"}
1
+ {"version":3,"file":"parsers.js","names":[],"sources":["../src/parsers/tsxParser.ts"],"sourcesContent":["import { defineParser } from './defineParser.ts'\nimport { typescriptParser } from './typescriptParser.ts'\n\nexport const tsxParser = defineParser({\n name: 'tsx',\n extNames: ['.tsx', '.jsx'],\n install() {},\n async parse(file, options = { extname: '.tsx' }) {\n return typescriptParser.parse(file, options)\n },\n})\n"],"mappings":";;;;;AAGA,MAAa,YAAY,aAAa;CACpC,MAAM;CACN,UAAU,CAAC,QAAQ,OAAO;CAC1B,UAAU;CACV,MAAM,MAAM,MAAM,UAAU,EAAE,SAAS,QAAQ,EAAE;AAC/C,SAAO,iBAAiB,MAAM,MAAM,QAAQ;;CAE/C,CAAC"}
package/dist/plugins.cjs CHANGED
@@ -1,7 +1,7 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_chunk = require('./chunk-DVipidnM.cjs');
3
- const require_onProcessExit = require('./onProcessExit-BHrZkYzP.cjs');
4
- const require_getRelativePath = require('./getRelativePath-DpbA6qm5.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_chunk = require("./chunk-MlS0t1Af.cjs");
3
+ const require_onProcessExit = require("./onProcessExit-C2AuepQI.cjs");
4
+ const require_getRelativePath = require("./getRelativePath-WX4HB169.cjs");
5
5
  let node_path = require("node:path");
6
6
  node_path = require_chunk.__toESM(node_path);
7
7
  let node_fs = require("node:fs");
@@ -9,7 +9,6 @@ let node_fs_promises = require("node:fs/promises");
9
9
  let node_util = require("node:util");
10
10
  let _clack_prompts = require("@clack/prompts");
11
11
  _clack_prompts = require_chunk.__toESM(_clack_prompts);
12
-
13
12
  //#region src/plugins/definePlugin.ts
14
13
  /**
15
14
  * Defines a Fabric plugin with type safety.
@@ -40,7 +39,6 @@ function definePlugin(plugin) {
40
39
  ...plugin
41
40
  };
42
41
  }
43
-
44
42
  //#endregion
45
43
  //#region src/plugins/barrelPlugin.ts
46
44
  /** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */
@@ -162,7 +160,6 @@ const barrelPlugin = definePlugin({
162
160
  } };
163
161
  }
164
162
  });
165
-
166
163
  //#endregion
167
164
  //#region src/plugins/fsPlugin.ts
168
165
  async function write(path, data, options = {}) {
@@ -213,7 +210,6 @@ const fsPlugin = definePlugin({
213
210
  } };
214
211
  }
215
212
  });
216
-
217
213
  //#endregion
218
214
  //#region src/plugins/fsxPlugin/Runtime.ts
219
215
  var Runtime = class {
@@ -281,7 +277,6 @@ var Runtime = class {
281
277
  return this.exitPromise;
282
278
  }
283
279
  };
284
-
285
280
  //#endregion
286
281
  //#region src/plugins/fsxPlugin/fsxPlugin.ts
287
282
  const fsxPlugin = definePlugin({
@@ -293,9 +288,9 @@ const fsxPlugin = definePlugin({
293
288
  ...options
294
289
  });
295
290
  return {
296
- async render(App) {
291
+ async render(Fabric) {
297
292
  await ctx.emit("lifecycle:start");
298
- return runtime.render(App);
293
+ return runtime.render(Fabric);
299
294
  },
300
295
  async waitUntilExit() {
301
296
  await runtime.waitUntilExit();
@@ -303,7 +298,6 @@ const fsxPlugin = definePlugin({
303
298
  };
304
299
  }
305
300
  });
306
-
307
301
  //#endregion
308
302
  //#region src/plugins/loggerPlugin.ts
309
303
  function pluralize(word, count) {
@@ -378,11 +372,11 @@ const loggerPlugin = definePlugin({
378
372
  });
379
373
  }
380
374
  });
381
-
382
375
  //#endregion
383
376
  exports.barrelPlugin = barrelPlugin;
384
377
  exports.definePlugin = definePlugin;
385
378
  exports.fsPlugin = fsPlugin;
386
379
  exports.fsxPlugin = fsxPlugin;
387
380
  exports.loggerPlugin = loggerPlugin;
381
+
388
382
  //# sourceMappingURL=plugins.cjs.map
@@ -1 +1 @@
1
- {"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 '../KubbFile.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 || !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 '../KubbFile.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(App: FabricElement<any>): Promise<string>\n waitUntilExit(): Promise<void>\n}\n\ndeclare global {\n namespace Kubb {\n interface Fabric {\n render(App: 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(App) {\n await ctx.emit('lifecycle:start')\n return runtime.render(App)\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,QAAO,EAAE;CAGX,MAAM,sCAAsB,IAAI,KAA4C;AAE5E,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,mBAA2C,EAAE;AACnD,OAAK,MAAM,UAAU,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M,cAAc;;AAGtB,kBAAM,MAAM,4BAAa,QAAQ,SAAS,CAAC,4BAAa,OAAO,YAAY,GAAG;IAC9E;;CAEL,CAAC"}
1
+ {"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 '../KubbFile.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 || !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 '../KubbFile.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,QAAO,EAAE;CAGX,MAAM,sCAAsB,IAAI,KAA4C;AAE5E,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,mBAA2C,EAAE;AACnD,OAAK,MAAM,UAAU,KAAK,WAAW,EAAE,CACrC,KAAI,OAAO,eAAe,OAAO,KAC/B,kBAAiB,KAAK,OAAO;AAGjC,MAAI,iBAAiB,SAAS,EAC5B,qBAAoB,IAAI,MAAM,iBAAiB;;CAInD,MAAM,8BAAc,IAAI,KAAmC;CAC3D,MAAM,yBAAS,IAAI,KAAiC;CAEpD,MAAM,WAAWA,sBAAAA,SAAS,UAAU,OAAO,KAAK;AAEhD,KAAI,CAAC,SACH,QAAO,EA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UAAA,WAAa,SAAS,IAAI,CAAC,aAAa,UAAU,QAAQ,MAAM,OAAO,GAAG;AACjG,UAAM,cAAc,KAAA;SAEpB,gBAAM,IAAI,QAAQ,IAAA,GAAA,UAAA,WAAa,SAAS,IAAI,CAAC,aAAa,UAAU,QAAQ,MAAM,OAAO,GAAG;IAE9F;AAEF,MAAI,GAAG,iBAAiB,YAAY;AAClC,OAAI,MAAM,aAAa;AACrB,UAAM,YAAY,MAAM;AACxB,UAAM,cAAc,KAAA;;AAGtB,kBAAM,MAAM,IAAA,GAAA,UAAA,WAAa,QAAQ,SAAS,CAAC,IAAA,GAAA,UAAA,WAAa,OAAO,YAAY,GAAG;IAC9E;;CAEL,CAAC"}
package/dist/plugins.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { n as __name } from "./chunk-BVHe6Par.js";
2
- import { E as Extname, a as FabricElement, l as Plugin, u as UserPlugin } from "./Fabric-D4udrNnL.js";
3
- import { r as TreeNode, t as ComponentNode } from "./useNodeTree-CPJ6Y80N.js";
1
+ import { n as __name } from "./chunk-O_arW02_.js";
2
+ import { E as Extname, a as FabricElement, l as Plugin, u as UserPlugin } from "./Fabric-CFkgoZwY.js";
3
+ import { r as TreeNode, t as ComponentNode } from "./useNodeTree-Wc1WxA05.js";
4
4
 
5
5
  //#region src/plugins/barrelPlugin.d.ts
6
6
  type Mode = 'all' | 'named' | 'propagate' | false;
@@ -93,13 +93,13 @@ type Options$1 = {
93
93
  debug?: boolean;
94
94
  };
95
95
  type ExtendOptions = {
96
- render(App: FabricElement<any>): Promise<string>;
96
+ render(Fabric: FabricElement<any>): Promise<string>;
97
97
  waitUntilExit(): Promise<void>;
98
98
  };
99
99
  declare global {
100
100
  namespace Kubb {
101
101
  interface Fabric {
102
- render(App: FabricElement<any>): Promise<string>;
102
+ render(Fabric: FabricElement<any>): Promise<string>;
103
103
  waitUntilExit(): Promise<void>;
104
104
  }
105
105
  }
@@ -116,5 +116,5 @@ type Options = {
116
116
  };
117
117
  declare const loggerPlugin: Plugin<Options, {}>;
118
118
  //#endregion
119
- export { barrelPlugin, definePlugin, fsPlugin, fsxPlugin, loggerPlugin };
119
+ export { type Plugin, barrelPlugin, definePlugin, fsPlugin, fsxPlugin, loggerPlugin };
120
120
  //# sourceMappingURL=plugins.d.ts.map
package/dist/plugins.js CHANGED
@@ -1,12 +1,11 @@
1
- import { n as __name } from "./chunk-BVHe6Par.js";
2
- import { l as TreeNode, n as Root, p as createFile, t as onProcessExit } from "./onProcessExit-CnZym153.js";
3
- import { t as getRelativePath } from "./getRelativePath-C4Au07ON.js";
1
+ import "./chunk-O_arW02_.js";
2
+ import { c as createFile, i as TreeNode, n as Root, t as onProcessExit } from "./onProcessExit-Cput7j2c.js";
3
+ import { t as getRelativePath } from "./getRelativePath-NAm_Y-vp.js";
4
4
  import path, { dirname, relative, resolve } from "node:path";
5
5
  import { rmSync } from "node:fs";
6
6
  import { mkdir, readFile, writeFile } from "node:fs/promises";
7
7
  import { styleText } from "node:util";
8
8
  import * as clack from "@clack/prompts";
9
-
10
9
  //#region src/plugins/definePlugin.ts
11
10
  /**
12
11
  * Defines a Fabric plugin with type safety.
@@ -37,7 +36,6 @@ function definePlugin(plugin) {
37
36
  ...plugin
38
37
  };
39
38
  }
40
-
41
39
  //#endregion
42
40
  //#region src/plugins/barrelPlugin.ts
43
41
  /** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */
@@ -159,7 +157,6 @@ const barrelPlugin = definePlugin({
159
157
  } };
160
158
  }
161
159
  });
162
-
163
160
  //#endregion
164
161
  //#region src/plugins/fsPlugin.ts
165
162
  async function write(path, data, options = {}) {
@@ -210,7 +207,6 @@ const fsPlugin = definePlugin({
210
207
  } };
211
208
  }
212
209
  });
213
-
214
210
  //#endregion
215
211
  //#region src/plugins/fsxPlugin/Runtime.ts
216
212
  var Runtime = class {
@@ -278,7 +274,6 @@ var Runtime = class {
278
274
  return this.exitPromise;
279
275
  }
280
276
  };
281
-
282
277
  //#endregion
283
278
  //#region src/plugins/fsxPlugin/fsxPlugin.ts
284
279
  const fsxPlugin = definePlugin({
@@ -290,9 +285,9 @@ const fsxPlugin = definePlugin({
290
285
  ...options
291
286
  });
292
287
  return {
293
- async render(App) {
288
+ async render(Fabric) {
294
289
  await ctx.emit("lifecycle:start");
295
- return runtime.render(App);
290
+ return runtime.render(Fabric);
296
291
  },
297
292
  async waitUntilExit() {
298
293
  await runtime.waitUntilExit();
@@ -300,7 +295,6 @@ const fsxPlugin = definePlugin({
300
295
  };
301
296
  }
302
297
  });
303
-
304
298
  //#endregion
305
299
  //#region src/plugins/loggerPlugin.ts
306
300
  function pluralize(word, count) {
@@ -375,7 +369,7 @@ const loggerPlugin = definePlugin({
375
369
  });
376
370
  }
377
371
  });
378
-
379
372
  //#endregion
380
373
  export { barrelPlugin, definePlugin, fsPlugin, fsxPlugin, loggerPlugin };
374
+
381
375
  //# sourceMappingURL=plugins.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.js","names":["#options","#renderPromise"],"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 '../KubbFile.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 || !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 '../KubbFile.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(App: FabricElement<any>): Promise<string>\n waitUntilExit(): Promise<void>\n}\n\ndeclare global {\n namespace Kubb {\n interface Fabric {\n render(App: 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(App) {\n await ctx.emit('lifecycle:start')\n return runtime.render(App)\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,QAAO,E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AM,OAAO,GAAG;AACjG,UAAM,cAAc;SAEpB,OAAM,IAAI,QAAQ,GAAG,UAAU,SAAS,IAAI,CAAC,aAAa,UAAU,QAAQ,MAAM,OAAO,GAAG;IAE9F;AAEF,MAAI,GAAG,iBAAiB,YAAY;AAClC,OAAI,MAAM,aAAa;AACrB,UAAM,YAAY,MAAM;AACxB,UAAM,cAAc;;AAGtB,SAAM,MAAM,GAAG,UAAU,QAAQ,SAAS,CAAC,GAAG,UAAU,OAAO,YAAY,GAAG;IAC9E;;CAEL,CAAC"}
1
+ {"version":3,"file":"plugins.js","names":["#options","#renderPromise"],"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 '../KubbFile.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 || !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 '../KubbFile.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,QAAO,EAAE;CAGX,MAAM,sCAAsB,IAAI,KAA4C;AAE5E,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,mBAA2C,EAAE;AACnD,OAAK,MAAM,UAAU,KAAK,WAAW,EAAE,CACrC,KAAI,OAAO,eAAe,OAAO,KAC/B,kBAAiB,KAAK,OAAO;AAGjC,MAAI,iBAAiB,SAAS,EAC5B,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ACxB,UAAM,cAAc,KAAA;;AAGtB,SAAM,MAAM,GAAG,UAAU,QAAQ,SAAS,CAAC,GAAG,UAAU,OAAO,YAAY,GAAG;IAC9E;;CAEL,CAAC"}
@@ -1,6 +1,6 @@
1
- import { n as __name } from "./chunk-BVHe6Par.js";
2
- import { b as FileManager, h as Context } from "./Fabric-D4udrNnL.js";
3
- import { r as TreeNode, t as ComponentNode } from "./useNodeTree-CPJ6Y80N.js";
1
+ import { n as __name } from "./chunk-O_arW02_.js";
2
+ import { b as FileManager, h as Context } from "./Fabric-CFkgoZwY.js";
3
+ import { r as TreeNode, t as ComponentNode } from "./useNodeTree-Wc1WxA05.js";
4
4
 
5
5
  //#region src/contexts/RootContext.d.ts
6
6
  type RootContextProps = {
@@ -23,5 +23,10 @@ type RootContextProps = {
23
23
  */
24
24
  declare const RootContext: Context<RootContextProps>;
25
25
  //#endregion
26
- export { RootContextProps as n, RootContext as t };
27
- //# sourceMappingURL=RootContext-BEiEsH2Z.d.ts.map
26
+ //#region src/types.d.ts
27
+ type JSDoc = {
28
+ comments: string[];
29
+ };
30
+ //#endregion
31
+ export { RootContext as n, RootContextProps as r, JSDoc as t };
32
+ //# sourceMappingURL=types-BwR3_cUx.d.ts.map
package/dist/types.cjs CHANGED
@@ -1,20 +1,18 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_chunk = require('./chunk-DVipidnM.cjs');
3
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
2
  //#region src/KubbFile.ts
5
- var KubbFile_exports = /* @__PURE__ */ require_chunk.__exportAll({});
6
-
3
+ var KubbFile_exports = /* @__PURE__ */ require("./chunk-MlS0t1Af.cjs").__exportAll({});
7
4
  //#endregion
8
- Object.defineProperty(exports, 'FabricFile', {
9
- enumerable: true,
10
- get: function () {
11
- return KubbFile_exports;
12
- }
5
+ Object.defineProperty(exports, "FabricFile", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return KubbFile_exports;
9
+ }
13
10
  });
14
- Object.defineProperty(exports, 'KubbFile', {
15
- enumerable: true,
16
- get: function () {
17
- return KubbFile_exports;
18
- }
11
+ Object.defineProperty(exports, "KubbFile", {
12
+ enumerable: true,
13
+ get: function() {
14
+ return KubbFile_exports;
15
+ }
19
16
  });
17
+
20
18
  //# sourceMappingURL=types.cjs.map
package/dist/types.d.ts CHANGED
@@ -1,12 +1,4 @@
1
- import { n as __name } from "./chunk-BVHe6Par.js";
2
- import { c as FabricOptions, h as Context, i as FabricContext, k as KubbFile_d_exports, m as RenderContextProps, o as FabricMode, r as FabricConfig, t as Fabric } from "./Fabric-D4udrNnL.js";
3
- import { t as ComponentNode } from "./useNodeTree-CPJ6Y80N.js";
4
- import { n as RootContextProps } from "./RootContext-BEiEsH2Z.js";
5
-
6
- //#region src/types.d.ts
7
- type JSDoc = {
8
- comments: string[];
9
- };
10
- //#endregion
11
- export { type ComponentNode, type Context, type Fabric, type FabricConfig, type FabricContext, KubbFile_d_exports as FabricFile, KubbFile_d_exports as KubbFile, type FabricMode, type FabricOptions, JSDoc, type RenderContextProps, type RootContextProps };
12
- //# sourceMappingURL=types.d.ts.map
1
+ import { c as FabricOptions, h as Context, i as FabricContext, k as KubbFile_d_exports, m as RenderContextProps, o as FabricMode, r as FabricConfig, t as Fabric } from "./Fabric-CFkgoZwY.js";
2
+ import { t as ComponentNode } from "./useNodeTree-Wc1WxA05.js";
3
+ import { r as RootContextProps, t as JSDoc } from "./types-BwR3_cUx.js";
4
+ export { ComponentNode, Context, Fabric, FabricConfig, FabricContext, KubbFile_d_exports as FabricFile, KubbFile_d_exports as KubbFile, FabricMode, FabricOptions, JSDoc, RenderContextProps, RootContextProps };
package/dist/types.js CHANGED
@@ -1,8 +1,7 @@
1
- import { t as __exportAll } from "./chunk-BVHe6Par.js";
2
-
1
+ import { t as __exportAll } from "./chunk-O_arW02_.js";
3
2
  //#region src/KubbFile.ts
4
3
  var KubbFile_exports = /* @__PURE__ */ __exportAll({});
5
-
6
4
  //#endregion
7
5
  export { KubbFile_exports as FabricFile, KubbFile_exports as KubbFile };
6
+
8
7
  //# sourceMappingURL=types.js.map
@@ -1,5 +1,5 @@
1
- import { n as __name } from "./chunk-BVHe6Par.js";
2
- import { D as File } from "./Fabric-D4udrNnL.js";
1
+ import { n as __name } from "./chunk-O_arW02_.js";
2
+ import { D as File } from "./Fabric-CFkgoZwY.js";
3
3
 
4
4
  //#region src/utils/TreeNode.d.ts
5
5
  type BarrelData = {
@@ -56,4 +56,4 @@ type ComponentNode = {
56
56
  declare function useNodeTree(): TreeNode<ComponentNode> | null;
57
57
  //#endregion
58
58
  export { useNodeTree as n, TreeNode as r, ComponentNode as t };
59
- //# sourceMappingURL=useNodeTree-CPJ6Y80N.d.ts.map
59
+ //# sourceMappingURL=useNodeTree-Wc1WxA05.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/fabric-core",
3
- "version": "0.13.3",
3
+ "version": "0.15.0",
4
4
  "description": "Core functionality for Kubb's fabric - A language-agnostic toolkit providing the foundation for plugin-based code generation with TypeScript support",
5
5
  "keywords": [
6
6
  "codegen",
@@ -84,7 +84,7 @@
84
84
  }
85
85
  ],
86
86
  "dependencies": {
87
- "@clack/prompts": "^1.0.1",
87
+ "@clack/prompts": "^1.1.0",
88
88
  "p-limit": "^7.3.0",
89
89
  "remeda": "^2.33.6",
90
90
  "typescript": "5.9.3"