@kubb/fabric-core 0.2.15 → 0.2.16

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 (43) hide show
  1. package/dist/{Fabric-0mXLgmur.d.cts → Fabric-AmREkq58.d.ts} +93 -49
  2. package/dist/{Fabric-C-AqOkTA.d.ts → Fabric-CBrTERuf.d.cts} +93 -49
  3. package/dist/{defineProperty-B05cRoSl.cjs → defineProperty-Dlhh3lSJ.cjs} +33 -19
  4. package/dist/defineProperty-Dlhh3lSJ.cjs.map +1 -0
  5. package/dist/{defineProperty-BZknW4oy.js → defineProperty-_FBdEen_.js} +28 -14
  6. package/dist/defineProperty-_FBdEen_.js.map +1 -0
  7. package/dist/index.cjs +57 -26
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +25 -3
  10. package/dist/index.d.ts +25 -3
  11. package/dist/index.js +57 -26
  12. package/dist/index.js.map +1 -1
  13. package/dist/parsers/typescript.d.cts +2 -2
  14. package/dist/parsers/typescript.d.ts +2 -2
  15. package/dist/parsers.d.cts +2 -2
  16. package/dist/parsers.d.ts +2 -2
  17. package/dist/plugins.cjs +3 -9
  18. package/dist/plugins.cjs.map +1 -1
  19. package/dist/plugins.d.cts +1 -11
  20. package/dist/plugins.d.ts +1 -11
  21. package/dist/plugins.js +1 -7
  22. package/dist/plugins.js.map +1 -1
  23. package/dist/types.cjs.map +1 -1
  24. package/dist/types.d.cts +2 -3
  25. package/dist/types.d.ts +2 -3
  26. package/dist/types.js.map +1 -1
  27. package/dist/{typescriptParser-B4-y6QxR.d.cts → typescriptParser-C3B3dzh_.d.cts} +2 -2
  28. package/dist/{typescriptParser-By3ckLtc.d.ts → typescriptParser-DaOfAlmM.d.ts} +2 -2
  29. package/package.json +1 -1
  30. package/src/Fabric.ts +99 -50
  31. package/src/FileManager.ts +19 -2
  32. package/src/KubbFile.ts +0 -2
  33. package/src/createFile.ts +87 -71
  34. package/src/defineFabric.ts +41 -24
  35. package/src/plugins/barrelPlugin.ts +0 -8
  36. package/src/plugins/fsPlugin.ts +0 -8
  37. package/src/types.ts +0 -1
  38. package/src/utils/AsyncEventEmitter.ts +29 -8
  39. package/dist/defineFabric-D_m6CB1s.d.ts +0 -9
  40. package/dist/defineFabric-Dkt2l0wC.d.cts +0 -9
  41. package/dist/defineProperty-B05cRoSl.cjs.map +0 -1
  42. package/dist/defineProperty-BZknW4oy.js.map +0 -1
  43. package/src/utils/EventEmitter.ts +0 -31
@@ -1,3 +1,3 @@
1
- import "../Fabric-C-AqOkTA.js";
2
- import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-By3ckLtc.js";
1
+ import "../Fabric-AmREkq58.js";
2
+ import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-DaOfAlmM.js";
3
3
  export { createExport, createImport, print, typescriptParser };
@@ -1,5 +1,5 @@
1
- import { d as UserParser, u as Parser } from "./Fabric-0mXLgmur.cjs";
2
- import { i as typescriptParser } from "./typescriptParser-B4-y6QxR.cjs";
1
+ import { d as UserParser, u as Parser } from "./Fabric-CBrTERuf.cjs";
2
+ import { i as typescriptParser } from "./typescriptParser-C3B3dzh_.cjs";
3
3
 
4
4
  //#region src/parsers/createParser.d.ts
5
5
  declare function createParser<TOptions = unknown, TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta>;
package/dist/parsers.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { d as UserParser, u as Parser } from "./Fabric-C-AqOkTA.js";
2
- import { i as typescriptParser } from "./typescriptParser-By3ckLtc.js";
1
+ import { d as UserParser, u as Parser } from "./Fabric-AmREkq58.js";
2
+ import { i as typescriptParser } from "./typescriptParser-DaOfAlmM.js";
3
3
 
4
4
  //#region src/parsers/createParser.d.ts
5
5
  declare function createParser<TOptions = unknown, TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta>;
package/dist/plugins.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const require_trimExtName = require('./trimExtName-Bb4zGVF1.cjs');
2
- const require_defineProperty = require('./defineProperty-B05cRoSl.cjs');
2
+ const require_defineProperty = require('./defineProperty-Dlhh3lSJ.cjs');
3
3
  const require_getRelativePath = require('./getRelativePath-C6lvNCs7.cjs');
4
4
  let node_path = require("node:path");
5
5
  node_path = require_trimExtName.__toESM(node_path);
@@ -16,12 +16,6 @@ node_process = require_trimExtName.__toESM(node_process);
16
16
  let cli_progress = require("cli-progress");
17
17
  cli_progress = require_trimExtName.__toESM(cli_progress);
18
18
 
19
- //#region \0@oxc-project+runtime@0.95.0/helpers/classPrivateFieldSet2.js
20
- function _classPrivateFieldSet2(s, a, r) {
21
- return s.set(require_defineProperty._assertClassBrand(s, a), r), r;
22
- }
23
-
24
- //#endregion
25
19
  //#region src/utils/TreeNode.ts
26
20
  var _cachedLeaves = /* @__PURE__ */ new WeakMap();
