@kubb/fabric-core 0.13.1 → 0.13.2

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.
@@ -1,4 +1,4 @@
1
- import { D as File } from "./Fabric-CE-4sqCG.js";
1
+ import { D as File } from "./Fabric-BOjvMvNC.js";
2
2
 
3
3
  //#region src/utils/TreeNode.d.ts
4
4
  type BarrelData = {
@@ -55,4 +55,4 @@ type ComponentNode = {
55
55
  declare function useNodeTree(): TreeNode<ComponentNode> | null;
56
56
  //#endregion
57
57
  export { useNodeTree as n, TreeNode as r, ComponentNode as t };
58
- //# sourceMappingURL=useNodeTree-BpHR6gQx.d.ts.map
58
+ //# sourceMappingURL=useNodeTree-6ZhDpI13.d.ts.map
@@ -1,4 +1,4 @@
1
- import { D as File } from "./Fabric-efyCO1t7.js";
1
+ import { D as File } from "./Fabric-w9Y9duM6.js";
2
2
 
3
3
  //#region src/utils/TreeNode.d.ts
4
4
  type BarrelData = {
@@ -55,4 +55,4 @@ type ComponentNode = {
55
55
  declare function useNodeTree(): TreeNode<ComponentNode> | null;
56
56
  //#endregion
57
57
  export { useNodeTree as n, TreeNode as r, ComponentNode as t };
58
- //# sourceMappingURL=useNodeTree-DuQ5Df0t.d.ts.map
58
+ //# sourceMappingURL=useNodeTree-Brj-fAVZ.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/fabric-core",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "Core functionality for Kubb's fabric - A language-agnostic toolkit providing the foundation for plugin-based code generation with TypeScript support",
5
5
  "keywords": [
6
6
  "codegen",
package/src/Fabric.ts CHANGED
@@ -5,12 +5,6 @@ import type { Parser } from './parsers/types.ts'
5
5
  import type { Plugin } from './plugins/types.ts'
6
6
  import type { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
7
7
 
8
- declare global {
9
- namespace Kubb {
10
- interface Fabric {}
11
- }
12
- }
13
-
14
8
  export type FabricElement<TProps extends object = object> = {
15
9
  (): FabricNode
16
10
  type: string
@@ -249,4 +243,9 @@ export interface Fabric<T extends FabricOptions = FabricOptions> extends Kubb.Fa
249
243
  * Add one or more files to the Fabric file manager and merge the source, imports, exports
250
244
  */
251
245
  upsertFile(...files: KubbFile.File[]): Promise<void>
246
+ /**
247
+ * Unmount the Fabric instance and remove all registered event listeners.
248
+ * Plugins may extend this to perform additional cleanup (e.g. process signal listeners).
249
+ */
250
+ unmount(error?: Error | number | null): void
252
251
  }
@@ -67,10 +67,13 @@ export function createFabric<T extends FabricOptions>(config: FabricConfig<T> =
67
67
  return fileManager.files
68
68
  },
69
69
  async addFile(...files) {
70
- await fileManager.add(...files)
70
+ fileManager.add(...files)
71
71
  },
72
72
  async upsertFile(...files) {
73
- await fileManager.upsert(...files)
73
+ fileManager.upsert(...files)
74
+ },
75
+ unmount(_error?: Error | number | null) {
76
+ events.removeAll()
74
77
  },
75
78
  async use(pluginOrParser, ...options) {
76
79
  if (pluginOrParser.type === 'plugin') {
@@ -3,11 +3,18 @@ const SIGNALS: NodeJS.Signals[] = ['SIGINT', 'SIGTERM', 'SIGHUP']
3
3
  /**
4
4
  * Register a callback to run when the process exits (via exit event or common signals).
5
5
  * Returns an unsubscribe function.
6
+ *
7
+ * Dynamically adjusts `process.maxListeners` to avoid MaxListenersExceededWarning
8
+ * when multiple instances are created (e.g. in tests).
6
9
  */
7
10
  export function onProcessExit(callback: (code: number | null) => void): () => void {
8
11
  const exitHandler = (code: number) => callback(code)
9
12
 
10
13
  const signalHandlers = new Map<NodeJS.Signals, () => void>()
14
+ const count = SIGNALS.length + 1 // SIGINT + SIGTERM + SIGHUP + exit
15
+
16
+ // Increase the limit to accommodate this registration
17
+ process.setMaxListeners(process.getMaxListeners() + count)
11
18
 
12
19
  for (const signal of SIGNALS) {
13
20
  const handler = () => {
@@ -29,6 +36,8 @@ export function onProcessExit(callback: (code: number | null) => void): () => vo
29
36
  for (const [signal, handler] of signalHandlers) {
30
37
  process.removeListener(signal, handler)
31
38
  }
39
+ // Restore the limit when listeners are removed
40
+ process.setMaxListeners(Math.max(process.getMaxListeners() - count, 0))
32
41
  }
33
42
 
34
43
  return unsubscribe