@kubb/fabric-core 0.0.0-canary-20251030134404 → 0.0.0-canary-20251104092721

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +5 -1
  2. package/dist/{Fabric-CxMkO4Rt.d.ts → Fabric-0mXLgmur.d.cts} +22 -21
  3. package/dist/{Fabric-BfnUdEpq.d.cts → Fabric-C-AqOkTA.d.ts} +22 -21
  4. package/dist/{defineFabric-CR1OjcoI.d.ts → defineFabric-D_m6CB1s.d.ts} +2 -2
  5. package/dist/{defineFabric-TvKfRefj.d.cts → defineFabric-Dkt2l0wC.d.cts} +2 -2
  6. package/dist/{defineProperty-CspRhtP3.cjs → defineProperty-B05cRoSl.cjs} +26 -26
  7. package/dist/{defineProperty-CspRhtP3.cjs.map → defineProperty-B05cRoSl.cjs.map} +1 -1
  8. package/dist/{defineProperty-BtekiGIK.js → defineProperty-BZknW4oy.js} +27 -27
  9. package/dist/{defineProperty-BtekiGIK.js.map → defineProperty-BZknW4oy.js.map} +1 -1
  10. package/dist/index.cjs +50 -39
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +2 -2
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +50 -39
  15. package/dist/index.js.map +1 -1
  16. package/dist/parsers/typescript.d.cts +2 -2
  17. package/dist/parsers/typescript.d.ts +2 -2
  18. package/dist/parsers.cjs.map +1 -1
  19. package/dist/parsers.d.cts +2 -2
  20. package/dist/parsers.d.ts +2 -2
  21. package/dist/parsers.js.map +1 -1
  22. package/dist/plugins.cjs +96 -96
  23. package/dist/plugins.cjs.map +1 -1
  24. package/dist/plugins.d.cts +35 -35
  25. package/dist/plugins.d.ts +35 -35
  26. package/dist/plugins.js +94 -94
  27. package/dist/plugins.js.map +1 -1
  28. package/dist/types.d.cts +2 -2
  29. package/dist/types.d.ts +2 -2
  30. package/dist/{typescriptParser-Dz9T1BQ1.d.cts → typescriptParser-B4-y6QxR.d.cts} +2 -2
  31. package/dist/{typescriptParser-DypTa1AN.d.ts → typescriptParser-By3ckLtc.d.ts} +2 -2
  32. package/dist/typescriptParser-CNHO6H2_.cjs.map +1 -1
  33. package/dist/typescriptParser-CWT7zCJy.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/Fabric.ts +12 -11
  36. package/src/FileManager.ts +4 -4
  37. package/src/FileProcessor.ts +3 -4
  38. package/src/createFile.ts +3 -3
  39. package/src/defineFabric.ts +16 -8
  40. package/src/index.ts +3 -3
  41. package/src/parsers/tsxParser.ts +1 -1
  42. package/src/parsers/types.ts +1 -1
  43. package/src/parsers/typescriptParser.ts +1 -1
  44. package/src/plugins/barrelPlugin.ts +13 -13
  45. package/src/plugins/fsPlugin.ts +8 -8
  46. package/src/plugins/graphPlugin.ts +8 -9
  47. package/src/plugins/index.ts +2 -3
  48. package/src/plugins/progressPlugin.ts +6 -6
  49. package/src/plugins/types.ts +1 -1
  50. package/src/types.ts +2 -2
package/src/createFile.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type * as KubbFile from './KubbFile.ts'
2
- import { trimExtName } from './utils/trimExtName.ts'
3
1
  import { createHash } from 'node:crypto'
4
2
  import path from 'node:path'
5
- import { isDeepEqual, uniqueBy } from 'remeda'
6
3
  import { orderBy } from 'natural-orderby'
4
+ import { isDeepEqual, uniqueBy } from 'remeda'
5
+ import type * as KubbFile from './KubbFile.ts'
6
+ import { trimExtName } from './utils/trimExtName.ts'
7
7
 