27
21
  var TreeNode = class TreeNode {
@@ -36,7 +30,7 @@ var TreeNode = class TreeNode {
36
30
  addChild(data) {
37
31
  const child = new TreeNode(data, this);
38
32
  this.children.push(child);
39
- _classPrivateFieldSet2(_cachedLeaves, this, void 0);
33
+ require_defineProperty._classPrivateFieldSet2(_cachedLeaves, this, void 0);
40
34
  return child;
41
35
  }
42
36
  get leaves() {
@@ -46,7 +40,7 @@ var TreeNode = class TreeNode {
46
40
  const result = [];
47
41
  for (const node of stack) if (node.children.length) for (const child of node.children) stack.push(child);
48
42
  else result.push(node);
49
- _classPrivateFieldSet2(_cachedLeaves, this, result);
43
+ require_defineProperty._classPrivateFieldSet2(_cachedLeaves, this, result);
50
44
  return result;
51
45
  }
52
46
  forEach(callback) {
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.cjs","names":["stack: Array<TreeNode<TData>>","result: Array<TreeNode<TData>>","nodes: Array<{ id: string; label: string }>","edges: Array<{ from: string; to: string }>","next: TreeNode<BarrelData> | undefined","path","createFile","getRelativePath","path","fs","path","http","createFile","path","SingleBar","Presets","process"],"sources":["../src/utils/TreeNode.ts","../src/plugins/createPlugin.ts","../src/plugins/barrelPlugin.ts","../src/plugins/fsPlugin.ts","../src/utils/open.ts","../src/plugins/graphPlugin.ts","../src/plugins/progressPlugin.ts"],"sourcesContent":["import type * as KubbFile from '../KubbFile.ts'\n\ntype BarrelData = {\n file?: KubbFile.File\n path: string\n name: string\n}\n\nexport type Graph = {\n nodes: Array<{ id: string; label: string }>\n edges: Array<{ from: string; to: string }>\n}\n\nexport class TreeNode<TData = unknown> {\n data: TData\n parent?: TreeNode<TData>\n children: Array<TreeNode<TData>> = []\n #cachedLeaves?: Array<TreeNode<TData>>\n\n constructor(data: TData, parent?: TreeNode<TData>) {\n this.data = data\n this.parent = parent\n }\n\n addChild(data: TData): TreeNode<TData> {\n const child = new TreeNode(data, this)\n this.children.push(child)\n this.#cachedLeaves = undefined // invalidate cached leaves\n return child\n }\n\n get leaves(): Array<TreeNode<TData>> {\n if (this.#cachedLeaves) return this.#cachedLeaves\n if (this.children.length === 0) return [this]\n\n const stack: Array<TreeNode<TData>> = [...this.children]\n const result: Array<TreeNode<TData>> = []\n\n for (const node of stack) {\n if (node.children.length) {\n for (const child of node.children) stack.push(child)\n } else {\n result.push(node)\n }\n }\n\n this.#cachedLeaves = result\n return result\n }\n\n forEach(callback: (node: TreeNode<TData>) => void): this {\n const stack: Array<TreeNode<TData>> = [this]\n\n for (const node of stack) {\n callback(node)\n if (node.children.length) {\n for (const child of node.children) stack.push(child)\n }\n }\n return this\n }\n\n findDeep(predicate: (node: TreeNode<TData>) => boolean): TreeNode<TData> | undefined {\n for (const leaf of this.leaves) {\n if (predicate(leaf)) return leaf\n }\n return undefined\n }\n\n static toGraph(root: TreeNode<BarrelData>): Graph {\n const nodes: Array<{ id: string; label: string }> = []\n const edges: Array<{ from: string; to: string }> = []\n\n root.forEach((node) => {\n nodes.push({\n id: node.data.path,\n label: node.data.name,\n })\n\n for (const child of node.children) {\n edges.push({\n from: node.data.path,\n to: child.data.path,\n })\n }\n })\n\n return { nodes, edges }\n }\n\n static fromFiles(files: Array<KubbFile.File>, rootFolder = ''): TreeNode<BarrelData> | null {\n const normalizePath = (p: string): string => p.replace(/\\\\/g, '/')\n const normalizedRoot = normalizePath(rootFolder)\n const rootPrefix = normalizedRoot.endsWith('/') ? normalizedRoot : `${normalizedRoot}/`\n\n const filteredFiles = files.filter((file) => {\n const filePath = normalizePath(file.path)\n\n return !filePath.endsWith('.json') && (!rootFolder || filePath.startsWith(rootPrefix))\n })\n\n if (filteredFiles.length === 0) {\n return null\n }\n\n const treeNode = new TreeNode<BarrelData>({\n name: rootFolder || '',\n path: rootFolder || '',\n file: undefined,\n })\n\n for (const file of filteredFiles) {\n const relPath = normalizePath(file.path).slice(rootPrefix.length)\n const parts = relPath.split('/')\n\n let current = treeNode\n let currentPath = rootFolder\n\n for (const [index, part] of parts.entries()) {\n const isLast = index === parts.length - 1\n currentPath += (currentPath.endsWith('/') ? '' : '/') + part\n\n let next: TreeNode<BarrelData> | undefined\n for (const child of current.children) {\n if ((child.data as BarrelData).name === part) {\n next = child\n break\n }\n }\n\n if (!next) {\n next = current.addChild({\n name: part,\n path: currentPath,\n file: isLast ? file : undefined,\n })\n }\n\n current = next\n }\n }\n\n return treeNode\n }\n}\n","import type { Plugin, UserPlugin } from './types.ts'\n\nexport function createPlugin<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 { createPlugin } from './createPlugin.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 writeEntry(options: WriteEntryOptions): Promise<void>\n}\n\n// biome-ignore lint/suspicious/noTsIgnore: production ready\n// @ts-ignore\ndeclare module '@kubb/fabric-core' {\n interface Fabric {\n writeEntry(options: WriteEntryOptions): Promise<void>\n }\n}\n\ndeclare global {\n namespace Kubb {\n interface Fabric {\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 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 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 // Collect all leaves under the current directory node\n node.leaves.forEach((leaf) => {\n const file = leaf.data.file\n if (!file) {\n return\n }\n\n const sources = file.sources || []\n sources.forEach((source) => {\n if (!file.path || !source.isIndexable || !source.name) {\n return\n }\n\n const key = `${source.name}|${source.isTypeOnly ? '1' : '0'}`\n if (seen.has(key)) {\n return\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 = createPlugin<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('write: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 = ctx.files.filter((file) => {\n return file.sources.some((source) => source.isIndexable)\n })\n\n const entryFile = createFile({\n path: rootPath,\n baseName: 'index.ts',\n exports: barrelFiles\n .flatMap((file) => {\n const containsOnlyTypes = file.sources.every((source) => source.isTypeOnly)\n\n return file.sources\n ?.map((source) => {\n if (!file.path || !source.isIndexable) {\n return undefined\n }\n\n return {\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 .filter(Boolean)\n })\n .filter(Boolean),\n sources: [],\n })\n\n await ctx.addFile(entryFile)\n\n await ctx.fileManager.write({\n mode: ctx.config?.options?.mode,\n dryRun: options.dryRun,\n parsers: ctx.installedParsers,\n })\n },\n }\n },\n})\n","import { resolve } from 'node:path'\nimport fs from 'fs-extra'\nimport type * as KubbFile from '../KubbFile.ts'\nimport { createPlugin } from './createPlugin.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 fs.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 fs.outputFile(resolve(path), data.trim(), { encoding: 'utf-8' })\n\n if (options?.sanity) {\n const savedData = await fs.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\n// biome-ignore lint/suspicious/noTsIgnore: production ready\n// @ts-ignore\ndeclare module '@kubb/fabric-core' {\n interface Fabric {\n write(options?: WriteOptions): Promise<void>\n }\n}\n\ndeclare global {\n namespace Kubb {\n interface Fabric {\n write(options?: WriteOptions): Promise<void>\n }\n }\n}\n\nexport const fsPlugin = createPlugin<Options, ExtendOptions>({\n name: 'fs',\n install(ctx, options = {}) {\n if (options.clean) {\n fs.removeSync(options.clean.path)\n }\n\n ctx.on('process:progress', 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?.options?.mode,\n extension: options.extension,\n dryRun,\n parsers: ctx.installedParsers,\n })\n },\n }\n },\n})\n","import { spawn } from 'node:child_process'\n\nconst spawnBin = (bin: string, args: string[]): Promise<boolean> => {\n return new Promise((resolve) => {\n const process = spawn(bin, args, {\n detached: true,\n shell: false,\n windowsHide: true,\n })\n\n process.on('close', (code) => {\n resolve(!code)\n })\n })\n}\n\ntype Options = {\n app?: string\n}\n\nexport async function open(path: string, options?: Options): Promise<boolean> {\n const app = options?.app\n\n if (process.platform === 'win32') {\n return spawnBin('cmd.exe', ['/c', 'start', app || '', path.replace(/[&^]/g, '^$&')])\n }\n\n if (process.platform === 'linux') {\n return spawnBin(app || 'xdg-open', [path])\n }\n if (process.platform === 'darwin') {\n return spawnBin('open', app ? ['-a', app, path] : [path])\n }\n\n throw new Error(`Unsupported platform, could not open \"${path}\"`)\n}\n","import http from 'node:http'\nimport type { AddressInfo } from 'node:net'\nimport path from 'node:path'\nimport handler from 'serve-handler'\nimport { createFile } from '../createFile.ts'\nimport type * as KubbFile from '../KubbFile.ts'\nimport { open } from '../utils/open.ts'\nimport { type Graph, TreeNode } from '../utils/TreeNode.ts'\nimport { createPlugin } from './createPlugin.ts'\n\ntype Options = {\n root: string\n /**\n * @default false\n */\n open?: boolean\n}\n\ntype GetGraphOptions = {\n files: KubbFile.File[]\n root: string\n}\n\nexport function getGraph({ files, root }: GetGraphOptions): Graph | undefined {\n const treeNode = TreeNode.fromFiles(files, root)\n\n if (!treeNode) {\n return undefined\n }\n\n return TreeNode.toGraph(treeNode)\n}\nconst html = `\n <!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <title>File Graph</title>\n <script type=\"module\">\n import { Network } from 'https://cdn.jsdelivr.net/npm/vis-network/standalone/esm/vis-network.min.js'\n\n async function main() {\n const res = await fetch('./graph.json')\n const { nodes, edges } = await res.json()\n const container = document.getElementById('graph')\n\n const network = new Network(\n container,\n { nodes, edges },\n {\n layout: { hierarchical: { direction: 'UD', sortMethod: 'directed' } },\n nodes: { shape: 'box', font: { face: 'monospace' } },\n edges: { arrows: 'to' },\n physics: false,\n },\n )\n }\n\n main()\n </script>\n <style>\n html, body, #graph { height: 100%; margin: 0; }\n </style>\n </head>\n <body>\n <div id=\"graph\"></div>\n </body>\n</html>\n`\n\nasync function serve(root: string) {\n const server = http.createServer((req, res) => {\n return handler(req, res, {\n public: root,\n cleanUrls: true,\n })\n })\n\n server.listen(0, async () => {\n const { port } = server.address() as AddressInfo\n console.log(`Running on http://localhost:${port}/graph.html`)\n\n await open(`http://localhost:${port}/graph.html`)\n })\n}\n\nexport const graphPlugin = createPlugin<Options>({\n name: 'graph',\n install(ctx, options) {\n if (!options) {\n throw new Error('Graph plugin requires options.root and options.mode')\n }\n\n ctx.on('write:start', async ({ files }) => {\n const root = options.root\n\n const graph = getGraph({ files, root })\n\n if (!graph) {\n return undefined\n }\n\n const graphFile = createFile({\n baseName: 'graph.json',\n path: path.join(root, 'graph.json'),\n sources: [\n {\n name: 'graph',\n value: JSON.stringify(graph, null, 2),\n },\n ],\n })\n\n const graphHtmlFile = createFile({\n baseName: 'graph.html',\n path: path.join(root, 'graph.html'),\n sources: [\n {\n name: 'graph',\n value: html,\n },\n ],\n })\n\n await ctx.addFile(graphFile, graphHtmlFile)\n\n if (options.open) {\n await serve(root)\n }\n })\n },\n})\n","import { relative } from 'node:path'\nimport process from 'node:process'\nimport { Presets, SingleBar } from 'cli-progress'\nimport { createPlugin } from './createPlugin.ts'\n\nexport const progressPlugin = createPlugin({\n name: 'progress',\n install(ctx) {\n const progressBar = new SingleBar(\n {\n format: '{bar} {percentage}% | {value}/{total} | {message}',\n barCompleteChar: '█',\n barIncompleteChar: '░',\n hideCursor: true,\n clearOnComplete: true,\n },\n Presets.shades_grey,\n )\n\n ctx.on('process:start', async ({ files }) => {\n progressBar.start(files.length, 0, { message: 'Starting...' })\n })\n\n ctx.on('process:progress', async ({ file }) => {\n const message = `Writing ${relative(process.cwd(), file.path)}`\n progressBar.increment(1, { message })\n })\n\n ctx.on('process:end', async ({ files }) => {\n progressBar.update(files.length, { message: 'Done ✅' })\n progressBar.stop()\n })\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,IAAa,WAAb,MAAa,SAA0B;CAMrC,YAAY,MAAa,QAA0B;+CALnD;+CACA;+CACA,YAAmC,EAAE;;AAInC,OAAK,OAAO;AACZ,OAAK,SAAS;;CAGhB,SAAS,MAA8B;EACrC,MAAM,QAAQ,IAAI,SAAS,MAAM,KAAK;AACtC,OAAK,SAAS,KAAK,MAAM;AACzB,8CAAqB,OAAS;AAC9B,SAAO;;CAGT,IAAI,SAAiC;AACnC,mEAAI,KAAkB,CAAE,qEAAO,KAAkB;AACjD,MAAI,KAAK,SAAS,WAAW,EAAG,QAAO,CAAC,KAAK;EAE7C,MAAMA,QAAgC,CAAC,GAAG,KAAK,SAAS;EACxD,MAAMC,SAAiC,EAAE;AAEzC,OAAK,MAAM,QAAQ,MACjB,KAAI,KAAK,SAAS,OAChB,MAAK,MAAM,SAAS,KAAK,SAAU,OAAM,KAAK,MAAM;MAEpD,QAAO,KAAK,KAAK;AAIrB,8CAAqB,OAAM;AAC3B,SAAO;;CAGT,QAAQ,UAAiD;EACvD,MAAMD,QAAgC,CAAC,KAAK;AAE5C,OAAK,MAAM,QAAQ,OAAO;AACxB,YAAS,KAAK;AACd,OAAI,KAAK,SAAS,OAChB,MAAK,MAAM,SAAS,KAAK,SAAU,OAAM,KAAK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MAAM,gBAAgBD,kCAAW;IAC/B,UAAU;IACV,MAAMC,kBAAK,KAAK,MAAM,aAAa;IACnC,SAAS,CACP;KACE,MAAM;KACN,OAAO;KACR,CACF;IACF,CAAC;AAEF,SAAM,IAAI,QAAQ,WAAW,cAAc;AAE3C,OAAI,QAAQ,KACV,OAAM,MAAM,KAAK;IAEnB;;CAEL,CAAC;;;;AC9HF,MAAa,iBAAiB,aAAa;CACzC,MAAM;CACN,QAAQ,KAAK;EACX,MAAM,cAAc,IAAIC,uBACtB;GACE,QAAQ;GACR,iBAAiB;GACjB,mBAAmB;GACnB,YAAY;GACZ,iBAAiB;GAClB,EACDC,qBAAQ,YACT;AAED,MAAI,GAAG,iBAAiB,OAAO,EAAE,YAAY;AAC3C,eAAY,MAAM,MAAM,QAAQ,GAAG,EAAE,SAAS,eAAe,CAAC;IAC9D;AAEF,MAAI,GAAG,oBAAoB,OAAO,EAAE,WAAW;GAC7C,MAAM,UAAU,mCAAoBC,qBAAQ,KAAK,EAAE,KAAK,KAAK;AAC7D,eAAY,UAAU,GAAG,EAAE,SAAS,CAAC;IACrC;AAEF,MAAI,GAAG,eAAe,OAAO,EAAE,YAAY;AACzC,eAAY,OAAO,MAAM,QAAQ,EAAE,SAAS,UAAU,CAAC;AACvD,eAAY,MAAM;IAClB;;CAEL,CAAC"}
1
+ {"version":3,"file":"plugins.cjs","names":["stack: Array<TreeNode<TData>>","result: Array<TreeNode<TData>>","nodes: Array<{ id: string; label: string }>","edges: Array<{ from: string; to: string }>","next: TreeNode<BarrelData> | undefined","path","createFile","getRelativePath","path","fs","path","http","createFile","path","SingleBar","Presets","process"],"sources":["../src/utils/TreeNode.ts","../src/plugins/createPlugin.ts","../src/plugins/barrelPlugin.ts","../src/plugins/fsPlugin.ts","../src/utils/open.ts","../src/plugins/graphPlugin.ts","../src/plugins/progressPlugin.ts"],"sourcesContent":["import type * as KubbFile from '../KubbFile.ts'\n\ntype BarrelData = {\n file?: KubbFile.File\n path: string\n name: string\n}\n\nexport type Graph = {\n nodes: Array<{ id: string; label: string }>\n edges: Array<{ from: string; to: string }>\n}\n\nexport class TreeNode<TData = unknown> {\n data: TData\n parent?: TreeNode<TData>\n children: Array<TreeNode<TData>> = []\n #cachedLeaves?: Array<TreeNode<TData>>\n\n constructor(data: TData, parent?: TreeNode<TData>) {\n this.data = data\n this.parent = parent\n }\n\n addChild(data: TData): TreeNode<TData> {\n const child = new TreeNode(data, this)\n this.children.push(child)\n this.#cachedLeaves = undefined // invalidate cached leaves\n return child\n }\n\n get leaves(): Array<TreeNode<TData>> {\n if (this.#cachedLeaves) return this.#cachedLeaves\n if (this.children.length === 0) return [this]\n\n const stack: Array<TreeNode<TData>> = [...this.children]\n const result: Array<TreeNode<TData>> = []\n\n for (const node of stack) {\n if (node.children.length) {\n for (const child of node.children) stack.push(child)\n } else {\n result.push(node)\n }\n }\n\n this.#cachedLeaves = result\n return result\n }\n\n forEach(callback: (node: TreeNode<TData>) => void): this {\n const stack: Array<TreeNode<TData>> = [this]\n\n for (const node of stack) {\n callback(node)\n if (node.children.length) {\n for (const child of node.children) stack.push(child)\n }\n }\n return this\n }\n\n findDeep(predicate: (node: TreeNode<TData>) => boolean): TreeNode<TData> | undefined {\n for (const leaf of this.leaves) {\n if (predicate(leaf)) return leaf\n }\n return undefined\n }\n\n static toGraph(root: TreeNode<BarrelData>): Graph {\n const nodes: Array<{ id: string; label: string }> = []\n const edges: Array<{ from: string; to: string }> = []\n\n root.forEach((node) => {\n nodes.push({\n id: node.data.path,\n label: node.data.name,\n })\n\n for (const child of node.children) {\n edges.push({\n from: node.data.path,\n to: child.data.path,\n })\n }\n })\n\n return { nodes, edges }\n }\n\n static fromFiles(files: Array<KubbFile.File>, rootFolder = ''): TreeNode<BarrelData> | null {\n const normalizePath = (p: string): string => p.replace(/\\\\/g, '/')\n const normalizedRoot = normalizePath(rootFolder)\n const rootPrefix = normalizedRoot.endsWith('/') ? normalizedRoot : `${normalizedRoot}/`\n\n const filteredFiles = files.filter((file) => {\n const filePath = normalizePath(file.path)\n\n return !filePath.endsWith('.json') && (!rootFolder || filePath.startsWith(rootPrefix))\n })\n\n if (filteredFiles.length === 0) {\n return null\n }\n\n const treeNode = new TreeNode<BarrelData>({\n name: rootFolder || '',\n path: rootFolder || '',\n file: undefined,\n })\n\n for (const file of filteredFiles) {\n const relPath = normalizePath(file.path).slice(rootPrefix.length)\n const parts = relPath.split('/')\n\n let current = treeNode\n let currentPath = rootFolder\n\n for (const [index, part] of parts.entries()) {\n const isLast = index === parts.length - 1\n currentPath += (currentPath.endsWith('/') ? '' : '/') + part\n\n let next: TreeNode<BarrelData> | undefined\n for (const child of current.children) {\n if ((child.data as BarrelData).name === part) {\n next = child\n break\n }\n }\n\n if (!next) {\n next = current.addChild({\n name: part,\n path: currentPath,\n file: isLast ? file : undefined,\n })\n }\n\n current = next\n }\n }\n\n return treeNode\n }\n}\n","import type { Plugin, UserPlugin } from './types.ts'\n\nexport function createPlugin<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 { createPlugin } from './createPlugin.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 writeEntry(options: WriteEntryOptions): Promise<void>\n}\n\ndeclare global {\n namespace Kubb {\n interface Fabric {\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 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 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 // Collect all leaves under the current directory node\n node.leaves.forEach((leaf) => {\n const file = leaf.data.file\n if (!file) {\n return\n }\n\n const sources = file.sources || []\n sources.forEach((source) => {\n if (!file.path || !source.isIndexable || !source.name) {\n return\n }\n\n const key = `${source.name}|${source.isTypeOnly ? '1' : '0'}`\n if (seen.has(key)) {\n return\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 = createPlugin<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('write: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 = ctx.files.filter((file) => {\n return file.sources.some((source) => source.isIndexable)\n })\n\n const entryFile = createFile({\n path: rootPath,\n baseName: 'index.ts',\n exports: barrelFiles\n .flatMap((file) => {\n const containsOnlyTypes = file.sources.every((source) => source.isTypeOnly)\n\n return file.sources\n ?.map((source) => {\n if (!file.path || !source.isIndexable) {\n return undefined\n }\n\n return {\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 .filter(Boolean)\n })\n .filter(Boolean),\n sources: [],\n })\n\n await ctx.addFile(entryFile)\n\n await ctx.fileManager.write({\n mode: ctx.config?.options?.mode,\n dryRun: options.dryRun,\n parsers: ctx.installedParsers,\n })\n },\n }\n },\n})\n","import { resolve } from 'node:path'\nimport fs from 'fs-extra'\nimport type * as KubbFile from '../KubbFile.ts'\nimport { createPlugin } from './createPlugin.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 fs.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 fs.outputFile(resolve(path), data.trim(), { encoding: 'utf-8' })\n\n if (options?.sanity) {\n const savedData = await fs.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 = createPlugin<Options, ExtendOptions>({\n name: 'fs',\n install(ctx, options = {}) {\n if (options.clean) {\n fs.removeSync(options.clean.path)\n }\n\n ctx.on('process:progress', 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?.options?.mode,\n extension: options.extension,\n dryRun,\n parsers: ctx.installedParsers,\n })\n },\n }\n },\n})\n","import { spawn } from 'node:child_process'\n\nconst spawnBin = (bin: string, args: string[]): Promise<boolean> => {\n return new Promise((resolve) => {\n const process = spawn(bin, args, {\n detached: true,\n shell: false,\n windowsHide: true,\n })\n\n process.on('close', (code) => {\n resolve(!code)\n })\n })\n}\n\ntype Options = {\n app?: string\n}\n\nexport async function open(path: string, options?: Options): Promise<boolean> {\n const app = options?.app\n\n if (process.platform === 'win32') {\n return spawnBin('cmd.exe', ['/c', 'start', app || '', path.replace(/[&^]/g, '^$&')])\n }\n\n if (process.platform === 'linux') {\n return spawnBin(app || 'xdg-open', [path])\n }\n if (process.platform === 'darwin') {\n return spawnBin('open', app ? ['-a', app, path] : [path])\n }\n\n throw new Error(`Unsupported platform, could not open \"${path}\"`)\n}\n","import http from 'node:http'\nimport type { AddressInfo } from 'node:net'\nimport path from 'node:path'\nimport handler from 'serve-handler'\nimport { createFile } from '../createFile.ts'\nimport type * as KubbFile from '../KubbFile.ts'\nimport { open } from '../utils/open.ts'\nimport { type Graph, TreeNode } from '../utils/TreeNode.ts'\nimport { createPlugin } from './createPlugin.ts'\n\ntype Options = {\n root: string\n /**\n * @default false\n */\n open?: boolean\n}\n\ntype GetGraphOptions = {\n files: KubbFile.File[]\n root: string\n}\n\nexport function getGraph({ files, root }: GetGraphOptions): Graph | undefined {\n const treeNode = TreeNode.fromFiles(files, root)\n\n if (!treeNode) {\n return undefined\n }\n\n return TreeNode.toGraph(treeNode)\n}\nconst html = `\n <!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <title>File Graph</title>\n <script type=\"module\">\n import { Network } from 'https://cdn.jsdelivr.net/npm/vis-network/standalone/esm/vis-network.min.js'\n\n async function main() {\n const res = await fetch('./graph.json')\n const { nodes, edges } = await res.json()\n const container = document.getElementById('graph')\n\n const network = new Network(\n container,\n { nodes, edges },\n {\n layout: { hierarchical: { direction: 'UD', sortMethod: 'directed' } },\n nodes: { shape: 'box', font: { face: 'monospace' } },\n edges: { arrows: 'to' },\n physics: false,\n },\n )\n }\n\n main()\n </script>\n <style>\n html, body, #graph { height: 100%; margin: 0; }\n </style>\n </head>\n <body>\n <div id=\"graph\"></div>\n </body>\n</html>\n`\n\nasync function serve(root: string) {\n const server = http.createServer((req, res) => {\n return handler(req, res, {\n public: root,\n cleanUrls: true,\n })\n })\n\n server.listen(0, async () => {\n const { port } = server.address() as AddressInfo\n console.log(`Running on http://localhost:${port}/graph.html`)\n\n await open(`http://localhost:${port}/graph.html`)\n })\n}\n\nexport const graphPlugin = createPlugin<Options>({\n name: 'graph',\n install(ctx, options) {\n if (!options) {\n throw new Error('Graph plugin requires options.root and options.mode')\n }\n\n ctx.on('write:start', async ({ files }) => {\n const root = options.root\n\n const graph = getGraph({ files, root })\n\n if (!graph) {\n return undefined\n }\n\n const graphFile = createFile({\n baseName: 'graph.json',\n path: path.join(root, 'graph.json'),\n sources: [\n {\n name: 'graph',\n value: JSON.stringify(graph, null, 2),\n },\n ],\n })\n\n const graphHtmlFile = createFile({\n baseName: 'graph.html',\n path: path.join(root, 'graph.html'),\n sources: [\n {\n name: 'graph',\n value: html,\n },\n ],\n })\n\n await ctx.addFile(graphFile, graphHtmlFile)\n\n if (options.open) {\n await serve(root)\n }\n })\n },\n})\n","import { relative } from 'node:path'\nimport process from 'node:process'\nimport { Presets, SingleBar } from 'cli-progress'\nimport { createPlugin } from './createPlugin.ts'\n\nexport const progressPlugin = createPlugin({\n name: 'progress',\n install(ctx) {\n const progressBar = new SingleBar(\n {\n format: '{bar} {percentage}% | {value}/{total} | {message}',\n barCompleteChar: '█',\n barIncompleteChar: '░',\n hideCursor: true,\n clearOnComplete: true,\n },\n Presets.shades_grey,\n )\n\n ctx.on('process:start', async ({ files }) => {\n progressBar.start(files.length, 0, { message: 'Starting...' })\n })\n\n ctx.on('process:progress', async ({ file }) => {\n const message = `Writing ${relative(process.cwd(), file.path)}`\n progressBar.increment(1, { message })\n })\n\n ctx.on('process:end', async ({ files }) => {\n progressBar.update(files.length, { message: 'Done ✅' })\n progressBar.stop()\n })\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAaA,IAAa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AAC3C,eAAY,MAAM,MAAM,QAAQ,GAAG,EAAE,SAAS,eAAe,CAAC;IAC9D;AAEF,MAAI,GAAG,oBAAoB,OAAO,EAAE,WAAW;GAC7C,MAAM,UAAU,mCAAoBC,qBAAQ,KAAK,EAAE,KAAK,KAAK;AAC7D,eAAY,UAAU,GAAG,EAAE,SAAS,CAAC;IACrC;AAEF,MAAI,GAAG,eAAe,OAAO,EAAE,YAAY;AACzC,eAAY,OAAO,MAAM,QAAQ,EAAE,SAAS,UAAU,CAAC;AACvD,eAAY,MAAM;IAClB;;CAEL,CAAC"}
@@ -1,4 +1,4 @@
1
- import { f as Extname, o as Plugin, s as UserPlugin } from "./Fabric-0mXLgmur.cjs";
1
+ import { f as Extname, o as Plugin, s as UserPlugin } from "./Fabric-CBrTERuf.cjs";
2
2
 
3
3
  //#region src/plugins/barrelPlugin.d.ts
4
4
  type Mode = 'all' | 'named' | 'propagate' | false;
@@ -14,11 +14,6 @@ type WriteEntryOptions = {
14
14
  type ExtendOptions$1 = {
15
15
  writeEntry(options: WriteEntryOptions): Promise<void>;
16
16
  };
17
- declare module '@kubb/fabric-core' {
18
- interface Fabric {
19
- writeEntry(options: WriteEntryOptions): Promise<void>;
20
- }
21
- }
22
17
  declare global {
23
18
  namespace Kubb {
24
19
  interface Fabric {
@@ -49,11 +44,6 @@ type Options$1 = {
49
44
  type ExtendOptions = {
50
45
  write(options?: WriteOptions): Promise<void>;
51
46
  };
52
- declare module '@kubb/fabric-core' {
53
- interface Fabric {
54
- write(options?: WriteOptions): Promise<void>;
55
- }
56
- }
57
47
  declare global {
58
48
  namespace Kubb {
59
49
  interface Fabric {
package/dist/plugins.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { f as Extname, o as Plugin, s as UserPlugin } from "./Fabric-C-AqOkTA.js";
1
+ import { f as Extname, o as Plugin, s as UserPlugin } from "./Fabric-AmREkq58.js";
2
2
 
3
3
  //#region src/plugins/barrelPlugin.d.ts
4
4
  type Mode = 'all' | 'named' | 'propagate' | false;
@@ -14,11 +14,6 @@ type WriteEntryOptions = {
14
14
  type ExtendOptions$1 = {
15
15
  writeEntry(options: WriteEntryOptions): Promise<void>;
16
16
  };
17
- declare module '@kubb/fabric-core' {
18
- interface Fabric {
19
- writeEntry(options: WriteEntryOptions): Promise<void>;
20
- }
21
- }
22
17
  declare global {
23
18
  namespace Kubb {
24
19
  interface Fabric {
@@ -49,11 +44,6 @@ type Options$1 = {
49
44
  type ExtendOptions = {
50
45
  write(options?: WriteOptions): Promise<void>;
51
46
  };
52
- declare module '@kubb/fabric-core' {
53
- interface Fabric {
54
- write(options?: WriteOptions): Promise<void>;
55
- }
56
- }
57
47
  declare global {
58
48
  namespace Kubb {
59
49
  interface Fabric {
package/dist/plugins.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as createFile, i as _classPrivateFieldInitSpec, n as _classPrivateFieldGet2, r as _assertClassBrand, t as _defineProperty } from "./defineProperty-BZknW4oy.js";
1
+ import { a as createFile, i as _classPrivateFieldInitSpec, n as _classPrivateFieldSet2, r as _classPrivateFieldGet2, t as _defineProperty } from "./defineProperty-_FBdEen_.js";
2
2
  import "./trimExtName-CeOVQVbu.js";
3
3
  import { t as getRelativePath } from "./getRelativePath-CERJmYkp.js";
4
4
  import path, { relative, resolve } from "node:path";
@@ -9,12 +9,6 @@ import { spawn } from "node:child_process";
9
9
  import process$1 from "node:process";
10
10
  import { Presets, SingleBar } from "cli-progress";
11
11
 
12
- //#region \0@oxc-project+runtime@0.95.0/helpers/classPrivateFieldSet2.js
13
- function _classPrivateFieldSet2(s, a, r) {
14
- return s.set(_assertClassBrand(s, a), r), r;
15
- }
16
-
17
- //#endregion
18
12
  //#region src/utils/TreeNode.ts
19
13
  var _cachedLeaves = /* @__PURE__ */ new WeakMap();
20
14
  var TreeNode = class TreeNode {
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.js","names":["stack: Array<TreeNode<TData>>","result: Array<TreeNode<TData>>","nodes: Array<{ id: string; label: string }>","edges: Array<{ from: string; to: string }>","next: TreeNode<BarrelData> | undefined","path","path","process"],"sources":["../src/utils/TreeNode.ts","../src/plugins/createPlugin.ts","../src/plugins/barrelPlugin.ts","../src/plugins/fsPlugin.ts","../src/utils/open.ts","../src/plugins/graphPlugin.ts","../src/plugins/progressPlugin.ts"],"sourcesContent":["import type * as KubbFile from '../KubbFile.ts'\n\ntype BarrelData = {\n file?: KubbFile.File\n path: string\n name: string\n}\n\nexport type Graph = {\n nodes: Array<{ id: string; label: string }>\n edges: Array<{ from: string; to: string }>\n}\n\nexport class TreeNode<TData = unknown> {\n data: TData\n parent?: TreeNode<TData>\n children: Array<TreeNode<TData>> = []\n #cachedLeaves?: Array<TreeNode<TData>>\n\n constructor(data: TData, parent?: TreeNode<TData>) {\n this.data = data\n this.parent = parent\n }\n\n addChild(data: TData): TreeNode<TData> {\n const child = new TreeNode(data, this)\n this.children.push(child)\n this.#cachedLeaves = undefined // invalidate cached leaves\n return child\n }\n\n get leaves(): Array<TreeNode<TData>> {\n if (this.#cachedLeaves) return this.#cachedLeaves\n if (this.children.length === 0) return [this]\n\n const stack: Array<TreeNode<TData>> = [...this.children]\n const result: Array<TreeNode<TData>> = []\n\n for (const node of stack) {\n if (node.children.length) {\n for (const child of node.children) stack.push(child)\n } else {\n result.push(node)\n }\n }\n\n this.#cachedLeaves = result\n return result\n }\n\n forEach(callback: (node: TreeNode<TData>) => void): this {\n const stack: Array<TreeNode<TData>> = [this]\n\n for (const node of stack) {\n callback(node)\n if (node.children.length) {\n for (const child of node.children) stack.push(child)\n }\n }\n return this\n }\n\n findDeep(predicate: (node: TreeNode<TData>) => boolean): TreeNode<TData> | undefined {\n for (const leaf of this.leaves) {\n if (predicate(leaf)) return leaf\n }\n return undefined\n }\n\n static toGraph(root: TreeNode<BarrelData>): Graph {\n const nodes: Array<{ id: string; label: string }> = []\n const edges: Array<{ from: string; to: string }> = []\n\n root.forEach((node) => {\n nodes.push({\n id: node.data.path,\n label: node.data.name,\n })\n\n for (const child of node.children) {\n edges.push({\n from: node.data.path,\n to: child.data.path,\n })\n }\n })\n\n return { nodes, edges }\n }\n\n static fromFiles(files: Array<KubbFile.File>, rootFolder = ''): TreeNode<BarrelData> | null {\n const normalizePath = (p: string): string => p.replace(/\\\\/g, '/')\n const normalizedRoot = normalizePath(rootFolder)\n const rootPrefix = normalizedRoot.endsWith('/') ? normalizedRoot : `${normalizedRoot}/`\n\n const filteredFiles = files.filter((file) => {\n const filePath = normalizePath(file.path)\n\n return !filePath.endsWith('.json') && (!rootFolder || filePath.startsWith(rootPrefix))\n })\n\n if (filteredFiles.length === 0) {\n return null\n }\n\n const treeNode = new TreeNode<BarrelData>({\n name: rootFolder || '',\n path: rootFolder || '',\n file: undefined,\n })\n\n for (const file of filteredFiles) {\n const relPath = normalizePath(file.path).slice(rootPrefix.length)\n const parts = relPath.split('/')\n\n let current = treeNode\n let currentPath = rootFolder\n\n for (const [index, part] of parts.entries()) {\n const isLast = index === parts.length - 1\n currentPath += (currentPath.endsWith('/') ? '' : '/') + part\n\n let next: TreeNode<BarrelData> | undefined\n for (const child of current.children) {\n if ((child.data as BarrelData).name === part) {\n next = child\n break\n }\n }\n\n if (!next) {\n next = current.addChild({\n name: part,\n path: currentPath,\n file: isLast ? file : undefined,\n })\n }\n\n current = next\n }\n }\n\n return treeNode\n }\n}\n","import type { Plugin, UserPlugin } from './types.ts'\n\nexport function createPlugin<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 { createPlugin } from './createPlugin.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 writeEntry(options: WriteEntryOptions): Promise<void>\n}\n\n// biome-ignore lint/suspicious/noTsIgnore: production ready\n// @ts-ignore\ndeclare module '@kubb/fabric-core' {\n interface Fabric {\n writeEntry(options: WriteEntryOptions): Promise<void>\n }\n}\n\ndeclare global {\n namespace Kubb {\n interface Fabric {\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 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 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 // Collect all leaves under the current directory node\n node.leaves.forEach((leaf) => {\n const file = leaf.data.file\n if (!file) {\n return\n }\n\n const sources = file.sources || []\n sources.forEach((source) => {\n if (!file.path || !source.isIndexable || !source.name) {\n return\n }\n\n const key = `${source.name}|${source.isTypeOnly ? '1' : '0'}`\n if (seen.has(key)) {\n return\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 = createPlugin<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('write: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 = ctx.files.filter((file) => {\n return file.sources.some((source) => source.isIndexable)\n })\n\n const entryFile = createFile({\n path: rootPath,\n baseName: 'index.ts',\n exports: barrelFiles\n .flatMap((file) => {\n const containsOnlyTypes = file.sources.every((source) => source.isTypeOnly)\n\n return file.sources\n ?.map((source) => {\n if (!file.path || !source.isIndexable) {\n return undefined\n }\n\n return {\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 .filter(Boolean)\n })\n .filter(Boolean),\n sources: [],\n })\n\n await ctx.addFile(entryFile)\n\n await ctx.fileManager.write({\n mode: ctx.config?.options?.mode,\n dryRun: options.dryRun,\n parsers: ctx.installedParsers,\n })\n },\n }\n },\n})\n","import { resolve } from 'node:path'\nimport fs from 'fs-extra'\nimport type * as KubbFile from '../KubbFile.ts'\nimport { createPlugin } from './createPlugin.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 fs.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 fs.outputFile(resolve(path), data.trim(), { encoding: 'utf-8' })\n\n if (options?.sanity) {\n const savedData = await fs.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\n// biome-ignore lint/suspicious/noTsIgnore: production ready\n// @ts-ignore\ndeclare module '@kubb/fabric-core' {\n interface Fabric {\n write(options?: WriteOptions): Promise<void>\n }\n}\n\ndeclare global {\n namespace Kubb {\n interface Fabric {\n write(options?: WriteOptions): Promise<void>\n }\n }\n}\n\nexport const fsPlugin = createPlugin<Options, ExtendOptions>({\n name: 'fs',\n install(ctx, options = {}) {\n if (options.clean) {\n fs.removeSync(options.clean.path)\n }\n\n ctx.on('process:progress', 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?.options?.mode,\n extension: options.extension,\n dryRun,\n parsers: ctx.installedParsers,\n })\n },\n }\n },\n})\n","import { spawn } from 'node:child_process'\n\nconst spawnBin = (bin: string, args: string[]): Promise<boolean> => {\n return new Promise((resolve) => {\n const process = spawn(bin, args, {\n detached: true,\n shell: false,\n windowsHide: true,\n })\n\n process.on('close', (code) => {\n resolve(!code)\n })\n })\n}\n\ntype Options = {\n app?: string\n}\n\nexport async function open(path: string, options?: Options): Promise<boolean> {\n const app = options?.app\n\n if (process.platform === 'win32') {\n return spawnBin('cmd.exe', ['/c', 'start', app || '', path.replace(/[&^]/g, '^$&')])\n }\n\n if (process.platform === 'linux') {\n return spawnBin(app || 'xdg-open', [path])\n }\n if (process.platform === 'darwin') {\n return spawnBin('open', app ? ['-a', app, path] : [path])\n }\n\n throw new Error(`Unsupported platform, could not open \"${path}\"`)\n}\n","import http from 'node:http'\nimport type { AddressInfo } from 'node:net'\nimport path from 'node:path'\nimport handler from 'serve-handler'\nimport { createFile } from '../createFile.ts'\nimport type * as KubbFile from '../KubbFile.ts'\nimport { open } from '../utils/open.ts'\nimport { type Graph, TreeNode } from '../utils/TreeNode.ts'\nimport { createPlugin } from './createPlugin.ts'\n\ntype Options = {\n root: string\n /**\n * @default false\n */\n open?: boolean\n}\n\ntype GetGraphOptions = {\n files: KubbFile.File[]\n root: string\n}\n\nexport function getGraph({ files, root }: GetGraphOptions): Graph | undefined {\n const treeNode = TreeNode.fromFiles(files, root)\n\n if (!treeNode) {\n return undefined\n }\n\n return TreeNode.toGraph(treeNode)\n}\nconst html = `\n <!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <title>File Graph</title>\n <script type=\"module\">\n import { Network } from 'https://cdn.jsdelivr.net/npm/vis-network/standalone/esm/vis-network.min.js'\n\n async function main() {\n const res = await fetch('./graph.json')\n const { nodes, edges } = await res.json()\n const container = document.getElementById('graph')\n\n const network = new Network(\n container,\n { nodes, edges },\n {\n layout: { hierarchical: { direction: 'UD', sortMethod: 'directed' } },\n nodes: { shape: 'box', font: { face: 'monospace' } },\n edges: { arrows: 'to' },\n physics: false,\n },\n )\n }\n\n main()\n </script>\n <style>\n html, body, #graph { height: 100%; margin: 0; }\n </style>\n </head>\n <body>\n <div id=\"graph\"></div>\n </body>\n</html>\n`\n\nasync function serve(root: string) {\n const server = http.createServer((req, res) => {\n return handler(req, res, {\n public: root,\n cleanUrls: true,\n })\n })\n\n server.listen(0, async () => {\n const { port } = server.address() as AddressInfo\n console.log(`Running on http://localhost:${port}/graph.html`)\n\n await open(`http://localhost:${port}/graph.html`)\n })\n}\n\nexport const graphPlugin = createPlugin<Options>({\n name: 'graph',\n install(ctx, options) {\n if (!options) {\n throw new Error('Graph plugin requires options.root and options.mode')\n }\n\n ctx.on('write:start', async ({ files }) => {\n const root = options.root\n\n const graph = getGraph({ files, root })\n\n if (!graph) {\n return undefined\n }\n\n const graphFile = createFile({\n baseName: 'graph.json',\n path: path.join(root, 'graph.json'),\n sources: [\n {\n name: 'graph',\n value: JSON.stringify(graph, null, 2),\n },\n ],\n })\n\n const graphHtmlFile = createFile({\n baseName: 'graph.html',\n path: path.join(root, 'graph.html'),\n sources: [\n {\n name: 'graph',\n value: html,\n },\n ],\n })\n\n await ctx.addFile(graphFile, graphHtmlFile)\n\n if (options.open) {\n await serve(root)\n }\n })\n },\n})\n","import { relative } from 'node:path'\nimport process from 'node:process'\nimport { Presets, SingleBar } from 'cli-progress'\nimport { createPlugin } from './createPlugin.ts'\n\nexport const progressPlugin = createPlugin({\n name: 'progress',\n install(ctx) {\n const progressBar = new SingleBar(\n {\n format: '{bar} {percentage}% | {value}/{total} | {message}',\n barCompleteChar: '█',\n barIncompleteChar: '░',\n hideCursor: true,\n clearOnComplete: true,\n },\n Presets.shades_grey,\n )\n\n ctx.on('process:start', async ({ files }) => {\n progressBar.start(files.length, 0, { message: 'Starting...' })\n })\n\n ctx.on('process:progress', async ({ file }) => {\n const message = `Writing ${relative(process.cwd(), file.path)}`\n progressBar.increment(1, { message })\n })\n\n ctx.on('process:end', async ({ files }) => {\n progressBar.update(files.length, { message: 'Done ✅' })\n progressBar.stop()\n })\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAaA,IAAa,WAAb,MAAa,SAA0B;CAMrC,YAAY,MAAa,QAA0B;wBALnD;wBACA;wBACA,YAAmC,EAAE;;AAInC,OAAK,OAAO;AACZ,OAAK,SAAS;;CAGhB,SAAS,MAA8B;EACrC,MAAM,QAAQ,IAAI,SAAS,MAAM,KAAK;AACtC,OAAK,SAAS,KAAK,MAAM;AACzB,8CAAqB,OAAS;AAC9B,SAAO;;CAGT,IAAI,SAAiC;AACnC,4CAAI,KAAkB,CAAE,8CAAO,KAAkB;AACjD,MAAI,KAAK,SAAS,WAAW,EAAG,QAAO,CAAC,KAAK;EAE7C,MAAMA,QAAgC,CAAC,GAAG,KAAK,SAAS;EACxD,MAAMC,SAAiC,EAAE;AAEzC,OAAK,MAAM,QAAQ,MACjB,KAAI,KAAK,SAAS,OAChB,MAAK,MAAM,SAAS,KAAK,SAAU,OAAM,KAAK,MAAM;MAEpD,QAAO,KAAK,KAAK;AAIrB,8CAAqB,OAAM;AAC3B,SAAO;;CAGT,QAAQ,UAAiD;EACvD,MAAMD,QAAgC,CAAC,KAAK;AAE5C,OAAK,MAAM,QAAQ,OAAO;AACxB,YAAS,KAAK;AACd,OAAI,KAAK,SAAS,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UAAU,OAAO,MAAM,EAAE;KACtC,CACF;IACF,CAAC;GAEF,MAAM,gBAAgB,WAAW;IAC/B,UAAU;IACV,MAAM,KAAK,KAAK,MAAM,aAAa;IACnC,SAAS,CACP;KACE,MAAM;KACN,OAAO;KACR,CACF;IACF,CAAC;AAEF,SAAM,IAAI,QAAQ,WAAW,cAAc;AAE3C,OAAI,QAAQ,KACV,OAAM,MAAM,KAAK;IAEnB;;CAEL,CAAC;;;;AC9HF,MAAa,iBAAiB,aAAa;CACzC,MAAM;CACN,QAAQ,KAAK;EACX,MAAM,cAAc,IAAI,UACtB;GACE,QAAQ;GACR,iBAAiB;GACjB,mBAAmB;GACnB,YAAY;GACZ,iBAAiB;GAClB,EACD,QAAQ,YACT;AAED,MAAI,GAAG,iBAAiB,OAAO,EAAE,YAAY;AAC3C,eAAY,MAAM,MAAM,QAAQ,GAAG,EAAE,SAAS,eAAe,CAAC;IAC9D;AAEF,MAAI,GAAG,oBAAoB,OAAO,EAAE,WAAW;GAC7C,MAAM,UAAU,WAAW,SAASC,UAAQ,KAAK,EAAE,KAAK,KAAK;AAC7D,eAAY,UAAU,GAAG,EAAE,SAAS,CAAC;IACrC;AAEF,MAAI,GAAG,eAAe,OAAO,EAAE,YAAY;AACzC,eAAY,OAAO,MAAM,QAAQ,EAAE,SAAS,UAAU,CAAC;AACvD,eAAY,MAAM;IAClB;;CAEL,CAAC"}
1
+ {"version":3,"file":"plugins.js","names":["stack: Array<TreeNode<TData>>","result: Array<TreeNode<TData>>","nodes: Array<{ id: string; label: string }>","edges: Array<{ from: string; to: string }>","next: TreeNode<BarrelData> | undefined","path","path","process"],"sources":["../src/utils/TreeNode.ts","../src/plugins/createPlugin.ts","../src/plugins/barrelPlugin.ts","../src/plugins/fsPlugin.ts","../src/utils/open.ts","../src/plugins/graphPlugin.ts","../src/plugins/progressPlugin.ts"],"sourcesContent":["import type * as KubbFile from '../KubbFile.ts'\n\ntype BarrelData = {\n file?: KubbFile.File\n path: string\n name: string\n}\n\nexport type Graph = {\n nodes: Array<{ id: string; label: string }>\n edges: Array<{ from: string; to: string }>\n}\n\nexport class TreeNode<TData = unknown> {\n data: TData\n parent?: TreeNode<TData>\n children: Array<TreeNode<TData>> = []\n #cachedLeaves?: Array<TreeNode<TData>>\n\n constructor(data: TData, parent?: TreeNode<TData>) {\n this.data = data\n this.parent = parent\n }\n\n addChild(data: TData): TreeNode<TData> {\n const child = new TreeNode(data, this)\n this.children.push(child)\n this.#cachedLeaves = undefined // invalidate cached leaves\n return child\n }\n\n get leaves(): Array<TreeNode<TData>> {\n if (this.#cachedLeaves) return this.#cachedLeaves\n if (this.children.length === 0) return [this]\n\n const stack: Array<TreeNode<TData>> = [...this.children]\n const result: Array<TreeNode<TData>> = []\n\n for (const node of stack) {\n if (node.children.length) {\n for (const child of node.children) stack.push(child)\n } else {\n result.push(node)\n }\n }\n\n this.#cachedLeaves = result\n return result\n }\n\n forEach(callback: (node: TreeNode<TData>) => void): this {\n const stack: Array<TreeNode<TData>> = [this]\n\n for (const node of stack) {\n callback(node)\n if (node.children.length) {\n for (const child of node.children) stack.push(child)\n }\n }\n return this\n }\n\n findDeep(predicate: (node: TreeNode<TData>) => boolean): TreeNode<TData> | undefined {\n for (const leaf of this.leaves) {\n if (predicate(leaf)) return leaf\n }\n return undefined\n }\n\n static toGraph(root: TreeNode<BarrelData>): Graph {\n const nodes: Array<{ id: string; label: string }> = []\n const edges: Array<{ from: string; to: string }> = []\n\n root.forEach((node) => {\n nodes.push({\n id: node.data.path,\n label: node.data.name,\n })\n\n for (const child of node.children) {\n edges.push({\n from: node.data.path,\n to: child.data.path,\n })\n }\n })\n\n return { nodes, edges }\n }\n\n static fromFiles(files: Array<KubbFile.File>, rootFolder = ''): TreeNode<BarrelData> | null {\n const normalizePath = (p: string): string => p.replace(/\\\\/g, '/')\n const normalizedRoot = normalizePath(rootFolder)\n const rootPrefix = normalizedRoot.endsWith('/') ? normalizedRoot : `${normalizedRoot}/`\n\n const filteredFiles = files.filter((file) => {\n const filePath = normalizePath(file.path)\n\n return !filePath.endsWith('.json') && (!rootFolder || filePath.startsWith(rootPrefix))\n })\n\n if (filteredFiles.length === 0) {\n return null\n }\n\n const treeNode = new TreeNode<BarrelData>({\n name: rootFolder || '',\n path: rootFolder || '',\n file: undefined,\n })\n\n for (const file of filteredFiles) {\n const relPath = normalizePath(file.path).slice(rootPrefix.length)\n const parts = relPath.split('/')\n\n let current = treeNode\n let currentPath = rootFolder\n\n for (const [index, part] of parts.entries()) {\n const isLast = index === parts.length - 1\n currentPath += (currentPath.endsWith('/') ? '' : '/') + part\n\n let next: TreeNode<BarrelData> | undefined\n for (const child of current.children) {\n if ((child.data as BarrelData).name === part) {\n next = child\n break\n }\n }\n\n if (!next) {\n next = current.addChild({\n name: part,\n path: currentPath,\n file: isLast ? file : undefined,\n })\n }\n\n current = next\n }\n }\n\n return treeNode\n }\n}\n","import type { Plugin, UserPlugin } from './types.ts'\n\nexport function createPlugin<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 { createPlugin } from './createPlugin.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 writeEntry(options: WriteEntryOptions): Promise<void>\n}\n\ndeclare global {\n namespace Kubb {\n interface Fabric {\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 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 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 // Collect all leaves under the current directory node\n node.leaves.forEach((leaf) => {\n const file = leaf.data.file\n if (!file) {\n return\n }\n\n const sources = file.sources || []\n sources.forEach((source) => {\n if (!file.path || !source.isIndexable || !source.name) {\n return\n }\n\n const key = `${source.name}|${source.isTypeOnly ? '1' : '0'}`\n if (seen.has(key)) {\n return\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 = createPlugin<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('write: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 = ctx.files.filter((file) => {\n return file.sources.some((source) => source.isIndexable)\n })\n\n const entryFile = createFile({\n path: rootPath,\n baseName: 'index.ts',\n exports: barrelFiles\n .flatMap((file) => {\n const containsOnlyTypes = file.sources.every((source) => source.isTypeOnly)\n\n return file.sources\n ?.map((source) => {\n if (!file.path || !source.isIndexable) {\n return undefined\n }\n\n return {\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 .filter(Boolean)\n })\n .filter(Boolean),\n sources: [],\n })\n\n await ctx.addFile(entryFile)\n\n await ctx.fileManager.write({\n mode: ctx.config?.options?.mode,\n dryRun: options.dryRun,\n parsers: ctx.installedParsers,\n })\n },\n }\n },\n})\n","import { resolve } from 'node:path'\nimport fs from 'fs-extra'\nimport type * as KubbFile from '../KubbFile.ts'\nimport { createPlugin } from './createPlugin.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 fs.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 fs.outputFile(resolve(path), data.trim(), { encoding: 'utf-8' })\n\n if (options?.sanity) {\n const savedData = await fs.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 = createPlugin<Options, ExtendOptions>({\n name: 'fs',\n install(ctx, options = {}) {\n if (options.clean) {\n fs.removeSync(options.clean.path)\n }\n\n ctx.on('process:progress', 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?.options?.mode,\n extension: options.extension,\n dryRun,\n parsers: ctx.installedParsers,\n })\n },\n }\n },\n})\n","import { spawn } from 'node:child_process'\n\nconst spawnBin = (bin: string, args: string[]): Promise<boolean> => {\n return new Promise((resolve) => {\n const process = spawn(bin, args, {\n detached: true,\n shell: false,\n windowsHide: true,\n })\n\n process.on('close', (code) => {\n resolve(!code)\n })\n })\n}\n\ntype Options = {\n app?: string\n}\n\nexport async function open(path: string, options?: Options): Promise<boolean> {\n const app = options?.app\n\n if (process.platform === 'win32') {\n return spawnBin('cmd.exe', ['/c', 'start', app || '', path.replace(/[&^]/g, '^$&')])\n }\n\n if (process.platform === 'linux') {\n return spawnBin(app || 'xdg-open', [path])\n }\n if (process.platform === 'darwin') {\n return spawnBin('open', app ? ['-a', app, path] : [path])\n }\n\n throw new Error(`Unsupported platform, could not open \"${path}\"`)\n}\n","import http from 'node:http'\nimport type { AddressInfo } from 'node:net'\nimport path from 'node:path'\nimport handler from 'serve-handler'\nimport { createFile } from '../createFile.ts'\nimport type * as KubbFile from '../KubbFile.ts'\nimport { open } from '../utils/open.ts'\nimport { type Graph, TreeNode } from '../utils/TreeNode.ts'\nimport { createPlugin } from './createPlugin.ts'\n\ntype Options = {\n root: string\n /**\n * @default false\n */\n open?: boolean\n}\n\ntype GetGraphOptions = {\n files: KubbFile.File[]\n root: string\n}\n\nexport function getGraph({ files, root }: GetGraphOptions): Graph | undefined {\n const treeNode = TreeNode.fromFiles(files, root)\n\n if (!treeNode) {\n return undefined\n }\n\n return TreeNode.toGraph(treeNode)\n}\nconst html = `\n <!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <title>File Graph</title>\n <script type=\"module\">\n import { Network } from 'https://cdn.jsdelivr.net/npm/vis-network/standalone/esm/vis-network.min.js'\n\n async function main() {\n const res = await fetch('./graph.json')\n const { nodes, edges } = await res.json()\n const container = document.getElementById('graph')\n\n const network = new Network(\n container,\n { nodes, edges },\n {\n layout: { hierarchical: { direction: 'UD', sortMethod: 'directed' } },\n nodes: { shape: 'box', font: { face: 'monospace' } },\n edges: { arrows: 'to' },\n physics: false,\n },\n )\n }\n\n main()\n </script>\n <style>\n html, body, #graph { height: 100%; margin: 0; }\n </style>\n </head>\n <body>\n <div id=\"graph\"></div>\n </body>\n</html>\n`\n\nasync function serve(root: string) {\n const server = http.createServer((req, res) => {\n return handler(req, res, {\n public: root,\n cleanUrls: true,\n })\n })\n\n server.listen(0, async () => {\n const { port } = server.address() as AddressInfo\n console.log(`Running on http://localhost:${port}/graph.html`)\n\n await open(`http://localhost:${port}/graph.html`)\n })\n}\n\nexport const graphPlugin = createPlugin<Options>({\n name: 'graph',\n install(ctx, options) {\n if (!options) {\n throw new Error('Graph plugin requires options.root and options.mode')\n }\n\n ctx.on('write:start', async ({ files }) => {\n const root = options.root\n\n const graph = getGraph({ files, root })\n\n if (!graph) {\n return undefined\n }\n\n const graphFile = createFile({\n baseName: 'graph.json',\n path: path.join(root, 'graph.json'),\n sources: [\n {\n name: 'graph',\n value: JSON.stringify(graph, null, 2),\n },\n ],\n })\n\n const graphHtmlFile = createFile({\n baseName: 'graph.html',\n path: path.join(root, 'graph.html'),\n sources: [\n {\n name: 'graph',\n value: html,\n },\n ],\n })\n\n await ctx.addFile(graphFile, graphHtmlFile)\n\n if (options.open) {\n await serve(root)\n }\n })\n },\n})\n","import { relative } from 'node:path'\nimport process from 'node:process'\nimport { Presets, SingleBar } from 'cli-progress'\nimport { createPlugin } from './createPlugin.ts'\n\nexport const progressPlugin = createPlugin({\n name: 'progress',\n install(ctx) {\n const progressBar = new SingleBar(\n {\n format: '{bar} {percentage}% | {value}/{total} | {message}',\n barCompleteChar: '█',\n barIncompleteChar: '░',\n hideCursor: true,\n clearOnComplete: true,\n },\n Presets.shades_grey,\n )\n\n ctx.on('process:start', async ({ files }) => {\n progressBar.start(files.length, 0, { message: 'Starting...' })\n })\n\n ctx.on('process:progress', async ({ file }) => {\n const message = `Writing ${relative(process.cwd(), file.path)}`\n progressBar.increment(1, { message })\n })\n\n ctx.on('process:end', async ({ files }) => {\n progressBar.update(files.length, { message: 'Done ✅' })\n progressBar.stop()\n })\n },\n})\n"],"mappings":";;;;;;;;;;;;;AAaA,IAAa,WAAb,M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MAAM,MAAM,QAAQ,GAAG,EAAE,SAAS,eAAe,CAAC;IAC9D;AAEF,MAAI,GAAG,oBAAoB,OAAO,EAAE,WAAW;GAC7C,MAAM,UAAU,WAAW,SAASC,UAAQ,KAAK,EAAE,KAAK,KAAK;AAC7D,eAAY,UAAU,GAAG,EAAE,SAAS,CAAC;IACrC;AAEF,MAAI,GAAG,eAAe,OAAO,EAAE,YAAY;AACzC,eAAY,OAAO,MAAM,QAAQ,EAAE,SAAS,UAAU,CAAC;AACvD,eAAY,MAAM;IAClB;;CAEL,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","names":[],"sources":["../src/KubbFile.ts"],"sourcesContent":["type BasePath<T extends string = string> = `${T}/`\n\nexport type Import = {\n /**\n * Import name to be used\n * @example [\"useState\"]\n * @example \"React\"\n */\n name:\n | string\n | Array<\n | string\n | {\n propertyName: string\n name?: string\n }\n >\n /**\n * Path for the import\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n\n isNameSpace?: boolean\n /**\n * When root is set it will get the path with relative getRelativePath(root, path).\n */\n root?: string\n}\n\nexport type Source = {\n name?: string\n value?: string\n isTypeOnly?: boolean\n /**\n * Has const or type 'export'\n * @default false\n */\n isExportable?: boolean\n /**\n * When set, barrel generation will add this\n * @default false\n */\n isIndexable?: boolean\n}\n\nexport type Export = {\n /**\n * Export name to be used.\n * @example [\"useState\"]\n * @example \"React\"\n */\n name?: string | Array<string>\n /**\n * Path for the import.\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n /**\n * Make it possible to override the name, this will result in: `export * as aliasName from './path'`.\n */\n asAlias?: boolean\n}\n\nexport type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`\n\nexport type Mode = 'single' | 'split'\n\n/**\n * Name to be used to dynamicly create the baseName(based on input.path)\n * Based on UNIX basename\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\nexport type BaseName = `${string}.${string}`\n\n/**\n * Path will be full qualified path to a specified file\n */\nexport type Path = string\n\nexport type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`\n\nexport type OptionalPath = Path | undefined | null\n\nexport type File<TMeta extends object = object> = {\n /**\n * Name to be used to create the path\n * Based on UNIX basename, `${name}.extname`\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: BaseName\n /**\n * Path will be full qualified path to a specified file\n */\n path: AdvancedPath<BaseName> | Path\n sources: Array<Source>\n imports?: Array<Import>\n exports?: Array<Export>\n /**\n * Use extra meta, this is getting used to generate the barrel/index files.\n */\n meta?: TMeta\n banner?: string\n footer?: string\n}\n\nexport type ResolvedImport = Import\n\nexport type ResolvedExport = Export\n\nexport type ResolvedFile<TMeta extends object = object> = File<TMeta> & {\n /**\n * @default hash\n */\n id: string\n /**\n * Contains the first part of the baseName, generated based on baseName\n * @link https://nodejs.org/api/path.html#pathformatpathobject\n */\n name: string\n extname: Extname\n imports: Array<ResolvedImport>\n exports: Array<ResolvedExport>\n}\n"],"mappings":""}
1
+ {"version":3,"file":"types.cjs","names":[],"sources":["../src/KubbFile.ts"],"sourcesContent":["type BasePath<T extends string = string> = `${T}/`\n\nexport type Import = {\n /**\n * Import name to be used\n * @example [\"useState\"]\n * @example \"React\"\n */\n name:\n | string\n | Array<\n | string\n | {\n propertyName: string\n name?: string\n }\n >\n /**\n * Path for the import\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n\n isNameSpace?: boolean\n /**\n * When root is set it will get the path with relative getRelativePath(root, path).\n */\n root?: string\n}\n\nexport type Source = {\n name?: string\n value?: string\n isTypeOnly?: boolean\n /**\n * Has const or type 'export'\n * @default false\n */\n isExportable?: boolean\n /**\n * When set, barrel generation will add this\n * @default false\n */\n isIndexable?: boolean\n}\n\nexport type Export = {\n /**\n * Export name to be used.\n * @example [\"useState\"]\n * @example \"React\"\n */\n name?: string | Array<string>\n /**\n * Path for the import.\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n /**\n * Make it possible to override the name, this will result in: `export * as aliasName from './path'`.\n */\n asAlias?: boolean\n}\n\nexport type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`\n\nexport type Mode = 'single' | 'split'\n\n/**\n * Name to be used to dynamicly create the baseName(based on input.path)\n * Based on UNIX basename\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\nexport type BaseName = `${string}.${string}`\n\n/**\n * Path will be full qualified path to a specified file\n */\nexport type Path = string\n\nexport type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`\n\nexport type File<TMeta extends object = object> = {\n /**\n * Name to be used to create the path\n * Based on UNIX basename, `${name}.extname`\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: BaseName\n /**\n * Path will be full qualified path to a specified file\n */\n path: AdvancedPath<BaseName> | Path\n sources: Array<Source>\n imports?: Array<Import>\n exports?: Array<Export>\n /**\n * Use extra meta, this is getting used to generate the barrel/index files.\n */\n meta?: TMeta\n banner?: string\n footer?: string\n}\n\nexport type ResolvedImport = Import\n\nexport type ResolvedExport = Export\n\nexport type ResolvedFile<TMeta extends object = object> = File<TMeta> & {\n /**\n * @default hash\n */\n id: string\n /**\n * Contains the first part of the baseName, generated based on baseName\n * @link https://nodejs.org/api/path.html#pathformatpathobject\n */\n name: string\n extname: Extname\n imports: Array<ResolvedImport>\n exports: Array<ResolvedExport>\n}\n"],"mappings":""}
package/dist/types.d.cts CHANGED
@@ -1,3 +1,2 @@
1
- import { a as FabricOptions, i as FabricMode, m as KubbFile_d_exports, n as FabricConfig, r as FabricContext } from "./Fabric-0mXLgmur.cjs";
2
- import { t as DefineFabric } from "./defineFabric-Dkt2l0wC.cjs";
3
- export { type DefineFabric, type FabricConfig, type FabricContext, type FabricMode, type FabricOptions, KubbFile_d_exports as KubbFile };
1
+ import { a as FabricOptions, i as FabricMode, m as KubbFile_d_exports, n as FabricConfig, r as FabricContext } from "./Fabric-CBrTERuf.cjs";
2
+ export { type FabricConfig, type FabricContext, type FabricMode, type FabricOptions, KubbFile_d_exports as KubbFile };
package/dist/types.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- import { a as FabricOptions, i as FabricMode, m as KubbFile_d_exports, n as FabricConfig, r as FabricContext } from "./Fabric-C-AqOkTA.js";
2
- import { t as DefineFabric } from "./defineFabric-D_m6CB1s.js";
3
- export { type DefineFabric, type FabricConfig, type FabricContext, type FabricMode, type FabricOptions, KubbFile_d_exports as KubbFile };
1
+ import { a as FabricOptions, i as FabricMode, m as KubbFile_d_exports, n as FabricConfig, r as FabricContext } from "./Fabric-AmREkq58.js";
2
+ export { type FabricConfig, type FabricContext, type FabricMode, type FabricOptions, KubbFile_d_exports as KubbFile };
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../src/KubbFile.ts"],"sourcesContent":["type BasePath<T extends string = string> = `${T}/`\n\nexport type Import = {\n /**\n * Import name to be used\n * @example [\"useState\"]\n * @example \"React\"\n */\n name:\n | string\n | Array<\n | string\n | {\n propertyName: string\n name?: string\n }\n >\n /**\n * Path for the import\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n\n isNameSpace?: boolean\n /**\n * When root is set it will get the path with relative getRelativePath(root, path).\n */\n root?: string\n}\n\nexport type Source = {\n name?: string\n value?: string\n isTypeOnly?: boolean\n /**\n * Has const or type 'export'\n * @default false\n */\n isExportable?: boolean\n /**\n * When set, barrel generation will add this\n * @default false\n */\n isIndexable?: boolean\n}\n\nexport type Export = {\n /**\n * Export name to be used.\n * @example [\"useState\"]\n * @example \"React\"\n */\n name?: string | Array<string>\n /**\n * Path for the import.\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n /**\n * Make it possible to override the name, this will result in: `export * as aliasName from './path'`.\n */\n asAlias?: boolean\n}\n\nexport type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`\n\nexport type Mode = 'single' | 'split'\n\n/**\n * Name to be used to dynamicly create the baseName(based on input.path)\n * Based on UNIX basename\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\nexport type BaseName = `${string}.${string}`\n\n/**\n * Path will be full qualified path to a specified file\n */\nexport type Path = string\n\nexport type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`\n\nexport type OptionalPath = Path | undefined | null\n\nexport type File<TMeta extends object = object> = {\n /**\n * Name to be used to create the path\n * Based on UNIX basename, `${name}.extname`\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: BaseName\n /**\n * Path will be full qualified path to a specified file\n */\n path: AdvancedPath<BaseName> | Path\n sources: Array<Source>\n imports?: Array<Import>\n exports?: Array<Export>\n /**\n * Use extra meta, this is getting used to generate the barrel/index files.\n */\n meta?: TMeta\n banner?: string\n footer?: string\n}\n\nexport type ResolvedImport = Import\n\nexport type ResolvedExport = Export\n\nexport type ResolvedFile<TMeta extends object = object> = File<TMeta> & {\n /**\n * @default hash\n */\n id: string\n /**\n * Contains the first part of the baseName, generated based on baseName\n * @link https://nodejs.org/api/path.html#pathformatpathobject\n */\n name: string\n extname: Extname\n imports: Array<ResolvedImport>\n exports: Array<ResolvedExport>\n}\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../src/KubbFile.ts"],"sourcesContent":["type BasePath<T extends string = string> = `${T}/`\n\nexport type Import = {\n /**\n * Import name to be used\n * @example [\"useState\"]\n * @example \"React\"\n */\n name:\n | string\n | Array<\n | string\n | {\n propertyName: string\n name?: string\n }\n >\n /**\n * Path for the import\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n\n isNameSpace?: boolean\n /**\n * When root is set it will get the path with relative getRelativePath(root, path).\n */\n root?: string\n}\n\nexport type Source = {\n name?: string\n value?: string\n isTypeOnly?: boolean\n /**\n * Has const or type 'export'\n * @default false\n */\n isExportable?: boolean\n /**\n * When set, barrel generation will add this\n * @default false\n */\n isIndexable?: boolean\n}\n\nexport type Export = {\n /**\n * Export name to be used.\n * @example [\"useState\"]\n * @example \"React\"\n */\n name?: string | Array<string>\n /**\n * Path for the import.\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n /**\n * Make it possible to override the name, this will result in: `export * as aliasName from './path'`.\n */\n asAlias?: boolean\n}\n\nexport type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`\n\nexport type Mode = 'single' | 'split'\n\n/**\n * Name to be used to dynamicly create the baseName(based on input.path)\n * Based on UNIX basename\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\nexport type BaseName = `${string}.${string}`\n\n/**\n * Path will be full qualified path to a specified file\n */\nexport type Path = string\n\nexport type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`\n\nexport type File<TMeta extends object = object> = {\n /**\n * Name to be used to create the path\n * Based on UNIX basename, `${name}.extname`\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: BaseName\n /**\n * Path will be full qualified path to a specified file\n */\n path: AdvancedPath<BaseName> | Path\n sources: Array<Source>\n imports?: Array<Import>\n exports?: Array<Export>\n /**\n * Use extra meta, this is getting used to generate the barrel/index files.\n */\n meta?: TMeta\n banner?: string\n footer?: string\n}\n\nexport type ResolvedImport = Import\n\nexport type ResolvedExport = Export\n\nexport type ResolvedFile<TMeta extends object = object> = File<TMeta> & {\n /**\n * @default hash\n */\n id: string\n /**\n * Contains the first part of the baseName, generated based on baseName\n * @link https://nodejs.org/api/path.html#pathformatpathobject\n */\n name: string\n extname: Extname\n imports: Array<ResolvedImport>\n exports: Array<ResolvedExport>\n}\n"],"mappings":""}
@@ -1,4 +1,4 @@
1
- import { u as Parser } from "./Fabric-0mXLgmur.cjs";
1
+ import { u as Parser } from "./Fabric-CBrTERuf.cjs";
2
2
  import ts from "typescript";
3
3
 
4
4
  //#region src/parsers/typescriptParser.d.ts
@@ -47,4 +47,4 @@ declare function createExport({
47
47
  declare const typescriptParser: Parser<[], any>;
48
48
  //#endregion
49
49
  export { typescriptParser as i, createImport as n, print as r, createExport as t };
50
- //# sourceMappingURL=typescriptParser-B4-y6QxR.d.cts.map
50
+ //# sourceMappingURL=typescriptParser-C3B3dzh_.d.cts.map
@@ -1,4 +1,4 @@
1
- import { u as Parser } from "./Fabric-C-AqOkTA.js";
1
+ import { u as Parser } from "./Fabric-AmREkq58.js";
2
2
  import ts from "typescript";
3
3
 
4
4
  //#region src/parsers/typescriptParser.d.ts
@@ -47,4 +47,4 @@ declare function createExport({
47
47
  declare const typescriptParser: Parser<[], any>;
48
48
  //#endregion
49
49
  export { typescriptParser as i, createImport as n, print as r, createExport as t };
50
- //# sourceMappingURL=typescriptParser-By3ckLtc.d.ts.map
50
+ //# sourceMappingURL=typescriptParser-DaOfAlmM.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/fabric-core",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
5
5
  "keywords": [
6
6
  "typescript",