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