8
8
  function hashObject(obj: Record<string, unknown>): string {
9
9
  const str = JSON.stringify(obj, Object.keys(obj).sort())
@@ -1,11 +1,9 @@
1
- import { FileManager } from './FileManager.ts'
2
1
  import { isFunction } from 'remeda'
3
- import type { Plugin } from './plugins/types.ts'
2
+ import type { Fabric, FabricConfig, FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'
3
+ import { FileManager } from './FileManager.ts'
4
4
  import type { Parser } from './parsers/types.ts'
5
+ import type { Plugin } from './plugins/types.ts'
5
6
  import { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
6
- import type { FabricConfig, FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'
7
-
8
- import type { Fabric } from './Fabric.ts'
9
7
 
10
8
  type RootRenderFunction<TOptions extends FabricOptions> = (fabric: Fabric<TOptions>) => void | Promise<void>
11
9
 
@@ -18,11 +16,21 @@ export function defineFabric<TOptions extends FabricOptions>(instance?: RootRend
18
16
  const installedParsers = new Set<Parser<any>>()
19
17
  const fileManager = new FileManager({ events })
20
18
  const context = {
21
- events,
19
+ get files() {
20
+ return fileManager.files
21
+ },
22
+ async addFile(...newFiles) {
23
+ await fileManager.add(...newFiles)
24
+ },
22
25
  config,
23
26
  fileManager,
24
27
  installedPlugins,
25
28
  installedParsers,
29
+ on: events.on.bind(events),
30
+ off: events.off.bind(events),
31
+ onOnce: events.onOnce.bind(events),
32
+ removeAll: events.removeAll.bind(events),
33
+ emit: events.emit.bind(events),
26
34
  } as FabricContext<TOptions>
27
35
 
28
36
  const fabric = {
@@ -46,7 +54,7 @@ export function defineFabric<TOptions extends FabricOptions>(instance?: RootRend
46
54
  if (pluginOrParser.inject && isFunction(pluginOrParser.inject)) {
47
55
  const injecter = pluginOrParser.inject
48
56
 
49
- const extraApp = (injecter as any)(fabric, ...args)
57
+ const extraApp = (injecter as any)(context, ...args)
50
58
  Object.assign(fabric, extraApp)
51
59
  }
52
60
  }
@@ -61,7 +69,7 @@ export function defineFabric<TOptions extends FabricOptions>(instance?: RootRend
61
69
  if (pluginOrParser && isFunction(pluginOrParser.install)) {
62
70
  const installer = pluginOrParser.install
63
71
 
64
- await (installer as any)(fabric, ...args)
72
+ await (installer as any)(context, ...args)
65
73
  }
66
74
 
67
75
  return fabric
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { createFabric } from './createFabric.ts'
2
- export { defineFabric } from './defineFabric.ts'
3
- export { FileManager } from './FileManager.ts'
4
2
  export { createFile } from './createFile.ts'
5
- export { FileProcessor } from './FileProcessor.ts'
3
+ export { defineFabric } from './defineFabric.ts'
6
4
  // we need this to override the globals of `fabric.use`
7
5
  export type { Fabric } from './Fabric.ts'
6
+ export { FileManager } from './FileManager.ts'
7
+ export { FileProcessor } from './FileProcessor.ts'
@@ -1,5 +1,5 @@
1
- import { typescriptParser } from './typescriptParser.ts'
2
1
  import { createParser } from './createParser.ts'
2
+ import { typescriptParser } from './typescriptParser.ts'
3
3
 
4
4
  export const tsxParser = createParser({
5
5
  name: 'tsx',
@@ -1,5 +1,5 @@
1
- import type * as KubbFile from '../KubbFile.ts'
2
1
  import type { Install } from '../Fabric.ts'
2
+ import type * as KubbFile from '../KubbFile.ts'
3
3
 
4
4
  type PrintOptions = {
5
5
  extname?: KubbFile.Extname
@@ -1,7 +1,7 @@
1
+ import path from 'node:path'
1
2
  import ts from 'typescript'
2
3
  import { getRelativePath } from '../utils/getRelativePath.ts'
3
4
  import { trimExtName } from '../utils/trimExtName.ts'
4
- import path from 'node:path'
5
5
  import { createParser } from './createParser.ts'
6
6
 
7
7
  const { factory } = ts
@@ -1,11 +1,11 @@
1
1
  /** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */
2
2
 
3
- import { createPlugin } from './createPlugin.ts'
4
- import type * as KubbFile from '../KubbFile.ts'
5
- import { TreeNode } from '../utils/TreeNode.ts'
6
3
  import path from 'node:path'
7
- import { getRelativePath } from '../utils/getRelativePath.ts'
8
4
  import { createFile } from '../createFile.ts'
5
+ import type * as KubbFile from '../KubbFile.ts'
6
+ import { getRelativePath } from '../utils/getRelativePath.ts'
7
+ import { TreeNode } from '../utils/TreeNode.ts'
8
+ import { createPlugin } from './createPlugin.ts'
9
9
 
10
10
  type Mode = 'all' | 'named' | 'propagate' | false
11
11
 
@@ -135,7 +135,7 @@ export function getBarrelFiles({ files, root, mode }: GetBarrelFilesOptions): Ar
135
135
 
136
136
  export const barrelPlugin = createPlugin<Options, ExtendOptions>({
137
137
  name: 'barrel',
138
- install(app, options) {
138
+ install(ctx, options) {
139
139
  if (!options) {
140
140
  throw new Error('Barrel plugin requires options.root and options.mode')
141
141
  }
@@ -144,14 +144,14 @@ export const barrelPlugin = createPlugin<Options, ExtendOptions>({
144
144
  return undefined
145
145
  }
146
146
 
147
- app.context.events.on('write:start', async ({ files }) => {
147
+ ctx.on('write:start', async ({ files }) => {
148
148
  const root = options.root
149
149
  const barrelFiles = getBarrelFiles({ files, root, mode: options.mode })
150
150
 
151
- await app.context.fileManager.add(...barrelFiles)
151
+ await ctx.fileManager.add(...barrelFiles)
152
152
  })
153
153
  },
154
- inject(app, options) {
154
+ inject(ctx, options) {
155
155
  if (!options) {
156
156
  throw new Error('Barrel plugin requires options.root and options.mode')
157
157
  }
@@ -164,7 +164,7 @@ export const barrelPlugin = createPlugin<Options, ExtendOptions>({
164
164
 
165
165
  const rootPath = path.resolve(root, 'index.ts')
166
166
 
167
- const barrelFiles = app.files.filter((file) => {
167
+ const barrelFiles = ctx.files.filter((file) => {
168
168
  return file.sources.some((source) => source.isIndexable)
169
169
  })
170
170
 
@@ -193,12 +193,12 @@ export const barrelPlugin = createPlugin<Options, ExtendOptions>({
193
193
  sources: [],
194
194
  })
195
195
 
196
- await app.context.fileManager.add(entryFile)
196
+ await ctx.addFile(entryFile)
197
197
 
198
- await app.context.fileManager.write({
199
- mode: app.context.config?.options?.mode,
198
+ await ctx.fileManager.write({
199
+ mode: ctx.config?.options?.mode,
200
200
  dryRun: options.dryRun,
201
- parsers: app.context.installedParsers,
201
+ parsers: ctx.installedParsers,
202
202
  })
203
203
  },
204
204
  }
@@ -1,7 +1,7 @@
1
- import { createPlugin } from './createPlugin.ts'
2
- import fs from 'fs-extra'
3
1
  import { resolve } from 'node:path'
2
+ import fs from 'fs-extra'
4
3
  import type * as KubbFile from '../KubbFile.ts'
4
+ import { createPlugin } from './createPlugin.ts'
5
5
 
6
6
  type WriteOptions = {
7
7
  extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>
@@ -95,30 +95,30 @@ declare global {
95
95
 
96
96
  export const fsPlugin = createPlugin<Options, ExtendOptions>({
97
97
  name: 'fs',
98
- install(app, options = {}) {
98
+ install(ctx, options = {}) {
99
99
  if (options.clean) {
100
100
  fs.removeSync(options.clean.path)
101
101
  }
102
102
 
103
- app.context.events.on('process:progress', async ({ file, source }) => {
103
+ ctx.on('process:progress', async ({ file, source }) => {
104
104
  if (options.onBeforeWrite) {
105
105
  await options.onBeforeWrite(file.path, source)
106
106
  }
107
107
  await write(file.path, source, { sanity: false })
108
108
  })
109
109
  },
110
- inject(app, { dryRun } = {}) {
110
+ inject(ctx, { dryRun } = {}) {
111
111
  return {
112
112
  async write(
113
113
  options = {
114
114
  extension: { '.ts': '.ts' },
115
115
  },
116
116
  ) {
117
- await app.context.fileManager.write({
118
- mode: app.context.config?.options?.mode,
117
+ await ctx.fileManager.write({
118
+ mode: ctx.config?.options?.mode,
119
119
  extension: options.extension,
120
120
  dryRun,
121
- parsers: app.context.installedParsers,
121
+ parsers: ctx.installedParsers,
122
122
  })
123
123
  },
124
124
  }
@@ -1,13 +1,12 @@
1
- import { createPlugin } from './createPlugin.ts'
2
- import type * as KubbFile from '../KubbFile.ts'
3
- import { type Graph, TreeNode } from '../utils/TreeNode.ts'
4
- import path from 'node:path'
5
1
  import http from 'node:http'
6
2
  import type { AddressInfo } from 'node:net'
3
+ import path from 'node:path'
7
4
  import handler from 'serve-handler'
8
- import { open } from '../utils/open.ts'
9
-
10
5
  import { createFile } from '../createFile.ts'
6
+ import type * as KubbFile from '../KubbFile.ts'
7
+ import { open } from '../utils/open.ts'
8
+ import { type Graph, TreeNode } from '../utils/TreeNode.ts'
9
+ import { createPlugin } from './createPlugin.ts'
11
10
 
12
11
  type Options = {
13
12
  root: string
@@ -87,12 +86,12 @@ async function serve(root: string) {
87
86
 
88
87
  export const graphPlugin = createPlugin<Options>({
89
88
  name: 'graph',
90
- install(app, options) {
89
+ install(ctx, options) {
91
90
  if (!options) {
92
91
  throw new Error('Graph plugin requires options.root and options.mode')
93
92
  }
94
93
 
95
- app.context.events.on('write:start', async ({ files }) => {
94
+ ctx.on('write:start', async ({ files }) => {
96
95
  const root = options.root
97
96
 
98
97
  const graph = getGraph({ files, root })
@@ -123,7 +122,7 @@ export const graphPlugin = createPlugin<Options>({
123
122
  ],
124
123
  })
125
124
 
126
- await app.context.fileManager.add(graphFile, graphHtmlFile)
125
+ await ctx.addFile(graphFile, graphHtmlFile)
127
126
 
128
127
  if (options.open) {
129
128
  await serve(root)
@@ -1,6 +1,5 @@
1
+ export { barrelPlugin } from './barrelPlugin.ts'
1
2
  export { createPlugin } from './createPlugin.ts'
2
-
3
3
  export { fsPlugin } from './fsPlugin.ts'
4
- export { barrelPlugin } from './barrelPlugin.ts'
5
- export { progressPlugin } from './progressPlugin.ts'
6
4
  export { graphPlugin } from './graphPlugin.ts'
5
+ export { progressPlugin } from './progressPlugin.ts'
@@ -1,11 +1,11 @@
1
- import { Presets, SingleBar } from 'cli-progress'
2
- import { createPlugin } from './createPlugin.ts'
3
1
  import { relative } from 'node:path'
4
2
  import process from 'node:process'
3
+ import { Presets, SingleBar } from 'cli-progress'
4
+ import { createPlugin } from './createPlugin.ts'
5
5
 
6
6
  export const progressPlugin = createPlugin({
7
7
  name: 'progress',
8
- install(app) {
8
+ install(ctx) {
9
9
  const progressBar = new SingleBar(
10
10
  {
11
11
  format: '{bar} {percentage}% | {value}/{total} | {message}',
@@ -17,16 +17,16 @@ export const progressPlugin = createPlugin({
17
17
  Presets.shades_grey,
18
18
  )
19
19
 
20
- app.context.events.on('process:start', async ({ files }) => {
20
+ ctx.on('process:start', async ({ files }) => {
21
21
  progressBar.start(files.length, 0, { message: 'Starting...' })
22
22
  })
23
23
 
24
- app.context.events.on('process:progress', async ({ file }) => {
24
+ ctx.on('process:progress', async ({ file }) => {
25
25
  const message = `Writing ${relative(process.cwd(), file.path)}`
26
26
  progressBar.increment(1, { message })
27
27
  })
28
28
 
29
- app.context.events.on('process:end', async ({ files }) => {
29
+ ctx.on('process:end', async ({ files }) => {
30
30
  progressBar.update(files.length, { message: 'Done ✅' })
31
31
  progressBar.stop()
32
32
  })
@@ -1,4 +1,4 @@
1
- import type { Install, Inject } from '../Fabric.ts'
1
+ import type { Inject, Install } from '../Fabric.ts'
2
2
 
3
3
  export type Plugin<TOptions = unknown, TAppExtension extends Record<string, any> = {}> = {
4
4
  name: string
package/src/types.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * as KubbFile from './KubbFile.ts'
2
1
  export type { DefineFabric } from './defineFabric.ts'
3
- export type { FabricContext, FabricMode, FabricConfig, FabricOptions } from './Fabric.ts'
2
+ export type { FabricConfig, FabricContext, FabricMode, FabricOptions } from './Fabric.ts'
3
+ export * as KubbFile from './KubbFile.ts'