@kubb/core 1.15.0-canary.20231025T103357 → 1.15.0-canary.20231025T223729
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 +938 -876
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -320
- package/dist/index.d.ts +266 -320
- package/dist/index.js +863 -783
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +1194 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +228 -0
- package/dist/utils.d.ts +228 -0
- package/dist/utils.js +1145 -0
- package/dist/utils.js.map +1 -0
- package/globals.d.ts +33 -16
- package/package.json +9 -4
package/dist/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import mod, { createRequire } from 'module';
|
|
2
2
|
import pc3 from 'picocolors';
|
|
3
|
-
export { default as pc } from 'picocolors';
|
|
4
|
-
import crypto from 'crypto';
|
|
5
3
|
import fs2, { remove } from 'fs-extra';
|
|
6
|
-
import { camelCase, camelCaseTransformMerge } from 'change-case';
|
|
7
|
-
import { orderBy } from 'natural-orderby';
|
|
8
|
-
import { performance } from 'perf_hooks';
|
|
9
4
|
import seedrandom from 'seedrandom';
|
|
10
|
-
import pathParser from 'path';
|
|
11
5
|
import { switcher } from 'js-runtime';
|
|
12
|
-
import
|
|
13
|
-
import
|
|
6
|
+
import { camelCase, camelCaseTransformMerge } from 'change-case';
|
|
7
|
+
import crypto2 from 'crypto';
|
|
8
|
+
import path, { resolve, dirname, extname } from 'path';
|
|
9
|
+
import { print } from '@kubb/parser';
|
|
10
|
+
import * as factory from '@kubb/parser/factory';
|
|
14
11
|
import isEqual from 'lodash.isequal';
|
|
12
|
+
import { orderBy } from 'natural-orderby';
|
|
13
|
+
import dirTree from 'directory-tree';
|
|
15
14
|
import { EventEmitter as EventEmitter$1 } from 'events';
|
|
15
|
+
import { performance } from 'perf_hooks';
|
|
16
16
|
import os from 'os';
|
|
17
17
|
import { pathToFileURL } from 'url';
|
|
18
18
|
import { findUp, findUpSync } from 'find-up';
|
|
@@ -27,110 +27,15 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
27
27
|
return require.apply(this, arguments);
|
|
28
28
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
29
29
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
33
|
-
return {
|
|
34
|
-
set(id, value) {
|
|
35
|
-
Store[id] = [0, value];
|
|
36
|
-
},
|
|
37
|
-
get(id) {
|
|
38
|
-
const item = Store[id];
|
|
39
|
-
if (!item) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
item[0] = 0;
|
|
43
|
-
return item[1];
|
|
44
|
-
},
|
|
45
|
-
has(id) {
|
|
46
|
-
const item = Store[id];
|
|
47
|
-
if (!item) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
item[0] = 0;
|
|
51
|
-
return true;
|
|
52
|
-
},
|
|
53
|
-
delete(id) {
|
|
54
|
-
return delete Store[id];
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
async function clean(path) {
|
|
59
|
-
return remove(path);
|
|
30
|
+
async function clean(path3) {
|
|
31
|
+
return remove(path3);
|
|
60
32
|
}
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this.type = type;
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
add(item) {
|
|
69
|
-
if (!item) {
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
if (Array.isArray(item)) {
|
|
73
|
-
item.filter(Boolean).forEach((it) => this.items.push(it));
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
this.items.push(item);
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
toString() {
|
|
80
|
-
const sortedData = orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ["desc", "desc"]);
|
|
81
|
-
return sortedData.filter(({ enabled = true }) => enabled).reduce((acc, { name, type, required = true, ...rest }) => {
|
|
82
|
-
if (!name) {
|
|
83
|
-
acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
84
|
-
return acc;
|
|
85
|
-
}
|
|
86
|
-
const parameterName = name.startsWith("{") ? name : camelCase(name, { delimiter: "", transform: camelCaseTransformMerge });
|
|
87
|
-
if (type) {
|
|
88
|
-
if (required) {
|
|
89
|
-
acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
90
|
-
} else {
|
|
91
|
-
acc.push(`${parameterName}?: ${type}`);
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
acc.push(`${parameterName}`);
|
|
95
|
-
}
|
|
96
|
-
return acc;
|
|
97
|
-
}, []).join(", ");
|
|
98
|
-
}
|
|
33
|
+
var LogLevel = {
|
|
34
|
+
silent: "silent",
|
|
35
|
+
info: "info",
|
|
36
|
+
debug: "debug"
|
|
99
37
|
};
|
|
100
|
-
|
|
101
|
-
// src/utils/getUniqueName.ts
|
|
102
|
-
function getUniqueName(originalName, data) {
|
|
103
|
-
let used = data[originalName] || 0;
|
|
104
|
-
if (used) {
|
|
105
|
-
data[originalName] = ++used;
|
|
106
|
-
originalName += used;
|
|
107
|
-
}
|
|
108
|
-
data[originalName] = 1;
|
|
109
|
-
return originalName;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/utils/isPromise.ts
|
|
113
|
-
function isPromise(result) {
|
|
114
|
-
return typeof result?.then === "function";
|
|
115
|
-
}
|
|
116
|
-
function isPromiseFulfilledResult(result) {
|
|
117
|
-
return result.status === "fulfilled";
|
|
118
|
-
}
|
|
119
|
-
function isPromiseRejectedResult(result) {
|
|
120
|
-
return result.status === "rejected";
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// src/utils/jsdoc.ts
|
|
124
|
-
function createJSDocBlockText({ comments }) {
|
|
125
|
-
const filteredComments = comments.filter(Boolean);
|
|
126
|
-
if (!filteredComments.length) {
|
|
127
|
-
return "";
|
|
128
|
-
}
|
|
129
|
-
return `/**
|
|
130
|
-
* ${filteredComments.join("\n * ")}
|
|
131
|
-
*/`;
|
|
132
|
-
}
|
|
133
|
-
function createLogger(spinner) {
|
|
38
|
+
function createLogger({ logLevel, name, spinner }) {
|
|
134
39
|
const logs = [];
|
|
135
40
|
const log = (message) => {
|
|
136
41
|
if (message && spinner) {
|
|
@@ -156,6 +61,8 @@ function createLogger(spinner) {
|
|
|
156
61
|
}
|
|
157
62
|
};
|
|
158
63
|
const logger = {
|
|
64
|
+
name,
|
|
65
|
+
logLevel,
|
|
159
66
|
log,
|
|
160
67
|
error,
|
|
161
68
|
warn,
|
|
@@ -165,75 +72,6 @@ function createLogger(spinner) {
|
|
|
165
72
|
};
|
|
166
73
|
return logger;
|
|
167
74
|
}
|
|
168
|
-
|
|
169
|
-
// src/utils/nameSorter.ts
|
|
170
|
-
function nameSorter(a, b) {
|
|
171
|
-
if (a.name < b.name) {
|
|
172
|
-
return -1;
|
|
173
|
-
}
|
|
174
|
-
if (a.name > b.name) {
|
|
175
|
-
return 1;
|
|
176
|
-
}
|
|
177
|
-
return 0;
|
|
178
|
-
}
|
|
179
|
-
var Queue = class {
|
|
180
|
-
#queue = [];
|
|
181
|
-
#workerCount = 0;
|
|
182
|
-
#maxParallel;
|
|
183
|
-
#debug = false;
|
|
184
|
-
constructor(maxParallel, debug = false) {
|
|
185
|
-
this.#maxParallel = maxParallel;
|
|
186
|
-
this.#debug = debug;
|
|
187
|
-
}
|
|
188
|
-
run(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
|
|
189
|
-
return new Promise((resolve, reject) => {
|
|
190
|
-
const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
|
|
191
|
-
options.controller?.signal.addEventListener("abort", () => {
|
|
192
|
-
this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
|
|
193
|
-
reject("Aborted");
|
|
194
|
-
});
|
|
195
|
-
this.#queue.push(item);
|
|
196
|
-
this.#work();
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
runSync(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
|
|
200
|
-
new Promise((resolve, reject) => {
|
|
201
|
-
const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
|
|
202
|
-
options.controller?.signal.addEventListener("abort", () => {
|
|
203
|
-
this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
|
|
204
|
-
});
|
|
205
|
-
this.#queue.push(item);
|
|
206
|
-
this.#work();
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
get hasJobs() {
|
|
210
|
-
return this.#workerCount > 0 || this.#queue.length > 0;
|
|
211
|
-
}
|
|
212
|
-
get count() {
|
|
213
|
-
return this.#workerCount;
|
|
214
|
-
}
|
|
215
|
-
#work() {
|
|
216
|
-
if (this.#workerCount >= this.#maxParallel) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
this.#workerCount++;
|
|
220
|
-
let entry;
|
|
221
|
-
while (entry = this.#queue.shift()) {
|
|
222
|
-
const { reject, resolve, job, name, description } = entry;
|
|
223
|
-
if (this.#debug) {
|
|
224
|
-
performance.mark(name + "_start");
|
|
225
|
-
}
|
|
226
|
-
job().then((result) => {
|
|
227
|
-
resolve(result);
|
|
228
|
-
if (this.#debug) {
|
|
229
|
-
performance.mark(name + "_stop");
|
|
230
|
-
performance.measure(description, name + "_start", name + "_stop");
|
|
231
|
-
}
|
|
232
|
-
}).catch((err) => reject(err));
|
|
233
|
-
}
|
|
234
|
-
this.#workerCount--;
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
75
|
var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
|
|
238
76
|
function randomColour(text, colours = defaultColours) {
|
|
239
77
|
if (!text) {
|
|
@@ -260,46 +98,22 @@ function randomPicoColour(text, colors = defaultColours) {
|
|
|
260
98
|
}
|
|
261
99
|
return formatter(text);
|
|
262
100
|
}
|
|
263
|
-
function slash(path, platform = "linux") {
|
|
264
|
-
const isWindowsPath = /^\\\\\?\\/.test(path);
|
|
265
|
-
if (["linux", "mac"].includes(platform) && !isWindowsPath) {
|
|
266
|
-
return path.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
267
|
-
}
|
|
268
|
-
return path.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
269
|
-
}
|
|
270
|
-
function getRelativePath(rootDir, filePath, platform = "linux") {
|
|
271
|
-
if (!rootDir || !filePath) {
|
|
272
|
-
throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
|
|
273
|
-
}
|
|
274
|
-
const relativePath = pathParser.relative(rootDir, filePath);
|
|
275
|
-
const path = slash(relativePath, platform);
|
|
276
|
-
if (path.startsWith("../")) {
|
|
277
|
-
return path.replace(pathParser.basename(path), pathParser.basename(path, pathParser.extname(filePath)));
|
|
278
|
-
}
|
|
279
|
-
return `./${path.replace(pathParser.basename(path), pathParser.basename(path, pathParser.extname(filePath)))}`;
|
|
280
|
-
}
|
|
281
|
-
function getPathMode(path) {
|
|
282
|
-
if (!path) {
|
|
283
|
-
return "directory";
|
|
284
|
-
}
|
|
285
|
-
return pathParser.extname(path) ? "file" : "directory";
|
|
286
|
-
}
|
|
287
101
|
var reader = switcher(
|
|
288
102
|
{
|
|
289
|
-
node: async (
|
|
290
|
-
return fs2.readFile(
|
|
103
|
+
node: async (path3) => {
|
|
104
|
+
return fs2.readFile(path3, { encoding: "utf8" });
|
|
291
105
|
},
|
|
292
|
-
bun: async (
|
|
293
|
-
const file = Bun.file(
|
|
106
|
+
bun: async (path3) => {
|
|
107
|
+
const file = Bun.file(path3);
|
|
294
108
|
return file.text();
|
|
295
109
|
}
|
|
296
110
|
},
|
|
297
111
|
"node"
|
|
298
112
|
);
|
|
299
|
-
|
|
113
|
+
switcher(
|
|
300
114
|
{
|
|
301
|
-
node: (
|
|
302
|
-
return fs2.readFileSync(
|
|
115
|
+
node: (path3) => {
|
|
116
|
+
return fs2.readFileSync(path3, { encoding: "utf8" });
|
|
303
117
|
},
|
|
304
118
|
bun: () => {
|
|
305
119
|
throw new Error("Bun cannot read sync");
|
|
@@ -307,79 +121,116 @@ var syncReader = switcher(
|
|
|
307
121
|
},
|
|
308
122
|
"node"
|
|
309
123
|
);
|
|
310
|
-
async function read(
|
|
311
|
-
return reader(
|
|
312
|
-
}
|
|
313
|
-
function readSync(path) {
|
|
314
|
-
return syncReader(path);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// src/utils/renderTemplate.ts
|
|
318
|
-
function renderTemplate(template, data = void 0) {
|
|
319
|
-
if (!data || !Object.keys(data).length) {
|
|
320
|
-
return template.replace(/{{(.*?)}}/g, "");
|
|
321
|
-
}
|
|
322
|
-
const matches = template.match(/{{(.*?)}}/g);
|
|
323
|
-
return matches?.reduce((prev, curr) => {
|
|
324
|
-
const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
|
|
325
|
-
if (index === void 0) {
|
|
326
|
-
return prev;
|
|
327
|
-
}
|
|
328
|
-
const value = data[index];
|
|
329
|
-
if (value === void 0) {
|
|
330
|
-
return prev;
|
|
331
|
-
}
|
|
332
|
-
return prev.replace(curr, () => {
|
|
333
|
-
if (typeof value === "boolean") {
|
|
334
|
-
return `${value.toString()}` || "false";
|
|
335
|
-
}
|
|
336
|
-
return value || "";
|
|
337
|
-
}).trim();
|
|
338
|
-
}, template) || "";
|
|
124
|
+
async function read(path3) {
|
|
125
|
+
return reader(path3);
|
|
339
126
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
super(message, { cause: options.cause });
|
|
346
|
-
this.name = "SummaryError";
|
|
347
|
-
this.summary = options.summary || [];
|
|
127
|
+
var URLPath = class {
|
|
128
|
+
path;
|
|
129
|
+
constructor(path3) {
|
|
130
|
+
this.path = path3;
|
|
131
|
+
return this;
|
|
348
132
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
135
|
+
* @example /pet/{petId} => /pet/:petId
|
|
136
|
+
*/
|
|
137
|
+
get URL() {
|
|
138
|
+
return this.toURLPath();
|
|
139
|
+
}
|
|
140
|
+
get isURL() {
|
|
141
|
+
try {
|
|
142
|
+
const url = new URL(this.path);
|
|
143
|
+
if (url?.href) {
|
|
144
|
+
return true;
|
|
360
145
|
}
|
|
361
|
-
|
|
362
|
-
|
|
146
|
+
} catch (error) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
153
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
154
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
155
|
+
* @example /account/userID => `/account/${userId}`
|
|
156
|
+
*/
|
|
157
|
+
get template() {
|
|
158
|
+
return this.toTemplateString();
|
|
159
|
+
}
|
|
160
|
+
get object() {
|
|
161
|
+
return this.toObject();
|
|
162
|
+
}
|
|
163
|
+
get params() {
|
|
164
|
+
return this.getParams();
|
|
165
|
+
}
|
|
166
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
167
|
+
const object = {
|
|
168
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
|
|
169
|
+
params: this.getParams()
|
|
170
|
+
};
|
|
171
|
+
if (stringify) {
|
|
172
|
+
if (type !== "template") {
|
|
173
|
+
throw new Error("Type should be `template` when using stringiyf");
|
|
363
174
|
}
|
|
364
|
-
|
|
365
|
-
wait = true;
|
|
366
|
-
timeout2 = setTimeout(() => {
|
|
367
|
-
wait = false;
|
|
368
|
-
}, delay);
|
|
369
|
-
return val;
|
|
370
|
-
},
|
|
371
|
-
() => {
|
|
372
|
-
cancelled = true;
|
|
373
|
-
clearTimeout(timeout2);
|
|
175
|
+
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
374
176
|
}
|
|
375
|
-
|
|
177
|
+
return object;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
181
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
182
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
183
|
+
* @example /account/userID => `/account/${userId}`
|
|
184
|
+
*/
|
|
185
|
+
toTemplateString(replacer) {
|
|
186
|
+
const regex = /{(\w|-)*}/g;
|
|
187
|
+
const found = this.path.match(regex);
|
|
188
|
+
let newPath = this.path.replaceAll("{", "${");
|
|
189
|
+
if (found) {
|
|
190
|
+
newPath = found.reduce((prev, curr) => {
|
|
191
|
+
const pathParam = replacer ? replacer(camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge })) : camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge });
|
|
192
|
+
const replacement = `\${${pathParam}}`;
|
|
193
|
+
return prev.replace(curr, replacement);
|
|
194
|
+
}, this.path);
|
|
195
|
+
}
|
|
196
|
+
return `\`${newPath}\``;
|
|
197
|
+
}
|
|
198
|
+
getParams(replacer) {
|
|
199
|
+
const regex = /{(\w|-)*}/g;
|
|
200
|
+
const found = this.path.match(regex);
|
|
201
|
+
if (!found) {
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
const params = {};
|
|
205
|
+
found.forEach((item) => {
|
|
206
|
+
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
207
|
+
const pathParam = replacer ? replacer(camelCase(item, { delimiter: "", transform: camelCaseTransformMerge })) : camelCase(item, { delimiter: "", transform: camelCaseTransformMerge });
|
|
208
|
+
params[pathParam] = pathParam;
|
|
209
|
+
}, this.path);
|
|
210
|
+
return params;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
214
|
+
* @example /pet/{petId} => /pet/:petId
|
|
215
|
+
*/
|
|
216
|
+
toURLPath() {
|
|
217
|
+
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
218
|
+
}
|
|
376
219
|
};
|
|
377
220
|
|
|
221
|
+
// src/config.ts
|
|
222
|
+
function defineConfig(options) {
|
|
223
|
+
return options;
|
|
224
|
+
}
|
|
225
|
+
function isInputPath(result) {
|
|
226
|
+
return !!result && "path" in result;
|
|
227
|
+
}
|
|
228
|
+
|
|
378
229
|
// src/utils/timeout.ts
|
|
379
230
|
async function timeout(ms) {
|
|
380
|
-
return new Promise((
|
|
231
|
+
return new Promise((resolve2) => {
|
|
381
232
|
setTimeout(() => {
|
|
382
|
-
|
|
233
|
+
resolve2(true);
|
|
383
234
|
}, ms);
|
|
384
235
|
});
|
|
385
236
|
}
|
|
@@ -389,6 +240,17 @@ function combineCodes(codes) {
|
|
|
389
240
|
return codes.join("\n");
|
|
390
241
|
}
|
|
391
242
|
|
|
243
|
+
// src/utils/transformers/createJSDocBlockText.ts
|
|
244
|
+
function createJSDocBlockText({ comments }) {
|
|
245
|
+
const filteredComments = comments.filter(Boolean);
|
|
246
|
+
if (!filteredComments.length) {
|
|
247
|
+
return "";
|
|
248
|
+
}
|
|
249
|
+
return `/**
|
|
250
|
+
* ${filteredComments.join("\n * ")}
|
|
251
|
+
*/`;
|
|
252
|
+
}
|
|
253
|
+
|
|
392
254
|
// src/utils/transformers/escape.ts
|
|
393
255
|
function escape(text) {
|
|
394
256
|
return text ? text.replaceAll("`", "\\`") : "";
|
|
@@ -414,6 +276,39 @@ function jsStringEscape(input) {
|
|
|
414
276
|
});
|
|
415
277
|
}
|
|
416
278
|
|
|
279
|
+
// src/utils/transformers/indent.ts
|
|
280
|
+
function createIndent(size) {
|
|
281
|
+
return Array.from({ length: size + 1 }).join(" ");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/utils/transformers/nameSorter.ts
|
|
285
|
+
function nameSorter(a, b) {
|
|
286
|
+
if (a.name < b.name) {
|
|
287
|
+
return -1;
|
|
288
|
+
}
|
|
289
|
+
if (a.name > b.name) {
|
|
290
|
+
return 1;
|
|
291
|
+
}
|
|
292
|
+
return 0;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// src/utils/transformers/searchAndReplace.ts
|
|
296
|
+
function searchAndReplace(options) {
|
|
297
|
+
const { text, replaceBy, prefix = "", key } = options;
|
|
298
|
+
const searchValues = options.searchValues?.(prefix, key) || [
|
|
299
|
+
`${prefix}["${key}"]`,
|
|
300
|
+
`${prefix}['${key}']`,
|
|
301
|
+
`${prefix}[\`${key}\`]`,
|
|
302
|
+
`${prefix}"${key}"`,
|
|
303
|
+
`${prefix}'${key}'`,
|
|
304
|
+
`${prefix}\`${key}\``,
|
|
305
|
+
new RegExp(`${prefix}${key}`, "g")
|
|
306
|
+
];
|
|
307
|
+
return searchValues.reduce((prev, searchValue) => {
|
|
308
|
+
return prev.toString().replaceAll(searchValue, replaceBy);
|
|
309
|
+
}, text);
|
|
310
|
+
}
|
|
311
|
+
|
|
417
312
|
// src/utils/transformers/transformReservedWord.ts
|
|
418
313
|
var reservedWords = [
|
|
419
314
|
"abstract",
|
|
@@ -506,6 +401,80 @@ function transformReservedWord(word) {
|
|
|
506
401
|
}
|
|
507
402
|
return word;
|
|
508
403
|
}
|
|
404
|
+
|
|
405
|
+
// src/utils/transformers/index.ts
|
|
406
|
+
var transformers = {
|
|
407
|
+
combineCodes,
|
|
408
|
+
escape,
|
|
409
|
+
jsStringEscape,
|
|
410
|
+
createIndent,
|
|
411
|
+
transformReservedWord,
|
|
412
|
+
nameSorter,
|
|
413
|
+
searchAndReplace,
|
|
414
|
+
JSDoc: {
|
|
415
|
+
createJSDocBlockText
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
async function saveCreateDirectory(path3) {
|
|
419
|
+
const passedPath = dirname(resolve(path3));
|
|
420
|
+
await fs2.mkdir(passedPath, { recursive: true });
|
|
421
|
+
}
|
|
422
|
+
var writer = switcher(
|
|
423
|
+
{
|
|
424
|
+
node: async (path3, data) => {
|
|
425
|
+
try {
|
|
426
|
+
await fs2.stat(resolve(path3));
|
|
427
|
+
const oldContent = await fs2.readFile(resolve(path3), { encoding: "utf-8" });
|
|
428
|
+
if (oldContent?.toString() === data?.toString()) {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
} catch (_err) {
|
|
432
|
+
}
|
|
433
|
+
await saveCreateDirectory(path3);
|
|
434
|
+
await fs2.writeFile(resolve(path3), data, { encoding: "utf-8" });
|
|
435
|
+
const savedData = await fs2.readFile(resolve(path3), { encoding: "utf-8" });
|
|
436
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
437
|
+
throw new Error(`Sanity check failed for ${path3}
|
|
438
|
+
|
|
439
|
+
Data[${data.length}]:
|
|
440
|
+
${data}
|
|
441
|
+
|
|
442
|
+
Saved[${savedData.length}]:
|
|
443
|
+
${savedData}
|
|
444
|
+
`);
|
|
445
|
+
}
|
|
446
|
+
return savedData;
|
|
447
|
+
},
|
|
448
|
+
bun: async (path3, data) => {
|
|
449
|
+
try {
|
|
450
|
+
await saveCreateDirectory(path3);
|
|
451
|
+
await Bun.write(resolve(path3), data);
|
|
452
|
+
const file = Bun.file(resolve(path3));
|
|
453
|
+
const savedData = await file.text();
|
|
454
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
455
|
+
throw new Error(`Sanity check failed for ${path3}
|
|
456
|
+
|
|
457
|
+
Data[${data.length}]:
|
|
458
|
+
${data}
|
|
459
|
+
|
|
460
|
+
Saved[${savedData.length}]:
|
|
461
|
+
${savedData}
|
|
462
|
+
`);
|
|
463
|
+
}
|
|
464
|
+
return savedData;
|
|
465
|
+
} catch (e) {
|
|
466
|
+
console.log(e, resolve(path3));
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
},
|
|
470
|
+
"node"
|
|
471
|
+
);
|
|
472
|
+
async function write(data, path3) {
|
|
473
|
+
if (data.trim() === "") {
|
|
474
|
+
return void 0;
|
|
475
|
+
}
|
|
476
|
+
return writer(path3, data.trim());
|
|
477
|
+
}
|
|
509
478
|
var TreeNode = class _TreeNode {
|
|
510
479
|
data;
|
|
511
480
|
parent;
|
|
@@ -570,16 +539,16 @@ var TreeNode = class _TreeNode {
|
|
|
570
539
|
}
|
|
571
540
|
return this;
|
|
572
541
|
}
|
|
573
|
-
static build(
|
|
542
|
+
static build(path3, options = {}) {
|
|
574
543
|
try {
|
|
575
544
|
const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
|
|
576
|
-
const filteredTree = dirTree(
|
|
545
|
+
const filteredTree = dirTree(path3, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
|
|
577
546
|
if (!filteredTree) {
|
|
578
547
|
return null;
|
|
579
548
|
}
|
|
580
|
-
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type ||
|
|
549
|
+
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || FileManager.getMode(filteredTree.path) });
|
|
581
550
|
const recurse = (node, item) => {
|
|
582
|
-
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type ||
|
|
551
|
+
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || FileManager.getMode(item.path) });
|
|
583
552
|
if (item.children?.length) {
|
|
584
553
|
item.children?.forEach((child) => {
|
|
585
554
|
recurse(subNode, child);
|
|
@@ -594,227 +563,271 @@ var TreeNode = class _TreeNode {
|
|
|
594
563
|
}
|
|
595
564
|
};
|
|
596
565
|
|
|
597
|
-
// src/
|
|
598
|
-
var
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
this.path = path;
|
|
566
|
+
// src/BarrelManager.ts
|
|
567
|
+
var BarrelManager = class {
|
|
568
|
+
#options = {};
|
|
569
|
+
constructor(options = {}) {
|
|
570
|
+
this.#options = options;
|
|
603
571
|
return this;
|
|
604
572
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
if (url?.href) {
|
|
616
|
-
return true;
|
|
573
|
+
getIndexes(root, extName) {
|
|
574
|
+
const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = this.#options;
|
|
575
|
+
const extMapper = {
|
|
576
|
+
".ts": {
|
|
577
|
+
extensions: /\.ts/,
|
|
578
|
+
exclude: [/schemas/, /json/]
|
|
579
|
+
},
|
|
580
|
+
".json": {
|
|
581
|
+
extensions: /\.json/,
|
|
582
|
+
exclude: []
|
|
617
583
|
}
|
|
618
|
-
}
|
|
619
|
-
|
|
584
|
+
};
|
|
585
|
+
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
|
|
586
|
+
if (!tree) {
|
|
587
|
+
return null;
|
|
620
588
|
}
|
|
621
|
-
|
|
589
|
+
const fileReducer = (files2, currentTree) => {
|
|
590
|
+
if (!currentTree.children) {
|
|
591
|
+
return [];
|
|
592
|
+
}
|
|
593
|
+
if (currentTree.children?.length > 1) {
|
|
594
|
+
const indexPath = path.resolve(currentTree.data.path, "index.ts");
|
|
595
|
+
const exports = currentTree.children.filter(Boolean).map((file) => {
|
|
596
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
597
|
+
if (importPath.includes("index") && indexPath.includes("index")) {
|
|
598
|
+
return void 0;
|
|
599
|
+
}
|
|
600
|
+
return {
|
|
601
|
+
path: includeExt ? file.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
|
|
602
|
+
isTypeOnly
|
|
603
|
+
};
|
|
604
|
+
}).filter(Boolean);
|
|
605
|
+
files2.push({
|
|
606
|
+
path: indexPath,
|
|
607
|
+
baseName: "index.ts",
|
|
608
|
+
source: "",
|
|
609
|
+
exports: output ? exports?.filter((item) => {
|
|
610
|
+
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
611
|
+
}) : exports
|
|
612
|
+
});
|
|
613
|
+
} else {
|
|
614
|
+
currentTree.children?.forEach((child) => {
|
|
615
|
+
const indexPath = path.resolve(currentTree.data.path, "index.ts");
|
|
616
|
+
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
617
|
+
const exports = [
|
|
618
|
+
{
|
|
619
|
+
path: includeExt ? child.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
|
|
620
|
+
isTypeOnly
|
|
621
|
+
}
|
|
622
|
+
];
|
|
623
|
+
files2.push({
|
|
624
|
+
path: indexPath,
|
|
625
|
+
baseName: "index.ts",
|
|
626
|
+
source: "",
|
|
627
|
+
exports: output ? exports?.filter((item) => {
|
|
628
|
+
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
629
|
+
}) : exports
|
|
630
|
+
});
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
currentTree.children.forEach((childItem) => {
|
|
634
|
+
fileReducer(files2, childItem);
|
|
635
|
+
});
|
|
636
|
+
return files2;
|
|
637
|
+
};
|
|
638
|
+
const files = fileReducer([], tree).reverse();
|
|
639
|
+
const filteredFiles = filter ? files.filter(filter) : files;
|
|
640
|
+
return map ? filteredFiles.map(map) : filteredFiles;
|
|
622
641
|
}
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
// src/FileManager.ts
|
|
645
|
+
var FileManager = class _FileManager {
|
|
646
|
+
#cache = /* @__PURE__ */ new Map();
|
|
647
|
+
#task;
|
|
648
|
+
#isWriting = false;
|
|
623
649
|
/**
|
|
624
|
-
*
|
|
625
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
626
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
627
|
-
* @example /account/userID => `/account/${userId}`
|
|
650
|
+
* Timeout between writes
|
|
628
651
|
*/
|
|
629
|
-
|
|
630
|
-
|
|
652
|
+
#timeout = 0;
|
|
653
|
+
#queue;
|
|
654
|
+
constructor(options) {
|
|
655
|
+
if (options) {
|
|
656
|
+
this.#task = options.task;
|
|
657
|
+
this.#queue = options.queue;
|
|
658
|
+
this.#timeout = options.timeout || 0;
|
|
659
|
+
}
|
|
660
|
+
return this;
|
|
631
661
|
}
|
|
632
|
-
get
|
|
633
|
-
|
|
662
|
+
get files() {
|
|
663
|
+
const files = [];
|
|
664
|
+
this.#cache.forEach((item) => {
|
|
665
|
+
files.push(...item.flat(1));
|
|
666
|
+
});
|
|
667
|
+
return files;
|
|
634
668
|
}
|
|
635
|
-
get
|
|
636
|
-
return this
|
|
669
|
+
get isExecuting() {
|
|
670
|
+
return this.#queue?.hasJobs ?? this.#isWriting ?? false;
|
|
637
671
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
672
|
+
#validate(file) {
|
|
673
|
+
if (!file.validate) {
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
|
|
677
|
+
throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
async add(...files) {
|
|
681
|
+
const promises = files.map((file) => {
|
|
682
|
+
this.#validate(file);
|
|
683
|
+
if (file.override) {
|
|
684
|
+
return this.#add(file);
|
|
646
685
|
}
|
|
647
|
-
return
|
|
686
|
+
return this.#addOrAppend(file);
|
|
687
|
+
});
|
|
688
|
+
const resolvedFiles = await Promise.all(promises);
|
|
689
|
+
if (files.length > 1) {
|
|
690
|
+
return resolvedFiles;
|
|
648
691
|
}
|
|
649
|
-
return
|
|
692
|
+
return resolvedFiles[0];
|
|
650
693
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
newPath = found.reduce((prev, curr) => {
|
|
663
|
-
const pathParam = replacer ? replacer(camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge })) : camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge });
|
|
664
|
-
const replacement = `\${${pathParam}}`;
|
|
665
|
-
return prev.replace(curr, replacement);
|
|
666
|
-
}, this.path);
|
|
694
|
+
async #add(file) {
|
|
695
|
+
const controller = new AbortController();
|
|
696
|
+
const resolvedFile = { id: crypto2.randomUUID(), ...file };
|
|
697
|
+
this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
698
|
+
if (this.#queue) {
|
|
699
|
+
await this.#queue.run(
|
|
700
|
+
async () => {
|
|
701
|
+
return this.#task?.(resolvedFile);
|
|
702
|
+
},
|
|
703
|
+
{ controller }
|
|
704
|
+
);
|
|
667
705
|
}
|
|
668
|
-
return
|
|
706
|
+
return resolvedFile;
|
|
669
707
|
}
|
|
670
|
-
|
|
671
|
-
const
|
|
672
|
-
const
|
|
673
|
-
if (
|
|
708
|
+
async #addOrAppend(file) {
|
|
709
|
+
const previousCaches = this.#cache.get(file.path);
|
|
710
|
+
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
711
|
+
if (previousCache) {
|
|
712
|
+
this.#cache.delete(previousCache.path);
|
|
713
|
+
return this.#add({
|
|
714
|
+
...file,
|
|
715
|
+
source: previousCache.source && file.source ? `${previousCache.source}
|
|
716
|
+
${file.source}` : "",
|
|
717
|
+
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
718
|
+
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
719
|
+
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
return this.#add(file);
|
|
723
|
+
}
|
|
724
|
+
async addIndexes({ root, extName = ".ts", meta, options = {} }) {
|
|
725
|
+
const barrelManager = new BarrelManager(options);
|
|
726
|
+
const files = barrelManager.getIndexes(root, extName);
|
|
727
|
+
if (!files) {
|
|
674
728
|
return void 0;
|
|
675
729
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
730
|
+
return await Promise.all(
|
|
731
|
+
files.map((file) => {
|
|
732
|
+
return this.#addOrAppend({
|
|
733
|
+
...file,
|
|
734
|
+
meta: meta ? meta : file.meta
|
|
735
|
+
});
|
|
736
|
+
})
|
|
737
|
+
);
|
|
683
738
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
return
|
|
739
|
+
getCacheByUUID(UUID) {
|
|
740
|
+
let cache;
|
|
741
|
+
this.#cache.forEach((files) => {
|
|
742
|
+
cache = files.find((item) => item.id === UUID);
|
|
743
|
+
});
|
|
744
|
+
return cache;
|
|
690
745
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
// src/utils/Warning.ts
|
|
694
|
-
var Warning = class extends Error {
|
|
695
|
-
constructor(message, options) {
|
|
696
|
-
super(message, { cause: options?.cause });
|
|
697
|
-
this.name = "Warning";
|
|
746
|
+
get(path3) {
|
|
747
|
+
return this.#cache.get(path3);
|
|
698
748
|
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
}
|
|
704
|
-
var writer = switcher(
|
|
705
|
-
{
|
|
706
|
-
node: async (path, data) => {
|
|
707
|
-
try {
|
|
708
|
-
await fs2.stat(path);
|
|
709
|
-
const oldContent = await fs2.readFile(path, { encoding: "utf-8" });
|
|
710
|
-
if (oldContent?.toString() === data) {
|
|
711
|
-
return;
|
|
712
|
-
}
|
|
713
|
-
} catch (_err) {
|
|
714
|
-
}
|
|
715
|
-
await saveCreateDirectory(path);
|
|
716
|
-
return fs2.writeFile(pathParser.resolve(path), data, { encoding: "utf-8" });
|
|
717
|
-
},
|
|
718
|
-
bun: async (path, data) => {
|
|
719
|
-
try {
|
|
720
|
-
await saveCreateDirectory(path);
|
|
721
|
-
await Bun.write(pathParser.resolve(path), data);
|
|
722
|
-
} catch (e) {
|
|
723
|
-
console.log(e, pathParser.resolve(path));
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
},
|
|
727
|
-
"node"
|
|
728
|
-
);
|
|
729
|
-
async function write(data, path) {
|
|
730
|
-
return writer(path, data);
|
|
731
|
-
}
|
|
732
|
-
function getIndexes(root, extName, options = {}) {
|
|
733
|
-
const extMapper = {
|
|
734
|
-
".ts": {
|
|
735
|
-
extensions: /\.ts/,
|
|
736
|
-
exclude: [/schemas/, /json/]
|
|
737
|
-
},
|
|
738
|
-
".json": {
|
|
739
|
-
extensions: /\.json/,
|
|
740
|
-
exclude: []
|
|
749
|
+
remove(path3) {
|
|
750
|
+
const cacheItem = this.get(path3);
|
|
751
|
+
if (!cacheItem) {
|
|
752
|
+
return;
|
|
741
753
|
}
|
|
742
|
-
|
|
743
|
-
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...options });
|
|
744
|
-
if (!tree) {
|
|
745
|
-
return null;
|
|
754
|
+
this.#cache.delete(path3);
|
|
746
755
|
}
|
|
747
|
-
|
|
748
|
-
if (!
|
|
749
|
-
|
|
756
|
+
async write(...params) {
|
|
757
|
+
if (!this.#isWriting) {
|
|
758
|
+
this.#isWriting = true;
|
|
759
|
+
const text = await write(...params);
|
|
760
|
+
this.#isWriting = false;
|
|
761
|
+
return text;
|
|
750
762
|
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
return { path: importPath };
|
|
762
|
-
}).filter(Boolean);
|
|
763
|
-
files2.push({
|
|
764
|
-
path,
|
|
765
|
-
baseName: "index.ts",
|
|
766
|
-
source: "",
|
|
767
|
-
exports
|
|
768
|
-
});
|
|
769
|
-
} else {
|
|
770
|
-
currentTree.children?.forEach((child) => {
|
|
771
|
-
const path = pathParser.resolve(currentTree.data.path, "index.ts");
|
|
772
|
-
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
773
|
-
files2.push({
|
|
774
|
-
path,
|
|
775
|
-
baseName: "index.ts",
|
|
776
|
-
source: "",
|
|
777
|
-
exports: [{ path: importPath }]
|
|
778
|
-
});
|
|
779
|
-
});
|
|
763
|
+
await timeout(this.#timeout);
|
|
764
|
+
return this.write(...params);
|
|
765
|
+
}
|
|
766
|
+
async read(...params) {
|
|
767
|
+
return read(...params);
|
|
768
|
+
}
|
|
769
|
+
// statics
|
|
770
|
+
static getSource(file) {
|
|
771
|
+
if (!_FileManager.isExtensionAllowed(file.baseName)) {
|
|
772
|
+
return file.source;
|
|
780
773
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
774
|
+
const exports = file.exports ? combineExports(file.exports) : [];
|
|
775
|
+
const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
|
|
776
|
+
const importNodes = imports.map((item) => factory.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
777
|
+
const exportNodes = exports.map(
|
|
778
|
+
(item) => factory.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias })
|
|
779
|
+
);
|
|
780
|
+
return [print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
781
|
+
}
|
|
782
|
+
static combineFiles(files) {
|
|
783
|
+
return files.filter(Boolean).reduce((acc, file) => {
|
|
784
|
+
const prevIndex = acc.findIndex((item) => item.path === file.path);
|
|
785
|
+
if (prevIndex === -1) {
|
|
786
|
+
return [...acc, file];
|
|
787
|
+
}
|
|
793
788
|
const prev = acc[prevIndex];
|
|
789
|
+
if (prev && file.override) {
|
|
790
|
+
acc[prevIndex] = {
|
|
791
|
+
imports: [],
|
|
792
|
+
exports: [],
|
|
793
|
+
...file
|
|
794
|
+
};
|
|
795
|
+
return acc;
|
|
796
|
+
}
|
|
794
797
|
if (prev) {
|
|
795
798
|
acc[prevIndex] = {
|
|
796
|
-
...
|
|
797
|
-
source: prev.source &&
|
|
798
|
-
${
|
|
799
|
-
imports: [...prev.imports || [], ...
|
|
800
|
-
exports: [...prev.exports || [], ...
|
|
801
|
-
env: { ...prev.env || {}, ...
|
|
799
|
+
...file,
|
|
800
|
+
source: prev.source && file.source ? `${prev.source}
|
|
801
|
+
${file.source}` : "",
|
|
802
|
+
imports: [...prev.imports || [], ...file.imports || []],
|
|
803
|
+
exports: [...prev.exports || [], ...file.exports || []],
|
|
804
|
+
env: { ...prev.env || {}, ...file.env || {} }
|
|
802
805
|
};
|
|
803
806
|
}
|
|
804
|
-
|
|
805
|
-
|
|
807
|
+
return acc;
|
|
808
|
+
}, []);
|
|
809
|
+
}
|
|
810
|
+
static getMode(path3) {
|
|
811
|
+
if (!path3) {
|
|
812
|
+
return "directory";
|
|
806
813
|
}
|
|
807
|
-
return
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
+
return extname(path3) ? "file" : "directory";
|
|
815
|
+
}
|
|
816
|
+
static get extensions() {
|
|
817
|
+
return [".js", ".ts", ".tsx"];
|
|
818
|
+
}
|
|
819
|
+
static isExtensionAllowed(baseName) {
|
|
820
|
+
return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
|
|
821
|
+
}
|
|
822
|
+
};
|
|
814
823
|
function combineExports(exports) {
|
|
815
|
-
|
|
824
|
+
const combinedExports = orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
816
825
|
const name = curr.name;
|
|
817
826
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
827
|
+
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly);
|
|
828
|
+
if (prevByPathAndIsTypeOnly) {
|
|
829
|
+
return prev;
|
|
830
|
+
}
|
|
818
831
|
const uniquePrev = prev.findLast(
|
|
819
832
|
(imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
820
833
|
);
|
|
@@ -836,12 +849,16 @@ function combineExports(exports) {
|
|
|
836
849
|
}
|
|
837
850
|
return [...prev, curr];
|
|
838
851
|
}, []);
|
|
852
|
+
return orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
839
853
|
}
|
|
840
854
|
function combineImports(imports, exports, source) {
|
|
841
|
-
|
|
855
|
+
const combinedImports = orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
842
856
|
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
843
857
|
const hasImportInSource = (importName) => {
|
|
844
|
-
|
|
858
|
+
if (!source) {
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
const checker = (name2) => name2 && !!source.includes(name2);
|
|
845
862
|
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
846
863
|
};
|
|
847
864
|
if (Array.isArray(name)) {
|
|
@@ -849,6 +866,10 @@ function combineImports(imports, exports, source) {
|
|
|
849
866
|
}
|
|
850
867
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
851
868
|
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
869
|
+
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly);
|
|
870
|
+
if (prevByPathNameAndIsTypeOnly) {
|
|
871
|
+
return prev;
|
|
872
|
+
}
|
|
852
873
|
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
853
874
|
return prev;
|
|
854
875
|
}
|
|
@@ -870,43 +891,7 @@ function combineImports(imports, exports, source) {
|
|
|
870
891
|
}
|
|
871
892
|
return [...prev, curr];
|
|
872
893
|
}, []);
|
|
873
|
-
|
|
874
|
-
function createFileSource(file) {
|
|
875
|
-
let { source } = file;
|
|
876
|
-
if (!isExtensionAllowed(file.baseName)) {
|
|
877
|
-
return file.source;
|
|
878
|
-
}
|
|
879
|
-
const exports = file.exports ? combineExports(file.exports) : [];
|
|
880
|
-
const imports = file.imports ? combineImports(file.imports, exports, source) : [];
|
|
881
|
-
const importNodes = imports.map((item) => createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
882
|
-
const importSource = print(importNodes);
|
|
883
|
-
const exportNodes = exports.map((item) => createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias }));
|
|
884
|
-
const exportSource = print(exportNodes);
|
|
885
|
-
source = getEnvSource(file.source, file.env);
|
|
886
|
-
if (importSource) {
|
|
887
|
-
source = `${importSource}
|
|
888
|
-
${source}`;
|
|
889
|
-
}
|
|
890
|
-
if (exportSource) {
|
|
891
|
-
source = `${exportSource}
|
|
892
|
-
${source}`;
|
|
893
|
-
}
|
|
894
|
-
return source;
|
|
895
|
-
}
|
|
896
|
-
function searchAndReplace(options) {
|
|
897
|
-
const { text, replaceBy, prefix = "", key } = options;
|
|
898
|
-
const searchValues = options.searchValues?.(prefix, key) || [
|
|
899
|
-
`${prefix}["${key}"]`,
|
|
900
|
-
`${prefix}['${key}']`,
|
|
901
|
-
`${prefix}[\`${key}\`]`,
|
|
902
|
-
`${prefix}"${key}"`,
|
|
903
|
-
`${prefix}'${key}'`,
|
|
904
|
-
`${prefix}\`${key}\``,
|
|
905
|
-
new RegExp(`${prefix}${key}`, "g")
|
|
906
|
-
];
|
|
907
|
-
return searchValues.reduce((prev, searchValue) => {
|
|
908
|
-
return prev.toString().replaceAll(searchValue, replaceBy);
|
|
909
|
-
}, text);
|
|
894
|
+
return orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
|
|
910
895
|
}
|
|
911
896
|
function getEnvSource(source, env) {
|
|
912
897
|
if (!env) {
|
|
@@ -923,127 +908,117 @@ function getEnvSource(source, env) {
|
|
|
923
908
|
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
924
909
|
}
|
|
925
910
|
if (typeof replaceBy === "string") {
|
|
926
|
-
prev = searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
927
|
-
prev = searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
911
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
912
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
928
913
|
`, "ig"), ""), replaceBy, key });
|
|
929
914
|
}
|
|
930
915
|
return prev;
|
|
931
916
|
}, source);
|
|
932
917
|
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
#cache = /* @__PURE__ */ new Map();
|
|
937
|
-
#task;
|
|
938
|
-
#queue;
|
|
939
|
-
constructor(options) {
|
|
940
|
-
if (options) {
|
|
941
|
-
this.#task = options.task;
|
|
942
|
-
this.#queue = options.queue;
|
|
943
|
-
}
|
|
944
|
-
return this;
|
|
945
|
-
}
|
|
946
|
-
get extensions() {
|
|
947
|
-
return extensions;
|
|
918
|
+
var EventEmitter = class {
|
|
919
|
+
constructor() {
|
|
920
|
+
this.#emitter.setMaxListeners(100);
|
|
948
921
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
this.#
|
|
952
|
-
files.push(...item.flat(1));
|
|
953
|
-
});
|
|
954
|
-
return files;
|
|
922
|
+
#emitter = new EventEmitter$1();
|
|
923
|
+
emit(eventName, ...eventArg) {
|
|
924
|
+
this.#emitter.emit(eventName, ...eventArg);
|
|
955
925
|
}
|
|
956
|
-
|
|
957
|
-
|
|
926
|
+
on(eventName, handler) {
|
|
927
|
+
this.#emitter.on(eventName, handler);
|
|
958
928
|
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
const resolvedFile = { id: crypto.randomUUID(), ...file };
|
|
962
|
-
this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
963
|
-
if (this.#queue) {
|
|
964
|
-
try {
|
|
965
|
-
await this.#queue.run(
|
|
966
|
-
async () => {
|
|
967
|
-
return this.#task?.(resolvedFile);
|
|
968
|
-
},
|
|
969
|
-
{ controller }
|
|
970
|
-
);
|
|
971
|
-
} catch {
|
|
972
|
-
return resolvedFile;
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
return resolvedFile;
|
|
929
|
+
off(eventName, handler) {
|
|
930
|
+
this.#emitter.off(eventName, handler);
|
|
976
931
|
}
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
980
|
-
if (previousCache) {
|
|
981
|
-
this.#cache.delete(previousCache.path);
|
|
982
|
-
return this.add({
|
|
983
|
-
...file,
|
|
984
|
-
source: previousCache.source && file.source ? `${previousCache.source}
|
|
985
|
-
${file.source}` : "",
|
|
986
|
-
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
987
|
-
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
988
|
-
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
return this.add(file);
|
|
932
|
+
removeAll() {
|
|
933
|
+
this.#emitter.removeAllListeners();
|
|
992
934
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
return this.addOrAppend(file);
|
|
1004
|
-
})
|
|
1005
|
-
);
|
|
935
|
+
};
|
|
936
|
+
var Queue = class {
|
|
937
|
+
#queue = [];
|
|
938
|
+
eventEmitter = new EventEmitter();
|
|
939
|
+
#workerCount = 0;
|
|
940
|
+
#maxParallel;
|
|
941
|
+
#debug = false;
|
|
942
|
+
constructor(maxParallel, debug = false) {
|
|
943
|
+
this.#maxParallel = maxParallel;
|
|
944
|
+
this.#debug = debug;
|
|
1006
945
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
946
|
+
run(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
|
|
947
|
+
return new Promise((resolve2, reject) => {
|
|
948
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
949
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
950
|
+
this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
|
|
951
|
+
reject("Aborted");
|
|
952
|
+
});
|
|
953
|
+
this.#queue.push(item);
|
|
954
|
+
this.#work();
|
|
955
|
+
});
|
|
1010
956
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
957
|
+
runSync(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
|
|
958
|
+
new Promise((resolve2, reject) => {
|
|
959
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
960
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
961
|
+
this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
|
|
962
|
+
});
|
|
963
|
+
this.#queue.push(item);
|
|
964
|
+
this.#work();
|
|
1015
965
|
});
|
|
1016
|
-
return cache;
|
|
1017
966
|
}
|
|
1018
|
-
get(
|
|
1019
|
-
return this.#
|
|
967
|
+
get hasJobs() {
|
|
968
|
+
return this.#workerCount > 0 || this.#queue.length > 0;
|
|
1020
969
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
if (!cacheItem) {
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
this.#cache.delete(path);
|
|
970
|
+
get count() {
|
|
971
|
+
return this.#workerCount;
|
|
1027
972
|
}
|
|
1028
|
-
|
|
1029
|
-
if (this.#
|
|
1030
|
-
return
|
|
1031
|
-
return write(...params);
|
|
1032
|
-
});
|
|
973
|
+
#work() {
|
|
974
|
+
if (this.#workerCount >= this.#maxParallel) {
|
|
975
|
+
return;
|
|
1033
976
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
977
|
+
this.#workerCount++;
|
|
978
|
+
let entry;
|
|
979
|
+
while (entry = this.#queue.shift()) {
|
|
980
|
+
const { reject, resolve: resolve2, job, name, description } = entry;
|
|
981
|
+
if (this.#debug) {
|
|
982
|
+
performance.mark(name + "_start");
|
|
983
|
+
}
|
|
984
|
+
job().then((result) => {
|
|
985
|
+
this.eventEmitter.emit("jobDone", result);
|
|
986
|
+
resolve2(result);
|
|
987
|
+
if (this.#debug) {
|
|
988
|
+
performance.mark(name + "_stop");
|
|
989
|
+
performance.measure(description, name + "_start", name + "_stop");
|
|
990
|
+
}
|
|
991
|
+
}).catch((err) => {
|
|
992
|
+
this.eventEmitter.emit("jobFailed", err);
|
|
993
|
+
reject(err);
|
|
1040
994
|
});
|
|
1041
995
|
}
|
|
1042
|
-
|
|
996
|
+
this.#workerCount--;
|
|
1043
997
|
}
|
|
1044
998
|
};
|
|
1045
999
|
|
|
1046
|
-
// src/
|
|
1000
|
+
// src/utils/uniqueName.ts
|
|
1001
|
+
function setUniqueName(originalName, data) {
|
|
1002
|
+
let used = data[originalName] || 0;
|
|
1003
|
+
if (used) {
|
|
1004
|
+
data[originalName] = ++used;
|
|
1005
|
+
return originalName;
|
|
1006
|
+
}
|
|
1007
|
+
data[originalName] = 1;
|
|
1008
|
+
return originalName;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// src/errors.ts
|
|
1012
|
+
var PluginError = class extends Error {
|
|
1013
|
+
pluginManager;
|
|
1014
|
+
cause;
|
|
1015
|
+
constructor(message, options) {
|
|
1016
|
+
super(message, { cause: options.cause });
|
|
1017
|
+
this.name = "PluginError";
|
|
1018
|
+
this.cause = options.cause;
|
|
1019
|
+
this.pluginManager = options.pluginManager;
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1047
1022
|
var ParallelPluginError = class extends Error {
|
|
1048
1023
|
errors = [];
|
|
1049
1024
|
pluginManager;
|
|
@@ -1068,30 +1043,55 @@ var ParallelPluginError = class extends Error {
|
|
|
1068
1043
|
})?.cause;
|
|
1069
1044
|
}
|
|
1070
1045
|
};
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
var PluginError = class extends Error {
|
|
1074
|
-
pluginManager;
|
|
1075
|
-
cause;
|
|
1046
|
+
var SummaryError = class extends Error {
|
|
1047
|
+
summary;
|
|
1076
1048
|
constructor(message, options) {
|
|
1077
1049
|
super(message, { cause: options.cause });
|
|
1078
|
-
this.name = "
|
|
1079
|
-
this.
|
|
1080
|
-
this.pluginManager = options.pluginManager;
|
|
1050
|
+
this.name = "SummaryError";
|
|
1051
|
+
this.summary = options.summary || [];
|
|
1081
1052
|
}
|
|
1082
1053
|
};
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1054
|
+
var Warning = class extends Error {
|
|
1055
|
+
constructor(message, options) {
|
|
1056
|
+
super(message, { cause: options?.cause });
|
|
1057
|
+
this.name = "Warning";
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
var ValidationPluginError = class extends Error {
|
|
1061
|
+
};
|
|
1062
|
+
|
|
1063
|
+
// src/utils/cache.ts
|
|
1064
|
+
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
1065
|
+
return {
|
|
1066
|
+
set(id, value) {
|
|
1067
|
+
Store[id] = [0, value];
|
|
1068
|
+
},
|
|
1069
|
+
get(id) {
|
|
1070
|
+
const item = Store[id];
|
|
1071
|
+
if (!item) {
|
|
1072
|
+
return null;
|
|
1073
|
+
}
|
|
1074
|
+
item[0] = 0;
|
|
1075
|
+
return item[1];
|
|
1076
|
+
},
|
|
1077
|
+
has(id) {
|
|
1078
|
+
const item = Store[id];
|
|
1079
|
+
if (!item) {
|
|
1080
|
+
return false;
|
|
1081
|
+
}
|
|
1082
|
+
item[0] = 0;
|
|
1083
|
+
return true;
|
|
1084
|
+
},
|
|
1085
|
+
delete(id) {
|
|
1086
|
+
return delete Store[id];
|
|
1093
1087
|
}
|
|
1094
|
-
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
// src/plugin.ts
|
|
1092
|
+
function createPlugin(factory2) {
|
|
1093
|
+
return (options) => {
|
|
1094
|
+
return factory2(options);
|
|
1095
1095
|
};
|
|
1096
1096
|
}
|
|
1097
1097
|
var pluginName = "core";
|
|
@@ -1100,6 +1100,8 @@ var definePlugin = createPlugin((options) => {
|
|
|
1100
1100
|
return {
|
|
1101
1101
|
name: pluginName,
|
|
1102
1102
|
options,
|
|
1103
|
+
key: ["controller", "core"],
|
|
1104
|
+
kind: "controller",
|
|
1103
1105
|
api() {
|
|
1104
1106
|
return {
|
|
1105
1107
|
get config() {
|
|
@@ -1108,18 +1110,18 @@ var definePlugin = createPlugin((options) => {
|
|
|
1108
1110
|
get plugins() {
|
|
1109
1111
|
return options.getPlugins();
|
|
1110
1112
|
},
|
|
1113
|
+
get plugin() {
|
|
1114
|
+
return options.plugin;
|
|
1115
|
+
},
|
|
1111
1116
|
logger,
|
|
1112
1117
|
fileManager,
|
|
1113
1118
|
pluginManager,
|
|
1114
1119
|
async addFile(...files) {
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
return fileManager.addOrAppend(file);
|
|
1121
|
-
})
|
|
1122
|
-
);
|
|
1120
|
+
const resolvedFiles = await fileManager.add(...files);
|
|
1121
|
+
if (!Array.isArray(resolvedFiles)) {
|
|
1122
|
+
return [resolvedFiles];
|
|
1123
|
+
}
|
|
1124
|
+
return resolvedFiles;
|
|
1123
1125
|
},
|
|
1124
1126
|
resolvePath,
|
|
1125
1127
|
resolveName,
|
|
@@ -1127,63 +1129,58 @@ var definePlugin = createPlugin((options) => {
|
|
|
1127
1129
|
};
|
|
1128
1130
|
},
|
|
1129
1131
|
resolvePath(baseName) {
|
|
1130
|
-
const root =
|
|
1131
|
-
return
|
|
1132
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
1133
|
+
return path.resolve(root, baseName);
|
|
1132
1134
|
},
|
|
1133
1135
|
resolveName(name) {
|
|
1134
1136
|
return name;
|
|
1135
1137
|
}
|
|
1136
1138
|
};
|
|
1137
1139
|
});
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1140
|
+
|
|
1141
|
+
// src/utils/executeStrategies.ts
|
|
1142
|
+
function hookSeq(promises) {
|
|
1143
|
+
return promises.reduce(
|
|
1144
|
+
(promise, func) => {
|
|
1145
|
+
if (!func || typeof func !== "function") {
|
|
1146
|
+
throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
1147
|
+
}
|
|
1148
|
+
return promise.then((result) => {
|
|
1149
|
+
const calledFunc = func();
|
|
1150
|
+
if (calledFunc) {
|
|
1151
|
+
return calledFunc.then(Array.prototype.concat.bind(result));
|
|
1152
|
+
}
|
|
1153
|
+
});
|
|
1154
|
+
},
|
|
1155
|
+
Promise.resolve([])
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
// src/PromiseManager.ts
|
|
1160
|
+
var PromiseManager = class {
|
|
1161
|
+
#options = {};
|
|
1162
|
+
constructor(options = {}) {
|
|
1163
|
+
this.#options = options;
|
|
1164
|
+
return this;
|
|
1151
1165
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1166
|
+
run(strategy, promises) {
|
|
1167
|
+
if (strategy === "seq") {
|
|
1168
|
+
return hookSeq(promises);
|
|
1169
|
+
}
|
|
1170
|
+
throw new Error(`${strategy} not implemented`);
|
|
1154
1171
|
}
|
|
1155
1172
|
};
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
function
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
...plugin,
|
|
1165
|
-
key,
|
|
1166
|
-
api
|
|
1167
|
-
};
|
|
1168
|
-
}
|
|
1169
|
-
return {
|
|
1170
|
-
...plugin,
|
|
1171
|
-
key
|
|
1172
|
-
};
|
|
1173
|
+
function isPromise(result) {
|
|
1174
|
+
return !!result && typeof result?.then === "function";
|
|
1175
|
+
}
|
|
1176
|
+
function isPromiseFulfilledResult(result) {
|
|
1177
|
+
return result.status === "fulfilled";
|
|
1178
|
+
}
|
|
1179
|
+
function isPromiseRejectedResult(result) {
|
|
1180
|
+
return result.status === "rejected";
|
|
1173
1181
|
}
|
|
1174
1182
|
|
|
1175
|
-
// src/
|
|
1176
|
-
var hookNames = {
|
|
1177
|
-
validate: 1,
|
|
1178
|
-
buildStart: 1,
|
|
1179
|
-
resolvePath: 1,
|
|
1180
|
-
resolveName: 1,
|
|
1181
|
-
load: 1,
|
|
1182
|
-
transform: 1,
|
|
1183
|
-
writeFile: 1,
|
|
1184
|
-
buildEnd: 1
|
|
1185
|
-
};
|
|
1186
|
-
var hooks = Object.keys(hookNames);
|
|
1183
|
+
// src/PluginManager.ts
|
|
1187
1184
|
var PluginManager = class {
|
|
1188
1185
|
plugins;
|
|
1189
1186
|
fileManager;
|
|
@@ -1192,10 +1189,14 @@ var PluginManager = class {
|
|
|
1192
1189
|
executed = [];
|
|
1193
1190
|
logger;
|
|
1194
1191
|
#core;
|
|
1192
|
+
#usedPluginNames = {};
|
|
1193
|
+
#promiseManager;
|
|
1195
1194
|
constructor(config, options) {
|
|
1196
1195
|
this.logger = options.logger;
|
|
1197
|
-
this.queue = new Queue(100,
|
|
1198
|
-
this.fileManager = new FileManager({ task: options.task, queue: this.queue });
|
|
1196
|
+
this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
|
|
1197
|
+
this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
|
|
1198
|
+
this.#promiseManager = new PromiseManager();
|
|
1199
|
+
const plugins = config.plugins || [];
|
|
1199
1200
|
const core = definePlugin({
|
|
1200
1201
|
config,
|
|
1201
1202
|
logger: this.logger,
|
|
@@ -1203,23 +1204,29 @@ var PluginManager = class {
|
|
|
1203
1204
|
fileManager: this.fileManager,
|
|
1204
1205
|
resolvePath: this.resolvePath.bind(this),
|
|
1205
1206
|
resolveName: this.resolveName.bind(this),
|
|
1206
|
-
getPlugins: this.#getSortedPlugins.bind(this)
|
|
1207
|
-
|
|
1207
|
+
getPlugins: this.#getSortedPlugins.bind(this)
|
|
1208
|
+
});
|
|
1209
|
+
this.#core = this.#parse(core, this, core.api.call(null));
|
|
1210
|
+
this.plugins = [this.#core, ...plugins].map((plugin) => {
|
|
1211
|
+
return this.#parse(plugin, this, this.#core.api);
|
|
1208
1212
|
});
|
|
1209
|
-
this.#core = pluginParser(core, core.api.call(null));
|
|
1210
|
-
this.plugins = [this.#core, ...config.plugins || []].reduce((prev, plugin) => {
|
|
1211
|
-
const convertedApi = pluginParser(plugin, this.#core?.api);
|
|
1212
|
-
return [...prev, convertedApi];
|
|
1213
|
-
}, []);
|
|
1214
1213
|
return this;
|
|
1215
1214
|
}
|
|
1216
1215
|
resolvePath = (params) => {
|
|
1217
|
-
if (params.
|
|
1218
|
-
|
|
1219
|
-
|
|
1216
|
+
if (params.pluginKey) {
|
|
1217
|
+
const paths = this.hookForPluginSync({
|
|
1218
|
+
pluginKey: params.pluginKey,
|
|
1220
1219
|
hookName: "resolvePath",
|
|
1221
1220
|
parameters: [params.baseName, params.directory, params.options]
|
|
1222
1221
|
});
|
|
1222
|
+
if (paths && paths?.length > 1) {
|
|
1223
|
+
throw new Error(
|
|
1224
|
+
`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1225
|
+
|
|
1226
|
+
Paths: ${JSON.stringify(paths, void 0, 2)}`
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
return paths?.at(0);
|
|
1223
1230
|
}
|
|
1224
1231
|
return this.hookFirstSync({
|
|
1225
1232
|
hookName: "resolvePath",
|
|
@@ -1227,13 +1234,20 @@ var PluginManager = class {
|
|
|
1227
1234
|
}).result;
|
|
1228
1235
|
};
|
|
1229
1236
|
resolveName = (params) => {
|
|
1230
|
-
if (params.
|
|
1231
|
-
const
|
|
1232
|
-
|
|
1237
|
+
if (params.pluginKey) {
|
|
1238
|
+
const names = this.hookForPluginSync({
|
|
1239
|
+
pluginKey: params.pluginKey,
|
|
1233
1240
|
hookName: "resolveName",
|
|
1234
1241
|
parameters: [params.name, params.type]
|
|
1235
1242
|
});
|
|
1236
|
-
|
|
1243
|
+
if (names && names?.length > 1) {
|
|
1244
|
+
throw new Error(
|
|
1245
|
+
`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1246
|
+
|
|
1247
|
+
Names: ${JSON.stringify(names, void 0, 2)}`
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
return transformReservedWord(names?.at(0) || params.name);
|
|
1237
1251
|
}
|
|
1238
1252
|
const name = this.hookFirstSync({
|
|
1239
1253
|
hookName: "resolveName",
|
|
@@ -1248,30 +1262,35 @@ var PluginManager = class {
|
|
|
1248
1262
|
* Run only hook for a specific plugin name
|
|
1249
1263
|
*/
|
|
1250
1264
|
hookForPlugin({
|
|
1251
|
-
|
|
1265
|
+
pluginKey,
|
|
1252
1266
|
hookName,
|
|
1253
1267
|
parameters
|
|
1254
1268
|
}) {
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1269
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1270
|
+
const promises = plugins.map((plugin) => {
|
|
1271
|
+
return this.#execute({
|
|
1272
|
+
strategy: "hookFirst",
|
|
1273
|
+
hookName,
|
|
1274
|
+
parameters,
|
|
1275
|
+
plugin
|
|
1276
|
+
});
|
|
1277
|
+
}).filter(Boolean);
|
|
1278
|
+
return Promise.all(promises);
|
|
1262
1279
|
}
|
|
1263
1280
|
hookForPluginSync({
|
|
1264
|
-
|
|
1281
|
+
pluginKey,
|
|
1265
1282
|
hookName,
|
|
1266
1283
|
parameters
|
|
1267
1284
|
}) {
|
|
1268
|
-
const
|
|
1269
|
-
return
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1285
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1286
|
+
return plugins.map((plugin) => {
|
|
1287
|
+
return this.#executeSync({
|
|
1288
|
+
strategy: "hookFirst",
|
|
1289
|
+
hookName,
|
|
1290
|
+
parameters,
|
|
1291
|
+
plugin
|
|
1292
|
+
});
|
|
1293
|
+
}).filter(Boolean);
|
|
1275
1294
|
}
|
|
1276
1295
|
/**
|
|
1277
1296
|
* Chains, first non-null result stops and returns
|
|
@@ -1387,37 +1406,58 @@ var PluginManager = class {
|
|
|
1387
1406
|
* Chains plugins
|
|
1388
1407
|
*/
|
|
1389
1408
|
hookSeq({ hookName, parameters }) {
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
parameters,
|
|
1397
|
-
plugin
|
|
1398
|
-
});
|
|
1409
|
+
const promises = this.#getSortedPlugins().map((plugin) => {
|
|
1410
|
+
return () => this.#execute({
|
|
1411
|
+
strategy: "hookSeq",
|
|
1412
|
+
hookName,
|
|
1413
|
+
parameters,
|
|
1414
|
+
plugin
|
|
1399
1415
|
});
|
|
1400
|
-
}
|
|
1401
|
-
return
|
|
1416
|
+
});
|
|
1417
|
+
return this.#promiseManager.run("seq", promises);
|
|
1402
1418
|
}
|
|
1403
1419
|
#getSortedPlugins(hookName) {
|
|
1404
1420
|
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1405
1421
|
if (hookName) {
|
|
1422
|
+
if (this.logger.logLevel === "info") {
|
|
1423
|
+
const containsHookName = plugins.some((item) => item[hookName]);
|
|
1424
|
+
if (!containsHookName) {
|
|
1425
|
+
this.logger.warn(`No hook ${hookName} found`);
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1406
1428
|
return plugins.filter((item) => item[hookName]);
|
|
1407
1429
|
}
|
|
1408
1430
|
return plugins;
|
|
1409
1431
|
}
|
|
1410
|
-
|
|
1432
|
+
getPluginsByKey(hookName, pluginKey) {
|
|
1411
1433
|
const plugins = [...this.plugins];
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
|
|
1434
|
+
const [searchKind, searchPluginName, searchIdentifier] = pluginKey;
|
|
1435
|
+
const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
|
|
1436
|
+
const [kind, name, identifier] = item.key;
|
|
1437
|
+
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
1438
|
+
const kindCheck = kind === searchKind;
|
|
1439
|
+
const nameCheck = name === searchPluginName;
|
|
1440
|
+
if (searchIdentifier) {
|
|
1441
|
+
return identifierCheck && kindCheck && nameCheck;
|
|
1442
|
+
}
|
|
1443
|
+
return kindCheck && nameCheck;
|
|
1444
|
+
});
|
|
1445
|
+
if (!pluginByPluginName?.length) {
|
|
1446
|
+
const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
|
|
1447
|
+
if (this.logger.logLevel === "info") {
|
|
1448
|
+
if (corePlugin) {
|
|
1449
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
|
|
1450
|
+
} else {
|
|
1451
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
return corePlugin ? [corePlugin] : [];
|
|
1415
1455
|
}
|
|
1416
1456
|
return pluginByPluginName;
|
|
1417
1457
|
}
|
|
1418
1458
|
#addExecutedToCallStack(executer) {
|
|
1419
1459
|
if (executer) {
|
|
1420
|
-
this.eventEmitter.emit("
|
|
1460
|
+
this.eventEmitter.emit("executed", executer);
|
|
1421
1461
|
this.executed.push(executer);
|
|
1422
1462
|
}
|
|
1423
1463
|
}
|
|
@@ -1487,7 +1527,7 @@ var PluginManager = class {
|
|
|
1487
1527
|
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1488
1528
|
try {
|
|
1489
1529
|
if (typeof hook === "function") {
|
|
1490
|
-
const fn = hook.apply(this.#core.api, parameters);
|
|
1530
|
+
const fn = hook.apply({ ...this.#core.api, plugin }, parameters);
|
|
1491
1531
|
output = fn;
|
|
1492
1532
|
return fn;
|
|
1493
1533
|
}
|
|
@@ -1513,34 +1553,50 @@ var PluginManager = class {
|
|
|
1513
1553
|
this.eventEmitter.emit("error", pluginError);
|
|
1514
1554
|
throw pluginError;
|
|
1515
1555
|
}
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1556
|
+
#parse(plugin, pluginManager, context) {
|
|
1557
|
+
const usedPluginNames = pluginManager.#usedPluginNames;
|
|
1558
|
+
setUniqueName(plugin.name, usedPluginNames);
|
|
1559
|
+
const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
1560
|
+
if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
|
|
1561
|
+
pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
|
|
1562
|
+
}
|
|
1563
|
+
if (!plugin.transform) {
|
|
1564
|
+
plugin.transform = function transform(code) {
|
|
1565
|
+
return code;
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
if (plugin.api && typeof plugin.api === "function") {
|
|
1569
|
+
const api = plugin.api.call(context);
|
|
1570
|
+
return {
|
|
1571
|
+
...plugin,
|
|
1572
|
+
key,
|
|
1573
|
+
api
|
|
1574
|
+
};
|
|
1575
|
+
}
|
|
1576
|
+
return {
|
|
1577
|
+
...plugin,
|
|
1578
|
+
key
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
static getDependedPlugins(plugins, dependedPluginNames) {
|
|
1582
|
+
let pluginNames = [];
|
|
1583
|
+
if (typeof dependedPluginNames === "string") {
|
|
1584
|
+
pluginNames = [dependedPluginNames];
|
|
1585
|
+
} else {
|
|
1586
|
+
pluginNames = dependedPluginNames;
|
|
1587
|
+
}
|
|
1588
|
+
return pluginNames.map((pluginName2) => {
|
|
1589
|
+
const plugin = plugins.find((plugin2) => plugin2.name === pluginName2);
|
|
1590
|
+
if (!plugin) {
|
|
1591
|
+
throw new ValidationPluginError(`This plugin depends on the ${pluginName2} plugin.`);
|
|
1592
|
+
}
|
|
1593
|
+
return plugin;
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
1597
|
+
static get hooks() {
|
|
1598
|
+
return ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
1599
|
+
}
|
|
1544
1600
|
};
|
|
1545
1601
|
|
|
1546
1602
|
// src/build.ts
|
|
@@ -1548,13 +1604,13 @@ async function transformReducer(_previousCode, result, _plugin) {
|
|
|
1548
1604
|
return result;
|
|
1549
1605
|
}
|
|
1550
1606
|
async function build(options) {
|
|
1551
|
-
const { config,
|
|
1607
|
+
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
1552
1608
|
try {
|
|
1553
|
-
if (
|
|
1609
|
+
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
1554
1610
|
await read(config.input.path);
|
|
1555
1611
|
}
|
|
1556
1612
|
} catch (e) {
|
|
1557
|
-
if (
|
|
1613
|
+
if (isInputPath(config)) {
|
|
1558
1614
|
throw new Error(
|
|
1559
1615
|
"Cannot read file/URL defined in `input.path` or set with `kubb generate PATH` in the CLI of your Kubb config " + pc3.dim(config.input.path),
|
|
1560
1616
|
{
|
|
@@ -1567,11 +1623,11 @@ async function build(options) {
|
|
|
1567
1623
|
await clean(config.output.path);
|
|
1568
1624
|
}
|
|
1569
1625
|
const queueTask = async (file) => {
|
|
1570
|
-
const { path } = file;
|
|
1571
|
-
let code =
|
|
1626
|
+
const { path: path3 } = file;
|
|
1627
|
+
let code = FileManager.getSource(file);
|
|
1572
1628
|
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1573
1629
|
hookName: "load",
|
|
1574
|
-
parameters: [
|
|
1630
|
+
parameters: [path3]
|
|
1575
1631
|
});
|
|
1576
1632
|
if (loadedResult && isPromise(loadedResult)) {
|
|
1577
1633
|
code = await loadedResult;
|
|
@@ -1582,28 +1638,53 @@ async function build(options) {
|
|
|
1582
1638
|
if (code) {
|
|
1583
1639
|
const transformedCode = await pluginManager.hookReduceArg0({
|
|
1584
1640
|
hookName: "transform",
|
|
1585
|
-
parameters: [code,
|
|
1641
|
+
parameters: [code, path3],
|
|
1586
1642
|
reduce: transformReducer
|
|
1587
1643
|
});
|
|
1588
1644
|
if (config.output.write || config.output.write === void 0) {
|
|
1589
|
-
|
|
1645
|
+
if (file.meta?.pluginKey) {
|
|
1646
|
+
return pluginManager.hookForPlugin({
|
|
1647
|
+
pluginKey: file.meta?.pluginKey,
|
|
1648
|
+
hookName: "writeFile",
|
|
1649
|
+
parameters: [transformedCode, path3]
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
return pluginManager.hookFirst({
|
|
1590
1653
|
hookName: "writeFile",
|
|
1591
|
-
parameters: [transformedCode,
|
|
1654
|
+
parameters: [transformedCode, path3]
|
|
1592
1655
|
});
|
|
1593
1656
|
}
|
|
1594
1657
|
}
|
|
1595
1658
|
};
|
|
1596
|
-
const pluginManager = new PluginManager(config, {
|
|
1659
|
+
const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
|
|
1597
1660
|
const { plugins, fileManager } = pluginManager;
|
|
1598
1661
|
pluginManager.on("execute", (executer) => {
|
|
1662
|
+
const { hookName, parameters, plugin } = executer;
|
|
1663
|
+
if (hookName === "writeFile" && logger.spinner) {
|
|
1664
|
+
const [code] = parameters;
|
|
1665
|
+
if (logger.logLevel === LogLevel.info) {
|
|
1666
|
+
logger.spinner.start(`\u{1F4BE} Writing`);
|
|
1667
|
+
}
|
|
1668
|
+
if (logger.logLevel === "debug") {
|
|
1669
|
+
logger.info(`PluginKey ${pc3.dim(JSON.stringify(plugin.key))}
|
|
1670
|
+
with source
|
|
1671
|
+
|
|
1672
|
+
${code}`);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
});
|
|
1676
|
+
pluginManager.on("executed", (executer) => {
|
|
1599
1677
|
const { hookName, plugin, output, parameters } = executer;
|
|
1600
1678
|
const messsage = `${randomPicoColour(plugin.name)} Executing ${hookName}`;
|
|
1601
|
-
if (logLevel === LogLevel.info) {
|
|
1602
|
-
if (
|
|
1679
|
+
if (logger.logLevel === LogLevel.info && logger.spinner) {
|
|
1680
|
+
if (hookName === "writeFile") {
|
|
1681
|
+
const [_code, path3] = parameters;
|
|
1682
|
+
logger.spinner.suffixText = pc3.dim(path3);
|
|
1683
|
+
} else {
|
|
1603
1684
|
logger.spinner.suffixText = messsage;
|
|
1604
1685
|
}
|
|
1605
1686
|
}
|
|
1606
|
-
if (logLevel === LogLevel.debug) {
|
|
1687
|
+
if (logger.logLevel === LogLevel.debug) {
|
|
1607
1688
|
logger.info(messsage);
|
|
1608
1689
|
const logs = [
|
|
1609
1690
|
parameters && `${pc3.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
|
|
@@ -1623,15 +1704,14 @@ async function build(options) {
|
|
|
1623
1704
|
parameters: [config]
|
|
1624
1705
|
});
|
|
1625
1706
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
return options;
|
|
1707
|
+
if (!fileManager.isExecuting && logger.spinner) {
|
|
1708
|
+
logger.spinner.suffixText = "";
|
|
1709
|
+
logger.spinner.succeed(`\u{1F4BE} Writing completed`);
|
|
1710
|
+
}
|
|
1711
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1632
1712
|
}
|
|
1633
1713
|
|
|
1634
|
-
// src/
|
|
1714
|
+
// src/Generator.ts
|
|
1635
1715
|
var Generator = class {
|
|
1636
1716
|
#options = {};
|
|
1637
1717
|
#context = {};
|
|
@@ -1654,10 +1734,6 @@ var Generator = class {
|
|
|
1654
1734
|
this.#options = { ...this.#options, ...options };
|
|
1655
1735
|
}
|
|
1656
1736
|
};
|
|
1657
|
-
|
|
1658
|
-
// src/generators/SchemaGenerator.ts
|
|
1659
|
-
var SchemaGenerator = class extends Generator {
|
|
1660
|
-
};
|
|
1661
1737
|
var PackageManager = class _PackageManager {
|
|
1662
1738
|
static #cache = {};
|
|
1663
1739
|
#cwd;
|
|
@@ -1680,17 +1756,17 @@ var PackageManager = class _PackageManager {
|
|
|
1680
1756
|
}
|
|
1681
1757
|
return directory;
|
|
1682
1758
|
}
|
|
1683
|
-
getLocation(
|
|
1684
|
-
let location =
|
|
1759
|
+
getLocation(path3) {
|
|
1760
|
+
let location = path3;
|
|
1685
1761
|
if (this.#cwd) {
|
|
1686
1762
|
const require2 = mod.createRequire(this.normalizeDirectory(this.#cwd));
|
|
1687
|
-
location = require2.resolve(
|
|
1763
|
+
location = require2.resolve(path3);
|
|
1688
1764
|
}
|
|
1689
1765
|
return location;
|
|
1690
1766
|
}
|
|
1691
|
-
async import(
|
|
1767
|
+
async import(path3) {
|
|
1692
1768
|
try {
|
|
1693
|
-
let location = this.getLocation(
|
|
1769
|
+
let location = this.getLocation(path3);
|
|
1694
1770
|
if (os.platform() == "win32") {
|
|
1695
1771
|
location = pathToFileURL(location).href;
|
|
1696
1772
|
}
|
|
@@ -1766,9 +1842,13 @@ var PackageManager = class _PackageManager {
|
|
|
1766
1842
|
}
|
|
1767
1843
|
};
|
|
1768
1844
|
|
|
1845
|
+
// src/SchemaGenerator.ts
|
|
1846
|
+
var SchemaGenerator = class extends Generator {
|
|
1847
|
+
};
|
|
1848
|
+
|
|
1769
1849
|
// src/index.ts
|
|
1770
1850
|
var src_default = build;
|
|
1771
1851
|
|
|
1772
|
-
export { FileManager,
|
|
1852
|
+
export { FileManager, Generator, PackageManager, ParallelPluginError, PluginError, PluginManager, PromiseManager, SchemaGenerator, SummaryError, ValidationPluginError, Warning, build, createPlugin, src_default as default, defineConfig, isInputPath, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, pluginName as name, pluginName };
|
|
1773
1853
|
//# sourceMappingURL=out.js.map
|
|
1774
1854
|
//# sourceMappingURL=index.js.map
|