@kubb/core 1.15.0-canary.20231027T200912 → 2.0.0-canary.20231027T203719
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 +1163 -1025
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +255 -313
- package/dist/index.d.ts +255 -313
- package/dist/index.js +1105 -958
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +1260 -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 +1207 -0
- package/dist/utils.js.map +1 -0
- package/globals.d.ts +33 -16
- package/package.json +14 -9
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,287 @@ 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
|
+
var _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
717
|
+
var _FileManager = class _FileManager {
|
|
718
|
+
constructor(options) {
|
|
719
|
+
__privateAdd(this, _validate);
|
|
720
|
+
__privateAdd(this, _add);
|
|
721
|
+
__privateAdd(this, _addOrAppend);
|
|
722
|
+
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
|
|
723
|
+
__privateAdd(this, _task, void 0);
|
|
724
|
+
__privateAdd(this, _isWriting, false);
|
|
725
|
+
/**
|
|
726
|
+
* Timeout between writes
|
|
727
|
+
*/
|
|
728
|
+
__privateAdd(this, _timeout, 0);
|
|
729
|
+
__privateAdd(this, _queue, void 0);
|
|
730
|
+
if (options) {
|
|
731
|
+
__privateSet(this, _task, options.task);
|
|
732
|
+
__privateSet(this, _queue, options.queue);
|
|
733
|
+
__privateSet(this, _timeout, options.timeout || 0);
|
|
734
|
+
}
|
|
735
|
+
return this;
|
|
647
736
|
}
|
|
648
|
-
get
|
|
649
|
-
|
|
737
|
+
get files() {
|
|
738
|
+
const files = [];
|
|
739
|
+
__privateGet(this, _cache).forEach((item) => {
|
|
740
|
+
files.push(...item.flat(1));
|
|
741
|
+
});
|
|
742
|
+
return files;
|
|
650
743
|
}
|
|
651
|
-
get
|
|
652
|
-
return this
|
|
744
|
+
get isExecuting() {
|
|
745
|
+
return __privateGet(this, _queue)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
|
|
653
746
|
}
|
|
654
|
-
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
if (stringify) {
|
|
660
|
-
if (type !== "template") {
|
|
661
|
-
throw new Error("Type should be `template` when using stringiyf");
|
|
747
|
+
async add(...files) {
|
|
748
|
+
const promises = files.map((file) => {
|
|
749
|
+
__privateMethod(this, _validate, validate_fn).call(this, file);
|
|
750
|
+
if (file.override) {
|
|
751
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
662
752
|
}
|
|
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);
|
|
753
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
|
|
754
|
+
});
|
|
755
|
+
const resolvedFiles = await Promise.all(promises);
|
|
756
|
+
if (files.length > 1) {
|
|
757
|
+
return resolvedFiles;
|
|
683
758
|
}
|
|
684
|
-
return
|
|
759
|
+
return resolvedFiles[0];
|
|
685
760
|
}
|
|
686
|
-
|
|
687
|
-
const
|
|
688
|
-
const
|
|
689
|
-
if (!
|
|
761
|
+
async addIndexes({ root, extName = ".ts", meta, options = {} }) {
|
|
762
|
+
const barrelManager = new BarrelManager(options);
|
|
763
|
+
const files = barrelManager.getIndexes(root, extName);
|
|
764
|
+
if (!files) {
|
|
690
765
|
return void 0;
|
|
691
766
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
767
|
+
return await Promise.all(
|
|
768
|
+
files.map((file) => {
|
|
769
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
770
|
+
...file,
|
|
771
|
+
meta: meta ? meta : file.meta
|
|
772
|
+
});
|
|
773
|
+
})
|
|
774
|
+
);
|
|
699
775
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
return
|
|
776
|
+
getCacheByUUID(UUID) {
|
|
777
|
+
let cache;
|
|
778
|
+
__privateGet(this, _cache).forEach((files) => {
|
|
779
|
+
cache = files.find((item) => item.id === UUID);
|
|
780
|
+
});
|
|
781
|
+
return cache;
|
|
706
782
|
}
|
|
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";
|
|
783
|
+
get(path5) {
|
|
784
|
+
return __privateGet(this, _cache).get(path5);
|
|
714
785
|
}
|
|
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: []
|
|
786
|
+
remove(path5) {
|
|
787
|
+
const cacheItem = this.get(path5);
|
|
788
|
+
if (!cacheItem) {
|
|
789
|
+
return;
|
|
757
790
|
}
|
|
758
|
-
|
|
759
|
-
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...options });
|
|
760
|
-
if (!tree) {
|
|
761
|
-
return null;
|
|
791
|
+
__privateGet(this, _cache).delete(path5);
|
|
762
792
|
}
|
|
763
|
-
|
|
764
|
-
if (!
|
|
765
|
-
|
|
793
|
+
async write(...params) {
|
|
794
|
+
if (!__privateGet(this, _isWriting)) {
|
|
795
|
+
__privateSet(this, _isWriting, true);
|
|
796
|
+
const text = await write(...params);
|
|
797
|
+
__privateSet(this, _isWriting, false);
|
|
798
|
+
return text;
|
|
766
799
|
}
|
|
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
|
-
});
|
|
800
|
+
await timeout(__privateGet(this, _timeout));
|
|
801
|
+
return this.write(...params);
|
|
802
|
+
}
|
|
803
|
+
async read(...params) {
|
|
804
|
+
return read(...params);
|
|
805
|
+
}
|
|
806
|
+
// statics
|
|
807
|
+
static getSource(file) {
|
|
808
|
+
if (!_FileManager.isExtensionAllowed(file.baseName)) {
|
|
809
|
+
return file.source;
|
|
796
810
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
});
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
811
|
+
const exports = file.exports ? combineExports(file.exports) : [];
|
|
812
|
+
const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
|
|
813
|
+
const importNodes = imports.map((item) => factory__namespace.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
814
|
+
const exportNodes = exports.map(
|
|
815
|
+
(item) => factory__namespace.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias })
|
|
816
|
+
);
|
|
817
|
+
return [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
818
|
+
}
|
|
819
|
+
static combineFiles(files) {
|
|
820
|
+
return files.filter(Boolean).reduce((acc, file) => {
|
|
821
|
+
const prevIndex = acc.findIndex((item) => item.path === file.path);
|
|
822
|
+
if (prevIndex === -1) {
|
|
823
|
+
return [...acc, file];
|
|
824
|
+
}
|
|
809
825
|
const prev = acc[prevIndex];
|
|
826
|
+
if (prev && file.override) {
|
|
827
|
+
acc[prevIndex] = {
|
|
828
|
+
imports: [],
|
|
829
|
+
exports: [],
|
|
830
|
+
...file
|
|
831
|
+
};
|
|
832
|
+
return acc;
|
|
833
|
+
}
|
|
810
834
|
if (prev) {
|
|
811
835
|
acc[prevIndex] = {
|
|
812
|
-
...
|
|
813
|
-
source: prev.source &&
|
|
814
|
-
${
|
|
815
|
-
imports: [...prev.imports || [], ...
|
|
816
|
-
exports: [...prev.exports || [], ...
|
|
817
|
-
env: { ...prev.env || {}, ...
|
|
836
|
+
...file,
|
|
837
|
+
source: prev.source && file.source ? `${prev.source}
|
|
838
|
+
${file.source}` : "",
|
|
839
|
+
imports: [...prev.imports || [], ...file.imports || []],
|
|
840
|
+
exports: [...prev.exports || [], ...file.exports || []],
|
|
841
|
+
env: { ...prev.env || {}, ...file.env || {} }
|
|
818
842
|
};
|
|
819
843
|
}
|
|
820
|
-
|
|
821
|
-
|
|
844
|
+
return acc;
|
|
845
|
+
}, []);
|
|
846
|
+
}
|
|
847
|
+
static getMode(path5) {
|
|
848
|
+
if (!path5) {
|
|
849
|
+
return "directory";
|
|
822
850
|
}
|
|
823
|
-
return
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
851
|
+
return path4.extname(path5) ? "file" : "directory";
|
|
852
|
+
}
|
|
853
|
+
static get extensions() {
|
|
854
|
+
return [".js", ".ts", ".tsx"];
|
|
855
|
+
}
|
|
856
|
+
static isExtensionAllowed(baseName) {
|
|
857
|
+
return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
_cache = new WeakMap();
|
|
861
|
+
_task = new WeakMap();
|
|
862
|
+
_isWriting = new WeakMap();
|
|
863
|
+
_timeout = new WeakMap();
|
|
864
|
+
_queue = new WeakMap();
|
|
865
|
+
_validate = new WeakSet();
|
|
866
|
+
validate_fn = function(file) {
|
|
867
|
+
if (!file.validate) {
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
|
|
871
|
+
throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
_add = new WeakSet();
|
|
875
|
+
add_fn = async function(file) {
|
|
876
|
+
const controller = new AbortController();
|
|
877
|
+
const resolvedFile = { id: crypto2__default.default.randomUUID(), ...file };
|
|
878
|
+
__privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
879
|
+
if (__privateGet(this, _queue)) {
|
|
880
|
+
await __privateGet(this, _queue).run(
|
|
881
|
+
async () => {
|
|
882
|
+
var _a;
|
|
883
|
+
return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
|
|
884
|
+
},
|
|
885
|
+
{ controller }
|
|
886
|
+
);
|
|
887
|
+
}
|
|
888
|
+
return resolvedFile;
|
|
889
|
+
};
|
|
890
|
+
_addOrAppend = new WeakSet();
|
|
891
|
+
addOrAppend_fn = async function(file) {
|
|
892
|
+
const previousCaches = __privateGet(this, _cache).get(file.path);
|
|
893
|
+
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
894
|
+
if (previousCache) {
|
|
895
|
+
__privateGet(this, _cache).delete(previousCache.path);
|
|
896
|
+
return __privateMethod(this, _add, add_fn).call(this, {
|
|
897
|
+
...file,
|
|
898
|
+
source: previousCache.source && file.source ? `${previousCache.source}
|
|
899
|
+
${file.source}` : "",
|
|
900
|
+
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
901
|
+
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
902
|
+
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
906
|
+
};
|
|
907
|
+
var FileManager = _FileManager;
|
|
830
908
|
function combineExports(exports) {
|
|
831
|
-
|
|
909
|
+
const combinedExports = naturalOrderby.orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
832
910
|
const name = curr.name;
|
|
833
911
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
912
|
+
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
|
|
913
|
+
if (prevByPathAndIsTypeOnly) {
|
|
914
|
+
return prev;
|
|
915
|
+
}
|
|
834
916
|
const uniquePrev = prev.findLast(
|
|
835
917
|
(imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
836
918
|
);
|
|
@@ -852,12 +934,16 @@ function combineExports(exports) {
|
|
|
852
934
|
}
|
|
853
935
|
return [...prev, curr];
|
|
854
936
|
}, []);
|
|
937
|
+
return naturalOrderby.orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
855
938
|
}
|
|
856
939
|
function combineImports(imports, exports, source) {
|
|
857
|
-
|
|
940
|
+
const combinedImports = naturalOrderby.orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
858
941
|
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
859
942
|
const hasImportInSource = (importName) => {
|
|
860
|
-
|
|
943
|
+
if (!source) {
|
|
944
|
+
return true;
|
|
945
|
+
}
|
|
946
|
+
const checker = (name2) => name2 && !!source.includes(name2);
|
|
861
947
|
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
862
948
|
};
|
|
863
949
|
if (Array.isArray(name)) {
|
|
@@ -865,6 +951,10 @@ function combineImports(imports, exports, source) {
|
|
|
865
951
|
}
|
|
866
952
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
867
953
|
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
954
|
+
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
|
|
955
|
+
if (prevByPathNameAndIsTypeOnly) {
|
|
956
|
+
return prev;
|
|
957
|
+
}
|
|
868
958
|
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
869
959
|
return prev;
|
|
870
960
|
}
|
|
@@ -886,43 +976,7 @@ function combineImports(imports, exports, source) {
|
|
|
886
976
|
}
|
|
887
977
|
return [...prev, curr];
|
|
888
978
|
}, []);
|
|
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);
|
|
979
|
+
return naturalOrderby.orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
|
|
926
980
|
}
|
|
927
981
|
function getEnvSource(source, env) {
|
|
928
982
|
if (!env) {
|
|
@@ -939,132 +993,128 @@ function getEnvSource(source, env) {
|
|
|
939
993
|
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
940
994
|
}
|
|
941
995
|
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).*
|
|
996
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
997
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
944
998
|
`, "ig"), ""), replaceBy, key });
|
|
945
999
|
}
|
|
946
1000
|
return prev;
|
|
947
1001
|
}, source);
|
|
948
1002
|
}
|
|
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;
|
|
1003
|
+
var _emitter;
|
|
1004
|
+
var EventEmitter = class {
|
|
1005
|
+
constructor() {
|
|
1006
|
+
__privateAdd(this, _emitter, new events.EventEmitter());
|
|
1007
|
+
__privateGet(this, _emitter).setMaxListeners(100);
|
|
961
1008
|
}
|
|
962
|
-
|
|
963
|
-
|
|
1009
|
+
emit(eventName, ...eventArg) {
|
|
1010
|
+
__privateGet(this, _emitter).emit(eventName, ...eventArg);
|
|
964
1011
|
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
this.#cache.forEach((item) => {
|
|
968
|
-
files.push(...item.flat(1));
|
|
969
|
-
});
|
|
970
|
-
return files;
|
|
1012
|
+
on(eventName, handler) {
|
|
1013
|
+
__privateGet(this, _emitter).on(eventName, handler);
|
|
971
1014
|
}
|
|
972
|
-
|
|
973
|
-
|
|
1015
|
+
off(eventName, handler) {
|
|
1016
|
+
__privateGet(this, _emitter).off(eventName, handler);
|
|
974
1017
|
}
|
|
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;
|
|
1018
|
+
removeAll() {
|
|
1019
|
+
__privateGet(this, _emitter).removeAllListeners();
|
|
992
1020
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1021
|
+
};
|
|
1022
|
+
_emitter = new WeakMap();
|
|
1023
|
+
var _queue2, _workerCount, _maxParallel, _debug, _work, work_fn;
|
|
1024
|
+
var Queue = class {
|
|
1025
|
+
constructor(maxParallel, debug = false) {
|
|
1026
|
+
__privateAdd(this, _work);
|
|
1027
|
+
__privateAdd(this, _queue2, []);
|
|
1028
|
+
this.eventEmitter = new EventEmitter();
|
|
1029
|
+
__privateAdd(this, _workerCount, 0);
|
|
1030
|
+
__privateAdd(this, _maxParallel, void 0);
|
|
1031
|
+
__privateAdd(this, _debug, false);
|
|
1032
|
+
__privateSet(this, _maxParallel, maxParallel);
|
|
1033
|
+
__privateSet(this, _debug, debug);
|
|
1034
|
+
}
|
|
1035
|
+
run(job, options = { controller: new AbortController(), name: crypto2__default.default.randomUUID(), description: "" }) {
|
|
1036
|
+
return new Promise((resolve2, reject) => {
|
|
1037
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
1038
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
1039
|
+
__privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
|
|
1040
|
+
reject("Aborted");
|
|
1005
1041
|
});
|
|
1006
|
-
|
|
1007
|
-
|
|
1042
|
+
__privateGet(this, _queue2).push(item);
|
|
1043
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
1044
|
+
});
|
|
1008
1045
|
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
}
|
|
1019
|
-
return this.addOrAppend(file);
|
|
1020
|
-
})
|
|
1021
|
-
);
|
|
1046
|
+
runSync(job, options = { controller: new AbortController(), name: crypto2__default.default.randomUUID(), description: "" }) {
|
|
1047
|
+
new Promise((resolve2, reject) => {
|
|
1048
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
1049
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
1050
|
+
__privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
|
|
1051
|
+
});
|
|
1052
|
+
__privateGet(this, _queue2).push(item);
|
|
1053
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
1054
|
+
});
|
|
1022
1055
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
this.#cache.set(path3, [...previousFiles, file]);
|
|
1056
|
+
get hasJobs() {
|
|
1057
|
+
return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue2).length > 0;
|
|
1026
1058
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
this.#cache.forEach((files) => {
|
|
1030
|
-
cache = files.find((item) => item.id === UUID);
|
|
1031
|
-
});
|
|
1032
|
-
return cache;
|
|
1059
|
+
get count() {
|
|
1060
|
+
return __privateGet(this, _workerCount);
|
|
1033
1061
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1062
|
+
};
|
|
1063
|
+
_queue2 = new WeakMap();
|
|
1064
|
+
_workerCount = new WeakMap();
|
|
1065
|
+
_maxParallel = new WeakMap();
|
|
1066
|
+
_debug = new WeakMap();
|
|
1067
|
+
_work = new WeakSet();
|
|
1068
|
+
work_fn = function() {
|
|
1069
|
+
if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
|
|
1070
|
+
return;
|
|
1036
1071
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1072
|
+
__privateWrapper(this, _workerCount)._++;
|
|
1073
|
+
let entry;
|
|
1074
|
+
while (entry = __privateGet(this, _queue2).shift()) {
|
|
1075
|
+
const { reject, resolve: resolve2, job, name, description } = entry;
|
|
1076
|
+
if (__privateGet(this, _debug)) {
|
|
1077
|
+
perf_hooks.performance.mark(name + "_start");
|
|
1078
|
+
}
|
|
1079
|
+
job().then((result) => {
|
|
1080
|
+
this.eventEmitter.emit("jobDone", result);
|
|
1081
|
+
resolve2(result);
|
|
1082
|
+
if (__privateGet(this, _debug)) {
|
|
1083
|
+
perf_hooks.performance.mark(name + "_stop");
|
|
1084
|
+
perf_hooks.performance.measure(description, name + "_start", name + "_stop");
|
|
1085
|
+
}
|
|
1086
|
+
}).catch((err) => {
|
|
1087
|
+
this.eventEmitter.emit("jobFailed", err);
|
|
1088
|
+
reject(err);
|
|
1089
|
+
});
|
|
1043
1090
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1091
|
+
__privateWrapper(this, _workerCount)._--;
|
|
1092
|
+
};
|
|
1093
|
+
|
|
1094
|
+
// src/utils/uniqueName.ts
|
|
1095
|
+
function setUniqueName(originalName, data) {
|
|
1096
|
+
let used = data[originalName] || 0;
|
|
1097
|
+
if (used) {
|
|
1098
|
+
data[originalName] = ++used;
|
|
1099
|
+
return originalName;
|
|
1051
1100
|
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1101
|
+
data[originalName] = 1;
|
|
1102
|
+
return originalName;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
// src/errors.ts
|
|
1106
|
+
var PluginError = class extends Error {
|
|
1107
|
+
constructor(message, options) {
|
|
1108
|
+
super(message, { cause: options.cause });
|
|
1109
|
+
this.name = "PluginError";
|
|
1110
|
+
this.cause = options.cause;
|
|
1111
|
+
this.pluginManager = options.pluginManager;
|
|
1059
1112
|
}
|
|
1060
1113
|
};
|
|
1061
|
-
|
|
1062
|
-
// src/managers/pluginManager/ParallelPluginError.ts
|
|
1063
1114
|
var ParallelPluginError = class extends Error {
|
|
1064
|
-
errors = [];
|
|
1065
|
-
pluginManager;
|
|
1066
1115
|
constructor(message, options) {
|
|
1067
1116
|
super(message, { cause: options.cause });
|
|
1117
|
+
this.errors = [];
|
|
1068
1118
|
this.name = "ParallelPluginError";
|
|
1069
1119
|
this.errors = options.errors;
|
|
1070
1120
|
this.pluginManager = options.pluginManager;
|
|
@@ -1084,30 +1134,54 @@ var ParallelPluginError = class extends Error {
|
|
|
1084
1134
|
})?.cause;
|
|
1085
1135
|
}
|
|
1086
1136
|
};
|
|
1087
|
-
|
|
1088
|
-
// src/managers/pluginManager/PluginError.ts
|
|
1089
|
-
var PluginError = class extends Error {
|
|
1090
|
-
pluginManager;
|
|
1091
|
-
cause;
|
|
1137
|
+
var SummaryError = class extends Error {
|
|
1092
1138
|
constructor(message, options) {
|
|
1093
1139
|
super(message, { cause: options.cause });
|
|
1094
|
-
this.name = "
|
|
1095
|
-
this.
|
|
1096
|
-
this.pluginManager = options.pluginManager;
|
|
1140
|
+
this.name = "SummaryError";
|
|
1141
|
+
this.summary = options.summary || [];
|
|
1097
1142
|
}
|
|
1098
1143
|
};
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1144
|
+
var Warning = class extends Error {
|
|
1145
|
+
constructor(message, options) {
|
|
1146
|
+
super(message, { cause: options?.cause });
|
|
1147
|
+
this.name = "Warning";
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
var ValidationPluginError = class extends Error {
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
// src/utils/cache.ts
|
|
1154
|
+
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
1155
|
+
return {
|
|
1156
|
+
set(id, value) {
|
|
1157
|
+
Store[id] = [0, value];
|
|
1158
|
+
},
|
|
1159
|
+
get(id) {
|
|
1160
|
+
const item = Store[id];
|
|
1161
|
+
if (!item) {
|
|
1162
|
+
return null;
|
|
1163
|
+
}
|
|
1164
|
+
item[0] = 0;
|
|
1165
|
+
return item[1];
|
|
1166
|
+
},
|
|
1167
|
+
has(id) {
|
|
1168
|
+
const item = Store[id];
|
|
1169
|
+
if (!item) {
|
|
1170
|
+
return false;
|
|
1171
|
+
}
|
|
1172
|
+
item[0] = 0;
|
|
1173
|
+
return true;
|
|
1174
|
+
},
|
|
1175
|
+
delete(id) {
|
|
1176
|
+
return delete Store[id];
|
|
1109
1177
|
}
|
|
1110
|
-
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
// src/plugin.ts
|
|
1182
|
+
function createPlugin(factory2) {
|
|
1183
|
+
return (options) => {
|
|
1184
|
+
return factory2(options);
|
|
1111
1185
|
};
|
|
1112
1186
|
}
|
|
1113
1187
|
var pluginName = "core";
|
|
@@ -1116,6 +1190,8 @@ var definePlugin = createPlugin((options) => {
|
|
|
1116
1190
|
return {
|
|
1117
1191
|
name: pluginName,
|
|
1118
1192
|
options,
|
|
1193
|
+
key: ["controller", "core"],
|
|
1194
|
+
kind: "controller",
|
|
1119
1195
|
api() {
|
|
1120
1196
|
return {
|
|
1121
1197
|
get config() {
|
|
@@ -1124,18 +1200,18 @@ var definePlugin = createPlugin((options) => {
|
|
|
1124
1200
|
get plugins() {
|
|
1125
1201
|
return options.getPlugins();
|
|
1126
1202
|
},
|
|
1203
|
+
get plugin() {
|
|
1204
|
+
return options.plugin;
|
|
1205
|
+
},
|
|
1127
1206
|
logger,
|
|
1128
1207
|
fileManager,
|
|
1129
1208
|
pluginManager,
|
|
1130
1209
|
async addFile(...files) {
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
return fileManager.addOrAppend(file);
|
|
1137
|
-
})
|
|
1138
|
-
);
|
|
1210
|
+
const resolvedFiles = await fileManager.add(...files);
|
|
1211
|
+
if (!Array.isArray(resolvedFiles)) {
|
|
1212
|
+
return [resolvedFiles];
|
|
1213
|
+
}
|
|
1214
|
+
return resolvedFiles;
|
|
1139
1215
|
},
|
|
1140
1216
|
resolvePath,
|
|
1141
1217
|
resolveName,
|
|
@@ -1143,75 +1219,133 @@ var definePlugin = createPlugin((options) => {
|
|
|
1143
1219
|
};
|
|
1144
1220
|
},
|
|
1145
1221
|
resolvePath(baseName) {
|
|
1146
|
-
const root =
|
|
1147
|
-
return
|
|
1222
|
+
const root = path4__default.default.resolve(this.config.root, this.config.output.path);
|
|
1223
|
+
return path4__default.default.resolve(root, baseName);
|
|
1148
1224
|
},
|
|
1149
1225
|
resolveName(name) {
|
|
1150
1226
|
return name;
|
|
1151
1227
|
}
|
|
1152
1228
|
};
|
|
1153
1229
|
});
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1230
|
+
|
|
1231
|
+
// src/utils/executeStrategies.ts
|
|
1232
|
+
function hookSeq(promises) {
|
|
1233
|
+
return promises.reduce(
|
|
1234
|
+
(promise, func) => {
|
|
1235
|
+
if (!func || typeof func !== "function") {
|
|
1236
|
+
throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
1237
|
+
}
|
|
1238
|
+
return promise.then((result) => {
|
|
1239
|
+
const calledFunc = func();
|
|
1240
|
+
if (calledFunc) {
|
|
1241
|
+
return calledFunc.then(Array.prototype.concat.bind(result));
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
},
|
|
1245
|
+
Promise.resolve([])
|
|
1246
|
+
);
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
// src/PromiseManager.ts
|
|
1250
|
+
var _options2;
|
|
1251
|
+
var PromiseManager = class {
|
|
1252
|
+
constructor(options = {}) {
|
|
1253
|
+
__privateAdd(this, _options2, {});
|
|
1254
|
+
__privateSet(this, _options2, options);
|
|
1255
|
+
return this;
|
|
1167
1256
|
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1257
|
+
run(strategy, promises) {
|
|
1258
|
+
if (strategy === "seq") {
|
|
1259
|
+
return hookSeq(promises);
|
|
1260
|
+
}
|
|
1261
|
+
throw new Error(`${strategy} not implemented`);
|
|
1170
1262
|
}
|
|
1171
1263
|
};
|
|
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
|
-
};
|
|
1264
|
+
_options2 = new WeakMap();
|
|
1265
|
+
function isPromise(result) {
|
|
1266
|
+
return !!result && typeof result?.then === "function";
|
|
1267
|
+
}
|
|
1268
|
+
function isPromiseRejectedResult(result) {
|
|
1269
|
+
return result.status === "rejected";
|
|
1189
1270
|
}
|
|
1190
1271
|
|
|
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);
|
|
1272
|
+
// src/PluginManager.ts
|
|
1273
|
+
var _core, _usedPluginNames, _promiseManager, _getSortedPlugins, getSortedPlugins_fn, _addExecutedToCallStack, addExecutedToCallStack_fn, _execute, execute_fn, _executeSync, executeSync_fn, _catcher, catcher_fn, _parse, parse_fn;
|
|
1203
1274
|
var PluginManager = class {
|
|
1204
|
-
plugins;
|
|
1205
|
-
fileManager;
|
|
1206
|
-
eventEmitter = new EventEmitter();
|
|
1207
|
-
queue;
|
|
1208
|
-
executed = [];
|
|
1209
|
-
logger;
|
|
1210
|
-
#core;
|
|
1211
1275
|
constructor(config, options) {
|
|
1276
|
+
__privateAdd(this, _getSortedPlugins);
|
|
1277
|
+
__privateAdd(this, _addExecutedToCallStack);
|
|
1278
|
+
/**
|
|
1279
|
+
* Run an async plugin hook and return the result.
|
|
1280
|
+
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
1281
|
+
* @param args Arguments passed to the plugin hook.
|
|
1282
|
+
* @param plugin The actual pluginObject to run.
|
|
1283
|
+
*/
|
|
1284
|
+
// Implementation signature
|
|
1285
|
+
__privateAdd(this, _execute);
|
|
1286
|
+
/**
|
|
1287
|
+
* Run a sync plugin hook and return the result.
|
|
1288
|
+
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
1289
|
+
* @param args Arguments passed to the plugin hook.
|
|
1290
|
+
* @param plugin The acutal plugin
|
|
1291
|
+
* @param replaceContext When passed, the plugin context can be overridden.
|
|
1292
|
+
*/
|
|
1293
|
+
__privateAdd(this, _executeSync);
|
|
1294
|
+
__privateAdd(this, _catcher);
|
|
1295
|
+
__privateAdd(this, _parse);
|
|
1296
|
+
this.eventEmitter = new EventEmitter();
|
|
1297
|
+
this.executed = [];
|
|
1298
|
+
__privateAdd(this, _core, void 0);
|
|
1299
|
+
__privateAdd(this, _usedPluginNames, {});
|
|
1300
|
+
__privateAdd(this, _promiseManager, void 0);
|
|
1301
|
+
this.resolvePath = (params) => {
|
|
1302
|
+
if (params.pluginKey) {
|
|
1303
|
+
const paths = this.hookForPluginSync({
|
|
1304
|
+
pluginKey: params.pluginKey,
|
|
1305
|
+
hookName: "resolvePath",
|
|
1306
|
+
parameters: [params.baseName, params.directory, params.options]
|
|
1307
|
+
});
|
|
1308
|
+
if (paths && paths?.length > 1) {
|
|
1309
|
+
throw new Error(
|
|
1310
|
+
`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1311
|
+
|
|
1312
|
+
Paths: ${JSON.stringify(paths, void 0, 2)}`
|
|
1313
|
+
);
|
|
1314
|
+
}
|
|
1315
|
+
return paths?.at(0);
|
|
1316
|
+
}
|
|
1317
|
+
return this.hookFirstSync({
|
|
1318
|
+
hookName: "resolvePath",
|
|
1319
|
+
parameters: [params.baseName, params.directory, params.options]
|
|
1320
|
+
}).result;
|
|
1321
|
+
};
|
|
1322
|
+
this.resolveName = (params) => {
|
|
1323
|
+
if (params.pluginKey) {
|
|
1324
|
+
const names = this.hookForPluginSync({
|
|
1325
|
+
pluginKey: params.pluginKey,
|
|
1326
|
+
hookName: "resolveName",
|
|
1327
|
+
parameters: [params.name, params.type]
|
|
1328
|
+
});
|
|
1329
|
+
if (names && names?.length > 1) {
|
|
1330
|
+
throw new Error(
|
|
1331
|
+
`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1332
|
+
|
|
1333
|
+
Names: ${JSON.stringify(names, void 0, 2)}`
|
|
1334
|
+
);
|
|
1335
|
+
}
|
|
1336
|
+
return transformReservedWord(names?.at(0) || params.name);
|
|
1337
|
+
}
|
|
1338
|
+
const name = this.hookFirstSync({
|
|
1339
|
+
hookName: "resolveName",
|
|
1340
|
+
parameters: [params.name, params.type]
|
|
1341
|
+
}).result;
|
|
1342
|
+
return transformReservedWord(name);
|
|
1343
|
+
};
|
|
1212
1344
|
this.logger = options.logger;
|
|
1213
|
-
this.queue = new Queue(100,
|
|
1214
|
-
this.fileManager = new FileManager({ task: options.task, queue: this.queue });
|
|
1345
|
+
this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
|
|
1346
|
+
this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
|
|
1347
|
+
__privateSet(this, _promiseManager, new PromiseManager());
|
|
1348
|
+
const plugins = config.plugins || [];
|
|
1215
1349
|
const core = definePlugin({
|
|
1216
1350
|
config,
|
|
1217
1351
|
logger: this.logger,
|
|
@@ -1219,44 +1353,14 @@ var PluginManager = class {
|
|
|
1219
1353
|
fileManager: this.fileManager,
|
|
1220
1354
|
resolvePath: this.resolvePath.bind(this),
|
|
1221
1355
|
resolveName: this.resolveName.bind(this),
|
|
1222
|
-
getPlugins: this
|
|
1223
|
-
|
|
1356
|
+
getPlugins: __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).bind(this)
|
|
1357
|
+
});
|
|
1358
|
+
__privateSet(this, _core, __privateMethod(this, _parse, parse_fn).call(this, core, this, core.api.call(null)));
|
|
1359
|
+
this.plugins = [__privateGet(this, _core), ...plugins].map((plugin) => {
|
|
1360
|
+
return __privateMethod(this, _parse, parse_fn).call(this, plugin, this, __privateGet(this, _core).api);
|
|
1224
1361
|
});
|
|
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
1362
|
return this;
|
|
1231
1363
|
}
|
|
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
1364
|
on(eventName, handler) {
|
|
1261
1365
|
this.eventEmitter.on(eventName, handler);
|
|
1262
1366
|
}
|
|
@@ -1264,30 +1368,35 @@ var PluginManager = class {
|
|
|
1264
1368
|
* Run only hook for a specific plugin name
|
|
1265
1369
|
*/
|
|
1266
1370
|
hookForPlugin({
|
|
1267
|
-
|
|
1371
|
+
pluginKey,
|
|
1268
1372
|
hookName,
|
|
1269
1373
|
parameters
|
|
1270
1374
|
}) {
|
|
1271
|
-
const
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1375
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1376
|
+
const promises = plugins.map((plugin) => {
|
|
1377
|
+
return __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1378
|
+
strategy: "hookFirst",
|
|
1379
|
+
hookName,
|
|
1380
|
+
parameters,
|
|
1381
|
+
plugin
|
|
1382
|
+
});
|
|
1383
|
+
}).filter(Boolean);
|
|
1384
|
+
return Promise.all(promises);
|
|
1278
1385
|
}
|
|
1279
1386
|
hookForPluginSync({
|
|
1280
|
-
|
|
1387
|
+
pluginKey,
|
|
1281
1388
|
hookName,
|
|
1282
1389
|
parameters
|
|
1283
1390
|
}) {
|
|
1284
|
-
const
|
|
1285
|
-
return
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1391
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1392
|
+
return plugins.map((plugin) => {
|
|
1393
|
+
return __privateMethod(this, _executeSync, executeSync_fn).call(this, {
|
|
1394
|
+
strategy: "hookFirst",
|
|
1395
|
+
hookName,
|
|
1396
|
+
parameters,
|
|
1397
|
+
plugin
|
|
1398
|
+
});
|
|
1399
|
+
}).filter(Boolean);
|
|
1291
1400
|
}
|
|
1292
1401
|
/**
|
|
1293
1402
|
* Chains, first non-null result stops and returns
|
|
@@ -1298,7 +1407,7 @@ var PluginManager = class {
|
|
|
1298
1407
|
skipped
|
|
1299
1408
|
}) {
|
|
1300
1409
|
let promise = Promise.resolve(null);
|
|
1301
|
-
for (const plugin of this
|
|
1410
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1302
1411
|
if (skipped && skipped.has(plugin)) {
|
|
1303
1412
|
continue;
|
|
1304
1413
|
}
|
|
@@ -1306,7 +1415,7 @@ var PluginManager = class {
|
|
|
1306
1415
|
if (parseResult?.result != null) {
|
|
1307
1416
|
return parseResult;
|
|
1308
1417
|
}
|
|
1309
|
-
const value = await this
|
|
1418
|
+
const value = await __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1310
1419
|
strategy: "hookFirst",
|
|
1311
1420
|
hookName,
|
|
1312
1421
|
parameters,
|
|
@@ -1331,12 +1440,12 @@ var PluginManager = class {
|
|
|
1331
1440
|
skipped
|
|
1332
1441
|
}) {
|
|
1333
1442
|
let parseResult = null;
|
|
1334
|
-
for (const plugin of this
|
|
1443
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1335
1444
|
if (skipped && skipped.has(plugin)) {
|
|
1336
1445
|
continue;
|
|
1337
1446
|
}
|
|
1338
1447
|
parseResult = {
|
|
1339
|
-
result: this
|
|
1448
|
+
result: __privateMethod(this, _executeSync, executeSync_fn).call(this, {
|
|
1340
1449
|
strategy: "hookFirst",
|
|
1341
1450
|
hookName,
|
|
1342
1451
|
parameters,
|
|
@@ -1358,8 +1467,8 @@ var PluginManager = class {
|
|
|
1358
1467
|
parameters
|
|
1359
1468
|
}) {
|
|
1360
1469
|
const parallelPromises = [];
|
|
1361
|
-
for (const plugin of this
|
|
1362
|
-
const promise = this
|
|
1470
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1471
|
+
const promise = __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
|
|
1363
1472
|
if (promise) {
|
|
1364
1473
|
parallelPromises.push(promise);
|
|
1365
1474
|
}
|
|
@@ -1386,16 +1495,16 @@ var PluginManager = class {
|
|
|
1386
1495
|
}) {
|
|
1387
1496
|
const [argument0, ...rest] = parameters;
|
|
1388
1497
|
let promise = Promise.resolve(argument0);
|
|
1389
|
-
for (const plugin of this
|
|
1498
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1390
1499
|
promise = promise.then((arg0) => {
|
|
1391
|
-
const value = this
|
|
1500
|
+
const value = __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1392
1501
|
strategy: "hookReduceArg0",
|
|
1393
1502
|
hookName,
|
|
1394
1503
|
parameters: [arg0, ...rest],
|
|
1395
1504
|
plugin
|
|
1396
1505
|
});
|
|
1397
1506
|
return value;
|
|
1398
|
-
}).then((result) => reduce.call(this
|
|
1507
|
+
}).then((result) => reduce.call(__privateGet(this, _core).api, argument0, result, plugin));
|
|
1399
1508
|
}
|
|
1400
1509
|
return promise;
|
|
1401
1510
|
}
|
|
@@ -1403,160 +1512,192 @@ var PluginManager = class {
|
|
|
1403
1512
|
* Chains plugins
|
|
1404
1513
|
*/
|
|
1405
1514
|
hookSeq({ hookName, parameters }) {
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
parameters,
|
|
1413
|
-
plugin
|
|
1414
|
-
});
|
|
1515
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1516
|
+
return () => __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1517
|
+
strategy: "hookSeq",
|
|
1518
|
+
hookName,
|
|
1519
|
+
parameters,
|
|
1520
|
+
plugin
|
|
1415
1521
|
});
|
|
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;
|
|
1522
|
+
});
|
|
1523
|
+
return __privateGet(this, _promiseManager).run("seq", promises);
|
|
1425
1524
|
}
|
|
1426
|
-
|
|
1525
|
+
getPluginsByKey(hookName, pluginKey) {
|
|
1427
1526
|
const plugins = [...this.plugins];
|
|
1428
|
-
const
|
|
1429
|
-
|
|
1430
|
-
|
|
1527
|
+
const [searchKind, searchPluginName, searchIdentifier] = pluginKey;
|
|
1528
|
+
const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
|
|
1529
|
+
const [kind, name, identifier] = item.key;
|
|
1530
|
+
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
1531
|
+
const kindCheck = kind === searchKind;
|
|
1532
|
+
const nameCheck = name === searchPluginName;
|
|
1533
|
+
if (searchIdentifier) {
|
|
1534
|
+
return identifierCheck && kindCheck && nameCheck;
|
|
1535
|
+
}
|
|
1536
|
+
return kindCheck && nameCheck;
|
|
1537
|
+
});
|
|
1538
|
+
if (!pluginByPluginName?.length) {
|
|
1539
|
+
const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
|
|
1540
|
+
if (this.logger.logLevel === "info") {
|
|
1541
|
+
if (corePlugin) {
|
|
1542
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
|
|
1543
|
+
} else {
|
|
1544
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
return corePlugin ? [corePlugin] : [];
|
|
1431
1548
|
}
|
|
1432
1549
|
return pluginByPluginName;
|
|
1433
1550
|
}
|
|
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;
|
|
1551
|
+
static getDependedPlugins(plugins, dependedPluginNames) {
|
|
1552
|
+
let pluginNames = [];
|
|
1553
|
+
if (typeof dependedPluginNames === "string") {
|
|
1554
|
+
pluginNames = [dependedPluginNames];
|
|
1555
|
+
} else {
|
|
1556
|
+
pluginNames = dependedPluginNames;
|
|
1457
1557
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
if (
|
|
1461
|
-
|
|
1462
|
-
if (isPromise(possiblePromiseResult)) {
|
|
1463
|
-
return Promise.resolve(possiblePromiseResult);
|
|
1464
|
-
}
|
|
1465
|
-
return possiblePromiseResult;
|
|
1558
|
+
return pluginNames.map((pluginName2) => {
|
|
1559
|
+
const plugin = plugins.find((plugin2) => plugin2.name === pluginName2);
|
|
1560
|
+
if (!plugin) {
|
|
1561
|
+
throw new ValidationPluginError(`This plugin depends on the ${pluginName2} plugin.`);
|
|
1466
1562
|
}
|
|
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
|
-
});
|
|
1563
|
+
return plugin;
|
|
1482
1564
|
});
|
|
1483
|
-
return task;
|
|
1484
1565
|
}
|
|
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;
|
|
1566
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
1567
|
+
static get hooks() {
|
|
1568
|
+
return ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
1569
|
+
}
|
|
1570
|
+
};
|
|
1571
|
+
_core = new WeakMap();
|
|
1572
|
+
_usedPluginNames = new WeakMap();
|
|
1573
|
+
_promiseManager = new WeakMap();
|
|
1574
|
+
_getSortedPlugins = new WeakSet();
|
|
1575
|
+
getSortedPlugins_fn = function(hookName) {
|
|
1576
|
+
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1577
|
+
if (hookName) {
|
|
1578
|
+
if (this.logger.logLevel === "info") {
|
|
1579
|
+
const containsHookName = plugins.some((item) => item[hookName]);
|
|
1580
|
+
if (!containsHookName) {
|
|
1581
|
+
this.logger.warn(`No hook ${hookName} found`);
|
|
1509
1582
|
}
|
|
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
1583
|
}
|
|
1584
|
+
return plugins.filter((item) => item[hookName]);
|
|
1524
1585
|
}
|
|
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
|
-
}
|
|
1586
|
+
return plugins;
|
|
1532
1587
|
};
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1588
|
+
_addExecutedToCallStack = new WeakSet();
|
|
1589
|
+
addExecutedToCallStack_fn = function(executer) {
|
|
1590
|
+
if (executer) {
|
|
1591
|
+
this.eventEmitter.emit("executed", executer);
|
|
1592
|
+
this.executed.push(executer);
|
|
1593
|
+
}
|
|
1538
1594
|
};
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1595
|
+
_execute = new WeakSet();
|
|
1596
|
+
execute_fn = function({
|
|
1597
|
+
strategy,
|
|
1598
|
+
hookName,
|
|
1599
|
+
parameters,
|
|
1600
|
+
plugin
|
|
1601
|
+
}) {
|
|
1602
|
+
const hook = plugin[hookName];
|
|
1603
|
+
let output;
|
|
1604
|
+
if (!hook) {
|
|
1605
|
+
return null;
|
|
1606
|
+
}
|
|
1607
|
+
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1608
|
+
const task = Promise.resolve().then(() => {
|
|
1609
|
+
if (typeof hook === "function") {
|
|
1610
|
+
const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
1611
|
+
if (isPromise(possiblePromiseResult)) {
|
|
1612
|
+
return Promise.resolve(possiblePromiseResult);
|
|
1613
|
+
}
|
|
1614
|
+
return possiblePromiseResult;
|
|
1615
|
+
}
|
|
1616
|
+
return hook;
|
|
1617
|
+
}).then((result) => {
|
|
1618
|
+
output = result;
|
|
1619
|
+
return result;
|
|
1620
|
+
}).catch((e) => {
|
|
1621
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1622
|
+
return null;
|
|
1623
|
+
}).finally(() => {
|
|
1624
|
+
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1625
|
+
parameters,
|
|
1626
|
+
output,
|
|
1627
|
+
strategy,
|
|
1628
|
+
hookName,
|
|
1629
|
+
plugin
|
|
1630
|
+
});
|
|
1552
1631
|
});
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1632
|
+
return task;
|
|
1633
|
+
};
|
|
1634
|
+
_executeSync = new WeakSet();
|
|
1635
|
+
executeSync_fn = function({
|
|
1636
|
+
strategy,
|
|
1637
|
+
hookName,
|
|
1638
|
+
parameters,
|
|
1639
|
+
plugin
|
|
1640
|
+
}) {
|
|
1641
|
+
const hook = plugin[hookName];
|
|
1642
|
+
let output;
|
|
1643
|
+
if (!hook) {
|
|
1644
|
+
return null;
|
|
1645
|
+
}
|
|
1646
|
+
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1647
|
+
try {
|
|
1648
|
+
if (typeof hook === "function") {
|
|
1649
|
+
const fn = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
1650
|
+
output = fn;
|
|
1651
|
+
return fn;
|
|
1652
|
+
}
|
|
1653
|
+
output = hook;
|
|
1654
|
+
return hook;
|
|
1655
|
+
} catch (e) {
|
|
1656
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1657
|
+
return null;
|
|
1658
|
+
} finally {
|
|
1659
|
+
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1660
|
+
parameters,
|
|
1661
|
+
output,
|
|
1662
|
+
strategy,
|
|
1663
|
+
hookName,
|
|
1664
|
+
plugin
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
};
|
|
1668
|
+
_catcher = new WeakSet();
|
|
1669
|
+
catcher_fn = function(e, plugin, hookName) {
|
|
1670
|
+
const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
|
|
1671
|
+
`;
|
|
1672
|
+
const pluginError = new PluginError(text, { cause: e, pluginManager: this });
|
|
1673
|
+
this.eventEmitter.emit("error", pluginError);
|
|
1674
|
+
throw pluginError;
|
|
1675
|
+
};
|
|
1676
|
+
_parse = new WeakSet();
|
|
1677
|
+
parse_fn = function(plugin, pluginManager, context) {
|
|
1678
|
+
const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
|
|
1679
|
+
setUniqueName(plugin.name, usedPluginNames);
|
|
1680
|
+
const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
1681
|
+
if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
|
|
1682
|
+
pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
|
|
1683
|
+
}
|
|
1684
|
+
if (!plugin.transform) {
|
|
1685
|
+
plugin.transform = function transform(code) {
|
|
1686
|
+
return code;
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
if (plugin.api && typeof plugin.api === "function") {
|
|
1690
|
+
const api = plugin.api.call(context);
|
|
1691
|
+
return {
|
|
1692
|
+
...plugin,
|
|
1693
|
+
key,
|
|
1694
|
+
api
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
1697
|
+
return {
|
|
1698
|
+
...plugin,
|
|
1699
|
+
key
|
|
1700
|
+
};
|
|
1560
1701
|
};
|
|
1561
1702
|
|
|
1562
1703
|
// src/build.ts
|
|
@@ -1564,13 +1705,13 @@ async function transformReducer(_previousCode, result, _plugin) {
|
|
|
1564
1705
|
return result;
|
|
1565
1706
|
}
|
|
1566
1707
|
async function build(options) {
|
|
1567
|
-
const { config,
|
|
1708
|
+
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
1568
1709
|
try {
|
|
1569
|
-
if (
|
|
1710
|
+
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
1570
1711
|
await read(config.input.path);
|
|
1571
1712
|
}
|
|
1572
1713
|
} catch (e) {
|
|
1573
|
-
if (
|
|
1714
|
+
if (isInputPath(config)) {
|
|
1574
1715
|
throw new Error(
|
|
1575
1716
|
"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
1717
|
{
|
|
@@ -1583,11 +1724,11 @@ async function build(options) {
|
|
|
1583
1724
|
await clean(config.output.path);
|
|
1584
1725
|
}
|
|
1585
1726
|
const queueTask = async (file) => {
|
|
1586
|
-
const { path:
|
|
1587
|
-
let code =
|
|
1727
|
+
const { path: path5 } = file;
|
|
1728
|
+
let code = FileManager.getSource(file);
|
|
1588
1729
|
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1589
1730
|
hookName: "load",
|
|
1590
|
-
parameters: [
|
|
1731
|
+
parameters: [path5]
|
|
1591
1732
|
});
|
|
1592
1733
|
if (loadedResult && isPromise(loadedResult)) {
|
|
1593
1734
|
code = await loadedResult;
|
|
@@ -1598,28 +1739,53 @@ async function build(options) {
|
|
|
1598
1739
|
if (code) {
|
|
1599
1740
|
const transformedCode = await pluginManager.hookReduceArg0({
|
|
1600
1741
|
hookName: "transform",
|
|
1601
|
-
parameters: [code,
|
|
1742
|
+
parameters: [code, path5],
|
|
1602
1743
|
reduce: transformReducer
|
|
1603
1744
|
});
|
|
1604
1745
|
if (config.output.write || config.output.write === void 0) {
|
|
1605
|
-
|
|
1746
|
+
if (file.meta?.pluginKey) {
|
|
1747
|
+
return pluginManager.hookForPlugin({
|
|
1748
|
+
pluginKey: file.meta?.pluginKey,
|
|
1749
|
+
hookName: "writeFile",
|
|
1750
|
+
parameters: [transformedCode, path5]
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
return pluginManager.hookFirst({
|
|
1606
1754
|
hookName: "writeFile",
|
|
1607
|
-
parameters: [transformedCode,
|
|
1755
|
+
parameters: [transformedCode, path5]
|
|
1608
1756
|
});
|
|
1609
1757
|
}
|
|
1610
1758
|
}
|
|
1611
1759
|
};
|
|
1612
|
-
const pluginManager = new PluginManager(config, {
|
|
1760
|
+
const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
|
|
1613
1761
|
const { plugins, fileManager } = pluginManager;
|
|
1614
1762
|
pluginManager.on("execute", (executer) => {
|
|
1763
|
+
const { hookName, parameters, plugin } = executer;
|
|
1764
|
+
if (hookName === "writeFile" && logger.spinner) {
|
|
1765
|
+
const [code] = parameters;
|
|
1766
|
+
if (logger.logLevel === LogLevel.info) {
|
|
1767
|
+
logger.spinner.start(`\u{1F4BE} Writing`);
|
|
1768
|
+
}
|
|
1769
|
+
if (logger.logLevel === "debug") {
|
|
1770
|
+
logger.info(`PluginKey ${pc3__default.default.dim(JSON.stringify(plugin.key))}
|
|
1771
|
+
with source
|
|
1772
|
+
|
|
1773
|
+
${code}`);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
});
|
|
1777
|
+
pluginManager.on("executed", (executer) => {
|
|
1615
1778
|
const { hookName, plugin, output, parameters } = executer;
|
|
1616
1779
|
const messsage = `${randomPicoColour(plugin.name)} Executing ${hookName}`;
|
|
1617
|
-
if (logLevel === LogLevel.info) {
|
|
1618
|
-
if (
|
|
1780
|
+
if (logger.logLevel === LogLevel.info && logger.spinner) {
|
|
1781
|
+
if (hookName === "writeFile") {
|
|
1782
|
+
const [_code, path5] = parameters;
|
|
1783
|
+
logger.spinner.suffixText = pc3__default.default.dim(path5);
|
|
1784
|
+
} else {
|
|
1619
1785
|
logger.spinner.suffixText = messsage;
|
|
1620
1786
|
}
|
|
1621
1787
|
}
|
|
1622
|
-
if (logLevel === LogLevel.debug) {
|
|
1788
|
+
if (logger.logLevel === LogLevel.debug) {
|
|
1623
1789
|
logger.info(messsage);
|
|
1624
1790
|
const logs = [
|
|
1625
1791
|
parameters && `${pc3__default.default.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
|
|
@@ -1639,93 +1805,95 @@ async function build(options) {
|
|
|
1639
1805
|
parameters: [config]
|
|
1640
1806
|
});
|
|
1641
1807
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
return options;
|
|
1808
|
+
if (!fileManager.isExecuting && logger.spinner) {
|
|
1809
|
+
logger.spinner.suffixText = "";
|
|
1810
|
+
logger.spinner.succeed(`\u{1F4BE} Writing completed`);
|
|
1811
|
+
}
|
|
1812
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1648
1813
|
}
|
|
1649
1814
|
|
|
1650
|
-
// src/
|
|
1815
|
+
// src/Generator.ts
|
|
1816
|
+
var _options3, _context;
|
|
1651
1817
|
var Generator = class {
|
|
1652
|
-
#options = {};
|
|
1653
|
-
#context = {};
|
|
1654
1818
|
constructor(options, context) {
|
|
1819
|
+
__privateAdd(this, _options3, {});
|
|
1820
|
+
__privateAdd(this, _context, {});
|
|
1655
1821
|
if (context) {
|
|
1656
|
-
this
|
|
1822
|
+
__privateSet(this, _context, context);
|
|
1657
1823
|
}
|
|
1658
1824
|
if (options) {
|
|
1659
|
-
this
|
|
1825
|
+
__privateSet(this, _options3, options);
|
|
1660
1826
|
}
|
|
1661
1827
|
return this;
|
|
1662
1828
|
}
|
|
1663
1829
|
get options() {
|
|
1664
|
-
return this
|
|
1830
|
+
return __privateGet(this, _options3);
|
|
1665
1831
|
}
|
|
1666
1832
|
get context() {
|
|
1667
|
-
return this
|
|
1833
|
+
return __privateGet(this, _context);
|
|
1668
1834
|
}
|
|
1669
1835
|
set options(options) {
|
|
1670
|
-
this
|
|
1836
|
+
__privateSet(this, _options3, { ...__privateGet(this, _options3), ...options });
|
|
1671
1837
|
}
|
|
1672
1838
|
};
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
var SchemaGenerator = class extends Generator {
|
|
1676
|
-
};
|
|
1839
|
+
_options3 = new WeakMap();
|
|
1840
|
+
_context = new WeakMap();
|
|
1677
1841
|
|
|
1678
1842
|
// ../../node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
|
|
1679
1843
|
var Node = class {
|
|
1680
|
-
value;
|
|
1681
|
-
next;
|
|
1682
1844
|
constructor(value) {
|
|
1845
|
+
__publicField(this, "value");
|
|
1846
|
+
__publicField(this, "next");
|
|
1683
1847
|
this.value = value;
|
|
1684
1848
|
}
|
|
1685
1849
|
};
|
|
1850
|
+
var _head, _tail, _size;
|
|
1686
1851
|
var Queue2 = class {
|
|
1687
|
-
#head;
|
|
1688
|
-
#tail;
|
|
1689
|
-
#size;
|
|
1690
1852
|
constructor() {
|
|
1853
|
+
__privateAdd(this, _head, void 0);
|
|
1854
|
+
__privateAdd(this, _tail, void 0);
|
|
1855
|
+
__privateAdd(this, _size, void 0);
|
|
1691
1856
|
this.clear();
|
|
1692
1857
|
}
|
|
1693
1858
|
enqueue(value) {
|
|
1694
1859
|
const node = new Node(value);
|
|
1695
|
-
if (this
|
|
1696
|
-
this
|
|
1697
|
-
this
|
|
1860
|
+
if (__privateGet(this, _head)) {
|
|
1861
|
+
__privateGet(this, _tail).next = node;
|
|
1862
|
+
__privateSet(this, _tail, node);
|
|
1698
1863
|
} else {
|
|
1699
|
-
this
|
|
1700
|
-
this
|
|
1864
|
+
__privateSet(this, _head, node);
|
|
1865
|
+
__privateSet(this, _tail, node);
|
|
1701
1866
|
}
|
|
1702
|
-
this
|
|
1867
|
+
__privateWrapper(this, _size)._++;
|
|
1703
1868
|
}
|
|
1704
1869
|
dequeue() {
|
|
1705
|
-
const current = this
|
|
1870
|
+
const current = __privateGet(this, _head);
|
|
1706
1871
|
if (!current) {
|
|
1707
1872
|
return;
|
|
1708
1873
|
}
|
|
1709
|
-
this
|
|
1710
|
-
this
|
|
1874
|
+
__privateSet(this, _head, __privateGet(this, _head).next);
|
|
1875
|
+
__privateWrapper(this, _size)._--;
|
|
1711
1876
|
return current.value;
|
|
1712
1877
|
}
|
|
1713
1878
|
clear() {
|
|
1714
|
-
this
|
|
1715
|
-
this
|
|
1716
|
-
this
|
|
1879
|
+
__privateSet(this, _head, void 0);
|
|
1880
|
+
__privateSet(this, _tail, void 0);
|
|
1881
|
+
__privateSet(this, _size, 0);
|
|
1717
1882
|
}
|
|
1718
1883
|
get size() {
|
|
1719
|
-
return this
|
|
1884
|
+
return __privateGet(this, _size);
|
|
1720
1885
|
}
|
|
1721
1886
|
*[Symbol.iterator]() {
|
|
1722
|
-
let current = this
|
|
1887
|
+
let current = __privateGet(this, _head);
|
|
1723
1888
|
while (current) {
|
|
1724
1889
|
yield current.value;
|
|
1725
1890
|
current = current.next;
|
|
1726
1891
|
}
|
|
1727
1892
|
}
|
|
1728
1893
|
};
|
|
1894
|
+
_head = new WeakMap();
|
|
1895
|
+
_tail = new WeakMap();
|
|
1896
|
+
_size = new WeakMap();
|
|
1729
1897
|
|
|
1730
1898
|
// ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
|
|
1731
1899
|
function pLimit(concurrency) {
|
|
@@ -1740,18 +1908,18 @@ function pLimit(concurrency) {
|
|
|
1740
1908
|
queue.dequeue()();
|
|
1741
1909
|
}
|
|
1742
1910
|
};
|
|
1743
|
-
const run = async (fn,
|
|
1911
|
+
const run = async (fn, resolve2, args) => {
|
|
1744
1912
|
activeCount++;
|
|
1745
1913
|
const result = (async () => fn(...args))();
|
|
1746
|
-
|
|
1914
|
+
resolve2(result);
|
|
1747
1915
|
try {
|
|
1748
1916
|
await result;
|
|
1749
1917
|
} catch {
|
|
1750
1918
|
}
|
|
1751
1919
|
next();
|
|
1752
1920
|
};
|
|
1753
|
-
const enqueue = (fn,
|
|
1754
|
-
queue.enqueue(run.bind(void 0, fn,
|
|
1921
|
+
const enqueue = (fn, resolve2, args) => {
|
|
1922
|
+
queue.enqueue(run.bind(void 0, fn, resolve2, args));
|
|
1755
1923
|
(async () => {
|
|
1756
1924
|
await Promise.resolve();
|
|
1757
1925
|
if (activeCount < concurrency && queue.size > 0) {
|
|
@@ -1759,8 +1927,8 @@ function pLimit(concurrency) {
|
|
|
1759
1927
|
}
|
|
1760
1928
|
})();
|
|
1761
1929
|
};
|
|
1762
|
-
const generator = (fn, ...args) => new Promise((
|
|
1763
|
-
enqueue(fn,
|
|
1930
|
+
const generator = (fn, ...args) => new Promise((resolve2) => {
|
|
1931
|
+
enqueue(fn, resolve2, args);
|
|
1764
1932
|
});
|
|
1765
1933
|
Object.defineProperties(generator, {
|
|
1766
1934
|
activeCount: {
|
|
@@ -1835,7 +2003,7 @@ async function locatePath(paths, {
|
|
|
1835
2003
|
const statFunction = allowSymlinks ? fs3.promises.stat : fs3.promises.lstat;
|
|
1836
2004
|
return pLocate(paths, async (path_) => {
|
|
1837
2005
|
try {
|
|
1838
|
-
const stat = await statFunction(
|
|
2006
|
+
const stat = await statFunction(path4__default.default.resolve(cwd, path_));
|
|
1839
2007
|
return matchType(type, stat);
|
|
1840
2008
|
} catch {
|
|
1841
2009
|
return false;
|
|
@@ -1852,7 +2020,7 @@ function locatePathSync(paths, {
|
|
|
1852
2020
|
const statFunction = allowSymlinks ? fs3__default.default.statSync : fs3__default.default.lstatSync;
|
|
1853
2021
|
for (const path_ of paths) {
|
|
1854
2022
|
try {
|
|
1855
|
-
const stat = statFunction(
|
|
2023
|
+
const stat = statFunction(path4__default.default.resolve(cwd, path_), {
|
|
1856
2024
|
throwIfNoEntry: false
|
|
1857
2025
|
});
|
|
1858
2026
|
if (!stat) {
|
|
@@ -1870,9 +2038,9 @@ function locatePathSync(paths, {
|
|
|
1870
2038
|
var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? url.fileURLToPath(urlOrPath) : urlOrPath;
|
|
1871
2039
|
var findUpStop = Symbol("findUpStop");
|
|
1872
2040
|
async function findUpMultiple(name, options = {}) {
|
|
1873
|
-
let directory =
|
|
1874
|
-
const { root } =
|
|
1875
|
-
const stopAt =
|
|
2041
|
+
let directory = path4__default.default.resolve(toPath2(options.cwd) || "");
|
|
2042
|
+
const { root } = path4__default.default.parse(directory);
|
|
2043
|
+
const stopAt = path4__default.default.resolve(directory, options.stopAt || root);
|
|
1876
2044
|
const limit = options.limit || Number.POSITIVE_INFINITY;
|
|
1877
2045
|
const paths = [name].flat();
|
|
1878
2046
|
const runMatcher = async (locateOptions) => {
|
|
@@ -1892,18 +2060,18 @@ async function findUpMultiple(name, options = {}) {
|
|
|
1892
2060
|
break;
|
|
1893
2061
|
}
|
|
1894
2062
|
if (foundPath) {
|
|
1895
|
-
matches.push(
|
|
2063
|
+
matches.push(path4__default.default.resolve(directory, foundPath));
|
|
1896
2064
|
}
|
|
1897
2065
|
if (directory === stopAt || matches.length >= limit) {
|
|
1898
2066
|
break;
|
|
1899
2067
|
}
|
|
1900
|
-
directory =
|
|
2068
|
+
directory = path4__default.default.dirname(directory);
|
|
1901
2069
|
}
|
|
1902
2070
|
return matches;
|
|
1903
2071
|
}
|
|
1904
2072
|
function findUpMultipleSync(name, options = {}) {
|
|
1905
|
-
let directory =
|
|
1906
|
-
const { root } =
|
|
2073
|
+
let directory = path4__default.default.resolve(toPath2(options.cwd) || "");
|
|
2074
|
+
const { root } = path4__default.default.parse(directory);
|
|
1907
2075
|
const stopAt = options.stopAt || root;
|
|
1908
2076
|
const limit = options.limit || Number.POSITIVE_INFINITY;
|
|
1909
2077
|
const paths = [name].flat();
|
|
@@ -1924,12 +2092,12 @@ function findUpMultipleSync(name, options = {}) {
|
|
|
1924
2092
|
break;
|
|
1925
2093
|
}
|
|
1926
2094
|
if (foundPath) {
|
|
1927
|
-
matches.push(
|
|
2095
|
+
matches.push(path4__default.default.resolve(directory, foundPath));
|
|
1928
2096
|
}
|
|
1929
2097
|
if (directory === stopAt || matches.length >= limit) {
|
|
1930
2098
|
break;
|
|
1931
2099
|
}
|
|
1932
|
-
directory =
|
|
2100
|
+
directory = path4__default.default.dirname(directory);
|
|
1933
2101
|
}
|
|
1934
2102
|
return matches;
|
|
1935
2103
|
}
|
|
@@ -1941,39 +2109,39 @@ function findUpSync(name, options = {}) {
|
|
|
1941
2109
|
const matches = findUpMultipleSync(name, { ...options, limit: 1 });
|
|
1942
2110
|
return matches[0];
|
|
1943
2111
|
}
|
|
1944
|
-
var
|
|
1945
|
-
|
|
1946
|
-
#cwd;
|
|
1947
|
-
#SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
|
|
2112
|
+
var _cache2, _cwd, _SLASHES;
|
|
2113
|
+
var _PackageManager = class _PackageManager {
|
|
1948
2114
|
constructor(workspace) {
|
|
2115
|
+
__privateAdd(this, _cwd, void 0);
|
|
2116
|
+
__privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
|
|
1949
2117
|
if (workspace) {
|
|
1950
|
-
this
|
|
2118
|
+
__privateSet(this, _cwd, workspace);
|
|
1951
2119
|
}
|
|
1952
2120
|
return this;
|
|
1953
2121
|
}
|
|
1954
2122
|
set workspace(workspace) {
|
|
1955
|
-
this
|
|
2123
|
+
__privateSet(this, _cwd, workspace);
|
|
1956
2124
|
}
|
|
1957
2125
|
get workspace() {
|
|
1958
|
-
return this
|
|
2126
|
+
return __privateGet(this, _cwd);
|
|
1959
2127
|
}
|
|
1960
2128
|
normalizeDirectory(directory) {
|
|
1961
|
-
if (!this
|
|
2129
|
+
if (!__privateGet(this, _SLASHES).has(directory[directory.length - 1])) {
|
|
1962
2130
|
return `${directory}/`;
|
|
1963
2131
|
}
|
|
1964
2132
|
return directory;
|
|
1965
2133
|
}
|
|
1966
|
-
getLocation(
|
|
1967
|
-
let location =
|
|
1968
|
-
if (this
|
|
1969
|
-
const require2 = mod__default.default.createRequire(this.normalizeDirectory(this
|
|
1970
|
-
location = require2.resolve(
|
|
2134
|
+
getLocation(path5) {
|
|
2135
|
+
let location = path5;
|
|
2136
|
+
if (__privateGet(this, _cwd)) {
|
|
2137
|
+
const require2 = mod__default.default.createRequire(this.normalizeDirectory(__privateGet(this, _cwd)));
|
|
2138
|
+
location = require2.resolve(path5);
|
|
1971
2139
|
}
|
|
1972
2140
|
return location;
|
|
1973
2141
|
}
|
|
1974
|
-
async import(
|
|
2142
|
+
async import(path5) {
|
|
1975
2143
|
try {
|
|
1976
|
-
let location = this.getLocation(
|
|
2144
|
+
let location = this.getLocation(path5);
|
|
1977
2145
|
if (os__default.default.platform() == "win32") {
|
|
1978
2146
|
location = url.pathToFileURL(location).href;
|
|
1979
2147
|
}
|
|
@@ -1986,7 +2154,7 @@ var PackageManager = class _PackageManager {
|
|
|
1986
2154
|
}
|
|
1987
2155
|
async getPackageJSON() {
|
|
1988
2156
|
const pkgPath = await findUp(["package.json"], {
|
|
1989
|
-
cwd: this
|
|
2157
|
+
cwd: __privateGet(this, _cwd)
|
|
1990
2158
|
});
|
|
1991
2159
|
if (!pkgPath) {
|
|
1992
2160
|
return void 0;
|
|
@@ -1995,7 +2163,7 @@ var PackageManager = class _PackageManager {
|
|
|
1995
2163
|
}
|
|
1996
2164
|
getPackageJSONSync() {
|
|
1997
2165
|
const pkgPath = findUpSync(["package.json"], {
|
|
1998
|
-
cwd: this
|
|
2166
|
+
cwd: __privateGet(this, _cwd)
|
|
1999
2167
|
});
|
|
2000
2168
|
if (!pkgPath) {
|
|
2001
2169
|
return void 0;
|
|
@@ -2003,11 +2171,11 @@ var PackageManager = class _PackageManager {
|
|
|
2003
2171
|
return __require(pkgPath);
|
|
2004
2172
|
}
|
|
2005
2173
|
static setVersion(dependency, version) {
|
|
2006
|
-
_PackageManager
|
|
2174
|
+
__privateGet(_PackageManager, _cache2)[dependency] = version;
|
|
2007
2175
|
}
|
|
2008
2176
|
async getVersion(dependency) {
|
|
2009
|
-
if (_PackageManager
|
|
2010
|
-
return _PackageManager
|
|
2177
|
+
if (__privateGet(_PackageManager, _cache2)[dependency]) {
|
|
2178
|
+
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
2011
2179
|
}
|
|
2012
2180
|
const packageJSON = await this.getPackageJSON();
|
|
2013
2181
|
if (!packageJSON) {
|
|
@@ -2016,8 +2184,8 @@ var PackageManager = class _PackageManager {
|
|
|
2016
2184
|
return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
|
|
2017
2185
|
}
|
|
2018
2186
|
getVersionSync(dependency) {
|
|
2019
|
-
if (_PackageManager
|
|
2020
|
-
return _PackageManager
|
|
2187
|
+
if (__privateGet(_PackageManager, _cache2)[dependency]) {
|
|
2188
|
+
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
2021
2189
|
}
|
|
2022
2190
|
const packageJSON = this.getPackageJSONSync();
|
|
2023
2191
|
if (!packageJSON) {
|
|
@@ -2048,68 +2216,38 @@ var PackageManager = class _PackageManager {
|
|
|
2048
2216
|
return semver.satisfies(semVer, version);
|
|
2049
2217
|
}
|
|
2050
2218
|
};
|
|
2219
|
+
_cache2 = new WeakMap();
|
|
2220
|
+
_cwd = new WeakMap();
|
|
2221
|
+
_SLASHES = new WeakMap();
|
|
2222
|
+
__privateAdd(_PackageManager, _cache2, {});
|
|
2223
|
+
var PackageManager = _PackageManager;
|
|
2224
|
+
|
|
2225
|
+
// src/SchemaGenerator.ts
|
|
2226
|
+
var SchemaGenerator = class extends Generator {
|
|
2227
|
+
};
|
|
2051
2228
|
|
|
2052
2229
|
// src/index.ts
|
|
2053
2230
|
var src_default = build;
|
|
2054
2231
|
|
|
2055
|
-
Object.defineProperty(exports, 'pc', {
|
|
2056
|
-
enumerable: true,
|
|
2057
|
-
get: function () { return pc3__default.default; }
|
|
2058
|
-
});
|
|
2059
2232
|
exports.FileManager = FileManager;
|
|
2060
|
-
exports.FunctionParams = FunctionParams;
|
|
2061
2233
|
exports.Generator = Generator;
|
|
2062
|
-
exports.LogLevel = LogLevel;
|
|
2063
2234
|
exports.PackageManager = PackageManager;
|
|
2064
2235
|
exports.ParallelPluginError = ParallelPluginError;
|
|
2065
2236
|
exports.PluginError = PluginError;
|
|
2066
2237
|
exports.PluginManager = PluginManager;
|
|
2067
|
-
exports.
|
|
2238
|
+
exports.PromiseManager = PromiseManager;
|
|
2068
2239
|
exports.SchemaGenerator = SchemaGenerator;
|
|
2069
2240
|
exports.SummaryError = SummaryError;
|
|
2070
|
-
exports.TreeNode = TreeNode;
|
|
2071
|
-
exports.URLPath = URLPath;
|
|
2072
2241
|
exports.ValidationPluginError = ValidationPluginError;
|
|
2073
2242
|
exports.Warning = Warning;
|
|
2074
2243
|
exports.build = build;
|
|
2075
|
-
exports.clean = clean;
|
|
2076
|
-
exports.combineCodes = combineCodes;
|
|
2077
2244
|
exports.combineExports = combineExports;
|
|
2078
|
-
exports.combineFiles = combineFiles;
|
|
2079
2245
|
exports.combineImports = combineImports;
|
|
2080
|
-
exports.createFileSource = createFileSource;
|
|
2081
|
-
exports.createJSDocBlockText = createJSDocBlockText;
|
|
2082
|
-
exports.createLogger = createLogger;
|
|
2083
2246
|
exports.createPlugin = createPlugin;
|
|
2084
|
-
exports.createPluginCache = createPluginCache;
|
|
2085
2247
|
exports.default = src_default;
|
|
2086
|
-
exports.defaultColours = defaultColours;
|
|
2087
2248
|
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;
|
|
2249
|
+
exports.isInputPath = isInputPath;
|
|
2101
2250
|
exports.name = pluginName;
|
|
2102
|
-
exports.nameSorter = nameSorter;
|
|
2103
2251
|
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
2252
|
//# sourceMappingURL=out.js.map
|
|
2115
2253
|
//# sourceMappingURL=index.cjs.map
|