@kubb/core 3.16.1 → 3.16.3
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-Dk759iZ3.js +918 -0
- package/dist/FileManager-Dk759iZ3.js.map +1 -0
- package/dist/FileManager-DsRjYJa_.cjs +1031 -0
- package/dist/FileManager-DsRjYJa_.cjs.map +1 -0
- package/dist/PluginManager-1jPxuyQK.d.ts +511 -0
- package/dist/PluginManager-Cvj5AlsU.d.cts +511 -0
- package/dist/chunk-DWy1uDak.cjs +39 -0
- package/dist/chunk-DbvY3SJr.js +33 -0
- package/dist/fs-BacxV1CO.js +87 -0
- package/dist/fs-BacxV1CO.js.map +1 -0
- package/dist/fs-BazSaf2y.cjs +129 -0
- package/dist/fs-BazSaf2y.cjs.map +1 -0
- package/dist/fs.cjs +15 -39
- package/dist/fs.d.cts +2 -19
- package/dist/fs.d.ts +2 -19
- package/dist/fs.js +4 -3
- package/dist/index-BKHQGQVq.d.ts +140 -0
- package/dist/index-BfD6z1P5.d.cts +141 -0
- package/dist/index-Cb4pChs8.d.ts +180 -0
- package/dist/index-D2ptHzfn.d.cts +180 -0
- package/dist/index.cjs +1000 -1028
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +107 -89
- package/dist/index.d.ts +107 -89
- package/dist/index.js +1020 -864
- package/dist/index.js.map +1 -1
- package/dist/logger-BxvJpQMX.cjs +1115 -0
- package/dist/logger-BxvJpQMX.cjs.map +1 -0
- package/dist/logger-Cs45J4yy.js +1085 -0
- package/dist/logger-Cs45J4yy.js.map +1 -0
- package/dist/logger-OWS6fqk0.d.cts +69 -0
- package/dist/logger-xcdTETKy.d.ts +69 -0
- package/dist/logger.cjs +6 -24
- package/dist/logger.d.cts +2 -3
- package/dist/logger.d.ts +2 -3
- package/dist/logger.js +4 -4
- package/dist/mocks.cjs +49 -65
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +6 -6
- package/dist/mocks.d.ts +6 -6
- package/dist/mocks.js +48 -59
- package/dist/mocks.js.map +1 -1
- package/dist/prompt-DwEAzq0q.js +853 -0
- package/dist/prompt-DwEAzq0q.js.map +1 -0
- package/dist/prompt-qiwl6Be9.cjs +855 -0
- package/dist/prompt-qiwl6Be9.cjs.map +1 -0
- package/dist/transformers-B3CHtwuB.cjs +948 -0
- package/dist/transformers-B3CHtwuB.cjs.map +1 -0
- package/dist/transformers-CJqBQFIl.js +829 -0
- package/dist/transformers-CJqBQFIl.js.map +1 -0
- package/dist/transformers.cjs +33 -88
- package/dist/transformers.d.cts +75 -54
- package/dist/transformers.d.ts +75 -54
- package/dist/transformers.js +4 -3
- package/dist/utils.cjs +20 -73
- package/dist/utils.d.cts +5 -126
- package/dist/utils.d.ts +5 -126
- package/dist/utils.js +6 -5
- package/dist/write-CLTPlucv.js +42 -0
- package/dist/write-CLTPlucv.js.map +1 -0
- package/dist/write-l_NzIqyy.cjs +48 -0
- package/dist/write-l_NzIqyy.cjs.map +1 -0
- package/package.json +28 -35
- package/src/BarrelManager.ts +1 -0
- package/src/PromiseManager.ts +1 -7
- package/src/build.ts +9 -11
- package/src/index.ts +5 -5
- package/src/logger.ts +10 -10
- package/src/utils/FunctionParams.ts +3 -1
- package/src/utils/TreeNode.ts +3 -1
- package/dist/PluginManager-E3SghPP9.d.cts +0 -458
- package/dist/PluginManager-PDmRCu9k.d.ts +0 -458
- package/dist/chunk-4V7HK7PT.js +0 -1199
- package/dist/chunk-4V7HK7PT.js.map +0 -1
- package/dist/chunk-BHSTNFNQ.cjs +0 -701
- package/dist/chunk-BHSTNFNQ.cjs.map +0 -1
- package/dist/chunk-CAZ37TGB.js +0 -918
- package/dist/chunk-CAZ37TGB.js.map +0 -1
- package/dist/chunk-E4XLCCPK.cjs +0 -170
- package/dist/chunk-E4XLCCPK.cjs.map +0 -1
- package/dist/chunk-GBYHPDPK.js +0 -595
- package/dist/chunk-GBYHPDPK.js.map +0 -1
- package/dist/chunk-MCNA6SYG.cjs +0 -1231
- package/dist/chunk-MCNA6SYG.cjs.map +0 -1
- package/dist/chunk-QR7CQIA3.cjs +0 -943
- package/dist/chunk-QR7CQIA3.cjs.map +0 -1
- package/dist/chunk-YRPOID7E.js +0 -157
- package/dist/chunk-YRPOID7E.js.map +0 -1
- package/dist/fs.cjs.map +0 -1
- package/dist/fs.js.map +0 -1
- package/dist/logger-BWq-oJU_.d.cts +0 -63
- package/dist/logger-BWq-oJU_.d.ts +0 -63
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.js.map +0 -1
- package/dist/parser-C1vOjVEd.d.ts +0 -41
- package/dist/parser-D6vU1kA9.d.cts +0 -41
- package/dist/prompt-ELTHGQK6.js +0 -753
- package/dist/prompt-ELTHGQK6.js.map +0 -1
- package/dist/prompt-U7M5G25C.cjs +0 -761
- package/dist/prompt-U7M5G25C.cjs.map +0 -1
- package/dist/transformers.cjs.map +0 -1
- package/dist/transformers.js.map +0 -1
- package/dist/types-CA8nQKwM.d.cts +0 -132
- package/dist/types-CA8nQKwM.d.ts +0 -132
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,1084 +1,1055 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_chunk = require('./chunk-DWy1uDak.cjs');
|
|
3
|
+
const require_fs = require('./fs-BazSaf2y.cjs');
|
|
4
|
+
require('./write-l_NzIqyy.cjs');
|
|
5
|
+
const require_logger = require('./logger-BxvJpQMX.cjs');
|
|
6
|
+
const require_transformers = require('./transformers-B3CHtwuB.cjs');
|
|
7
|
+
const require_FileManager = require('./FileManager-DsRjYJa_.cjs');
|
|
8
|
+
const node_path = require_chunk.__toESM(require("node:path"));
|
|
9
|
+
const picocolors = require_chunk.__toESM(require("picocolors"));
|
|
10
|
+
const remeda = require_chunk.__toESM(require("remeda"));
|
|
11
|
+
const node_process = require_chunk.__toESM(require("node:process"));
|
|
12
|
+
const node_module = require_chunk.__toESM(require("node:module"));
|
|
13
|
+
const node_os = require_chunk.__toESM(require("node:os"));
|
|
14
|
+
const node_url = require_chunk.__toESM(require("node:url"));
|
|
15
|
+
const node_fs = require_chunk.__toESM(require("node:fs"));
|
|
16
|
+
const semver = require_chunk.__toESM(require("semver"));
|
|
4
17
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
//#region src/BaseGenerator.ts
|
|
19
|
+
/**
|
|
20
|
+
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
21
|
+
* @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
|
|
22
|
+
*/
|
|
23
|
+
var BaseGenerator = class {
|
|
24
|
+
#options = {};
|
|
25
|
+
#context = {};
|
|
26
|
+
constructor(options, context) {
|
|
27
|
+
if (context) this.#context = context;
|
|
28
|
+
if (options) this.#options = options;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
get options() {
|
|
32
|
+
return this.#options;
|
|
33
|
+
}
|
|
34
|
+
get context() {
|
|
35
|
+
return this.#context;
|
|
36
|
+
}
|
|
37
|
+
set options(options) {
|
|
38
|
+
this.#options = {
|
|
39
|
+
...this.#options,
|
|
40
|
+
...options
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
20
44
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/config.ts
|
|
47
|
+
/**
|
|
48
|
+
* Type helper to make it easier to use vite.config.ts accepts a direct UserConfig object, or a function that returns it. The function receives a ConfigEnv object.
|
|
49
|
+
*/
|
|
50
|
+
function defineConfig(options) {
|
|
51
|
+
return options;
|
|
52
|
+
}
|
|
53
|
+
function isInputPath(result) {
|
|
54
|
+
return !!result && "path" in result?.input;
|
|
55
|
+
}
|
|
27
56
|
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/utils/executeStrategies.ts
|
|
59
|
+
/**
|
|
60
|
+
* Chains promises
|
|
61
|
+
*/
|
|
28
62
|
function hookSeq(promises) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (calledFunc) {
|
|
37
|
-
return calledFunc.then(Array.prototype.concat.bind(state));
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
Promise.resolve([])
|
|
42
|
-
);
|
|
63
|
+
return promises.filter(Boolean).reduce((promise, func) => {
|
|
64
|
+
if (typeof func !== "function") throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
65
|
+
return promise.then((state) => {
|
|
66
|
+
const calledFunc = func(state);
|
|
67
|
+
if (calledFunc) return calledFunc.then(Array.prototype.concat.bind(state));
|
|
68
|
+
});
|
|
69
|
+
}, Promise.resolve([]));
|
|
43
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Chains promises, first non-null result stops and returns
|
|
73
|
+
*/
|
|
44
74
|
function hookFirst(promises, nullCheck = (state) => state !== null) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return func(state);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return promise;
|
|
75
|
+
let promise = Promise.resolve(null);
|
|
76
|
+
for (const func of promises.filter(Boolean)) promise = promise.then((state) => {
|
|
77
|
+
if (nullCheck(state)) return state;
|
|
78
|
+
return func(state);
|
|
79
|
+
});
|
|
80
|
+
return promise;
|
|
55
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Runs an array of promise functions with optional concurrency limit.
|
|
84
|
+
*/
|
|
56
85
|
function hookParallel(promises, concurrency = Number.POSITIVE_INFINITY) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
86
|
+
const limit = require_FileManager.pLimit(concurrency);
|
|
87
|
+
const tasks = promises.filter(Boolean).map((promise) => limit(() => promise()));
|
|
88
|
+
return Promise.allSettled(tasks);
|
|
60
89
|
}
|
|
61
90
|
|
|
62
|
-
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/PromiseManager.ts
|
|
63
93
|
var PromiseManager = class {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
if (strategy === "parallel") {
|
|
77
|
-
return hookParallel(promises, concurrency);
|
|
78
|
-
}
|
|
79
|
-
throw new Error(`${strategy} not implemented`);
|
|
80
|
-
}
|
|
94
|
+
#options = {};
|
|
95
|
+
constructor(options = {}) {
|
|
96
|
+
this.#options = options;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
run(strategy, promises, { concurrency = Number.POSITIVE_INFINITY } = {}) {
|
|
100
|
+
if (strategy === "seq") return hookSeq(promises);
|
|
101
|
+
if (strategy === "first") return hookFirst(promises, this.#options.nullCheck);
|
|
102
|
+
if (strategy === "parallel") return hookParallel(promises, concurrency);
|
|
103
|
+
throw new Error(`${strategy} not implemented`);
|
|
104
|
+
}
|
|
81
105
|
};
|
|
82
106
|
function isPromiseRejectedResult(result) {
|
|
83
|
-
|
|
107
|
+
return result.status === "rejected";
|
|
84
108
|
}
|
|
85
109
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
};
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/errors.ts
|
|
112
|
+
var ValidationPluginError = class extends Error {};
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/plugin.ts
|
|
89
116
|
function createPlugin(factory) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
117
|
+
return (options = {}) => {
|
|
118
|
+
return factory(options);
|
|
119
|
+
};
|
|
93
120
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
};
|
|
121
|
+
const pluginCore = createPlugin((options) => {
|
|
122
|
+
const { fileManager, pluginManager, resolvePath, resolveName, logger } = options;
|
|
123
|
+
return {
|
|
124
|
+
name: "core",
|
|
125
|
+
options,
|
|
126
|
+
key: ["core"],
|
|
127
|
+
context() {
|
|
128
|
+
return {
|
|
129
|
+
get config() {
|
|
130
|
+
return options.config;
|
|
131
|
+
},
|
|
132
|
+
get plugins() {
|
|
133
|
+
return options.getPlugins();
|
|
134
|
+
},
|
|
135
|
+
get plugin() {
|
|
136
|
+
return options.plugin;
|
|
137
|
+
},
|
|
138
|
+
logger,
|
|
139
|
+
fileManager,
|
|
140
|
+
pluginManager,
|
|
141
|
+
async addFile(...files) {
|
|
142
|
+
const resolvedFiles = await fileManager.add(...files);
|
|
143
|
+
if (!Array.isArray(resolvedFiles)) return [resolvedFiles];
|
|
144
|
+
return resolvedFiles;
|
|
145
|
+
},
|
|
146
|
+
resolvePath,
|
|
147
|
+
resolveName
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
resolvePath(baseName) {
|
|
151
|
+
const root = node_path.default.resolve(options.config.root, options.config.output.path);
|
|
152
|
+
return node_path.default.resolve(root, baseName);
|
|
153
|
+
},
|
|
154
|
+
resolveName(name) {
|
|
155
|
+
return name;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
133
158
|
});
|
|
134
159
|
|
|
135
|
-
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/PluginManager.ts
|
|
136
162
|
var PluginManager = class {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
return null;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
#catcher(cause, plugin, hookName) {
|
|
582
|
-
const text = `${cause.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
|
|
583
|
-
this.logger.emit("error", text, cause);
|
|
584
|
-
this.events.emit("error", cause);
|
|
585
|
-
}
|
|
586
|
-
#parse(plugin, pluginManager, context) {
|
|
587
|
-
const usedPluginNames = pluginManager.#usedPluginNames;
|
|
588
|
-
chunkQR7CQIA3_cjs.setUniqueName(plugin.name, usedPluginNames);
|
|
589
|
-
const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
590
|
-
if (plugin.context && typeof plugin.context === "function") {
|
|
591
|
-
return {
|
|
592
|
-
...plugin,
|
|
593
|
-
key,
|
|
594
|
-
context: plugin.context.call(context)
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
return {
|
|
598
|
-
...plugin,
|
|
599
|
-
key
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
static getDependedPlugins(plugins, dependedPluginNames) {
|
|
603
|
-
let pluginNames = [];
|
|
604
|
-
if (typeof dependedPluginNames === "string") {
|
|
605
|
-
pluginNames = [dependedPluginNames];
|
|
606
|
-
} else {
|
|
607
|
-
pluginNames = dependedPluginNames;
|
|
608
|
-
}
|
|
609
|
-
return pluginNames.map((pluginName) => {
|
|
610
|
-
const plugin = plugins.find((plugin2) => plugin2.name === pluginName);
|
|
611
|
-
if (!plugin) {
|
|
612
|
-
throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`);
|
|
613
|
-
}
|
|
614
|
-
return plugin;
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
static get hooks() {
|
|
618
|
-
return ["buildStart", "resolvePath", "resolveName", "buildEnd"];
|
|
619
|
-
}
|
|
163
|
+
plugins = /* @__PURE__ */ new Set();
|
|
164
|
+
fileManager;
|
|
165
|
+
events = new require_logger.EventEmitter();
|
|
166
|
+
config;
|
|
167
|
+
executed = [];
|
|
168
|
+
logger;
|
|
169
|
+
options;
|
|
170
|
+
#core;
|
|
171
|
+
#usedPluginNames = {};
|
|
172
|
+
#promiseManager;
|
|
173
|
+
constructor(config, options) {
|
|
174
|
+
this.config = config;
|
|
175
|
+
this.options = options;
|
|
176
|
+
this.logger = options.logger;
|
|
177
|
+
this.fileManager = new require_FileManager.FileManager();
|
|
178
|
+
this.#promiseManager = new PromiseManager({ nullCheck: (state) => !!state?.result });
|
|
179
|
+
const core = pluginCore({
|
|
180
|
+
config,
|
|
181
|
+
logger: this.logger,
|
|
182
|
+
pluginManager: this,
|
|
183
|
+
fileManager: this.fileManager,
|
|
184
|
+
resolvePath: this.resolvePath.bind(this),
|
|
185
|
+
resolveName: this.resolveName.bind(this),
|
|
186
|
+
getPlugins: this.#getSortedPlugins.bind(this)
|
|
187
|
+
});
|
|
188
|
+
this.#core = this.#parse(core, this, core.context.call(null));
|
|
189
|
+
[this.#core, ...config.plugins || []].forEach((plugin) => {
|
|
190
|
+
const parsedPlugin = this.#parse(plugin, this, this.#core.context);
|
|
191
|
+
this.plugins.add(parsedPlugin);
|
|
192
|
+
});
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
getFile({ name, mode, extname, pluginKey, options }) {
|
|
196
|
+
const baseName = `${name}${extname}`;
|
|
197
|
+
const path$3 = this.resolvePath({
|
|
198
|
+
baseName,
|
|
199
|
+
mode,
|
|
200
|
+
pluginKey,
|
|
201
|
+
options
|
|
202
|
+
});
|
|
203
|
+
if (!path$3) throw new Error(`Filepath should be defined for resolvedName "${name}" and pluginKey [${JSON.stringify(pluginKey)}]`);
|
|
204
|
+
return {
|
|
205
|
+
path: path$3,
|
|
206
|
+
baseName,
|
|
207
|
+
meta: { pluginKey },
|
|
208
|
+
sources: []
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
resolvePath = (params) => {
|
|
212
|
+
if (params.pluginKey) {
|
|
213
|
+
const paths = this.hookForPluginSync({
|
|
214
|
+
pluginKey: params.pluginKey,
|
|
215
|
+
hookName: "resolvePath",
|
|
216
|
+
parameters: [
|
|
217
|
+
params.baseName,
|
|
218
|
+
params.mode,
|
|
219
|
+
params.options
|
|
220
|
+
],
|
|
221
|
+
message: `Resolving path '${params.baseName}'`
|
|
222
|
+
});
|
|
223
|
+
if (paths && paths?.length > 1) this.logger.emit("debug", {
|
|
224
|
+
date: /* @__PURE__ */ new Date(),
|
|
225
|
+
logs: [`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : "\""} is not unique enough\n\nPaths: ${JSON.stringify(paths, void 0, 2)}\n\nFalling back on the first item.\n`]
|
|
226
|
+
});
|
|
227
|
+
return paths?.at(0);
|
|
228
|
+
}
|
|
229
|
+
return this.hookFirstSync({
|
|
230
|
+
hookName: "resolvePath",
|
|
231
|
+
parameters: [
|
|
232
|
+
params.baseName,
|
|
233
|
+
params.mode,
|
|
234
|
+
params.options
|
|
235
|
+
],
|
|
236
|
+
message: `Resolving path '${params.baseName}'`
|
|
237
|
+
}).result;
|
|
238
|
+
};
|
|
239
|
+
resolveName = (params) => {
|
|
240
|
+
if (params.pluginKey) {
|
|
241
|
+
const names = this.hookForPluginSync({
|
|
242
|
+
pluginKey: params.pluginKey,
|
|
243
|
+
hookName: "resolveName",
|
|
244
|
+
parameters: [require_transformers.trim(params.name), params.type],
|
|
245
|
+
message: `Resolving name '${params.name}' and type '${params.type}'`
|
|
246
|
+
});
|
|
247
|
+
if (names && names?.length > 1) this.logger.emit("debug", {
|
|
248
|
+
date: /* @__PURE__ */ new Date(),
|
|
249
|
+
logs: [`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : "\""} is not unique enough\n\nNames: ${JSON.stringify(names, void 0, 2)}\n\nFalling back on the first item.\n`]
|
|
250
|
+
});
|
|
251
|
+
return require_transformers.transformReservedWord(names?.at(0) || params.name);
|
|
252
|
+
}
|
|
253
|
+
const name = this.hookFirstSync({
|
|
254
|
+
hookName: "resolveName",
|
|
255
|
+
parameters: [require_transformers.trim(params.name), params.type],
|
|
256
|
+
message: `Resolving name '${params.name}' and type '${params.type}'`
|
|
257
|
+
}).result;
|
|
258
|
+
return require_transformers.transformReservedWord(name);
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
262
|
+
*/
|
|
263
|
+
on(eventName, handler) {
|
|
264
|
+
this.events.on(eventName, handler);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Run a specific hookName for plugin x.
|
|
268
|
+
*/
|
|
269
|
+
async hookForPlugin({ pluginKey, hookName, parameters, message }) {
|
|
270
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
271
|
+
this.logger.emit("progress_start", {
|
|
272
|
+
id: hookName,
|
|
273
|
+
size: plugins.length,
|
|
274
|
+
message: "Running plugins..."
|
|
275
|
+
});
|
|
276
|
+
const items = [];
|
|
277
|
+
for (const plugin of plugins) {
|
|
278
|
+
const result = await this.#execute({
|
|
279
|
+
strategy: "hookFirst",
|
|
280
|
+
hookName,
|
|
281
|
+
parameters,
|
|
282
|
+
plugin,
|
|
283
|
+
message
|
|
284
|
+
});
|
|
285
|
+
if (result !== void 0 && result !== null) items.push(result);
|
|
286
|
+
}
|
|
287
|
+
this.logger.emit("progress_stop", { id: hookName });
|
|
288
|
+
return items;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Run a specific hookName for plugin x.
|
|
292
|
+
*/
|
|
293
|
+
hookForPluginSync({ pluginKey, hookName, parameters, message }) {
|
|
294
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
295
|
+
const result = plugins.map((plugin) => {
|
|
296
|
+
return this.#executeSync({
|
|
297
|
+
strategy: "hookFirst",
|
|
298
|
+
hookName,
|
|
299
|
+
parameters,
|
|
300
|
+
plugin,
|
|
301
|
+
message
|
|
302
|
+
});
|
|
303
|
+
}).filter(Boolean);
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* First non-null result stops and will return it's value.
|
|
308
|
+
*/
|
|
309
|
+
async hookFirst({ hookName, parameters, skipped, message }) {
|
|
310
|
+
const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
|
|
311
|
+
return skipped ? skipped.has(plugin) : true;
|
|
312
|
+
});
|
|
313
|
+
this.logger.emit("progress_start", {
|
|
314
|
+
id: hookName,
|
|
315
|
+
size: plugins.length
|
|
316
|
+
});
|
|
317
|
+
const promises = plugins.map((plugin) => {
|
|
318
|
+
return async () => {
|
|
319
|
+
const value = await this.#execute({
|
|
320
|
+
strategy: "hookFirst",
|
|
321
|
+
hookName,
|
|
322
|
+
parameters,
|
|
323
|
+
plugin,
|
|
324
|
+
message
|
|
325
|
+
});
|
|
326
|
+
return Promise.resolve({
|
|
327
|
+
plugin,
|
|
328
|
+
result: value
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
});
|
|
332
|
+
const result = await this.#promiseManager.run("first", promises);
|
|
333
|
+
this.logger.emit("progress_stop", { id: hookName });
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* First non-null result stops and will return it's value.
|
|
338
|
+
*/
|
|
339
|
+
hookFirstSync({ hookName, parameters, skipped, message }) {
|
|
340
|
+
let parseResult = null;
|
|
341
|
+
const plugins = this.#getSortedPlugins(hookName).filter((plugin) => {
|
|
342
|
+
return skipped ? skipped.has(plugin) : true;
|
|
343
|
+
});
|
|
344
|
+
for (const plugin of plugins) {
|
|
345
|
+
parseResult = {
|
|
346
|
+
result: this.#executeSync({
|
|
347
|
+
strategy: "hookFirst",
|
|
348
|
+
hookName,
|
|
349
|
+
parameters,
|
|
350
|
+
plugin,
|
|
351
|
+
message
|
|
352
|
+
}),
|
|
353
|
+
plugin
|
|
354
|
+
};
|
|
355
|
+
if (parseResult?.result != null) break;
|
|
356
|
+
}
|
|
357
|
+
return parseResult;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
|
|
361
|
+
*/
|
|
362
|
+
async hookParallel({ hookName, parameters, message }) {
|
|
363
|
+
const plugins = this.#getSortedPlugins(hookName);
|
|
364
|
+
this.logger.emit("progress_start", {
|
|
365
|
+
id: hookName,
|
|
366
|
+
size: plugins.length
|
|
367
|
+
});
|
|
368
|
+
const promises = plugins.map((plugin) => {
|
|
369
|
+
return () => this.#execute({
|
|
370
|
+
strategy: "hookParallel",
|
|
371
|
+
hookName,
|
|
372
|
+
parameters,
|
|
373
|
+
plugin,
|
|
374
|
+
message
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
const results = await this.#promiseManager.run("parallel", promises, { concurrency: this.options.concurrency });
|
|
378
|
+
results.forEach((result, index) => {
|
|
379
|
+
if (isPromiseRejectedResult(result)) {
|
|
380
|
+
const plugin = this.#getSortedPlugins(hookName)[index];
|
|
381
|
+
this.#catcher(result.reason, plugin, hookName);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
this.logger.emit("progress_stop", { id: hookName });
|
|
385
|
+
return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Chains plugins
|
|
389
|
+
*/
|
|
390
|
+
async hookSeq({ hookName, parameters, message }) {
|
|
391
|
+
const plugins = this.#getSortedPlugins(hookName);
|
|
392
|
+
this.logger.emit("progress_start", {
|
|
393
|
+
id: hookName,
|
|
394
|
+
size: plugins.length
|
|
395
|
+
});
|
|
396
|
+
const promises = plugins.map((plugin) => {
|
|
397
|
+
return () => this.#execute({
|
|
398
|
+
strategy: "hookSeq",
|
|
399
|
+
hookName,
|
|
400
|
+
parameters,
|
|
401
|
+
plugin,
|
|
402
|
+
message
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
await this.#promiseManager.run("seq", promises);
|
|
406
|
+
this.logger.emit("progress_stop", { id: hookName });
|
|
407
|
+
}
|
|
408
|
+
#getSortedPlugins(hookName) {
|
|
409
|
+
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
410
|
+
if (hookName) return plugins.filter((plugin) => hookName in plugin);
|
|
411
|
+
return plugins.map((plugin) => {
|
|
412
|
+
if (plugin.pre) {
|
|
413
|
+
const isValid = plugin.pre.every((pluginName) => plugins.find((pluginToFind) => pluginToFind.name === pluginName));
|
|
414
|
+
if (!isValid) throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, void 0, 2)})`);
|
|
415
|
+
}
|
|
416
|
+
return plugin;
|
|
417
|
+
}).sort((a, b) => {
|
|
418
|
+
if (b.pre?.includes(a.name)) return 1;
|
|
419
|
+
if (b.post?.includes(a.name)) return -1;
|
|
420
|
+
return 0;
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
getPluginByKey(pluginKey) {
|
|
424
|
+
const plugins = [...this.plugins];
|
|
425
|
+
const [searchPluginName] = pluginKey;
|
|
426
|
+
return plugins.find((item) => {
|
|
427
|
+
const [name] = item.key;
|
|
428
|
+
return name === searchPluginName;
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
getPluginsByKey(hookName, pluginKey) {
|
|
432
|
+
const plugins = [...this.plugins];
|
|
433
|
+
const [searchPluginName, searchIdentifier] = pluginKey;
|
|
434
|
+
const pluginByPluginName = plugins.filter((plugin) => hookName in plugin).filter((item) => {
|
|
435
|
+
const [name, identifier] = item.key;
|
|
436
|
+
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
437
|
+
const nameCheck = name === searchPluginName;
|
|
438
|
+
if (searchIdentifier) return identifierCheck && nameCheck;
|
|
439
|
+
return nameCheck;
|
|
440
|
+
});
|
|
441
|
+
if (!pluginByPluginName?.length) {
|
|
442
|
+
const corePlugin = plugins.find((plugin) => plugin.name === "core" && hookName in plugin);
|
|
443
|
+
if (corePlugin) this.logger.emit("debug", {
|
|
444
|
+
date: /* @__PURE__ */ new Date(),
|
|
445
|
+
logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`]
|
|
446
|
+
});
|
|
447
|
+
else this.logger.emit("debug", {
|
|
448
|
+
date: /* @__PURE__ */ new Date(),
|
|
449
|
+
logs: [`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`]
|
|
450
|
+
});
|
|
451
|
+
return corePlugin ? [corePlugin] : [];
|
|
452
|
+
}
|
|
453
|
+
return pluginByPluginName;
|
|
454
|
+
}
|
|
455
|
+
#addExecutedToCallStack(executer) {
|
|
456
|
+
if (executer) {
|
|
457
|
+
this.events.emit("executed", executer);
|
|
458
|
+
this.executed.push(executer);
|
|
459
|
+
this.logger.emit("progressed", {
|
|
460
|
+
id: executer.hookName,
|
|
461
|
+
message: `${executer.plugin.name}: ${executer.message}`
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Run an async plugin hook and return the result.
|
|
467
|
+
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
468
|
+
* @param args Arguments passed to the plugin hook.
|
|
469
|
+
* @param plugin The actual pluginObject to run.
|
|
470
|
+
*/
|
|
471
|
+
#execute({ strategy, hookName, parameters, plugin, message }) {
|
|
472
|
+
const hook = plugin[hookName];
|
|
473
|
+
let output;
|
|
474
|
+
if (!hook) return null;
|
|
475
|
+
this.events.emit("executing", {
|
|
476
|
+
strategy,
|
|
477
|
+
hookName,
|
|
478
|
+
parameters,
|
|
479
|
+
plugin,
|
|
480
|
+
message
|
|
481
|
+
});
|
|
482
|
+
const task = (async () => {
|
|
483
|
+
try {
|
|
484
|
+
if (typeof hook === "function") {
|
|
485
|
+
const result = await Promise.resolve(hook.apply({
|
|
486
|
+
...this.#core.context,
|
|
487
|
+
plugin
|
|
488
|
+
}, parameters));
|
|
489
|
+
output = result;
|
|
490
|
+
this.#addExecutedToCallStack({
|
|
491
|
+
parameters,
|
|
492
|
+
output,
|
|
493
|
+
strategy,
|
|
494
|
+
hookName,
|
|
495
|
+
plugin,
|
|
496
|
+
message
|
|
497
|
+
});
|
|
498
|
+
return result;
|
|
499
|
+
}
|
|
500
|
+
output = hook;
|
|
501
|
+
this.#addExecutedToCallStack({
|
|
502
|
+
parameters,
|
|
503
|
+
output,
|
|
504
|
+
strategy,
|
|
505
|
+
hookName,
|
|
506
|
+
plugin,
|
|
507
|
+
message
|
|
508
|
+
});
|
|
509
|
+
return hook;
|
|
510
|
+
} catch (e) {
|
|
511
|
+
this.#catcher(e, plugin, hookName);
|
|
512
|
+
return null;
|
|
513
|
+
}
|
|
514
|
+
})();
|
|
515
|
+
return task;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Run a sync plugin hook and return the result.
|
|
519
|
+
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
520
|
+
* @param args Arguments passed to the plugin hook.
|
|
521
|
+
* @param plugin The acutal plugin
|
|
522
|
+
* @param replaceContext When passed, the plugin context can be overridden.
|
|
523
|
+
*/
|
|
524
|
+
#executeSync({ strategy, hookName, parameters, plugin, message }) {
|
|
525
|
+
const hook = plugin[hookName];
|
|
526
|
+
let output;
|
|
527
|
+
if (!hook) return null;
|
|
528
|
+
this.events.emit("executing", {
|
|
529
|
+
strategy,
|
|
530
|
+
hookName,
|
|
531
|
+
parameters,
|
|
532
|
+
plugin,
|
|
533
|
+
message
|
|
534
|
+
});
|
|
535
|
+
try {
|
|
536
|
+
if (typeof hook === "function") {
|
|
537
|
+
const fn = hook.apply({
|
|
538
|
+
...this.#core.context,
|
|
539
|
+
plugin
|
|
540
|
+
}, parameters);
|
|
541
|
+
output = fn;
|
|
542
|
+
this.#addExecutedToCallStack({
|
|
543
|
+
parameters,
|
|
544
|
+
output,
|
|
545
|
+
strategy,
|
|
546
|
+
hookName,
|
|
547
|
+
plugin,
|
|
548
|
+
message
|
|
549
|
+
});
|
|
550
|
+
return fn;
|
|
551
|
+
}
|
|
552
|
+
output = hook;
|
|
553
|
+
this.#addExecutedToCallStack({
|
|
554
|
+
parameters,
|
|
555
|
+
output,
|
|
556
|
+
strategy,
|
|
557
|
+
hookName,
|
|
558
|
+
plugin,
|
|
559
|
+
message
|
|
560
|
+
});
|
|
561
|
+
return hook;
|
|
562
|
+
} catch (e) {
|
|
563
|
+
this.#catcher(e, plugin, hookName);
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
#catcher(cause, plugin, hookName) {
|
|
568
|
+
const text = `${cause.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})`;
|
|
569
|
+
this.logger.emit("error", text, cause);
|
|
570
|
+
this.events.emit("error", cause);
|
|
571
|
+
}
|
|
572
|
+
#parse(plugin, pluginManager, context) {
|
|
573
|
+
const usedPluginNames = pluginManager.#usedPluginNames;
|
|
574
|
+
require_FileManager.setUniqueName(plugin.name, usedPluginNames);
|
|
575
|
+
const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
576
|
+
if (plugin.context && typeof plugin.context === "function") return {
|
|
577
|
+
...plugin,
|
|
578
|
+
key,
|
|
579
|
+
context: plugin.context.call(context)
|
|
580
|
+
};
|
|
581
|
+
return {
|
|
582
|
+
...plugin,
|
|
583
|
+
key
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
static getDependedPlugins(plugins, dependedPluginNames) {
|
|
587
|
+
let pluginNames = [];
|
|
588
|
+
if (typeof dependedPluginNames === "string") pluginNames = [dependedPluginNames];
|
|
589
|
+
else pluginNames = dependedPluginNames;
|
|
590
|
+
return pluginNames.map((pluginName) => {
|
|
591
|
+
const plugin = plugins.find((plugin$1) => plugin$1.name === pluginName);
|
|
592
|
+
if (!plugin) throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`);
|
|
593
|
+
return plugin;
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
static get hooks() {
|
|
597
|
+
return [
|
|
598
|
+
"buildStart",
|
|
599
|
+
"resolvePath",
|
|
600
|
+
"resolveName",
|
|
601
|
+
"buildEnd"
|
|
602
|
+
];
|
|
603
|
+
}
|
|
620
604
|
};
|
|
621
605
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
return options;
|
|
625
|
-
}
|
|
626
|
-
function isInputPath(result) {
|
|
627
|
-
return !!result && "path" in result?.input;
|
|
628
|
-
}
|
|
606
|
+
//#endregion
|
|
607
|
+
//#region src/build.ts
|
|
629
608
|
async function setup(options) {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
".ts": ".ts"
|
|
659
|
-
},
|
|
660
|
-
defaultBanner: "simple",
|
|
661
|
-
...userConfig.output
|
|
662
|
-
},
|
|
663
|
-
plugins: userConfig.plugins
|
|
664
|
-
};
|
|
665
|
-
if (definedConfig.output.clean) {
|
|
666
|
-
await chunkE4XLCCPK_cjs.clean(definedConfig.output.path);
|
|
667
|
-
await chunkE4XLCCPK_cjs.clean(path3.join(definedConfig.root, ".kubb"));
|
|
668
|
-
}
|
|
669
|
-
return new PluginManager(definedConfig, { logger, concurrency: 5 });
|
|
609
|
+
if (options.pluginManager) return options.pluginManager;
|
|
610
|
+
const { config: userConfig, logger = require_logger.createLogger() } = options;
|
|
611
|
+
if (Array.isArray(userConfig.input)) console.warn(picocolors.default.yellow("This feature is still under development — use with caution"));
|
|
612
|
+
try {
|
|
613
|
+
if (isInputPath(userConfig) && !new require_FileManager.URLPath(userConfig.input.path).isURL) await require_fs.exists(userConfig.input.path);
|
|
614
|
+
} catch (e) {
|
|
615
|
+
if (isInputPath(userConfig)) throw new Error(`Cannot read file/URL defined in \`input.path\` or set with \`kubb generate PATH\` in the CLI of your Kubb config ${userConfig.input.path}`, { cause: e });
|
|
616
|
+
}
|
|
617
|
+
const definedConfig = {
|
|
618
|
+
root: userConfig.root || process.cwd(),
|
|
619
|
+
...userConfig,
|
|
620
|
+
output: {
|
|
621
|
+
write: true,
|
|
622
|
+
barrelType: "named",
|
|
623
|
+
extension: { ".ts": ".ts" },
|
|
624
|
+
defaultBanner: "simple",
|
|
625
|
+
...userConfig.output
|
|
626
|
+
},
|
|
627
|
+
plugins: userConfig.plugins
|
|
628
|
+
};
|
|
629
|
+
if (definedConfig.output.clean) {
|
|
630
|
+
await require_fs.clean(definedConfig.output.path);
|
|
631
|
+
await require_fs.clean((0, node_path.join)(definedConfig.root, ".kubb"));
|
|
632
|
+
}
|
|
633
|
+
return new PluginManager(definedConfig, {
|
|
634
|
+
logger,
|
|
635
|
+
concurrency: 5
|
|
636
|
+
});
|
|
670
637
|
}
|
|
671
638
|
async function build(options) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
639
|
+
const { files, pluginManager, error } = await safeBuild(options);
|
|
640
|
+
if (error) throw error;
|
|
641
|
+
return {
|
|
642
|
+
files,
|
|
643
|
+
pluginManager,
|
|
644
|
+
error
|
|
645
|
+
};
|
|
679
646
|
}
|
|
680
647
|
async function safeBuild(options) {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
648
|
+
const pluginManager = await setup(options);
|
|
649
|
+
const config = pluginManager.config;
|
|
650
|
+
try {
|
|
651
|
+
pluginManager.events.on("executing", ({ plugin, message }) => {
|
|
652
|
+
pluginManager.logger.emit("debug", {
|
|
653
|
+
date: /* @__PURE__ */ new Date(),
|
|
654
|
+
logs: [`Executing pluginKey ${plugin.key?.join(".")} | ${message}`]
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
pluginManager.events.on("executed", ({ plugin, message, output }) => {
|
|
658
|
+
pluginManager.logger.emit("debug", {
|
|
659
|
+
date: /* @__PURE__ */ new Date(),
|
|
660
|
+
logs: [`Executed pluginKey ${plugin.key?.join(".")} | ${message} | ${JSON.stringify(output, void 0, 2)}`]
|
|
661
|
+
});
|
|
662
|
+
});
|
|
663
|
+
await pluginManager.hookParallel({
|
|
664
|
+
hookName: "buildStart",
|
|
665
|
+
parameters: [config],
|
|
666
|
+
message: "buildStart"
|
|
667
|
+
});
|
|
668
|
+
if (config.output.barrelType) {
|
|
669
|
+
const root = (0, node_path.resolve)(config.root);
|
|
670
|
+
const rootPath = (0, node_path.resolve)(root, config.output.path, "index.ts");
|
|
671
|
+
const files$1 = await pluginManager.fileManager.getFiles();
|
|
672
|
+
const barrelFiles = files$1.filter((file) => {
|
|
673
|
+
return file.sources.some((source) => source.isIndexable);
|
|
674
|
+
});
|
|
675
|
+
const rootFile = {
|
|
676
|
+
path: rootPath,
|
|
677
|
+
baseName: "index.ts",
|
|
678
|
+
exports: barrelFiles.flatMap((file) => {
|
|
679
|
+
const containsOnlyTypes = file.sources?.every((source) => source.isTypeOnly);
|
|
680
|
+
return file.sources?.map((source) => {
|
|
681
|
+
if (!file.path || !source.isIndexable) return void 0;
|
|
682
|
+
const plugin = [...pluginManager.plugins].find((item) => {
|
|
683
|
+
const meta = file.meta;
|
|
684
|
+
return (0, remeda.isDeepEqual)(item.key, meta?.pluginKey);
|
|
685
|
+
});
|
|
686
|
+
const pluginOptions = plugin?.options;
|
|
687
|
+
if (!pluginOptions || pluginOptions?.output?.barrelType === false) return void 0;
|
|
688
|
+
return {
|
|
689
|
+
name: config.output.barrelType === "all" ? void 0 : [source.name],
|
|
690
|
+
path: require_fs.getRelativePath(rootPath, file.path),
|
|
691
|
+
isTypeOnly: config.output.barrelType === "all" ? containsOnlyTypes : source.isTypeOnly
|
|
692
|
+
};
|
|
693
|
+
}).filter(Boolean);
|
|
694
|
+
}).filter(Boolean),
|
|
695
|
+
sources: [],
|
|
696
|
+
meta: {}
|
|
697
|
+
};
|
|
698
|
+
await pluginManager.fileManager.add(rootFile);
|
|
699
|
+
}
|
|
700
|
+
const files = await pluginManager.fileManager.processFiles({
|
|
701
|
+
root: config.root,
|
|
702
|
+
extension: config.output.extension,
|
|
703
|
+
dryRun: !config.output.write,
|
|
704
|
+
logger: pluginManager.logger
|
|
705
|
+
});
|
|
706
|
+
await pluginManager.hookParallel({
|
|
707
|
+
hookName: "buildEnd",
|
|
708
|
+
message: `Build stopped for ${config.name}`
|
|
709
|
+
});
|
|
710
|
+
await pluginManager.fileManager.clear();
|
|
711
|
+
return {
|
|
712
|
+
files,
|
|
713
|
+
pluginManager
|
|
714
|
+
};
|
|
715
|
+
} catch (e) {
|
|
716
|
+
return {
|
|
717
|
+
files: [],
|
|
718
|
+
pluginManager,
|
|
719
|
+
error: e
|
|
720
|
+
};
|
|
721
|
+
}
|
|
753
722
|
}
|
|
754
723
|
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region ../../node_modules/.pnpm/yocto-queue@1.1.1/node_modules/yocto-queue/index.js
|
|
726
|
+
var Node = class {
|
|
727
|
+
value;
|
|
728
|
+
next;
|
|
729
|
+
constructor(value) {
|
|
730
|
+
this.value = value;
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
var Queue = class {
|
|
734
|
+
#head;
|
|
735
|
+
#tail;
|
|
736
|
+
#size;
|
|
737
|
+
constructor() {
|
|
738
|
+
this.clear();
|
|
739
|
+
}
|
|
740
|
+
enqueue(value) {
|
|
741
|
+
const node = new Node(value);
|
|
742
|
+
if (this.#head) {
|
|
743
|
+
this.#tail.next = node;
|
|
744
|
+
this.#tail = node;
|
|
745
|
+
} else {
|
|
746
|
+
this.#head = node;
|
|
747
|
+
this.#tail = node;
|
|
748
|
+
}
|
|
749
|
+
this.#size++;
|
|
750
|
+
}
|
|
751
|
+
dequeue() {
|
|
752
|
+
const current = this.#head;
|
|
753
|
+
if (!current) return;
|
|
754
|
+
this.#head = this.#head.next;
|
|
755
|
+
this.#size--;
|
|
756
|
+
return current.value;
|
|
757
|
+
}
|
|
758
|
+
peek() {
|
|
759
|
+
if (!this.#head) return;
|
|
760
|
+
return this.#head.value;
|
|
761
|
+
}
|
|
762
|
+
clear() {
|
|
763
|
+
this.#head = void 0;
|
|
764
|
+
this.#tail = void 0;
|
|
765
|
+
this.#size = 0;
|
|
766
|
+
}
|
|
767
|
+
get size() {
|
|
768
|
+
return this.#size;
|
|
769
|
+
}
|
|
770
|
+
*[Symbol.iterator]() {
|
|
771
|
+
let current = this.#head;
|
|
772
|
+
while (current) {
|
|
773
|
+
yield current.value;
|
|
774
|
+
current = current.next;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
777
|
};
|
|
778
|
+
|
|
779
|
+
//#endregion
|
|
780
|
+
//#region ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
|
|
781
|
+
function pLimit$1(concurrency) {
|
|
782
|
+
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
783
|
+
const queue = new Queue();
|
|
784
|
+
let activeCount = 0;
|
|
785
|
+
const next = () => {
|
|
786
|
+
activeCount--;
|
|
787
|
+
if (queue.size > 0) queue.dequeue()();
|
|
788
|
+
};
|
|
789
|
+
const run = async (fn, resolve$1, args) => {
|
|
790
|
+
activeCount++;
|
|
791
|
+
const result = (async () => fn(...args))();
|
|
792
|
+
resolve$1(result);
|
|
793
|
+
try {
|
|
794
|
+
await result;
|
|
795
|
+
} catch {}
|
|
796
|
+
next();
|
|
797
|
+
};
|
|
798
|
+
const enqueue = (fn, resolve$1, args) => {
|
|
799
|
+
queue.enqueue(run.bind(void 0, fn, resolve$1, args));
|
|
800
|
+
(async () => {
|
|
801
|
+
await Promise.resolve();
|
|
802
|
+
if (activeCount < concurrency && queue.size > 0) queue.dequeue()();
|
|
803
|
+
})();
|
|
804
|
+
};
|
|
805
|
+
const generator = (fn, ...args) => new Promise((resolve$1) => {
|
|
806
|
+
enqueue(fn, resolve$1, args);
|
|
807
|
+
});
|
|
808
|
+
Object.defineProperties(generator, {
|
|
809
|
+
activeCount: { get: () => activeCount },
|
|
810
|
+
pendingCount: { get: () => queue.size },
|
|
811
|
+
clearQueue: { value: () => {
|
|
812
|
+
queue.clear();
|
|
813
|
+
} }
|
|
814
|
+
});
|
|
815
|
+
return generator;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
//#endregion
|
|
819
|
+
//#region ../../node_modules/.pnpm/p-locate@6.0.0/node_modules/p-locate/index.js
|
|
778
820
|
var EndError = class extends Error {
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
821
|
+
constructor(value) {
|
|
822
|
+
super();
|
|
823
|
+
this.value = value;
|
|
824
|
+
}
|
|
783
825
|
};
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
}
|
|
790
|
-
return false;
|
|
826
|
+
const testElement = async (element, tester) => tester(await element);
|
|
827
|
+
const finder = async (element) => {
|
|
828
|
+
const values = await Promise.all(element);
|
|
829
|
+
if (values[1] === true) throw new EndError(values[0]);
|
|
830
|
+
return false;
|
|
791
831
|
};
|
|
792
|
-
async function pLocate(iterable, tester, {
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
if (error instanceof EndError) {
|
|
803
|
-
return error.value;
|
|
804
|
-
}
|
|
805
|
-
throw error;
|
|
806
|
-
}
|
|
832
|
+
async function pLocate(iterable, tester, { concurrency = Number.POSITIVE_INFINITY, preserveOrder = true } = {}) {
|
|
833
|
+
const limit = pLimit$1(concurrency);
|
|
834
|
+
const items = [...iterable].map((element) => [element, limit(testElement, element, tester)]);
|
|
835
|
+
const checkLimit = pLimit$1(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
|
|
836
|
+
try {
|
|
837
|
+
await Promise.all(items.map((element) => checkLimit(finder, element)));
|
|
838
|
+
} catch (error) {
|
|
839
|
+
if (error instanceof EndError) return error.value;
|
|
840
|
+
throw error;
|
|
841
|
+
}
|
|
807
842
|
}
|
|
808
843
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
844
|
+
//#endregion
|
|
845
|
+
//#region ../../node_modules/.pnpm/locate-path@7.2.0/node_modules/locate-path/index.js
|
|
846
|
+
const typeMappings = {
|
|
847
|
+
directory: "isDirectory",
|
|
848
|
+
file: "isFile"
|
|
813
849
|
};
|
|
814
850
|
function checkType(type) {
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
}
|
|
818
|
-
throw new Error(`Invalid type specified: ${type}`);
|
|
851
|
+
if (Object.hasOwnProperty.call(typeMappings, type)) return;
|
|
852
|
+
throw new Error(`Invalid type specified: ${type}`);
|
|
819
853
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
async function locatePath(paths, {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
return false;
|
|
838
|
-
}
|
|
839
|
-
}, { concurrency, preserveOrder });
|
|
854
|
+
const matchType = (type, stat) => stat[typeMappings[type]]();
|
|
855
|
+
const toPath$1 = (urlOrPath) => urlOrPath instanceof URL ? (0, node_url.fileURLToPath)(urlOrPath) : urlOrPath;
|
|
856
|
+
async function locatePath(paths, { cwd = node_process.default.cwd(), type = "file", allowSymlinks = true, concurrency, preserveOrder } = {}) {
|
|
857
|
+
checkType(type);
|
|
858
|
+
cwd = toPath$1(cwd);
|
|
859
|
+
const statFunction = allowSymlinks ? node_fs.promises.stat : node_fs.promises.lstat;
|
|
860
|
+
return pLocate(paths, async (path_) => {
|
|
861
|
+
try {
|
|
862
|
+
const stat = await statFunction(node_path.default.resolve(cwd, path_));
|
|
863
|
+
return matchType(type, stat);
|
|
864
|
+
} catch {
|
|
865
|
+
return false;
|
|
866
|
+
}
|
|
867
|
+
}, {
|
|
868
|
+
concurrency,
|
|
869
|
+
preserveOrder
|
|
870
|
+
});
|
|
840
871
|
}
|
|
841
|
-
function locatePathSync(paths, {
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
try {
|
|
851
|
-
const stat = statFunction(path3__default.default.resolve(cwd, path_), {
|
|
852
|
-
throwIfNoEntry: false
|
|
853
|
-
});
|
|
854
|
-
if (!stat) {
|
|
855
|
-
continue;
|
|
856
|
-
}
|
|
857
|
-
if (matchType(type, stat)) {
|
|
858
|
-
return path_;
|
|
859
|
-
}
|
|
860
|
-
} catch {
|
|
861
|
-
}
|
|
862
|
-
}
|
|
872
|
+
function locatePathSync(paths, { cwd = node_process.default.cwd(), type = "file", allowSymlinks = true } = {}) {
|
|
873
|
+
checkType(type);
|
|
874
|
+
cwd = toPath$1(cwd);
|
|
875
|
+
const statFunction = allowSymlinks ? node_fs.default.statSync : node_fs.default.lstatSync;
|
|
876
|
+
for (const path_ of paths) try {
|
|
877
|
+
const stat = statFunction(node_path.default.resolve(cwd, path_), { throwIfNoEntry: false });
|
|
878
|
+
if (!stat) continue;
|
|
879
|
+
if (matchType(type, stat)) return path_;
|
|
880
|
+
} catch {}
|
|
863
881
|
}
|
|
864
|
-
|
|
865
|
-
|
|
882
|
+
|
|
883
|
+
//#endregion
|
|
884
|
+
//#region ../../node_modules/.pnpm/unicorn-magic@0.1.0/node_modules/unicorn-magic/node.js
|
|
885
|
+
function toPath(urlOrPath) {
|
|
886
|
+
return urlOrPath instanceof URL ? (0, node_url.fileURLToPath)(urlOrPath) : urlOrPath;
|
|
866
887
|
}
|
|
867
888
|
|
|
868
|
-
|
|
869
|
-
|
|
889
|
+
//#endregion
|
|
890
|
+
//#region ../../node_modules/.pnpm/find-up@7.0.0/node_modules/find-up/index.js
|
|
891
|
+
const findUpStop = Symbol("findUpStop");
|
|
870
892
|
async function findUpMultiple(name, options = {}) {
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
}
|
|
895
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
896
|
-
break;
|
|
897
|
-
}
|
|
898
|
-
directory = path3__default.default.dirname(directory);
|
|
899
|
-
}
|
|
900
|
-
return matches;
|
|
893
|
+
let directory = node_path.default.resolve(toPath(options.cwd) ?? "");
|
|
894
|
+
const { root } = node_path.default.parse(directory);
|
|
895
|
+
const stopAt = node_path.default.resolve(directory, toPath(options.stopAt ?? root));
|
|
896
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
897
|
+
const paths = [name].flat();
|
|
898
|
+
const runMatcher = async (locateOptions) => {
|
|
899
|
+
if (typeof name !== "function") return locatePath(paths, locateOptions);
|
|
900
|
+
const foundPath = await name(locateOptions.cwd);
|
|
901
|
+
if (typeof foundPath === "string") return locatePath([foundPath], locateOptions);
|
|
902
|
+
return foundPath;
|
|
903
|
+
};
|
|
904
|
+
const matches = [];
|
|
905
|
+
while (true) {
|
|
906
|
+
const foundPath = await runMatcher({
|
|
907
|
+
...options,
|
|
908
|
+
cwd: directory
|
|
909
|
+
});
|
|
910
|
+
if (foundPath === findUpStop) break;
|
|
911
|
+
if (foundPath) matches.push(node_path.default.resolve(directory, foundPath));
|
|
912
|
+
if (directory === stopAt || matches.length >= limit) break;
|
|
913
|
+
directory = node_path.default.dirname(directory);
|
|
914
|
+
}
|
|
915
|
+
return matches;
|
|
901
916
|
}
|
|
902
917
|
function findUpMultipleSync(name, options = {}) {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
}
|
|
927
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
928
|
-
break;
|
|
929
|
-
}
|
|
930
|
-
directory = path3__default.default.dirname(directory);
|
|
931
|
-
}
|
|
932
|
-
return matches;
|
|
918
|
+
let directory = node_path.default.resolve(toPath(options.cwd) ?? "");
|
|
919
|
+
const { root } = node_path.default.parse(directory);
|
|
920
|
+
const stopAt = node_path.default.resolve(directory, toPath(options.stopAt) ?? root);
|
|
921
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
922
|
+
const paths = [name].flat();
|
|
923
|
+
const runMatcher = (locateOptions) => {
|
|
924
|
+
if (typeof name !== "function") return locatePathSync(paths, locateOptions);
|
|
925
|
+
const foundPath = name(locateOptions.cwd);
|
|
926
|
+
if (typeof foundPath === "string") return locatePathSync([foundPath], locateOptions);
|
|
927
|
+
return foundPath;
|
|
928
|
+
};
|
|
929
|
+
const matches = [];
|
|
930
|
+
while (true) {
|
|
931
|
+
const foundPath = runMatcher({
|
|
932
|
+
...options,
|
|
933
|
+
cwd: directory
|
|
934
|
+
});
|
|
935
|
+
if (foundPath === findUpStop) break;
|
|
936
|
+
if (foundPath) matches.push(node_path.default.resolve(directory, foundPath));
|
|
937
|
+
if (directory === stopAt || matches.length >= limit) break;
|
|
938
|
+
directory = node_path.default.dirname(directory);
|
|
939
|
+
}
|
|
940
|
+
return matches;
|
|
933
941
|
}
|
|
934
942
|
async function findUp(name, options = {}) {
|
|
935
|
-
|
|
936
|
-
|
|
943
|
+
const matches = await findUpMultiple(name, {
|
|
944
|
+
...options,
|
|
945
|
+
limit: 1
|
|
946
|
+
});
|
|
947
|
+
return matches[0];
|
|
937
948
|
}
|
|
938
949
|
function findUpSync(name, options = {}) {
|
|
939
|
-
|
|
940
|
-
|
|
950
|
+
const matches = findUpMultipleSync(name, {
|
|
951
|
+
...options,
|
|
952
|
+
limit: 1
|
|
953
|
+
});
|
|
954
|
+
return matches[0];
|
|
941
955
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
if (!packageJSON) {
|
|
1035
|
-
return void 0;
|
|
1036
|
-
}
|
|
1037
|
-
return this.#match(packageJSON, dependency);
|
|
1038
|
-
}
|
|
1039
|
-
async isValid(dependency, version) {
|
|
1040
|
-
const packageVersion = await this.getVersion(dependency);
|
|
1041
|
-
if (!packageVersion) {
|
|
1042
|
-
return false;
|
|
1043
|
-
}
|
|
1044
|
-
if (packageVersion === version) {
|
|
1045
|
-
return true;
|
|
1046
|
-
}
|
|
1047
|
-
const semVer = semver.coerce(packageVersion);
|
|
1048
|
-
if (!semVer) {
|
|
1049
|
-
throw new Error(`${packageVersion} is not valid`);
|
|
1050
|
-
}
|
|
1051
|
-
return semver.satisfies(semVer, version);
|
|
1052
|
-
}
|
|
1053
|
-
isValidSync(dependency, version) {
|
|
1054
|
-
const packageVersion = this.getVersionSync(dependency);
|
|
1055
|
-
if (!packageVersion) {
|
|
1056
|
-
return false;
|
|
1057
|
-
}
|
|
1058
|
-
if (version === "next" && packageVersion === version) {
|
|
1059
|
-
return true;
|
|
1060
|
-
}
|
|
1061
|
-
const semVer = semver.coerce(packageVersion);
|
|
1062
|
-
if (!semVer) {
|
|
1063
|
-
return false;
|
|
1064
|
-
}
|
|
1065
|
-
return semver.satisfies(semVer, version);
|
|
1066
|
-
}
|
|
956
|
+
|
|
957
|
+
//#endregion
|
|
958
|
+
//#region src/PackageManager.ts
|
|
959
|
+
var PackageManager = class PackageManager {
|
|
960
|
+
static #cache = {};
|
|
961
|
+
#cwd;
|
|
962
|
+
#SLASHES = new Set(["/", "\\"]);
|
|
963
|
+
constructor(workspace) {
|
|
964
|
+
if (workspace) this.#cwd = workspace;
|
|
965
|
+
return this;
|
|
966
|
+
}
|
|
967
|
+
set workspace(workspace) {
|
|
968
|
+
this.#cwd = workspace;
|
|
969
|
+
}
|
|
970
|
+
get workspace() {
|
|
971
|
+
return this.#cwd;
|
|
972
|
+
}
|
|
973
|
+
normalizeDirectory(directory) {
|
|
974
|
+
if (!this.#SLASHES.has(directory[directory.length - 1])) return `${directory}/`;
|
|
975
|
+
return directory;
|
|
976
|
+
}
|
|
977
|
+
getLocation(path$3) {
|
|
978
|
+
let location = path$3;
|
|
979
|
+
if (this.#cwd) {
|
|
980
|
+
const require$1 = node_module.default.createRequire(this.normalizeDirectory(this.#cwd));
|
|
981
|
+
location = require$1.resolve(path$3);
|
|
982
|
+
}
|
|
983
|
+
return location;
|
|
984
|
+
}
|
|
985
|
+
async import(path$3) {
|
|
986
|
+
try {
|
|
987
|
+
let location = this.getLocation(path$3);
|
|
988
|
+
if (node_os.default.platform() === "win32") location = (0, node_url.pathToFileURL)(location).href;
|
|
989
|
+
const module$1 = await import(location);
|
|
990
|
+
return module$1?.default ?? module$1;
|
|
991
|
+
} catch (e) {
|
|
992
|
+
console.error(e);
|
|
993
|
+
return void 0;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
async getPackageJSON() {
|
|
997
|
+
const pkgPath = await findUp(["package.json"], { cwd: this.#cwd });
|
|
998
|
+
if (!pkgPath) return void 0;
|
|
999
|
+
const json = await require_fs.read(pkgPath);
|
|
1000
|
+
return JSON.parse(json);
|
|
1001
|
+
}
|
|
1002
|
+
getPackageJSONSync() {
|
|
1003
|
+
const pkgPath = findUpSync(["package.json"], { cwd: this.#cwd });
|
|
1004
|
+
if (!pkgPath) return void 0;
|
|
1005
|
+
const json = require_fs.readSync(pkgPath);
|
|
1006
|
+
return JSON.parse(json);
|
|
1007
|
+
}
|
|
1008
|
+
static setVersion(dependency, version) {
|
|
1009
|
+
PackageManager.#cache[dependency] = version;
|
|
1010
|
+
}
|
|
1011
|
+
#match(packageJSON, dependency) {
|
|
1012
|
+
const dependencies = {
|
|
1013
|
+
...packageJSON["dependencies"] || {},
|
|
1014
|
+
...packageJSON["devDependencies"] || {}
|
|
1015
|
+
};
|
|
1016
|
+
if (typeof dependency === "string" && dependencies[dependency]) return dependencies[dependency];
|
|
1017
|
+
const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
|
|
1018
|
+
return matchedDependency ? dependencies[matchedDependency] : void 0;
|
|
1019
|
+
}
|
|
1020
|
+
async getVersion(dependency) {
|
|
1021
|
+
if (typeof dependency === "string" && PackageManager.#cache[dependency]) return PackageManager.#cache[dependency];
|
|
1022
|
+
const packageJSON = await this.getPackageJSON();
|
|
1023
|
+
if (!packageJSON) return void 0;
|
|
1024
|
+
return this.#match(packageJSON, dependency);
|
|
1025
|
+
}
|
|
1026
|
+
getVersionSync(dependency) {
|
|
1027
|
+
if (typeof dependency === "string" && PackageManager.#cache[dependency]) return PackageManager.#cache[dependency];
|
|
1028
|
+
const packageJSON = this.getPackageJSONSync();
|
|
1029
|
+
if (!packageJSON) return void 0;
|
|
1030
|
+
return this.#match(packageJSON, dependency);
|
|
1031
|
+
}
|
|
1032
|
+
async isValid(dependency, version) {
|
|
1033
|
+
const packageVersion = await this.getVersion(dependency);
|
|
1034
|
+
if (!packageVersion) return false;
|
|
1035
|
+
if (packageVersion === version) return true;
|
|
1036
|
+
const semVer = (0, semver.coerce)(packageVersion);
|
|
1037
|
+
if (!semVer) throw new Error(`${packageVersion} is not valid`);
|
|
1038
|
+
return (0, semver.satisfies)(semVer, version);
|
|
1039
|
+
}
|
|
1040
|
+
isValidSync(dependency, version) {
|
|
1041
|
+
const packageVersion = this.getVersionSync(dependency);
|
|
1042
|
+
if (!packageVersion) return false;
|
|
1043
|
+
if (version === "next" && packageVersion === version) return true;
|
|
1044
|
+
const semVer = (0, semver.coerce)(packageVersion);
|
|
1045
|
+
if (!semVer) return false;
|
|
1046
|
+
return (0, semver.satisfies)(semVer, version);
|
|
1047
|
+
}
|
|
1067
1048
|
};
|
|
1068
1049
|
|
|
1069
|
-
|
|
1070
|
-
enumerable: true,
|
|
1071
|
-
get: function () { return chunkQR7CQIA3_cjs.FileManager; }
|
|
1072
|
-
});
|
|
1073
|
-
Object.defineProperty(exports, "getDefaultBanner", {
|
|
1074
|
-
enumerable: true,
|
|
1075
|
-
get: function () { return chunkQR7CQIA3_cjs.getDefaultBanner; }
|
|
1076
|
-
});
|
|
1077
|
-
Object.defineProperty(exports, "getSource", {
|
|
1078
|
-
enumerable: true,
|
|
1079
|
-
get: function () { return chunkQR7CQIA3_cjs.getSource; }
|
|
1080
|
-
});
|
|
1050
|
+
//#endregion
|
|
1081
1051
|
exports.BaseGenerator = BaseGenerator;
|
|
1052
|
+
exports.FileManager = require_FileManager.FileManager;
|
|
1082
1053
|
exports.PackageManager = PackageManager;
|
|
1083
1054
|
exports.PluginManager = PluginManager;
|
|
1084
1055
|
exports.PromiseManager = PromiseManager;
|
|
@@ -1086,8 +1057,9 @@ exports.build = build;
|
|
|
1086
1057
|
exports.createPlugin = createPlugin;
|
|
1087
1058
|
exports.default = build;
|
|
1088
1059
|
exports.defineConfig = defineConfig;
|
|
1060
|
+
exports.getDefaultBanner = require_FileManager.getDefaultBanner;
|
|
1061
|
+
exports.getSource = require_FileManager.getSource;
|
|
1089
1062
|
exports.isInputPath = isInputPath;
|
|
1090
1063
|
exports.safeBuild = safeBuild;
|
|
1091
1064
|
exports.setup = setup;
|
|
1092
|
-
//# sourceMappingURL=index.cjs.map
|
|
1093
1065
|
//# sourceMappingURL=index.cjs.map
|