@kubb/core 3.0.0-alpha.1 → 3.0.0-alpha.11
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/{FileManager-EVJig-LT.d.ts → FileManager-BbUCeEyv.d.cts} +108 -94
- package/dist/{FileManager-DSLZ6ps7.d.cts → FileManager-CpuFz6eH.d.ts} +108 -94
- package/dist/chunk-2EU7DMPM.js +96 -0
- package/dist/chunk-2EU7DMPM.js.map +1 -0
- package/dist/chunk-4X5FFJPJ.js +8 -13
- package/dist/chunk-4X5FFJPJ.js.map +1 -1
- package/dist/chunk-52WA2JF5.cjs +1536 -0
- package/dist/chunk-52WA2JF5.cjs.map +1 -0
- package/dist/chunk-ADFKVVPE.cjs +42 -0
- package/dist/chunk-ADFKVVPE.cjs.map +1 -0
- package/dist/{chunk-3OXCZ5DJ.js → chunk-E6CN2CZC.js} +63 -54
- package/dist/chunk-E6CN2CZC.js.map +1 -0
- package/dist/chunk-HBQM723K.js +1049 -0
- package/dist/chunk-HBQM723K.js.map +1 -0
- package/dist/{chunk-67C6RBGQ.cjs → chunk-HMCSWG5L.cjs} +25 -26
- package/dist/chunk-HMCSWG5L.cjs.map +1 -0
- package/dist/chunk-L6YLVCKM.js +894 -0
- package/dist/chunk-L6YLVCKM.js.map +1 -0
- package/dist/chunk-PJLUPV3P.cjs +1088 -0
- package/dist/chunk-PJLUPV3P.cjs.map +1 -0
- package/dist/chunk-TTDCUWK7.cjs +101 -0
- package/dist/chunk-TTDCUWK7.cjs.map +1 -0
- package/dist/{chunk-LM2YQC3T.cjs → chunk-YEVCYV36.cjs} +81 -51
- package/dist/chunk-YEVCYV36.cjs.map +1 -0
- package/dist/index.cjs +545 -610
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -19
- package/dist/index.d.ts +6 -19
- package/dist/index.js +438 -522
- package/dist/index.js.map +1 -1
- package/dist/{logger-DChjnJMn.d.cts → logger-DvbHXjIO.d.cts} +29 -19
- package/dist/{logger-DChjnJMn.d.ts → logger-DvbHXjIO.d.ts} +29 -19
- package/dist/logger.cjs +25 -15
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -2
- package/dist/logger.d.ts +1 -2
- package/dist/logger.js +3 -15
- package/dist/logger.js.map +1 -1
- package/dist/mocks.cjs +27 -26
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +6 -9
- package/dist/mocks.d.ts +6 -9
- package/dist/mocks.js +22 -24
- package/dist/mocks.js.map +1 -1
- package/dist/prompt-L5KFKY73.cjs +760 -0
- package/dist/prompt-L5KFKY73.cjs.map +1 -0
- package/dist/prompt-WQQUN22Z.js +749 -0
- package/dist/prompt-WQQUN22Z.js.map +1 -0
- package/dist/transformers.cjs +215 -49
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.d.cts +1 -3
- package/dist/transformers.d.ts +1 -3
- package/dist/transformers.js +148 -35
- package/dist/transformers.js.map +1 -1
- package/dist/utils.cjs +65 -26
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +31 -3
- package/dist/utils.d.ts +31 -3
- package/dist/utils.js +3 -26
- package/dist/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/BarrelManager.ts +93 -107
- package/src/{Generator.ts → BaseGenerator.ts} +1 -1
- package/src/FileManager.ts +198 -297
- package/src/PackageManager.ts +1 -1
- package/src/PluginManager.ts +152 -101
- package/src/__snapshots__/barrel.json +91 -0
- package/src/__snapshots__/grouped.json +114 -0
- package/src/__snapshots__/ordered.json +62 -0
- package/src/build.ts +86 -171
- package/src/errors.ts +0 -11
- package/src/index.ts +1 -2
- package/src/logger.ts +76 -34
- package/src/plugin.ts +3 -3
- package/src/transformers/index.ts +2 -3
- package/src/transformers/trim.ts +0 -4
- package/src/types.ts +35 -35
- package/src/utils/TreeNode.ts +132 -50
- package/src/utils/executeStrategies.ts +1 -1
- package/src/utils/index.ts +2 -1
- package/src/utils/parser.ts +157 -0
- package/dist/chunk-3OXCZ5DJ.js.map +0 -1
- package/dist/chunk-5JZNFPUP.js +0 -309
- package/dist/chunk-5JZNFPUP.js.map +0 -1
- package/dist/chunk-67C6RBGQ.cjs.map +0 -1
- package/dist/chunk-ADC5UNZ5.cjs +0 -1227
- package/dist/chunk-ADC5UNZ5.cjs.map +0 -1
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-HMLY7DHA.js.map +0 -1
- package/dist/chunk-JKZG2IJR.js +0 -283
- package/dist/chunk-JKZG2IJR.js.map +0 -1
- package/dist/chunk-LM2YQC3T.cjs.map +0 -1
- package/dist/chunk-PZT4CTBV.cjs +0 -299
- package/dist/chunk-PZT4CTBV.cjs.map +0 -1
- package/dist/chunk-SA2GZKXS.js +0 -596
- package/dist/chunk-SA2GZKXS.js.map +0 -1
- package/dist/chunk-XCPFG6DO.cjs +0 -66
- package/dist/chunk-XCPFG6DO.cjs.map +0 -1
- package/dist/chunk-YTSNYMHW.cjs +0 -320
- package/dist/chunk-YTSNYMHW.cjs.map +0 -1
- package/schema.json +0 -86
- package/src/utils/getParser.ts +0 -17
package/dist/index.js
CHANGED
|
@@ -1,34 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
} from
|
|
14
|
-
import {
|
|
15
|
-
URLPath,
|
|
16
|
-
setUniqueName
|
|
17
|
-
} from "./chunk-5JZNFPUP.js";
|
|
18
|
-
import "./chunk-4X5FFJPJ.js";
|
|
19
|
-
import {
|
|
20
|
-
__privateAdd,
|
|
21
|
-
__privateGet,
|
|
22
|
-
__privateMethod,
|
|
23
|
-
__privateSet
|
|
24
|
-
} from "./chunk-HMLY7DHA.js";
|
|
25
|
-
|
|
26
|
-
// src/build.ts
|
|
27
|
-
import { clean, read } from "@kubb/fs";
|
|
28
|
-
|
|
29
|
-
// src/PluginManager.ts
|
|
30
|
-
import PQueue from "p-queue";
|
|
31
|
-
import { readSync } from "@kubb/fs";
|
|
1
|
+
import { transformReservedWord } from './chunk-2EU7DMPM.js';
|
|
2
|
+
import { EventEmitter, createLogger } from './chunk-E6CN2CZC.js';
|
|
3
|
+
import { FileManager, setUniqueName, processFiles, URLPath } from './chunk-L6YLVCKM.js';
|
|
4
|
+
export { FileManager } from './chunk-L6YLVCKM.js';
|
|
5
|
+
import './chunk-4X5FFJPJ.js';
|
|
6
|
+
import './chunk-HBQM723K.js';
|
|
7
|
+
import { getRelativePath, read, readSync, clean } from '@kubb/fs';
|
|
8
|
+
import path, { resolve, join } from 'node:path';
|
|
9
|
+
import mod from 'node:module';
|
|
10
|
+
import os from 'node:os';
|
|
11
|
+
import { pathToFileURL } from 'node:url';
|
|
12
|
+
import { findUp, findUpSync } from 'find-up';
|
|
13
|
+
import { coerce, satisfies } from 'semver';
|
|
32
14
|
|
|
33
15
|
// src/utils/executeStrategies.ts
|
|
34
16
|
function hookSeq(promises) {
|
|
@@ -65,11 +47,10 @@ function hookParallel(promises) {
|
|
|
65
47
|
}
|
|
66
48
|
|
|
67
49
|
// src/PromiseManager.ts
|
|
68
|
-
var _options;
|
|
69
50
|
var PromiseManager = class {
|
|
51
|
+
#options = {};
|
|
70
52
|
constructor(options = {}) {
|
|
71
|
-
|
|
72
|
-
__privateSet(this, _options, options);
|
|
53
|
+
this.#options = options;
|
|
73
54
|
return this;
|
|
74
55
|
}
|
|
75
56
|
run(strategy, promises) {
|
|
@@ -77,7 +58,7 @@ var PromiseManager = class {
|
|
|
77
58
|
return hookSeq(promises);
|
|
78
59
|
}
|
|
79
60
|
if (strategy === "first") {
|
|
80
|
-
return hookFirst(promises,
|
|
61
|
+
return hookFirst(promises, this.#options.nullCheck);
|
|
81
62
|
}
|
|
82
63
|
if (strategy === "parallel") {
|
|
83
64
|
return hookParallel(promises);
|
|
@@ -85,7 +66,6 @@ var PromiseManager = class {
|
|
|
85
66
|
throw new Error(`${strategy} not implemented`);
|
|
86
67
|
}
|
|
87
68
|
};
|
|
88
|
-
_options = new WeakMap();
|
|
89
69
|
function isPromise(result) {
|
|
90
70
|
return !!result && typeof result?.then === "function";
|
|
91
71
|
}
|
|
@@ -94,18 +74,9 @@ function isPromiseRejectedResult(result) {
|
|
|
94
74
|
}
|
|
95
75
|
|
|
96
76
|
// src/errors.ts
|
|
97
|
-
var Warning = class extends Error {
|
|
98
|
-
constructor(message, options) {
|
|
99
|
-
super(message, { cause: options?.cause });
|
|
100
|
-
this.name = "Warning";
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
77
|
var ValidationPluginError = class extends Error {
|
|
104
78
|
};
|
|
105
79
|
|
|
106
|
-
// src/plugin.ts
|
|
107
|
-
import path from "path";
|
|
108
|
-
|
|
109
80
|
// src/utils/cache.ts
|
|
110
81
|
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
111
82
|
return {
|
|
@@ -146,7 +117,7 @@ var pluginCore = createPlugin((options) => {
|
|
|
146
117
|
name: "core",
|
|
147
118
|
options,
|
|
148
119
|
key: ["core"],
|
|
149
|
-
|
|
120
|
+
context() {
|
|
150
121
|
return {
|
|
151
122
|
get config() {
|
|
152
123
|
return options.config;
|
|
@@ -173,7 +144,7 @@ var pluginCore = createPlugin((options) => {
|
|
|
173
144
|
};
|
|
174
145
|
},
|
|
175
146
|
resolvePath(baseName) {
|
|
176
|
-
const root = path.resolve(
|
|
147
|
+
const root = path.resolve(options.config.root, options.config.output.path);
|
|
177
148
|
return path.resolve(root, baseName);
|
|
178
149
|
},
|
|
179
150
|
resolveName(name) {
|
|
@@ -183,74 +154,25 @@ var pluginCore = createPlugin((options) => {
|
|
|
183
154
|
});
|
|
184
155
|
|
|
185
156
|
// src/PluginManager.ts
|
|
186
|
-
var _core, _usedPluginNames, _promiseManager, _PluginManager_instances, getSortedPlugins_fn, addExecutedToCallStack_fn, execute_fn, executeSync_fn, catcher_fn, parse_fn;
|
|
187
157
|
var PluginManager = class {
|
|
158
|
+
plugins;
|
|
159
|
+
fileManager;
|
|
160
|
+
events = new EventEmitter();
|
|
161
|
+
config;
|
|
162
|
+
executed = [];
|
|
163
|
+
logger;
|
|
164
|
+
options;
|
|
165
|
+
#core;
|
|
166
|
+
#usedPluginNames = {};
|
|
167
|
+
#promiseManager;
|
|
188
168
|
constructor(config, options) {
|
|
189
|
-
__privateAdd(this, _PluginManager_instances);
|
|
190
|
-
this.events = new EventEmitter();
|
|
191
|
-
this.executed = [];
|
|
192
|
-
__privateAdd(this, _core);
|
|
193
|
-
__privateAdd(this, _usedPluginNames, {});
|
|
194
|
-
__privateAdd(this, _promiseManager);
|
|
195
|
-
this.resolvePath = (params) => {
|
|
196
|
-
if (params.pluginKey) {
|
|
197
|
-
const paths = this.hookForPluginSync({
|
|
198
|
-
pluginKey: params.pluginKey,
|
|
199
|
-
hookName: "resolvePath",
|
|
200
|
-
parameters: [params.baseName, params.mode, params.options]
|
|
201
|
-
});
|
|
202
|
-
if (paths && paths?.length > 1) {
|
|
203
|
-
this.logger.emit("debug", [
|
|
204
|
-
`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
205
|
-
|
|
206
|
-
Paths: ${JSON.stringify(paths, void 0, 2)}
|
|
207
|
-
|
|
208
|
-
Falling back on the first item.
|
|
209
|
-
`
|
|
210
|
-
]);
|
|
211
|
-
}
|
|
212
|
-
return paths?.at(0);
|
|
213
|
-
}
|
|
214
|
-
return this.hookFirstSync({
|
|
215
|
-
hookName: "resolvePath",
|
|
216
|
-
parameters: [params.baseName, params.mode, params.options]
|
|
217
|
-
}).result;
|
|
218
|
-
};
|
|
219
|
-
this.resolveName = (params) => {
|
|
220
|
-
if (params.pluginKey) {
|
|
221
|
-
const names = this.hookForPluginSync({
|
|
222
|
-
pluginKey: params.pluginKey,
|
|
223
|
-
hookName: "resolveName",
|
|
224
|
-
parameters: [params.name, params.type]
|
|
225
|
-
});
|
|
226
|
-
if (names && names?.length > 1) {
|
|
227
|
-
this.logger.emit("debug", [
|
|
228
|
-
`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
229
|
-
|
|
230
|
-
Names: ${JSON.stringify(names, void 0, 2)}
|
|
231
|
-
|
|
232
|
-
Falling back on the first item.
|
|
233
|
-
`
|
|
234
|
-
]);
|
|
235
|
-
}
|
|
236
|
-
return transformReservedWord(names?.at(0) || params.name);
|
|
237
|
-
}
|
|
238
|
-
const name = this.hookFirstSync({
|
|
239
|
-
hookName: "resolveName",
|
|
240
|
-
parameters: [params.name, params.type]
|
|
241
|
-
}).result;
|
|
242
|
-
return transformReservedWord(name);
|
|
243
|
-
};
|
|
244
169
|
this.config = config;
|
|
170
|
+
this.options = options;
|
|
245
171
|
this.logger = options.logger;
|
|
246
|
-
this.
|
|
247
|
-
this
|
|
248
|
-
task: options.task,
|
|
249
|
-
queue: this.queue
|
|
250
|
-
});
|
|
251
|
-
__privateSet(this, _promiseManager, new PromiseManager({
|
|
172
|
+
this.fileManager = new FileManager();
|
|
173
|
+
this.#promiseManager = new PromiseManager({
|
|
252
174
|
nullCheck: (state) => !!state?.result
|
|
253
|
-
})
|
|
175
|
+
});
|
|
254
176
|
const plugins = config.plugins || [];
|
|
255
177
|
const core = pluginCore({
|
|
256
178
|
config,
|
|
@@ -259,34 +181,89 @@ Falling back on the first item.
|
|
|
259
181
|
fileManager: this.fileManager,
|
|
260
182
|
resolvePath: this.resolvePath.bind(this),
|
|
261
183
|
resolveName: this.resolveName.bind(this),
|
|
262
|
-
getPlugins:
|
|
184
|
+
getPlugins: this.#getSortedPlugins.bind(this)
|
|
263
185
|
});
|
|
264
|
-
|
|
265
|
-
this.plugins = [
|
|
266
|
-
return
|
|
186
|
+
this.#core = this.#parse(core, this, core.context.call(null));
|
|
187
|
+
this.plugins = [this.#core, ...plugins].map((plugin) => {
|
|
188
|
+
return this.#parse(plugin, this, this.#core.context);
|
|
267
189
|
});
|
|
268
190
|
return this;
|
|
269
191
|
}
|
|
270
192
|
getFile({ name, mode, extName, pluginKey, options }) {
|
|
271
|
-
let source = "";
|
|
272
193
|
const baseName = `${name}${extName}`;
|
|
273
194
|
const path2 = this.resolvePath({ baseName, mode, pluginKey, options });
|
|
274
195
|
if (!path2) {
|
|
275
196
|
throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`);
|
|
276
197
|
}
|
|
277
|
-
try {
|
|
278
|
-
source = readSync(path2);
|
|
279
|
-
} catch (_e) {
|
|
280
|
-
}
|
|
281
198
|
return {
|
|
282
199
|
path: path2,
|
|
283
200
|
baseName,
|
|
284
201
|
meta: {
|
|
285
202
|
pluginKey
|
|
286
203
|
},
|
|
287
|
-
|
|
204
|
+
sources: []
|
|
288
205
|
};
|
|
289
206
|
}
|
|
207
|
+
resolvePath = (params) => {
|
|
208
|
+
if (params.pluginKey) {
|
|
209
|
+
const paths = this.hookForPluginSync({
|
|
210
|
+
pluginKey: params.pluginKey,
|
|
211
|
+
hookName: "resolvePath",
|
|
212
|
+
parameters: [params.baseName, params.mode, params.options],
|
|
213
|
+
message: `Resolving path '${params.baseName}'`
|
|
214
|
+
});
|
|
215
|
+
if (paths && paths?.length > 1) {
|
|
216
|
+
this.logger.emit("debug", {
|
|
217
|
+
date: /* @__PURE__ */ new Date(),
|
|
218
|
+
logs: [
|
|
219
|
+
`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
220
|
+
|
|
221
|
+
Paths: ${JSON.stringify(paths, void 0, 2)}
|
|
222
|
+
|
|
223
|
+
Falling back on the first item.
|
|
224
|
+
`
|
|
225
|
+
]
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return paths?.at(0);
|
|
229
|
+
}
|
|
230
|
+
return this.hookFirstSync({
|
|
231
|
+
hookName: "resolvePath",
|
|
232
|
+
parameters: [params.baseName, params.mode, params.options],
|
|
233
|
+
message: `Resolving path '${params.baseName}'`
|
|
234
|
+
}).result;
|
|
235
|
+
};
|
|
236
|
+
//TODO refactor by using the order of plugins and the cache of the fileManager instead of guessing and recreating the name/path
|
|
237
|
+
resolveName = (params) => {
|
|
238
|
+
if (params.pluginKey) {
|
|
239
|
+
const names = this.hookForPluginSync({
|
|
240
|
+
pluginKey: params.pluginKey,
|
|
241
|
+
hookName: "resolveName",
|
|
242
|
+
parameters: [params.name, params.type],
|
|
243
|
+
message: `Resolving name '${params.name}' and type '${params.type}'`
|
|
244
|
+
});
|
|
245
|
+
if (names && names?.length > 1) {
|
|
246
|
+
this.logger.emit("debug", {
|
|
247
|
+
date: /* @__PURE__ */ new Date(),
|
|
248
|
+
logs: [
|
|
249
|
+
`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
250
|
+
|
|
251
|
+
Names: ${JSON.stringify(names, void 0, 2)}
|
|
252
|
+
|
|
253
|
+
Falling back on the first item.
|
|
254
|
+
`
|
|
255
|
+
]
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
return transformReservedWord(names?.at(0) || params.name);
|
|
259
|
+
}
|
|
260
|
+
const name = this.hookFirstSync({
|
|
261
|
+
hookName: "resolveName",
|
|
262
|
+
parameters: [params.name, params.type],
|
|
263
|
+
message: `Resolving name '${params.name}' and type '${params.type}'`
|
|
264
|
+
}).result;
|
|
265
|
+
return transformReservedWord(name);
|
|
266
|
+
};
|
|
290
267
|
/**
|
|
291
268
|
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
292
269
|
*/
|
|
@@ -296,21 +273,26 @@ Falling back on the first item.
|
|
|
296
273
|
/**
|
|
297
274
|
* Run a specific hookName for plugin x.
|
|
298
275
|
*/
|
|
299
|
-
hookForPlugin({
|
|
276
|
+
async hookForPlugin({
|
|
300
277
|
pluginKey,
|
|
301
278
|
hookName,
|
|
302
|
-
parameters
|
|
279
|
+
parameters,
|
|
280
|
+
message
|
|
303
281
|
}) {
|
|
304
282
|
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
283
|
+
this.logger.emit("progress_start", { id: hookName, size: plugins.length, message: "Running plugins..." });
|
|
305
284
|
const promises = plugins.map((plugin) => {
|
|
306
|
-
return
|
|
285
|
+
return this.#execute({
|
|
307
286
|
strategy: "hookFirst",
|
|
308
287
|
hookName,
|
|
309
288
|
parameters,
|
|
310
|
-
plugin
|
|
289
|
+
plugin,
|
|
290
|
+
message
|
|
311
291
|
});
|
|
312
292
|
}).filter(Boolean);
|
|
313
|
-
|
|
293
|
+
const items = await Promise.all(promises);
|
|
294
|
+
this.logger.emit("progress_stop", { id: hookName });
|
|
295
|
+
return items;
|
|
314
296
|
}
|
|
315
297
|
/**
|
|
316
298
|
* Run a specific hookName for plugin x.
|
|
@@ -318,17 +300,20 @@ Falling back on the first item.
|
|
|
318
300
|
hookForPluginSync({
|
|
319
301
|
pluginKey,
|
|
320
302
|
hookName,
|
|
321
|
-
parameters
|
|
303
|
+
parameters,
|
|
304
|
+
message
|
|
322
305
|
}) {
|
|
323
306
|
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
324
|
-
|
|
325
|
-
return
|
|
307
|
+
const result = plugins.map((plugin) => {
|
|
308
|
+
return this.#executeSync({
|
|
326
309
|
strategy: "hookFirst",
|
|
327
310
|
hookName,
|
|
328
311
|
parameters,
|
|
329
|
-
plugin
|
|
312
|
+
plugin,
|
|
313
|
+
message
|
|
330
314
|
});
|
|
331
315
|
}).filter(Boolean);
|
|
316
|
+
return result;
|
|
332
317
|
}
|
|
333
318
|
/**
|
|
334
319
|
* First non-null result stops and will return it's value.
|
|
@@ -336,17 +321,21 @@ Falling back on the first item.
|
|
|
336
321
|
async hookFirst({
|
|
337
322
|
hookName,
|
|
338
323
|
parameters,
|
|
339
|
-
skipped
|
|
324
|
+
skipped,
|
|
325
|
+
message
|
|
340
326
|
}) {
|
|
341
|
-
const
|
|
327
|
+
const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
|
|
342
328
|
return skipped ? skipped.has(plugin) : true;
|
|
343
|
-
})
|
|
329
|
+
});
|
|
330
|
+
this.logger.emit("progress_start", { id: hookName, size: plugins.length });
|
|
331
|
+
const promises = plugins.map((plugin) => {
|
|
344
332
|
return async () => {
|
|
345
|
-
const value = await
|
|
333
|
+
const value = await this.#execute({
|
|
346
334
|
strategy: "hookFirst",
|
|
347
335
|
hookName,
|
|
348
336
|
parameters,
|
|
349
|
-
plugin
|
|
337
|
+
plugin,
|
|
338
|
+
message
|
|
350
339
|
});
|
|
351
340
|
return Promise.resolve({
|
|
352
341
|
plugin,
|
|
@@ -354,7 +343,9 @@ Falling back on the first item.
|
|
|
354
343
|
});
|
|
355
344
|
};
|
|
356
345
|
});
|
|
357
|
-
|
|
346
|
+
const result = await this.#promiseManager.run("first", promises);
|
|
347
|
+
this.logger.emit("progress_stop", { id: hookName });
|
|
348
|
+
return result;
|
|
358
349
|
}
|
|
359
350
|
/**
|
|
360
351
|
* First non-null result stops and will return it's value.
|
|
@@ -362,19 +353,21 @@ Falling back on the first item.
|
|
|
362
353
|
hookFirstSync({
|
|
363
354
|
hookName,
|
|
364
355
|
parameters,
|
|
365
|
-
skipped
|
|
356
|
+
skipped,
|
|
357
|
+
message
|
|
366
358
|
}) {
|
|
367
359
|
let parseResult = null;
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
360
|
+
const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
|
|
361
|
+
return skipped ? skipped.has(plugin) : true;
|
|
362
|
+
});
|
|
363
|
+
for (const plugin of plugins) {
|
|
372
364
|
parseResult = {
|
|
373
|
-
result:
|
|
365
|
+
result: this.#executeSync({
|
|
374
366
|
strategy: "hookFirst",
|
|
375
367
|
hookName,
|
|
376
368
|
parameters,
|
|
377
|
-
plugin
|
|
369
|
+
plugin,
|
|
370
|
+
message
|
|
378
371
|
}),
|
|
379
372
|
plugin
|
|
380
373
|
};
|
|
@@ -389,23 +382,28 @@ Falling back on the first item.
|
|
|
389
382
|
*/
|
|
390
383
|
async hookParallel({
|
|
391
384
|
hookName,
|
|
392
|
-
parameters
|
|
385
|
+
parameters,
|
|
386
|
+
message
|
|
393
387
|
}) {
|
|
394
|
-
const
|
|
395
|
-
|
|
388
|
+
const plugins = this.#getSortedPlugins(hookName);
|
|
389
|
+
this.logger.emit("progress_start", { id: hookName, size: plugins.length });
|
|
390
|
+
const promises = plugins.map((plugin) => {
|
|
391
|
+
return () => this.#execute({
|
|
396
392
|
strategy: "hookParallel",
|
|
397
393
|
hookName,
|
|
398
394
|
parameters,
|
|
399
|
-
plugin
|
|
395
|
+
plugin,
|
|
396
|
+
message
|
|
400
397
|
});
|
|
401
398
|
});
|
|
402
|
-
const results = await
|
|
399
|
+
const results = await this.#promiseManager.run("parallel", promises);
|
|
403
400
|
results.forEach((result, index) => {
|
|
404
401
|
if (isPromiseRejectedResult(result)) {
|
|
405
|
-
const plugin =
|
|
406
|
-
|
|
402
|
+
const plugin = this.#getSortedPlugins(hookName)[index];
|
|
403
|
+
this.#catcher(result.reason, plugin, hookName);
|
|
407
404
|
}
|
|
408
405
|
});
|
|
406
|
+
this.logger.emit("progress_stop", { id: hookName });
|
|
409
407
|
return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
410
408
|
}
|
|
411
409
|
/**
|
|
@@ -414,36 +412,70 @@ Falling back on the first item.
|
|
|
414
412
|
hookReduceArg0({
|
|
415
413
|
hookName,
|
|
416
414
|
parameters,
|
|
417
|
-
reduce
|
|
415
|
+
reduce,
|
|
416
|
+
message
|
|
418
417
|
}) {
|
|
419
418
|
const [argument0, ...rest] = parameters;
|
|
419
|
+
const plugins = this.#getSortedPlugins(hookName);
|
|
420
420
|
let promise = Promise.resolve(argument0);
|
|
421
|
-
for (const plugin of
|
|
421
|
+
for (const plugin of plugins) {
|
|
422
422
|
promise = promise.then((arg0) => {
|
|
423
|
-
const value =
|
|
423
|
+
const value = this.#execute({
|
|
424
424
|
strategy: "hookReduceArg0",
|
|
425
425
|
hookName,
|
|
426
426
|
parameters: [arg0, ...rest],
|
|
427
|
-
plugin
|
|
427
|
+
plugin,
|
|
428
|
+
message
|
|
428
429
|
});
|
|
429
430
|
return value;
|
|
430
|
-
}).then((result) => reduce.call(
|
|
431
|
+
}).then((result) => reduce.call(this.#core.context, argument0, result, plugin));
|
|
431
432
|
}
|
|
432
433
|
return promise;
|
|
433
434
|
}
|
|
434
435
|
/**
|
|
435
436
|
* Chains plugins
|
|
436
437
|
*/
|
|
437
|
-
async hookSeq({
|
|
438
|
-
|
|
439
|
-
|
|
438
|
+
async hookSeq({
|
|
439
|
+
hookName,
|
|
440
|
+
parameters,
|
|
441
|
+
message
|
|
442
|
+
}) {
|
|
443
|
+
const plugins = this.#getSortedPlugins(hookName);
|
|
444
|
+
this.logger.emit("progress_start", { id: hookName, size: plugins.length });
|
|
445
|
+
const promises = plugins.map((plugin) => {
|
|
446
|
+
return () => this.#execute({
|
|
440
447
|
strategy: "hookSeq",
|
|
441
448
|
hookName,
|
|
442
449
|
parameters,
|
|
443
|
-
plugin
|
|
450
|
+
plugin,
|
|
451
|
+
message
|
|
444
452
|
});
|
|
445
453
|
});
|
|
446
|
-
|
|
454
|
+
await this.#promiseManager.run("seq", promises);
|
|
455
|
+
this.logger.emit("progress_stop", { id: hookName });
|
|
456
|
+
}
|
|
457
|
+
#getSortedPlugins(hookName) {
|
|
458
|
+
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
459
|
+
if (hookName) {
|
|
460
|
+
return plugins.filter((item) => item[hookName]);
|
|
461
|
+
}
|
|
462
|
+
return plugins.map((plugin) => {
|
|
463
|
+
if (plugin.pre) {
|
|
464
|
+
const isValid = plugin.pre.every((pluginName) => plugins.find((pluginToFind) => pluginToFind.name === pluginName));
|
|
465
|
+
if (!isValid) {
|
|
466
|
+
throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return plugin;
|
|
470
|
+
}).sort((a, b) => {
|
|
471
|
+
if (b.pre?.includes(a.name)) {
|
|
472
|
+
return 1;
|
|
473
|
+
}
|
|
474
|
+
if (b.post?.includes(a.name)) {
|
|
475
|
+
return -1;
|
|
476
|
+
}
|
|
477
|
+
return 0;
|
|
478
|
+
});
|
|
447
479
|
}
|
|
448
480
|
getPluginsByKey(hookName, pluginKey) {
|
|
449
481
|
const plugins = [...this.plugins];
|
|
@@ -460,14 +492,146 @@ Falling back on the first item.
|
|
|
460
492
|
if (!pluginByPluginName?.length) {
|
|
461
493
|
const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
|
|
462
494
|
if (corePlugin) {
|
|
463
|
-
this.logger.emit("debug",
|
|
495
|
+
this.logger.emit("debug", {
|
|
496
|
+
date: /* @__PURE__ */ new Date(),
|
|
497
|
+
logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`]
|
|
498
|
+
});
|
|
464
499
|
} else {
|
|
465
|
-
this.logger.emit("debug",
|
|
500
|
+
this.logger.emit("debug", {
|
|
501
|
+
date: /* @__PURE__ */ new Date(),
|
|
502
|
+
logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`]
|
|
503
|
+
});
|
|
466
504
|
}
|
|
467
505
|
return corePlugin ? [corePlugin] : [];
|
|
468
506
|
}
|
|
469
507
|
return pluginByPluginName;
|
|
470
508
|
}
|
|
509
|
+
#addExecutedToCallStack(executer) {
|
|
510
|
+
if (executer) {
|
|
511
|
+
this.events.emit("executed", executer);
|
|
512
|
+
this.executed.push(executer);
|
|
513
|
+
this.logger.emit("progressed", { id: executer.hookName, message: `${executer.plugin.name}: ${executer.message}` });
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Run an async plugin hook and return the result.
|
|
518
|
+
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
519
|
+
* @param args Arguments passed to the plugin hook.
|
|
520
|
+
* @param plugin The actual pluginObject to run.
|
|
521
|
+
*/
|
|
522
|
+
// Implementation signature
|
|
523
|
+
#execute({
|
|
524
|
+
strategy,
|
|
525
|
+
hookName,
|
|
526
|
+
parameters,
|
|
527
|
+
plugin,
|
|
528
|
+
message
|
|
529
|
+
}) {
|
|
530
|
+
const hook = plugin[hookName];
|
|
531
|
+
let output;
|
|
532
|
+
if (!hook) {
|
|
533
|
+
return null;
|
|
534
|
+
}
|
|
535
|
+
this.events.emit("executing", { strategy, hookName, parameters, plugin, message });
|
|
536
|
+
const promise = new Promise((resolve2) => {
|
|
537
|
+
resolve2(void 0);
|
|
538
|
+
});
|
|
539
|
+
const task = promise.then(() => {
|
|
540
|
+
if (typeof hook === "function") {
|
|
541
|
+
const possiblePromiseResult = hook.apply({ ...this.#core.context, plugin }, parameters);
|
|
542
|
+
if (isPromise(possiblePromiseResult)) {
|
|
543
|
+
return Promise.resolve(possiblePromiseResult);
|
|
544
|
+
}
|
|
545
|
+
return possiblePromiseResult;
|
|
546
|
+
}
|
|
547
|
+
return hook;
|
|
548
|
+
}).then((result) => {
|
|
549
|
+
output = result;
|
|
550
|
+
this.#addExecutedToCallStack({
|
|
551
|
+
parameters,
|
|
552
|
+
output,
|
|
553
|
+
strategy,
|
|
554
|
+
hookName,
|
|
555
|
+
plugin,
|
|
556
|
+
message
|
|
557
|
+
});
|
|
558
|
+
return result;
|
|
559
|
+
}).catch((e) => {
|
|
560
|
+
this.#catcher(e, plugin, hookName);
|
|
561
|
+
return null;
|
|
562
|
+
});
|
|
563
|
+
return task;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Run a sync plugin hook and return the result.
|
|
567
|
+
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
568
|
+
* @param args Arguments passed to the plugin hook.
|
|
569
|
+
* @param plugin The acutal plugin
|
|
570
|
+
* @param replaceContext When passed, the plugin context can be overridden.
|
|
571
|
+
*/
|
|
572
|
+
#executeSync({
|
|
573
|
+
strategy,
|
|
574
|
+
hookName,
|
|
575
|
+
parameters,
|
|
576
|
+
plugin,
|
|
577
|
+
message
|
|
578
|
+
}) {
|
|
579
|
+
const hook = plugin[hookName];
|
|
580
|
+
let output;
|
|
581
|
+
if (!hook) {
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
this.events.emit("executing", { strategy, hookName, parameters, plugin, message });
|
|
585
|
+
try {
|
|
586
|
+
if (typeof hook === "function") {
|
|
587
|
+
const fn = hook.apply({ ...this.#core.context, plugin }, parameters);
|
|
588
|
+
output = fn;
|
|
589
|
+
this.#addExecutedToCallStack({
|
|
590
|
+
parameters,
|
|
591
|
+
output,
|
|
592
|
+
strategy,
|
|
593
|
+
hookName,
|
|
594
|
+
plugin,
|
|
595
|
+
message
|
|
596
|
+
});
|
|
597
|
+
return fn;
|
|
598
|
+
}
|
|
599
|
+
output = hook;
|
|
600
|
+
this.#addExecutedToCallStack({
|
|
601
|
+
parameters,
|
|
602
|
+
output,
|
|
603
|
+
strategy,
|
|
604
|
+
hookName,
|
|
605
|
+
plugin,
|
|
606
|
+
message
|
|
607
|
+
});
|
|
608
|
+
return hook;
|
|
609
|
+
} catch (e) {
|
|
610
|
+
this.#catcher(e, plugin, hookName);
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
#catcher(cause, plugin, hookName) {
|
|
615
|
+
const text = `${cause.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
|
|
616
|
+
this.logger.emit("error", text, cause);
|
|
617
|
+
this.events.emit("error", cause);
|
|
618
|
+
}
|
|
619
|
+
#parse(plugin, pluginManager, context) {
|
|
620
|
+
const usedPluginNames = pluginManager.#usedPluginNames;
|
|
621
|
+
setUniqueName(plugin.name, usedPluginNames);
|
|
622
|
+
const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
623
|
+
if (plugin.context && typeof plugin.context === "function") {
|
|
624
|
+
return {
|
|
625
|
+
...plugin,
|
|
626
|
+
key,
|
|
627
|
+
context: plugin.context.call(context)
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
return {
|
|
631
|
+
...plugin,
|
|
632
|
+
key
|
|
633
|
+
};
|
|
634
|
+
}
|
|
471
635
|
static getDependedPlugins(plugins, dependedPluginNames) {
|
|
472
636
|
let pluginNames = [];
|
|
473
637
|
if (typeof dependedPluginNames === "string") {
|
|
@@ -484,157 +648,8 @@ Falling back on the first item.
|
|
|
484
648
|
});
|
|
485
649
|
}
|
|
486
650
|
static get hooks() {
|
|
487
|
-
return ["buildStart", "resolvePath", "resolveName", "
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
_core = new WeakMap();
|
|
491
|
-
_usedPluginNames = new WeakMap();
|
|
492
|
-
_promiseManager = new WeakMap();
|
|
493
|
-
_PluginManager_instances = new WeakSet();
|
|
494
|
-
getSortedPlugins_fn = function(hookName) {
|
|
495
|
-
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
496
|
-
if (hookName) {
|
|
497
|
-
if (this.logger.logLevel === LogLevel.info) {
|
|
498
|
-
const containsHookName = plugins.some((item) => item[hookName]);
|
|
499
|
-
if (!containsHookName) {
|
|
500
|
-
this.logger.emit("warning", `No hook ${hookName} found`);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return plugins.filter((item) => item[hookName]);
|
|
504
|
-
}
|
|
505
|
-
return plugins.map((plugin) => {
|
|
506
|
-
if (plugin.pre) {
|
|
507
|
-
const isValid = plugin.pre.every((pluginName) => plugins.find((pluginToFind) => pluginToFind.name === pluginName));
|
|
508
|
-
if (!isValid) {
|
|
509
|
-
throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
return plugin;
|
|
513
|
-
}).sort((a, b) => {
|
|
514
|
-
if (b.pre?.includes(a.name)) {
|
|
515
|
-
return 1;
|
|
516
|
-
}
|
|
517
|
-
if (b.post?.includes(a.name)) {
|
|
518
|
-
return -1;
|
|
519
|
-
}
|
|
520
|
-
return 0;
|
|
521
|
-
});
|
|
522
|
-
};
|
|
523
|
-
addExecutedToCallStack_fn = function(executer) {
|
|
524
|
-
if (executer) {
|
|
525
|
-
this.events.emit("executed", executer);
|
|
526
|
-
this.executed.push(executer);
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
/**
|
|
530
|
-
* Run an async plugin hook and return the result.
|
|
531
|
-
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
532
|
-
* @param args Arguments passed to the plugin hook.
|
|
533
|
-
* @param plugin The actual pluginObject to run.
|
|
534
|
-
*/
|
|
535
|
-
// Implementation signature
|
|
536
|
-
execute_fn = function({
|
|
537
|
-
strategy,
|
|
538
|
-
hookName,
|
|
539
|
-
parameters,
|
|
540
|
-
plugin
|
|
541
|
-
}) {
|
|
542
|
-
const hook = plugin[hookName];
|
|
543
|
-
let output;
|
|
544
|
-
if (!hook) {
|
|
545
|
-
return null;
|
|
546
|
-
}
|
|
547
|
-
this.events.emit("execute", { strategy, hookName, parameters, plugin });
|
|
548
|
-
const task = Promise.resolve().then(() => {
|
|
549
|
-
if (typeof hook === "function") {
|
|
550
|
-
const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
551
|
-
if (isPromise(possiblePromiseResult)) {
|
|
552
|
-
return Promise.resolve(possiblePromiseResult);
|
|
553
|
-
}
|
|
554
|
-
return possiblePromiseResult;
|
|
555
|
-
}
|
|
556
|
-
return hook;
|
|
557
|
-
}).then((result) => {
|
|
558
|
-
output = result;
|
|
559
|
-
__privateMethod(this, _PluginManager_instances, addExecutedToCallStack_fn).call(this, {
|
|
560
|
-
parameters,
|
|
561
|
-
output,
|
|
562
|
-
strategy,
|
|
563
|
-
hookName,
|
|
564
|
-
plugin
|
|
565
|
-
});
|
|
566
|
-
return result;
|
|
567
|
-
}).catch((e) => {
|
|
568
|
-
__privateMethod(this, _PluginManager_instances, catcher_fn).call(this, e, plugin, hookName);
|
|
569
|
-
return null;
|
|
570
|
-
});
|
|
571
|
-
return task;
|
|
572
|
-
};
|
|
573
|
-
/**
|
|
574
|
-
* Run a sync plugin hook and return the result.
|
|
575
|
-
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
576
|
-
* @param args Arguments passed to the plugin hook.
|
|
577
|
-
* @param plugin The acutal plugin
|
|
578
|
-
* @param replaceContext When passed, the plugin context can be overridden.
|
|
579
|
-
*/
|
|
580
|
-
executeSync_fn = function({
|
|
581
|
-
strategy,
|
|
582
|
-
hookName,
|
|
583
|
-
parameters,
|
|
584
|
-
plugin
|
|
585
|
-
}) {
|
|
586
|
-
const hook = plugin[hookName];
|
|
587
|
-
let output;
|
|
588
|
-
if (!hook) {
|
|
589
|
-
return null;
|
|
590
|
-
}
|
|
591
|
-
this.events.emit("execute", { strategy, hookName, parameters, plugin });
|
|
592
|
-
try {
|
|
593
|
-
if (typeof hook === "function") {
|
|
594
|
-
const fn = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
595
|
-
output = fn;
|
|
596
|
-
return fn;
|
|
597
|
-
}
|
|
598
|
-
output = hook;
|
|
599
|
-
__privateMethod(this, _PluginManager_instances, addExecutedToCallStack_fn).call(this, {
|
|
600
|
-
parameters,
|
|
601
|
-
output,
|
|
602
|
-
strategy,
|
|
603
|
-
hookName,
|
|
604
|
-
plugin
|
|
605
|
-
});
|
|
606
|
-
return hook;
|
|
607
|
-
} catch (e) {
|
|
608
|
-
__privateMethod(this, _PluginManager_instances, catcher_fn).call(this, e, plugin, hookName);
|
|
609
|
-
return null;
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
catcher_fn = function(cause, plugin, hookName) {
|
|
613
|
-
const text = `${cause.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
|
|
614
|
-
this.logger.emit("error", text, cause);
|
|
615
|
-
this.events.emit("error", cause);
|
|
616
|
-
};
|
|
617
|
-
parse_fn = function(plugin, pluginManager, context) {
|
|
618
|
-
const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
|
|
619
|
-
setUniqueName(plugin.name, usedPluginNames);
|
|
620
|
-
const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
621
|
-
if (!plugin.transform) {
|
|
622
|
-
plugin.transform = function transform(_path, code) {
|
|
623
|
-
return code;
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
if (plugin.api && typeof plugin.api === "function") {
|
|
627
|
-
const api = plugin.api.call(context);
|
|
628
|
-
return {
|
|
629
|
-
...plugin,
|
|
630
|
-
key,
|
|
631
|
-
api
|
|
632
|
-
};
|
|
651
|
+
return ["buildStart", "resolvePath", "resolveName", "buildEnd"];
|
|
633
652
|
}
|
|
634
|
-
return {
|
|
635
|
-
...plugin,
|
|
636
|
-
key
|
|
637
|
-
};
|
|
638
653
|
};
|
|
639
654
|
|
|
640
655
|
// src/config.ts
|
|
@@ -644,240 +659,158 @@ function defineConfig(options) {
|
|
|
644
659
|
function isInputPath(result) {
|
|
645
660
|
return !!result && "path" in result;
|
|
646
661
|
}
|
|
647
|
-
|
|
648
|
-
// src/build.ts
|
|
649
|
-
async function transformReducer(_previousCode, result, _plugin) {
|
|
650
|
-
return result;
|
|
651
|
-
}
|
|
652
662
|
async function setup(options) {
|
|
653
|
-
const { config, logger = createLogger(
|
|
654
|
-
let count = 0;
|
|
663
|
+
const { config, logger = createLogger() } = options;
|
|
655
664
|
try {
|
|
656
665
|
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
657
666
|
await read(config.input.path);
|
|
658
667
|
}
|
|
659
668
|
} catch (e) {
|
|
660
669
|
if (isInputPath(config)) {
|
|
661
|
-
throw new Error(
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
cause: e
|
|
665
|
-
}
|
|
666
|
-
);
|
|
670
|
+
throw new Error(`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${config.input.path}`, {
|
|
671
|
+
cause: e
|
|
672
|
+
});
|
|
667
673
|
}
|
|
668
674
|
}
|
|
669
675
|
if (config.output.clean) {
|
|
670
676
|
await clean(config.output.path);
|
|
677
|
+
await clean(join(config.root, ".kubb"));
|
|
671
678
|
}
|
|
672
|
-
|
|
673
|
-
const { path: path2 } = file;
|
|
674
|
-
let source = await FileManager.getSource(file);
|
|
675
|
-
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
676
|
-
hookName: "load",
|
|
677
|
-
parameters: [path2]
|
|
678
|
-
});
|
|
679
|
-
if (loadedResult && isPromise(loadedResult)) {
|
|
680
|
-
source = await loadedResult;
|
|
681
|
-
}
|
|
682
|
-
if (loadedResult && !isPromise(loadedResult)) {
|
|
683
|
-
source = loadedResult;
|
|
684
|
-
}
|
|
685
|
-
if (source) {
|
|
686
|
-
source = await pluginManager.hookReduceArg0({
|
|
687
|
-
hookName: "transform",
|
|
688
|
-
parameters: [path2, source],
|
|
689
|
-
reduce: transformReducer
|
|
690
|
-
});
|
|
691
|
-
if (config.output.write || config.output.write === void 0) {
|
|
692
|
-
if (file.meta?.pluginKey) {
|
|
693
|
-
await pluginManager.hookForPlugin({
|
|
694
|
-
pluginKey: file.meta?.pluginKey,
|
|
695
|
-
hookName: "writeFile",
|
|
696
|
-
parameters: [path2, source]
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
await pluginManager.hookFirst({
|
|
700
|
-
hookName: "writeFile",
|
|
701
|
-
parameters: [path2, source]
|
|
702
|
-
});
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
return {
|
|
706
|
-
...file,
|
|
707
|
-
source: source || ""
|
|
708
|
-
};
|
|
709
|
-
};
|
|
710
|
-
const pluginManager = new PluginManager(config, { logger, task });
|
|
711
|
-
pluginManager.on("execute", (executer) => {
|
|
712
|
-
const { hookName, parameters, plugin } = executer;
|
|
713
|
-
if (hookName === "writeFile") {
|
|
714
|
-
const [code] = parameters;
|
|
715
|
-
logger.emit("debug", [`PluginKey ${p.dim(JSON.stringify(plugin.key))}
|
|
716
|
-
with source
|
|
717
|
-
|
|
718
|
-
${code}`]);
|
|
719
|
-
}
|
|
720
|
-
});
|
|
721
|
-
pluginManager.queue.on("add", () => {
|
|
722
|
-
if (logger.logLevel !== LogLevel.info) {
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
if (count === 0) {
|
|
726
|
-
logger.emit("start", "\u{1F4BE} Writing");
|
|
727
|
-
}
|
|
728
|
-
});
|
|
729
|
-
pluginManager.queue.on("active", () => {
|
|
730
|
-
if (logger.logLevel !== LogLevel.info) {
|
|
731
|
-
return;
|
|
732
|
-
}
|
|
733
|
-
if (logger.spinner && pluginManager.queue.size > 0) {
|
|
734
|
-
const text = `Item: ${count} Size: ${pluginManager.queue.size} Pending: ${pluginManager.queue.pending}`;
|
|
735
|
-
logger.spinner.suffixText = p.dim(text);
|
|
736
|
-
}
|
|
737
|
-
++count;
|
|
738
|
-
});
|
|
739
|
-
pluginManager.queue.on("completed", () => {
|
|
740
|
-
if (logger.logLevel !== LogLevel.info) {
|
|
741
|
-
return;
|
|
742
|
-
}
|
|
743
|
-
if (logger.spinner) {
|
|
744
|
-
const text = `Item: ${count} Size: ${pluginManager.queue.size} Pending: ${pluginManager.queue.pending}`;
|
|
745
|
-
logger.spinner.suffixText = p.dim(text);
|
|
746
|
-
}
|
|
747
|
-
});
|
|
748
|
-
pluginManager.on("executed", (executer) => {
|
|
749
|
-
const { hookName, plugin, output, parameters } = executer;
|
|
750
|
-
const logs = [
|
|
751
|
-
`${randomCliColour(plugin.name)} Executing ${hookName}`,
|
|
752
|
-
parameters && `${p.bgWhite("Parameters")} ${randomCliColour(plugin.name)} ${hookName}`,
|
|
753
|
-
JSON.stringify(parameters, void 0, 2),
|
|
754
|
-
output && `${p.bgWhite("Output")} ${randomCliColour(plugin.name)} ${hookName}`,
|
|
755
|
-
output
|
|
756
|
-
].filter(Boolean);
|
|
757
|
-
logger.emit("debug", logs);
|
|
758
|
-
});
|
|
759
|
-
return pluginManager;
|
|
679
|
+
return new PluginManager(config, { logger });
|
|
760
680
|
}
|
|
761
681
|
async function build(options) {
|
|
762
|
-
const pluginManager = await
|
|
763
|
-
|
|
764
|
-
await pluginManager.hookParallel({
|
|
765
|
-
hookName: "buildStart",
|
|
766
|
-
parameters: [options.config]
|
|
767
|
-
});
|
|
768
|
-
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
769
|
-
if (logger.logLevel === LogLevel.info) {
|
|
770
|
-
logger.emit("end", "\u{1F4BE} Writing completed");
|
|
771
|
-
}
|
|
772
|
-
const files = await Promise.all(
|
|
773
|
-
fileManager.files.map(async (file) => ({
|
|
774
|
-
...file,
|
|
775
|
-
source: await FileManager.getSource(file)
|
|
776
|
-
}))
|
|
777
|
-
);
|
|
682
|
+
const { files, pluginManager, error } = await safeBuild(options);
|
|
683
|
+
if (error) throw error;
|
|
778
684
|
return {
|
|
779
685
|
files,
|
|
780
|
-
pluginManager
|
|
686
|
+
pluginManager,
|
|
687
|
+
error
|
|
781
688
|
};
|
|
782
689
|
}
|
|
783
690
|
async function safeBuild(options) {
|
|
691
|
+
let files = [];
|
|
784
692
|
const pluginManager = await setup(options);
|
|
785
|
-
const { fileManager, logger } = pluginManager;
|
|
786
693
|
try {
|
|
694
|
+
pluginManager.events.on("executing", ({ plugin, message }) => {
|
|
695
|
+
pluginManager.logger.emit("debug", { date: /* @__PURE__ */ new Date(), logs: [`Executing pluginKey ${plugin.key?.join(".")} | ${message}`] });
|
|
696
|
+
});
|
|
697
|
+
pluginManager.events.on("executed", ({ plugin, message, output }) => {
|
|
698
|
+
pluginManager.logger.emit("debug", {
|
|
699
|
+
date: /* @__PURE__ */ new Date(),
|
|
700
|
+
logs: [`Executed pluginKey ${plugin.key?.join(".")} | ${message} | ${JSON.stringify(output, void 0, 2)}`]
|
|
701
|
+
});
|
|
702
|
+
});
|
|
787
703
|
await pluginManager.hookParallel({
|
|
788
704
|
hookName: "buildStart",
|
|
789
|
-
parameters: [options.config]
|
|
705
|
+
parameters: [options.config],
|
|
706
|
+
message: "buildStart"
|
|
790
707
|
});
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
708
|
+
const root = resolve(options.config.root);
|
|
709
|
+
const rootPath = resolve(root, options.config.output.path, "index.ts");
|
|
710
|
+
const barrelFiles = pluginManager.fileManager.files.filter((file) => {
|
|
711
|
+
return file.sources.some((source) => source.isIndexable);
|
|
712
|
+
});
|
|
713
|
+
const rootFile = {
|
|
714
|
+
path: rootPath,
|
|
715
|
+
baseName: "index.ts",
|
|
716
|
+
exports: barrelFiles.flatMap((file) => {
|
|
717
|
+
return file.sources?.map((source) => {
|
|
718
|
+
if (!file.path || !source.isIndexable) {
|
|
719
|
+
return void 0;
|
|
720
|
+
}
|
|
721
|
+
const plugin = pluginManager.plugins.find((item) => {
|
|
722
|
+
const meta = file.meta;
|
|
723
|
+
return item.name === meta?.pluginKey?.[0];
|
|
724
|
+
});
|
|
725
|
+
if (plugin?.output?.exportType === false) {
|
|
726
|
+
return void 0;
|
|
727
|
+
}
|
|
728
|
+
if (FileManager.getMode(plugin?.output?.path) === "single") {
|
|
729
|
+
return void 0;
|
|
730
|
+
}
|
|
731
|
+
return {
|
|
732
|
+
name: options.config.output.exportType === "barrel" ? void 0 : [source.name],
|
|
733
|
+
path: getRelativePath(rootPath, file.path),
|
|
734
|
+
isTypeOnly: source.isTypeOnly
|
|
735
|
+
};
|
|
736
|
+
}).filter(Boolean);
|
|
737
|
+
}).filter(Boolean),
|
|
738
|
+
sources: [],
|
|
739
|
+
meta: {}
|
|
740
|
+
};
|
|
741
|
+
if (options.config.output.exportType) {
|
|
742
|
+
await pluginManager.fileManager.add(rootFile);
|
|
743
|
+
}
|
|
744
|
+
files = await processFiles({
|
|
745
|
+
config: options.config,
|
|
746
|
+
dryRun: !options.config.output.write,
|
|
747
|
+
files: pluginManager.fileManager.files,
|
|
748
|
+
logger: pluginManager.logger
|
|
749
|
+
});
|
|
750
|
+
await pluginManager.hookParallel({ hookName: "buildEnd", message: `Build stopped for ${options.config.name}` });
|
|
751
|
+
pluginManager.fileManager.clear();
|
|
795
752
|
} catch (e) {
|
|
796
|
-
const files2 = await Promise.all(
|
|
797
|
-
fileManager.files.map(async (file) => ({
|
|
798
|
-
...file,
|
|
799
|
-
source: await FileManager.getSource(file)
|
|
800
|
-
}))
|
|
801
|
-
);
|
|
802
753
|
return {
|
|
803
|
-
files:
|
|
754
|
+
files: [],
|
|
804
755
|
pluginManager,
|
|
805
756
|
error: e
|
|
806
757
|
};
|
|
807
758
|
}
|
|
808
|
-
const files = await Promise.all(
|
|
809
|
-
fileManager.files.map(async (file) => ({
|
|
810
|
-
...file,
|
|
811
|
-
source: await FileManager.getSource(file)
|
|
812
|
-
}))
|
|
813
|
-
);
|
|
814
759
|
return {
|
|
815
760
|
files,
|
|
816
761
|
pluginManager
|
|
817
762
|
};
|
|
818
763
|
}
|
|
819
764
|
|
|
820
|
-
// src/
|
|
821
|
-
var
|
|
822
|
-
|
|
765
|
+
// src/BaseGenerator.ts
|
|
766
|
+
var BaseGenerator = class {
|
|
767
|
+
#options = {};
|
|
768
|
+
#context = {};
|
|
823
769
|
constructor(options, context) {
|
|
824
|
-
__privateAdd(this, _options2, {});
|
|
825
|
-
__privateAdd(this, _context, {});
|
|
826
770
|
if (context) {
|
|
827
|
-
|
|
771
|
+
this.#context = context;
|
|
828
772
|
}
|
|
829
773
|
if (options) {
|
|
830
|
-
|
|
774
|
+
this.#options = options;
|
|
831
775
|
}
|
|
832
776
|
return this;
|
|
833
777
|
}
|
|
834
778
|
get options() {
|
|
835
|
-
return
|
|
779
|
+
return this.#options;
|
|
836
780
|
}
|
|
837
781
|
get context() {
|
|
838
|
-
return
|
|
782
|
+
return this.#context;
|
|
839
783
|
}
|
|
840
784
|
set options(options) {
|
|
841
|
-
|
|
785
|
+
this.#options = { ...this.#options, ...options };
|
|
842
786
|
}
|
|
843
787
|
};
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
import mod from "module";
|
|
849
|
-
import os from "os";
|
|
850
|
-
import { pathToFileURL } from "url";
|
|
851
|
-
import { findUp, findUpSync } from "find-up";
|
|
852
|
-
import { coerce, satisfies } from "semver";
|
|
853
|
-
import { read as read2, readSync as readSync2 } from "@kubb/fs";
|
|
854
|
-
var _cache, _cwd, _SLASHES, _PackageManager_instances, match_fn;
|
|
855
|
-
var _PackageManager = class _PackageManager {
|
|
788
|
+
var PackageManager = class _PackageManager {
|
|
789
|
+
static #cache = {};
|
|
790
|
+
#cwd;
|
|
791
|
+
#SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
|
|
856
792
|
constructor(workspace) {
|
|
857
|
-
__privateAdd(this, _PackageManager_instances);
|
|
858
|
-
__privateAdd(this, _cwd);
|
|
859
|
-
__privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
|
|
860
793
|
if (workspace) {
|
|
861
|
-
|
|
794
|
+
this.#cwd = workspace;
|
|
862
795
|
}
|
|
863
796
|
return this;
|
|
864
797
|
}
|
|
865
798
|
set workspace(workspace) {
|
|
866
|
-
|
|
799
|
+
this.#cwd = workspace;
|
|
867
800
|
}
|
|
868
801
|
get workspace() {
|
|
869
|
-
return
|
|
802
|
+
return this.#cwd;
|
|
870
803
|
}
|
|
871
804
|
normalizeDirectory(directory) {
|
|
872
|
-
if (!
|
|
805
|
+
if (!this.#SLASHES.has(directory[directory.length - 1])) {
|
|
873
806
|
return `${directory}/`;
|
|
874
807
|
}
|
|
875
808
|
return directory;
|
|
876
809
|
}
|
|
877
810
|
getLocation(path2) {
|
|
878
811
|
let location = path2;
|
|
879
|
-
if (
|
|
880
|
-
const require2 = mod.createRequire(this.normalizeDirectory(
|
|
812
|
+
if (this.#cwd) {
|
|
813
|
+
const require2 = mod.createRequire(this.normalizeDirectory(this.#cwd));
|
|
881
814
|
location = require2.resolve(path2);
|
|
882
815
|
}
|
|
883
816
|
return location;
|
|
@@ -891,52 +824,63 @@ var _PackageManager = class _PackageManager {
|
|
|
891
824
|
const module = await import(location);
|
|
892
825
|
return module?.default ?? module;
|
|
893
826
|
} catch (e) {
|
|
894
|
-
console.
|
|
827
|
+
console.error(e);
|
|
895
828
|
return void 0;
|
|
896
829
|
}
|
|
897
830
|
}
|
|
898
831
|
async getPackageJSON() {
|
|
899
832
|
const pkgPath = await findUp(["package.json"], {
|
|
900
|
-
cwd:
|
|
833
|
+
cwd: this.#cwd
|
|
901
834
|
});
|
|
902
835
|
if (!pkgPath) {
|
|
903
836
|
return void 0;
|
|
904
837
|
}
|
|
905
|
-
const json = await
|
|
838
|
+
const json = await read(pkgPath);
|
|
906
839
|
return JSON.parse(json);
|
|
907
840
|
}
|
|
908
841
|
getPackageJSONSync() {
|
|
909
842
|
const pkgPath = findUpSync(["package.json"], {
|
|
910
|
-
cwd:
|
|
843
|
+
cwd: this.#cwd
|
|
911
844
|
});
|
|
912
845
|
if (!pkgPath) {
|
|
913
846
|
return void 0;
|
|
914
847
|
}
|
|
915
|
-
const json =
|
|
848
|
+
const json = readSync(pkgPath);
|
|
916
849
|
return JSON.parse(json);
|
|
917
850
|
}
|
|
918
851
|
static setVersion(dependency, version) {
|
|
919
|
-
|
|
852
|
+
_PackageManager.#cache[dependency] = version;
|
|
853
|
+
}
|
|
854
|
+
#match(packageJSON, dependency) {
|
|
855
|
+
const dependencies = {
|
|
856
|
+
...packageJSON["dependencies"] || {},
|
|
857
|
+
...packageJSON["devDependencies"] || {}
|
|
858
|
+
};
|
|
859
|
+
if (typeof dependency === "string" && dependencies[dependency]) {
|
|
860
|
+
return dependencies[dependency];
|
|
861
|
+
}
|
|
862
|
+
const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
|
|
863
|
+
return matchedDependency ? dependencies[matchedDependency] : void 0;
|
|
920
864
|
}
|
|
921
865
|
async getVersion(dependency) {
|
|
922
|
-
if (typeof dependency === "string" &&
|
|
923
|
-
return
|
|
866
|
+
if (typeof dependency === "string" && _PackageManager.#cache[dependency]) {
|
|
867
|
+
return _PackageManager.#cache[dependency];
|
|
924
868
|
}
|
|
925
869
|
const packageJSON = await this.getPackageJSON();
|
|
926
870
|
if (!packageJSON) {
|
|
927
871
|
return void 0;
|
|
928
872
|
}
|
|
929
|
-
return
|
|
873
|
+
return this.#match(packageJSON, dependency);
|
|
930
874
|
}
|
|
931
875
|
getVersionSync(dependency) {
|
|
932
|
-
if (typeof dependency === "string" &&
|
|
933
|
-
return
|
|
876
|
+
if (typeof dependency === "string" && _PackageManager.#cache[dependency]) {
|
|
877
|
+
return _PackageManager.#cache[dependency];
|
|
934
878
|
}
|
|
935
879
|
const packageJSON = this.getPackageJSONSync();
|
|
936
880
|
if (!packageJSON) {
|
|
937
881
|
return void 0;
|
|
938
882
|
}
|
|
939
|
-
return
|
|
883
|
+
return this.#match(packageJSON, dependency);
|
|
940
884
|
}
|
|
941
885
|
async isValid(dependency, version) {
|
|
942
886
|
const packageVersion = await this.getVersion(dependency);
|
|
@@ -964,35 +908,7 @@ var _PackageManager = class _PackageManager {
|
|
|
964
908
|
return satisfies(semVer, version);
|
|
965
909
|
}
|
|
966
910
|
};
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
_PackageManager_instances = new WeakSet();
|
|
971
|
-
match_fn = function(packageJSON, dependency) {
|
|
972
|
-
const dependencies = {
|
|
973
|
-
...packageJSON["dependencies"] || {},
|
|
974
|
-
...packageJSON["devDependencies"] || {}
|
|
975
|
-
};
|
|
976
|
-
if (typeof dependency === "string" && dependencies[dependency]) {
|
|
977
|
-
return dependencies[dependency];
|
|
978
|
-
}
|
|
979
|
-
const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
|
|
980
|
-
return matchedDependency ? dependencies[matchedDependency] : void 0;
|
|
981
|
-
};
|
|
982
|
-
__privateAdd(_PackageManager, _cache, {});
|
|
983
|
-
var PackageManager = _PackageManager;
|
|
984
|
-
export {
|
|
985
|
-
FileManager,
|
|
986
|
-
Generator,
|
|
987
|
-
PackageManager,
|
|
988
|
-
PluginManager,
|
|
989
|
-
PromiseManager,
|
|
990
|
-
Warning,
|
|
991
|
-
build,
|
|
992
|
-
createPlugin,
|
|
993
|
-
build as default,
|
|
994
|
-
defineConfig,
|
|
995
|
-
isInputPath,
|
|
996
|
-
safeBuild
|
|
997
|
-
};
|
|
911
|
+
|
|
912
|
+
export { BaseGenerator, PackageManager, PluginManager, PromiseManager, build, createPlugin, build as default, defineConfig, isInputPath, safeBuild };
|
|
913
|
+
//# sourceMappingURL=index.js.map
|
|
998
914
|
//# sourceMappingURL=index.js.map
|