@kubb/core 1.15.0-canary.20231025T223729 → 1.15.0-canary.20231026T165002
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 +842 -904
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +320 -266
- package/dist/index.d.ts +320 -266
- package/dist/index.js +783 -863
- package/dist/index.js.map +1 -1
- package/globals.d.ts +16 -33
- package/package.json +3 -8
- package/dist/utils.cjs +0 -1194
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts +0 -228
- package/dist/utils.d.ts +0 -228
- package/dist/utils.js +0 -1145
- package/dist/utils.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -3,19 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var pc3 = require('picocolors');
|
|
6
|
+
var crypto = require('crypto');
|
|
6
7
|
var fs2 = require('fs-extra');
|
|
8
|
+
var changeCase = require('change-case');
|
|
9
|
+
var naturalOrderby = require('natural-orderby');
|
|
10
|
+
var perf_hooks = require('perf_hooks');
|
|
7
11
|
var seedrandom = require('seedrandom');
|
|
8
|
-
var
|
|
12
|
+
var path2 = require('path');
|
|
9
13
|
var jsRuntime = require('js-runtime');
|
|
10
|
-
var
|
|
11
|
-
var crypto2 = require('crypto');
|
|
14
|
+
var dirTree = require('directory-tree');
|
|
12
15
|
var parser = require('@kubb/parser');
|
|
13
|
-
var factory = require('@kubb/parser/factory');
|
|
14
16
|
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');
|
|
19
18
|
var mod = require('module');
|
|
20
19
|
var os = require('os');
|
|
21
20
|
var url = require('url');
|
|
@@ -25,32 +24,13 @@ var semver = require('semver');
|
|
|
25
24
|
|
|
26
25
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
27
26
|
|
|
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
|
-
|
|
46
27
|
var pc3__default = /*#__PURE__*/_interopDefault(pc3);
|
|
28
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
47
29
|
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
48
30
|
var seedrandom__default = /*#__PURE__*/_interopDefault(seedrandom);
|
|
49
|
-
var
|
|
50
|
-
var crypto2__default = /*#__PURE__*/_interopDefault(crypto2);
|
|
51
|
-
var factory__namespace = /*#__PURE__*/_interopNamespace(factory);
|
|
52
|
-
var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
|
|
31
|
+
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
53
32
|
var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
|
|
33
|
+
var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
|
|
54
34
|
var mod__default = /*#__PURE__*/_interopDefault(mod);
|
|
55
35
|
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
56
36
|
var process__default = /*#__PURE__*/_interopDefault(process);
|
|
@@ -63,15 +43,110 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
63
43
|
return require.apply(this, arguments);
|
|
64
44
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
65
45
|
});
|
|
66
|
-
|
|
67
|
-
|
|
46
|
+
|
|
47
|
+
// src/utils/cache.ts
|
|
48
|
+
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
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
|
+
};
|
|
68
73
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
+
}
|
|
73
115
|
};
|
|
74
|
-
|
|
116
|
+
|
|
117
|
+
// src/utils/getUniqueName.ts
|
|
118
|
+
function getUniqueName(originalName, data) {
|
|
119
|
+
let used = data[originalName] || 0;
|
|
120
|
+
if (used) {
|
|
121
|
+
data[originalName] = ++used;
|
|
122
|
+
originalName += used;
|
|
123
|
+
}
|
|
124
|
+
data[originalName] = 1;
|
|
125
|
+
return originalName;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/utils/isPromise.ts
|
|
129
|
+
function isPromise(result) {
|
|
130
|
+
return typeof result?.then === "function";
|
|
131
|
+
}
|
|
132
|
+
function isPromiseFulfilledResult(result) {
|
|
133
|
+
return result.status === "fulfilled";
|
|
134
|
+
}
|
|
135
|
+
function isPromiseRejectedResult(result) {
|
|
136
|
+
return result.status === "rejected";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/utils/jsdoc.ts
|
|
140
|
+
function createJSDocBlockText({ comments }) {
|
|
141
|
+
const filteredComments = comments.filter(Boolean);
|
|
142
|
+
if (!filteredComments.length) {
|
|
143
|
+
return "";
|
|
144
|
+
}
|
|
145
|
+
return `/**
|
|
146
|
+
* ${filteredComments.join("\n * ")}
|
|
147
|
+
*/`;
|
|
148
|
+
}
|
|
149
|
+
function createLogger(spinner) {
|
|
75
150
|
const logs = [];
|
|
76
151
|
const log = (message) => {
|
|
77
152
|
if (message && spinner) {
|
|
@@ -97,8 +172,6 @@ function createLogger({ logLevel, name, spinner }) {
|
|
|
97
172
|
}
|
|
98
173
|
};
|
|
99
174
|
const logger = {
|
|
100
|
-
name,
|
|
101
|
-
logLevel,
|
|
102
175
|
log,
|
|
103
176
|
error,
|
|
104
177
|
warn,
|
|
@@ -108,6 +181,75 @@ function createLogger({ logLevel, name, spinner }) {
|
|
|
108
181
|
};
|
|
109
182
|
return logger;
|
|
110
183
|
}
|
|
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
|
+
};
|
|
111
253
|
var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
|
|
112
254
|
function randomColour(text, colours = defaultColours) {
|
|
113
255
|
if (!text) {
|
|
@@ -134,22 +276,46 @@ function randomPicoColour(text, colors = defaultColours) {
|
|
|
134
276
|
}
|
|
135
277
|
return formatter(text);
|
|
136
278
|
}
|
|
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
|
+
}
|
|
137
303
|
var reader = jsRuntime.switcher(
|
|
138
304
|
{
|
|
139
|
-
node: async (
|
|
140
|
-
return fs2__default.default.readFile(
|
|
305
|
+
node: async (path3) => {
|
|
306
|
+
return fs2__default.default.readFile(path3, { encoding: "utf8" });
|
|
141
307
|
},
|
|
142
|
-
bun: async (
|
|
143
|
-
const file = Bun.file(
|
|
308
|
+
bun: async (path3) => {
|
|
309
|
+
const file = Bun.file(path3);
|
|
144
310
|
return file.text();
|
|
145
311
|
}
|
|
146
312
|
},
|
|
147
313
|
"node"
|
|
148
314
|
);
|
|
149
|
-
jsRuntime.switcher(
|
|
315
|
+
var syncReader = jsRuntime.switcher(
|
|
150
316
|
{
|
|
151
|
-
node: (
|
|
152
|
-
return fs2__default.default.readFileSync(
|
|
317
|
+
node: (path3) => {
|
|
318
|
+
return fs2__default.default.readFileSync(path3, { encoding: "utf8" });
|
|
153
319
|
},
|
|
154
320
|
bun: () => {
|
|
155
321
|
throw new Error("Bun cannot read sync");
|
|
@@ -157,116 +323,79 @@ jsRuntime.switcher(
|
|
|
157
323
|
},
|
|
158
324
|
"node"
|
|
159
325
|
);
|
|
160
|
-
async function read(
|
|
161
|
-
return reader(
|
|
326
|
+
async function read(path3) {
|
|
327
|
+
return reader(path3);
|
|
162
328
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
try {
|
|
178
|
-
const url = new URL(this.path);
|
|
179
|
-
if (url?.href) {
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
} catch (error) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
189
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
190
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
191
|
-
* @example /account/userID => `/account/${userId}`
|
|
192
|
-
*/
|
|
193
|
-
get template() {
|
|
194
|
-
return this.toTemplateString();
|
|
195
|
-
}
|
|
196
|
-
get object() {
|
|
197
|
-
return this.toObject();
|
|
198
|
-
}
|
|
199
|
-
get params() {
|
|
200
|
-
return this.getParams();
|
|
201
|
-
}
|
|
202
|
-
toObject({ type = "path", replacer, stringify } = {}) {
|
|
203
|
-
const object = {
|
|
204
|
-
url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
|
|
205
|
-
params: this.getParams()
|
|
206
|
-
};
|
|
207
|
-
if (stringify) {
|
|
208
|
-
if (type !== "template") {
|
|
209
|
-
throw new Error("Type should be `template` when using stringiyf");
|
|
210
|
-
}
|
|
211
|
-
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
212
|
-
}
|
|
213
|
-
return object;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
217
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
218
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
219
|
-
* @example /account/userID => `/account/${userId}`
|
|
220
|
-
*/
|
|
221
|
-
toTemplateString(replacer) {
|
|
222
|
-
const regex = /{(\w|-)*}/g;
|
|
223
|
-
const found = this.path.match(regex);
|
|
224
|
-
let newPath = this.path.replaceAll("{", "${");
|
|
225
|
-
if (found) {
|
|
226
|
-
newPath = found.reduce((prev, curr) => {
|
|
227
|
-
const pathParam = replacer ? replacer(changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
228
|
-
const replacement = `\${${pathParam}}`;
|
|
229
|
-
return prev.replace(curr, replacement);
|
|
230
|
-
}, this.path);
|
|
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;
|
|
231
343
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const regex = /{(\w|-)*}/g;
|
|
236
|
-
const found = this.path.match(regex);
|
|
237
|
-
if (!found) {
|
|
238
|
-
return void 0;
|
|
344
|
+
const value = data[index];
|
|
345
|
+
if (value === void 0) {
|
|
346
|
+
return prev;
|
|
239
347
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Convert Swagger path to URLPath(syntax of Express)
|
|
250
|
-
* @example /pet/{petId} => /pet/:petId
|
|
251
|
-
*/
|
|
252
|
-
toURLPath() {
|
|
253
|
-
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
// src/config.ts
|
|
258
|
-
function defineConfig(options) {
|
|
259
|
-
return options;
|
|
260
|
-
}
|
|
261
|
-
function isInputPath(result) {
|
|
262
|
-
return !!result && "path" in result;
|
|
348
|
+
return prev.replace(curr, () => {
|
|
349
|
+
if (typeof value === "boolean") {
|
|
350
|
+
return `${value.toString()}` || "false";
|
|
351
|
+
}
|
|
352
|
+
return value || "";
|
|
353
|
+
}).trim();
|
|
354
|
+
}, template) || "";
|
|
263
355
|
}
|
|
264
356
|
|
|
357
|
+
// src/utils/SummaryError.ts
|
|
358
|
+
var SummaryError = class extends Error {
|
|
359
|
+
summary;
|
|
360
|
+
constructor(message, options) {
|
|
361
|
+
super(message, { cause: options.cause });
|
|
362
|
+
this.name = "SummaryError";
|
|
363
|
+
this.summary = options.summary || [];
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
// src/utils/throttle.ts
|
|
368
|
+
var throttle = (fn, delay) => {
|
|
369
|
+
let wait = false;
|
|
370
|
+
let timeout2;
|
|
371
|
+
let cancelled = false;
|
|
372
|
+
return [
|
|
373
|
+
(...args) => {
|
|
374
|
+
if (cancelled) {
|
|
375
|
+
return void 0;
|
|
376
|
+
}
|
|
377
|
+
if (wait) {
|
|
378
|
+
return void 0;
|
|
379
|
+
}
|
|
380
|
+
const val = fn(...args);
|
|
381
|
+
wait = true;
|
|
382
|
+
timeout2 = setTimeout(() => {
|
|
383
|
+
wait = false;
|
|
384
|
+
}, delay);
|
|
385
|
+
return val;
|
|
386
|
+
},
|
|
387
|
+
() => {
|
|
388
|
+
cancelled = true;
|
|
389
|
+
clearTimeout(timeout2);
|
|
390
|
+
}
|
|
391
|
+
];
|
|
392
|
+
};
|
|
393
|
+
|
|
265
394
|
// src/utils/timeout.ts
|
|
266
395
|
async function timeout(ms) {
|
|
267
|
-
return new Promise((
|
|
396
|
+
return new Promise((resolve) => {
|
|
268
397
|
setTimeout(() => {
|
|
269
|
-
|
|
398
|
+
resolve(true);
|
|
270
399
|
}, ms);
|
|
271
400
|
});
|
|
272
401
|
}
|
|
@@ -276,17 +405,6 @@ function combineCodes(codes) {
|
|
|
276
405
|
return codes.join("\n");
|
|
277
406
|
}
|
|
278
407
|
|
|
279
|
-
// src/utils/transformers/createJSDocBlockText.ts
|
|
280
|
-
function createJSDocBlockText({ comments }) {
|
|
281
|
-
const filteredComments = comments.filter(Boolean);
|
|
282
|
-
if (!filteredComments.length) {
|
|
283
|
-
return "";
|
|
284
|
-
}
|
|
285
|
-
return `/**
|
|
286
|
-
* ${filteredComments.join("\n * ")}
|
|
287
|
-
*/`;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
408
|
// src/utils/transformers/escape.ts
|
|
291
409
|
function escape(text) {
|
|
292
410
|
return text ? text.replaceAll("`", "\\`") : "";
|
|
@@ -312,39 +430,6 @@ function jsStringEscape(input) {
|
|
|
312
430
|
});
|
|
313
431
|
}
|
|
314
432
|
|
|
315
|
-
// src/utils/transformers/indent.ts
|
|
316
|
-
function createIndent(size) {
|
|
317
|
-
return Array.from({ length: size + 1 }).join(" ");
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// src/utils/transformers/nameSorter.ts
|
|
321
|
-
function nameSorter(a, b) {
|
|
322
|
-
if (a.name < b.name) {
|
|
323
|
-
return -1;
|
|
324
|
-
}
|
|
325
|
-
if (a.name > b.name) {
|
|
326
|
-
return 1;
|
|
327
|
-
}
|
|
328
|
-
return 0;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// src/utils/transformers/searchAndReplace.ts
|
|
332
|
-
function searchAndReplace(options) {
|
|
333
|
-
const { text, replaceBy, prefix = "", key } = options;
|
|
334
|
-
const searchValues = options.searchValues?.(prefix, key) || [
|
|
335
|
-
`${prefix}["${key}"]`,
|
|
336
|
-
`${prefix}['${key}']`,
|
|
337
|
-
`${prefix}[\`${key}\`]`,
|
|
338
|
-
`${prefix}"${key}"`,
|
|
339
|
-
`${prefix}'${key}'`,
|
|
340
|
-
`${prefix}\`${key}\``,
|
|
341
|
-
new RegExp(`${prefix}${key}`, "g")
|
|
342
|
-
];
|
|
343
|
-
return searchValues.reduce((prev, searchValue) => {
|
|
344
|
-
return prev.toString().replaceAll(searchValue, replaceBy);
|
|
345
|
-
}, text);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
433
|
// src/utils/transformers/transformReservedWord.ts
|
|
349
434
|
var reservedWords = [
|
|
350
435
|
"abstract",
|
|
@@ -437,80 +522,6 @@ function transformReservedWord(word) {
|
|
|
437
522
|
}
|
|
438
523
|
return word;
|
|
439
524
|
}
|
|
440
|
-
|
|
441
|
-
// src/utils/transformers/index.ts
|
|
442
|
-
var transformers = {
|
|
443
|
-
combineCodes,
|
|
444
|
-
escape,
|
|
445
|
-
jsStringEscape,
|
|
446
|
-
createIndent,
|
|
447
|
-
transformReservedWord,
|
|
448
|
-
nameSorter,
|
|
449
|
-
searchAndReplace,
|
|
450
|
-
JSDoc: {
|
|
451
|
-
createJSDocBlockText
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
async function saveCreateDirectory(path5) {
|
|
455
|
-
const passedPath = path4.dirname(path4.resolve(path5));
|
|
456
|
-
await fs2__default.default.mkdir(passedPath, { recursive: true });
|
|
457
|
-
}
|
|
458
|
-
var writer = jsRuntime.switcher(
|
|
459
|
-
{
|
|
460
|
-
node: async (path5, data) => {
|
|
461
|
-
try {
|
|
462
|
-
await fs2__default.default.stat(path4.resolve(path5));
|
|
463
|
-
const oldContent = await fs2__default.default.readFile(path4.resolve(path5), { encoding: "utf-8" });
|
|
464
|
-
if (oldContent?.toString() === data?.toString()) {
|
|
465
|
-
return;
|
|
466
|
-
}
|
|
467
|
-
} catch (_err) {
|
|
468
|
-
}
|
|
469
|
-
await saveCreateDirectory(path5);
|
|
470
|
-
await fs2__default.default.writeFile(path4.resolve(path5), data, { encoding: "utf-8" });
|
|
471
|
-
const savedData = await fs2__default.default.readFile(path4.resolve(path5), { encoding: "utf-8" });
|
|
472
|
-
if (savedData?.toString() !== data?.toString()) {
|
|
473
|
-
throw new Error(`Sanity check failed for ${path5}
|
|
474
|
-
|
|
475
|
-
Data[${data.length}]:
|
|
476
|
-
${data}
|
|
477
|
-
|
|
478
|
-
Saved[${savedData.length}]:
|
|
479
|
-
${savedData}
|
|
480
|
-
`);
|
|
481
|
-
}
|
|
482
|
-
return savedData;
|
|
483
|
-
},
|
|
484
|
-
bun: async (path5, data) => {
|
|
485
|
-
try {
|
|
486
|
-
await saveCreateDirectory(path5);
|
|
487
|
-
await Bun.write(path4.resolve(path5), data);
|
|
488
|
-
const file = Bun.file(path4.resolve(path5));
|
|
489
|
-
const savedData = await file.text();
|
|
490
|
-
if (savedData?.toString() !== data?.toString()) {
|
|
491
|
-
throw new Error(`Sanity check failed for ${path5}
|
|
492
|
-
|
|
493
|
-
Data[${data.length}]:
|
|
494
|
-
${data}
|
|
495
|
-
|
|
496
|
-
Saved[${savedData.length}]:
|
|
497
|
-
${savedData}
|
|
498
|
-
`);
|
|
499
|
-
}
|
|
500
|
-
return savedData;
|
|
501
|
-
} catch (e) {
|
|
502
|
-
console.log(e, path4.resolve(path5));
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
},
|
|
506
|
-
"node"
|
|
507
|
-
);
|
|
508
|
-
async function write(data, path5) {
|
|
509
|
-
if (data.trim() === "") {
|
|
510
|
-
return void 0;
|
|
511
|
-
}
|
|
512
|
-
return writer(path5, data.trim());
|
|
513
|
-
}
|
|
514
525
|
var TreeNode = class _TreeNode {
|
|
515
526
|
data;
|
|
516
527
|
parent;
|
|
@@ -575,16 +586,16 @@ var TreeNode = class _TreeNode {
|
|
|
575
586
|
}
|
|
576
587
|
return this;
|
|
577
588
|
}
|
|
578
|
-
static build(
|
|
589
|
+
static build(path3, options = {}) {
|
|
579
590
|
try {
|
|
580
591
|
const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
|
|
581
|
-
const filteredTree = dirTree__default.default(
|
|
592
|
+
const filteredTree = dirTree__default.default(path3, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
|
|
582
593
|
if (!filteredTree) {
|
|
583
594
|
return null;
|
|
584
595
|
}
|
|
585
|
-
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type ||
|
|
596
|
+
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || getPathMode(filteredTree.path) });
|
|
586
597
|
const recurse = (node, item) => {
|
|
587
|
-
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type ||
|
|
598
|
+
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || getPathMode(item.path) });
|
|
588
599
|
if (item.children?.length) {
|
|
589
600
|
item.children?.forEach((child) => {
|
|
590
601
|
recurse(subNode, child);
|
|
@@ -599,271 +610,227 @@ var TreeNode = class _TreeNode {
|
|
|
599
610
|
}
|
|
600
611
|
};
|
|
601
612
|
|
|
602
|
-
// src/
|
|
603
|
-
var
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
613
|
+
// src/utils/uniqueIdFactory.ts
|
|
614
|
+
var uniqueIdFactory = (counter) => (str = "") => `${str}${++counter}`;
|
|
615
|
+
var URLPath = class {
|
|
616
|
+
path;
|
|
617
|
+
constructor(path3) {
|
|
618
|
+
this.path = path3;
|
|
607
619
|
return this;
|
|
608
620
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
621
|
+
/**
|
|
622
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
623
|
+
* @example /pet/{petId} => /pet/:petId
|
|
624
|
+
*/
|
|
625
|
+
get URL() {
|
|
626
|
+
return this.toURLPath();
|
|
627
|
+
}
|
|
628
|
+
get isURL() {
|
|
629
|
+
try {
|
|
630
|
+
const url = new URL(this.path);
|
|
631
|
+
if (url?.href) {
|
|
632
|
+
return true;
|
|
619
633
|
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
if (!tree) {
|
|
623
|
-
return null;
|
|
634
|
+
} catch (error) {
|
|
635
|
+
return false;
|
|
624
636
|
}
|
|
625
|
-
|
|
626
|
-
if (!currentTree.children) {
|
|
627
|
-
return [];
|
|
628
|
-
}
|
|
629
|
-
if (currentTree.children?.length > 1) {
|
|
630
|
-
const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
|
|
631
|
-
const exports = currentTree.children.filter(Boolean).map((file) => {
|
|
632
|
-
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
633
|
-
if (importPath.includes("index") && indexPath.includes("index")) {
|
|
634
|
-
return void 0;
|
|
635
|
-
}
|
|
636
|
-
return {
|
|
637
|
-
path: includeExt ? file.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
|
|
638
|
-
isTypeOnly
|
|
639
|
-
};
|
|
640
|
-
}).filter(Boolean);
|
|
641
|
-
files2.push({
|
|
642
|
-
path: indexPath,
|
|
643
|
-
baseName: "index.ts",
|
|
644
|
-
source: "",
|
|
645
|
-
exports: output ? exports?.filter((item) => {
|
|
646
|
-
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
647
|
-
}) : exports
|
|
648
|
-
});
|
|
649
|
-
} else {
|
|
650
|
-
currentTree.children?.forEach((child) => {
|
|
651
|
-
const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
|
|
652
|
-
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
653
|
-
const exports = [
|
|
654
|
-
{
|
|
655
|
-
path: includeExt ? child.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
|
|
656
|
-
isTypeOnly
|
|
657
|
-
}
|
|
658
|
-
];
|
|
659
|
-
files2.push({
|
|
660
|
-
path: indexPath,
|
|
661
|
-
baseName: "index.ts",
|
|
662
|
-
source: "",
|
|
663
|
-
exports: output ? exports?.filter((item) => {
|
|
664
|
-
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
665
|
-
}) : exports
|
|
666
|
-
});
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
currentTree.children.forEach((childItem) => {
|
|
670
|
-
fileReducer(files2, childItem);
|
|
671
|
-
});
|
|
672
|
-
return files2;
|
|
673
|
-
};
|
|
674
|
-
const files = fileReducer([], tree).reverse();
|
|
675
|
-
const filteredFiles = filter ? files.filter(filter) : files;
|
|
676
|
-
return map ? filteredFiles.map(map) : filteredFiles;
|
|
637
|
+
return false;
|
|
677
638
|
}
|
|
678
|
-
};
|
|
679
|
-
|
|
680
|
-
// src/FileManager.ts
|
|
681
|
-
var FileManager = class _FileManager {
|
|
682
|
-
#cache = /* @__PURE__ */ new Map();
|
|
683
|
-
#task;
|
|
684
|
-
#isWriting = false;
|
|
685
639
|
/**
|
|
686
|
-
*
|
|
640
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
641
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
642
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
643
|
+
* @example /account/userID => `/account/${userId}`
|
|
687
644
|
*/
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
constructor(options) {
|
|
691
|
-
if (options) {
|
|
692
|
-
this.#task = options.task;
|
|
693
|
-
this.#queue = options.queue;
|
|
694
|
-
this.#timeout = options.timeout || 0;
|
|
695
|
-
}
|
|
696
|
-
return this;
|
|
697
|
-
}
|
|
698
|
-
get files() {
|
|
699
|
-
const files = [];
|
|
700
|
-
this.#cache.forEach((item) => {
|
|
701
|
-
files.push(...item.flat(1));
|
|
702
|
-
});
|
|
703
|
-
return files;
|
|
645
|
+
get template() {
|
|
646
|
+
return this.toTemplateString();
|
|
704
647
|
}
|
|
705
|
-
get
|
|
706
|
-
return this
|
|
648
|
+
get object() {
|
|
649
|
+
return this.toObject();
|
|
707
650
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
return;
|
|
711
|
-
}
|
|
712
|
-
if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
|
|
713
|
-
throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
|
|
714
|
-
}
|
|
651
|
+
get params() {
|
|
652
|
+
return this.getParams();
|
|
715
653
|
}
|
|
716
|
-
|
|
717
|
-
const
|
|
718
|
-
this
|
|
719
|
-
|
|
720
|
-
|
|
654
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
655
|
+
const object = {
|
|
656
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
|
|
657
|
+
params: this.getParams()
|
|
658
|
+
};
|
|
659
|
+
if (stringify) {
|
|
660
|
+
if (type !== "template") {
|
|
661
|
+
throw new Error("Type should be `template` when using stringiyf");
|
|
721
662
|
}
|
|
722
|
-
return
|
|
723
|
-
});
|
|
724
|
-
const resolvedFiles = await Promise.all(promises);
|
|
725
|
-
if (files.length > 1) {
|
|
726
|
-
return resolvedFiles;
|
|
727
|
-
}
|
|
728
|
-
return resolvedFiles[0];
|
|
729
|
-
}
|
|
730
|
-
async #add(file) {
|
|
731
|
-
const controller = new AbortController();
|
|
732
|
-
const resolvedFile = { id: crypto2__default.default.randomUUID(), ...file };
|
|
733
|
-
this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
734
|
-
if (this.#queue) {
|
|
735
|
-
await this.#queue.run(
|
|
736
|
-
async () => {
|
|
737
|
-
return this.#task?.(resolvedFile);
|
|
738
|
-
},
|
|
739
|
-
{ controller }
|
|
740
|
-
);
|
|
663
|
+
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
741
664
|
}
|
|
742
|
-
return
|
|
665
|
+
return object;
|
|
743
666
|
}
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
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);
|
|
757
683
|
}
|
|
758
|
-
return
|
|
684
|
+
return `\`${newPath}\``;
|
|
759
685
|
}
|
|
760
|
-
|
|
761
|
-
const
|
|
762
|
-
const
|
|
763
|
-
if (!
|
|
686
|
+
getParams(replacer) {
|
|
687
|
+
const regex = /{(\w|-)*}/g;
|
|
688
|
+
const found = this.path.match(regex);
|
|
689
|
+
if (!found) {
|
|
764
690
|
return void 0;
|
|
765
691
|
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
);
|
|
692
|
+
const params = {};
|
|
693
|
+
found.forEach((item) => {
|
|
694
|
+
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
695
|
+
const pathParam = replacer ? replacer(changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
696
|
+
params[pathParam] = pathParam;
|
|
697
|
+
}, this.path);
|
|
698
|
+
return params;
|
|
774
699
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
return
|
|
700
|
+
/**
|
|
701
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
702
|
+
* @example /pet/{petId} => /pet/:petId
|
|
703
|
+
*/
|
|
704
|
+
toURLPath() {
|
|
705
|
+
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
781
706
|
}
|
|
782
|
-
|
|
783
|
-
|
|
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";
|
|
784
714
|
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
715
|
+
};
|
|
716
|
+
async function saveCreateDirectory(path3) {
|
|
717
|
+
const passedPath = path2__default.default.dirname(path2__default.default.resolve(path3));
|
|
718
|
+
await fs2__default.default.mkdir(passedPath, { recursive: true });
|
|
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
|
+
}
|
|
789
741
|
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
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: []
|
|
798
757
|
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
return read(...params);
|
|
758
|
+
};
|
|
759
|
+
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...options });
|
|
760
|
+
if (!tree) {
|
|
761
|
+
return null;
|
|
804
762
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
return file.source;
|
|
763
|
+
const fileReducer = (files2, currentTree) => {
|
|
764
|
+
if (!currentTree.children) {
|
|
765
|
+
return [];
|
|
809
766
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
767
|
+
if (currentTree.children?.length > 1) {
|
|
768
|
+
const path3 = path2__default.default.resolve(currentTree.data.path, "index.ts");
|
|
769
|
+
const exports = currentTree.children.map((file) => {
|
|
770
|
+
if (!file) {
|
|
771
|
+
return void 0;
|
|
772
|
+
}
|
|
773
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
774
|
+
if (importPath.includes("index") && path3.includes("index")) {
|
|
775
|
+
return void 0;
|
|
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
|
+
});
|
|
796
|
+
}
|
|
797
|
+
currentTree.children.forEach((childItem) => {
|
|
798
|
+
fileReducer(files2, childItem);
|
|
799
|
+
});
|
|
800
|
+
return files2;
|
|
801
|
+
};
|
|
802
|
+
const files = fileReducer([], tree);
|
|
803
|
+
return files;
|
|
804
|
+
}
|
|
805
|
+
function combineFiles(files) {
|
|
806
|
+
return files.filter(Boolean).reduce((acc, curr) => {
|
|
807
|
+
const prevIndex = acc.findIndex((item) => item.path === curr.path);
|
|
808
|
+
if (prevIndex !== -1) {
|
|
824
809
|
const prev = acc[prevIndex];
|
|
825
|
-
if (prev && file.override) {
|
|
826
|
-
acc[prevIndex] = {
|
|
827
|
-
imports: [],
|
|
828
|
-
exports: [],
|
|
829
|
-
...file
|
|
830
|
-
};
|
|
831
|
-
return acc;
|
|
832
|
-
}
|
|
833
810
|
if (prev) {
|
|
834
811
|
acc[prevIndex] = {
|
|
835
|
-
...
|
|
836
|
-
source: prev.source &&
|
|
837
|
-
${
|
|
838
|
-
imports: [...prev.imports || [], ...
|
|
839
|
-
exports: [...prev.exports || [], ...
|
|
840
|
-
env: { ...prev.env || {}, ...
|
|
812
|
+
...curr,
|
|
813
|
+
source: prev.source && curr.source ? `${prev.source}
|
|
814
|
+
${curr.source}` : "",
|
|
815
|
+
imports: [...prev.imports || [], ...curr.imports || []],
|
|
816
|
+
exports: [...prev.exports || [], ...curr.exports || []],
|
|
817
|
+
env: { ...prev.env || {}, ...curr.env || {} }
|
|
841
818
|
};
|
|
842
819
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
}
|
|
846
|
-
static getMode(path5) {
|
|
847
|
-
if (!path5) {
|
|
848
|
-
return "directory";
|
|
820
|
+
} else {
|
|
821
|
+
acc.push(curr);
|
|
849
822
|
}
|
|
850
|
-
return
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
}
|
|
858
|
-
};
|
|
823
|
+
return acc;
|
|
824
|
+
}, []);
|
|
825
|
+
}
|
|
826
|
+
var extensions = [".js", ".ts", ".tsx"];
|
|
827
|
+
function isExtensionAllowed(baseName) {
|
|
828
|
+
return extensions.some((extension) => baseName.endsWith(extension));
|
|
829
|
+
}
|
|
859
830
|
function combineExports(exports) {
|
|
860
|
-
|
|
831
|
+
return exports.reduce((prev, curr) => {
|
|
861
832
|
const name = curr.name;
|
|
862
833
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
863
|
-
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
|
|
864
|
-
if (prevByPathAndIsTypeOnly) {
|
|
865
|
-
return prev;
|
|
866
|
-
}
|
|
867
834
|
const uniquePrev = prev.findLast(
|
|
868
835
|
(imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
869
836
|
);
|
|
@@ -885,16 +852,12 @@ function combineExports(exports) {
|
|
|
885
852
|
}
|
|
886
853
|
return [...prev, curr];
|
|
887
854
|
}, []);
|
|
888
|
-
return naturalOrderby.orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
889
855
|
}
|
|
890
856
|
function combineImports(imports, exports, source) {
|
|
891
|
-
|
|
857
|
+
return imports.reduce((prev, curr) => {
|
|
892
858
|
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
893
859
|
const hasImportInSource = (importName) => {
|
|
894
|
-
|
|
895
|
-
return true;
|
|
896
|
-
}
|
|
897
|
-
const checker = (name2) => name2 && !!source.includes(name2);
|
|
860
|
+
const checker = (name2) => name2 && !!source.includes(`${name2}`);
|
|
898
861
|
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
899
862
|
};
|
|
900
863
|
if (Array.isArray(name)) {
|
|
@@ -902,10 +865,6 @@ function combineImports(imports, exports, source) {
|
|
|
902
865
|
}
|
|
903
866
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
904
867
|
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
905
|
-
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
|
|
906
|
-
if (prevByPathNameAndIsTypeOnly) {
|
|
907
|
-
return prev;
|
|
908
|
-
}
|
|
909
868
|
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
910
869
|
return prev;
|
|
911
870
|
}
|
|
@@ -927,7 +886,43 @@ function combineImports(imports, exports, source) {
|
|
|
927
886
|
}
|
|
928
887
|
return [...prev, curr];
|
|
929
888
|
}, []);
|
|
930
|
-
|
|
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);
|
|
931
926
|
}
|
|
932
927
|
function getEnvSource(source, env) {
|
|
933
928
|
if (!env) {
|
|
@@ -944,117 +939,127 @@ function getEnvSource(source, env) {
|
|
|
944
939
|
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
945
940
|
}
|
|
946
941
|
if (typeof replaceBy === "string") {
|
|
947
|
-
prev =
|
|
948
|
-
prev =
|
|
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).*
|
|
949
944
|
`, "ig"), ""), replaceBy, key });
|
|
950
945
|
}
|
|
951
946
|
return prev;
|
|
952
947
|
}, source);
|
|
953
948
|
}
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
#
|
|
959
|
-
|
|
960
|
-
|
|
949
|
+
|
|
950
|
+
// src/managers/fileManager/FileManager.ts
|
|
951
|
+
var FileManager = class {
|
|
952
|
+
#cache = /* @__PURE__ */ new Map();
|
|
953
|
+
#task;
|
|
954
|
+
#queue;
|
|
955
|
+
constructor(options) {
|
|
956
|
+
if (options) {
|
|
957
|
+
this.#task = options.task;
|
|
958
|
+
this.#queue = options.queue;
|
|
959
|
+
}
|
|
960
|
+
return this;
|
|
961
961
|
}
|
|
962
|
-
|
|
963
|
-
|
|
962
|
+
get extensions() {
|
|
963
|
+
return extensions;
|
|
964
964
|
}
|
|
965
|
-
|
|
966
|
-
|
|
965
|
+
get files() {
|
|
966
|
+
const files = [];
|
|
967
|
+
this.#cache.forEach((item) => {
|
|
968
|
+
files.push(...item.flat(1));
|
|
969
|
+
});
|
|
970
|
+
return files;
|
|
967
971
|
}
|
|
968
|
-
|
|
969
|
-
this.#
|
|
972
|
+
get isExecuting() {
|
|
973
|
+
return this.#queue?.hasJobs ?? false;
|
|
970
974
|
}
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
975
|
+
async add(file) {
|
|
976
|
+
const controller = new AbortController();
|
|
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;
|
|
981
992
|
}
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
993
|
+
async addOrAppend(file) {
|
|
994
|
+
const previousCaches = this.#cache.get(file.path);
|
|
995
|
+
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
996
|
+
if (previousCache) {
|
|
997
|
+
this.#cache.delete(previousCache.path);
|
|
998
|
+
return this.add({
|
|
999
|
+
...file,
|
|
1000
|
+
source: previousCache.source && file.source ? `${previousCache.source}
|
|
1001
|
+
${file.source}` : "",
|
|
1002
|
+
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
1003
|
+
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
1004
|
+
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
988
1005
|
});
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
});
|
|
1006
|
+
}
|
|
1007
|
+
return this.add(file);
|
|
992
1008
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1009
|
+
async addIndexes(root, extName = ".ts", options = {}) {
|
|
1010
|
+
const files = await getIndexes(root, extName, options);
|
|
1011
|
+
if (!files) {
|
|
1012
|
+
return void 0;
|
|
1013
|
+
}
|
|
1014
|
+
return Promise.all(
|
|
1015
|
+
files.map((file) => {
|
|
1016
|
+
if (file.override) {
|
|
1017
|
+
return this.add(file);
|
|
1018
|
+
}
|
|
1019
|
+
return this.addOrAppend(file);
|
|
1020
|
+
})
|
|
1021
|
+
);
|
|
1002
1022
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1023
|
+
#append(path3, file) {
|
|
1024
|
+
const previousFiles = this.#cache.get(path3) || [];
|
|
1025
|
+
this.#cache.set(path3, [...previousFiles, file]);
|
|
1005
1026
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1027
|
+
getCacheByUUID(UUID) {
|
|
1028
|
+
let cache;
|
|
1029
|
+
this.#cache.forEach((files) => {
|
|
1030
|
+
cache = files.find((item) => item.id === UUID);
|
|
1031
|
+
});
|
|
1032
|
+
return cache;
|
|
1008
1033
|
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1034
|
+
get(path3) {
|
|
1035
|
+
return this.#cache.get(path3);
|
|
1036
|
+
}
|
|
1037
|
+
remove(path3) {
|
|
1038
|
+
const cacheItem = this.get(path3);
|
|
1039
|
+
if (!cacheItem) {
|
|
1011
1040
|
return;
|
|
1012
1041
|
}
|
|
1013
|
-
this.#
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
}
|
|
1020
|
-
job().then((result) => {
|
|
1021
|
-
this.eventEmitter.emit("jobDone", result);
|
|
1022
|
-
resolve2(result);
|
|
1023
|
-
if (this.#debug) {
|
|
1024
|
-
perf_hooks.performance.mark(name + "_stop");
|
|
1025
|
-
perf_hooks.performance.measure(description, name + "_start", name + "_stop");
|
|
1026
|
-
}
|
|
1027
|
-
}).catch((err) => {
|
|
1028
|
-
this.eventEmitter.emit("jobFailed", err);
|
|
1029
|
-
reject(err);
|
|
1042
|
+
this.#cache.delete(path3);
|
|
1043
|
+
}
|
|
1044
|
+
async write(...params) {
|
|
1045
|
+
if (this.#queue) {
|
|
1046
|
+
return this.#queue.run(async () => {
|
|
1047
|
+
return write(...params);
|
|
1030
1048
|
});
|
|
1031
1049
|
}
|
|
1032
|
-
|
|
1033
|
-
}
|
|
1034
|
-
};
|
|
1035
|
-
|
|
1036
|
-
// src/utils/uniqueName.ts
|
|
1037
|
-
function setUniqueName(originalName, data) {
|
|
1038
|
-
let used = data[originalName] || 0;
|
|
1039
|
-
if (used) {
|
|
1040
|
-
data[originalName] = ++used;
|
|
1041
|
-
return originalName;
|
|
1050
|
+
return write(...params);
|
|
1042
1051
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
cause;
|
|
1051
|
-
constructor(message, options) {
|
|
1052
|
-
super(message, { cause: options.cause });
|
|
1053
|
-
this.name = "PluginError";
|
|
1054
|
-
this.cause = options.cause;
|
|
1055
|
-
this.pluginManager = options.pluginManager;
|
|
1052
|
+
async read(...params) {
|
|
1053
|
+
if (this.#queue) {
|
|
1054
|
+
return this.#queue.run(async () => {
|
|
1055
|
+
return read(...params);
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
return read(...params);
|
|
1056
1059
|
}
|
|
1057
1060
|
};
|
|
1061
|
+
|
|
1062
|
+
// src/managers/pluginManager/ParallelPluginError.ts
|
|
1058
1063
|
var ParallelPluginError = class extends Error {
|
|
1059
1064
|
errors = [];
|
|
1060
1065
|
pluginManager;
|
|
@@ -1079,55 +1084,30 @@ var ParallelPluginError = class extends Error {
|
|
|
1079
1084
|
})?.cause;
|
|
1080
1085
|
}
|
|
1081
1086
|
};
|
|
1082
|
-
|
|
1083
|
-
|
|
1087
|
+
|
|
1088
|
+
// src/managers/pluginManager/PluginError.ts
|
|
1089
|
+
var PluginError = class extends Error {
|
|
1090
|
+
pluginManager;
|
|
1091
|
+
cause;
|
|
1084
1092
|
constructor(message, options) {
|
|
1085
1093
|
super(message, { cause: options.cause });
|
|
1086
|
-
this.name = "
|
|
1087
|
-
this.
|
|
1088
|
-
|
|
1089
|
-
};
|
|
1090
|
-
var Warning = class extends Error {
|
|
1091
|
-
constructor(message, options) {
|
|
1092
|
-
super(message, { cause: options?.cause });
|
|
1093
|
-
this.name = "Warning";
|
|
1094
|
+
this.name = "PluginError";
|
|
1095
|
+
this.cause = options.cause;
|
|
1096
|
+
this.pluginManager = options.pluginManager;
|
|
1094
1097
|
}
|
|
1095
1098
|
};
|
|
1096
|
-
|
|
1097
|
-
};
|
|
1098
|
-
|
|
1099
|
-
// src/utils/cache.ts
|
|
1100
|
-
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
1101
|
-
return {
|
|
1102
|
-
set(id, value) {
|
|
1103
|
-
Store[id] = [0, value];
|
|
1104
|
-
},
|
|
1105
|
-
get(id) {
|
|
1106
|
-
const item = Store[id];
|
|
1107
|
-
if (!item) {
|
|
1108
|
-
return null;
|
|
1109
|
-
}
|
|
1110
|
-
item[0] = 0;
|
|
1111
|
-
return item[1];
|
|
1112
|
-
},
|
|
1113
|
-
has(id) {
|
|
1114
|
-
const item = Store[id];
|
|
1115
|
-
if (!item) {
|
|
1116
|
-
return false;
|
|
1117
|
-
}
|
|
1118
|
-
item[0] = 0;
|
|
1119
|
-
return true;
|
|
1120
|
-
},
|
|
1121
|
-
delete(id) {
|
|
1122
|
-
return delete Store[id];
|
|
1123
|
-
}
|
|
1124
|
-
};
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
// src/plugin.ts
|
|
1128
|
-
function createPlugin(factory2) {
|
|
1099
|
+
function createPlugin(factory) {
|
|
1129
1100
|
return (options) => {
|
|
1130
|
-
|
|
1101
|
+
const plugin = factory(options);
|
|
1102
|
+
if (Array.isArray(plugin)) {
|
|
1103
|
+
throw new Error("Not implemented");
|
|
1104
|
+
}
|
|
1105
|
+
if (!plugin.transform) {
|
|
1106
|
+
plugin.transform = function transform(code) {
|
|
1107
|
+
return code;
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
return plugin;
|
|
1131
1111
|
};
|
|
1132
1112
|
}
|
|
1133
1113
|
var pluginName = "core";
|
|
@@ -1136,8 +1116,6 @@ var definePlugin = createPlugin((options) => {
|
|
|
1136
1116
|
return {
|
|
1137
1117
|
name: pluginName,
|
|
1138
1118
|
options,
|
|
1139
|
-
key: ["controller", "core"],
|
|
1140
|
-
kind: "controller",
|
|
1141
1119
|
api() {
|
|
1142
1120
|
return {
|
|
1143
1121
|
get config() {
|
|
@@ -1146,18 +1124,18 @@ var definePlugin = createPlugin((options) => {
|
|
|
1146
1124
|
get plugins() {
|
|
1147
1125
|
return options.getPlugins();
|
|
1148
1126
|
},
|
|
1149
|
-
get plugin() {
|
|
1150
|
-
return options.plugin;
|
|
1151
|
-
},
|
|
1152
1127
|
logger,
|
|
1153
1128
|
fileManager,
|
|
1154
1129
|
pluginManager,
|
|
1155
1130
|
async addFile(...files) {
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1131
|
+
return Promise.all(
|
|
1132
|
+
files.map((file) => {
|
|
1133
|
+
if (file.override) {
|
|
1134
|
+
return fileManager.add(file);
|
|
1135
|
+
}
|
|
1136
|
+
return fileManager.addOrAppend(file);
|
|
1137
|
+
})
|
|
1138
|
+
);
|
|
1161
1139
|
},
|
|
1162
1140
|
resolvePath,
|
|
1163
1141
|
resolveName,
|
|
@@ -1165,58 +1143,63 @@ var definePlugin = createPlugin((options) => {
|
|
|
1165
1143
|
};
|
|
1166
1144
|
},
|
|
1167
1145
|
resolvePath(baseName) {
|
|
1168
|
-
const root =
|
|
1169
|
-
return
|
|
1146
|
+
const root = path2__default.default.resolve(this.config.root, this.config.output.path);
|
|
1147
|
+
return path2__default.default.resolve(root, baseName);
|
|
1170
1148
|
},
|
|
1171
1149
|
resolveName(name) {
|
|
1172
1150
|
return name;
|
|
1173
1151
|
}
|
|
1174
1152
|
};
|
|
1175
1153
|
});
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
return promises.reduce(
|
|
1180
|
-
(promise, func) => {
|
|
1181
|
-
if (!func || typeof func !== "function") {
|
|
1182
|
-
throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
1183
|
-
}
|
|
1184
|
-
return promise.then((result) => {
|
|
1185
|
-
const calledFunc = func();
|
|
1186
|
-
if (calledFunc) {
|
|
1187
|
-
return calledFunc.then(Array.prototype.concat.bind(result));
|
|
1188
|
-
}
|
|
1189
|
-
});
|
|
1190
|
-
},
|
|
1191
|
-
Promise.resolve([])
|
|
1192
|
-
);
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
// src/PromiseManager.ts
|
|
1196
|
-
var PromiseManager = class {
|
|
1197
|
-
#options = {};
|
|
1198
|
-
constructor(options = {}) {
|
|
1199
|
-
this.#options = options;
|
|
1200
|
-
return this;
|
|
1154
|
+
var EventEmitter = class {
|
|
1155
|
+
constructor() {
|
|
1156
|
+
this.#emitter.setMaxListeners(100);
|
|
1201
1157
|
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1158
|
+
#emitter = new events.EventEmitter();
|
|
1159
|
+
emit(eventName, ...eventArg) {
|
|
1160
|
+
this.#emitter.emit(eventName, ...eventArg);
|
|
1161
|
+
}
|
|
1162
|
+
on(eventName, handler) {
|
|
1163
|
+
this.#emitter.on(eventName, handler);
|
|
1164
|
+
}
|
|
1165
|
+
off(eventName, handler) {
|
|
1166
|
+
this.#emitter.off(eventName, handler);
|
|
1167
|
+
}
|
|
1168
|
+
removeAll() {
|
|
1169
|
+
this.#emitter.removeAllListeners();
|
|
1207
1170
|
}
|
|
1208
1171
|
};
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
}
|
|
1212
|
-
function
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1172
|
+
|
|
1173
|
+
// src/managers/pluginManager/pluginParser.ts
|
|
1174
|
+
var usedPluginNames = {};
|
|
1175
|
+
function pluginParser(plugin, context) {
|
|
1176
|
+
const key = [plugin.kind, plugin.name, getUniqueName(plugin.name, usedPluginNames).split(plugin.name).at(1)];
|
|
1177
|
+
if (plugin.api && typeof plugin.api === "function") {
|
|
1178
|
+
const api = plugin.api.call(context);
|
|
1179
|
+
return {
|
|
1180
|
+
...plugin,
|
|
1181
|
+
key,
|
|
1182
|
+
api
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
return {
|
|
1186
|
+
...plugin,
|
|
1187
|
+
key
|
|
1188
|
+
};
|
|
1217
1189
|
}
|
|
1218
1190
|
|
|
1219
|
-
// src/PluginManager.ts
|
|
1191
|
+
// src/managers/pluginManager/PluginManager.ts
|
|
1192
|
+
var hookNames = {
|
|
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);
|
|
1220
1203
|
var PluginManager = class {
|
|
1221
1204
|
plugins;
|
|
1222
1205
|
fileManager;
|
|
@@ -1225,14 +1208,10 @@ var PluginManager = class {
|
|
|
1225
1208
|
executed = [];
|
|
1226
1209
|
logger;
|
|
1227
1210
|
#core;
|
|
1228
|
-
#usedPluginNames = {};
|
|
1229
|
-
#promiseManager;
|
|
1230
1211
|
constructor(config, options) {
|
|
1231
1212
|
this.logger = options.logger;
|
|
1232
|
-
this.queue = new Queue(100,
|
|
1233
|
-
this.fileManager = new FileManager({ task: options.task, queue: this.queue
|
|
1234
|
-
this.#promiseManager = new PromiseManager();
|
|
1235
|
-
const plugins = config.plugins || [];
|
|
1213
|
+
this.queue = new Queue(100, options.debug);
|
|
1214
|
+
this.fileManager = new FileManager({ task: options.task, queue: this.queue });
|
|
1236
1215
|
const core = definePlugin({
|
|
1237
1216
|
config,
|
|
1238
1217
|
logger: this.logger,
|
|
@@ -1240,29 +1219,23 @@ var PluginManager = class {
|
|
|
1240
1219
|
fileManager: this.fileManager,
|
|
1241
1220
|
resolvePath: this.resolvePath.bind(this),
|
|
1242
1221
|
resolveName: this.resolveName.bind(this),
|
|
1243
|
-
getPlugins: this.#getSortedPlugins.bind(this)
|
|
1244
|
-
|
|
1245
|
-
this.#core = this.#parse(core, this, core.api.call(null));
|
|
1246
|
-
this.plugins = [this.#core, ...plugins].map((plugin) => {
|
|
1247
|
-
return this.#parse(plugin, this, this.#core.api);
|
|
1222
|
+
getPlugins: this.#getSortedPlugins.bind(this),
|
|
1223
|
+
plugin: void 0
|
|
1248
1224
|
});
|
|
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
|
+
}, []);
|
|
1249
1230
|
return this;
|
|
1250
1231
|
}
|
|
1251
1232
|
resolvePath = (params) => {
|
|
1252
|
-
if (params.
|
|
1253
|
-
|
|
1254
|
-
|
|
1233
|
+
if (params.pluginName) {
|
|
1234
|
+
return this.hookForPluginSync({
|
|
1235
|
+
pluginName: params.pluginName,
|
|
1255
1236
|
hookName: "resolvePath",
|
|
1256
1237
|
parameters: [params.baseName, params.directory, params.options]
|
|
1257
1238
|
});
|
|
1258
|
-
if (paths && paths?.length > 1) {
|
|
1259
|
-
throw new Error(
|
|
1260
|
-
`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1261
|
-
|
|
1262
|
-
Paths: ${JSON.stringify(paths, void 0, 2)}`
|
|
1263
|
-
);
|
|
1264
|
-
}
|
|
1265
|
-
return paths?.at(0);
|
|
1266
1239
|
}
|
|
1267
1240
|
return this.hookFirstSync({
|
|
1268
1241
|
hookName: "resolvePath",
|
|
@@ -1270,20 +1243,13 @@ Paths: ${JSON.stringify(paths, void 0, 2)}`
|
|
|
1270
1243
|
}).result;
|
|
1271
1244
|
};
|
|
1272
1245
|
resolveName = (params) => {
|
|
1273
|
-
if (params.
|
|
1274
|
-
const
|
|
1275
|
-
|
|
1246
|
+
if (params.pluginName) {
|
|
1247
|
+
const name2 = this.hookForPluginSync({
|
|
1248
|
+
pluginName: params.pluginName,
|
|
1276
1249
|
hookName: "resolveName",
|
|
1277
1250
|
parameters: [params.name, params.type]
|
|
1278
1251
|
});
|
|
1279
|
-
|
|
1280
|
-
throw new Error(
|
|
1281
|
-
`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1282
|
-
|
|
1283
|
-
Names: ${JSON.stringify(names, void 0, 2)}`
|
|
1284
|
-
);
|
|
1285
|
-
}
|
|
1286
|
-
return transformReservedWord(names?.at(0) || params.name);
|
|
1252
|
+
return transformReservedWord(name2 || params.name);
|
|
1287
1253
|
}
|
|
1288
1254
|
const name = this.hookFirstSync({
|
|
1289
1255
|
hookName: "resolveName",
|
|
@@ -1298,35 +1264,30 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1298
1264
|
* Run only hook for a specific plugin name
|
|
1299
1265
|
*/
|
|
1300
1266
|
hookForPlugin({
|
|
1301
|
-
|
|
1267
|
+
pluginName: pluginName2,
|
|
1302
1268
|
hookName,
|
|
1303
1269
|
parameters
|
|
1304
1270
|
}) {
|
|
1305
|
-
const
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
});
|
|
1313
|
-
}).filter(Boolean);
|
|
1314
|
-
return Promise.all(promises);
|
|
1271
|
+
const plugin = this.getPlugin(hookName, pluginName2);
|
|
1272
|
+
return this.#execute({
|
|
1273
|
+
strategy: "hookFirst",
|
|
1274
|
+
hookName,
|
|
1275
|
+
parameters,
|
|
1276
|
+
plugin
|
|
1277
|
+
});
|
|
1315
1278
|
}
|
|
1316
1279
|
hookForPluginSync({
|
|
1317
|
-
|
|
1280
|
+
pluginName: pluginName2,
|
|
1318
1281
|
hookName,
|
|
1319
1282
|
parameters
|
|
1320
1283
|
}) {
|
|
1321
|
-
const
|
|
1322
|
-
return
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
});
|
|
1329
|
-
}).filter(Boolean);
|
|
1284
|
+
const plugin = this.getPlugin(hookName, pluginName2);
|
|
1285
|
+
return this.#executeSync({
|
|
1286
|
+
strategy: "hookFirst",
|
|
1287
|
+
hookName,
|
|
1288
|
+
parameters,
|
|
1289
|
+
plugin
|
|
1290
|
+
});
|
|
1330
1291
|
}
|
|
1331
1292
|
/**
|
|
1332
1293
|
* Chains, first non-null result stops and returns
|
|
@@ -1442,58 +1403,37 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1442
1403
|
* Chains plugins
|
|
1443
1404
|
*/
|
|
1444
1405
|
hookSeq({ hookName, parameters }) {
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1406
|
+
let promise = Promise.resolve();
|
|
1407
|
+
for (const plugin of this.#getSortedPlugins()) {
|
|
1408
|
+
promise = promise.then(() => {
|
|
1409
|
+
this.#execute({
|
|
1410
|
+
strategy: "hookSeq",
|
|
1411
|
+
hookName,
|
|
1412
|
+
parameters,
|
|
1413
|
+
plugin
|
|
1414
|
+
});
|
|
1451
1415
|
});
|
|
1452
|
-
}
|
|
1453
|
-
return
|
|
1416
|
+
}
|
|
1417
|
+
return promise.then(noReturn);
|
|
1454
1418
|
}
|
|
1455
1419
|
#getSortedPlugins(hookName) {
|
|
1456
1420
|
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1457
1421
|
if (hookName) {
|
|
1458
|
-
if (this.logger.logLevel === "info") {
|
|
1459
|
-
const containsHookName = plugins.some((item) => item[hookName]);
|
|
1460
|
-
if (!containsHookName) {
|
|
1461
|
-
this.logger.warn(`No hook ${hookName} found`);
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
1422
|
return plugins.filter((item) => item[hookName]);
|
|
1465
1423
|
}
|
|
1466
1424
|
return plugins;
|
|
1467
1425
|
}
|
|
1468
|
-
|
|
1426
|
+
getPlugin(hookName, pluginName2) {
|
|
1469
1427
|
const plugins = [...this.plugins];
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
1474
|
-
const kindCheck = kind === searchKind;
|
|
1475
|
-
const nameCheck = name === searchPluginName;
|
|
1476
|
-
if (searchIdentifier) {
|
|
1477
|
-
return identifierCheck && kindCheck && nameCheck;
|
|
1478
|
-
}
|
|
1479
|
-
return kindCheck && nameCheck;
|
|
1480
|
-
});
|
|
1481
|
-
if (!pluginByPluginName?.length) {
|
|
1482
|
-
const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
|
|
1483
|
-
if (this.logger.logLevel === "info") {
|
|
1484
|
-
if (corePlugin) {
|
|
1485
|
-
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
|
|
1486
|
-
} else {
|
|
1487
|
-
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
return corePlugin ? [corePlugin] : [];
|
|
1428
|
+
const pluginByPluginName = plugins.find((item) => item.name === pluginName2 && item[hookName]);
|
|
1429
|
+
if (!pluginByPluginName) {
|
|
1430
|
+
return this.#core;
|
|
1491
1431
|
}
|
|
1492
1432
|
return pluginByPluginName;
|
|
1493
1433
|
}
|
|
1494
1434
|
#addExecutedToCallStack(executer) {
|
|
1495
1435
|
if (executer) {
|
|
1496
|
-
this.eventEmitter.emit("
|
|
1436
|
+
this.eventEmitter.emit("execute", executer);
|
|
1497
1437
|
this.executed.push(executer);
|
|
1498
1438
|
}
|
|
1499
1439
|
}
|
|
@@ -1563,7 +1503,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1563
1503
|
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1564
1504
|
try {
|
|
1565
1505
|
if (typeof hook === "function") {
|
|
1566
|
-
const fn = hook.apply(
|
|
1506
|
+
const fn = hook.apply(this.#core.api, parameters);
|
|
1567
1507
|
output = fn;
|
|
1568
1508
|
return fn;
|
|
1569
1509
|
}
|
|
@@ -1589,50 +1529,34 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1589
1529
|
this.eventEmitter.emit("error", pluginError);
|
|
1590
1530
|
throw pluginError;
|
|
1591
1531
|
}
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
pluginNames = [dependedPluginNames];
|
|
1621
|
-
} else {
|
|
1622
|
-
pluginNames = dependedPluginNames;
|
|
1623
|
-
}
|
|
1624
|
-
return pluginNames.map((pluginName2) => {
|
|
1625
|
-
const plugin = plugins.find((plugin2) => plugin2.name === pluginName2);
|
|
1626
|
-
if (!plugin) {
|
|
1627
|
-
throw new ValidationPluginError(`This plugin depends on the ${pluginName2} plugin.`);
|
|
1628
|
-
}
|
|
1629
|
-
return plugin;
|
|
1630
|
-
});
|
|
1631
|
-
}
|
|
1632
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
1633
|
-
static get hooks() {
|
|
1634
|
-
return ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
1635
|
-
}
|
|
1532
|
+
};
|
|
1533
|
+
function noReturn() {
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
// src/managers/pluginManager/validate.ts
|
|
1537
|
+
var ValidationPluginError = class extends Error {
|
|
1538
|
+
};
|
|
1539
|
+
function getDependedPlugins(plugins, dependedPluginNames) {
|
|
1540
|
+
let pluginNames = [];
|
|
1541
|
+
if (typeof dependedPluginNames === "string") {
|
|
1542
|
+
pluginNames = [dependedPluginNames];
|
|
1543
|
+
} else {
|
|
1544
|
+
pluginNames = dependedPluginNames;
|
|
1545
|
+
}
|
|
1546
|
+
return pluginNames.map((pluginName2) => {
|
|
1547
|
+
const plugin = plugins.find((plugin2) => plugin2.name === pluginName2);
|
|
1548
|
+
if (!plugin) {
|
|
1549
|
+
throw new ValidationPluginError(`This plugin depends on the ${pluginName2} plugin.`);
|
|
1550
|
+
}
|
|
1551
|
+
return plugin;
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
// src/types.ts
|
|
1556
|
+
var LogLevel = {
|
|
1557
|
+
silent: "silent",
|
|
1558
|
+
info: "info",
|
|
1559
|
+
debug: "debug"
|
|
1636
1560
|
};
|
|
1637
1561
|
|
|
1638
1562
|
// src/build.ts
|
|
@@ -1640,13 +1564,13 @@ async function transformReducer(_previousCode, result, _plugin) {
|
|
|
1640
1564
|
return result;
|
|
1641
1565
|
}
|
|
1642
1566
|
async function build(options) {
|
|
1643
|
-
const { config, logger = createLogger(
|
|
1567
|
+
const { config, logLevel, logger = createLogger() } = options;
|
|
1644
1568
|
try {
|
|
1645
|
-
if (
|
|
1569
|
+
if ("path" in config.input && !new URLPath(config.input.path).isURL) {
|
|
1646
1570
|
await read(config.input.path);
|
|
1647
1571
|
}
|
|
1648
1572
|
} catch (e) {
|
|
1649
|
-
if (
|
|
1573
|
+
if ("path" in config.input) {
|
|
1650
1574
|
throw new Error(
|
|
1651
1575
|
"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),
|
|
1652
1576
|
{
|
|
@@ -1659,11 +1583,11 @@ async function build(options) {
|
|
|
1659
1583
|
await clean(config.output.path);
|
|
1660
1584
|
}
|
|
1661
1585
|
const queueTask = async (file) => {
|
|
1662
|
-
const { path:
|
|
1663
|
-
let code =
|
|
1586
|
+
const { path: path3 } = file;
|
|
1587
|
+
let code = createFileSource(file);
|
|
1664
1588
|
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1665
1589
|
hookName: "load",
|
|
1666
|
-
parameters: [
|
|
1590
|
+
parameters: [path3]
|
|
1667
1591
|
});
|
|
1668
1592
|
if (loadedResult && isPromise(loadedResult)) {
|
|
1669
1593
|
code = await loadedResult;
|
|
@@ -1674,53 +1598,28 @@ async function build(options) {
|
|
|
1674
1598
|
if (code) {
|
|
1675
1599
|
const transformedCode = await pluginManager.hookReduceArg0({
|
|
1676
1600
|
hookName: "transform",
|
|
1677
|
-
parameters: [code,
|
|
1601
|
+
parameters: [code, path3],
|
|
1678
1602
|
reduce: transformReducer
|
|
1679
1603
|
});
|
|
1680
1604
|
if (config.output.write || config.output.write === void 0) {
|
|
1681
|
-
|
|
1682
|
-
return pluginManager.hookForPlugin({
|
|
1683
|
-
pluginKey: file.meta?.pluginKey,
|
|
1684
|
-
hookName: "writeFile",
|
|
1685
|
-
parameters: [transformedCode, path5]
|
|
1686
|
-
});
|
|
1687
|
-
}
|
|
1688
|
-
return pluginManager.hookFirst({
|
|
1605
|
+
await pluginManager.hookParallel({
|
|
1689
1606
|
hookName: "writeFile",
|
|
1690
|
-
parameters: [transformedCode,
|
|
1607
|
+
parameters: [transformedCode, path3]
|
|
1691
1608
|
});
|
|
1692
1609
|
}
|
|
1693
1610
|
}
|
|
1694
1611
|
};
|
|
1695
|
-
const pluginManager = new PluginManager(config, { logger, task: queueTask
|
|
1612
|
+
const pluginManager = new PluginManager(config, { debug: logLevel === LogLevel.debug, logger, task: queueTask });
|
|
1696
1613
|
const { plugins, fileManager } = pluginManager;
|
|
1697
1614
|
pluginManager.on("execute", (executer) => {
|
|
1698
|
-
const { hookName, parameters, plugin } = executer;
|
|
1699
|
-
if (hookName === "writeFile" && logger.spinner) {
|
|
1700
|
-
const [code] = parameters;
|
|
1701
|
-
if (logger.logLevel === LogLevel.info) {
|
|
1702
|
-
logger.spinner.start(`\u{1F4BE} Writing`);
|
|
1703
|
-
}
|
|
1704
|
-
if (logger.logLevel === "debug") {
|
|
1705
|
-
logger.info(`PluginKey ${pc3__default.default.dim(JSON.stringify(plugin.key))}
|
|
1706
|
-
with source
|
|
1707
|
-
|
|
1708
|
-
${code}`);
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
});
|
|
1712
|
-
pluginManager.on("executed", (executer) => {
|
|
1713
1615
|
const { hookName, plugin, output, parameters } = executer;
|
|
1714
1616
|
const messsage = `${randomPicoColour(plugin.name)} Executing ${hookName}`;
|
|
1715
|
-
if (
|
|
1716
|
-
if (
|
|
1717
|
-
const [_code, path5] = parameters;
|
|
1718
|
-
logger.spinner.suffixText = pc3__default.default.dim(path5);
|
|
1719
|
-
} else {
|
|
1617
|
+
if (logLevel === LogLevel.info) {
|
|
1618
|
+
if (logger.spinner) {
|
|
1720
1619
|
logger.spinner.suffixText = messsage;
|
|
1721
1620
|
}
|
|
1722
1621
|
}
|
|
1723
|
-
if (
|
|
1622
|
+
if (logLevel === LogLevel.debug) {
|
|
1724
1623
|
logger.info(messsage);
|
|
1725
1624
|
const logs = [
|
|
1726
1625
|
parameters && `${pc3__default.default.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
|
|
@@ -1740,14 +1639,15 @@ ${code}`);
|
|
|
1740
1639
|
parameters: [config]
|
|
1741
1640
|
});
|
|
1742
1641
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1642
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: createFileSource(file) })), pluginManager };
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
// src/config.ts
|
|
1646
|
+
function defineConfig(options) {
|
|
1647
|
+
return options;
|
|
1748
1648
|
}
|
|
1749
1649
|
|
|
1750
|
-
// src/Generator.ts
|
|
1650
|
+
// src/generators/Generator.ts
|
|
1751
1651
|
var Generator = class {
|
|
1752
1652
|
#options = {};
|
|
1753
1653
|
#context = {};
|
|
@@ -1771,6 +1671,10 @@ var Generator = class {
|
|
|
1771
1671
|
}
|
|
1772
1672
|
};
|
|
1773
1673
|
|
|
1674
|
+
// src/generators/SchemaGenerator.ts
|
|
1675
|
+
var SchemaGenerator = class extends Generator {
|
|
1676
|
+
};
|
|
1677
|
+
|
|
1774
1678
|
// ../../node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
|
|
1775
1679
|
var Node = class {
|
|
1776
1680
|
value;
|
|
@@ -1836,18 +1740,18 @@ function pLimit(concurrency) {
|
|
|
1836
1740
|
queue.dequeue()();
|
|
1837
1741
|
}
|
|
1838
1742
|
};
|
|
1839
|
-
const run = async (fn,
|
|
1743
|
+
const run = async (fn, resolve, args) => {
|
|
1840
1744
|
activeCount++;
|
|
1841
1745
|
const result = (async () => fn(...args))();
|
|
1842
|
-
|
|
1746
|
+
resolve(result);
|
|
1843
1747
|
try {
|
|
1844
1748
|
await result;
|
|
1845
1749
|
} catch {
|
|
1846
1750
|
}
|
|
1847
1751
|
next();
|
|
1848
1752
|
};
|
|
1849
|
-
const enqueue = (fn,
|
|
1850
|
-
queue.enqueue(run.bind(void 0, fn,
|
|
1753
|
+
const enqueue = (fn, resolve, args) => {
|
|
1754
|
+
queue.enqueue(run.bind(void 0, fn, resolve, args));
|
|
1851
1755
|
(async () => {
|
|
1852
1756
|
await Promise.resolve();
|
|
1853
1757
|
if (activeCount < concurrency && queue.size > 0) {
|
|
@@ -1855,8 +1759,8 @@ function pLimit(concurrency) {
|
|
|
1855
1759
|
}
|
|
1856
1760
|
})();
|
|
1857
1761
|
};
|
|
1858
|
-
const generator = (fn, ...args) => new Promise((
|
|
1859
|
-
enqueue(fn,
|
|
1762
|
+
const generator = (fn, ...args) => new Promise((resolve) => {
|
|
1763
|
+
enqueue(fn, resolve, args);
|
|
1860
1764
|
});
|
|
1861
1765
|
Object.defineProperties(generator, {
|
|
1862
1766
|
activeCount: {
|
|
@@ -1931,7 +1835,7 @@ async function locatePath(paths, {
|
|
|
1931
1835
|
const statFunction = allowSymlinks ? fs3.promises.stat : fs3.promises.lstat;
|
|
1932
1836
|
return pLocate(paths, async (path_) => {
|
|
1933
1837
|
try {
|
|
1934
|
-
const stat = await statFunction(
|
|
1838
|
+
const stat = await statFunction(path2__default.default.resolve(cwd, path_));
|
|
1935
1839
|
return matchType(type, stat);
|
|
1936
1840
|
} catch {
|
|
1937
1841
|
return false;
|
|
@@ -1948,7 +1852,7 @@ function locatePathSync(paths, {
|
|
|
1948
1852
|
const statFunction = allowSymlinks ? fs3__default.default.statSync : fs3__default.default.lstatSync;
|
|
1949
1853
|
for (const path_ of paths) {
|
|
1950
1854
|
try {
|
|
1951
|
-
const stat = statFunction(
|
|
1855
|
+
const stat = statFunction(path2__default.default.resolve(cwd, path_), {
|
|
1952
1856
|
throwIfNoEntry: false
|
|
1953
1857
|
});
|
|
1954
1858
|
if (!stat) {
|
|
@@ -1966,9 +1870,9 @@ function locatePathSync(paths, {
|
|
|
1966
1870
|
var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? url.fileURLToPath(urlOrPath) : urlOrPath;
|
|
1967
1871
|
var findUpStop = Symbol("findUpStop");
|
|
1968
1872
|
async function findUpMultiple(name, options = {}) {
|
|
1969
|
-
let directory =
|
|
1970
|
-
const { root } =
|
|
1971
|
-
const stopAt =
|
|
1873
|
+
let directory = path2__default.default.resolve(toPath2(options.cwd) || "");
|
|
1874
|
+
const { root } = path2__default.default.parse(directory);
|
|
1875
|
+
const stopAt = path2__default.default.resolve(directory, options.stopAt || root);
|
|
1972
1876
|
const limit = options.limit || Number.POSITIVE_INFINITY;
|
|
1973
1877
|
const paths = [name].flat();
|
|
1974
1878
|
const runMatcher = async (locateOptions) => {
|
|
@@ -1988,18 +1892,18 @@ async function findUpMultiple(name, options = {}) {
|
|
|
1988
1892
|
break;
|
|
1989
1893
|
}
|
|
1990
1894
|
if (foundPath) {
|
|
1991
|
-
matches.push(
|
|
1895
|
+
matches.push(path2__default.default.resolve(directory, foundPath));
|
|
1992
1896
|
}
|
|
1993
1897
|
if (directory === stopAt || matches.length >= limit) {
|
|
1994
1898
|
break;
|
|
1995
1899
|
}
|
|
1996
|
-
directory =
|
|
1900
|
+
directory = path2__default.default.dirname(directory);
|
|
1997
1901
|
}
|
|
1998
1902
|
return matches;
|
|
1999
1903
|
}
|
|
2000
1904
|
function findUpMultipleSync(name, options = {}) {
|
|
2001
|
-
let directory =
|
|
2002
|
-
const { root } =
|
|
1905
|
+
let directory = path2__default.default.resolve(toPath2(options.cwd) || "");
|
|
1906
|
+
const { root } = path2__default.default.parse(directory);
|
|
2003
1907
|
const stopAt = options.stopAt || root;
|
|
2004
1908
|
const limit = options.limit || Number.POSITIVE_INFINITY;
|
|
2005
1909
|
const paths = [name].flat();
|
|
@@ -2020,12 +1924,12 @@ function findUpMultipleSync(name, options = {}) {
|
|
|
2020
1924
|
break;
|
|
2021
1925
|
}
|
|
2022
1926
|
if (foundPath) {
|
|
2023
|
-
matches.push(
|
|
1927
|
+
matches.push(path2__default.default.resolve(directory, foundPath));
|
|
2024
1928
|
}
|
|
2025
1929
|
if (directory === stopAt || matches.length >= limit) {
|
|
2026
1930
|
break;
|
|
2027
1931
|
}
|
|
2028
|
-
directory =
|
|
1932
|
+
directory = path2__default.default.dirname(directory);
|
|
2029
1933
|
}
|
|
2030
1934
|
return matches;
|
|
2031
1935
|
}
|
|
@@ -2059,17 +1963,17 @@ var PackageManager = class _PackageManager {
|
|
|
2059
1963
|
}
|
|
2060
1964
|
return directory;
|
|
2061
1965
|
}
|
|
2062
|
-
getLocation(
|
|
2063
|
-
let location =
|
|
1966
|
+
getLocation(path3) {
|
|
1967
|
+
let location = path3;
|
|
2064
1968
|
if (this.#cwd) {
|
|
2065
1969
|
const require2 = mod__default.default.createRequire(this.normalizeDirectory(this.#cwd));
|
|
2066
|
-
location = require2.resolve(
|
|
1970
|
+
location = require2.resolve(path3);
|
|
2067
1971
|
}
|
|
2068
1972
|
return location;
|
|
2069
1973
|
}
|
|
2070
|
-
async import(
|
|
1974
|
+
async import(path3) {
|
|
2071
1975
|
try {
|
|
2072
|
-
let location = this.getLocation(
|
|
1976
|
+
let location = this.getLocation(path3);
|
|
2073
1977
|
if (os__default.default.platform() == "win32") {
|
|
2074
1978
|
location = url.pathToFileURL(location).href;
|
|
2075
1979
|
}
|
|
@@ -2145,33 +2049,67 @@ var PackageManager = class _PackageManager {
|
|
|
2145
2049
|
}
|
|
2146
2050
|
};
|
|
2147
2051
|
|
|
2148
|
-
// src/SchemaGenerator.ts
|
|
2149
|
-
var SchemaGenerator = class extends Generator {
|
|
2150
|
-
};
|
|
2151
|
-
|
|
2152
2052
|
// src/index.ts
|
|
2153
2053
|
var src_default = build;
|
|
2154
2054
|
|
|
2055
|
+
Object.defineProperty(exports, 'pc', {
|
|
2056
|
+
enumerable: true,
|
|
2057
|
+
get: function () { return pc3__default.default; }
|
|
2058
|
+
});
|
|
2155
2059
|
exports.FileManager = FileManager;
|
|
2060
|
+
exports.FunctionParams = FunctionParams;
|
|
2156
2061
|
exports.Generator = Generator;
|
|
2062
|
+
exports.LogLevel = LogLevel;
|
|
2157
2063
|
exports.PackageManager = PackageManager;
|
|
2158
2064
|
exports.ParallelPluginError = ParallelPluginError;
|
|
2159
2065
|
exports.PluginError = PluginError;
|
|
2160
2066
|
exports.PluginManager = PluginManager;
|
|
2161
|
-
exports.
|
|
2067
|
+
exports.Queue = Queue;
|
|
2162
2068
|
exports.SchemaGenerator = SchemaGenerator;
|
|
2163
2069
|
exports.SummaryError = SummaryError;
|
|
2070
|
+
exports.TreeNode = TreeNode;
|
|
2071
|
+
exports.URLPath = URLPath;
|
|
2164
2072
|
exports.ValidationPluginError = ValidationPluginError;
|
|
2165
2073
|
exports.Warning = Warning;
|
|
2166
2074
|
exports.build = build;
|
|
2075
|
+
exports.clean = clean;
|
|
2076
|
+
exports.combineCodes = combineCodes;
|
|
2077
|
+
exports.combineExports = combineExports;
|
|
2078
|
+
exports.combineFiles = combineFiles;
|
|
2079
|
+
exports.combineImports = combineImports;
|
|
2080
|
+
exports.createFileSource = createFileSource;
|
|
2081
|
+
exports.createJSDocBlockText = createJSDocBlockText;
|
|
2082
|
+
exports.createLogger = createLogger;
|
|
2167
2083
|
exports.createPlugin = createPlugin;
|
|
2084
|
+
exports.createPluginCache = createPluginCache;
|
|
2168
2085
|
exports.default = src_default;
|
|
2086
|
+
exports.defaultColours = defaultColours;
|
|
2169
2087
|
exports.defineConfig = defineConfig;
|
|
2170
|
-
exports.
|
|
2088
|
+
exports.escape = escape;
|
|
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;
|
|
2171
2097
|
exports.isPromise = isPromise;
|
|
2172
2098
|
exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
|
|
2173
2099
|
exports.isPromiseRejectedResult = isPromiseRejectedResult;
|
|
2100
|
+
exports.jsStringEscape = jsStringEscape;
|
|
2174
2101
|
exports.name = pluginName;
|
|
2102
|
+
exports.nameSorter = nameSorter;
|
|
2175
2103
|
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;
|
|
2176
2114
|
//# sourceMappingURL=out.js.map
|
|
2177
2115
|
//# sourceMappingURL=index.cjs.map
|