unplugin-kubb 6.0.0-alpha.3 → 6.0.0-alpha.30
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.
- package/dist/astro.cjs +1 -1
- package/dist/esbuild.cjs +1 -1
- package/dist/esbuild.d.ts +2 -2
- package/dist/esbuild.js +1 -1
- package/dist/farm.cjs +1 -1
- package/dist/farm.d.ts +2 -2
- package/dist/farm.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +1 -1
- package/dist/nuxt.d.ts +2 -2
- package/dist/rolldown.cjs +1 -1
- package/dist/rolldown.d.ts +2 -2
- package/dist/rolldown.js +1 -1
- package/dist/rollup.cjs +1 -1
- package/dist/rollup.d.ts +2 -2
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +1 -1
- package/dist/rspack.js +1 -1
- package/dist/{unpluginFactory-DlKbJ1As.cjs → unpluginFactory-CDWqfP-i.cjs} +67 -23
- package/dist/unpluginFactory-CDWqfP-i.cjs.map +1 -0
- package/dist/{unpluginFactory-AvZEHRLs.js → unpluginFactory-c7gQHQC-.js} +67 -23
- package/dist/unpluginFactory-c7gQHQC-.js.map +1 -0
- package/dist/unpluginFactory.cjs +1 -1
- package/dist/unpluginFactory.js +1 -1
- package/dist/vite.cjs +1 -1
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.js +1 -1
- package/package.json +4 -4
- package/src/unpluginFactory.ts +1 -1
- package/dist/unpluginFactory-AvZEHRLs.js.map +0 -1
- package/dist/unpluginFactory-DlKbJ1As.cjs.map +0 -1
package/dist/astro.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_unpluginFactory = require("./unpluginFactory-
|
|
1
|
+
const require_unpluginFactory = require("./unpluginFactory-CDWqfP-i.cjs");
|
|
2
2
|
const require_vite = require("./vite.cjs");
|
|
3
3
|
//#region src/astro.ts
|
|
4
4
|
var astro_default = /* @__PURE__ */ require_unpluginFactory.__name((options) => ({
|
package/dist/esbuild.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_unpluginFactory = require("./unpluginFactory-
|
|
1
|
+
const require_unpluginFactory = require("./unpluginFactory-CDWqfP-i.cjs");
|
|
2
2
|
//#region src/esbuild.ts
|
|
3
3
|
var esbuild_default = (0, require("unplugin").createEsbuildPlugin)(require_unpluginFactory.unpluginFactory);
|
|
4
4
|
//#endregion
|
package/dist/esbuild.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { Options } from "./types.js";
|
|
3
|
-
import * as esbuild from "esbuild";
|
|
3
|
+
import * as _$esbuild from "esbuild";
|
|
4
4
|
|
|
5
5
|
//#region src/esbuild.d.ts
|
|
6
|
-
declare const _default: (options?: Options | undefined) => esbuild.Plugin;
|
|
6
|
+
declare const _default: (options?: Options | undefined) => _$esbuild.Plugin;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { _default as default };
|
|
9
9
|
//# sourceMappingURL=esbuild.d.ts.map
|
package/dist/esbuild.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as unpluginFactory } from "./unpluginFactory-
|
|
1
|
+
import { t as unpluginFactory } from "./unpluginFactory-c7gQHQC-.js";
|
|
2
2
|
import { createEsbuildPlugin } from "unplugin";
|
|
3
3
|
//#region src/esbuild.ts
|
|
4
4
|
var esbuild_default = createEsbuildPlugin(unpluginFactory);
|
package/dist/farm.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_unpluginFactory = require("./unpluginFactory-
|
|
1
|
+
const require_unpluginFactory = require("./unpluginFactory-CDWqfP-i.cjs");
|
|
2
2
|
//#region src/farm.ts
|
|
3
3
|
var farm_default = (0, require("unplugin").createFarmPlugin)(require_unpluginFactory.unpluginFactory);
|
|
4
4
|
//#endregion
|
package/dist/farm.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { Options } from "./types.js";
|
|
3
|
-
import * as _farmfe_core0 from "@farmfe/core";
|
|
3
|
+
import * as _$_farmfe_core0 from "@farmfe/core";
|
|
4
4
|
|
|
5
5
|
//#region src/farm.d.ts
|
|
6
|
-
declare const _default: (options?: Options | undefined) => _farmfe_core0.JsPlugin;
|
|
6
|
+
declare const _default: (options?: Options | undefined) => _$_farmfe_core0.JsPlugin;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { _default as default };
|
|
9
9
|
//# sourceMappingURL=farm.d.ts.map
|
package/dist/farm.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_unpluginFactory = require("./unpluginFactory-
|
|
5
|
+
const require_unpluginFactory = require("./unpluginFactory-CDWqfP-i.cjs");
|
|
6
6
|
//#region src/index.ts
|
|
7
7
|
const plugin = /* @__PURE__ */ (0, require("unplugin").createUnplugin)(require_unpluginFactory.unpluginFactory);
|
|
8
8
|
//#endregion
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { Options } from "./types.js";
|
|
3
3
|
import { unpluginFactory } from "./unpluginFactory.js";
|
|
4
|
-
import * as unplugin from "unplugin";
|
|
4
|
+
import * as _$unplugin from "unplugin";
|
|
5
5
|
|
|
6
6
|
//#region src/index.d.ts
|
|
7
|
-
declare const plugin: unplugin.UnpluginInstance<Options | undefined, boolean>;
|
|
7
|
+
declare const plugin: _$unplugin.UnpluginInstance<Options | undefined, boolean>;
|
|
8
8
|
//#endregion
|
|
9
9
|
export { type Options, plugin as default, plugin as unplugin, unpluginFactory };
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as unpluginFactory } from "./unpluginFactory-
|
|
1
|
+
import { t as unpluginFactory } from "./unpluginFactory-c7gQHQC-.js";
|
|
2
2
|
import { createUnplugin } from "unplugin";
|
|
3
3
|
//#region src/index.ts
|
|
4
4
|
const plugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
package/dist/nuxt.cjs
CHANGED
package/dist/nuxt.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { Options } from "./types.js";
|
|
3
|
-
import * as _nuxt_schema0 from "@nuxt/schema";
|
|
3
|
+
import * as _$_nuxt_schema0 from "@nuxt/schema";
|
|
4
4
|
|
|
5
5
|
//#region src/nuxt.d.ts
|
|
6
6
|
interface ModuleOptions extends Options {}
|
|
7
|
-
declare const _default: _nuxt_schema0.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
7
|
+
declare const _default: _$_nuxt_schema0.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
8
8
|
//#endregion
|
|
9
9
|
export { ModuleOptions, _default as default };
|
|
10
10
|
//# sourceMappingURL=nuxt.d.ts.map
|
package/dist/rolldown.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_unpluginFactory = require("./unpluginFactory-
|
|
1
|
+
const require_unpluginFactory = require("./unpluginFactory-CDWqfP-i.cjs");
|
|
2
2
|
//#region src/rolldown.ts
|
|
3
3
|
var rolldown_default = (0, require("unplugin").createRolldownPlugin)(require_unpluginFactory.unpluginFactory);
|
|
4
4
|
//#endregion
|
package/dist/rolldown.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { Options } from "./types.js";
|
|
3
|
-
import * as rolldown from "rolldown";
|
|
3
|
+
import * as _$rolldown from "rolldown";
|
|
4
4
|
|
|
5
5
|
//#region src/rolldown.d.ts
|
|
6
|
-
declare const _default: (options?: Options | undefined) => rolldown.Plugin<any> | rolldown.Plugin<any>[];
|
|
6
|
+
declare const _default: (options?: Options | undefined) => _$rolldown.Plugin<any> | _$rolldown.Plugin<any>[];
|
|
7
7
|
//#endregion
|
|
8
8
|
export { _default as default };
|
|
9
9
|
//# sourceMappingURL=rolldown.d.ts.map
|
package/dist/rolldown.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as unpluginFactory } from "./unpluginFactory-
|
|
1
|
+
import { t as unpluginFactory } from "./unpluginFactory-c7gQHQC-.js";
|
|
2
2
|
import { createRolldownPlugin } from "unplugin";
|
|
3
3
|
//#region src/rolldown.ts
|
|
4
4
|
var rolldown_default = createRolldownPlugin(unpluginFactory);
|
package/dist/rollup.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_unpluginFactory = require("./unpluginFactory-
|
|
1
|
+
const require_unpluginFactory = require("./unpluginFactory-CDWqfP-i.cjs");
|
|
2
2
|
//#region src/rollup.ts
|
|
3
3
|
var rollup_default = (0, require("unplugin").createRollupPlugin)(require_unpluginFactory.unpluginFactory);
|
|
4
4
|
//#endregion
|
package/dist/rollup.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { Options } from "./types.js";
|
|
3
|
-
import * as rollup from "rollup";
|
|
3
|
+
import * as _$rollup from "rollup";
|
|
4
4
|
|
|
5
5
|
//#region src/rollup.d.ts
|
|
6
|
-
declare const _default: (options?: Options | undefined) => rollup.Plugin<any> | rollup.Plugin<any>[];
|
|
6
|
+
declare const _default: (options?: Options | undefined) => _$rollup.Plugin<any> | _$rollup.Plugin<any>[];
|
|
7
7
|
//#endregion
|
|
8
8
|
export { _default as default };
|
|
9
9
|
//# sourceMappingURL=rollup.d.ts.map
|
package/dist/rollup.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as unpluginFactory } from "./unpluginFactory-
|
|
1
|
+
import { t as unpluginFactory } from "./unpluginFactory-c7gQHQC-.js";
|
|
2
2
|
import { createRollupPlugin } from "unplugin";
|
|
3
3
|
//#region src/rollup.ts
|
|
4
4
|
var rollup_default = createRollupPlugin(unpluginFactory);
|
package/dist/rspack.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_unpluginFactory = require("./unpluginFactory-
|
|
1
|
+
const require_unpluginFactory = require("./unpluginFactory-CDWqfP-i.cjs");
|
|
2
2
|
//#region src/rspack.ts
|
|
3
3
|
var rspack_default = (0, require("unplugin").createRspackPlugin)(require_unpluginFactory.unpluginFactory);
|
|
4
4
|
//#endregion
|
package/dist/rspack.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as unpluginFactory } from "./unpluginFactory-
|
|
1
|
+
import { t as unpluginFactory } from "./unpluginFactory-c7gQHQC-.js";
|
|
2
2
|
import { createRspackPlugin } from "unplugin";
|
|
3
3
|
//#region src/rspack.ts
|
|
4
4
|
var rspack_default = createRspackPlugin(unpluginFactory);
|
|
@@ -31,8 +31,14 @@ let _kubb_core = require("@kubb/core");
|
|
|
31
31
|
//#region ../../internals/utils/src/errors.ts
|
|
32
32
|
/**
|
|
33
33
|
* Coerces an unknown thrown value to an `Error` instance.
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* try { ... } catch(err) {
|
|
39
|
+
* throw new BuildError('Build failed', { cause: toError(err), errors: [] })
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
36
42
|
*/
|
|
37
43
|
function toError(value) {
|
|
38
44
|
return value instanceof Error ? value : new Error(String(value));
|
|
@@ -40,12 +46,19 @@ function toError(value) {
|
|
|
40
46
|
//#endregion
|
|
41
47
|
//#region ../../internals/utils/src/asyncEventEmitter.ts
|
|
42
48
|
/**
|
|
43
|
-
*
|
|
49
|
+
* Typed `EventEmitter` that awaits all async listeners before resolving.
|
|
44
50
|
* Wraps Node's `EventEmitter` with full TypeScript event-map inference.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const emitter = new AsyncEventEmitter<{ build: [name: string] }>()
|
|
55
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
56
|
+
* await emitter.emit('build', 'petstore') // all listeners awaited
|
|
57
|
+
* ```
|
|
45
58
|
*/
|
|
46
59
|
var AsyncEventEmitter = class {
|
|
47
60
|
/**
|
|
48
|
-
*
|
|
61
|
+
* Maximum number of listeners per event before Node emits a memory-leak warning.
|
|
49
62
|
* @default 10
|
|
50
63
|
*/
|
|
51
64
|
constructor(maxListener = 10) {
|
|
@@ -53,31 +66,48 @@ var AsyncEventEmitter = class {
|
|
|
53
66
|
}
|
|
54
67
|
#emitter = new node_events.EventEmitter();
|
|
55
68
|
/**
|
|
56
|
-
* Emits
|
|
69
|
+
* Emits `eventName` and awaits all registered listeners sequentially.
|
|
57
70
|
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* await emitter.emit('build', 'petstore')
|
|
75
|
+
* ```
|
|
58
76
|
*/
|
|
59
77
|
async emit(eventName, ...eventArgs) {
|
|
60
78
|
const listeners = this.#emitter.listeners(eventName);
|
|
61
79
|
if (listeners.length === 0) return;
|
|
62
|
-
|
|
80
|
+
for (const listener of listeners) try {
|
|
81
|
+
await listener(...eventArgs);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
let serializedArgs;
|
|
63
84
|
try {
|
|
64
|
-
|
|
65
|
-
} catch
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
serializedArgs = JSON.stringify(eventArgs);
|
|
69
|
-
} catch {
|
|
70
|
-
serializedArgs = String(eventArgs);
|
|
71
|
-
}
|
|
72
|
-
throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: toError(err) });
|
|
85
|
+
serializedArgs = JSON.stringify(eventArgs);
|
|
86
|
+
} catch {
|
|
87
|
+
serializedArgs = String(eventArgs);
|
|
73
88
|
}
|
|
74
|
-
|
|
89
|
+
throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: toError(err) });
|
|
90
|
+
}
|
|
75
91
|
}
|
|
76
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Registers a persistent listener for `eventName`.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
77
100
|
on(eventName, handler) {
|
|
78
101
|
this.#emitter.on(eventName, handler);
|
|
79
102
|
}
|
|
80
|
-
/**
|
|
103
|
+
/**
|
|
104
|
+
* Registers a one-shot listener that removes itself after the first invocation.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* emitter.onOnce('build', async (name) => { console.log(name) })
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
81
111
|
onOnce(eventName, handler) {
|
|
82
112
|
const wrapper = (...args) => {
|
|
83
113
|
this.off(eventName, wrapper);
|
|
@@ -85,18 +115,32 @@ var AsyncEventEmitter = class {
|
|
|
85
115
|
};
|
|
86
116
|
this.on(eventName, wrapper);
|
|
87
117
|
}
|
|
88
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* Removes a previously registered listener.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* emitter.off('build', handler)
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
89
126
|
off(eventName, handler) {
|
|
90
127
|
this.#emitter.off(eventName, handler);
|
|
91
128
|
}
|
|
92
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* Removes all listeners from every event channel.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* emitter.removeAll()
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
93
137
|
removeAll() {
|
|
94
138
|
this.#emitter.removeAllListeners();
|
|
95
139
|
}
|
|
96
140
|
};
|
|
97
141
|
//#endregion
|
|
98
142
|
//#region package.json
|
|
99
|
-
var version = "6.0.0-alpha.
|
|
143
|
+
var version = "6.0.0-alpha.30";
|
|
100
144
|
//#endregion
|
|
101
145
|
//#region src/unpluginFactory.ts
|
|
102
146
|
const unpluginFactory = (options, meta) => {
|
|
@@ -136,7 +180,7 @@ const unpluginFactory = (options, meta) => {
|
|
|
136
180
|
console.log(config.name ? `✓ Generation completed for ${config.name}` : "✓ Generation completed");
|
|
137
181
|
});
|
|
138
182
|
events.on("generation:summary", (config, { status, failedPlugins }) => {
|
|
139
|
-
const pluginsCount = config.plugins
|
|
183
|
+
const pluginsCount = config.plugins.length;
|
|
140
184
|
const successCount = pluginsCount - failedPlugins.size;
|
|
141
185
|
console.log(status === "success" ? `Kubb Summary: ✓ ${`${successCount} successful`}, ${pluginsCount} total` : `Kubb Summary: ✓ ${`${successCount} successful`}, ✗ ${`${failedPlugins.size} failed`}, ${pluginsCount} total`);
|
|
142
186
|
});
|
|
@@ -197,4 +241,4 @@ Object.defineProperty(exports, "unpluginFactory", {
|
|
|
197
241
|
}
|
|
198
242
|
});
|
|
199
243
|
|
|
200
|
-
//# sourceMappingURL=unpluginFactory-
|
|
244
|
+
//# sourceMappingURL=unpluginFactory-CDWqfP-i.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unpluginFactory-CDWqfP-i.cjs","names":["#emitter","NodeEventEmitter","process","unpluginVersion"],"sources":["../../../internals/utils/src/errors.ts","../../../internals/utils/src/asyncEventEmitter.ts","../package.json","../src/unpluginFactory.ts"],"sourcesContent":["/** Thrown when a plugin's configuration or input fails validation.\n *\n * @example\n * ```ts\n * throw new ValidationPluginError('Invalid config: \"output.path\" is required')\n * ```\n */\nexport class ValidationPluginError extends Error {}\n\n/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n *\n * @example\n * ```ts\n * throw new BuildError('Build failed', { errors: [err1, err2] })\n * ```\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new BuildError('Build failed', { cause: toError(err), errors: [] })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error`, or `undefined` when absent or not an `Error`.\n *\n * @example\n * ```ts\n * const cause = toCause(buildError) // Error | undefined\n * ```\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport { toError } from './errors.ts'\n\n/**\n * A function that can be registered as an event listener, synchronous or async.\n */\ntype AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>\n\n/**\n * Typed `EventEmitter` that awaits all async listeners before resolving.\n * Wraps Node's `EventEmitter` with full TypeScript event-map inference.\n *\n * @example\n * ```ts\n * const emitter = new AsyncEventEmitter<{ build: [name: string] }>()\n * emitter.on('build', async (name) => { console.log(name) })\n * await emitter.emit('build', 'petstore') // all listeners awaited\n * ```\n */\nexport class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {\n /**\n * Maximum number of listeners per event before Node emits a memory-leak warning.\n * @default 10\n */\n constructor(maxListener = 10) {\n this.#emitter.setMaxListeners(maxListener)\n }\n\n #emitter = new NodeEventEmitter()\n\n /**\n * Emits `eventName` and awaits all registered listeners sequentially.\n * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.\n *\n * @example\n * ```ts\n * await emitter.emit('build', 'petstore')\n * ```\n */\n async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<AsyncListener<TEvents[TEventName]>>\n\n if (listeners.length === 0) {\n return\n }\n\n for (const listener of listeners) {\n try {\n await listener(...eventArgs)\n } catch (err) {\n let serializedArgs: string\n try {\n serializedArgs = JSON.stringify(eventArgs)\n } catch {\n serializedArgs = String(eventArgs)\n }\n throw new Error(`Error in async listener for \"${eventName}\" with eventArgs ${serializedArgs}`, { cause: toError(err) })\n }\n }\n }\n\n /**\n * Registers a persistent listener for `eventName`.\n *\n * @example\n * ```ts\n * emitter.on('build', async (name) => { console.log(name) })\n * ```\n */\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.on(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Registers a one-shot listener that removes itself after the first invocation.\n *\n * @example\n * ```ts\n * emitter.onOnce('build', async (name) => { console.log(name) })\n * ```\n */\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n const wrapper: AsyncListener<TEvents[TEventName]> = (...args) => {\n this.off(eventName, wrapper)\n return handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n /**\n * Removes a previously registered listener.\n *\n * @example\n * ```ts\n * emitter.off('build', handler)\n * ```\n */\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.off(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Removes all listeners from every event channel.\n *\n * @example\n * ```ts\n * emitter.removeAll()\n * ```\n */\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","","import process from 'node:process'\nimport { AsyncEventEmitter } from '@internals/utils'\nimport { type Config, type KubbEvents, safeBuild } from '@kubb/core'\nimport type { UnpluginFactory } from 'unplugin'\nimport { version as unpluginVersion } from '../package.json'\nimport type { Options } from './types.ts'\n\ntype RollupContext = {\n info?: (message: string) => void\n warn?: (message: string) => void\n error?: (message: string) => void\n}\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (options, meta) => {\n const name = 'unplugin-kubb' as const\n const events = new AsyncEventEmitter<KubbEvents>()\n const isVite = meta.framework === 'vite'\n const hrStart = process.hrtime()\n\n async function runBuild(ctx: RollupContext) {\n if (!options?.config) {\n if (ctx.error) {\n ctx.error?.(`[${name}] Config is not set`)\n } else {\n console.error(`[${name}] Config is not set`)\n }\n return\n }\n\n events.on('lifecycle:start', (version) => {\n console.log(`Kubb Unplugin ${version} 🧩`)\n })\n\n events.on('error', (error) => {\n console.error(`✗ ${error?.message || 'failed'}`)\n })\n\n events.on('warn', (message) => {\n console.warn(`⚠ ${message}`)\n })\n\n events.on('info', (message) => {\n console.info(`ℹ ${message}`)\n })\n\n events.on('success', (message) => {\n console.log(`✓ ${message}`)\n })\n\n events.on('plugin:end', (plugin, { duration }) => {\n const durationStr = duration >= 1000 ? `${(duration / 1000).toFixed(2)}s` : `${duration}ms`\n\n console.log(`✓ ${plugin.name} completed in ${durationStr}`)\n })\n\n events.on('files:processing:end', () => {\n const text = '✓ Files written successfully'\n\n console.log(text)\n })\n\n events.on('generation:end', (config) => {\n console.log(config.name ? `✓ Generation completed for ${config.name}` : '✓ Generation completed')\n })\n\n events.on('generation:summary', (config, { status, failedPlugins }) => {\n const pluginsCount = config.plugins.length\n const successCount = pluginsCount - failedPlugins.size\n\n console.log(\n status === 'success'\n ? `Kubb Summary: ✓ ${`${successCount} successful`}, ${pluginsCount} total`\n : `Kubb Summary: ✓ ${`${successCount} successful`}, ✗ ${`${failedPlugins.size} failed`}, ${pluginsCount} total`,\n )\n })\n\n await events.emit('lifecycle:start', unpluginVersion)\n\n const { root: _root, ...userConfig } = options.config as Config\n\n await events.emit('generation:start', options.config as Config)\n\n const { error, failedPlugins, pluginTimings, files, sources } = await safeBuild({\n config: {\n root: process.cwd(),\n ...userConfig,\n output: {\n write: true,\n ...userConfig.output,\n },\n },\n events,\n })\n\n const hasFailures = failedPlugins.size > 0 || error\n if (hasFailures) {\n // Collect all errors from failed plugins and general error\n const allErrors: Error[] = [\n error,\n ...Array.from(failedPlugins)\n .filter((it) => it.error)\n .map((it) => it.error),\n ].filter(Boolean)\n\n allErrors.forEach((err) => {\n events.emit('error', err)\n })\n }\n\n await events.emit('generation:end', options.config as Config, files, sources)\n await events.emit('generation:summary', options.config as Config, {\n failedPlugins,\n filesCreated: files.length,\n status: failedPlugins.size > 0 || error ? 'failed' : 'success',\n hrStart,\n pluginTimings,\n })\n\n await events.emit('lifecycle:end')\n }\n\n return {\n name,\n enforce: 'pre',\n apply: isVite ? 'build' : undefined,\n async buildStart() {\n await runBuild(this as unknown as RollupContext)\n },\n\n vite: {},\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,QAAQ,OAAuB;AAC7C,QAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;;;;;;;;ACrBlE,IAAa,oBAAb,MAAoF;;;;;CAKlF,YAAY,cAAc,IAAI;AAC5B,QAAA,QAAc,gBAAgB,YAAY;;CAG5C,WAAW,IAAIC,YAAAA,cAAkB;;;;;;;;;;CAWjC,MAAM,KAAgD,WAAuB,GAA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GAAG,MAAM,CACxB,KAAK,OAAO,GAAG,MAAM,CACzB,CAAC,OAAO,QAAQ,CAEP,SAAS,QAAQ;AACzB,UAAO,KAAK,SAAS,IAAI;IACzB;AAGJ,QAAM,OAAO,KAAK,kBAAkB,QAAQ,QAAkB,OAAO,QAAQ;AAC7E,QAAM,OAAO,KAAK,sBAAsB,QAAQ,QAAkB;GAChE;GACA,cAAc,MAAM;GACpB,QAAQ,cAAc,OAAO,KAAK,QAAQ,WAAW;GACrD;GACA;GACD,CAAC;AAEF,QAAM,OAAO,KAAK,gBAAgB;;AAGpC,QAAO;EACL;EACA,SAAS;EACT,OAAO,SAAS,UAAU,KAAA;EAC1B,MAAM,aAAa;AACjB,SAAM,SAAS,KAAiC;;EAGlD,MAAM,EAAE;EACT"}
|
|
@@ -5,8 +5,14 @@ import { safeBuild } from "@kubb/core";
|
|
|
5
5
|
//#region ../../internals/utils/src/errors.ts
|
|
6
6
|
/**
|
|
7
7
|
* Coerces an unknown thrown value to an `Error` instance.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* try { ... } catch(err) {
|
|
13
|
+
* throw new BuildError('Build failed', { cause: toError(err), errors: [] })
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
10
16
|
*/
|
|
11
17
|
function toError(value) {
|
|
12
18
|
return value instanceof Error ? value : new Error(String(value));
|
|
@@ -14,12 +20,19 @@ function toError(value) {
|
|
|
14
20
|
//#endregion
|
|
15
21
|
//#region ../../internals/utils/src/asyncEventEmitter.ts
|
|
16
22
|
/**
|
|
17
|
-
*
|
|
23
|
+
* Typed `EventEmitter` that awaits all async listeners before resolving.
|
|
18
24
|
* Wraps Node's `EventEmitter` with full TypeScript event-map inference.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const emitter = new AsyncEventEmitter<{ build: [name: string] }>()
|
|
29
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
30
|
+
* await emitter.emit('build', 'petstore') // all listeners awaited
|
|
31
|
+
* ```
|
|
19
32
|
*/
|
|
20
33
|
var AsyncEventEmitter = class {
|
|
21
34
|
/**
|
|
22
|
-
*
|
|
35
|
+
* Maximum number of listeners per event before Node emits a memory-leak warning.
|
|
23
36
|
* @default 10
|
|
24
37
|
*/
|
|
25
38
|
constructor(maxListener = 10) {
|
|
@@ -27,31 +40,48 @@ var AsyncEventEmitter = class {
|
|
|
27
40
|
}
|
|
28
41
|
#emitter = new EventEmitter();
|
|
29
42
|
/**
|
|
30
|
-
* Emits
|
|
43
|
+
* Emits `eventName` and awaits all registered listeners sequentially.
|
|
31
44
|
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* await emitter.emit('build', 'petstore')
|
|
49
|
+
* ```
|
|
32
50
|
*/
|
|
33
51
|
async emit(eventName, ...eventArgs) {
|
|
34
52
|
const listeners = this.#emitter.listeners(eventName);
|
|
35
53
|
if (listeners.length === 0) return;
|
|
36
|
-
|
|
54
|
+
for (const listener of listeners) try {
|
|
55
|
+
await listener(...eventArgs);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
let serializedArgs;
|
|
37
58
|
try {
|
|
38
|
-
|
|
39
|
-
} catch
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
serializedArgs = JSON.stringify(eventArgs);
|
|
43
|
-
} catch {
|
|
44
|
-
serializedArgs = String(eventArgs);
|
|
45
|
-
}
|
|
46
|
-
throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: toError(err) });
|
|
59
|
+
serializedArgs = JSON.stringify(eventArgs);
|
|
60
|
+
} catch {
|
|
61
|
+
serializedArgs = String(eventArgs);
|
|
47
62
|
}
|
|
48
|
-
|
|
63
|
+
throw new Error(`Error in async listener for "${eventName}" with eventArgs ${serializedArgs}`, { cause: toError(err) });
|
|
64
|
+
}
|
|
49
65
|
}
|
|
50
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Registers a persistent listener for `eventName`.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
51
74
|
on(eventName, handler) {
|
|
52
75
|
this.#emitter.on(eventName, handler);
|
|
53
76
|
}
|
|
54
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* Registers a one-shot listener that removes itself after the first invocation.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* emitter.onOnce('build', async (name) => { console.log(name) })
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
55
85
|
onOnce(eventName, handler) {
|
|
56
86
|
const wrapper = (...args) => {
|
|
57
87
|
this.off(eventName, wrapper);
|
|
@@ -59,18 +89,32 @@ var AsyncEventEmitter = class {
|
|
|
59
89
|
};
|
|
60
90
|
this.on(eventName, wrapper);
|
|
61
91
|
}
|
|
62
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Removes a previously registered listener.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* emitter.off('build', handler)
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
63
100
|
off(eventName, handler) {
|
|
64
101
|
this.#emitter.off(eventName, handler);
|
|
65
102
|
}
|
|
66
|
-
/**
|
|
103
|
+
/**
|
|
104
|
+
* Removes all listeners from every event channel.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* emitter.removeAll()
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
67
111
|
removeAll() {
|
|
68
112
|
this.#emitter.removeAllListeners();
|
|
69
113
|
}
|
|
70
114
|
};
|
|
71
115
|
//#endregion
|
|
72
116
|
//#region package.json
|
|
73
|
-
var version = "6.0.0-alpha.
|
|
117
|
+
var version = "6.0.0-alpha.30";
|
|
74
118
|
//#endregion
|
|
75
119
|
//#region src/unpluginFactory.ts
|
|
76
120
|
const unpluginFactory = (options, meta) => {
|
|
@@ -110,7 +154,7 @@ const unpluginFactory = (options, meta) => {
|
|
|
110
154
|
console.log(config.name ? `✓ Generation completed for ${config.name}` : "✓ Generation completed");
|
|
111
155
|
});
|
|
112
156
|
events.on("generation:summary", (config, { status, failedPlugins }) => {
|
|
113
|
-
const pluginsCount = config.plugins
|
|
157
|
+
const pluginsCount = config.plugins.length;
|
|
114
158
|
const successCount = pluginsCount - failedPlugins.size;
|
|
115
159
|
console.log(status === "success" ? `Kubb Summary: ✓ ${`${successCount} successful`}, ${pluginsCount} total` : `Kubb Summary: ✓ ${`${successCount} successful`}, ✗ ${`${failedPlugins.size} failed`}, ${pluginsCount} total`);
|
|
116
160
|
});
|
|
@@ -154,4 +198,4 @@ const unpluginFactory = (options, meta) => {
|
|
|
154
198
|
//#endregion
|
|
155
199
|
export { unpluginFactory as t };
|
|
156
200
|
|
|
157
|
-
//# sourceMappingURL=unpluginFactory-
|
|
201
|
+
//# sourceMappingURL=unpluginFactory-c7gQHQC-.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unpluginFactory-c7gQHQC-.js","names":["#emitter","NodeEventEmitter","unpluginVersion"],"sources":["../../../internals/utils/src/errors.ts","../../../internals/utils/src/asyncEventEmitter.ts","../package.json","../src/unpluginFactory.ts"],"sourcesContent":["/** Thrown when a plugin's configuration or input fails validation.\n *\n * @example\n * ```ts\n * throw new ValidationPluginError('Invalid config: \"output.path\" is required')\n * ```\n */\nexport class ValidationPluginError extends Error {}\n\n/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n *\n * @example\n * ```ts\n * throw new BuildError('Build failed', { errors: [err1, err2] })\n * ```\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new BuildError('Build failed', { cause: toError(err), errors: [] })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error`, or `undefined` when absent or not an `Error`.\n *\n * @example\n * ```ts\n * const cause = toCause(buildError) // Error | undefined\n * ```\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport { toError } from './errors.ts'\n\n/**\n * A function that can be registered as an event listener, synchronous or async.\n */\ntype AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>\n\n/**\n * Typed `EventEmitter` that awaits all async listeners before resolving.\n * Wraps Node's `EventEmitter` with full TypeScript event-map inference.\n *\n * @example\n * ```ts\n * const emitter = new AsyncEventEmitter<{ build: [name: string] }>()\n * emitter.on('build', async (name) => { console.log(name) })\n * await emitter.emit('build', 'petstore') // all listeners awaited\n * ```\n */\nexport class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {\n /**\n * Maximum number of listeners per event before Node emits a memory-leak warning.\n * @default 10\n */\n constructor(maxListener = 10) {\n this.#emitter.setMaxListeners(maxListener)\n }\n\n #emitter = new NodeEventEmitter()\n\n /**\n * Emits `eventName` and awaits all registered listeners sequentially.\n * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.\n *\n * @example\n * ```ts\n * await emitter.emit('build', 'petstore')\n * ```\n */\n async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<AsyncListener<TEvents[TEventName]>>\n\n if (listeners.length === 0) {\n return\n }\n\n for (const listener of listeners) {\n try {\n await listener(...eventArgs)\n } catch (err) {\n let serializedArgs: string\n try {\n serializedArgs = JSON.stringify(eventArgs)\n } catch {\n serializedArgs = String(eventArgs)\n }\n throw new Error(`Error in async listener for \"${eventName}\" with eventArgs ${serializedArgs}`, { cause: toError(err) })\n }\n }\n }\n\n /**\n * Registers a persistent listener for `eventName`.\n *\n * @example\n * ```ts\n * emitter.on('build', async (name) => { console.log(name) })\n * ```\n */\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.on(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Registers a one-shot listener that removes itself after the first invocation.\n *\n * @example\n * ```ts\n * emitter.onOnce('build', async (name) => { console.log(name) })\n * ```\n */\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n const wrapper: AsyncListener<TEvents[TEventName]> = (...args) => {\n this.off(eventName, wrapper)\n return handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n /**\n * Removes a previously registered listener.\n *\n * @example\n * ```ts\n * emitter.off('build', handler)\n * ```\n */\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.off(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /**\n * Removes all listeners from every event channel.\n *\n * @example\n * ```ts\n * emitter.removeAll()\n * ```\n */\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","","import process from 'node:process'\nimport { AsyncEventEmitter } from '@internals/utils'\nimport { type Config, type KubbEvents, safeBuild } from '@kubb/core'\nimport type { UnpluginFactory } from 'unplugin'\nimport { version as unpluginVersion } from '../package.json'\nimport type { Options } from './types.ts'\n\ntype RollupContext = {\n info?: (message: string) => void\n warn?: (message: string) => void\n error?: (message: string) => void\n}\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (options, meta) => {\n const name = 'unplugin-kubb' as const\n const events = new AsyncEventEmitter<KubbEvents>()\n const isVite = meta.framework === 'vite'\n const hrStart = process.hrtime()\n\n async function runBuild(ctx: RollupContext) {\n if (!options?.config) {\n if (ctx.error) {\n ctx.error?.(`[${name}] Config is not set`)\n } else {\n console.error(`[${name}] Config is not set`)\n }\n return\n }\n\n events.on('lifecycle:start', (version) => {\n console.log(`Kubb Unplugin ${version} 🧩`)\n })\n\n events.on('error', (error) => {\n console.error(`✗ ${error?.message || 'failed'}`)\n })\n\n events.on('warn', (message) => {\n console.warn(`⚠ ${message}`)\n })\n\n events.on('info', (message) => {\n console.info(`ℹ ${message}`)\n })\n\n events.on('success', (message) => {\n console.log(`✓ ${message}`)\n })\n\n events.on('plugin:end', (plugin, { duration }) => {\n const durationStr = duration >= 1000 ? `${(duration / 1000).toFixed(2)}s` : `${duration}ms`\n\n console.log(`✓ ${plugin.name} completed in ${durationStr}`)\n })\n\n events.on('files:processing:end', () => {\n const text = '✓ Files written successfully'\n\n console.log(text)\n })\n\n events.on('generation:end', (config) => {\n console.log(config.name ? `✓ Generation completed for ${config.name}` : '✓ Generation completed')\n })\n\n events.on('generation:summary', (config, { status, failedPlugins }) => {\n const pluginsCount = config.plugins.length\n const successCount = pluginsCount - failedPlugins.size\n\n console.log(\n status === 'success'\n ? `Kubb Summary: ✓ ${`${successCount} successful`}, ${pluginsCount} total`\n : `Kubb Summary: ✓ ${`${successCount} successful`}, ✗ ${`${failedPlugins.size} failed`}, ${pluginsCount} total`,\n )\n })\n\n await events.emit('lifecycle:start', unpluginVersion)\n\n const { root: _root, ...userConfig } = options.config as Config\n\n await events.emit('generation:start', options.config as Config)\n\n const { error, failedPlugins, pluginTimings, files, sources } = await safeBuild({\n config: {\n root: process.cwd(),\n ...userConfig,\n output: {\n write: true,\n ...userConfig.output,\n },\n },\n events,\n })\n\n const hasFailures = failedPlugins.size > 0 || error\n if (hasFailures) {\n // Collect all errors from failed plugins and general error\n const allErrors: Error[] = [\n error,\n ...Array.from(failedPlugins)\n .filter((it) => it.error)\n .map((it) => it.error),\n ].filter(Boolean)\n\n allErrors.forEach((err) => {\n events.emit('error', err)\n })\n }\n\n await events.emit('generation:end', options.config as Config, files, sources)\n await events.emit('generation:summary', options.config as Config, {\n failedPlugins,\n filesCreated: files.length,\n status: failedPlugins.size > 0 || error ? 'failed' : 'success',\n hrStart,\n pluginTimings,\n })\n\n await events.emit('lifecycle:end')\n }\n\n return {\n name,\n enforce: 'pre',\n apply: isVite ? 'build' : undefined,\n async buildStart() {\n await runBuild(this as unknown as RollupContext)\n },\n\n vite: {},\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,SAAgB,QAAQ,OAAuB;AAC7C,QAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;;;;;;;;ACrBlE,IAAa,oBAAb,MAAoF;;;;;CAKlF,YAAY,cAAc,IAAI;AAC5B,QAAA,QAAc,gBAAgB,YAAY;;CAG5C,WAAW,IAAIC,cAAkB;;;;;;;;;;CAWjC,MAAM,KAAgD,WAAuB,GAAG,WAA+C;EAC7H,MAAM,YAAY,MAAA,QAAc,UAAU,UAAU;AAEpD,MAAI,UAAU,WAAW,EACvB;AAGF,OAAK,MAAM,YAAY,UACrB,KAAI;AACF,SAAM,SAAS,GAAG,UAAU;WACrB,KAAK;GACZ,IAAI;AACJ,OAAI;AACF,qBAAiB,KAAK,UAAU,UAAU;WACpC;AACN,qBAAiB,OAAO,UAAU;;AAEpC,SAAM,IAAI,MAAM,gCAAgC,UAAU,mBAAmB,kBAAkB,EAAE,OAAO,QAAQ,IAA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pC,QAAO;EACL;EACA,SAAS;EACT,OAAO,SAAS,UAAU,KAAA;EAC1B,MAAM,aAAa;AACjB,SAAM,SAAS,KAAiC;;EAGlD,MAAM,EAAE;EACT"}
|
package/dist/unpluginFactory.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_unpluginFactory = require("./unpluginFactory-
|
|
2
|
+
const require_unpluginFactory = require("./unpluginFactory-CDWqfP-i.cjs");
|
|
3
3
|
exports.unpluginFactory = require_unpluginFactory.unpluginFactory;
|
package/dist/unpluginFactory.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as unpluginFactory } from "./unpluginFactory-
|
|
1
|
+
import { t as unpluginFactory } from "./unpluginFactory-c7gQHQC-.js";
|
|
2
2
|
export { unpluginFactory };
|
package/dist/vite.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_unpluginFactory = require("./unpluginFactory-
|
|
1
|
+
const require_unpluginFactory = require("./unpluginFactory-CDWqfP-i.cjs");
|
|
2
2
|
//#region src/vite.ts
|
|
3
3
|
var vite_default = (0, require("unplugin").createVitePlugin)(require_unpluginFactory.unpluginFactory);
|
|
4
4
|
//#endregion
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { Options } from "./types.js";
|
|
3
|
-
import * as vite from "vite";
|
|
3
|
+
import * as _$vite from "vite";
|
|
4
4
|
|
|
5
5
|
//#region src/vite.d.ts
|
|
6
|
-
declare const _default: (options?: Options | undefined) => vite.Plugin<any> | vite.Plugin<any>[];
|
|
6
|
+
declare const _default: (options?: Options | undefined) => _$vite.Plugin<any> | _$vite.Plugin<any>[];
|
|
7
7
|
//#endregion
|
|
8
8
|
export { _default as default };
|
|
9
9
|
//# sourceMappingURL=vite.d.ts.map
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_unpluginFactory = require("./unpluginFactory-
|
|
1
|
+
const require_unpluginFactory = require("./unpluginFactory-CDWqfP-i.cjs");
|
|
2
2
|
//#region src/webpack.ts
|
|
3
3
|
var webpack_default = (0, require("unplugin").createWebpackPlugin)(require_unpluginFactory.unpluginFactory);
|
|
4
4
|
//#endregion
|
package/dist/webpack.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as unpluginFactory } from "./unpluginFactory-
|
|
1
|
+
import { t as unpluginFactory } from "./unpluginFactory-c7gQHQC-.js";
|
|
2
2
|
import { createWebpackPlugin } from "unplugin";
|
|
3
3
|
//#region src/webpack.ts
|
|
4
4
|
var webpack_default = createWebpackPlugin(unpluginFactory);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-kubb",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.30",
|
|
4
4
|
"description": "Universal build plugin for Kubb, integrating OpenAPI code generation into Vite, Webpack, Rollup, esbuild, Rspack, Nuxt, and Astro build processes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unplugin",
|
|
@@ -98,15 +98,15 @@
|
|
|
98
98
|
],
|
|
99
99
|
"dependencies": {
|
|
100
100
|
"unplugin": "^3.0.0",
|
|
101
|
-
"@kubb/core": "5.0.0-alpha.
|
|
101
|
+
"@kubb/core": "5.0.0-alpha.30"
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
104
|
"@farmfe/core": "^1.7.11",
|
|
105
105
|
"@nuxt/kit": "^4.4.2",
|
|
106
106
|
"@nuxt/schema": "^4.4.2",
|
|
107
107
|
"esbuild": "*",
|
|
108
|
-
"rolldown": "~1.0.0-rc.
|
|
109
|
-
"rollup": "^4.
|
|
108
|
+
"rolldown": "~1.0.0-rc.13",
|
|
109
|
+
"rollup": "^4.60.1",
|
|
110
110
|
"vite": "^7.3.1",
|
|
111
111
|
"webpack": "^5.105.4",
|
|
112
112
|
"@internals/utils": "0.0.0"
|
package/src/unpluginFactory.ts
CHANGED
|
@@ -64,7 +64,7 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (options, m
|
|
|
64
64
|
})
|
|
65
65
|
|
|
66
66
|
events.on('generation:summary', (config, { status, failedPlugins }) => {
|
|
67
|
-
const pluginsCount = config.plugins
|
|
67
|
+
const pluginsCount = config.plugins.length
|
|
68
68
|
const successCount = pluginsCount - failedPlugins.size
|
|
69
69
|
|
|
70
70
|
console.log(
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unpluginFactory-AvZEHRLs.js","names":["#emitter","NodeEventEmitter","unpluginVersion"],"sources":["../../../internals/utils/src/errors.ts","../../../internals/utils/src/asyncEventEmitter.ts","../package.json","../src/unpluginFactory.ts"],"sourcesContent":["/** Thrown when a plugin's configuration or input fails validation. */\nexport class ValidationPluginError extends Error {}\n\n/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * When the value is already an `Error` it is returned as-is;\n * otherwise a new `Error` is created whose message is `String(value)`.\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Safely extracts a human-readable message from any thrown value.\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error | undefined`.\n * Returns `undefined` when the cause is absent or is not an `Error`.\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport { toError } from './errors.ts'\n\n/** A function that can be registered as an event listener, synchronous or async. */\ntype AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>\n\n/**\n * A typed EventEmitter that awaits all async listeners before resolving.\n * Wraps Node's `EventEmitter` with full TypeScript event-map inference.\n */\nexport class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {\n /**\n * `maxListener` controls the maximum number of listeners per event before Node emits a memory-leak warning.\n * @default 10\n */\n constructor(maxListener = 10) {\n this.#emitter.setMaxListeners(maxListener)\n }\n\n #emitter = new NodeEventEmitter()\n\n /**\n * Emits an event and awaits all registered listeners in parallel.\n * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.\n */\n async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<AsyncListener<TEvents[TEventName]>>\n\n if (listeners.length === 0) {\n return undefined\n }\n\n await Promise.all(\n listeners.map(async (listener) => {\n try {\n return await listener(...eventArgs)\n } catch (err) {\n let serializedArgs: string\n try {\n serializedArgs = JSON.stringify(eventArgs)\n } catch {\n serializedArgs = String(eventArgs)\n }\n throw new Error(`Error in async listener for \"${eventName}\" with eventArgs ${serializedArgs}`, { cause: toError(err) })\n }\n }),\n )\n }\n\n /** Registers a persistent listener for the given event. */\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.on(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /** Registers a one-shot listener that removes itself after the first invocation. */\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n const wrapper: AsyncListener<TEvents[TEventName]> = (...args) => {\n this.off(eventName, wrapper)\n return handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n /** Removes a previously registered listener. */\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.off(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /** Removes all listeners from every event channel. */\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","","import process from 'node:process'\nimport { AsyncEventEmitter } from '@internals/utils'\nimport { type Config, type KubbEvents, safeBuild } from '@kubb/core'\nimport type { UnpluginFactory } from 'unplugin'\nimport { version as unpluginVersion } from '../package.json'\nimport type { Options } from './types.ts'\n\ntype RollupContext = {\n info?: (message: string) => void\n warn?: (message: string) => void\n error?: (message: string) => void\n}\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (options, meta) => {\n const name = 'unplugin-kubb' as const\n const events = new AsyncEventEmitter<KubbEvents>()\n const isVite = meta.framework === 'vite'\n const hrStart = process.hrtime()\n\n async function runBuild(ctx: RollupContext) {\n if (!options?.config) {\n if (ctx.error) {\n ctx.error?.(`[${name}] Config is not set`)\n } else {\n console.error(`[${name}] Config is not set`)\n }\n return\n }\n\n events.on('lifecycle:start', (version) => {\n console.log(`Kubb Unplugin ${version} 🧩`)\n })\n\n events.on('error', (error) => {\n console.error(`✗ ${error?.message || 'failed'}`)\n })\n\n events.on('warn', (message) => {\n console.warn(`⚠ ${message}`)\n })\n\n events.on('info', (message) => {\n console.info(`ℹ ${message}`)\n })\n\n events.on('success', (message) => {\n console.log(`✓ ${message}`)\n })\n\n events.on('plugin:end', (plugin, { duration }) => {\n const durationStr = duration >= 1000 ? `${(duration / 1000).toFixed(2)}s` : `${duration}ms`\n\n console.log(`✓ ${plugin.name} completed in ${durationStr}`)\n })\n\n events.on('files:processing:end', () => {\n const text = '✓ Files written successfully'\n\n console.log(text)\n })\n\n events.on('generation:end', (config) => {\n console.log(config.name ? `✓ Generation completed for ${config.name}` : '✓ Generation completed')\n })\n\n events.on('generation:summary', (config, { status, failedPlugins }) => {\n const pluginsCount = config.plugins?.length || 0\n const successCount = pluginsCount - failedPlugins.size\n\n console.log(\n status === 'success'\n ? `Kubb Summary: ✓ ${`${successCount} successful`}, ${pluginsCount} total`\n : `Kubb Summary: ✓ ${`${successCount} successful`}, ✗ ${`${failedPlugins.size} failed`}, ${pluginsCount} total`,\n )\n })\n\n await events.emit('lifecycle:start', unpluginVersion)\n\n const { root: _root, ...userConfig } = options.config as Config\n\n await events.emit('generation:start', options.config as Config)\n\n const { error, failedPlugins, pluginTimings, files, sources } = await safeBuild({\n config: {\n root: process.cwd(),\n ...userConfig,\n output: {\n write: true,\n ...userConfig.output,\n },\n },\n events,\n })\n\n const hasFailures = failedPlugins.size > 0 || error\n if (hasFailures) {\n // Collect all errors from failed plugins and general error\n const allErrors: Error[] = [\n error,\n ...Array.from(failedPlugins)\n .filter((it) => it.error)\n .map((it) => it.error),\n ].filter(Boolean)\n\n allErrors.forEach((err) => {\n events.emit('error', err)\n })\n }\n\n await events.emit('generation:end', options.config as Config, files, sources)\n await events.emit('generation:summary', options.config as Config, {\n failedPlugins,\n filesCreated: files.length,\n status: failedPlugins.size > 0 || error ? 'failed' : 'success',\n hrStart,\n pluginTimings,\n })\n\n await events.emit('lifecycle:end')\n }\n\n return {\n name,\n enforce: 'pre',\n apply: isVite ? 'build' : undefined,\n async buildStart() {\n await runBuild(this as unknown as RollupContext)\n },\n\n vite: {},\n }\n}\n"],"mappings":";;;;;;;;;;AAsBA,SAAgB,QAAQ,OAAuB;AAC7C,QAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;ACblE,IAAa,oBAAb,MAAoF;;;;;CAKlF,YAAY,cAAc,IAAI;AAC5B,QAAA,QAAc,gBAAgB,YAAY;;CAG5C,WAAW,IAAIC,cAAkB;;;;;CAMjC,MAAM,KAAgD,WAAuB,GAAG,WAA+C;EAC7H,MAAM,YAAY,MAAA,QAAc,UAAU,UAAU;AAEpD,MAAI,UAAU,WAAW,EACvB;AAGF,QAAM,QAAQ,IACZ,UAAU,IAAI,OAAO,aAAa;AAChC,OAAI;AACF,WAAO,MAAM,SAAS,GAAG,UAAU;YAC5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O,KAAK,sBAAsB,QAAQ,QAAkB;GAChE;GACA,cAAc,MAAM;GACpB,QAAQ,cAAc,OAAO,KAAK,QAAQ,WAAW;GACrD;GACA;GACD,CAAC;AAEF,QAAM,OAAO,KAAK,gBAAgB;;AAGpC,QAAO;EACL;EACA,SAAS;EACT,OAAO,SAAS,UAAU,KAAA;EAC1B,MAAM,aAAa;AACjB,SAAM,SAAS,KAAiC;;EAGlD,MAAM,EAAE;EACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unpluginFactory-DlKbJ1As.cjs","names":["#emitter","NodeEventEmitter","process","unpluginVersion"],"sources":["../../../internals/utils/src/errors.ts","../../../internals/utils/src/asyncEventEmitter.ts","../package.json","../src/unpluginFactory.ts"],"sourcesContent":["/** Thrown when a plugin's configuration or input fails validation. */\nexport class ValidationPluginError extends Error {}\n\n/**\n * Thrown when one or more errors occur during a Kubb build.\n * Carries the full list of underlying errors on `errors`.\n */\nexport class BuildError extends Error {\n errors: Array<Error>\n\n constructor(message: string, options: { cause?: Error; errors: Array<Error> }) {\n super(message, { cause: options.cause })\n this.name = 'BuildError'\n this.errors = options.errors\n }\n}\n\n/**\n * Coerces an unknown thrown value to an `Error` instance.\n * When the value is already an `Error` it is returned as-is;\n * otherwise a new `Error` is created whose message is `String(value)`.\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Safely extracts a human-readable message from any thrown value.\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Extracts the `.cause` of an `Error` as an `Error | undefined`.\n * Returns `undefined` when the cause is absent or is not an `Error`.\n */\nexport function toCause(error: Error): Error | undefined {\n return error.cause instanceof Error ? error.cause : undefined\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\nimport { toError } from './errors.ts'\n\n/** A function that can be registered as an event listener, synchronous or async. */\ntype AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>\n\n/**\n * A typed EventEmitter that awaits all async listeners before resolving.\n * Wraps Node's `EventEmitter` with full TypeScript event-map inference.\n */\nexport class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {\n /**\n * `maxListener` controls the maximum number of listeners per event before Node emits a memory-leak warning.\n * @default 10\n */\n constructor(maxListener = 10) {\n this.#emitter.setMaxListeners(maxListener)\n }\n\n #emitter = new NodeEventEmitter()\n\n /**\n * Emits an event and awaits all registered listeners in parallel.\n * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.\n */\n async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<AsyncListener<TEvents[TEventName]>>\n\n if (listeners.length === 0) {\n return undefined\n }\n\n await Promise.all(\n listeners.map(async (listener) => {\n try {\n return await listener(...eventArgs)\n } catch (err) {\n let serializedArgs: string\n try {\n serializedArgs = JSON.stringify(eventArgs)\n } catch {\n serializedArgs = String(eventArgs)\n }\n throw new Error(`Error in async listener for \"${eventName}\" with eventArgs ${serializedArgs}`, { cause: toError(err) })\n }\n }),\n )\n }\n\n /** Registers a persistent listener for the given event. */\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.on(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /** Registers a one-shot listener that removes itself after the first invocation. */\n onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n const wrapper: AsyncListener<TEvents[TEventName]> = (...args) => {\n this.off(eventName, wrapper)\n return handler(...args)\n }\n this.on(eventName, wrapper)\n }\n\n /** Removes a previously registered listener. */\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void {\n this.#emitter.off(eventName, handler as AsyncListener<unknown[]>)\n }\n\n /** Removes all listeners from every event channel. */\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","","import process from 'node:process'\nimport { AsyncEventEmitter } from '@internals/utils'\nimport { type Config, type KubbEvents, safeBuild } from '@kubb/core'\nimport type { UnpluginFactory } from 'unplugin'\nimport { version as unpluginVersion } from '../package.json'\nimport type { Options } from './types.ts'\n\ntype RollupContext = {\n info?: (message: string) => void\n warn?: (message: string) => void\n error?: (message: string) => void\n}\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (options, meta) => {\n const name = 'unplugin-kubb' as const\n const events = new AsyncEventEmitter<KubbEvents>()\n const isVite = meta.framework === 'vite'\n const hrStart = process.hrtime()\n\n async function runBuild(ctx: RollupContext) {\n if (!options?.config) {\n if (ctx.error) {\n ctx.error?.(`[${name}] Config is not set`)\n } else {\n console.error(`[${name}] Config is not set`)\n }\n return\n }\n\n events.on('lifecycle:start', (version) => {\n console.log(`Kubb Unplugin ${version} 🧩`)\n })\n\n events.on('error', (error) => {\n console.error(`✗ ${error?.message || 'failed'}`)\n })\n\n events.on('warn', (message) => {\n console.warn(`⚠ ${message}`)\n })\n\n events.on('info', (message) => {\n console.info(`ℹ ${message}`)\n })\n\n events.on('success', (message) => {\n console.log(`✓ ${message}`)\n })\n\n events.on('plugin:end', (plugin, { duration }) => {\n const durationStr = duration >= 1000 ? `${(duration / 1000).toFixed(2)}s` : `${duration}ms`\n\n console.log(`✓ ${plugin.name} completed in ${durationStr}`)\n })\n\n events.on('files:processing:end', () => {\n const text = '✓ Files written successfully'\n\n console.log(text)\n })\n\n events.on('generation:end', (config) => {\n console.log(config.name ? `✓ Generation completed for ${config.name}` : '✓ Generation completed')\n })\n\n events.on('generation:summary', (config, { status, failedPlugins }) => {\n const pluginsCount = config.plugins?.length || 0\n const successCount = pluginsCount - failedPlugins.size\n\n console.log(\n status === 'success'\n ? `Kubb Summary: ✓ ${`${successCount} successful`}, ${pluginsCount} total`\n : `Kubb Summary: ✓ ${`${successCount} successful`}, ✗ ${`${failedPlugins.size} failed`}, ${pluginsCount} total`,\n )\n })\n\n await events.emit('lifecycle:start', unpluginVersion)\n\n const { root: _root, ...userConfig } = options.config as Config\n\n await events.emit('generation:start', options.config as Config)\n\n const { error, failedPlugins, pluginTimings, files, sources } = await safeBuild({\n config: {\n root: process.cwd(),\n ...userConfig,\n output: {\n write: true,\n ...userConfig.output,\n },\n },\n events,\n })\n\n const hasFailures = failedPlugins.size > 0 || error\n if (hasFailures) {\n // Collect all errors from failed plugins and general error\n const allErrors: Error[] = [\n error,\n ...Array.from(failedPlugins)\n .filter((it) => it.error)\n .map((it) => it.error),\n ].filter(Boolean)\n\n allErrors.forEach((err) => {\n events.emit('error', err)\n })\n }\n\n await events.emit('generation:end', options.config as Config, files, sources)\n await events.emit('generation:summary', options.config as Config, {\n failedPlugins,\n filesCreated: files.length,\n status: failedPlugins.size > 0 || error ? 'failed' : 'success',\n hrStart,\n pluginTimings,\n })\n\n await events.emit('lifecycle:end')\n }\n\n return {\n name,\n enforce: 'pre',\n apply: isVite ? 'build' : undefined,\n async buildStart() {\n await runBuild(this as unknown as RollupContext)\n },\n\n vite: {},\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,QAAQ,OAAuB;AAC7C,QAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;ACblE,IAAa,oBAAb,MAAoF;;;;;CAKlF,YAAY,cAAc,IAAI;AAC5B,QAAA,QAAc,gBAAgB,YAAY;;CAG5C,WAAW,IAAIC,YAAAA,cAAkB;;;;;CAMjC,MAAM,KAAgD,WAAuB,GAAG,WAA+C;EAC7H,MAAM,YAAY,MAAA,QAAc,UAAU,UAAU;AAEpD,MAAI,UAAU,WAAW,EACvB;AAGF,QAAM,QAAQ,IACZ,UAAU,IAAI,OAAO,aAAa;AAChC,OAAI;AACF,WAAO,MAAM,SAAS,GAAG,UAAU;YAC5B,KAAK;IACZ,IAAI;AACJ,QAAI;AACF,sBAAiB,KAAK,UAAU,UAAU;YACpC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