@kubb/core 2.0.0-beta.1 → 2.0.0-beta.11
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/Queue-2-6pMcCx.d.cts +32 -0
- package/dist/Queue-2-6pMcCx.d.ts +32 -0
- package/dist/fs.cjs +2383 -0
- package/dist/fs.cjs.map +1 -0
- package/dist/fs.d.cts +5 -0
- package/dist/fs.d.ts +5 -0
- package/dist/fs.js +2380 -0
- package/dist/fs.js.map +1 -0
- package/dist/index.cjs +3448 -394
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -127
- package/dist/index.d.ts +77 -127
- package/dist/index.js +3761 -423
- package/dist/index.js.map +1 -1
- package/dist/logger.cjs +90 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +32 -0
- package/dist/logger.d.ts +32 -0
- package/dist/logger.js +78 -0
- package/dist/logger.js.map +1 -0
- package/dist/transformers.cjs +222 -0
- package/dist/transformers.cjs.map +1 -0
- package/dist/transformers.d.cts +55 -0
- package/dist/transformers.d.ts +55 -0
- package/dist/transformers.js +207 -0
- package/dist/transformers.js.map +1 -0
- package/dist/utils.cjs +174 -899
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -146
- package/dist/utils.d.ts +2 -146
- package/dist/utils.js +175 -859
- package/dist/utils.js.map +1 -1
- package/dist/write-46ytbnu9.d.cts +7 -0
- package/dist/write-46ytbnu9.d.ts +7 -0
- package/package.json +27 -12
- package/src/BarrelManager.ts +55 -65
- package/src/FileManager.ts +109 -68
- package/src/PluginManager.ts +55 -32
- package/src/build.ts +5 -16
- package/src/fs/index.ts +3 -0
- package/src/index.ts +4 -5
- package/src/{utils/logger.ts → logger.ts} +37 -0
- package/src/plugin.ts +4 -4
- package/src/transformers/casing.ts +9 -0
- package/src/transformers/createJSDocBlockText.ts +9 -0
- package/src/transformers/index.ts +36 -0
- package/src/transformers/trim.ts +7 -0
- package/src/types.ts +23 -42
- package/src/utils/FunctionParams.ts +3 -2
- package/src/utils/TreeNode.ts +6 -3
- package/src/utils/URLPath.ts +5 -5
- package/src/utils/index.ts +10 -19
- package/src/SchemaGenerator.ts +0 -8
- package/src/utils/randomColour.ts +0 -39
- package/src/utils/throttle.ts +0 -30
- package/src/utils/transformers/createJSDocBlockText.ts +0 -15
- package/src/utils/transformers/index.ts +0 -22
- package/src/utils/transformers/trim.ts +0 -3
- /package/src/{utils → fs}/clean.ts +0 -0
- /package/src/{utils → fs}/read.ts +0 -0
- /package/src/{utils → fs}/write.ts +0 -0
- /package/src/{utils/transformers → transformers}/combineCodes.ts +0 -0
- /package/src/{utils/transformers → transformers}/escape.ts +0 -0
- /package/src/{utils/transformers → transformers}/indent.ts +0 -0
- /package/src/{utils/transformers → transformers}/nameSorter.ts +0 -0
- /package/src/{utils/transformers → transformers}/searchAndReplace.ts +0 -0
- /package/src/{utils/transformers → transformers}/transformReservedWord.ts +0 -0
package/dist/utils.js
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
|
-
import fs2, { remove } from 'fs-extra';
|
|
3
|
-
import { camelCase, camelCaseTransformMerge } from 'change-case';
|
|
4
2
|
import { orderBy } from 'natural-orderby';
|
|
5
|
-
import
|
|
6
|
-
export { default as pc } from 'picocolors';
|
|
3
|
+
import { camelCase as camelCase$1, camelCaseTransformMerge, pascalCase as pascalCase$1, pascalCaseTransformMerge } from 'change-case';
|
|
7
4
|
import crypto from 'crypto';
|
|
8
5
|
import { performance } from 'perf_hooks';
|
|
9
6
|
import { EventEmitter as EventEmitter$1 } from 'events';
|
|
10
|
-
import seedrandom from 'seedrandom';
|
|
11
|
-
import path, { resolve, relative, basename, extname, dirname } from 'path';
|
|
12
|
-
import { switcher } from 'js-runtime';
|
|
13
|
-
import dirTree from 'directory-tree';
|
|
14
|
-
import { print } from '@kubb/parser';
|
|
15
|
-
import * as factory from '@kubb/parser/factory';
|
|
16
|
-
import isEqual from 'lodash.isequal';
|
|
17
7
|
|
|
18
8
|
createRequire(import.meta.url);
|
|
19
9
|
|
|
@@ -47,376 +37,30 @@ var __privateMethod = (obj, member, method) => {
|
|
|
47
37
|
__accessCheck(obj, member, "access private method");
|
|
48
38
|
return method;
|
|
49
39
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
53
|
-
return {
|
|
54
|
-
set(id, value) {
|
|
55
|
-
Store[id] = [0, value];
|
|
56
|
-
},
|
|
57
|
-
get(id) {
|
|
58
|
-
const item = Store[id];
|
|
59
|
-
if (!item) {
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
item[0] = 0;
|
|
63
|
-
return item[1];
|
|
64
|
-
},
|
|
65
|
-
has(id) {
|
|
66
|
-
const item = Store[id];
|
|
67
|
-
if (!item) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
item[0] = 0;
|
|
71
|
-
return true;
|
|
72
|
-
},
|
|
73
|
-
delete(id) {
|
|
74
|
-
return delete Store[id];
|
|
75
|
-
}
|
|
76
|
-
};
|
|
40
|
+
function camelCase(text) {
|
|
41
|
+
return camelCase$1(text, { delimiter: "", stripRegexp: /[^A-Z0-9$]/gi, transform: camelCaseTransformMerge });
|
|
77
42
|
}
|
|
78
|
-
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
var FunctionParams = class {
|
|
82
|
-
constructor(type) {
|
|
83
|
-
this.items = [];
|
|
84
|
-
this.type = type;
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
add(item) {
|
|
88
|
-
if (!item) {
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
if (Array.isArray(item)) {
|
|
92
|
-
item.filter(Boolean).forEach((it) => this.items.push(it));
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
this.items.push(item);
|
|
96
|
-
return this;
|
|
97
|
-
}
|
|
98
|
-
toString() {
|
|
99
|
-
const sortedData = orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ["desc", "desc"]);
|
|
100
|
-
return sortedData.filter(({ enabled = true }) => enabled).reduce((acc, { name, type, required = true, ...rest }) => {
|
|
101
|
-
if (!name) {
|
|
102
|
-
acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
103
|
-
return acc;
|
|
104
|
-
}
|
|
105
|
-
const parameterName = name.startsWith("{") ? name : camelCase(name, { delimiter: "", transform: camelCaseTransformMerge });
|
|
106
|
-
if (type) {
|
|
107
|
-
if (required) {
|
|
108
|
-
acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
109
|
-
} else {
|
|
110
|
-
acc.push(`${parameterName}?: ${type}`);
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
acc.push(`${parameterName}`);
|
|
114
|
-
}
|
|
115
|
-
return acc;
|
|
116
|
-
}, []).join(", ");
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
var LogLevel = {
|
|
120
|
-
silent: "silent",
|
|
121
|
-
info: "info",
|
|
122
|
-
debug: "debug"
|
|
123
|
-
};
|
|
124
|
-
function createLogger({ logLevel, name, spinner }) {
|
|
125
|
-
const logs = [];
|
|
126
|
-
const log = (message) => {
|
|
127
|
-
if (message && spinner) {
|
|
128
|
-
spinner.text = message;
|
|
129
|
-
logs.push(message);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
const error = (message) => {
|
|
133
|
-
if (message) {
|
|
134
|
-
throw new Error(message || "Something went wrong");
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
const warn = (message) => {
|
|
138
|
-
if (message && spinner) {
|
|
139
|
-
spinner.warn(pc2.yellow(message));
|
|
140
|
-
logs.push(message);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
const info = (message) => {
|
|
144
|
-
if (message && spinner && logLevel !== LogLevel.silent) {
|
|
145
|
-
spinner.info(message);
|
|
146
|
-
logs.push(message);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
const logger = {
|
|
150
|
-
name,
|
|
151
|
-
logLevel,
|
|
152
|
-
log,
|
|
153
|
-
error,
|
|
154
|
-
warn,
|
|
155
|
-
info,
|
|
156
|
-
spinner,
|
|
157
|
-
logs
|
|
158
|
-
};
|
|
159
|
-
return logger;
|
|
43
|
+
function pascalCase(text) {
|
|
44
|
+
return pascalCase$1(text, { delimiter: "", stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge });
|
|
160
45
|
}
|
|
161
46
|
|
|
162
|
-
// src/
|
|
163
|
-
function isPromise(result) {
|
|
164
|
-
return !!result && typeof result?.then === "function";
|
|
165
|
-
}
|
|
166
|
-
function isPromiseFulfilledResult(result) {
|
|
167
|
-
return result.status === "fulfilled";
|
|
168
|
-
}
|
|
169
|
-
function isPromiseRejectedResult(result) {
|
|
170
|
-
return result.status === "rejected";
|
|
171
|
-
}
|
|
172
|
-
var _emitter;
|
|
173
|
-
var EventEmitter = class {
|
|
174
|
-
constructor() {
|
|
175
|
-
__privateAdd(this, _emitter, new EventEmitter$1());
|
|
176
|
-
__privateGet(this, _emitter).setMaxListeners(100);
|
|
177
|
-
}
|
|
178
|
-
emit(eventName, ...eventArg) {
|
|
179
|
-
__privateGet(this, _emitter).emit(eventName, ...eventArg);
|
|
180
|
-
}
|
|
181
|
-
on(eventName, handler) {
|
|
182
|
-
__privateGet(this, _emitter).on(eventName, handler);
|
|
183
|
-
}
|
|
184
|
-
off(eventName, handler) {
|
|
185
|
-
__privateGet(this, _emitter).off(eventName, handler);
|
|
186
|
-
}
|
|
187
|
-
removeAll() {
|
|
188
|
-
__privateGet(this, _emitter).removeAllListeners();
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
_emitter = new WeakMap();
|
|
192
|
-
|
|
193
|
-
// src/utils/Queue.ts
|
|
194
|
-
var _queue, _workerCount, _maxParallel, _debug, _work, work_fn;
|
|
195
|
-
var Queue = class {
|
|
196
|
-
constructor(maxParallel, debug = false) {
|
|
197
|
-
__privateAdd(this, _work);
|
|
198
|
-
__privateAdd(this, _queue, []);
|
|
199
|
-
this.eventEmitter = new EventEmitter();
|
|
200
|
-
__privateAdd(this, _workerCount, 0);
|
|
201
|
-
__privateAdd(this, _maxParallel, void 0);
|
|
202
|
-
__privateAdd(this, _debug, false);
|
|
203
|
-
__privateSet(this, _maxParallel, maxParallel);
|
|
204
|
-
__privateSet(this, _debug, debug);
|
|
205
|
-
}
|
|
206
|
-
run(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
|
|
207
|
-
return new Promise((resolve2, reject) => {
|
|
208
|
-
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
209
|
-
options.controller?.signal.addEventListener("abort", () => {
|
|
210
|
-
__privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
|
|
211
|
-
reject("Aborted");
|
|
212
|
-
});
|
|
213
|
-
__privateGet(this, _queue).push(item);
|
|
214
|
-
__privateMethod(this, _work, work_fn).call(this);
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
runSync(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
|
|
218
|
-
new Promise((resolve2, reject) => {
|
|
219
|
-
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
220
|
-
options.controller?.signal.addEventListener("abort", () => {
|
|
221
|
-
__privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
|
|
222
|
-
});
|
|
223
|
-
__privateGet(this, _queue).push(item);
|
|
224
|
-
__privateMethod(this, _work, work_fn).call(this);
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
get hasJobs() {
|
|
228
|
-
return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue).length > 0;
|
|
229
|
-
}
|
|
230
|
-
get count() {
|
|
231
|
-
return __privateGet(this, _workerCount);
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
_queue = new WeakMap();
|
|
235
|
-
_workerCount = new WeakMap();
|
|
236
|
-
_maxParallel = new WeakMap();
|
|
237
|
-
_debug = new WeakMap();
|
|
238
|
-
_work = new WeakSet();
|
|
239
|
-
work_fn = function() {
|
|
240
|
-
if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
__privateWrapper(this, _workerCount)._++;
|
|
244
|
-
let entry;
|
|
245
|
-
while (entry = __privateGet(this, _queue).shift()) {
|
|
246
|
-
const { reject, resolve: resolve2, job, name, description } = entry;
|
|
247
|
-
if (__privateGet(this, _debug)) {
|
|
248
|
-
performance.mark(name + "_start");
|
|
249
|
-
}
|
|
250
|
-
job().then((result) => {
|
|
251
|
-
this.eventEmitter.emit("jobDone", result);
|
|
252
|
-
resolve2(result);
|
|
253
|
-
if (__privateGet(this, _debug)) {
|
|
254
|
-
performance.mark(name + "_stop");
|
|
255
|
-
performance.measure(description, name + "_start", name + "_stop");
|
|
256
|
-
}
|
|
257
|
-
}).catch((err) => {
|
|
258
|
-
this.eventEmitter.emit("jobFailed", err);
|
|
259
|
-
reject(err);
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
__privateWrapper(this, _workerCount)._--;
|
|
263
|
-
};
|
|
264
|
-
var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
|
|
265
|
-
function randomColour(text, colours = defaultColours) {
|
|
266
|
-
if (!text) {
|
|
267
|
-
return "white";
|
|
268
|
-
}
|
|
269
|
-
const random = seedrandom(text);
|
|
270
|
-
const colour = colours.at(Math.floor(random() * colours.length)) || "white";
|
|
271
|
-
return colour;
|
|
272
|
-
}
|
|
273
|
-
function randomPicoColour(text, colors = defaultColours) {
|
|
274
|
-
const colours = pc2.createColors(true);
|
|
275
|
-
if (!text) {
|
|
276
|
-
return colours.white(text);
|
|
277
|
-
}
|
|
278
|
-
const colour = randomColour(text, colors);
|
|
279
|
-
const isDark = colour.includes("dark");
|
|
280
|
-
const key = colour.replace("dark", "").toLowerCase();
|
|
281
|
-
const formatter = colours[key];
|
|
282
|
-
if (isDark) {
|
|
283
|
-
return pc2.bold(formatter(text));
|
|
284
|
-
}
|
|
285
|
-
if (typeof formatter !== "function") {
|
|
286
|
-
throw new Error("Formatter for picoColor is not of type function/Formatter");
|
|
287
|
-
}
|
|
288
|
-
return formatter(text);
|
|
289
|
-
}
|
|
290
|
-
function slash(path2, platform = "linux") {
|
|
291
|
-
const isWindowsPath = /^\\\\\?\\/.test(path2);
|
|
292
|
-
if (["linux", "mac"].includes(platform) && !isWindowsPath) {
|
|
293
|
-
return path2.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
294
|
-
}
|
|
295
|
-
return path2.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
296
|
-
}
|
|
297
|
-
function getRelativePath(rootDir, filePath, platform = "linux") {
|
|
298
|
-
if (!rootDir || !filePath) {
|
|
299
|
-
throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
|
|
300
|
-
}
|
|
301
|
-
const relativePath = relative(rootDir, filePath);
|
|
302
|
-
const slashedPath = slash(relativePath, platform);
|
|
303
|
-
if (slashedPath.startsWith("../")) {
|
|
304
|
-
return slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath)));
|
|
305
|
-
}
|
|
306
|
-
return `./${slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath)))}`;
|
|
307
|
-
}
|
|
308
|
-
var reader = switcher(
|
|
309
|
-
{
|
|
310
|
-
node: async (path2) => {
|
|
311
|
-
return fs2.readFile(path2, { encoding: "utf8" });
|
|
312
|
-
},
|
|
313
|
-
bun: async (path2) => {
|
|
314
|
-
const file = Bun.file(path2);
|
|
315
|
-
return file.text();
|
|
316
|
-
}
|
|
317
|
-
},
|
|
318
|
-
"node"
|
|
319
|
-
);
|
|
320
|
-
var syncReader = switcher(
|
|
321
|
-
{
|
|
322
|
-
node: (path2) => {
|
|
323
|
-
return fs2.readFileSync(path2, { encoding: "utf8" });
|
|
324
|
-
},
|
|
325
|
-
bun: () => {
|
|
326
|
-
throw new Error("Bun cannot read sync");
|
|
327
|
-
}
|
|
328
|
-
},
|
|
329
|
-
"node"
|
|
330
|
-
);
|
|
331
|
-
async function read(path2) {
|
|
332
|
-
return reader(path2);
|
|
333
|
-
}
|
|
334
|
-
function readSync(path2) {
|
|
335
|
-
return syncReader(path2);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// src/utils/renderTemplate.ts
|
|
339
|
-
function renderTemplate(template, data = void 0) {
|
|
340
|
-
if (!data || !Object.keys(data).length) {
|
|
341
|
-
return template.replace(/{{(.*?)}}/g, "");
|
|
342
|
-
}
|
|
343
|
-
const matches = template.match(/{{(.*?)}}/g);
|
|
344
|
-
return matches?.reduce((prev, curr) => {
|
|
345
|
-
const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
|
|
346
|
-
if (index === void 0) {
|
|
347
|
-
return prev;
|
|
348
|
-
}
|
|
349
|
-
const value = data[index];
|
|
350
|
-
if (value === void 0) {
|
|
351
|
-
return prev;
|
|
352
|
-
}
|
|
353
|
-
return prev.replace(curr, () => {
|
|
354
|
-
if (typeof value === "boolean") {
|
|
355
|
-
return `${value.toString()}` || "false";
|
|
356
|
-
}
|
|
357
|
-
return value || "";
|
|
358
|
-
}).trim();
|
|
359
|
-
}, template) || "";
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
// src/utils/throttle.ts
|
|
363
|
-
var throttle = (fn, delay) => {
|
|
364
|
-
let wait = false;
|
|
365
|
-
let timeout2;
|
|
366
|
-
let cancelled = false;
|
|
367
|
-
return [
|
|
368
|
-
(...args) => {
|
|
369
|
-
if (cancelled) {
|
|
370
|
-
return void 0;
|
|
371
|
-
}
|
|
372
|
-
if (wait) {
|
|
373
|
-
return void 0;
|
|
374
|
-
}
|
|
375
|
-
const val = fn(...args);
|
|
376
|
-
wait = true;
|
|
377
|
-
timeout2 = setTimeout(() => {
|
|
378
|
-
wait = false;
|
|
379
|
-
}, delay);
|
|
380
|
-
return val;
|
|
381
|
-
},
|
|
382
|
-
() => {
|
|
383
|
-
cancelled = true;
|
|
384
|
-
clearTimeout(timeout2);
|
|
385
|
-
}
|
|
386
|
-
];
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
// src/utils/timeout.ts
|
|
390
|
-
async function timeout(ms) {
|
|
391
|
-
return new Promise((resolve2) => {
|
|
392
|
-
setTimeout(() => {
|
|
393
|
-
resolve2(true);
|
|
394
|
-
}, ms);
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// src/utils/transformers/combineCodes.ts
|
|
47
|
+
// src/transformers/combineCodes.ts
|
|
399
48
|
function combineCodes(codes) {
|
|
400
49
|
return codes.join("\n");
|
|
401
50
|
}
|
|
402
51
|
|
|
403
|
-
// src/
|
|
404
|
-
function createJSDocBlockText({ comments
|
|
52
|
+
// src/transformers/createJSDocBlockText.ts
|
|
53
|
+
function createJSDocBlockText({ comments }) {
|
|
405
54
|
const filteredComments = comments.filter(Boolean);
|
|
406
55
|
if (!filteredComments.length) {
|
|
407
56
|
return "";
|
|
408
57
|
}
|
|
409
|
-
|
|
58
|
+
return `/**
|
|
410
59
|
* ${filteredComments.join("\n * ")}
|
|
411
60
|
*/`;
|
|
412
|
-
if (newLine) {
|
|
413
|
-
return `${source}
|
|
414
|
-
`;
|
|
415
|
-
}
|
|
416
|
-
return source;
|
|
417
61
|
}
|
|
418
62
|
|
|
419
|
-
// src/
|
|
63
|
+
// src/transformers/escape.ts
|
|
420
64
|
function escape(text) {
|
|
421
65
|
return text ? text.replaceAll("`", "\\`") : "";
|
|
422
66
|
}
|
|
@@ -441,12 +85,12 @@ function jsStringEscape(input) {
|
|
|
441
85
|
});
|
|
442
86
|
}
|
|
443
87
|
|
|
444
|
-
// src/
|
|
88
|
+
// src/transformers/indent.ts
|
|
445
89
|
function createIndent(size) {
|
|
446
90
|
return Array.from({ length: size + 1 }).join(" ");
|
|
447
91
|
}
|
|
448
92
|
|
|
449
|
-
// src/
|
|
93
|
+
// src/transformers/nameSorter.ts
|
|
450
94
|
function nameSorter(a, b) {
|
|
451
95
|
if (a.name < b.name) {
|
|
452
96
|
return -1;
|
|
@@ -457,7 +101,7 @@ function nameSorter(a, b) {
|
|
|
457
101
|
return 0;
|
|
458
102
|
}
|
|
459
103
|
|
|
460
|
-
// src/
|
|
104
|
+
// src/transformers/searchAndReplace.ts
|
|
461
105
|
function searchAndReplace(options) {
|
|
462
106
|
const { text, replaceBy, prefix = "", key } = options;
|
|
463
107
|
const searchValues = options.searchValues?.(prefix, key) || [
|
|
@@ -474,7 +118,7 @@ function searchAndReplace(options) {
|
|
|
474
118
|
}, text);
|
|
475
119
|
}
|
|
476
120
|
|
|
477
|
-
// src/
|
|
121
|
+
// src/transformers/transformReservedWord.ts
|
|
478
122
|
var reservedWords = [
|
|
479
123
|
"abstract",
|
|
480
124
|
"arguments",
|
|
@@ -567,13 +211,16 @@ function transformReservedWord(word) {
|
|
|
567
211
|
return word;
|
|
568
212
|
}
|
|
569
213
|
|
|
570
|
-
// src/
|
|
214
|
+
// src/transformers/trim.ts
|
|
571
215
|
function trim(text) {
|
|
572
216
|
return text.replaceAll(/\n/g, "").trim();
|
|
573
217
|
}
|
|
218
|
+
function trimExtName(text) {
|
|
219
|
+
return text.replace(/\.[^/.]+$/, "");
|
|
220
|
+
}
|
|
574
221
|
|
|
575
|
-
// src/
|
|
576
|
-
var
|
|
222
|
+
// src/transformers/index.ts
|
|
223
|
+
var transformers_default = {
|
|
577
224
|
combineCodes,
|
|
578
225
|
escape,
|
|
579
226
|
jsStringEscape,
|
|
@@ -582,522 +229,189 @@ var transformers = {
|
|
|
582
229
|
nameSorter,
|
|
583
230
|
searchAndReplace,
|
|
584
231
|
trim,
|
|
232
|
+
trimExtName,
|
|
585
233
|
JSDoc: {
|
|
586
234
|
createJSDocBlockText
|
|
587
|
-
}
|
|
235
|
+
},
|
|
236
|
+
camelCase,
|
|
237
|
+
pascalCase
|
|
588
238
|
};
|
|
589
|
-
async function saveCreateDirectory(path2) {
|
|
590
|
-
const passedPath = dirname(resolve(path2));
|
|
591
|
-
await fs2.mkdir(passedPath, { recursive: true });
|
|
592
|
-
}
|
|
593
|
-
var writer = switcher(
|
|
594
|
-
{
|
|
595
|
-
node: async (path2, data) => {
|
|
596
|
-
try {
|
|
597
|
-
await fs2.stat(resolve(path2));
|
|
598
|
-
const oldContent = await fs2.readFile(resolve(path2), { encoding: "utf-8" });
|
|
599
|
-
if (oldContent?.toString() === data?.toString()) {
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
} catch (_err) {
|
|
603
|
-
}
|
|
604
|
-
await saveCreateDirectory(path2);
|
|
605
|
-
await fs2.writeFile(resolve(path2), data, { encoding: "utf-8" });
|
|
606
|
-
const savedData = await fs2.readFile(resolve(path2), { encoding: "utf-8" });
|
|
607
|
-
if (savedData?.toString() !== data?.toString()) {
|
|
608
|
-
throw new Error(`Sanity check failed for ${path2}
|
|
609
|
-
|
|
610
|
-
Data[${data.length}]:
|
|
611
|
-
${data}
|
|
612
|
-
|
|
613
|
-
Saved[${savedData.length}]:
|
|
614
|
-
${savedData}
|
|
615
|
-
`);
|
|
616
|
-
}
|
|
617
|
-
return savedData;
|
|
618
|
-
},
|
|
619
|
-
bun: async (path2, data) => {
|
|
620
|
-
try {
|
|
621
|
-
await saveCreateDirectory(path2);
|
|
622
|
-
await Bun.write(resolve(path2), data);
|
|
623
|
-
const file = Bun.file(resolve(path2));
|
|
624
|
-
const savedData = await file.text();
|
|
625
|
-
if (savedData?.toString() !== data?.toString()) {
|
|
626
|
-
throw new Error(`Sanity check failed for ${path2}
|
|
627
239
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
`);
|
|
634
|
-
}
|
|
635
|
-
return savedData;
|
|
636
|
-
} catch (e) {
|
|
637
|
-
console.log(e, resolve(path2));
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
},
|
|
641
|
-
"node"
|
|
642
|
-
);
|
|
643
|
-
async function write(data, path2) {
|
|
644
|
-
if (data.trim() === "") {
|
|
645
|
-
return void 0;
|
|
646
|
-
}
|
|
647
|
-
return writer(path2, data.trim());
|
|
648
|
-
}
|
|
649
|
-
var _options;
|
|
650
|
-
var BarrelManager = class {
|
|
651
|
-
constructor(options = {}) {
|
|
652
|
-
__privateAdd(this, _options, {});
|
|
653
|
-
__privateSet(this, _options, options);
|
|
240
|
+
// src/utils/FunctionParams.ts
|
|
241
|
+
var FunctionParams = class {
|
|
242
|
+
constructor(type) {
|
|
243
|
+
this.items = [];
|
|
244
|
+
this.type = type;
|
|
654
245
|
return this;
|
|
655
246
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
".ts": {
|
|
660
|
-
extensions: /\.ts/,
|
|
661
|
-
exclude: [/schemas/, /json/]
|
|
662
|
-
},
|
|
663
|
-
".json": {
|
|
664
|
-
extensions: /\.json/,
|
|
665
|
-
exclude: []
|
|
666
|
-
}
|
|
667
|
-
};
|
|
668
|
-
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
|
|
669
|
-
if (!tree) {
|
|
670
|
-
return null;
|
|
247
|
+
add(item) {
|
|
248
|
+
if (!item) {
|
|
249
|
+
return this;
|
|
671
250
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
}
|
|
676
|
-
if (currentTree.children?.length > 1) {
|
|
677
|
-
const indexPath = path.resolve(currentTree.data.path, "index.ts");
|
|
678
|
-
const exports = currentTree.children.filter(Boolean).map((file) => {
|
|
679
|
-
const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
680
|
-
if (importPath.includes("index") && file.data.type === "file") {
|
|
681
|
-
return void 0;
|
|
682
|
-
}
|
|
683
|
-
return {
|
|
684
|
-
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
685
|
-
isTypeOnly
|
|
686
|
-
};
|
|
687
|
-
}).filter(Boolean);
|
|
688
|
-
files2.push({
|
|
689
|
-
path: indexPath,
|
|
690
|
-
baseName: "index.ts",
|
|
691
|
-
source: "",
|
|
692
|
-
exports: output ? exports?.filter((item) => {
|
|
693
|
-
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
694
|
-
}) : exports
|
|
695
|
-
});
|
|
696
|
-
} else {
|
|
697
|
-
currentTree.children?.forEach((child) => {
|
|
698
|
-
const indexPath = path.resolve(currentTree.data.path, "index.ts");
|
|
699
|
-
const importPath = child.data.type === "directory" ? `./${child.data.name}/index` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
700
|
-
const exports = [
|
|
701
|
-
{
|
|
702
|
-
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
703
|
-
isTypeOnly
|
|
704
|
-
}
|
|
705
|
-
];
|
|
706
|
-
files2.push({
|
|
707
|
-
path: indexPath,
|
|
708
|
-
baseName: "index.ts",
|
|
709
|
-
source: "",
|
|
710
|
-
exports: output ? exports?.filter((item) => {
|
|
711
|
-
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
712
|
-
}) : exports
|
|
713
|
-
});
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
currentTree.children.forEach((childItem) => {
|
|
717
|
-
fileReducer(files2, childItem);
|
|
718
|
-
});
|
|
719
|
-
return files2;
|
|
720
|
-
};
|
|
721
|
-
const files = fileReducer([], tree).reverse();
|
|
722
|
-
const filteredFiles = filter ? files.filter(filter) : files;
|
|
723
|
-
return map ? filteredFiles.map(map) : filteredFiles;
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
|
-
_options = new WeakMap();
|
|
727
|
-
var _cache, _task, _isWriting, _timeout, _queue2, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
728
|
-
var _FileManager = class _FileManager {
|
|
729
|
-
constructor(options) {
|
|
730
|
-
__privateAdd(this, _validate);
|
|
731
|
-
__privateAdd(this, _add);
|
|
732
|
-
__privateAdd(this, _addOrAppend);
|
|
733
|
-
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
|
|
734
|
-
__privateAdd(this, _task, void 0);
|
|
735
|
-
__privateAdd(this, _isWriting, false);
|
|
736
|
-
/**
|
|
737
|
-
* Timeout between writes
|
|
738
|
-
*/
|
|
739
|
-
__privateAdd(this, _timeout, 0);
|
|
740
|
-
__privateAdd(this, _queue2, void 0);
|
|
741
|
-
if (options) {
|
|
742
|
-
__privateSet(this, _task, options.task);
|
|
743
|
-
__privateSet(this, _queue2, options.queue);
|
|
744
|
-
__privateSet(this, _timeout, options.timeout || 0);
|
|
251
|
+
if (Array.isArray(item)) {
|
|
252
|
+
item.filter(Boolean).forEach((it) => this.items.push(it));
|
|
253
|
+
return this;
|
|
745
254
|
}
|
|
255
|
+
this.items.push(item);
|
|
746
256
|
return this;
|
|
747
257
|
}
|
|
748
|
-
|
|
749
|
-
const
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
return files;
|
|
754
|
-
}
|
|
755
|
-
get isExecuting() {
|
|
756
|
-
return __privateGet(this, _queue2)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
|
|
757
|
-
}
|
|
758
|
-
async add(...files) {
|
|
759
|
-
const promises = files.map((file) => {
|
|
760
|
-
__privateMethod(this, _validate, validate_fn).call(this, file);
|
|
761
|
-
if (file.override) {
|
|
762
|
-
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
763
|
-
}
|
|
764
|
-
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
|
|
765
|
-
});
|
|
766
|
-
const resolvedFiles = await Promise.all(promises);
|
|
767
|
-
if (files.length > 1) {
|
|
768
|
-
return resolvedFiles;
|
|
769
|
-
}
|
|
770
|
-
return resolvedFiles[0];
|
|
771
|
-
}
|
|
772
|
-
async addIndexes({ root, extName = ".ts", meta, options = {} }) {
|
|
773
|
-
const barrelManager = new BarrelManager(options);
|
|
774
|
-
const files = barrelManager.getIndexes(root, extName);
|
|
775
|
-
if (!files) {
|
|
776
|
-
return void 0;
|
|
777
|
-
}
|
|
778
|
-
return await Promise.all(
|
|
779
|
-
files.map((file) => {
|
|
780
|
-
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
781
|
-
...file,
|
|
782
|
-
meta: meta ? meta : file.meta
|
|
783
|
-
});
|
|
784
|
-
})
|
|
785
|
-
);
|
|
786
|
-
}
|
|
787
|
-
getCacheByUUID(UUID) {
|
|
788
|
-
let cache;
|
|
789
|
-
__privateGet(this, _cache).forEach((files) => {
|
|
790
|
-
cache = files.find((item) => item.id === UUID);
|
|
791
|
-
});
|
|
792
|
-
return cache;
|
|
793
|
-
}
|
|
794
|
-
get(path2) {
|
|
795
|
-
return __privateGet(this, _cache).get(path2);
|
|
796
|
-
}
|
|
797
|
-
remove(path2) {
|
|
798
|
-
const cacheItem = this.get(path2);
|
|
799
|
-
if (!cacheItem) {
|
|
800
|
-
return;
|
|
801
|
-
}
|
|
802
|
-
__privateGet(this, _cache).delete(path2);
|
|
803
|
-
}
|
|
804
|
-
async write(...params) {
|
|
805
|
-
if (!__privateGet(this, _isWriting)) {
|
|
806
|
-
__privateSet(this, _isWriting, true);
|
|
807
|
-
const text = await write(...params);
|
|
808
|
-
__privateSet(this, _isWriting, false);
|
|
809
|
-
return text;
|
|
810
|
-
}
|
|
811
|
-
await timeout(__privateGet(this, _timeout));
|
|
812
|
-
return this.write(...params);
|
|
813
|
-
}
|
|
814
|
-
async read(...params) {
|
|
815
|
-
return read(...params);
|
|
816
|
-
}
|
|
817
|
-
// statics
|
|
818
|
-
static getSource(file) {
|
|
819
|
-
if (!_FileManager.isExtensionAllowed(file.baseName)) {
|
|
820
|
-
return file.source;
|
|
821
|
-
}
|
|
822
|
-
const exports = file.exports ? combineExports(file.exports) : [];
|
|
823
|
-
const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
|
|
824
|
-
const importNodes = imports.map((item) => factory.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
825
|
-
const exportNodes = exports.map(
|
|
826
|
-
(item) => factory.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias })
|
|
827
|
-
);
|
|
828
|
-
return [print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
829
|
-
}
|
|
830
|
-
static combineFiles(files) {
|
|
831
|
-
return files.filter(Boolean).reduce((acc, file) => {
|
|
832
|
-
const prevIndex = acc.findIndex((item) => item.path === file.path);
|
|
833
|
-
if (prevIndex === -1) {
|
|
834
|
-
return [...acc, file];
|
|
835
|
-
}
|
|
836
|
-
const prev = acc[prevIndex];
|
|
837
|
-
if (prev && file.override) {
|
|
838
|
-
acc[prevIndex] = {
|
|
839
|
-
imports: [],
|
|
840
|
-
exports: [],
|
|
841
|
-
...file
|
|
842
|
-
};
|
|
258
|
+
toString() {
|
|
259
|
+
const sortedData = orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ["desc", "desc"]);
|
|
260
|
+
return sortedData.filter(({ enabled = true }) => enabled).reduce((acc, { name, type, required = true, ...rest }) => {
|
|
261
|
+
if (!name) {
|
|
262
|
+
acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
843
263
|
return acc;
|
|
844
264
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
};
|
|
265
|
+
const parameterName = name.startsWith("{") ? name : transformers_default.camelCase(name);
|
|
266
|
+
if (type) {
|
|
267
|
+
if (required) {
|
|
268
|
+
acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
269
|
+
} else {
|
|
270
|
+
acc.push(`${parameterName}?: ${type}`);
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
acc.push(`${parameterName}`);
|
|
854
274
|
}
|
|
855
275
|
return acc;
|
|
856
|
-
}, []);
|
|
276
|
+
}, []).join(", ");
|
|
857
277
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// src/utils/promise.ts
|
|
281
|
+
function isPromise(result) {
|
|
282
|
+
return !!result && typeof result?.then === "function";
|
|
283
|
+
}
|
|
284
|
+
function isPromiseFulfilledResult(result) {
|
|
285
|
+
return result.status === "fulfilled";
|
|
286
|
+
}
|
|
287
|
+
function isPromiseRejectedResult(result) {
|
|
288
|
+
return result.status === "rejected";
|
|
289
|
+
}
|
|
290
|
+
var _emitter;
|
|
291
|
+
var EventEmitter = class {
|
|
292
|
+
constructor() {
|
|
293
|
+
__privateAdd(this, _emitter, new EventEmitter$1());
|
|
294
|
+
__privateGet(this, _emitter).setMaxListeners(100);
|
|
863
295
|
}
|
|
864
|
-
|
|
865
|
-
|
|
296
|
+
emit(eventName, ...eventArg) {
|
|
297
|
+
__privateGet(this, _emitter).emit(eventName, ...eventArg);
|
|
866
298
|
}
|
|
867
|
-
|
|
868
|
-
|
|
299
|
+
on(eventName, handler) {
|
|
300
|
+
__privateGet(this, _emitter).on(eventName, handler);
|
|
869
301
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
_task = new WeakMap();
|
|
873
|
-
_isWriting = new WeakMap();
|
|
874
|
-
_timeout = new WeakMap();
|
|
875
|
-
_queue2 = new WeakMap();
|
|
876
|
-
_validate = new WeakSet();
|
|
877
|
-
validate_fn = function(file) {
|
|
878
|
-
if (!file.validate) {
|
|
879
|
-
return;
|
|
302
|
+
off(eventName, handler) {
|
|
303
|
+
__privateGet(this, _emitter).off(eventName, handler);
|
|
880
304
|
}
|
|
881
|
-
|
|
882
|
-
|
|
305
|
+
removeAll() {
|
|
306
|
+
__privateGet(this, _emitter).removeAllListeners();
|
|
883
307
|
}
|
|
884
308
|
};
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
);
|
|
309
|
+
_emitter = new WeakMap();
|
|
310
|
+
|
|
311
|
+
// src/utils/Queue.ts
|
|
312
|
+
var _queue, _workerCount, _maxParallel, _debug, _work, work_fn;
|
|
313
|
+
var Queue = class {
|
|
314
|
+
constructor(maxParallel, debug = false) {
|
|
315
|
+
__privateAdd(this, _work);
|
|
316
|
+
__privateAdd(this, _queue, []);
|
|
317
|
+
this.eventEmitter = new EventEmitter();
|
|
318
|
+
__privateAdd(this, _workerCount, 0);
|
|
319
|
+
__privateAdd(this, _maxParallel, void 0);
|
|
320
|
+
__privateAdd(this, _debug, false);
|
|
321
|
+
__privateSet(this, _maxParallel, maxParallel);
|
|
322
|
+
__privateSet(this, _debug, debug);
|
|
898
323
|
}
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
...file,
|
|
909
|
-
source: previousCache.source && file.source ? `${previousCache.source}
|
|
910
|
-
${file.source}` : "",
|
|
911
|
-
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
912
|
-
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
913
|
-
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
324
|
+
run(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
|
|
325
|
+
return new Promise((resolve, reject) => {
|
|
326
|
+
const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
|
|
327
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
328
|
+
__privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
|
|
329
|
+
reject("Aborted");
|
|
330
|
+
});
|
|
331
|
+
__privateGet(this, _queue).push(item);
|
|
332
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
914
333
|
});
|
|
915
334
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
return prev;
|
|
926
|
-
}
|
|
927
|
-
const uniquePrev = prev.findLast(
|
|
928
|
-
(imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
929
|
-
);
|
|
930
|
-
if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) {
|
|
931
|
-
return prev;
|
|
932
|
-
}
|
|
933
|
-
if (!prevByPath) {
|
|
934
|
-
return [
|
|
935
|
-
...prev,
|
|
936
|
-
{
|
|
937
|
-
...curr,
|
|
938
|
-
name: Array.isArray(name) ? [...new Set(name)] : name
|
|
939
|
-
}
|
|
940
|
-
];
|
|
941
|
-
}
|
|
942
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
943
|
-
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...curr.name])];
|
|
944
|
-
return prev;
|
|
945
|
-
}
|
|
946
|
-
return [...prev, curr];
|
|
947
|
-
}, []);
|
|
948
|
-
return orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
949
|
-
}
|
|
950
|
-
function combineImports(imports, exports, source) {
|
|
951
|
-
const combinedImports = orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
952
|
-
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
953
|
-
const hasImportInSource = (importName) => {
|
|
954
|
-
if (!source) {
|
|
955
|
-
return true;
|
|
956
|
-
}
|
|
957
|
-
const checker = (name2) => name2 && !!source.includes(name2);
|
|
958
|
-
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
959
|
-
};
|
|
960
|
-
if (Array.isArray(name)) {
|
|
961
|
-
name = name.filter((item) => hasImportInSource(item));
|
|
962
|
-
}
|
|
963
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
964
|
-
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
965
|
-
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly);
|
|
966
|
-
if (prevByPathNameAndIsTypeOnly) {
|
|
967
|
-
return prev;
|
|
968
|
-
}
|
|
969
|
-
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
970
|
-
return prev;
|
|
971
|
-
}
|
|
972
|
-
if (!prevByPath) {
|
|
973
|
-
return [
|
|
974
|
-
...prev,
|
|
975
|
-
{
|
|
976
|
-
...curr,
|
|
977
|
-
name
|
|
978
|
-
}
|
|
979
|
-
];
|
|
980
|
-
}
|
|
981
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
982
|
-
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...name])];
|
|
983
|
-
return prev;
|
|
984
|
-
}
|
|
985
|
-
if (!Array.isArray(name) && name && !hasImportInSource(name)) {
|
|
986
|
-
return prev;
|
|
987
|
-
}
|
|
988
|
-
return [...prev, curr];
|
|
989
|
-
}, []);
|
|
990
|
-
return orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
|
|
991
|
-
}
|
|
992
|
-
function getEnvSource(source, env) {
|
|
993
|
-
if (!env) {
|
|
994
|
-
return source;
|
|
995
|
-
}
|
|
996
|
-
const keys = Object.keys(env);
|
|
997
|
-
if (!keys.length) {
|
|
998
|
-
return source;
|
|
335
|
+
runSync(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
|
|
336
|
+
new Promise((resolve, reject) => {
|
|
337
|
+
const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
|
|
338
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
339
|
+
__privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
|
|
340
|
+
});
|
|
341
|
+
__privateGet(this, _queue).push(item);
|
|
342
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
343
|
+
});
|
|
999
344
|
}
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
const replaceBy = environmentValue ? `'${environmentValue.replaceAll('"', "")?.replaceAll("'", "")}'` : "undefined";
|
|
1003
|
-
if (key.toUpperCase() !== key) {
|
|
1004
|
-
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
1005
|
-
}
|
|
1006
|
-
if (typeof replaceBy === "string") {
|
|
1007
|
-
prev = transformers.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
1008
|
-
prev = transformers.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
1009
|
-
`, "ig"), ""), replaceBy, key });
|
|
1010
|
-
}
|
|
1011
|
-
return prev;
|
|
1012
|
-
}, source);
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
// src/utils/TreeNode.ts
|
|
1016
|
-
var TreeNode = class _TreeNode {
|
|
1017
|
-
constructor(data, parent) {
|
|
1018
|
-
this.children = [];
|
|
1019
|
-
this.data = data;
|
|
1020
|
-
this.parent = parent;
|
|
1021
|
-
return this;
|
|
345
|
+
get hasJobs() {
|
|
346
|
+
return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue).length > 0;
|
|
1022
347
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
if (!this.children) {
|
|
1026
|
-
this.children = [];
|
|
1027
|
-
}
|
|
1028
|
-
this.children.push(child);
|
|
1029
|
-
return child;
|
|
348
|
+
get count() {
|
|
349
|
+
return __privateGet(this, _workerCount);
|
|
1030
350
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
target = this.children[i].find(data);
|
|
1041
|
-
if (target) {
|
|
1042
|
-
return target;
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
return null;
|
|
351
|
+
};
|
|
352
|
+
_queue = new WeakMap();
|
|
353
|
+
_workerCount = new WeakMap();
|
|
354
|
+
_maxParallel = new WeakMap();
|
|
355
|
+
_debug = new WeakMap();
|
|
356
|
+
_work = new WeakSet();
|
|
357
|
+
work_fn = function() {
|
|
358
|
+
if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
|
|
359
|
+
return;
|
|
1047
360
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
361
|
+
__privateWrapper(this, _workerCount)._++;
|
|
362
|
+
let entry;
|
|
363
|
+
while (entry = __privateGet(this, _queue).shift()) {
|
|
364
|
+
const { reject, resolve, job, name, description } = entry;
|
|
365
|
+
if (__privateGet(this, _debug)) {
|
|
366
|
+
performance.mark(name + "_start");
|
|
1051
367
|
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
368
|
+
job().then((result) => {
|
|
369
|
+
this.eventEmitter.emit("jobDone", result);
|
|
370
|
+
resolve(result);
|
|
371
|
+
if (__privateGet(this, _debug)) {
|
|
372
|
+
performance.mark(name + "_stop");
|
|
373
|
+
performance.measure(description, name + "_start", name + "_stop");
|
|
1056
374
|
}
|
|
1057
|
-
}
|
|
1058
|
-
|
|
375
|
+
}).catch((err) => {
|
|
376
|
+
this.eventEmitter.emit("jobFailed", err);
|
|
377
|
+
reject(err);
|
|
378
|
+
});
|
|
1059
379
|
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
380
|
+
__privateWrapper(this, _workerCount)._--;
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
// src/utils/renderTemplate.ts
|
|
384
|
+
function renderTemplate(template, data = void 0) {
|
|
385
|
+
if (!data || !Object.keys(data).length) {
|
|
386
|
+
return template.replace(/{{(.*?)}}/g, "");
|
|
1065
387
|
}
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
388
|
+
const matches = template.match(/{{(.*?)}}/g);
|
|
389
|
+
return matches?.reduce((prev, curr) => {
|
|
390
|
+
const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
|
|
391
|
+
if (index === void 0) {
|
|
392
|
+
return prev;
|
|
1069
393
|
}
|
|
1070
|
-
|
|
1071
|
-
if (
|
|
1072
|
-
|
|
1073
|
-
this.children[i].forEach(callback);
|
|
1074
|
-
}
|
|
394
|
+
const value = data[index];
|
|
395
|
+
if (value === void 0) {
|
|
396
|
+
return prev;
|
|
1075
397
|
}
|
|
1076
|
-
return
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
try {
|
|
1080
|
-
const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
|
|
1081
|
-
const filteredTree = dirTree(path2, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
|
|
1082
|
-
if (!filteredTree) {
|
|
1083
|
-
return null;
|
|
398
|
+
return prev.replace(curr, () => {
|
|
399
|
+
if (typeof value === "boolean") {
|
|
400
|
+
return `${value.toString()}` || "false";
|
|
1084
401
|
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
};
|
|
402
|
+
return value || "";
|
|
403
|
+
}).trim();
|
|
404
|
+
}, template) || "";
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// src/utils/timeout.ts
|
|
408
|
+
async function timeout(ms) {
|
|
409
|
+
return new Promise((resolve) => {
|
|
410
|
+
setTimeout(() => {
|
|
411
|
+
resolve(true);
|
|
412
|
+
}, ms);
|
|
413
|
+
});
|
|
414
|
+
}
|
|
1101
415
|
|
|
1102
416
|
// src/utils/uniqueName.ts
|
|
1103
417
|
function getUniqueName(originalName, data) {
|
|
@@ -1118,9 +432,11 @@ function setUniqueName(originalName, data) {
|
|
|
1118
432
|
data[originalName] = 1;
|
|
1119
433
|
return originalName;
|
|
1120
434
|
}
|
|
435
|
+
|
|
436
|
+
// src/utils/URLPath.ts
|
|
1121
437
|
var URLPath = class {
|
|
1122
|
-
constructor(
|
|
1123
|
-
this.path =
|
|
438
|
+
constructor(path) {
|
|
439
|
+
this.path = path;
|
|
1124
440
|
return this;
|
|
1125
441
|
}
|
|
1126
442
|
/**
|
|
@@ -1184,7 +500,7 @@ var URLPath = class {
|
|
|
1184
500
|
let newPath = this.path.replaceAll("{", "${");
|
|
1185
501
|
if (found) {
|
|
1186
502
|
newPath = found.reduce((prev, curr) => {
|
|
1187
|
-
const pathParam = replacer ? replacer(camelCase(curr
|
|
503
|
+
const pathParam = replacer ? replacer(transformers_default.camelCase(curr)) : transformers_default.camelCase(curr);
|
|
1188
504
|
const replacement = `\${${pathParam}}`;
|
|
1189
505
|
return prev.replace(curr, replacement);
|
|
1190
506
|
}, this.path);
|
|
@@ -1200,7 +516,7 @@ var URLPath = class {
|
|
|
1200
516
|
const params = {};
|
|
1201
517
|
found.forEach((item) => {
|
|
1202
518
|
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
1203
|
-
const pathParam = replacer ? replacer(camelCase(item
|
|
519
|
+
const pathParam = replacer ? replacer(transformers_default.camelCase(item)) : transformers_default.camelCase(item);
|
|
1204
520
|
params[pathParam] = pathParam;
|
|
1205
521
|
}, this.path);
|
|
1206
522
|
return params;
|
|
@@ -1214,6 +530,6 @@ var URLPath = class {
|
|
|
1214
530
|
}
|
|
1215
531
|
};
|
|
1216
532
|
|
|
1217
|
-
export { FunctionParams,
|
|
533
|
+
export { FunctionParams, Queue, URLPath, getUniqueName, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, renderTemplate, setUniqueName, timeout };
|
|
1218
534
|
//# sourceMappingURL=out.js.map
|
|
1219
535
|
//# sourceMappingURL=utils.js.map
|