@kubb/core 1.15.0-canary.20231027T200912 → 2.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1190 -1038
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +267 -314
- package/dist/index.d.ts +267 -314
- package/dist/index.js +1132 -971
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +1258 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +235 -0
- package/dist/utils.d.ts +235 -0
- package/dist/utils.js +1205 -0
- package/dist/utils.js.map +1 -0
- package/globals.d.ts +33 -16
- package/package.json +9 -4
package/dist/index.cjs
CHANGED
|
@@ -3,18 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var pc3 = require('picocolors');
|
|
6
|
-
var crypto = require('crypto');
|
|
7
6
|
var fs2 = require('fs-extra');
|
|
8
|
-
var changeCase = require('change-case');
|
|
9
|
-
var naturalOrderby = require('natural-orderby');
|
|
10
|
-
var perf_hooks = require('perf_hooks');
|
|
11
7
|
var seedrandom = require('seedrandom');
|
|
12
|
-
var
|
|
8
|
+
var path4 = require('path');
|
|
13
9
|
var jsRuntime = require('js-runtime');
|
|
14
|
-
var
|
|
10
|
+
var changeCase = require('change-case');
|
|
11
|
+
var crypto2 = require('crypto');
|
|
15
12
|
var parser = require('@kubb/parser');
|
|
13
|
+
var factory = require('@kubb/parser/factory');
|
|
16
14
|
var isEqual = require('lodash.isequal');
|
|
15
|
+
var naturalOrderby = require('natural-orderby');
|
|
16
|
+
var dirTree = require('directory-tree');
|
|
17
17
|
var events = require('events');
|
|
18
|
+
var perf_hooks = require('perf_hooks');
|
|
18
19
|
var mod = require('module');
|
|
19
20
|
var os = require('os');
|
|
20
21
|
var url = require('url');
|
|
@@ -24,18 +25,39 @@ var semver = require('semver');
|
|
|
24
25
|
|
|
25
26
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
26
27
|
|
|
28
|
+
function _interopNamespace(e) {
|
|
29
|
+
if (e && e.__esModule) return e;
|
|
30
|
+
var n = Object.create(null);
|
|
31
|
+
if (e) {
|
|
32
|
+
Object.keys(e).forEach(function (k) {
|
|
33
|
+
if (k !== 'default') {
|
|
34
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
35
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return e[k]; }
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
n.default = e;
|
|
43
|
+
return Object.freeze(n);
|
|
44
|
+
}
|
|
45
|
+
|
|
27
46
|
var pc3__default = /*#__PURE__*/_interopDefault(pc3);
|
|
28
|
-
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
29
47
|
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
30
48
|
var seedrandom__default = /*#__PURE__*/_interopDefault(seedrandom);
|
|
31
|
-
var
|
|
32
|
-
var
|
|
49
|
+
var path4__default = /*#__PURE__*/_interopDefault(path4);
|
|
50
|
+
var crypto2__default = /*#__PURE__*/_interopDefault(crypto2);
|
|
51
|
+
var factory__namespace = /*#__PURE__*/_interopNamespace(factory);
|
|
33
52
|
var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
|
|
53
|
+
var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
|
|
34
54
|
var mod__default = /*#__PURE__*/_interopDefault(mod);
|
|
35
55
|
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
36
56
|
var process__default = /*#__PURE__*/_interopDefault(process);
|
|
37
57
|
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
38
58
|
|
|
59
|
+
var __defProp = Object.defineProperty;
|
|
60
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
39
61
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
40
62
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
41
63
|
}) : x)(function(x) {
|
|
@@ -43,110 +65,49 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
43
65
|
return require.apply(this, arguments);
|
|
44
66
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
45
67
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
set(id, value) {
|
|
51
|
-
Store[id] = [0, value];
|
|
52
|
-
},
|
|
53
|
-
get(id) {
|
|
54
|
-
const item = Store[id];
|
|
55
|
-
if (!item) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
item[0] = 0;
|
|
59
|
-
return item[1];
|
|
60
|
-
},
|
|
61
|
-
has(id) {
|
|
62
|
-
const item = Store[id];
|
|
63
|
-
if (!item) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
item[0] = 0;
|
|
67
|
-
return true;
|
|
68
|
-
},
|
|
69
|
-
delete(id) {
|
|
70
|
-
return delete Store[id];
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
async function clean(path3) {
|
|
75
|
-
return fs2.remove(path3);
|
|
76
|
-
}
|
|
77
|
-
var FunctionParams = class {
|
|
78
|
-
type;
|
|
79
|
-
items = [];
|
|
80
|
-
constructor(type) {
|
|
81
|
-
this.type = type;
|
|
82
|
-
return this;
|
|
83
|
-
}
|
|
84
|
-
add(item) {
|
|
85
|
-
if (!item) {
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
if (Array.isArray(item)) {
|
|
89
|
-
item.filter(Boolean).forEach((it) => this.items.push(it));
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
this.items.push(item);
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
toString() {
|
|
96
|
-
const sortedData = naturalOrderby.orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ["desc", "desc"]);
|
|
97
|
-
return sortedData.filter(({ enabled = true }) => enabled).reduce((acc, { name, type, required = true, ...rest }) => {
|
|
98
|
-
if (!name) {
|
|
99
|
-
acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
100
|
-
return acc;
|
|
101
|
-
}
|
|
102
|
-
const parameterName = name.startsWith("{") ? name : changeCase.camelCase(name, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
103
|
-
if (type) {
|
|
104
|
-
if (required) {
|
|
105
|
-
acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
106
|
-
} else {
|
|
107
|
-
acc.push(`${parameterName}?: ${type}`);
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
acc.push(`${parameterName}`);
|
|
111
|
-
}
|
|
112
|
-
return acc;
|
|
113
|
-
}, []).join(", ");
|
|
114
|
-
}
|
|
68
|
+
var __publicField = (obj, key, value) => {
|
|
69
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
70
|
+
return value;
|
|
115
71
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
function createJSDocBlockText({ comments }) {
|
|
141
|
-
const filteredComments = comments.filter(Boolean);
|
|
142
|
-
if (!filteredComments.length) {
|
|
143
|
-
return "";
|
|
72
|
+
var __accessCheck = (obj, member, msg) => {
|
|
73
|
+
if (!member.has(obj))
|
|
74
|
+
throw TypeError("Cannot " + msg);
|
|
75
|
+
};
|
|
76
|
+
var __privateGet = (obj, member, getter) => {
|
|
77
|
+
__accessCheck(obj, member, "read from private field");
|
|
78
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
79
|
+
};
|
|
80
|
+
var __privateAdd = (obj, member, value) => {
|
|
81
|
+
if (member.has(obj))
|
|
82
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
83
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
84
|
+
};
|
|
85
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
86
|
+
__accessCheck(obj, member, "write to private field");
|
|
87
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
88
|
+
return value;
|
|
89
|
+
};
|
|
90
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
91
|
+
set _(value) {
|
|
92
|
+
__privateSet(obj, member, value, setter);
|
|
93
|
+
},
|
|
94
|
+
get _() {
|
|
95
|
+
return __privateGet(obj, member, getter);
|
|
144
96
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
97
|
+
});
|
|
98
|
+
var __privateMethod = (obj, member, method) => {
|
|
99
|
+
__accessCheck(obj, member, "access private method");
|
|
100
|
+
return method;
|
|
101
|
+
};
|
|
102
|
+
async function clean(path5) {
|
|
103
|
+
return fs2.remove(path5);
|
|
148
104
|
}
|
|
149
|
-
|
|
105
|
+
var LogLevel = {
|
|
106
|
+
silent: "silent",
|
|
107
|
+
info: "info",
|
|
108
|
+
debug: "debug"
|
|
109
|
+
};
|
|
110
|
+
function createLogger({ logLevel, name, spinner }) {
|
|
150
111
|
const logs = [];
|
|
151
112
|
const log = (message) => {
|
|
152
113
|
if (message && spinner) {
|
|
@@ -172,6 +133,8 @@ function createLogger(spinner) {
|
|
|
172
133
|
}
|
|
173
134
|
};
|
|
174
135
|
const logger = {
|
|
136
|
+
name,
|
|
137
|
+
logLevel,
|
|
175
138
|
log,
|
|
176
139
|
error,
|
|
177
140
|
warn,
|
|
@@ -181,75 +144,6 @@ function createLogger(spinner) {
|
|
|
181
144
|
};
|
|
182
145
|
return logger;
|
|
183
146
|
}
|
|
184
|
-
|
|
185
|
-
// src/utils/nameSorter.ts
|
|
186
|
-
function nameSorter(a, b) {
|
|
187
|
-
if (a.name < b.name) {
|
|
188
|
-
return -1;
|
|
189
|
-
}
|
|
190
|
-
if (a.name > b.name) {
|
|
191
|
-
return 1;
|
|
192
|
-
}
|
|
193
|
-
return 0;
|
|
194
|
-
}
|
|
195
|
-
var Queue = class {
|
|
196
|
-
#queue = [];
|
|
197
|
-
#workerCount = 0;
|
|
198
|
-
#maxParallel;
|
|
199
|
-
#debug = false;
|
|
200
|
-
constructor(maxParallel, debug = false) {
|
|
201
|
-
this.#maxParallel = maxParallel;
|
|
202
|
-
this.#debug = debug;
|
|
203
|
-
}
|
|
204
|
-
run(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
|
|
205
|
-
return new Promise((resolve, reject) => {
|
|
206
|
-
const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
|
|
207
|
-
options.controller?.signal.addEventListener("abort", () => {
|
|
208
|
-
this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
|
|
209
|
-
reject("Aborted");
|
|
210
|
-
});
|
|
211
|
-
this.#queue.push(item);
|
|
212
|
-
this.#work();
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
runSync(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
|
|
216
|
-
new Promise((resolve, reject) => {
|
|
217
|
-
const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
|
|
218
|
-
options.controller?.signal.addEventListener("abort", () => {
|
|
219
|
-
this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
|
|
220
|
-
});
|
|
221
|
-
this.#queue.push(item);
|
|
222
|
-
this.#work();
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
get hasJobs() {
|
|
226
|
-
return this.#workerCount > 0 || this.#queue.length > 0;
|
|
227
|
-
}
|
|
228
|
-
get count() {
|
|
229
|
-
return this.#workerCount;
|
|
230
|
-
}
|
|
231
|
-
#work() {
|
|
232
|
-
if (this.#workerCount >= this.#maxParallel) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
this.#workerCount++;
|
|
236
|
-
let entry;
|
|
237
|
-
while (entry = this.#queue.shift()) {
|
|
238
|
-
const { reject, resolve, job, name, description } = entry;
|
|
239
|
-
if (this.#debug) {
|
|
240
|
-
perf_hooks.performance.mark(name + "_start");
|
|
241
|
-
}
|
|
242
|
-
job().then((result) => {
|
|
243
|
-
resolve(result);
|
|
244
|
-
if (this.#debug) {
|
|
245
|
-
perf_hooks.performance.mark(name + "_stop");
|
|
246
|
-
perf_hooks.performance.measure(description, name + "_start", name + "_stop");
|
|
247
|
-
}
|
|
248
|
-
}).catch((err) => reject(err));
|
|
249
|
-
}
|
|
250
|
-
this.#workerCount--;
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
147
|
var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
|
|
254
148
|
function randomColour(text, colours = defaultColours) {
|
|
255
149
|
if (!text) {
|
|
@@ -276,46 +170,22 @@ function randomPicoColour(text, colors = defaultColours) {
|
|
|
276
170
|
}
|
|
277
171
|
return formatter(text);
|
|
278
172
|
}
|
|
279
|
-
function slash(path3, platform = "linux") {
|
|
280
|
-
const isWindowsPath = /^\\\\\?\\/.test(path3);
|
|
281
|
-
if (["linux", "mac"].includes(platform) && !isWindowsPath) {
|
|
282
|
-
return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
283
|
-
}
|
|
284
|
-
return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
285
|
-
}
|
|
286
|
-
function getRelativePath(rootDir, filePath, platform = "linux") {
|
|
287
|
-
if (!rootDir || !filePath) {
|
|
288
|
-
throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
|
|
289
|
-
}
|
|
290
|
-
const relativePath = path2__default.default.relative(rootDir, filePath);
|
|
291
|
-
const path3 = slash(relativePath, platform);
|
|
292
|
-
if (path3.startsWith("../")) {
|
|
293
|
-
return path3.replace(path2__default.default.basename(path3), path2__default.default.basename(path3, path2__default.default.extname(filePath)));
|
|
294
|
-
}
|
|
295
|
-
return `./${path3.replace(path2__default.default.basename(path3), path2__default.default.basename(path3, path2__default.default.extname(filePath)))}`;
|
|
296
|
-
}
|
|
297
|
-
function getPathMode(path3) {
|
|
298
|
-
if (!path3) {
|
|
299
|
-
return "directory";
|
|
300
|
-
}
|
|
301
|
-
return path2__default.default.extname(path3) ? "file" : "directory";
|
|
302
|
-
}
|
|
303
173
|
var reader = jsRuntime.switcher(
|
|
304
174
|
{
|
|
305
|
-
node: async (
|
|
306
|
-
return fs2__default.default.readFile(
|
|
175
|
+
node: async (path5) => {
|
|
176
|
+
return fs2__default.default.readFile(path5, { encoding: "utf8" });
|
|
307
177
|
},
|
|
308
|
-
bun: async (
|
|
309
|
-
const file = Bun.file(
|
|
178
|
+
bun: async (path5) => {
|
|
179
|
+
const file = Bun.file(path5);
|
|
310
180
|
return file.text();
|
|
311
181
|
}
|
|
312
182
|
},
|
|
313
183
|
"node"
|
|
314
184
|
);
|
|
315
|
-
|
|
185
|
+
jsRuntime.switcher(
|
|
316
186
|
{
|
|
317
|
-
node: (
|
|
318
|
-
return fs2__default.default.readFileSync(
|
|
187
|
+
node: (path5) => {
|
|
188
|
+
return fs2__default.default.readFileSync(path5, { encoding: "utf8" });
|
|
319
189
|
},
|
|
320
190
|
bun: () => {
|
|
321
191
|
throw new Error("Bun cannot read sync");
|
|
@@ -323,79 +193,115 @@ var syncReader = jsRuntime.switcher(
|
|
|
323
193
|
},
|
|
324
194
|
"node"
|
|
325
195
|
);
|
|
326
|
-
async function read(
|
|
327
|
-
return reader(
|
|
328
|
-
}
|
|
329
|
-
function readSync(path3) {
|
|
330
|
-
return syncReader(path3);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// src/utils/renderTemplate.ts
|
|
334
|
-
function renderTemplate(template, data = void 0) {
|
|
335
|
-
if (!data || !Object.keys(data).length) {
|
|
336
|
-
return template.replace(/{{(.*?)}}/g, "");
|
|
337
|
-
}
|
|
338
|
-
const matches = template.match(/{{(.*?)}}/g);
|
|
339
|
-
return matches?.reduce((prev, curr) => {
|
|
340
|
-
const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
|
|
341
|
-
if (index === void 0) {
|
|
342
|
-
return prev;
|
|
343
|
-
}
|
|
344
|
-
const value = data[index];
|
|
345
|
-
if (value === void 0) {
|
|
346
|
-
return prev;
|
|
347
|
-
}
|
|
348
|
-
return prev.replace(curr, () => {
|
|
349
|
-
if (typeof value === "boolean") {
|
|
350
|
-
return `${value.toString()}` || "false";
|
|
351
|
-
}
|
|
352
|
-
return value || "";
|
|
353
|
-
}).trim();
|
|
354
|
-
}, template) || "";
|
|
196
|
+
async function read(path5) {
|
|
197
|
+
return reader(path5);
|
|
355
198
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
constructor(message, options) {
|
|
361
|
-
super(message, { cause: options.cause });
|
|
362
|
-
this.name = "SummaryError";
|
|
363
|
-
this.summary = options.summary || [];
|
|
199
|
+
var URLPath = class {
|
|
200
|
+
constructor(path5) {
|
|
201
|
+
this.path = path5;
|
|
202
|
+
return this;
|
|
364
203
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
206
|
+
* @example /pet/{petId} => /pet/:petId
|
|
207
|
+
*/
|
|
208
|
+
get URL() {
|
|
209
|
+
return this.toURLPath();
|
|
210
|
+
}
|
|
211
|
+
get isURL() {
|
|
212
|
+
try {
|
|
213
|
+
const url = new URL(this.path);
|
|
214
|
+
if (url?.href) {
|
|
215
|
+
return true;
|
|
376
216
|
}
|
|
377
|
-
|
|
378
|
-
|
|
217
|
+
} catch (error) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
224
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
225
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
226
|
+
* @example /account/userID => `/account/${userId}`
|
|
227
|
+
*/
|
|
228
|
+
get template() {
|
|
229
|
+
return this.toTemplateString();
|
|
230
|
+
}
|
|
231
|
+
get object() {
|
|
232
|
+
return this.toObject();
|
|
233
|
+
}
|
|
234
|
+
get params() {
|
|
235
|
+
return this.getParams();
|
|
236
|
+
}
|
|
237
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
238
|
+
const object = {
|
|
239
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
|
|
240
|
+
params: this.getParams()
|
|
241
|
+
};
|
|
242
|
+
if (stringify) {
|
|
243
|
+
if (type !== "template") {
|
|
244
|
+
throw new Error("Type should be `template` when using stringiyf");
|
|
379
245
|
}
|
|
380
|
-
|
|
381
|
-
wait = true;
|
|
382
|
-
timeout2 = setTimeout(() => {
|
|
383
|
-
wait = false;
|
|
384
|
-
}, delay);
|
|
385
|
-
return val;
|
|
386
|
-
},
|
|
387
|
-
() => {
|
|
388
|
-
cancelled = true;
|
|
389
|
-
clearTimeout(timeout2);
|
|
246
|
+
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
390
247
|
}
|
|
391
|
-
|
|
248
|
+
return object;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
252
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
253
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
254
|
+
* @example /account/userID => `/account/${userId}`
|
|
255
|
+
*/
|
|
256
|
+
toTemplateString(replacer) {
|
|
257
|
+
const regex = /{(\w|-)*}/g;
|
|
258
|
+
const found = this.path.match(regex);
|
|
259
|
+
let newPath = this.path.replaceAll("{", "${");
|
|
260
|
+
if (found) {
|
|
261
|
+
newPath = found.reduce((prev, curr) => {
|
|
262
|
+
const pathParam = replacer ? replacer(changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
263
|
+
const replacement = `\${${pathParam}}`;
|
|
264
|
+
return prev.replace(curr, replacement);
|
|
265
|
+
}, this.path);
|
|
266
|
+
}
|
|
267
|
+
return `\`${newPath}\``;
|
|
268
|
+
}
|
|
269
|
+
getParams(replacer) {
|
|
270
|
+
const regex = /{(\w|-)*}/g;
|
|
271
|
+
const found = this.path.match(regex);
|
|
272
|
+
if (!found) {
|
|
273
|
+
return void 0;
|
|
274
|
+
}
|
|
275
|
+
const params = {};
|
|
276
|
+
found.forEach((item) => {
|
|
277
|
+
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
278
|
+
const pathParam = replacer ? replacer(changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
279
|
+
params[pathParam] = pathParam;
|
|
280
|
+
}, this.path);
|
|
281
|
+
return params;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
285
|
+
* @example /pet/{petId} => /pet/:petId
|
|
286
|
+
*/
|
|
287
|
+
toURLPath() {
|
|
288
|
+
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
289
|
+
}
|
|
392
290
|
};
|
|
393
291
|
|
|
292
|
+
// src/config.ts
|
|
293
|
+
function defineConfig(options) {
|
|
294
|
+
return options;
|
|
295
|
+
}
|
|
296
|
+
function isInputPath(result) {
|
|
297
|
+
return !!result && "path" in result;
|
|
298
|
+
}
|
|
299
|
+
|
|
394
300
|
// src/utils/timeout.ts
|
|
395
301
|
async function timeout(ms) {
|
|
396
|
-
return new Promise((
|
|
302
|
+
return new Promise((resolve2) => {
|
|
397
303
|
setTimeout(() => {
|
|
398
|
-
|
|
304
|
+
resolve2(true);
|
|
399
305
|
}, ms);
|
|
400
306
|
});
|
|
401
307
|
}
|
|
@@ -405,6 +311,17 @@ function combineCodes(codes) {
|
|
|
405
311
|
return codes.join("\n");
|
|
406
312
|
}
|
|
407
313
|
|
|
314
|
+
// src/utils/transformers/createJSDocBlockText.ts
|
|
315
|
+
function createJSDocBlockText({ comments }) {
|
|
316
|
+
const filteredComments = comments.filter(Boolean);
|
|
317
|
+
if (!filteredComments.length) {
|
|
318
|
+
return "";
|
|
319
|
+
}
|
|
320
|
+
return `/**
|
|
321
|
+
* ${filteredComments.join("\n * ")}
|
|
322
|
+
*/`;
|
|
323
|
+
}
|
|
324
|
+
|
|
408
325
|
// src/utils/transformers/escape.ts
|
|
409
326
|
function escape(text) {
|
|
410
327
|
return text ? text.replaceAll("`", "\\`") : "";
|
|
@@ -430,7 +347,40 @@ function jsStringEscape(input) {
|
|
|
430
347
|
});
|
|
431
348
|
}
|
|
432
349
|
|
|
433
|
-
// src/utils/transformers/
|
|
350
|
+
// src/utils/transformers/indent.ts
|
|
351
|
+
function createIndent(size) {
|
|
352
|
+
return Array.from({ length: size + 1 }).join(" ");
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/utils/transformers/nameSorter.ts
|
|
356
|
+
function nameSorter(a, b) {
|
|
357
|
+
if (a.name < b.name) {
|
|
358
|
+
return -1;
|
|
359
|
+
}
|
|
360
|
+
if (a.name > b.name) {
|
|
361
|
+
return 1;
|
|
362
|
+
}
|
|
363
|
+
return 0;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/utils/transformers/searchAndReplace.ts
|
|
367
|
+
function searchAndReplace(options) {
|
|
368
|
+
const { text, replaceBy, prefix = "", key } = options;
|
|
369
|
+
const searchValues = options.searchValues?.(prefix, key) || [
|
|
370
|
+
`${prefix}["${key}"]`,
|
|
371
|
+
`${prefix}['${key}']`,
|
|
372
|
+
`${prefix}[\`${key}\`]`,
|
|
373
|
+
`${prefix}"${key}"`,
|
|
374
|
+
`${prefix}'${key}'`,
|
|
375
|
+
`${prefix}\`${key}\``,
|
|
376
|
+
new RegExp(`${prefix}${key}`, "g")
|
|
377
|
+
];
|
|
378
|
+
return searchValues.reduce((prev, searchValue) => {
|
|
379
|
+
return prev.toString().replaceAll(searchValue, replaceBy);
|
|
380
|
+
}, text);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// src/utils/transformers/transformReservedWord.ts
|
|
434
384
|
var reservedWords = [
|
|
435
385
|
"abstract",
|
|
436
386
|
"arguments",
|
|
@@ -522,11 +472,83 @@ function transformReservedWord(word) {
|
|
|
522
472
|
}
|
|
523
473
|
return word;
|
|
524
474
|
}
|
|
475
|
+
|
|
476
|
+
// src/utils/transformers/index.ts
|
|
477
|
+
var transformers = {
|
|
478
|
+
combineCodes,
|
|
479
|
+
escape,
|
|
480
|
+
jsStringEscape,
|
|
481
|
+
createIndent,
|
|
482
|
+
transformReservedWord,
|
|
483
|
+
nameSorter,
|
|
484
|
+
searchAndReplace,
|
|
485
|
+
JSDoc: {
|
|
486
|
+
createJSDocBlockText
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
async function saveCreateDirectory(path5) {
|
|
490
|
+
const passedPath = path4.dirname(path4.resolve(path5));
|
|
491
|
+
await fs2__default.default.mkdir(passedPath, { recursive: true });
|
|
492
|
+
}
|
|
493
|
+
var writer = jsRuntime.switcher(
|
|
494
|
+
{
|
|
495
|
+
node: async (path5, data) => {
|
|
496
|
+
try {
|
|
497
|
+
await fs2__default.default.stat(path4.resolve(path5));
|
|
498
|
+
const oldContent = await fs2__default.default.readFile(path4.resolve(path5), { encoding: "utf-8" });
|
|
499
|
+
if (oldContent?.toString() === data?.toString()) {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
} catch (_err) {
|
|
503
|
+
}
|
|
504
|
+
await saveCreateDirectory(path5);
|
|
505
|
+
await fs2__default.default.writeFile(path4.resolve(path5), data, { encoding: "utf-8" });
|
|
506
|
+
const savedData = await fs2__default.default.readFile(path4.resolve(path5), { encoding: "utf-8" });
|
|
507
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
508
|
+
throw new Error(`Sanity check failed for ${path5}
|
|
509
|
+
|
|
510
|
+
Data[${data.length}]:
|
|
511
|
+
${data}
|
|
512
|
+
|
|
513
|
+
Saved[${savedData.length}]:
|
|
514
|
+
${savedData}
|
|
515
|
+
`);
|
|
516
|
+
}
|
|
517
|
+
return savedData;
|
|
518
|
+
},
|
|
519
|
+
bun: async (path5, data) => {
|
|
520
|
+
try {
|
|
521
|
+
await saveCreateDirectory(path5);
|
|
522
|
+
await Bun.write(path4.resolve(path5), data);
|
|
523
|
+
const file = Bun.file(path4.resolve(path5));
|
|
524
|
+
const savedData = await file.text();
|
|
525
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
526
|
+
throw new Error(`Sanity check failed for ${path5}
|
|
527
|
+
|
|
528
|
+
Data[${data.length}]:
|
|
529
|
+
${data}
|
|
530
|
+
|
|
531
|
+
Saved[${savedData.length}]:
|
|
532
|
+
${savedData}
|
|
533
|
+
`);
|
|
534
|
+
}
|
|
535
|
+
return savedData;
|
|
536
|
+
} catch (e) {
|
|
537
|
+
console.log(e, path4.resolve(path5));
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
},
|
|
541
|
+
"node"
|
|
542
|
+
);
|
|
543
|
+
async function write(data, path5) {
|
|
544
|
+
if (data.trim() === "") {
|
|
545
|
+
return void 0;
|
|
546
|
+
}
|
|
547
|
+
return writer(path5, data.trim());
|
|
548
|
+
}
|
|
525
549
|
var TreeNode = class _TreeNode {
|
|
526
|
-
data;
|
|
527
|
-
parent;
|
|
528
|
-
children = [];
|
|
529
550
|
constructor(data, parent) {
|
|
551
|
+
this.children = [];
|
|
530
552
|
this.data = data;
|
|
531
553
|
this.parent = parent;
|
|
532
554
|
return this;
|
|
@@ -586,16 +608,16 @@ var TreeNode = class _TreeNode {
|
|
|
586
608
|
}
|
|
587
609
|
return this;
|
|
588
610
|
}
|
|
589
|
-
static build(
|
|
611
|
+
static build(path5, options = {}) {
|
|
590
612
|
try {
|
|
591
613
|
const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
|
|
592
|
-
const filteredTree = dirTree__default.default(
|
|
614
|
+
const filteredTree = dirTree__default.default(path5, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
|
|
593
615
|
if (!filteredTree) {
|
|
594
616
|
return null;
|
|
595
617
|
}
|
|
596
|
-
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type ||
|
|
618
|
+
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || FileManager.getMode(filteredTree.path) });
|
|
597
619
|
const recurse = (node, item) => {
|
|
598
|
-
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type ||
|
|
620
|
+
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || FileManager.getMode(item.path) });
|
|
599
621
|
if (item.children?.length) {
|
|
600
622
|
item.children?.forEach((child) => {
|
|
601
623
|
recurse(subNode, child);
|
|
@@ -610,227 +632,290 @@ var TreeNode = class _TreeNode {
|
|
|
610
632
|
}
|
|
611
633
|
};
|
|
612
634
|
|
|
613
|
-
// src/
|
|
614
|
-
var
|
|
615
|
-
var
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
this
|
|
635
|
+
// src/BarrelManager.ts
|
|
636
|
+
var _options;
|
|
637
|
+
var BarrelManager = class {
|
|
638
|
+
constructor(options = {}) {
|
|
639
|
+
__privateAdd(this, _options, {});
|
|
640
|
+
__privateSet(this, _options, options);
|
|
619
641
|
return this;
|
|
620
642
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
if (url?.href) {
|
|
632
|
-
return true;
|
|
643
|
+
getIndexes(root, extName) {
|
|
644
|
+
const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = __privateGet(this, _options);
|
|
645
|
+
const extMapper = {
|
|
646
|
+
".ts": {
|
|
647
|
+
extensions: /\.ts/,
|
|
648
|
+
exclude: [/schemas/, /json/]
|
|
649
|
+
},
|
|
650
|
+
".json": {
|
|
651
|
+
extensions: /\.json/,
|
|
652
|
+
exclude: []
|
|
633
653
|
}
|
|
634
|
-
}
|
|
635
|
-
|
|
654
|
+
};
|
|
655
|
+
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
|
|
656
|
+
if (!tree) {
|
|
657
|
+
return null;
|
|
636
658
|
}
|
|
637
|
-
|
|
659
|
+
const fileReducer = (files2, currentTree) => {
|
|
660
|
+
if (!currentTree.children) {
|
|
661
|
+
return [];
|
|
662
|
+
}
|
|
663
|
+
if (currentTree.children?.length > 1) {
|
|
664
|
+
const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
|
|
665
|
+
const exports = currentTree.children.filter(Boolean).map((file) => {
|
|
666
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
667
|
+
if (importPath.includes("index") && indexPath.includes("index")) {
|
|
668
|
+
return void 0;
|
|
669
|
+
}
|
|
670
|
+
return {
|
|
671
|
+
path: includeExt ? file.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
|
|
672
|
+
isTypeOnly
|
|
673
|
+
};
|
|
674
|
+
}).filter(Boolean);
|
|
675
|
+
files2.push({
|
|
676
|
+
path: indexPath,
|
|
677
|
+
baseName: "index.ts",
|
|
678
|
+
source: "",
|
|
679
|
+
exports: output ? exports?.filter((item) => {
|
|
680
|
+
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
681
|
+
}) : exports
|
|
682
|
+
});
|
|
683
|
+
} else {
|
|
684
|
+
currentTree.children?.forEach((child) => {
|
|
685
|
+
const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
|
|
686
|
+
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
687
|
+
const exports = [
|
|
688
|
+
{
|
|
689
|
+
path: includeExt ? child.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
|
|
690
|
+
isTypeOnly
|
|
691
|
+
}
|
|
692
|
+
];
|
|
693
|
+
files2.push({
|
|
694
|
+
path: indexPath,
|
|
695
|
+
baseName: "index.ts",
|
|
696
|
+
source: "",
|
|
697
|
+
exports: output ? exports?.filter((item) => {
|
|
698
|
+
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
699
|
+
}) : exports
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
currentTree.children.forEach((childItem) => {
|
|
704
|
+
fileReducer(files2, childItem);
|
|
705
|
+
});
|
|
706
|
+
return files2;
|
|
707
|
+
};
|
|
708
|
+
const files = fileReducer([], tree).reverse();
|
|
709
|
+
const filteredFiles = filter ? files.filter(filter) : files;
|
|
710
|
+
return map ? filteredFiles.map(map) : filteredFiles;
|
|
638
711
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
712
|
+
};
|
|
713
|
+
_options = new WeakMap();
|
|
714
|
+
|
|
715
|
+
// src/FileManager.ts
|
|
716
|
+
exports.KubbFile = void 0;
|
|
717
|
+
((KubbFile2) => {
|
|
718
|
+
})(exports.KubbFile || (exports.KubbFile = {}));
|
|
719
|
+
var _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
720
|
+
var _FileManager = class _FileManager {
|
|
721
|
+
constructor(options) {
|
|
722
|
+
__privateAdd(this, _validate);
|
|
723
|
+
__privateAdd(this, _add);
|
|
724
|
+
__privateAdd(this, _addOrAppend);
|
|
725
|
+
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
|
|
726
|
+
__privateAdd(this, _task, void 0);
|
|
727
|
+
__privateAdd(this, _isWriting, false);
|
|
728
|
+
/**
|
|
729
|
+
* Timeout between writes
|
|
730
|
+
*/
|
|
731
|
+
__privateAdd(this, _timeout, 0);
|
|
732
|
+
__privateAdd(this, _queue, void 0);
|
|
733
|
+
if (options) {
|
|
734
|
+
__privateSet(this, _task, options.task);
|
|
735
|
+
__privateSet(this, _queue, options.queue);
|
|
736
|
+
__privateSet(this, _timeout, options.timeout || 0);
|
|
737
|
+
}
|
|
738
|
+
return this;
|
|
647
739
|
}
|
|
648
|
-
get
|
|
649
|
-
|
|
740
|
+
get files() {
|
|
741
|
+
const files = [];
|
|
742
|
+
__privateGet(this, _cache).forEach((item) => {
|
|
743
|
+
files.push(...item.flat(1));
|
|
744
|
+
});
|
|
745
|
+
return files;
|
|
650
746
|
}
|
|
651
|
-
get
|
|
652
|
-
return this
|
|
747
|
+
get isExecuting() {
|
|
748
|
+
return __privateGet(this, _queue)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
|
|
653
749
|
}
|
|
654
|
-
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
if (stringify) {
|
|
660
|
-
if (type !== "template") {
|
|
661
|
-
throw new Error("Type should be `template` when using stringiyf");
|
|
750
|
+
async add(...files) {
|
|
751
|
+
const promises = files.map((file) => {
|
|
752
|
+
__privateMethod(this, _validate, validate_fn).call(this, file);
|
|
753
|
+
if (file.override) {
|
|
754
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
662
755
|
}
|
|
663
|
-
return
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
669
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
670
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
671
|
-
* @example /account/userID => `/account/${userId}`
|
|
672
|
-
*/
|
|
673
|
-
toTemplateString(replacer) {
|
|
674
|
-
const regex = /{(\w|-)*}/g;
|
|
675
|
-
const found = this.path.match(regex);
|
|
676
|
-
let newPath = this.path.replaceAll("{", "${");
|
|
677
|
-
if (found) {
|
|
678
|
-
newPath = found.reduce((prev, curr) => {
|
|
679
|
-
const pathParam = replacer ? replacer(changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
680
|
-
const replacement = `\${${pathParam}}`;
|
|
681
|
-
return prev.replace(curr, replacement);
|
|
682
|
-
}, this.path);
|
|
756
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
|
|
757
|
+
});
|
|
758
|
+
const resolvedFiles = await Promise.all(promises);
|
|
759
|
+
if (files.length > 1) {
|
|
760
|
+
return resolvedFiles;
|
|
683
761
|
}
|
|
684
|
-
return
|
|
762
|
+
return resolvedFiles[0];
|
|
685
763
|
}
|
|
686
|
-
|
|
687
|
-
const
|
|
688
|
-
const
|
|
689
|
-
if (!
|
|
764
|
+
async addIndexes({ root, extName = ".ts", meta, options = {} }) {
|
|
765
|
+
const barrelManager = new BarrelManager(options);
|
|
766
|
+
const files = barrelManager.getIndexes(root, extName);
|
|
767
|
+
if (!files) {
|
|
690
768
|
return void 0;
|
|
691
769
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
770
|
+
return await Promise.all(
|
|
771
|
+
files.map((file) => {
|
|
772
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
773
|
+
...file,
|
|
774
|
+
meta: meta ? meta : file.meta
|
|
775
|
+
});
|
|
776
|
+
})
|
|
777
|
+
);
|
|
699
778
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
return
|
|
779
|
+
getCacheByUUID(UUID) {
|
|
780
|
+
let cache;
|
|
781
|
+
__privateGet(this, _cache).forEach((files) => {
|
|
782
|
+
cache = files.find((item) => item.id === UUID);
|
|
783
|
+
});
|
|
784
|
+
return cache;
|
|
706
785
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
// src/utils/Warning.ts
|
|
710
|
-
var Warning = class extends Error {
|
|
711
|
-
constructor(message, options) {
|
|
712
|
-
super(message, { cause: options?.cause });
|
|
713
|
-
this.name = "Warning";
|
|
786
|
+
get(path5) {
|
|
787
|
+
return __privateGet(this, _cache).get(path5);
|
|
714
788
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
}
|
|
720
|
-
var writer = jsRuntime.switcher(
|
|
721
|
-
{
|
|
722
|
-
node: async (path3, data) => {
|
|
723
|
-
try {
|
|
724
|
-
await fs2__default.default.stat(path3);
|
|
725
|
-
const oldContent = await fs2__default.default.readFile(path3, { encoding: "utf-8" });
|
|
726
|
-
if (oldContent?.toString() === data) {
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
} catch (_err) {
|
|
730
|
-
}
|
|
731
|
-
await saveCreateDirectory(path3);
|
|
732
|
-
return fs2__default.default.writeFile(path2__default.default.resolve(path3), data, { encoding: "utf-8" });
|
|
733
|
-
},
|
|
734
|
-
bun: async (path3, data) => {
|
|
735
|
-
try {
|
|
736
|
-
await saveCreateDirectory(path3);
|
|
737
|
-
await Bun.write(path2__default.default.resolve(path3), data);
|
|
738
|
-
} catch (e) {
|
|
739
|
-
console.log(e, path2__default.default.resolve(path3));
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
},
|
|
743
|
-
"node"
|
|
744
|
-
);
|
|
745
|
-
async function write(data, path3) {
|
|
746
|
-
return writer(path3, data);
|
|
747
|
-
}
|
|
748
|
-
function getIndexes(root, extName, options = {}) {
|
|
749
|
-
const extMapper = {
|
|
750
|
-
".ts": {
|
|
751
|
-
extensions: /\.ts/,
|
|
752
|
-
exclude: [/schemas/, /json/]
|
|
753
|
-
},
|
|
754
|
-
".json": {
|
|
755
|
-
extensions: /\.json/,
|
|
756
|
-
exclude: []
|
|
789
|
+
remove(path5) {
|
|
790
|
+
const cacheItem = this.get(path5);
|
|
791
|
+
if (!cacheItem) {
|
|
792
|
+
return;
|
|
757
793
|
}
|
|
758
|
-
|
|
759
|
-
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...options });
|
|
760
|
-
if (!tree) {
|
|
761
|
-
return null;
|
|
794
|
+
__privateGet(this, _cache).delete(path5);
|
|
762
795
|
}
|
|
763
|
-
|
|
764
|
-
if (!
|
|
765
|
-
|
|
796
|
+
async write(...params) {
|
|
797
|
+
if (!__privateGet(this, _isWriting)) {
|
|
798
|
+
__privateSet(this, _isWriting, true);
|
|
799
|
+
const text = await write(...params);
|
|
800
|
+
__privateSet(this, _isWriting, false);
|
|
801
|
+
return text;
|
|
766
802
|
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
return { path: importPath };
|
|
778
|
-
}).filter(Boolean);
|
|
779
|
-
files2.push({
|
|
780
|
-
path: path3,
|
|
781
|
-
baseName: "index.ts",
|
|
782
|
-
source: "",
|
|
783
|
-
exports
|
|
784
|
-
});
|
|
785
|
-
} else {
|
|
786
|
-
currentTree.children?.forEach((child) => {
|
|
787
|
-
const path3 = path2__default.default.resolve(currentTree.data.path, "index.ts");
|
|
788
|
-
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
789
|
-
files2.push({
|
|
790
|
-
path: path3,
|
|
791
|
-
baseName: "index.ts",
|
|
792
|
-
source: "",
|
|
793
|
-
exports: [{ path: importPath }]
|
|
794
|
-
});
|
|
795
|
-
});
|
|
803
|
+
await timeout(__privateGet(this, _timeout));
|
|
804
|
+
return this.write(...params);
|
|
805
|
+
}
|
|
806
|
+
async read(...params) {
|
|
807
|
+
return read(...params);
|
|
808
|
+
}
|
|
809
|
+
// statics
|
|
810
|
+
static getSource(file) {
|
|
811
|
+
if (!_FileManager.isExtensionAllowed(file.baseName)) {
|
|
812
|
+
return file.source;
|
|
796
813
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
});
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
814
|
+
const exports = file.exports ? combineExports(file.exports) : [];
|
|
815
|
+
const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
|
|
816
|
+
const importNodes = imports.map((item) => factory__namespace.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
817
|
+
const exportNodes = exports.map(
|
|
818
|
+
(item) => factory__namespace.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias })
|
|
819
|
+
);
|
|
820
|
+
return [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
821
|
+
}
|
|
822
|
+
static combineFiles(files) {
|
|
823
|
+
return files.filter(Boolean).reduce((acc, file) => {
|
|
824
|
+
const prevIndex = acc.findIndex((item) => item.path === file.path);
|
|
825
|
+
if (prevIndex === -1) {
|
|
826
|
+
return [...acc, file];
|
|
827
|
+
}
|
|
809
828
|
const prev = acc[prevIndex];
|
|
829
|
+
if (prev && file.override) {
|
|
830
|
+
acc[prevIndex] = {
|
|
831
|
+
imports: [],
|
|
832
|
+
exports: [],
|
|
833
|
+
...file
|
|
834
|
+
};
|
|
835
|
+
return acc;
|
|
836
|
+
}
|
|
810
837
|
if (prev) {
|
|
811
838
|
acc[prevIndex] = {
|
|
812
|
-
...
|
|
813
|
-
source: prev.source &&
|
|
814
|
-
${
|
|
815
|
-
imports: [...prev.imports || [], ...
|
|
816
|
-
exports: [...prev.exports || [], ...
|
|
817
|
-
env: { ...prev.env || {}, ...
|
|
839
|
+
...file,
|
|
840
|
+
source: prev.source && file.source ? `${prev.source}
|
|
841
|
+
${file.source}` : "",
|
|
842
|
+
imports: [...prev.imports || [], ...file.imports || []],
|
|
843
|
+
exports: [...prev.exports || [], ...file.exports || []],
|
|
844
|
+
env: { ...prev.env || {}, ...file.env || {} }
|
|
818
845
|
};
|
|
819
846
|
}
|
|
820
|
-
|
|
821
|
-
|
|
847
|
+
return acc;
|
|
848
|
+
}, []);
|
|
849
|
+
}
|
|
850
|
+
static getMode(path5) {
|
|
851
|
+
if (!path5) {
|
|
852
|
+
return "directory";
|
|
822
853
|
}
|
|
823
|
-
return
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
854
|
+
return path4.extname(path5) ? "file" : "directory";
|
|
855
|
+
}
|
|
856
|
+
static get extensions() {
|
|
857
|
+
return [".js", ".ts", ".tsx"];
|
|
858
|
+
}
|
|
859
|
+
static isExtensionAllowed(baseName) {
|
|
860
|
+
return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
_cache = new WeakMap();
|
|
864
|
+
_task = new WeakMap();
|
|
865
|
+
_isWriting = new WeakMap();
|
|
866
|
+
_timeout = new WeakMap();
|
|
867
|
+
_queue = new WeakMap();
|
|
868
|
+
_validate = new WeakSet();
|
|
869
|
+
validate_fn = function(file) {
|
|
870
|
+
if (!file.validate) {
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
|
|
874
|
+
throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
_add = new WeakSet();
|
|
878
|
+
add_fn = async function(file) {
|
|
879
|
+
const controller = new AbortController();
|
|
880
|
+
const resolvedFile = { id: crypto2__default.default.randomUUID(), ...file };
|
|
881
|
+
__privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
882
|
+
if (__privateGet(this, _queue)) {
|
|
883
|
+
await __privateGet(this, _queue).run(
|
|
884
|
+
async () => {
|
|
885
|
+
var _a;
|
|
886
|
+
return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
|
|
887
|
+
},
|
|
888
|
+
{ controller }
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
return resolvedFile;
|
|
892
|
+
};
|
|
893
|
+
_addOrAppend = new WeakSet();
|
|
894
|
+
addOrAppend_fn = async function(file) {
|
|
895
|
+
const previousCaches = __privateGet(this, _cache).get(file.path);
|
|
896
|
+
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
897
|
+
if (previousCache) {
|
|
898
|
+
__privateGet(this, _cache).delete(previousCache.path);
|
|
899
|
+
return __privateMethod(this, _add, add_fn).call(this, {
|
|
900
|
+
...file,
|
|
901
|
+
source: previousCache.source && file.source ? `${previousCache.source}
|
|
902
|
+
${file.source}` : "",
|
|
903
|
+
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
904
|
+
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
905
|
+
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
909
|
+
};
|
|
910
|
+
var FileManager = _FileManager;
|
|
830
911
|
function combineExports(exports) {
|
|
831
|
-
|
|
912
|
+
const combinedExports = naturalOrderby.orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
832
913
|
const name = curr.name;
|
|
833
914
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
915
|
+
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
|
|
916
|
+
if (prevByPathAndIsTypeOnly) {
|
|
917
|
+
return prev;
|
|
918
|
+
}
|
|
834
919
|
const uniquePrev = prev.findLast(
|
|
835
920
|
(imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
836
921
|
);
|
|
@@ -852,12 +937,16 @@ function combineExports(exports) {
|
|
|
852
937
|
}
|
|
853
938
|
return [...prev, curr];
|
|
854
939
|
}, []);
|
|
940
|
+
return naturalOrderby.orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
855
941
|
}
|
|
856
942
|
function combineImports(imports, exports, source) {
|
|
857
|
-
|
|
943
|
+
const combinedImports = naturalOrderby.orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
858
944
|
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
859
945
|
const hasImportInSource = (importName) => {
|
|
860
|
-
|
|
946
|
+
if (!source) {
|
|
947
|
+
return true;
|
|
948
|
+
}
|
|
949
|
+
const checker = (name2) => name2 && !!source.includes(name2);
|
|
861
950
|
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
862
951
|
};
|
|
863
952
|
if (Array.isArray(name)) {
|
|
@@ -865,6 +954,10 @@ function combineImports(imports, exports, source) {
|
|
|
865
954
|
}
|
|
866
955
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
867
956
|
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
957
|
+
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
|
|
958
|
+
if (prevByPathNameAndIsTypeOnly) {
|
|
959
|
+
return prev;
|
|
960
|
+
}
|
|
868
961
|
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
869
962
|
return prev;
|
|
870
963
|
}
|
|
@@ -886,43 +979,7 @@ function combineImports(imports, exports, source) {
|
|
|
886
979
|
}
|
|
887
980
|
return [...prev, curr];
|
|
888
981
|
}, []);
|
|
889
|
-
|
|
890
|
-
function createFileSource(file) {
|
|
891
|
-
let { source } = file;
|
|
892
|
-
if (!isExtensionAllowed(file.baseName)) {
|
|
893
|
-
return file.source;
|
|
894
|
-
}
|
|
895
|
-
const exports = file.exports ? combineExports(file.exports) : [];
|
|
896
|
-
const imports = file.imports ? combineImports(file.imports, exports, source) : [];
|
|
897
|
-
const importNodes = imports.map((item) => parser.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
898
|
-
const importSource = parser.print(importNodes);
|
|
899
|
-
const exportNodes = exports.map((item) => parser.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias }));
|
|
900
|
-
const exportSource = parser.print(exportNodes);
|
|
901
|
-
source = getEnvSource(file.source, file.env);
|
|
902
|
-
if (importSource) {
|
|
903
|
-
source = `${importSource}
|
|
904
|
-
${source}`;
|
|
905
|
-
}
|
|
906
|
-
if (exportSource) {
|
|
907
|
-
source = `${exportSource}
|
|
908
|
-
${source}`;
|
|
909
|
-
}
|
|
910
|
-
return source;
|
|
911
|
-
}
|
|
912
|
-
function searchAndReplace(options) {
|
|
913
|
-
const { text, replaceBy, prefix = "", key } = options;
|
|
914
|
-
const searchValues = options.searchValues?.(prefix, key) || [
|
|
915
|
-
`${prefix}["${key}"]`,
|
|
916
|
-
`${prefix}['${key}']`,
|
|
917
|
-
`${prefix}[\`${key}\`]`,
|
|
918
|
-
`${prefix}"${key}"`,
|
|
919
|
-
`${prefix}'${key}'`,
|
|
920
|
-
`${prefix}\`${key}\``,
|
|
921
|
-
new RegExp(`${prefix}${key}`, "g")
|
|
922
|
-
];
|
|
923
|
-
return searchValues.reduce((prev, searchValue) => {
|
|
924
|
-
return prev.toString().replaceAll(searchValue, replaceBy);
|
|
925
|
-
}, text);
|
|
982
|
+
return naturalOrderby.orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
|
|
926
983
|
}
|
|
927
984
|
function getEnvSource(source, env) {
|
|
928
985
|
if (!env) {
|
|
@@ -939,132 +996,128 @@ function getEnvSource(source, env) {
|
|
|
939
996
|
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
940
997
|
}
|
|
941
998
|
if (typeof replaceBy === "string") {
|
|
942
|
-
prev = searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
943
|
-
prev = searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
999
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
1000
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
944
1001
|
`, "ig"), ""), replaceBy, key });
|
|
945
1002
|
}
|
|
946
1003
|
return prev;
|
|
947
1004
|
}, source);
|
|
948
1005
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
#queue;
|
|
955
|
-
constructor(options) {
|
|
956
|
-
if (options) {
|
|
957
|
-
this.#task = options.task;
|
|
958
|
-
this.#queue = options.queue;
|
|
959
|
-
}
|
|
960
|
-
return this;
|
|
1006
|
+
var _emitter;
|
|
1007
|
+
var EventEmitter = class {
|
|
1008
|
+
constructor() {
|
|
1009
|
+
__privateAdd(this, _emitter, new events.EventEmitter());
|
|
1010
|
+
__privateGet(this, _emitter).setMaxListeners(100);
|
|
961
1011
|
}
|
|
962
|
-
|
|
963
|
-
|
|
1012
|
+
emit(eventName, ...eventArg) {
|
|
1013
|
+
__privateGet(this, _emitter).emit(eventName, ...eventArg);
|
|
964
1014
|
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
this.#cache.forEach((item) => {
|
|
968
|
-
files.push(...item.flat(1));
|
|
969
|
-
});
|
|
970
|
-
return files;
|
|
1015
|
+
on(eventName, handler) {
|
|
1016
|
+
__privateGet(this, _emitter).on(eventName, handler);
|
|
971
1017
|
}
|
|
972
|
-
|
|
973
|
-
|
|
1018
|
+
off(eventName, handler) {
|
|
1019
|
+
__privateGet(this, _emitter).off(eventName, handler);
|
|
974
1020
|
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
const resolvedFile = { id: crypto__default.default.randomUUID(), ...file };
|
|
978
|
-
this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
979
|
-
if (this.#queue) {
|
|
980
|
-
try {
|
|
981
|
-
await this.#queue.run(
|
|
982
|
-
async () => {
|
|
983
|
-
return this.#task?.(resolvedFile);
|
|
984
|
-
},
|
|
985
|
-
{ controller }
|
|
986
|
-
);
|
|
987
|
-
} catch {
|
|
988
|
-
return resolvedFile;
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
return resolvedFile;
|
|
1021
|
+
removeAll() {
|
|
1022
|
+
__privateGet(this, _emitter).removeAllListeners();
|
|
992
1023
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1024
|
+
};
|
|
1025
|
+
_emitter = new WeakMap();
|
|
1026
|
+
var _queue2, _workerCount, _maxParallel, _debug, _work, work_fn;
|
|
1027
|
+
var Queue = class {
|
|
1028
|
+
constructor(maxParallel, debug = false) {
|
|
1029
|
+
__privateAdd(this, _work);
|
|
1030
|
+
__privateAdd(this, _queue2, []);
|
|
1031
|
+
this.eventEmitter = new EventEmitter();
|
|
1032
|
+
__privateAdd(this, _workerCount, 0);
|
|
1033
|
+
__privateAdd(this, _maxParallel, void 0);
|
|
1034
|
+
__privateAdd(this, _debug, false);
|
|
1035
|
+
__privateSet(this, _maxParallel, maxParallel);
|
|
1036
|
+
__privateSet(this, _debug, debug);
|
|
1037
|
+
}
|
|
1038
|
+
run(job, options = { controller: new AbortController(), name: crypto2__default.default.randomUUID(), description: "" }) {
|
|
1039
|
+
return new Promise((resolve2, reject) => {
|
|
1040
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
1041
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
1042
|
+
__privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
|
|
1043
|
+
reject("Aborted");
|
|
1005
1044
|
});
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
async addIndexes(root, extName = ".ts", options = {}) {
|
|
1010
|
-
const files = await getIndexes(root, extName, options);
|
|
1011
|
-
if (!files) {
|
|
1012
|
-
return void 0;
|
|
1013
|
-
}
|
|
1014
|
-
return Promise.all(
|
|
1015
|
-
files.map((file) => {
|
|
1016
|
-
if (file.override) {
|
|
1017
|
-
return this.add(file);
|
|
1018
|
-
}
|
|
1019
|
-
return this.addOrAppend(file);
|
|
1020
|
-
})
|
|
1021
|
-
);
|
|
1022
|
-
}
|
|
1023
|
-
#append(path3, file) {
|
|
1024
|
-
const previousFiles = this.#cache.get(path3) || [];
|
|
1025
|
-
this.#cache.set(path3, [...previousFiles, file]);
|
|
1045
|
+
__privateGet(this, _queue2).push(item);
|
|
1046
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
1047
|
+
});
|
|
1026
1048
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1049
|
+
runSync(job, options = { controller: new AbortController(), name: crypto2__default.default.randomUUID(), description: "" }) {
|
|
1050
|
+
new Promise((resolve2, reject) => {
|
|
1051
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
1052
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
1053
|
+
__privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
|
|
1054
|
+
});
|
|
1055
|
+
__privateGet(this, _queue2).push(item);
|
|
1056
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
1031
1057
|
});
|
|
1032
|
-
return cache;
|
|
1033
1058
|
}
|
|
1034
|
-
get(
|
|
1035
|
-
return this
|
|
1059
|
+
get hasJobs() {
|
|
1060
|
+
return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue2).length > 0;
|
|
1036
1061
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
if (!cacheItem) {
|
|
1040
|
-
return;
|
|
1041
|
-
}
|
|
1042
|
-
this.#cache.delete(path3);
|
|
1062
|
+
get count() {
|
|
1063
|
+
return __privateGet(this, _workerCount);
|
|
1043
1064
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1065
|
+
};
|
|
1066
|
+
_queue2 = new WeakMap();
|
|
1067
|
+
_workerCount = new WeakMap();
|
|
1068
|
+
_maxParallel = new WeakMap();
|
|
1069
|
+
_debug = new WeakMap();
|
|
1070
|
+
_work = new WeakSet();
|
|
1071
|
+
work_fn = function() {
|
|
1072
|
+
if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
|
|
1073
|
+
return;
|
|
1051
1074
|
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1075
|
+
__privateWrapper(this, _workerCount)._++;
|
|
1076
|
+
let entry;
|
|
1077
|
+
while (entry = __privateGet(this, _queue2).shift()) {
|
|
1078
|
+
const { reject, resolve: resolve2, job, name, description } = entry;
|
|
1079
|
+
if (__privateGet(this, _debug)) {
|
|
1080
|
+
perf_hooks.performance.mark(name + "_start");
|
|
1081
|
+
}
|
|
1082
|
+
job().then((result) => {
|
|
1083
|
+
this.eventEmitter.emit("jobDone", result);
|
|
1084
|
+
resolve2(result);
|
|
1085
|
+
if (__privateGet(this, _debug)) {
|
|
1086
|
+
perf_hooks.performance.mark(name + "_stop");
|
|
1087
|
+
perf_hooks.performance.measure(description, name + "_start", name + "_stop");
|
|
1088
|
+
}
|
|
1089
|
+
}).catch((err) => {
|
|
1090
|
+
this.eventEmitter.emit("jobFailed", err);
|
|
1091
|
+
reject(err);
|
|
1092
|
+
});
|
|
1059
1093
|
}
|
|
1094
|
+
__privateWrapper(this, _workerCount)._--;
|
|
1060
1095
|
};
|
|
1061
1096
|
|
|
1062
|
-
// src/
|
|
1097
|
+
// src/utils/uniqueName.ts
|
|
1098
|
+
function setUniqueName(originalName, data) {
|
|
1099
|
+
let used = data[originalName] || 0;
|
|
1100
|
+
if (used) {
|
|
1101
|
+
data[originalName] = ++used;
|
|
1102
|
+
return originalName;
|
|
1103
|
+
}
|
|
1104
|
+
data[originalName] = 1;
|
|
1105
|
+
return originalName;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// src/errors.ts
|
|
1109
|
+
var PluginError = class extends Error {
|
|
1110
|
+
constructor(message, options) {
|
|
1111
|
+
super(message, { cause: options.cause });
|
|
1112
|
+
this.name = "PluginError";
|
|
1113
|
+
this.cause = options.cause;
|
|
1114
|
+
this.pluginManager = options.pluginManager;
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1063
1117
|
var ParallelPluginError = class extends Error {
|
|
1064
|
-
errors = [];
|
|
1065
|
-
pluginManager;
|
|
1066
1118
|
constructor(message, options) {
|
|
1067
1119
|
super(message, { cause: options.cause });
|
|
1120
|
+
this.errors = [];
|
|
1068
1121
|
this.name = "ParallelPluginError";
|
|
1069
1122
|
this.errors = options.errors;
|
|
1070
1123
|
this.pluginManager = options.pluginManager;
|
|
@@ -1084,30 +1137,54 @@ var ParallelPluginError = class extends Error {
|
|
|
1084
1137
|
})?.cause;
|
|
1085
1138
|
}
|
|
1086
1139
|
};
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1140
|
+
var SummaryError = class extends Error {
|
|
1141
|
+
constructor(message, options) {
|
|
1142
|
+
super(message, { cause: options.cause });
|
|
1143
|
+
this.name = "SummaryError";
|
|
1144
|
+
this.summary = options.summary || [];
|
|
1145
|
+
}
|
|
1146
|
+
};
|
|
1147
|
+
var Warning = class extends Error {
|
|
1092
1148
|
constructor(message, options) {
|
|
1093
|
-
super(message, { cause: options
|
|
1094
|
-
this.name = "
|
|
1095
|
-
this.cause = options.cause;
|
|
1096
|
-
this.pluginManager = options.pluginManager;
|
|
1149
|
+
super(message, { cause: options?.cause });
|
|
1150
|
+
this.name = "Warning";
|
|
1097
1151
|
}
|
|
1098
1152
|
};
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1153
|
+
var ValidationPluginError = class extends Error {
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1156
|
+
// src/utils/cache.ts
|
|
1157
|
+
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
1158
|
+
return {
|
|
1159
|
+
set(id, value) {
|
|
1160
|
+
Store[id] = [0, value];
|
|
1161
|
+
},
|
|
1162
|
+
get(id) {
|
|
1163
|
+
const item = Store[id];
|
|
1164
|
+
if (!item) {
|
|
1165
|
+
return null;
|
|
1166
|
+
}
|
|
1167
|
+
item[0] = 0;
|
|
1168
|
+
return item[1];
|
|
1169
|
+
},
|
|
1170
|
+
has(id) {
|
|
1171
|
+
const item = Store[id];
|
|
1172
|
+
if (!item) {
|
|
1173
|
+
return false;
|
|
1174
|
+
}
|
|
1175
|
+
item[0] = 0;
|
|
1176
|
+
return true;
|
|
1177
|
+
},
|
|
1178
|
+
delete(id) {
|
|
1179
|
+
return delete Store[id];
|
|
1109
1180
|
}
|
|
1110
|
-
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
// src/plugin.ts
|
|
1185
|
+
function createPlugin(factory2) {
|
|
1186
|
+
return (options) => {
|
|
1187
|
+
return factory2(options);
|
|
1111
1188
|
};
|
|
1112
1189
|
}
|
|
1113
1190
|
var pluginName = "core";
|
|
@@ -1116,6 +1193,8 @@ var definePlugin = createPlugin((options) => {
|
|
|
1116
1193
|
return {
|
|
1117
1194
|
name: pluginName,
|
|
1118
1195
|
options,
|
|
1196
|
+
key: ["controller", "core"],
|
|
1197
|
+
kind: "controller",
|
|
1119
1198
|
api() {
|
|
1120
1199
|
return {
|
|
1121
1200
|
get config() {
|
|
@@ -1124,18 +1203,18 @@ var definePlugin = createPlugin((options) => {
|
|
|
1124
1203
|
get plugins() {
|
|
1125
1204
|
return options.getPlugins();
|
|
1126
1205
|
},
|
|
1206
|
+
get plugin() {
|
|
1207
|
+
return options.plugin;
|
|
1208
|
+
},
|
|
1127
1209
|
logger,
|
|
1128
1210
|
fileManager,
|
|
1129
1211
|
pluginManager,
|
|
1130
1212
|
async addFile(...files) {
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
return fileManager.addOrAppend(file);
|
|
1137
|
-
})
|
|
1138
|
-
);
|
|
1213
|
+
const resolvedFiles = await fileManager.add(...files);
|
|
1214
|
+
if (!Array.isArray(resolvedFiles)) {
|
|
1215
|
+
return [resolvedFiles];
|
|
1216
|
+
}
|
|
1217
|
+
return resolvedFiles;
|
|
1139
1218
|
},
|
|
1140
1219
|
resolvePath,
|
|
1141
1220
|
resolveName,
|
|
@@ -1143,75 +1222,149 @@ var definePlugin = createPlugin((options) => {
|
|
|
1143
1222
|
};
|
|
1144
1223
|
},
|
|
1145
1224
|
resolvePath(baseName) {
|
|
1146
|
-
const root =
|
|
1147
|
-
return
|
|
1225
|
+
const root = path4__default.default.resolve(this.config.root, this.config.output.path);
|
|
1226
|
+
return path4__default.default.resolve(root, baseName);
|
|
1148
1227
|
},
|
|
1149
1228
|
resolveName(name) {
|
|
1150
1229
|
return name;
|
|
1151
1230
|
}
|
|
1152
1231
|
};
|
|
1153
1232
|
});
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1233
|
+
|
|
1234
|
+
// src/utils/executeStrategies.ts
|
|
1235
|
+
function hookSeq(promises) {
|
|
1236
|
+
return promises.filter(Boolean).reduce(
|
|
1237
|
+
(promise, func) => {
|
|
1238
|
+
if (typeof func !== "function") {
|
|
1239
|
+
throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
1240
|
+
}
|
|
1241
|
+
return promise.then((state) => {
|
|
1242
|
+
const calledFunc = func(state);
|
|
1243
|
+
if (calledFunc) {
|
|
1244
|
+
return calledFunc.then(Array.prototype.concat.bind(state));
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1247
|
+
},
|
|
1248
|
+
Promise.resolve([])
|
|
1249
|
+
);
|
|
1250
|
+
}
|
|
1251
|
+
function hookFirst(promises, nullCheck = (state) => state !== null) {
|
|
1252
|
+
let promise = Promise.resolve(null);
|
|
1253
|
+
for (const func of promises.filter(Boolean)) {
|
|
1254
|
+
promise = promise.then((state) => {
|
|
1255
|
+
if (nullCheck(state)) {
|
|
1256
|
+
return state;
|
|
1257
|
+
}
|
|
1258
|
+
const calledFunc = func(state);
|
|
1259
|
+
return calledFunc;
|
|
1260
|
+
});
|
|
1164
1261
|
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1262
|
+
return promise;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
// src/PromiseManager.ts
|
|
1266
|
+
var _options2;
|
|
1267
|
+
var PromiseManager = class {
|
|
1268
|
+
constructor(options = {}) {
|
|
1269
|
+
__privateAdd(this, _options2, {});
|
|
1270
|
+
__privateSet(this, _options2, options);
|
|
1271
|
+
return this;
|
|
1167
1272
|
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1273
|
+
run(strategy, promises) {
|
|
1274
|
+
if (strategy === "seq") {
|
|
1275
|
+
return hookSeq(promises);
|
|
1276
|
+
}
|
|
1277
|
+
if (strategy === "first") {
|
|
1278
|
+
return hookFirst(promises, __privateGet(this, _options2).nullCheck);
|
|
1279
|
+
}
|
|
1280
|
+
throw new Error(`${strategy} not implemented`);
|
|
1170
1281
|
}
|
|
1171
1282
|
};
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
const api = plugin.api.call(context);
|
|
1179
|
-
return {
|
|
1180
|
-
...plugin,
|
|
1181
|
-
key,
|
|
1182
|
-
api
|
|
1183
|
-
};
|
|
1184
|
-
}
|
|
1185
|
-
return {
|
|
1186
|
-
...plugin,
|
|
1187
|
-
key
|
|
1188
|
-
};
|
|
1283
|
+
_options2 = new WeakMap();
|
|
1284
|
+
function isPromise(result) {
|
|
1285
|
+
return !!result && typeof result?.then === "function";
|
|
1286
|
+
}
|
|
1287
|
+
function isPromiseRejectedResult(result) {
|
|
1288
|
+
return result.status === "rejected";
|
|
1189
1289
|
}
|
|
1190
1290
|
|
|
1191
|
-
// src/
|
|
1192
|
-
var
|
|
1193
|
-
validate: 1,
|
|
1194
|
-
buildStart: 1,
|
|
1195
|
-
resolvePath: 1,
|
|
1196
|
-
resolveName: 1,
|
|
1197
|
-
load: 1,
|
|
1198
|
-
transform: 1,
|
|
1199
|
-
writeFile: 1,
|
|
1200
|
-
buildEnd: 1
|
|
1201
|
-
};
|
|
1202
|
-
var hooks = Object.keys(hookNames);
|
|
1291
|
+
// src/PluginManager.ts
|
|
1292
|
+
var _core, _usedPluginNames, _promiseManager, _getSortedPlugins, getSortedPlugins_fn, _addExecutedToCallStack, addExecutedToCallStack_fn, _execute, execute_fn, _executeSync, executeSync_fn, _catcher, catcher_fn, _parse, parse_fn;
|
|
1203
1293
|
var PluginManager = class {
|
|
1204
|
-
plugins;
|
|
1205
|
-
fileManager;
|
|
1206
|
-
eventEmitter = new EventEmitter();
|
|
1207
|
-
queue;
|
|
1208
|
-
executed = [];
|
|
1209
|
-
logger;
|
|
1210
|
-
#core;
|
|
1211
1294
|
constructor(config, options) {
|
|
1295
|
+
__privateAdd(this, _getSortedPlugins);
|
|
1296
|
+
__privateAdd(this, _addExecutedToCallStack);
|
|
1297
|
+
/**
|
|
1298
|
+
* Run an async plugin hook and return the result.
|
|
1299
|
+
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
1300
|
+
* @param args Arguments passed to the plugin hook.
|
|
1301
|
+
* @param plugin The actual pluginObject to run.
|
|
1302
|
+
*/
|
|
1303
|
+
// Implementation signature
|
|
1304
|
+
__privateAdd(this, _execute);
|
|
1305
|
+
/**
|
|
1306
|
+
* Run a sync plugin hook and return the result.
|
|
1307
|
+
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
1308
|
+
* @param args Arguments passed to the plugin hook.
|
|
1309
|
+
* @param plugin The acutal plugin
|
|
1310
|
+
* @param replaceContext When passed, the plugin context can be overridden.
|
|
1311
|
+
*/
|
|
1312
|
+
__privateAdd(this, _executeSync);
|
|
1313
|
+
__privateAdd(this, _catcher);
|
|
1314
|
+
__privateAdd(this, _parse);
|
|
1315
|
+
this.eventEmitter = new EventEmitter();
|
|
1316
|
+
this.executed = [];
|
|
1317
|
+
__privateAdd(this, _core, void 0);
|
|
1318
|
+
__privateAdd(this, _usedPluginNames, {});
|
|
1319
|
+
__privateAdd(this, _promiseManager, void 0);
|
|
1320
|
+
this.resolvePath = (params) => {
|
|
1321
|
+
if (params.pluginKey) {
|
|
1322
|
+
const paths = this.hookForPluginSync({
|
|
1323
|
+
pluginKey: params.pluginKey,
|
|
1324
|
+
hookName: "resolvePath",
|
|
1325
|
+
parameters: [params.baseName, params.directory, params.options]
|
|
1326
|
+
});
|
|
1327
|
+
if (paths && paths?.length > 1) {
|
|
1328
|
+
throw new Error(
|
|
1329
|
+
`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1330
|
+
|
|
1331
|
+
Paths: ${JSON.stringify(paths, void 0, 2)}`
|
|
1332
|
+
);
|
|
1333
|
+
}
|
|
1334
|
+
return paths?.at(0);
|
|
1335
|
+
}
|
|
1336
|
+
return this.hookFirstSync({
|
|
1337
|
+
hookName: "resolvePath",
|
|
1338
|
+
parameters: [params.baseName, params.directory, params.options]
|
|
1339
|
+
}).result;
|
|
1340
|
+
};
|
|
1341
|
+
this.resolveName = (params) => {
|
|
1342
|
+
if (params.pluginKey) {
|
|
1343
|
+
const names = this.hookForPluginSync({
|
|
1344
|
+
pluginKey: params.pluginKey,
|
|
1345
|
+
hookName: "resolveName",
|
|
1346
|
+
parameters: [params.name, params.type]
|
|
1347
|
+
});
|
|
1348
|
+
if (names && names?.length > 1) {
|
|
1349
|
+
throw new Error(
|
|
1350
|
+
`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1351
|
+
|
|
1352
|
+
Names: ${JSON.stringify(names, void 0, 2)}`
|
|
1353
|
+
);
|
|
1354
|
+
}
|
|
1355
|
+
return transformReservedWord(names?.at(0) || params.name);
|
|
1356
|
+
}
|
|
1357
|
+
const name = this.hookFirstSync({
|
|
1358
|
+
hookName: "resolveName",
|
|
1359
|
+
parameters: [params.name, params.type]
|
|
1360
|
+
}).result;
|
|
1361
|
+
return transformReservedWord(name);
|
|
1362
|
+
};
|
|
1212
1363
|
this.logger = options.logger;
|
|
1213
|
-
this.queue = new Queue(100,
|
|
1214
|
-
this.fileManager = new FileManager({ task: options.task, queue: this.queue });
|
|
1364
|
+
this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
|
|
1365
|
+
this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
|
|
1366
|
+
__privateSet(this, _promiseManager, new PromiseManager({ nullCheck: (state) => !!state?.result }));
|
|
1367
|
+
const plugins = config.plugins || [];
|
|
1215
1368
|
const core = definePlugin({
|
|
1216
1369
|
config,
|
|
1217
1370
|
logger: this.logger,
|
|
@@ -1219,44 +1372,14 @@ var PluginManager = class {
|
|
|
1219
1372
|
fileManager: this.fileManager,
|
|
1220
1373
|
resolvePath: this.resolvePath.bind(this),
|
|
1221
1374
|
resolveName: this.resolveName.bind(this),
|
|
1222
|
-
getPlugins: this
|
|
1223
|
-
|
|
1375
|
+
getPlugins: __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).bind(this)
|
|
1376
|
+
});
|
|
1377
|
+
__privateSet(this, _core, __privateMethod(this, _parse, parse_fn).call(this, core, this, core.api.call(null)));
|
|
1378
|
+
this.plugins = [__privateGet(this, _core), ...plugins].map((plugin) => {
|
|
1379
|
+
return __privateMethod(this, _parse, parse_fn).call(this, plugin, this, __privateGet(this, _core).api);
|
|
1224
1380
|
});
|
|
1225
|
-
this.#core = pluginParser(core, core.api.call(null));
|
|
1226
|
-
this.plugins = [this.#core, ...config.plugins || []].reduce((prev, plugin) => {
|
|
1227
|
-
const convertedApi = pluginParser(plugin, this.#core?.api);
|
|
1228
|
-
return [...prev, convertedApi];
|
|
1229
|
-
}, []);
|
|
1230
1381
|
return this;
|
|
1231
1382
|
}
|
|
1232
|
-
resolvePath = (params) => {
|
|
1233
|
-
if (params.pluginName) {
|
|
1234
|
-
return this.hookForPluginSync({
|
|
1235
|
-
pluginName: params.pluginName,
|
|
1236
|
-
hookName: "resolvePath",
|
|
1237
|
-
parameters: [params.baseName, params.directory, params.options]
|
|
1238
|
-
});
|
|
1239
|
-
}
|
|
1240
|
-
return this.hookFirstSync({
|
|
1241
|
-
hookName: "resolvePath",
|
|
1242
|
-
parameters: [params.baseName, params.directory, params.options]
|
|
1243
|
-
}).result;
|
|
1244
|
-
};
|
|
1245
|
-
resolveName = (params) => {
|
|
1246
|
-
if (params.pluginName) {
|
|
1247
|
-
const name2 = this.hookForPluginSync({
|
|
1248
|
-
pluginName: params.pluginName,
|
|
1249
|
-
hookName: "resolveName",
|
|
1250
|
-
parameters: [params.name, params.type]
|
|
1251
|
-
});
|
|
1252
|
-
return transformReservedWord(name2 || params.name);
|
|
1253
|
-
}
|
|
1254
|
-
const name = this.hookFirstSync({
|
|
1255
|
-
hookName: "resolveName",
|
|
1256
|
-
parameters: [params.name, params.type]
|
|
1257
|
-
}).result;
|
|
1258
|
-
return transformReservedWord(name);
|
|
1259
|
-
};
|
|
1260
1383
|
on(eventName, handler) {
|
|
1261
1384
|
this.eventEmitter.on(eventName, handler);
|
|
1262
1385
|
}
|
|
@@ -1264,49 +1387,49 @@ var PluginManager = class {
|
|
|
1264
1387
|
* Run only hook for a specific plugin name
|
|
1265
1388
|
*/
|
|
1266
1389
|
hookForPlugin({
|
|
1267
|
-
|
|
1390
|
+
pluginKey,
|
|
1268
1391
|
hookName,
|
|
1269
1392
|
parameters
|
|
1270
1393
|
}) {
|
|
1271
|
-
const
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1394
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1395
|
+
const promises = plugins.map((plugin) => {
|
|
1396
|
+
return __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1397
|
+
strategy: "hookFirst",
|
|
1398
|
+
hookName,
|
|
1399
|
+
parameters,
|
|
1400
|
+
plugin
|
|
1401
|
+
});
|
|
1402
|
+
}).filter(Boolean);
|
|
1403
|
+
return Promise.all(promises);
|
|
1278
1404
|
}
|
|
1279
1405
|
hookForPluginSync({
|
|
1280
|
-
|
|
1406
|
+
pluginKey,
|
|
1281
1407
|
hookName,
|
|
1282
1408
|
parameters
|
|
1283
1409
|
}) {
|
|
1284
|
-
const
|
|
1285
|
-
return
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1410
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1411
|
+
return plugins.map((plugin) => {
|
|
1412
|
+
return __privateMethod(this, _executeSync, executeSync_fn).call(this, {
|
|
1413
|
+
strategy: "hookFirst",
|
|
1414
|
+
hookName,
|
|
1415
|
+
parameters,
|
|
1416
|
+
plugin
|
|
1417
|
+
});
|
|
1418
|
+
}).filter(Boolean);
|
|
1291
1419
|
}
|
|
1292
1420
|
/**
|
|
1293
1421
|
* Chains, first non-null result stops and returns
|
|
1294
1422
|
*/
|
|
1295
|
-
hookFirst({
|
|
1423
|
+
async hookFirst({
|
|
1296
1424
|
hookName,
|
|
1297
1425
|
parameters,
|
|
1298
1426
|
skipped
|
|
1299
1427
|
}) {
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
promise = promise.then(async (parseResult) => {
|
|
1306
|
-
if (parseResult?.result != null) {
|
|
1307
|
-
return parseResult;
|
|
1308
|
-
}
|
|
1309
|
-
const value = await this.#execute({
|
|
1428
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).filter((plugin) => {
|
|
1429
|
+
return skipped ? skipped.has(plugin) : true;
|
|
1430
|
+
}).map((plugin) => {
|
|
1431
|
+
return async () => {
|
|
1432
|
+
const value = await __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1310
1433
|
strategy: "hookFirst",
|
|
1311
1434
|
hookName,
|
|
1312
1435
|
parameters,
|
|
@@ -1318,9 +1441,9 @@ var PluginManager = class {
|
|
|
1318
1441
|
result: value
|
|
1319
1442
|
}
|
|
1320
1443
|
);
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
return
|
|
1444
|
+
};
|
|
1445
|
+
});
|
|
1446
|
+
return __privateGet(this, _promiseManager).run("first", promises);
|
|
1324
1447
|
}
|
|
1325
1448
|
/**
|
|
1326
1449
|
* Chains, first non-null result stops and returns
|
|
@@ -1331,12 +1454,12 @@ var PluginManager = class {
|
|
|
1331
1454
|
skipped
|
|
1332
1455
|
}) {
|
|
1333
1456
|
let parseResult = null;
|
|
1334
|
-
for (const plugin of this
|
|
1457
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1335
1458
|
if (skipped && skipped.has(plugin)) {
|
|
1336
1459
|
continue;
|
|
1337
1460
|
}
|
|
1338
1461
|
parseResult = {
|
|
1339
|
-
result: this
|
|
1462
|
+
result: __privateMethod(this, _executeSync, executeSync_fn).call(this, {
|
|
1340
1463
|
strategy: "hookFirst",
|
|
1341
1464
|
hookName,
|
|
1342
1465
|
parameters,
|
|
@@ -1358,8 +1481,8 @@ var PluginManager = class {
|
|
|
1358
1481
|
parameters
|
|
1359
1482
|
}) {
|
|
1360
1483
|
const parallelPromises = [];
|
|
1361
|
-
for (const plugin of this
|
|
1362
|
-
const promise = this
|
|
1484
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1485
|
+
const promise = __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
|
|
1363
1486
|
if (promise) {
|
|
1364
1487
|
parallelPromises.push(promise);
|
|
1365
1488
|
}
|
|
@@ -1386,177 +1509,209 @@ var PluginManager = class {
|
|
|
1386
1509
|
}) {
|
|
1387
1510
|
const [argument0, ...rest] = parameters;
|
|
1388
1511
|
let promise = Promise.resolve(argument0);
|
|
1389
|
-
for (const plugin of this
|
|
1512
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1390
1513
|
promise = promise.then((arg0) => {
|
|
1391
|
-
const value = this
|
|
1514
|
+
const value = __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1392
1515
|
strategy: "hookReduceArg0",
|
|
1393
1516
|
hookName,
|
|
1394
1517
|
parameters: [arg0, ...rest],
|
|
1395
1518
|
plugin
|
|
1396
1519
|
});
|
|
1397
1520
|
return value;
|
|
1398
|
-
}).then((result) => reduce.call(this
|
|
1521
|
+
}).then((result) => reduce.call(__privateGet(this, _core).api, argument0, result, plugin));
|
|
1399
1522
|
}
|
|
1400
1523
|
return promise;
|
|
1401
1524
|
}
|
|
1402
1525
|
/**
|
|
1403
1526
|
* Chains plugins
|
|
1404
1527
|
*/
|
|
1405
|
-
hookSeq({ hookName, parameters }) {
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
parameters,
|
|
1413
|
-
plugin
|
|
1414
|
-
});
|
|
1528
|
+
async hookSeq({ hookName, parameters }) {
|
|
1529
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1530
|
+
return () => __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1531
|
+
strategy: "hookSeq",
|
|
1532
|
+
hookName,
|
|
1533
|
+
parameters,
|
|
1534
|
+
plugin
|
|
1415
1535
|
});
|
|
1416
|
-
}
|
|
1417
|
-
return
|
|
1418
|
-
}
|
|
1419
|
-
#getSortedPlugins(hookName) {
|
|
1420
|
-
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1421
|
-
if (hookName) {
|
|
1422
|
-
return plugins.filter((item) => item[hookName]);
|
|
1423
|
-
}
|
|
1424
|
-
return plugins;
|
|
1536
|
+
});
|
|
1537
|
+
return __privateGet(this, _promiseManager).run("seq", promises);
|
|
1425
1538
|
}
|
|
1426
|
-
|
|
1539
|
+
getPluginsByKey(hookName, pluginKey) {
|
|
1427
1540
|
const plugins = [...this.plugins];
|
|
1428
|
-
const
|
|
1429
|
-
|
|
1430
|
-
|
|
1541
|
+
const [searchKind, searchPluginName, searchIdentifier] = pluginKey;
|
|
1542
|
+
const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
|
|
1543
|
+
const [kind, name, identifier] = item.key;
|
|
1544
|
+
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
1545
|
+
const kindCheck = kind === searchKind;
|
|
1546
|
+
const nameCheck = name === searchPluginName;
|
|
1547
|
+
if (searchIdentifier) {
|
|
1548
|
+
return identifierCheck && kindCheck && nameCheck;
|
|
1549
|
+
}
|
|
1550
|
+
return kindCheck && nameCheck;
|
|
1551
|
+
});
|
|
1552
|
+
if (!pluginByPluginName?.length) {
|
|
1553
|
+
const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
|
|
1554
|
+
if (this.logger.logLevel === "info") {
|
|
1555
|
+
if (corePlugin) {
|
|
1556
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
|
|
1557
|
+
} else {
|
|
1558
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
return corePlugin ? [corePlugin] : [];
|
|
1431
1562
|
}
|
|
1432
1563
|
return pluginByPluginName;
|
|
1433
1564
|
}
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
/**
|
|
1441
|
-
* Run an async plugin hook and return the result.
|
|
1442
|
-
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
1443
|
-
* @param args Arguments passed to the plugin hook.
|
|
1444
|
-
* @param plugin The actual pluginObject to run.
|
|
1445
|
-
*/
|
|
1446
|
-
// Implementation signature
|
|
1447
|
-
#execute({
|
|
1448
|
-
strategy,
|
|
1449
|
-
hookName,
|
|
1450
|
-
parameters,
|
|
1451
|
-
plugin
|
|
1452
|
-
}) {
|
|
1453
|
-
const hook = plugin[hookName];
|
|
1454
|
-
let output;
|
|
1455
|
-
if (!hook) {
|
|
1456
|
-
return null;
|
|
1565
|
+
static getDependedPlugins(plugins, dependedPluginNames) {
|
|
1566
|
+
let pluginNames = [];
|
|
1567
|
+
if (typeof dependedPluginNames === "string") {
|
|
1568
|
+
pluginNames = [dependedPluginNames];
|
|
1569
|
+
} else {
|
|
1570
|
+
pluginNames = dependedPluginNames;
|
|
1457
1571
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
if (
|
|
1461
|
-
|
|
1462
|
-
if (isPromise(possiblePromiseResult)) {
|
|
1463
|
-
return Promise.resolve(possiblePromiseResult);
|
|
1464
|
-
}
|
|
1465
|
-
return possiblePromiseResult;
|
|
1572
|
+
return pluginNames.map((pluginName2) => {
|
|
1573
|
+
const plugin = plugins.find((plugin2) => plugin2.name === pluginName2);
|
|
1574
|
+
if (!plugin) {
|
|
1575
|
+
throw new ValidationPluginError(`This plugin depends on the ${pluginName2} plugin.`);
|
|
1466
1576
|
}
|
|
1467
|
-
return
|
|
1468
|
-
}).then((result) => {
|
|
1469
|
-
output = result;
|
|
1470
|
-
return result;
|
|
1471
|
-
}).catch((e) => {
|
|
1472
|
-
this.#catcher(e, plugin, hookName);
|
|
1473
|
-
return null;
|
|
1474
|
-
}).finally(() => {
|
|
1475
|
-
this.#addExecutedToCallStack({
|
|
1476
|
-
parameters,
|
|
1477
|
-
output,
|
|
1478
|
-
strategy,
|
|
1479
|
-
hookName,
|
|
1480
|
-
plugin
|
|
1481
|
-
});
|
|
1577
|
+
return plugin;
|
|
1482
1578
|
});
|
|
1483
|
-
return task;
|
|
1484
1579
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
return null;
|
|
1502
|
-
}
|
|
1503
|
-
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1504
|
-
try {
|
|
1505
|
-
if (typeof hook === "function") {
|
|
1506
|
-
const fn = hook.apply(this.#core.api, parameters);
|
|
1507
|
-
output = fn;
|
|
1508
|
-
return fn;
|
|
1580
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
1581
|
+
static get hooks() {
|
|
1582
|
+
return ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
_core = new WeakMap();
|
|
1586
|
+
_usedPluginNames = new WeakMap();
|
|
1587
|
+
_promiseManager = new WeakMap();
|
|
1588
|
+
_getSortedPlugins = new WeakSet();
|
|
1589
|
+
getSortedPlugins_fn = function(hookName) {
|
|
1590
|
+
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1591
|
+
if (hookName) {
|
|
1592
|
+
if (this.logger.logLevel === "info") {
|
|
1593
|
+
const containsHookName = plugins.some((item) => item[hookName]);
|
|
1594
|
+
if (!containsHookName) {
|
|
1595
|
+
this.logger.warn(`No hook ${hookName} found`);
|
|
1509
1596
|
}
|
|
1510
|
-
output = hook;
|
|
1511
|
-
return hook;
|
|
1512
|
-
} catch (e) {
|
|
1513
|
-
this.#catcher(e, plugin, hookName);
|
|
1514
|
-
return null;
|
|
1515
|
-
} finally {
|
|
1516
|
-
this.#addExecutedToCallStack({
|
|
1517
|
-
parameters,
|
|
1518
|
-
output,
|
|
1519
|
-
strategy,
|
|
1520
|
-
hookName,
|
|
1521
|
-
plugin
|
|
1522
|
-
});
|
|
1523
1597
|
}
|
|
1598
|
+
return plugins.filter((item) => item[hookName]);
|
|
1524
1599
|
}
|
|
1525
|
-
|
|
1526
|
-
const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
|
|
1527
|
-
`;
|
|
1528
|
-
const pluginError = new PluginError(text, { cause: e, pluginManager: this });
|
|
1529
|
-
this.eventEmitter.emit("error", pluginError);
|
|
1530
|
-
throw pluginError;
|
|
1531
|
-
}
|
|
1600
|
+
return plugins;
|
|
1532
1601
|
};
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1602
|
+
_addExecutedToCallStack = new WeakSet();
|
|
1603
|
+
addExecutedToCallStack_fn = function(executer) {
|
|
1604
|
+
if (executer) {
|
|
1605
|
+
this.eventEmitter.emit("executed", executer);
|
|
1606
|
+
this.executed.push(executer);
|
|
1607
|
+
}
|
|
1538
1608
|
};
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1609
|
+
_execute = new WeakSet();
|
|
1610
|
+
execute_fn = function({
|
|
1611
|
+
strategy,
|
|
1612
|
+
hookName,
|
|
1613
|
+
parameters,
|
|
1614
|
+
plugin
|
|
1615
|
+
}) {
|
|
1616
|
+
const hook = plugin[hookName];
|
|
1617
|
+
let output;
|
|
1618
|
+
if (!hook) {
|
|
1619
|
+
return null;
|
|
1620
|
+
}
|
|
1621
|
+
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1622
|
+
const task = Promise.resolve().then(() => {
|
|
1623
|
+
if (typeof hook === "function") {
|
|
1624
|
+
const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
1625
|
+
if (isPromise(possiblePromiseResult)) {
|
|
1626
|
+
return Promise.resolve(possiblePromiseResult);
|
|
1627
|
+
}
|
|
1628
|
+
return possiblePromiseResult;
|
|
1629
|
+
}
|
|
1630
|
+
return hook;
|
|
1631
|
+
}).then((result) => {
|
|
1632
|
+
output = result;
|
|
1633
|
+
return result;
|
|
1634
|
+
}).catch((e) => {
|
|
1635
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1636
|
+
return null;
|
|
1637
|
+
}).finally(() => {
|
|
1638
|
+
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1639
|
+
parameters,
|
|
1640
|
+
output,
|
|
1641
|
+
strategy,
|
|
1642
|
+
hookName,
|
|
1643
|
+
plugin
|
|
1644
|
+
});
|
|
1552
1645
|
});
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1646
|
+
return task;
|
|
1647
|
+
};
|
|
1648
|
+
_executeSync = new WeakSet();
|
|
1649
|
+
executeSync_fn = function({
|
|
1650
|
+
strategy,
|
|
1651
|
+
hookName,
|
|
1652
|
+
parameters,
|
|
1653
|
+
plugin
|
|
1654
|
+
}) {
|
|
1655
|
+
const hook = plugin[hookName];
|
|
1656
|
+
let output;
|
|
1657
|
+
if (!hook) {
|
|
1658
|
+
return null;
|
|
1659
|
+
}
|
|
1660
|
+
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1661
|
+
try {
|
|
1662
|
+
if (typeof hook === "function") {
|
|
1663
|
+
const fn = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
1664
|
+
output = fn;
|
|
1665
|
+
return fn;
|
|
1666
|
+
}
|
|
1667
|
+
output = hook;
|
|
1668
|
+
return hook;
|
|
1669
|
+
} catch (e) {
|
|
1670
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1671
|
+
return null;
|
|
1672
|
+
} finally {
|
|
1673
|
+
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1674
|
+
parameters,
|
|
1675
|
+
output,
|
|
1676
|
+
strategy,
|
|
1677
|
+
hookName,
|
|
1678
|
+
plugin
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
};
|
|
1682
|
+
_catcher = new WeakSet();
|
|
1683
|
+
catcher_fn = function(e, plugin, hookName) {
|
|
1684
|
+
const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
|
|
1685
|
+
`;
|
|
1686
|
+
const pluginError = new PluginError(text, { cause: e, pluginManager: this });
|
|
1687
|
+
this.eventEmitter.emit("error", pluginError);
|
|
1688
|
+
throw pluginError;
|
|
1689
|
+
};
|
|
1690
|
+
_parse = new WeakSet();
|
|
1691
|
+
parse_fn = function(plugin, pluginManager, context) {
|
|
1692
|
+
const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
|
|
1693
|
+
setUniqueName(plugin.name, usedPluginNames);
|
|
1694
|
+
const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
1695
|
+
if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
|
|
1696
|
+
pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
|
|
1697
|
+
}
|
|
1698
|
+
if (!plugin.transform) {
|
|
1699
|
+
plugin.transform = function transform(code) {
|
|
1700
|
+
return code;
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
if (plugin.api && typeof plugin.api === "function") {
|
|
1704
|
+
const api = plugin.api.call(context);
|
|
1705
|
+
return {
|
|
1706
|
+
...plugin,
|
|
1707
|
+
key,
|
|
1708
|
+
api
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
1711
|
+
return {
|
|
1712
|
+
...plugin,
|
|
1713
|
+
key
|
|
1714
|
+
};
|
|
1560
1715
|
};
|
|
1561
1716
|
|
|
1562
1717
|
// src/build.ts
|
|
@@ -1564,13 +1719,13 @@ async function transformReducer(_previousCode, result, _plugin) {
|
|
|
1564
1719
|
return result;
|
|
1565
1720
|
}
|
|
1566
1721
|
async function build(options) {
|
|
1567
|
-
const { config,
|
|
1722
|
+
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
1568
1723
|
try {
|
|
1569
|
-
if (
|
|
1724
|
+
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
1570
1725
|
await read(config.input.path);
|
|
1571
1726
|
}
|
|
1572
1727
|
} catch (e) {
|
|
1573
|
-
if (
|
|
1728
|
+
if (isInputPath(config)) {
|
|
1574
1729
|
throw new Error(
|
|
1575
1730
|
"Cannot read file/URL defined in `input.path` or set with `kubb generate PATH` in the CLI of your Kubb config " + pc3__default.default.dim(config.input.path),
|
|
1576
1731
|
{
|
|
@@ -1583,11 +1738,11 @@ async function build(options) {
|
|
|
1583
1738
|
await clean(config.output.path);
|
|
1584
1739
|
}
|
|
1585
1740
|
const queueTask = async (file) => {
|
|
1586
|
-
const { path:
|
|
1587
|
-
let code =
|
|
1741
|
+
const { path: path5 } = file;
|
|
1742
|
+
let code = FileManager.getSource(file);
|
|
1588
1743
|
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1589
1744
|
hookName: "load",
|
|
1590
|
-
parameters: [
|
|
1745
|
+
parameters: [path5]
|
|
1591
1746
|
});
|
|
1592
1747
|
if (loadedResult && isPromise(loadedResult)) {
|
|
1593
1748
|
code = await loadedResult;
|
|
@@ -1598,28 +1753,53 @@ async function build(options) {
|
|
|
1598
1753
|
if (code) {
|
|
1599
1754
|
const transformedCode = await pluginManager.hookReduceArg0({
|
|
1600
1755
|
hookName: "transform",
|
|
1601
|
-
parameters: [code,
|
|
1756
|
+
parameters: [code, path5],
|
|
1602
1757
|
reduce: transformReducer
|
|
1603
1758
|
});
|
|
1604
1759
|
if (config.output.write || config.output.write === void 0) {
|
|
1605
|
-
|
|
1760
|
+
if (file.meta?.pluginKey) {
|
|
1761
|
+
return pluginManager.hookForPlugin({
|
|
1762
|
+
pluginKey: file.meta?.pluginKey,
|
|
1763
|
+
hookName: "writeFile",
|
|
1764
|
+
parameters: [transformedCode, path5]
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
return pluginManager.hookFirst({
|
|
1606
1768
|
hookName: "writeFile",
|
|
1607
|
-
parameters: [transformedCode,
|
|
1769
|
+
parameters: [transformedCode, path5]
|
|
1608
1770
|
});
|
|
1609
1771
|
}
|
|
1610
1772
|
}
|
|
1611
1773
|
};
|
|
1612
|
-
const pluginManager = new PluginManager(config, {
|
|
1774
|
+
const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
|
|
1613
1775
|
const { plugins, fileManager } = pluginManager;
|
|
1614
1776
|
pluginManager.on("execute", (executer) => {
|
|
1777
|
+
const { hookName, parameters, plugin } = executer;
|
|
1778
|
+
if (hookName === "writeFile" && logger.spinner) {
|
|
1779
|
+
const [code] = parameters;
|
|
1780
|
+
if (logger.logLevel === LogLevel.info) {
|
|
1781
|
+
logger.spinner.start(`\u{1F4BE} Writing`);
|
|
1782
|
+
}
|
|
1783
|
+
if (logger.logLevel === "debug") {
|
|
1784
|
+
logger.info(`PluginKey ${pc3__default.default.dim(JSON.stringify(plugin.key))}
|
|
1785
|
+
with source
|
|
1786
|
+
|
|
1787
|
+
${code}`);
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
});
|
|
1791
|
+
pluginManager.on("executed", (executer) => {
|
|
1615
1792
|
const { hookName, plugin, output, parameters } = executer;
|
|
1616
1793
|
const messsage = `${randomPicoColour(plugin.name)} Executing ${hookName}`;
|
|
1617
|
-
if (logLevel === LogLevel.info) {
|
|
1618
|
-
if (
|
|
1794
|
+
if (logger.logLevel === LogLevel.info && logger.spinner) {
|
|
1795
|
+
if (hookName === "writeFile") {
|
|
1796
|
+
const [_code, path5] = parameters;
|
|
1797
|
+
logger.spinner.suffixText = pc3__default.default.dim(path5);
|
|
1798
|
+
} else {
|
|
1619
1799
|
logger.spinner.suffixText = messsage;
|
|
1620
1800
|
}
|
|
1621
1801
|
}
|
|
1622
|
-
if (logLevel === LogLevel.debug) {
|
|
1802
|
+
if (logger.logLevel === LogLevel.debug) {
|
|
1623
1803
|
logger.info(messsage);
|
|
1624
1804
|
const logs = [
|
|
1625
1805
|
parameters && `${pc3__default.default.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
|
|
@@ -1639,93 +1819,95 @@ async function build(options) {
|
|
|
1639
1819
|
parameters: [config]
|
|
1640
1820
|
});
|
|
1641
1821
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
return options;
|
|
1822
|
+
if (!fileManager.isExecuting && logger.spinner) {
|
|
1823
|
+
logger.spinner.suffixText = "";
|
|
1824
|
+
logger.spinner.succeed(`\u{1F4BE} Writing completed`);
|
|
1825
|
+
}
|
|
1826
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1648
1827
|
}
|
|
1649
1828
|
|
|
1650
|
-
// src/
|
|
1829
|
+
// src/Generator.ts
|
|
1830
|
+
var _options3, _context;
|
|
1651
1831
|
var Generator = class {
|
|
1652
|
-
#options = {};
|
|
1653
|
-
#context = {};
|
|
1654
1832
|
constructor(options, context) {
|
|
1833
|
+
__privateAdd(this, _options3, {});
|
|
1834
|
+
__privateAdd(this, _context, {});
|
|
1655
1835
|
if (context) {
|
|
1656
|
-
this
|
|
1836
|
+
__privateSet(this, _context, context);
|
|
1657
1837
|
}
|
|
1658
1838
|
if (options) {
|
|
1659
|
-
this
|
|
1839
|
+
__privateSet(this, _options3, options);
|
|
1660
1840
|
}
|
|
1661
1841
|
return this;
|
|
1662
1842
|
}
|
|
1663
1843
|
get options() {
|
|
1664
|
-
return this
|
|
1844
|
+
return __privateGet(this, _options3);
|
|
1665
1845
|
}
|
|
1666
1846
|
get context() {
|
|
1667
|
-
return this
|
|
1847
|
+
return __privateGet(this, _context);
|
|
1668
1848
|
}
|
|
1669
1849
|
set options(options) {
|
|
1670
|
-
this
|
|
1850
|
+
__privateSet(this, _options3, { ...__privateGet(this, _options3), ...options });
|
|
1671
1851
|
}
|
|
1672
1852
|
};
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
var SchemaGenerator = class extends Generator {
|
|
1676
|
-
};
|
|
1853
|
+
_options3 = new WeakMap();
|
|
1854
|
+
_context = new WeakMap();
|
|
1677
1855
|
|
|
1678
1856
|
// ../../node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
|
|
1679
1857
|
var Node = class {
|
|
1680
|
-
value;
|
|
1681
|
-
next;
|
|
1682
1858
|
constructor(value) {
|
|
1859
|
+
__publicField(this, "value");
|
|
1860
|
+
__publicField(this, "next");
|
|
1683
1861
|
this.value = value;
|
|
1684
1862
|
}
|
|
1685
1863
|
};
|
|
1864
|
+
var _head, _tail, _size;
|
|
1686
1865
|
var Queue2 = class {
|
|
1687
|
-
#head;
|
|
1688
|
-
#tail;
|
|
1689
|
-
#size;
|
|
1690
1866
|
constructor() {
|
|
1867
|
+
__privateAdd(this, _head, void 0);
|
|
1868
|
+
__privateAdd(this, _tail, void 0);
|
|
1869
|
+
__privateAdd(this, _size, void 0);
|
|
1691
1870
|
this.clear();
|
|
1692
1871
|
}
|
|
1693
1872
|
enqueue(value) {
|
|
1694
1873
|
const node = new Node(value);
|
|
1695
|
-
if (this
|
|
1696
|
-
this
|
|
1697
|
-
this
|
|
1874
|
+
if (__privateGet(this, _head)) {
|
|
1875
|
+
__privateGet(this, _tail).next = node;
|
|
1876
|
+
__privateSet(this, _tail, node);
|
|
1698
1877
|
} else {
|
|
1699
|
-
this
|
|
1700
|
-
this
|
|
1878
|
+
__privateSet(this, _head, node);
|
|
1879
|
+
__privateSet(this, _tail, node);
|
|
1701
1880
|
}
|
|
1702
|
-
this
|
|
1881
|
+
__privateWrapper(this, _size)._++;
|
|
1703
1882
|
}
|
|
1704
1883
|
dequeue() {
|
|
1705
|
-
const current = this
|
|
1884
|
+
const current = __privateGet(this, _head);
|
|
1706
1885
|
if (!current) {
|
|
1707
1886
|
return;
|
|
1708
1887
|
}
|
|
1709
|
-
this
|
|
1710
|
-
this
|
|
1888
|
+
__privateSet(this, _head, __privateGet(this, _head).next);
|
|
1889
|
+
__privateWrapper(this, _size)._--;
|
|
1711
1890
|
return current.value;
|
|
1712
1891
|
}
|
|
1713
1892
|
clear() {
|
|
1714
|
-
this
|
|
1715
|
-
this
|
|
1716
|
-
this
|
|
1893
|
+
__privateSet(this, _head, void 0);
|
|
1894
|
+
__privateSet(this, _tail, void 0);
|
|
1895
|
+
__privateSet(this, _size, 0);
|
|
1717
1896
|
}
|
|
1718
1897
|
get size() {
|
|
1719
|
-
return this
|
|
1898
|
+
return __privateGet(this, _size);
|
|
1720
1899
|
}
|
|
1721
1900
|
*[Symbol.iterator]() {
|
|
1722
|
-
let current = this
|
|
1901
|
+
let current = __privateGet(this, _head);
|
|
1723
1902
|
while (current) {
|
|
1724
1903
|
yield current.value;
|
|
1725
1904
|
current = current.next;
|
|
1726
1905
|
}
|
|
1727
1906
|
}
|
|
1728
1907
|
};
|
|
1908
|
+
_head = new WeakMap();
|
|
1909
|
+
_tail = new WeakMap();
|
|
1910
|
+
_size = new WeakMap();
|
|
1729
1911
|
|
|
1730
1912
|
// ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
|
|
1731
1913
|
function pLimit(concurrency) {
|
|
@@ -1740,18 +1922,18 @@ function pLimit(concurrency) {
|
|
|
1740
1922
|
queue.dequeue()();
|
|
1741
1923
|
}
|
|
1742
1924
|
};
|
|
1743
|
-
const run = async (fn,
|
|
1925
|
+
const run = async (fn, resolve2, args) => {
|
|
1744
1926
|
activeCount++;
|
|
1745
1927
|
const result = (async () => fn(...args))();
|
|
1746
|
-
|
|
1928
|
+
resolve2(result);
|
|
1747
1929
|
try {
|
|
1748
1930
|
await result;
|
|
1749
1931
|
} catch {
|
|
1750
1932
|
}
|
|
1751
1933
|
next();
|
|
1752
1934
|
};
|
|
1753
|
-
const enqueue = (fn,
|
|
1754
|
-
queue.enqueue(run.bind(void 0, fn,
|
|
1935
|
+
const enqueue = (fn, resolve2, args) => {
|
|
1936
|
+
queue.enqueue(run.bind(void 0, fn, resolve2, args));
|
|
1755
1937
|
(async () => {
|
|
1756
1938
|
await Promise.resolve();
|
|
1757
1939
|
if (activeCount < concurrency && queue.size > 0) {
|
|
@@ -1759,8 +1941,8 @@ function pLimit(concurrency) {
|
|
|
1759
1941
|
}
|
|
1760
1942
|
})();
|
|
1761
1943
|
};
|
|
1762
|
-
const generator = (fn, ...args) => new Promise((
|
|
1763
|
-
enqueue(fn,
|
|
1944
|
+
const generator = (fn, ...args) => new Promise((resolve2) => {
|
|
1945
|
+
enqueue(fn, resolve2, args);
|
|
1764
1946
|
});
|
|
1765
1947
|
Object.defineProperties(generator, {
|
|
1766
1948
|
activeCount: {
|
|
@@ -1835,7 +2017,7 @@ async function locatePath(paths, {
|
|
|
1835
2017
|
const statFunction = allowSymlinks ? fs3.promises.stat : fs3.promises.lstat;
|
|
1836
2018
|
return pLocate(paths, async (path_) => {
|
|
1837
2019
|
try {
|
|
1838
|
-
const stat = await statFunction(
|
|
2020
|
+
const stat = await statFunction(path4__default.default.resolve(cwd, path_));
|
|
1839
2021
|
return matchType(type, stat);
|
|
1840
2022
|
} catch {
|
|
1841
2023
|
return false;
|
|
@@ -1852,7 +2034,7 @@ function locatePathSync(paths, {
|
|
|
1852
2034
|
const statFunction = allowSymlinks ? fs3__default.default.statSync : fs3__default.default.lstatSync;
|
|
1853
2035
|
for (const path_ of paths) {
|
|
1854
2036
|
try {
|
|
1855
|
-
const stat = statFunction(
|
|
2037
|
+
const stat = statFunction(path4__default.default.resolve(cwd, path_), {
|
|
1856
2038
|
throwIfNoEntry: false
|
|
1857
2039
|
});
|
|
1858
2040
|
if (!stat) {
|
|
@@ -1870,9 +2052,9 @@ function locatePathSync(paths, {
|
|
|
1870
2052
|
var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? url.fileURLToPath(urlOrPath) : urlOrPath;
|
|
1871
2053
|
var findUpStop = Symbol("findUpStop");
|
|
1872
2054
|
async function findUpMultiple(name, options = {}) {
|
|
1873
|
-
let directory =
|
|
1874
|
-
const { root } =
|
|
1875
|
-
const stopAt =
|
|
2055
|
+
let directory = path4__default.default.resolve(toPath2(options.cwd) || "");
|
|
2056
|
+
const { root } = path4__default.default.parse(directory);
|
|
2057
|
+
const stopAt = path4__default.default.resolve(directory, options.stopAt || root);
|
|
1876
2058
|
const limit = options.limit || Number.POSITIVE_INFINITY;
|
|
1877
2059
|
const paths = [name].flat();
|
|
1878
2060
|
const runMatcher = async (locateOptions) => {
|
|
@@ -1892,18 +2074,18 @@ async function findUpMultiple(name, options = {}) {
|
|
|
1892
2074
|
break;
|
|
1893
2075
|
}
|
|
1894
2076
|
if (foundPath) {
|
|
1895
|
-
matches.push(
|
|
2077
|
+
matches.push(path4__default.default.resolve(directory, foundPath));
|
|
1896
2078
|
}
|
|
1897
2079
|
if (directory === stopAt || matches.length >= limit) {
|
|
1898
2080
|
break;
|
|
1899
2081
|
}
|
|
1900
|
-
directory =
|
|
2082
|
+
directory = path4__default.default.dirname(directory);
|
|
1901
2083
|
}
|
|
1902
2084
|
return matches;
|
|
1903
2085
|
}
|
|
1904
2086
|
function findUpMultipleSync(name, options = {}) {
|
|
1905
|
-
let directory =
|
|
1906
|
-
const { root } =
|
|
2087
|
+
let directory = path4__default.default.resolve(toPath2(options.cwd) || "");
|
|
2088
|
+
const { root } = path4__default.default.parse(directory);
|
|
1907
2089
|
const stopAt = options.stopAt || root;
|
|
1908
2090
|
const limit = options.limit || Number.POSITIVE_INFINITY;
|
|
1909
2091
|
const paths = [name].flat();
|
|
@@ -1924,12 +2106,12 @@ function findUpMultipleSync(name, options = {}) {
|
|
|
1924
2106
|
break;
|
|
1925
2107
|
}
|
|
1926
2108
|
if (foundPath) {
|
|
1927
|
-
matches.push(
|
|
2109
|
+
matches.push(path4__default.default.resolve(directory, foundPath));
|
|
1928
2110
|
}
|
|
1929
2111
|
if (directory === stopAt || matches.length >= limit) {
|
|
1930
2112
|
break;
|
|
1931
2113
|
}
|
|
1932
|
-
directory =
|
|
2114
|
+
directory = path4__default.default.dirname(directory);
|
|
1933
2115
|
}
|
|
1934
2116
|
return matches;
|
|
1935
2117
|
}
|
|
@@ -1941,39 +2123,39 @@ function findUpSync(name, options = {}) {
|
|
|
1941
2123
|
const matches = findUpMultipleSync(name, { ...options, limit: 1 });
|
|
1942
2124
|
return matches[0];
|
|
1943
2125
|
}
|
|
1944
|
-
var
|
|
1945
|
-
|
|
1946
|
-
#cwd;
|
|
1947
|
-
#SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
|
|
2126
|
+
var _cache2, _cwd, _SLASHES;
|
|
2127
|
+
var _PackageManager = class _PackageManager {
|
|
1948
2128
|
constructor(workspace) {
|
|
2129
|
+
__privateAdd(this, _cwd, void 0);
|
|
2130
|
+
__privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
|
|
1949
2131
|
if (workspace) {
|
|
1950
|
-
this
|
|
2132
|
+
__privateSet(this, _cwd, workspace);
|
|
1951
2133
|
}
|
|
1952
2134
|
return this;
|
|
1953
2135
|
}
|
|
1954
2136
|
set workspace(workspace) {
|
|
1955
|
-
this
|
|
2137
|
+
__privateSet(this, _cwd, workspace);
|
|
1956
2138
|
}
|
|
1957
2139
|
get workspace() {
|
|
1958
|
-
return this
|
|
2140
|
+
return __privateGet(this, _cwd);
|
|
1959
2141
|
}
|
|
1960
2142
|
normalizeDirectory(directory) {
|
|
1961
|
-
if (!this
|
|
2143
|
+
if (!__privateGet(this, _SLASHES).has(directory[directory.length - 1])) {
|
|
1962
2144
|
return `${directory}/`;
|
|
1963
2145
|
}
|
|
1964
2146
|
return directory;
|
|
1965
2147
|
}
|
|
1966
|
-
getLocation(
|
|
1967
|
-
let location =
|
|
1968
|
-
if (this
|
|
1969
|
-
const require2 = mod__default.default.createRequire(this.normalizeDirectory(this
|
|
1970
|
-
location = require2.resolve(
|
|
2148
|
+
getLocation(path5) {
|
|
2149
|
+
let location = path5;
|
|
2150
|
+
if (__privateGet(this, _cwd)) {
|
|
2151
|
+
const require2 = mod__default.default.createRequire(this.normalizeDirectory(__privateGet(this, _cwd)));
|
|
2152
|
+
location = require2.resolve(path5);
|
|
1971
2153
|
}
|
|
1972
2154
|
return location;
|
|
1973
2155
|
}
|
|
1974
|
-
async import(
|
|
2156
|
+
async import(path5) {
|
|
1975
2157
|
try {
|
|
1976
|
-
let location = this.getLocation(
|
|
2158
|
+
let location = this.getLocation(path5);
|
|
1977
2159
|
if (os__default.default.platform() == "win32") {
|
|
1978
2160
|
location = url.pathToFileURL(location).href;
|
|
1979
2161
|
}
|
|
@@ -1986,7 +2168,7 @@ var PackageManager = class _PackageManager {
|
|
|
1986
2168
|
}
|
|
1987
2169
|
async getPackageJSON() {
|
|
1988
2170
|
const pkgPath = await findUp(["package.json"], {
|
|
1989
|
-
cwd: this
|
|
2171
|
+
cwd: __privateGet(this, _cwd)
|
|
1990
2172
|
});
|
|
1991
2173
|
if (!pkgPath) {
|
|
1992
2174
|
return void 0;
|
|
@@ -1995,7 +2177,7 @@ var PackageManager = class _PackageManager {
|
|
|
1995
2177
|
}
|
|
1996
2178
|
getPackageJSONSync() {
|
|
1997
2179
|
const pkgPath = findUpSync(["package.json"], {
|
|
1998
|
-
cwd: this
|
|
2180
|
+
cwd: __privateGet(this, _cwd)
|
|
1999
2181
|
});
|
|
2000
2182
|
if (!pkgPath) {
|
|
2001
2183
|
return void 0;
|
|
@@ -2003,11 +2185,11 @@ var PackageManager = class _PackageManager {
|
|
|
2003
2185
|
return __require(pkgPath);
|
|
2004
2186
|
}
|
|
2005
2187
|
static setVersion(dependency, version) {
|
|
2006
|
-
_PackageManager
|
|
2188
|
+
__privateGet(_PackageManager, _cache2)[dependency] = version;
|
|
2007
2189
|
}
|
|
2008
2190
|
async getVersion(dependency) {
|
|
2009
|
-
if (_PackageManager
|
|
2010
|
-
return _PackageManager
|
|
2191
|
+
if (__privateGet(_PackageManager, _cache2)[dependency]) {
|
|
2192
|
+
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
2011
2193
|
}
|
|
2012
2194
|
const packageJSON = await this.getPackageJSON();
|
|
2013
2195
|
if (!packageJSON) {
|
|
@@ -2016,8 +2198,8 @@ var PackageManager = class _PackageManager {
|
|
|
2016
2198
|
return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
|
|
2017
2199
|
}
|
|
2018
2200
|
getVersionSync(dependency) {
|
|
2019
|
-
if (_PackageManager
|
|
2020
|
-
return _PackageManager
|
|
2201
|
+
if (__privateGet(_PackageManager, _cache2)[dependency]) {
|
|
2202
|
+
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
2021
2203
|
}
|
|
2022
2204
|
const packageJSON = this.getPackageJSONSync();
|
|
2023
2205
|
if (!packageJSON) {
|
|
@@ -2048,68 +2230,38 @@ var PackageManager = class _PackageManager {
|
|
|
2048
2230
|
return semver.satisfies(semVer, version);
|
|
2049
2231
|
}
|
|
2050
2232
|
};
|
|
2233
|
+
_cache2 = new WeakMap();
|
|
2234
|
+
_cwd = new WeakMap();
|
|
2235
|
+
_SLASHES = new WeakMap();
|
|
2236
|
+
__privateAdd(_PackageManager, _cache2, {});
|
|
2237
|
+
var PackageManager = _PackageManager;
|
|
2238
|
+
|
|
2239
|
+
// src/SchemaGenerator.ts
|
|
2240
|
+
var SchemaGenerator = class extends Generator {
|
|
2241
|
+
};
|
|
2051
2242
|
|
|
2052
2243
|
// src/index.ts
|
|
2053
2244
|
var src_default = build;
|
|
2054
2245
|
|
|
2055
|
-
Object.defineProperty(exports, 'pc', {
|
|
2056
|
-
enumerable: true,
|
|
2057
|
-
get: function () { return pc3__default.default; }
|
|
2058
|
-
});
|
|
2059
2246
|
exports.FileManager = FileManager;
|
|
2060
|
-
exports.FunctionParams = FunctionParams;
|
|
2061
2247
|
exports.Generator = Generator;
|
|
2062
|
-
exports.LogLevel = LogLevel;
|
|
2063
2248
|
exports.PackageManager = PackageManager;
|
|
2064
2249
|
exports.ParallelPluginError = ParallelPluginError;
|
|
2065
2250
|
exports.PluginError = PluginError;
|
|
2066
2251
|
exports.PluginManager = PluginManager;
|
|
2067
|
-
exports.
|
|
2252
|
+
exports.PromiseManager = PromiseManager;
|
|
2068
2253
|
exports.SchemaGenerator = SchemaGenerator;
|
|
2069
2254
|
exports.SummaryError = SummaryError;
|
|
2070
|
-
exports.TreeNode = TreeNode;
|
|
2071
|
-
exports.URLPath = URLPath;
|
|
2072
2255
|
exports.ValidationPluginError = ValidationPluginError;
|
|
2073
2256
|
exports.Warning = Warning;
|
|
2074
2257
|
exports.build = build;
|
|
2075
|
-
exports.clean = clean;
|
|
2076
|
-
exports.combineCodes = combineCodes;
|
|
2077
2258
|
exports.combineExports = combineExports;
|
|
2078
|
-
exports.combineFiles = combineFiles;
|
|
2079
2259
|
exports.combineImports = combineImports;
|
|
2080
|
-
exports.createFileSource = createFileSource;
|
|
2081
|
-
exports.createJSDocBlockText = createJSDocBlockText;
|
|
2082
|
-
exports.createLogger = createLogger;
|
|
2083
2260
|
exports.createPlugin = createPlugin;
|
|
2084
|
-
exports.createPluginCache = createPluginCache;
|
|
2085
2261
|
exports.default = src_default;
|
|
2086
|
-
exports.defaultColours = defaultColours;
|
|
2087
2262
|
exports.defineConfig = defineConfig;
|
|
2088
|
-
exports.
|
|
2089
|
-
exports.extensions = extensions;
|
|
2090
|
-
exports.getDependedPlugins = getDependedPlugins;
|
|
2091
|
-
exports.getIndexes = getIndexes;
|
|
2092
|
-
exports.getPathMode = getPathMode;
|
|
2093
|
-
exports.getRelativePath = getRelativePath;
|
|
2094
|
-
exports.getUniqueName = getUniqueName;
|
|
2095
|
-
exports.hooks = hooks;
|
|
2096
|
-
exports.isExtensionAllowed = isExtensionAllowed;
|
|
2097
|
-
exports.isPromise = isPromise;
|
|
2098
|
-
exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
|
|
2099
|
-
exports.isPromiseRejectedResult = isPromiseRejectedResult;
|
|
2100
|
-
exports.jsStringEscape = jsStringEscape;
|
|
2263
|
+
exports.isInputPath = isInputPath;
|
|
2101
2264
|
exports.name = pluginName;
|
|
2102
|
-
exports.nameSorter = nameSorter;
|
|
2103
2265
|
exports.pluginName = pluginName;
|
|
2104
|
-
exports.randomColour = randomColour;
|
|
2105
|
-
exports.randomPicoColour = randomPicoColour;
|
|
2106
|
-
exports.read = read;
|
|
2107
|
-
exports.readSync = readSync;
|
|
2108
|
-
exports.renderTemplate = renderTemplate;
|
|
2109
|
-
exports.throttle = throttle;
|
|
2110
|
-
exports.timeout = timeout;
|
|
2111
|
-
exports.transformReservedWord = transformReservedWord;
|
|
2112
|
-
exports.uniqueIdFactory = uniqueIdFactory;
|
|
2113
|
-
exports.write = write;
|
|
2114
2266
|
//# sourceMappingURL=out.js.map
|
|
2115
2267
|
//# sourceMappingURL=index.cjs.map
|