@kubb/core 1.15.0-canary.20231027T200912 → 2.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1190 -1038
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +267 -314
- package/dist/index.d.ts +267 -314
- package/dist/index.js +1132 -971
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +1258 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +235 -0
- package/dist/utils.d.ts +235 -0
- package/dist/utils.js +1205 -0
- package/dist/utils.js.map +1 -0
- package/globals.d.ts +33 -16
- package/package.json +9 -4
package/dist/index.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,45 @@ 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
|
-
|
|
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);
|
|
60
|
-
}
|
|
61
|
-
var FunctionParams = class {
|
|
62
|
-
type;
|
|
63
|
-
items = [];
|
|
64
|
-
constructor(type) {
|
|
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
|
-
}
|
|
30
|
+
var __accessCheck = (obj, member, msg) => {
|
|
31
|
+
if (!member.has(obj))
|
|
32
|
+
throw TypeError("Cannot " + msg);
|
|
99
33
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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 "";
|
|
34
|
+
var __privateGet = (obj, member, getter) => {
|
|
35
|
+
__accessCheck(obj, member, "read from private field");
|
|
36
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
37
|
+
};
|
|
38
|
+
var __privateAdd = (obj, member, value) => {
|
|
39
|
+
if (member.has(obj))
|
|
40
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
41
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
42
|
+
};
|
|
43
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
44
|
+
__accessCheck(obj, member, "write to private field");
|
|
45
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
46
|
+
return value;
|
|
47
|
+
};
|
|
48
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
49
|
+
set _(value) {
|
|
50
|
+
__privateSet(obj, member, value, setter);
|
|
51
|
+
},
|
|
52
|
+
get _() {
|
|
53
|
+
return __privateGet(obj, member, getter);
|
|
128
54
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
55
|
+
});
|
|
56
|
+
var __privateMethod = (obj, member, method) => {
|
|
57
|
+
__accessCheck(obj, member, "access private method");
|
|
58
|
+
return method;
|
|
59
|
+
};
|
|
60
|
+
async function clean(path3) {
|
|
61
|
+
return remove(path3);
|
|
132
62
|
}
|
|
133
|
-
|
|
63
|
+
var LogLevel = {
|
|
64
|
+
silent: "silent",
|
|
65
|
+
info: "info",
|
|
66
|
+
debug: "debug"
|
|
67
|
+
};
|
|
68
|
+
function createLogger({ logLevel, name, spinner }) {
|
|
134
69
|
const logs = [];
|
|
135
70
|
const log = (message) => {
|
|
136
71
|
if (message && spinner) {
|
|
@@ -156,6 +91,8 @@ function createLogger(spinner) {
|
|
|
156
91
|
}
|
|
157
92
|
};
|
|
158
93
|
const logger = {
|
|
94
|
+
name,
|
|
95
|
+
logLevel,
|
|
159
96
|
log,
|
|
160
97
|
error,
|
|
161
98
|
warn,
|
|
@@ -165,75 +102,6 @@ function createLogger(spinner) {
|
|
|
165
102
|
};
|
|
166
103
|
return logger;
|
|
167
104
|
}
|
|
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
105
|
var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
|
|
238
106
|
function randomColour(text, colours = defaultColours) {
|
|
239
107
|
if (!text) {
|
|
@@ -260,46 +128,22 @@ function randomPicoColour(text, colors = defaultColours) {
|
|
|
260
128
|
}
|
|
261
129
|
return formatter(text);
|
|
262
130
|
}
|
|
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
131
|
var reader = switcher(
|
|
288
132
|
{
|
|
289
|
-
node: async (
|
|
290
|
-
return fs2.readFile(
|
|
133
|
+
node: async (path3) => {
|
|
134
|
+
return fs2.readFile(path3, { encoding: "utf8" });
|
|
291
135
|
},
|
|
292
|
-
bun: async (
|
|
293
|
-
const file = Bun.file(
|
|
136
|
+
bun: async (path3) => {
|
|
137
|
+
const file = Bun.file(path3);
|
|
294
138
|
return file.text();
|
|
295
139
|
}
|
|
296
140
|
},
|
|
297
141
|
"node"
|
|
298
142
|
);
|
|
299
|
-
|
|
143
|
+
switcher(
|
|
300
144
|
{
|
|
301
|
-
node: (
|
|
302
|
-
return fs2.readFileSync(
|
|
145
|
+
node: (path3) => {
|
|
146
|
+
return fs2.readFileSync(path3, { encoding: "utf8" });
|
|
303
147
|
},
|
|
304
148
|
bun: () => {
|
|
305
149
|
throw new Error("Bun cannot read sync");
|
|
@@ -307,79 +151,115 @@ var syncReader = switcher(
|
|
|
307
151
|
},
|
|
308
152
|
"node"
|
|
309
153
|
);
|
|
310
|
-
async function read(
|
|
311
|
-
return reader(
|
|
312
|
-
}
|
|
313
|
-
function readSync(path) {
|
|
314
|
-
return syncReader(path);
|
|
154
|
+
async function read(path3) {
|
|
155
|
+
return reader(path3);
|
|
315
156
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
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) || "";
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// src/utils/SummaryError.ts
|
|
342
|
-
var SummaryError = class extends Error {
|
|
343
|
-
summary;
|
|
344
|
-
constructor(message, options) {
|
|
345
|
-
super(message, { cause: options.cause });
|
|
346
|
-
this.name = "SummaryError";
|
|
347
|
-
this.summary = options.summary || [];
|
|
157
|
+
var URLPath = class {
|
|
158
|
+
constructor(path3) {
|
|
159
|
+
this.path = path3;
|
|
160
|
+
return this;
|
|
348
161
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
164
|
+
* @example /pet/{petId} => /pet/:petId
|
|
165
|
+
*/
|
|
166
|
+
get URL() {
|
|
167
|
+
return this.toURLPath();
|
|
168
|
+
}
|
|
169
|
+
get isURL() {
|
|
170
|
+
try {
|
|
171
|
+
const url = new URL(this.path);
|
|
172
|
+
if (url?.href) {
|
|
173
|
+
return true;
|
|
360
174
|
}
|
|
361
|
-
|
|
362
|
-
|
|
175
|
+
} catch (error) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
182
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
183
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
184
|
+
* @example /account/userID => `/account/${userId}`
|
|
185
|
+
*/
|
|
186
|
+
get template() {
|
|
187
|
+
return this.toTemplateString();
|
|
188
|
+
}
|
|
189
|
+
get object() {
|
|
190
|
+
return this.toObject();
|
|
191
|
+
}
|
|
192
|
+
get params() {
|
|
193
|
+
return this.getParams();
|
|
194
|
+
}
|
|
195
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
196
|
+
const object = {
|
|
197
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
|
|
198
|
+
params: this.getParams()
|
|
199
|
+
};
|
|
200
|
+
if (stringify) {
|
|
201
|
+
if (type !== "template") {
|
|
202
|
+
throw new Error("Type should be `template` when using stringiyf");
|
|
363
203
|
}
|
|
364
|
-
|
|
365
|
-
wait = true;
|
|
366
|
-
timeout2 = setTimeout(() => {
|
|
367
|
-
wait = false;
|
|
368
|
-
}, delay);
|
|
369
|
-
return val;
|
|
370
|
-
},
|
|
371
|
-
() => {
|
|
372
|
-
cancelled = true;
|
|
373
|
-
clearTimeout(timeout2);
|
|
204
|
+
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
374
205
|
}
|
|
375
|
-
|
|
206
|
+
return object;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
210
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
211
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
212
|
+
* @example /account/userID => `/account/${userId}`
|
|
213
|
+
*/
|
|
214
|
+
toTemplateString(replacer) {
|
|
215
|
+
const regex = /{(\w|-)*}/g;
|
|
216
|
+
const found = this.path.match(regex);
|
|
217
|
+
let newPath = this.path.replaceAll("{", "${");
|
|
218
|
+
if (found) {
|
|
219
|
+
newPath = found.reduce((prev, curr) => {
|
|
220
|
+
const pathParam = replacer ? replacer(camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge })) : camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge });
|
|
221
|
+
const replacement = `\${${pathParam}}`;
|
|
222
|
+
return prev.replace(curr, replacement);
|
|
223
|
+
}, this.path);
|
|
224
|
+
}
|
|
225
|
+
return `\`${newPath}\``;
|
|
226
|
+
}
|
|
227
|
+
getParams(replacer) {
|
|
228
|
+
const regex = /{(\w|-)*}/g;
|
|
229
|
+
const found = this.path.match(regex);
|
|
230
|
+
if (!found) {
|
|
231
|
+
return void 0;
|
|
232
|
+
}
|
|
233
|
+
const params = {};
|
|
234
|
+
found.forEach((item) => {
|
|
235
|
+
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
236
|
+
const pathParam = replacer ? replacer(camelCase(item, { delimiter: "", transform: camelCaseTransformMerge })) : camelCase(item, { delimiter: "", transform: camelCaseTransformMerge });
|
|
237
|
+
params[pathParam] = pathParam;
|
|
238
|
+
}, this.path);
|
|
239
|
+
return params;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
243
|
+
* @example /pet/{petId} => /pet/:petId
|
|
244
|
+
*/
|
|
245
|
+
toURLPath() {
|
|
246
|
+
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
247
|
+
}
|
|
376
248
|
};
|
|
377
249
|
|
|
250
|
+
// src/config.ts
|
|
251
|
+
function defineConfig(options) {
|
|
252
|
+
return options;
|
|
253
|
+
}
|
|
254
|
+
function isInputPath(result) {
|
|
255
|
+
return !!result && "path" in result;
|
|
256
|
+
}
|
|
257
|
+
|
|
378
258
|
// src/utils/timeout.ts
|
|
379
259
|
async function timeout(ms) {
|
|
380
|
-
return new Promise((
|
|
260
|
+
return new Promise((resolve2) => {
|
|
381
261
|
setTimeout(() => {
|
|
382
|
-
|
|
262
|
+
resolve2(true);
|
|
383
263
|
}, ms);
|
|
384
264
|
});
|
|
385
265
|
}
|
|
@@ -389,6 +269,17 @@ function combineCodes(codes) {
|
|
|
389
269
|
return codes.join("\n");
|
|
390
270
|
}
|
|
391
271
|
|
|
272
|
+
// src/utils/transformers/createJSDocBlockText.ts
|
|
273
|
+
function createJSDocBlockText({ comments }) {
|
|
274
|
+
const filteredComments = comments.filter(Boolean);
|
|
275
|
+
if (!filteredComments.length) {
|
|
276
|
+
return "";
|
|
277
|
+
}
|
|
278
|
+
return `/**
|
|
279
|
+
* ${filteredComments.join("\n * ")}
|
|
280
|
+
*/`;
|
|
281
|
+
}
|
|
282
|
+
|
|
392
283
|
// src/utils/transformers/escape.ts
|
|
393
284
|
function escape(text) {
|
|
394
285
|
return text ? text.replaceAll("`", "\\`") : "";
|
|
@@ -414,16 +305,49 @@ function jsStringEscape(input) {
|
|
|
414
305
|
});
|
|
415
306
|
}
|
|
416
307
|
|
|
417
|
-
// src/utils/transformers/
|
|
418
|
-
|
|
419
|
-
"
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
308
|
+
// src/utils/transformers/indent.ts
|
|
309
|
+
function createIndent(size) {
|
|
310
|
+
return Array.from({ length: size + 1 }).join(" ");
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/utils/transformers/nameSorter.ts
|
|
314
|
+
function nameSorter(a, b) {
|
|
315
|
+
if (a.name < b.name) {
|
|
316
|
+
return -1;
|
|
317
|
+
}
|
|
318
|
+
if (a.name > b.name) {
|
|
319
|
+
return 1;
|
|
320
|
+
}
|
|
321
|
+
return 0;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// src/utils/transformers/searchAndReplace.ts
|
|
325
|
+
function searchAndReplace(options) {
|
|
326
|
+
const { text, replaceBy, prefix = "", key } = options;
|
|
327
|
+
const searchValues = options.searchValues?.(prefix, key) || [
|
|
328
|
+
`${prefix}["${key}"]`,
|
|
329
|
+
`${prefix}['${key}']`,
|
|
330
|
+
`${prefix}[\`${key}\`]`,
|
|
331
|
+
`${prefix}"${key}"`,
|
|
332
|
+
`${prefix}'${key}'`,
|
|
333
|
+
`${prefix}\`${key}\``,
|
|
334
|
+
new RegExp(`${prefix}${key}`, "g")
|
|
335
|
+
];
|
|
336
|
+
return searchValues.reduce((prev, searchValue) => {
|
|
337
|
+
return prev.toString().replaceAll(searchValue, replaceBy);
|
|
338
|
+
}, text);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/utils/transformers/transformReservedWord.ts
|
|
342
|
+
var reservedWords = [
|
|
343
|
+
"abstract",
|
|
344
|
+
"arguments",
|
|
345
|
+
"boolean",
|
|
346
|
+
"break",
|
|
347
|
+
"byte",
|
|
348
|
+
"case",
|
|
349
|
+
"catch",
|
|
350
|
+
"char",
|
|
427
351
|
"class",
|
|
428
352
|
"const",
|
|
429
353
|
"continue",
|
|
@@ -506,11 +430,83 @@ function transformReservedWord(word) {
|
|
|
506
430
|
}
|
|
507
431
|
return word;
|
|
508
432
|
}
|
|
433
|
+
|
|
434
|
+
// src/utils/transformers/index.ts
|
|
435
|
+
var transformers = {
|
|
436
|
+
combineCodes,
|
|
437
|
+
escape,
|
|
438
|
+
jsStringEscape,
|
|
439
|
+
createIndent,
|
|
440
|
+
transformReservedWord,
|
|
441
|
+
nameSorter,
|
|
442
|
+
searchAndReplace,
|
|
443
|
+
JSDoc: {
|
|
444
|
+
createJSDocBlockText
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
async function saveCreateDirectory(path3) {
|
|
448
|
+
const passedPath = dirname(resolve(path3));
|
|
449
|
+
await fs2.mkdir(passedPath, { recursive: true });
|
|
450
|
+
}
|
|
451
|
+
var writer = switcher(
|
|
452
|
+
{
|
|
453
|
+
node: async (path3, data) => {
|
|
454
|
+
try {
|
|
455
|
+
await fs2.stat(resolve(path3));
|
|
456
|
+
const oldContent = await fs2.readFile(resolve(path3), { encoding: "utf-8" });
|
|
457
|
+
if (oldContent?.toString() === data?.toString()) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
} catch (_err) {
|
|
461
|
+
}
|
|
462
|
+
await saveCreateDirectory(path3);
|
|
463
|
+
await fs2.writeFile(resolve(path3), data, { encoding: "utf-8" });
|
|
464
|
+
const savedData = await fs2.readFile(resolve(path3), { encoding: "utf-8" });
|
|
465
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
466
|
+
throw new Error(`Sanity check failed for ${path3}
|
|
467
|
+
|
|
468
|
+
Data[${data.length}]:
|
|
469
|
+
${data}
|
|
470
|
+
|
|
471
|
+
Saved[${savedData.length}]:
|
|
472
|
+
${savedData}
|
|
473
|
+
`);
|
|
474
|
+
}
|
|
475
|
+
return savedData;
|
|
476
|
+
},
|
|
477
|
+
bun: async (path3, data) => {
|
|
478
|
+
try {
|
|
479
|
+
await saveCreateDirectory(path3);
|
|
480
|
+
await Bun.write(resolve(path3), data);
|
|
481
|
+
const file = Bun.file(resolve(path3));
|
|
482
|
+
const savedData = await file.text();
|
|
483
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
484
|
+
throw new Error(`Sanity check failed for ${path3}
|
|
485
|
+
|
|
486
|
+
Data[${data.length}]:
|
|
487
|
+
${data}
|
|
488
|
+
|
|
489
|
+
Saved[${savedData.length}]:
|
|
490
|
+
${savedData}
|
|
491
|
+
`);
|
|
492
|
+
}
|
|
493
|
+
return savedData;
|
|
494
|
+
} catch (e) {
|
|
495
|
+
console.log(e, resolve(path3));
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
"node"
|
|
500
|
+
);
|
|
501
|
+
async function write(data, path3) {
|
|
502
|
+
if (data.trim() === "") {
|
|
503
|
+
return void 0;
|
|
504
|
+
}
|
|
505
|
+
return writer(path3, data.trim());
|
|
506
|
+
}
|
|
509
507
|
var TreeNode = class _TreeNode {
|
|
510
|
-
data;
|
|
511
|
-
parent;
|
|
512
|
-
children = [];
|
|
513
508
|
constructor(data, parent) {
|
|
509
|
+
this.children = [];
|
|
514
510
|
this.data = data;
|
|
515
511
|
this.parent = parent;
|
|
516
512
|
return this;
|
|
@@ -570,16 +566,16 @@ var TreeNode = class _TreeNode {
|
|
|
570
566
|
}
|
|
571
567
|
return this;
|
|
572
568
|
}
|
|
573
|
-
static build(
|
|
569
|
+
static build(path3, options = {}) {
|
|
574
570
|
try {
|
|
575
571
|
const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
|
|
576
|
-
const filteredTree = dirTree(
|
|
572
|
+
const filteredTree = dirTree(path3, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
|
|
577
573
|
if (!filteredTree) {
|
|
578
574
|
return null;
|
|
579
575
|
}
|
|
580
|
-
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type ||
|
|
576
|
+
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || FileManager.getMode(filteredTree.path) });
|
|
581
577
|
const recurse = (node, item) => {
|
|
582
|
-
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type ||
|
|
578
|
+
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || FileManager.getMode(item.path) });
|
|
583
579
|
if (item.children?.length) {
|
|
584
580
|
item.children?.forEach((child) => {
|
|
585
581
|
recurse(subNode, child);
|
|
@@ -594,227 +590,290 @@ var TreeNode = class _TreeNode {
|
|
|
594
590
|
}
|
|
595
591
|
};
|
|
596
592
|
|
|
597
|
-
// src/
|
|
598
|
-
var
|
|
599
|
-
var
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
this
|
|
593
|
+
// src/BarrelManager.ts
|
|
594
|
+
var _options;
|
|
595
|
+
var BarrelManager = class {
|
|
596
|
+
constructor(options = {}) {
|
|
597
|
+
__privateAdd(this, _options, {});
|
|
598
|
+
__privateSet(this, _options, options);
|
|
603
599
|
return this;
|
|
604
600
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
if (url?.href) {
|
|
616
|
-
return true;
|
|
601
|
+
getIndexes(root, extName) {
|
|
602
|
+
const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = __privateGet(this, _options);
|
|
603
|
+
const extMapper = {
|
|
604
|
+
".ts": {
|
|
605
|
+
extensions: /\.ts/,
|
|
606
|
+
exclude: [/schemas/, /json/]
|
|
607
|
+
},
|
|
608
|
+
".json": {
|
|
609
|
+
extensions: /\.json/,
|
|
610
|
+
exclude: []
|
|
617
611
|
}
|
|
618
|
-
}
|
|
619
|
-
|
|
612
|
+
};
|
|
613
|
+
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
|
|
614
|
+
if (!tree) {
|
|
615
|
+
return null;
|
|
620
616
|
}
|
|
621
|
-
|
|
617
|
+
const fileReducer = (files2, currentTree) => {
|
|
618
|
+
if (!currentTree.children) {
|
|
619
|
+
return [];
|
|
620
|
+
}
|
|
621
|
+
if (currentTree.children?.length > 1) {
|
|
622
|
+
const indexPath = path.resolve(currentTree.data.path, "index.ts");
|
|
623
|
+
const exports = currentTree.children.filter(Boolean).map((file) => {
|
|
624
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
625
|
+
if (importPath.includes("index") && indexPath.includes("index")) {
|
|
626
|
+
return void 0;
|
|
627
|
+
}
|
|
628
|
+
return {
|
|
629
|
+
path: includeExt ? file.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
|
|
630
|
+
isTypeOnly
|
|
631
|
+
};
|
|
632
|
+
}).filter(Boolean);
|
|
633
|
+
files2.push({
|
|
634
|
+
path: indexPath,
|
|
635
|
+
baseName: "index.ts",
|
|
636
|
+
source: "",
|
|
637
|
+
exports: output ? exports?.filter((item) => {
|
|
638
|
+
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
639
|
+
}) : exports
|
|
640
|
+
});
|
|
641
|
+
} else {
|
|
642
|
+
currentTree.children?.forEach((child) => {
|
|
643
|
+
const indexPath = path.resolve(currentTree.data.path, "index.ts");
|
|
644
|
+
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
645
|
+
const exports = [
|
|
646
|
+
{
|
|
647
|
+
path: includeExt ? child.data.type === "directory" ? `${importPath}/index${extName}` : `${importPath}${extName}` : importPath,
|
|
648
|
+
isTypeOnly
|
|
649
|
+
}
|
|
650
|
+
];
|
|
651
|
+
files2.push({
|
|
652
|
+
path: indexPath,
|
|
653
|
+
baseName: "index.ts",
|
|
654
|
+
source: "",
|
|
655
|
+
exports: output ? exports?.filter((item) => {
|
|
656
|
+
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
657
|
+
}) : exports
|
|
658
|
+
});
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
currentTree.children.forEach((childItem) => {
|
|
662
|
+
fileReducer(files2, childItem);
|
|
663
|
+
});
|
|
664
|
+
return files2;
|
|
665
|
+
};
|
|
666
|
+
const files = fileReducer([], tree).reverse();
|
|
667
|
+
const filteredFiles = filter ? files.filter(filter) : files;
|
|
668
|
+
return map ? filteredFiles.map(map) : filteredFiles;
|
|
622
669
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
670
|
+
};
|
|
671
|
+
_options = new WeakMap();
|
|
672
|
+
|
|
673
|
+
// src/FileManager.ts
|
|
674
|
+
var KubbFile;
|
|
675
|
+
((KubbFile2) => {
|
|
676
|
+
})(KubbFile || (KubbFile = {}));
|
|
677
|
+
var _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
678
|
+
var _FileManager = class _FileManager {
|
|
679
|
+
constructor(options) {
|
|
680
|
+
__privateAdd(this, _validate);
|
|
681
|
+
__privateAdd(this, _add);
|
|
682
|
+
__privateAdd(this, _addOrAppend);
|
|
683
|
+
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
|
|
684
|
+
__privateAdd(this, _task, void 0);
|
|
685
|
+
__privateAdd(this, _isWriting, false);
|
|
686
|
+
/**
|
|
687
|
+
* Timeout between writes
|
|
688
|
+
*/
|
|
689
|
+
__privateAdd(this, _timeout, 0);
|
|
690
|
+
__privateAdd(this, _queue, void 0);
|
|
691
|
+
if (options) {
|
|
692
|
+
__privateSet(this, _task, options.task);
|
|
693
|
+
__privateSet(this, _queue, options.queue);
|
|
694
|
+
__privateSet(this, _timeout, options.timeout || 0);
|
|
695
|
+
}
|
|
696
|
+
return this;
|
|
631
697
|
}
|
|
632
|
-
get
|
|
633
|
-
|
|
698
|
+
get files() {
|
|
699
|
+
const files = [];
|
|
700
|
+
__privateGet(this, _cache).forEach((item) => {
|
|
701
|
+
files.push(...item.flat(1));
|
|
702
|
+
});
|
|
703
|
+
return files;
|
|
634
704
|
}
|
|
635
|
-
get
|
|
636
|
-
return this
|
|
705
|
+
get isExecuting() {
|
|
706
|
+
return __privateGet(this, _queue)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
|
|
637
707
|
}
|
|
638
|
-
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
if (stringify) {
|
|
644
|
-
if (type !== "template") {
|
|
645
|
-
throw new Error("Type should be `template` when using stringiyf");
|
|
708
|
+
async add(...files) {
|
|
709
|
+
const promises = files.map((file) => {
|
|
710
|
+
__privateMethod(this, _validate, validate_fn).call(this, file);
|
|
711
|
+
if (file.override) {
|
|
712
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
646
713
|
}
|
|
647
|
-
return
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
653
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
654
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
655
|
-
* @example /account/userID => `/account/${userId}`
|
|
656
|
-
*/
|
|
657
|
-
toTemplateString(replacer) {
|
|
658
|
-
const regex = /{(\w|-)*}/g;
|
|
659
|
-
const found = this.path.match(regex);
|
|
660
|
-
let newPath = this.path.replaceAll("{", "${");
|
|
661
|
-
if (found) {
|
|
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);
|
|
714
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
|
|
715
|
+
});
|
|
716
|
+
const resolvedFiles = await Promise.all(promises);
|
|
717
|
+
if (files.length > 1) {
|
|
718
|
+
return resolvedFiles;
|
|
667
719
|
}
|
|
668
|
-
return
|
|
720
|
+
return resolvedFiles[0];
|
|
669
721
|
}
|
|
670
|
-
|
|
671
|
-
const
|
|
672
|
-
const
|
|
673
|
-
if (!
|
|
722
|
+
async addIndexes({ root, extName = ".ts", meta, options = {} }) {
|
|
723
|
+
const barrelManager = new BarrelManager(options);
|
|
724
|
+
const files = barrelManager.getIndexes(root, extName);
|
|
725
|
+
if (!files) {
|
|
674
726
|
return void 0;
|
|
675
727
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
728
|
+
return await Promise.all(
|
|
729
|
+
files.map((file) => {
|
|
730
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
731
|
+
...file,
|
|
732
|
+
meta: meta ? meta : file.meta
|
|
733
|
+
});
|
|
734
|
+
})
|
|
735
|
+
);
|
|
683
736
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
return
|
|
737
|
+
getCacheByUUID(UUID) {
|
|
738
|
+
let cache;
|
|
739
|
+
__privateGet(this, _cache).forEach((files) => {
|
|
740
|
+
cache = files.find((item) => item.id === UUID);
|
|
741
|
+
});
|
|
742
|
+
return cache;
|
|
690
743
|
}
|
|
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";
|
|
744
|
+
get(path3) {
|
|
745
|
+
return __privateGet(this, _cache).get(path3);
|
|
698
746
|
}
|
|
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: []
|
|
747
|
+
remove(path3) {
|
|
748
|
+
const cacheItem = this.get(path3);
|
|
749
|
+
if (!cacheItem) {
|
|
750
|
+
return;
|
|
741
751
|
}
|
|
742
|
-
|
|
743
|
-
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...options });
|
|
744
|
-
if (!tree) {
|
|
745
|
-
return null;
|
|
752
|
+
__privateGet(this, _cache).delete(path3);
|
|
746
753
|
}
|
|
747
|
-
|
|
748
|
-
if (!
|
|
749
|
-
|
|
754
|
+
async write(...params) {
|
|
755
|
+
if (!__privateGet(this, _isWriting)) {
|
|
756
|
+
__privateSet(this, _isWriting, true);
|
|
757
|
+
const text = await write(...params);
|
|
758
|
+
__privateSet(this, _isWriting, false);
|
|
759
|
+
return text;
|
|
750
760
|
}
|
|
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
|
-
});
|
|
761
|
+
await timeout(__privateGet(this, _timeout));
|
|
762
|
+
return this.write(...params);
|
|
763
|
+
}
|
|
764
|
+
async read(...params) {
|
|
765
|
+
return read(...params);
|
|
766
|
+
}
|
|
767
|
+
// statics
|
|
768
|
+
static getSource(file) {
|
|
769
|
+
if (!_FileManager.isExtensionAllowed(file.baseName)) {
|
|
770
|
+
return file.source;
|
|
780
771
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
772
|
+
const exports = file.exports ? combineExports(file.exports) : [];
|
|
773
|
+
const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
|
|
774
|
+
const importNodes = imports.map((item) => factory.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
775
|
+
const exportNodes = exports.map(
|
|
776
|
+
(item) => factory.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias })
|
|
777
|
+
);
|
|
778
|
+
return [print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
779
|
+
}
|
|
780
|
+
static combineFiles(files) {
|
|
781
|
+
return files.filter(Boolean).reduce((acc, file) => {
|
|
782
|
+
const prevIndex = acc.findIndex((item) => item.path === file.path);
|
|
783
|
+
if (prevIndex === -1) {
|
|
784
|
+
return [...acc, file];
|
|
785
|
+
}
|
|
793
786
|
const prev = acc[prevIndex];
|
|
787
|
+
if (prev && file.override) {
|
|
788
|
+
acc[prevIndex] = {
|
|
789
|
+
imports: [],
|
|
790
|
+
exports: [],
|
|
791
|
+
...file
|
|
792
|
+
};
|
|
793
|
+
return acc;
|
|
794
|
+
}
|
|
794
795
|
if (prev) {
|
|
795
796
|
acc[prevIndex] = {
|
|
796
|
-
...
|
|
797
|
-
source: prev.source &&
|
|
798
|
-
${
|
|
799
|
-
imports: [...prev.imports || [], ...
|
|
800
|
-
exports: [...prev.exports || [], ...
|
|
801
|
-
env: { ...prev.env || {}, ...
|
|
797
|
+
...file,
|
|
798
|
+
source: prev.source && file.source ? `${prev.source}
|
|
799
|
+
${file.source}` : "",
|
|
800
|
+
imports: [...prev.imports || [], ...file.imports || []],
|
|
801
|
+
exports: [...prev.exports || [], ...file.exports || []],
|
|
802
|
+
env: { ...prev.env || {}, ...file.env || {} }
|
|
802
803
|
};
|
|
803
804
|
}
|
|
804
|
-
|
|
805
|
-
|
|
805
|
+
return acc;
|
|
806
|
+
}, []);
|
|
807
|
+
}
|
|
808
|
+
static getMode(path3) {
|
|
809
|
+
if (!path3) {
|
|
810
|
+
return "directory";
|
|
806
811
|
}
|
|
807
|
-
return
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
812
|
+
return extname(path3) ? "file" : "directory";
|
|
813
|
+
}
|
|
814
|
+
static get extensions() {
|
|
815
|
+
return [".js", ".ts", ".tsx"];
|
|
816
|
+
}
|
|
817
|
+
static isExtensionAllowed(baseName) {
|
|
818
|
+
return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
_cache = new WeakMap();
|
|
822
|
+
_task = new WeakMap();
|
|
823
|
+
_isWriting = new WeakMap();
|
|
824
|
+
_timeout = new WeakMap();
|
|
825
|
+
_queue = new WeakMap();
|
|
826
|
+
_validate = new WeakSet();
|
|
827
|
+
validate_fn = function(file) {
|
|
828
|
+
if (!file.validate) {
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
|
|
832
|
+
throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
_add = new WeakSet();
|
|
836
|
+
add_fn = async function(file) {
|
|
837
|
+
const controller = new AbortController();
|
|
838
|
+
const resolvedFile = { id: crypto2.randomUUID(), ...file };
|
|
839
|
+
__privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
840
|
+
if (__privateGet(this, _queue)) {
|
|
841
|
+
await __privateGet(this, _queue).run(
|
|
842
|
+
async () => {
|
|
843
|
+
var _a;
|
|
844
|
+
return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
|
|
845
|
+
},
|
|
846
|
+
{ controller }
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
return resolvedFile;
|
|
850
|
+
};
|
|
851
|
+
_addOrAppend = new WeakSet();
|
|
852
|
+
addOrAppend_fn = async function(file) {
|
|
853
|
+
const previousCaches = __privateGet(this, _cache).get(file.path);
|
|
854
|
+
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
855
|
+
if (previousCache) {
|
|
856
|
+
__privateGet(this, _cache).delete(previousCache.path);
|
|
857
|
+
return __privateMethod(this, _add, add_fn).call(this, {
|
|
858
|
+
...file,
|
|
859
|
+
source: previousCache.source && file.source ? `${previousCache.source}
|
|
860
|
+
${file.source}` : "",
|
|
861
|
+
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
862
|
+
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
863
|
+
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
867
|
+
};
|
|
868
|
+
var FileManager = _FileManager;
|
|
814
869
|
function combineExports(exports) {
|
|
815
|
-
|
|
870
|
+
const combinedExports = orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
816
871
|
const name = curr.name;
|
|
817
872
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
873
|
+
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly);
|
|
874
|
+
if (prevByPathAndIsTypeOnly) {
|
|
875
|
+
return prev;
|
|
876
|
+
}
|
|
818
877
|
const uniquePrev = prev.findLast(
|
|
819
878
|
(imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
820
879
|
);
|
|
@@ -836,12 +895,16 @@ function combineExports(exports) {
|
|
|
836
895
|
}
|
|
837
896
|
return [...prev, curr];
|
|
838
897
|
}, []);
|
|
898
|
+
return orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
839
899
|
}
|
|
840
900
|
function combineImports(imports, exports, source) {
|
|
841
|
-
|
|
901
|
+
const combinedImports = orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
842
902
|
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
843
903
|
const hasImportInSource = (importName) => {
|
|
844
|
-
|
|
904
|
+
if (!source) {
|
|
905
|
+
return true;
|
|
906
|
+
}
|
|
907
|
+
const checker = (name2) => name2 && !!source.includes(name2);
|
|
845
908
|
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
846
909
|
};
|
|
847
910
|
if (Array.isArray(name)) {
|
|
@@ -849,6 +912,10 @@ function combineImports(imports, exports, source) {
|
|
|
849
912
|
}
|
|
850
913
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
851
914
|
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
915
|
+
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly);
|
|
916
|
+
if (prevByPathNameAndIsTypeOnly) {
|
|
917
|
+
return prev;
|
|
918
|
+
}
|
|
852
919
|
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
853
920
|
return prev;
|
|
854
921
|
}
|
|
@@ -870,43 +937,7 @@ function combineImports(imports, exports, source) {
|
|
|
870
937
|
}
|
|
871
938
|
return [...prev, curr];
|
|
872
939
|
}, []);
|
|
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);
|
|
940
|
+
return orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
|
|
910
941
|
}
|
|
911
942
|
function getEnvSource(source, env) {
|
|
912
943
|
if (!env) {
|
|
@@ -923,132 +954,128 @@ function getEnvSource(source, env) {
|
|
|
923
954
|
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
924
955
|
}
|
|
925
956
|
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).*
|
|
957
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
958
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
928
959
|
`, "ig"), ""), replaceBy, key });
|
|
929
960
|
}
|
|
930
961
|
return prev;
|
|
931
962
|
}, source);
|
|
932
963
|
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
#queue;
|
|
939
|
-
constructor(options) {
|
|
940
|
-
if (options) {
|
|
941
|
-
this.#task = options.task;
|
|
942
|
-
this.#queue = options.queue;
|
|
943
|
-
}
|
|
944
|
-
return this;
|
|
964
|
+
var _emitter;
|
|
965
|
+
var EventEmitter = class {
|
|
966
|
+
constructor() {
|
|
967
|
+
__privateAdd(this, _emitter, new EventEmitter$1());
|
|
968
|
+
__privateGet(this, _emitter).setMaxListeners(100);
|
|
945
969
|
}
|
|
946
|
-
|
|
947
|
-
|
|
970
|
+
emit(eventName, ...eventArg) {
|
|
971
|
+
__privateGet(this, _emitter).emit(eventName, ...eventArg);
|
|
948
972
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
this.#cache.forEach((item) => {
|
|
952
|
-
files.push(...item.flat(1));
|
|
953
|
-
});
|
|
954
|
-
return files;
|
|
973
|
+
on(eventName, handler) {
|
|
974
|
+
__privateGet(this, _emitter).on(eventName, handler);
|
|
955
975
|
}
|
|
956
|
-
|
|
957
|
-
|
|
976
|
+
off(eventName, handler) {
|
|
977
|
+
__privateGet(this, _emitter).off(eventName, handler);
|
|
958
978
|
}
|
|
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;
|
|
979
|
+
removeAll() {
|
|
980
|
+
__privateGet(this, _emitter).removeAllListeners();
|
|
976
981
|
}
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
982
|
+
};
|
|
983
|
+
_emitter = new WeakMap();
|
|
984
|
+
var _queue2, _workerCount, _maxParallel, _debug, _work, work_fn;
|
|
985
|
+
var Queue = class {
|
|
986
|
+
constructor(maxParallel, debug = false) {
|
|
987
|
+
__privateAdd(this, _work);
|
|
988
|
+
__privateAdd(this, _queue2, []);
|
|
989
|
+
this.eventEmitter = new EventEmitter();
|
|
990
|
+
__privateAdd(this, _workerCount, 0);
|
|
991
|
+
__privateAdd(this, _maxParallel, void 0);
|
|
992
|
+
__privateAdd(this, _debug, false);
|
|
993
|
+
__privateSet(this, _maxParallel, maxParallel);
|
|
994
|
+
__privateSet(this, _debug, debug);
|
|
995
|
+
}
|
|
996
|
+
run(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
|
|
997
|
+
return new Promise((resolve2, reject) => {
|
|
998
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
999
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
1000
|
+
__privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
|
|
1001
|
+
reject("Aborted");
|
|
989
1002
|
});
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
}
|
|
993
|
-
async addIndexes(root, extName = ".ts", options = {}) {
|
|
994
|
-
const files = await getIndexes(root, extName, options);
|
|
995
|
-
if (!files) {
|
|
996
|
-
return void 0;
|
|
997
|
-
}
|
|
998
|
-
return Promise.all(
|
|
999
|
-
files.map((file) => {
|
|
1000
|
-
if (file.override) {
|
|
1001
|
-
return this.add(file);
|
|
1002
|
-
}
|
|
1003
|
-
return this.addOrAppend(file);
|
|
1004
|
-
})
|
|
1005
|
-
);
|
|
1006
|
-
}
|
|
1007
|
-
#append(path, file) {
|
|
1008
|
-
const previousFiles = this.#cache.get(path) || [];
|
|
1009
|
-
this.#cache.set(path, [...previousFiles, file]);
|
|
1010
|
-
}
|
|
1011
|
-
getCacheByUUID(UUID) {
|
|
1012
|
-
let cache;
|
|
1013
|
-
this.#cache.forEach((files) => {
|
|
1014
|
-
cache = files.find((item) => item.id === UUID);
|
|
1003
|
+
__privateGet(this, _queue2).push(item);
|
|
1004
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
1015
1005
|
});
|
|
1016
|
-
return cache;
|
|
1017
1006
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1007
|
+
runSync(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
|
|
1008
|
+
new Promise((resolve2, reject) => {
|
|
1009
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
1010
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
1011
|
+
__privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
|
|
1012
|
+
});
|
|
1013
|
+
__privateGet(this, _queue2).push(item);
|
|
1014
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
1015
|
+
});
|
|
1020
1016
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
if (!cacheItem) {
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
this.#cache.delete(path);
|
|
1017
|
+
get hasJobs() {
|
|
1018
|
+
return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue2).length > 0;
|
|
1027
1019
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
return this.#queue.run(async () => {
|
|
1031
|
-
return write(...params);
|
|
1032
|
-
});
|
|
1033
|
-
}
|
|
1034
|
-
return write(...params);
|
|
1020
|
+
get count() {
|
|
1021
|
+
return __privateGet(this, _workerCount);
|
|
1035
1022
|
}
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1023
|
+
};
|
|
1024
|
+
_queue2 = new WeakMap();
|
|
1025
|
+
_workerCount = new WeakMap();
|
|
1026
|
+
_maxParallel = new WeakMap();
|
|
1027
|
+
_debug = new WeakMap();
|
|
1028
|
+
_work = new WeakSet();
|
|
1029
|
+
work_fn = function() {
|
|
1030
|
+
if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
__privateWrapper(this, _workerCount)._++;
|
|
1034
|
+
let entry;
|
|
1035
|
+
while (entry = __privateGet(this, _queue2).shift()) {
|
|
1036
|
+
const { reject, resolve: resolve2, job, name, description } = entry;
|
|
1037
|
+
if (__privateGet(this, _debug)) {
|
|
1038
|
+
performance.mark(name + "_start");
|
|
1039
|
+
}
|
|
1040
|
+
job().then((result) => {
|
|
1041
|
+
this.eventEmitter.emit("jobDone", result);
|
|
1042
|
+
resolve2(result);
|
|
1043
|
+
if (__privateGet(this, _debug)) {
|
|
1044
|
+
performance.mark(name + "_stop");
|
|
1045
|
+
performance.measure(description, name + "_start", name + "_stop");
|
|
1046
|
+
}
|
|
1047
|
+
}).catch((err) => {
|
|
1048
|
+
this.eventEmitter.emit("jobFailed", err);
|
|
1049
|
+
reject(err);
|
|
1050
|
+
});
|
|
1043
1051
|
}
|
|
1052
|
+
__privateWrapper(this, _workerCount)._--;
|
|
1044
1053
|
};
|
|
1045
1054
|
|
|
1046
|
-
// src/
|
|
1055
|
+
// src/utils/uniqueName.ts
|
|
1056
|
+
function setUniqueName(originalName, data) {
|
|
1057
|
+
let used = data[originalName] || 0;
|
|
1058
|
+
if (used) {
|
|
1059
|
+
data[originalName] = ++used;
|
|
1060
|
+
return originalName;
|
|
1061
|
+
}
|
|
1062
|
+
data[originalName] = 1;
|
|
1063
|
+
return originalName;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
// src/errors.ts
|
|
1067
|
+
var PluginError = class extends Error {
|
|
1068
|
+
constructor(message, options) {
|
|
1069
|
+
super(message, { cause: options.cause });
|
|
1070
|
+
this.name = "PluginError";
|
|
1071
|
+
this.cause = options.cause;
|
|
1072
|
+
this.pluginManager = options.pluginManager;
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1047
1075
|
var ParallelPluginError = class extends Error {
|
|
1048
|
-
errors = [];
|
|
1049
|
-
pluginManager;
|
|
1050
1076
|
constructor(message, options) {
|
|
1051
1077
|
super(message, { cause: options.cause });
|
|
1078
|
+
this.errors = [];
|
|
1052
1079
|
this.name = "ParallelPluginError";
|
|
1053
1080
|
this.errors = options.errors;
|
|
1054
1081
|
this.pluginManager = options.pluginManager;
|
|
@@ -1068,30 +1095,54 @@ var ParallelPluginError = class extends Error {
|
|
|
1068
1095
|
})?.cause;
|
|
1069
1096
|
}
|
|
1070
1097
|
};
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1098
|
+
var SummaryError = class extends Error {
|
|
1099
|
+
constructor(message, options) {
|
|
1100
|
+
super(message, { cause: options.cause });
|
|
1101
|
+
this.name = "SummaryError";
|
|
1102
|
+
this.summary = options.summary || [];
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
var Warning = class extends Error {
|
|
1076
1106
|
constructor(message, options) {
|
|
1077
|
-
super(message, { cause: options
|
|
1078
|
-
this.name = "
|
|
1079
|
-
this.cause = options.cause;
|
|
1080
|
-
this.pluginManager = options.pluginManager;
|
|
1107
|
+
super(message, { cause: options?.cause });
|
|
1108
|
+
this.name = "Warning";
|
|
1081
1109
|
}
|
|
1082
1110
|
};
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1111
|
+
var ValidationPluginError = class extends Error {
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1114
|
+
// src/utils/cache.ts
|
|
1115
|
+
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
1116
|
+
return {
|
|
1117
|
+
set(id, value) {
|
|
1118
|
+
Store[id] = [0, value];
|
|
1119
|
+
},
|
|
1120
|
+
get(id) {
|
|
1121
|
+
const item = Store[id];
|
|
1122
|
+
if (!item) {
|
|
1123
|
+
return null;
|
|
1124
|
+
}
|
|
1125
|
+
item[0] = 0;
|
|
1126
|
+
return item[1];
|
|
1127
|
+
},
|
|
1128
|
+
has(id) {
|
|
1129
|
+
const item = Store[id];
|
|
1130
|
+
if (!item) {
|
|
1131
|
+
return false;
|
|
1132
|
+
}
|
|
1133
|
+
item[0] = 0;
|
|
1134
|
+
return true;
|
|
1135
|
+
},
|
|
1136
|
+
delete(id) {
|
|
1137
|
+
return delete Store[id];
|
|
1093
1138
|
}
|
|
1094
|
-
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
// src/plugin.ts
|
|
1143
|
+
function createPlugin(factory2) {
|
|
1144
|
+
return (options) => {
|
|
1145
|
+
return factory2(options);
|
|
1095
1146
|
};
|
|
1096
1147
|
}
|
|
1097
1148
|
var pluginName = "core";
|
|
@@ -1100,6 +1151,8 @@ var definePlugin = createPlugin((options) => {
|
|
|
1100
1151
|
return {
|
|
1101
1152
|
name: pluginName,
|
|
1102
1153
|
options,
|
|
1154
|
+
key: ["controller", "core"],
|
|
1155
|
+
kind: "controller",
|
|
1103
1156
|
api() {
|
|
1104
1157
|
return {
|
|
1105
1158
|
get config() {
|
|
@@ -1108,18 +1161,18 @@ var definePlugin = createPlugin((options) => {
|
|
|
1108
1161
|
get plugins() {
|
|
1109
1162
|
return options.getPlugins();
|
|
1110
1163
|
},
|
|
1164
|
+
get plugin() {
|
|
1165
|
+
return options.plugin;
|
|
1166
|
+
},
|
|
1111
1167
|
logger,
|
|
1112
1168
|
fileManager,
|
|
1113
1169
|
pluginManager,
|
|
1114
1170
|
async addFile(...files) {
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
return fileManager.addOrAppend(file);
|
|
1121
|
-
})
|
|
1122
|
-
);
|
|
1171
|
+
const resolvedFiles = await fileManager.add(...files);
|
|
1172
|
+
if (!Array.isArray(resolvedFiles)) {
|
|
1173
|
+
return [resolvedFiles];
|
|
1174
|
+
}
|
|
1175
|
+
return resolvedFiles;
|
|
1123
1176
|
},
|
|
1124
1177
|
resolvePath,
|
|
1125
1178
|
resolveName,
|
|
@@ -1127,75 +1180,149 @@ var definePlugin = createPlugin((options) => {
|
|
|
1127
1180
|
};
|
|
1128
1181
|
},
|
|
1129
1182
|
resolvePath(baseName) {
|
|
1130
|
-
const root =
|
|
1131
|
-
return
|
|
1183
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
1184
|
+
return path.resolve(root, baseName);
|
|
1132
1185
|
},
|
|
1133
1186
|
resolveName(name) {
|
|
1134
1187
|
return name;
|
|
1135
1188
|
}
|
|
1136
1189
|
};
|
|
1137
1190
|
});
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1191
|
+
|
|
1192
|
+
// src/utils/executeStrategies.ts
|
|
1193
|
+
function hookSeq(promises) {
|
|
1194
|
+
return promises.filter(Boolean).reduce(
|
|
1195
|
+
(promise, func) => {
|
|
1196
|
+
if (typeof func !== "function") {
|
|
1197
|
+
throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
1198
|
+
}
|
|
1199
|
+
return promise.then((state) => {
|
|
1200
|
+
const calledFunc = func(state);
|
|
1201
|
+
if (calledFunc) {
|
|
1202
|
+
return calledFunc.then(Array.prototype.concat.bind(state));
|
|
1203
|
+
}
|
|
1204
|
+
});
|
|
1205
|
+
},
|
|
1206
|
+
Promise.resolve([])
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
function hookFirst(promises, nullCheck = (state) => state !== null) {
|
|
1210
|
+
let promise = Promise.resolve(null);
|
|
1211
|
+
for (const func of promises.filter(Boolean)) {
|
|
1212
|
+
promise = promise.then((state) => {
|
|
1213
|
+
if (nullCheck(state)) {
|
|
1214
|
+
return state;
|
|
1215
|
+
}
|
|
1216
|
+
const calledFunc = func(state);
|
|
1217
|
+
return calledFunc;
|
|
1218
|
+
});
|
|
1148
1219
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1220
|
+
return promise;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
// src/PromiseManager.ts
|
|
1224
|
+
var _options2;
|
|
1225
|
+
var PromiseManager = class {
|
|
1226
|
+
constructor(options = {}) {
|
|
1227
|
+
__privateAdd(this, _options2, {});
|
|
1228
|
+
__privateSet(this, _options2, options);
|
|
1229
|
+
return this;
|
|
1151
1230
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1231
|
+
run(strategy, promises) {
|
|
1232
|
+
if (strategy === "seq") {
|
|
1233
|
+
return hookSeq(promises);
|
|
1234
|
+
}
|
|
1235
|
+
if (strategy === "first") {
|
|
1236
|
+
return hookFirst(promises, __privateGet(this, _options2).nullCheck);
|
|
1237
|
+
}
|
|
1238
|
+
throw new Error(`${strategy} not implemented`);
|
|
1154
1239
|
}
|
|
1155
1240
|
};
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
const api = plugin.api.call(context);
|
|
1163
|
-
return {
|
|
1164
|
-
...plugin,
|
|
1165
|
-
key,
|
|
1166
|
-
api
|
|
1167
|
-
};
|
|
1168
|
-
}
|
|
1169
|
-
return {
|
|
1170
|
-
...plugin,
|
|
1171
|
-
key
|
|
1172
|
-
};
|
|
1241
|
+
_options2 = new WeakMap();
|
|
1242
|
+
function isPromise(result) {
|
|
1243
|
+
return !!result && typeof result?.then === "function";
|
|
1244
|
+
}
|
|
1245
|
+
function isPromiseRejectedResult(result) {
|
|
1246
|
+
return result.status === "rejected";
|
|
1173
1247
|
}
|
|
1174
1248
|
|
|
1175
|
-
// src/
|
|
1176
|
-
var
|
|
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);
|
|
1249
|
+
// src/PluginManager.ts
|
|
1250
|
+
var _core, _usedPluginNames, _promiseManager, _getSortedPlugins, getSortedPlugins_fn, _addExecutedToCallStack, addExecutedToCallStack_fn, _execute, execute_fn, _executeSync, executeSync_fn, _catcher, catcher_fn, _parse, parse_fn;
|
|
1187
1251
|
var PluginManager = class {
|
|
1188
|
-
plugins;
|
|
1189
|
-
fileManager;
|
|
1190
|
-
eventEmitter = new EventEmitter();
|
|
1191
|
-
queue;
|
|
1192
|
-
executed = [];
|
|
1193
|
-
logger;
|
|
1194
|
-
#core;
|
|
1195
1252
|
constructor(config, options) {
|
|
1253
|
+
__privateAdd(this, _getSortedPlugins);
|
|
1254
|
+
__privateAdd(this, _addExecutedToCallStack);
|
|
1255
|
+
/**
|
|
1256
|
+
* Run an async plugin hook and return the result.
|
|
1257
|
+
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
1258
|
+
* @param args Arguments passed to the plugin hook.
|
|
1259
|
+
* @param plugin The actual pluginObject to run.
|
|
1260
|
+
*/
|
|
1261
|
+
// Implementation signature
|
|
1262
|
+
__privateAdd(this, _execute);
|
|
1263
|
+
/**
|
|
1264
|
+
* Run a sync plugin hook and return the result.
|
|
1265
|
+
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
1266
|
+
* @param args Arguments passed to the plugin hook.
|
|
1267
|
+
* @param plugin The acutal plugin
|
|
1268
|
+
* @param replaceContext When passed, the plugin context can be overridden.
|
|
1269
|
+
*/
|
|
1270
|
+
__privateAdd(this, _executeSync);
|
|
1271
|
+
__privateAdd(this, _catcher);
|
|
1272
|
+
__privateAdd(this, _parse);
|
|
1273
|
+
this.eventEmitter = new EventEmitter();
|
|
1274
|
+
this.executed = [];
|
|
1275
|
+
__privateAdd(this, _core, void 0);
|
|
1276
|
+
__privateAdd(this, _usedPluginNames, {});
|
|
1277
|
+
__privateAdd(this, _promiseManager, void 0);
|
|
1278
|
+
this.resolvePath = (params) => {
|
|
1279
|
+
if (params.pluginKey) {
|
|
1280
|
+
const paths = this.hookForPluginSync({
|
|
1281
|
+
pluginKey: params.pluginKey,
|
|
1282
|
+
hookName: "resolvePath",
|
|
1283
|
+
parameters: [params.baseName, params.directory, params.options]
|
|
1284
|
+
});
|
|
1285
|
+
if (paths && paths?.length > 1) {
|
|
1286
|
+
throw new Error(
|
|
1287
|
+
`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1288
|
+
|
|
1289
|
+
Paths: ${JSON.stringify(paths, void 0, 2)}`
|
|
1290
|
+
);
|
|
1291
|
+
}
|
|
1292
|
+
return paths?.at(0);
|
|
1293
|
+
}
|
|
1294
|
+
return this.hookFirstSync({
|
|
1295
|
+
hookName: "resolvePath",
|
|
1296
|
+
parameters: [params.baseName, params.directory, params.options]
|
|
1297
|
+
}).result;
|
|
1298
|
+
};
|
|
1299
|
+
this.resolveName = (params) => {
|
|
1300
|
+
if (params.pluginKey) {
|
|
1301
|
+
const names = this.hookForPluginSync({
|
|
1302
|
+
pluginKey: params.pluginKey,
|
|
1303
|
+
hookName: "resolveName",
|
|
1304
|
+
parameters: [params.name, params.type]
|
|
1305
|
+
});
|
|
1306
|
+
if (names && names?.length > 1) {
|
|
1307
|
+
throw new Error(
|
|
1308
|
+
`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1309
|
+
|
|
1310
|
+
Names: ${JSON.stringify(names, void 0, 2)}`
|
|
1311
|
+
);
|
|
1312
|
+
}
|
|
1313
|
+
return transformReservedWord(names?.at(0) || params.name);
|
|
1314
|
+
}
|
|
1315
|
+
const name = this.hookFirstSync({
|
|
1316
|
+
hookName: "resolveName",
|
|
1317
|
+
parameters: [params.name, params.type]
|
|
1318
|
+
}).result;
|
|
1319
|
+
return transformReservedWord(name);
|
|
1320
|
+
};
|
|
1196
1321
|
this.logger = options.logger;
|
|
1197
|
-
this.queue = new Queue(100,
|
|
1198
|
-
this.fileManager = new FileManager({ task: options.task, queue: this.queue });
|
|
1322
|
+
this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
|
|
1323
|
+
this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
|
|
1324
|
+
__privateSet(this, _promiseManager, new PromiseManager({ nullCheck: (state) => !!state?.result }));
|
|
1325
|
+
const plugins = config.plugins || [];
|
|
1199
1326
|
const core = definePlugin({
|
|
1200
1327
|
config,
|
|
1201
1328
|
logger: this.logger,
|
|
@@ -1203,44 +1330,14 @@ var PluginManager = class {
|
|
|
1203
1330
|
fileManager: this.fileManager,
|
|
1204
1331
|
resolvePath: this.resolvePath.bind(this),
|
|
1205
1332
|
resolveName: this.resolveName.bind(this),
|
|
1206
|
-
getPlugins: this
|
|
1207
|
-
|
|
1333
|
+
getPlugins: __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).bind(this)
|
|
1334
|
+
});
|
|
1335
|
+
__privateSet(this, _core, __privateMethod(this, _parse, parse_fn).call(this, core, this, core.api.call(null)));
|
|
1336
|
+
this.plugins = [__privateGet(this, _core), ...plugins].map((plugin) => {
|
|
1337
|
+
return __privateMethod(this, _parse, parse_fn).call(this, plugin, this, __privateGet(this, _core).api);
|
|
1208
1338
|
});
|
|
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
1339
|
return this;
|
|
1215
1340
|
}
|
|
1216
|
-
resolvePath = (params) => {
|
|
1217
|
-
if (params.pluginName) {
|
|
1218
|
-
return this.hookForPluginSync({
|
|
1219
|
-
pluginName: params.pluginName,
|
|
1220
|
-
hookName: "resolvePath",
|
|
1221
|
-
parameters: [params.baseName, params.directory, params.options]
|
|
1222
|
-
});
|
|
1223
|
-
}
|
|
1224
|
-
return this.hookFirstSync({
|
|
1225
|
-
hookName: "resolvePath",
|
|
1226
|
-
parameters: [params.baseName, params.directory, params.options]
|
|
1227
|
-
}).result;
|
|
1228
|
-
};
|
|
1229
|
-
resolveName = (params) => {
|
|
1230
|
-
if (params.pluginName) {
|
|
1231
|
-
const name2 = this.hookForPluginSync({
|
|
1232
|
-
pluginName: params.pluginName,
|
|
1233
|
-
hookName: "resolveName",
|
|
1234
|
-
parameters: [params.name, params.type]
|
|
1235
|
-
});
|
|
1236
|
-
return transformReservedWord(name2 || params.name);
|
|
1237
|
-
}
|
|
1238
|
-
const name = this.hookFirstSync({
|
|
1239
|
-
hookName: "resolveName",
|
|
1240
|
-
parameters: [params.name, params.type]
|
|
1241
|
-
}).result;
|
|
1242
|
-
return transformReservedWord(name);
|
|
1243
|
-
};
|
|
1244
1341
|
on(eventName, handler) {
|
|
1245
1342
|
this.eventEmitter.on(eventName, handler);
|
|
1246
1343
|
}
|
|
@@ -1248,49 +1345,49 @@ var PluginManager = class {
|
|
|
1248
1345
|
* Run only hook for a specific plugin name
|
|
1249
1346
|
*/
|
|
1250
1347
|
hookForPlugin({
|
|
1251
|
-
|
|
1348
|
+
pluginKey,
|
|
1252
1349
|
hookName,
|
|
1253
1350
|
parameters
|
|
1254
1351
|
}) {
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1352
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1353
|
+
const promises = plugins.map((plugin) => {
|
|
1354
|
+
return __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1355
|
+
strategy: "hookFirst",
|
|
1356
|
+
hookName,
|
|
1357
|
+
parameters,
|
|
1358
|
+
plugin
|
|
1359
|
+
});
|
|
1360
|
+
}).filter(Boolean);
|
|
1361
|
+
return Promise.all(promises);
|
|
1262
1362
|
}
|
|
1263
1363
|
hookForPluginSync({
|
|
1264
|
-
|
|
1364
|
+
pluginKey,
|
|
1265
1365
|
hookName,
|
|
1266
1366
|
parameters
|
|
1267
1367
|
}) {
|
|
1268
|
-
const
|
|
1269
|
-
return
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1368
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1369
|
+
return plugins.map((plugin) => {
|
|
1370
|
+
return __privateMethod(this, _executeSync, executeSync_fn).call(this, {
|
|
1371
|
+
strategy: "hookFirst",
|
|
1372
|
+
hookName,
|
|
1373
|
+
parameters,
|
|
1374
|
+
plugin
|
|
1375
|
+
});
|
|
1376
|
+
}).filter(Boolean);
|
|
1275
1377
|
}
|
|
1276
1378
|
/**
|
|
1277
1379
|
* Chains, first non-null result stops and returns
|
|
1278
1380
|
*/
|
|
1279
|
-
hookFirst({
|
|
1381
|
+
async hookFirst({
|
|
1280
1382
|
hookName,
|
|
1281
1383
|
parameters,
|
|
1282
1384
|
skipped
|
|
1283
1385
|
}) {
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
promise = promise.then(async (parseResult) => {
|
|
1290
|
-
if (parseResult?.result != null) {
|
|
1291
|
-
return parseResult;
|
|
1292
|
-
}
|
|
1293
|
-
const value = await this.#execute({
|
|
1386
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).filter((plugin) => {
|
|
1387
|
+
return skipped ? skipped.has(plugin) : true;
|
|
1388
|
+
}).map((plugin) => {
|
|
1389
|
+
return async () => {
|
|
1390
|
+
const value = await __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1294
1391
|
strategy: "hookFirst",
|
|
1295
1392
|
hookName,
|
|
1296
1393
|
parameters,
|
|
@@ -1302,9 +1399,9 @@ var PluginManager = class {
|
|
|
1302
1399
|
result: value
|
|
1303
1400
|
}
|
|
1304
1401
|
);
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
return
|
|
1402
|
+
};
|
|
1403
|
+
});
|
|
1404
|
+
return __privateGet(this, _promiseManager).run("first", promises);
|
|
1308
1405
|
}
|
|
1309
1406
|
/**
|
|
1310
1407
|
* Chains, first non-null result stops and returns
|
|
@@ -1315,12 +1412,12 @@ var PluginManager = class {
|
|
|
1315
1412
|
skipped
|
|
1316
1413
|
}) {
|
|
1317
1414
|
let parseResult = null;
|
|
1318
|
-
for (const plugin of this
|
|
1415
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1319
1416
|
if (skipped && skipped.has(plugin)) {
|
|
1320
1417
|
continue;
|
|
1321
1418
|
}
|
|
1322
1419
|
parseResult = {
|
|
1323
|
-
result: this
|
|
1420
|
+
result: __privateMethod(this, _executeSync, executeSync_fn).call(this, {
|
|
1324
1421
|
strategy: "hookFirst",
|
|
1325
1422
|
hookName,
|
|
1326
1423
|
parameters,
|
|
@@ -1342,8 +1439,8 @@ var PluginManager = class {
|
|
|
1342
1439
|
parameters
|
|
1343
1440
|
}) {
|
|
1344
1441
|
const parallelPromises = [];
|
|
1345
|
-
for (const plugin of this
|
|
1346
|
-
const promise = this
|
|
1442
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1443
|
+
const promise = __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
|
|
1347
1444
|
if (promise) {
|
|
1348
1445
|
parallelPromises.push(promise);
|
|
1349
1446
|
}
|
|
@@ -1370,177 +1467,209 @@ var PluginManager = class {
|
|
|
1370
1467
|
}) {
|
|
1371
1468
|
const [argument0, ...rest] = parameters;
|
|
1372
1469
|
let promise = Promise.resolve(argument0);
|
|
1373
|
-
for (const plugin of this
|
|
1470
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1374
1471
|
promise = promise.then((arg0) => {
|
|
1375
|
-
const value = this
|
|
1472
|
+
const value = __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1376
1473
|
strategy: "hookReduceArg0",
|
|
1377
1474
|
hookName,
|
|
1378
1475
|
parameters: [arg0, ...rest],
|
|
1379
1476
|
plugin
|
|
1380
1477
|
});
|
|
1381
1478
|
return value;
|
|
1382
|
-
}).then((result) => reduce.call(this
|
|
1479
|
+
}).then((result) => reduce.call(__privateGet(this, _core).api, argument0, result, plugin));
|
|
1383
1480
|
}
|
|
1384
1481
|
return promise;
|
|
1385
1482
|
}
|
|
1386
1483
|
/**
|
|
1387
1484
|
* Chains plugins
|
|
1388
1485
|
*/
|
|
1389
|
-
hookSeq({ hookName, parameters }) {
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
parameters,
|
|
1397
|
-
plugin
|
|
1398
|
-
});
|
|
1486
|
+
async hookSeq({ hookName, parameters }) {
|
|
1487
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1488
|
+
return () => __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1489
|
+
strategy: "hookSeq",
|
|
1490
|
+
hookName,
|
|
1491
|
+
parameters,
|
|
1492
|
+
plugin
|
|
1399
1493
|
});
|
|
1400
|
-
}
|
|
1401
|
-
return
|
|
1402
|
-
}
|
|
1403
|
-
#getSortedPlugins(hookName) {
|
|
1404
|
-
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1405
|
-
if (hookName) {
|
|
1406
|
-
return plugins.filter((item) => item[hookName]);
|
|
1407
|
-
}
|
|
1408
|
-
return plugins;
|
|
1494
|
+
});
|
|
1495
|
+
return __privateGet(this, _promiseManager).run("seq", promises);
|
|
1409
1496
|
}
|
|
1410
|
-
|
|
1497
|
+
getPluginsByKey(hookName, pluginKey) {
|
|
1411
1498
|
const plugins = [...this.plugins];
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
|
|
1499
|
+
const [searchKind, searchPluginName, searchIdentifier] = pluginKey;
|
|
1500
|
+
const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
|
|
1501
|
+
const [kind, name, identifier] = item.key;
|
|
1502
|
+
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
1503
|
+
const kindCheck = kind === searchKind;
|
|
1504
|
+
const nameCheck = name === searchPluginName;
|
|
1505
|
+
if (searchIdentifier) {
|
|
1506
|
+
return identifierCheck && kindCheck && nameCheck;
|
|
1507
|
+
}
|
|
1508
|
+
return kindCheck && nameCheck;
|
|
1509
|
+
});
|
|
1510
|
+
if (!pluginByPluginName?.length) {
|
|
1511
|
+
const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
|
|
1512
|
+
if (this.logger.logLevel === "info") {
|
|
1513
|
+
if (corePlugin) {
|
|
1514
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
|
|
1515
|
+
} else {
|
|
1516
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
return corePlugin ? [corePlugin] : [];
|
|
1415
1520
|
}
|
|
1416
1521
|
return pluginByPluginName;
|
|
1417
1522
|
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
/**
|
|
1425
|
-
* Run an async plugin hook and return the result.
|
|
1426
|
-
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
1427
|
-
* @param args Arguments passed to the plugin hook.
|
|
1428
|
-
* @param plugin The actual pluginObject to run.
|
|
1429
|
-
*/
|
|
1430
|
-
// Implementation signature
|
|
1431
|
-
#execute({
|
|
1432
|
-
strategy,
|
|
1433
|
-
hookName,
|
|
1434
|
-
parameters,
|
|
1435
|
-
plugin
|
|
1436
|
-
}) {
|
|
1437
|
-
const hook = plugin[hookName];
|
|
1438
|
-
let output;
|
|
1439
|
-
if (!hook) {
|
|
1440
|
-
return null;
|
|
1523
|
+
static getDependedPlugins(plugins, dependedPluginNames) {
|
|
1524
|
+
let pluginNames = [];
|
|
1525
|
+
if (typeof dependedPluginNames === "string") {
|
|
1526
|
+
pluginNames = [dependedPluginNames];
|
|
1527
|
+
} else {
|
|
1528
|
+
pluginNames = dependedPluginNames;
|
|
1441
1529
|
}
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
if (
|
|
1445
|
-
|
|
1446
|
-
if (isPromise(possiblePromiseResult)) {
|
|
1447
|
-
return Promise.resolve(possiblePromiseResult);
|
|
1448
|
-
}
|
|
1449
|
-
return possiblePromiseResult;
|
|
1530
|
+
return pluginNames.map((pluginName2) => {
|
|
1531
|
+
const plugin = plugins.find((plugin2) => plugin2.name === pluginName2);
|
|
1532
|
+
if (!plugin) {
|
|
1533
|
+
throw new ValidationPluginError(`This plugin depends on the ${pluginName2} plugin.`);
|
|
1450
1534
|
}
|
|
1451
|
-
return
|
|
1452
|
-
}).then((result) => {
|
|
1453
|
-
output = result;
|
|
1454
|
-
return result;
|
|
1455
|
-
}).catch((e) => {
|
|
1456
|
-
this.#catcher(e, plugin, hookName);
|
|
1457
|
-
return null;
|
|
1458
|
-
}).finally(() => {
|
|
1459
|
-
this.#addExecutedToCallStack({
|
|
1460
|
-
parameters,
|
|
1461
|
-
output,
|
|
1462
|
-
strategy,
|
|
1463
|
-
hookName,
|
|
1464
|
-
plugin
|
|
1465
|
-
});
|
|
1535
|
+
return plugin;
|
|
1466
1536
|
});
|
|
1467
|
-
return task;
|
|
1468
1537
|
}
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
return null;
|
|
1486
|
-
}
|
|
1487
|
-
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1488
|
-
try {
|
|
1489
|
-
if (typeof hook === "function") {
|
|
1490
|
-
const fn = hook.apply(this.#core.api, parameters);
|
|
1491
|
-
output = fn;
|
|
1492
|
-
return fn;
|
|
1538
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
1539
|
+
static get hooks() {
|
|
1540
|
+
return ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
_core = new WeakMap();
|
|
1544
|
+
_usedPluginNames = new WeakMap();
|
|
1545
|
+
_promiseManager = new WeakMap();
|
|
1546
|
+
_getSortedPlugins = new WeakSet();
|
|
1547
|
+
getSortedPlugins_fn = function(hookName) {
|
|
1548
|
+
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1549
|
+
if (hookName) {
|
|
1550
|
+
if (this.logger.logLevel === "info") {
|
|
1551
|
+
const containsHookName = plugins.some((item) => item[hookName]);
|
|
1552
|
+
if (!containsHookName) {
|
|
1553
|
+
this.logger.warn(`No hook ${hookName} found`);
|
|
1493
1554
|
}
|
|
1494
|
-
output = hook;
|
|
1495
|
-
return hook;
|
|
1496
|
-
} catch (e) {
|
|
1497
|
-
this.#catcher(e, plugin, hookName);
|
|
1498
|
-
return null;
|
|
1499
|
-
} finally {
|
|
1500
|
-
this.#addExecutedToCallStack({
|
|
1501
|
-
parameters,
|
|
1502
|
-
output,
|
|
1503
|
-
strategy,
|
|
1504
|
-
hookName,
|
|
1505
|
-
plugin
|
|
1506
|
-
});
|
|
1507
1555
|
}
|
|
1556
|
+
return plugins.filter((item) => item[hookName]);
|
|
1508
1557
|
}
|
|
1509
|
-
|
|
1510
|
-
const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
|
|
1511
|
-
`;
|
|
1512
|
-
const pluginError = new PluginError(text, { cause: e, pluginManager: this });
|
|
1513
|
-
this.eventEmitter.emit("error", pluginError);
|
|
1514
|
-
throw pluginError;
|
|
1515
|
-
}
|
|
1558
|
+
return plugins;
|
|
1516
1559
|
};
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1560
|
+
_addExecutedToCallStack = new WeakSet();
|
|
1561
|
+
addExecutedToCallStack_fn = function(executer) {
|
|
1562
|
+
if (executer) {
|
|
1563
|
+
this.eventEmitter.emit("executed", executer);
|
|
1564
|
+
this.executed.push(executer);
|
|
1565
|
+
}
|
|
1522
1566
|
};
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1567
|
+
_execute = new WeakSet();
|
|
1568
|
+
execute_fn = function({
|
|
1569
|
+
strategy,
|
|
1570
|
+
hookName,
|
|
1571
|
+
parameters,
|
|
1572
|
+
plugin
|
|
1573
|
+
}) {
|
|
1574
|
+
const hook = plugin[hookName];
|
|
1575
|
+
let output;
|
|
1576
|
+
if (!hook) {
|
|
1577
|
+
return null;
|
|
1578
|
+
}
|
|
1579
|
+
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1580
|
+
const task = Promise.resolve().then(() => {
|
|
1581
|
+
if (typeof hook === "function") {
|
|
1582
|
+
const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
1583
|
+
if (isPromise(possiblePromiseResult)) {
|
|
1584
|
+
return Promise.resolve(possiblePromiseResult);
|
|
1585
|
+
}
|
|
1586
|
+
return possiblePromiseResult;
|
|
1587
|
+
}
|
|
1588
|
+
return hook;
|
|
1589
|
+
}).then((result) => {
|
|
1590
|
+
output = result;
|
|
1591
|
+
return result;
|
|
1592
|
+
}).catch((e) => {
|
|
1593
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1594
|
+
return null;
|
|
1595
|
+
}).finally(() => {
|
|
1596
|
+
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1597
|
+
parameters,
|
|
1598
|
+
output,
|
|
1599
|
+
strategy,
|
|
1600
|
+
hookName,
|
|
1601
|
+
plugin
|
|
1602
|
+
});
|
|
1536
1603
|
});
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1604
|
+
return task;
|
|
1605
|
+
};
|
|
1606
|
+
_executeSync = new WeakSet();
|
|
1607
|
+
executeSync_fn = function({
|
|
1608
|
+
strategy,
|
|
1609
|
+
hookName,
|
|
1610
|
+
parameters,
|
|
1611
|
+
plugin
|
|
1612
|
+
}) {
|
|
1613
|
+
const hook = plugin[hookName];
|
|
1614
|
+
let output;
|
|
1615
|
+
if (!hook) {
|
|
1616
|
+
return null;
|
|
1617
|
+
}
|
|
1618
|
+
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1619
|
+
try {
|
|
1620
|
+
if (typeof hook === "function") {
|
|
1621
|
+
const fn = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
1622
|
+
output = fn;
|
|
1623
|
+
return fn;
|
|
1624
|
+
}
|
|
1625
|
+
output = hook;
|
|
1626
|
+
return hook;
|
|
1627
|
+
} catch (e) {
|
|
1628
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1629
|
+
return null;
|
|
1630
|
+
} finally {
|
|
1631
|
+
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1632
|
+
parameters,
|
|
1633
|
+
output,
|
|
1634
|
+
strategy,
|
|
1635
|
+
hookName,
|
|
1636
|
+
plugin
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
};
|
|
1640
|
+
_catcher = new WeakSet();
|
|
1641
|
+
catcher_fn = function(e, plugin, hookName) {
|
|
1642
|
+
const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
|
|
1643
|
+
`;
|
|
1644
|
+
const pluginError = new PluginError(text, { cause: e, pluginManager: this });
|
|
1645
|
+
this.eventEmitter.emit("error", pluginError);
|
|
1646
|
+
throw pluginError;
|
|
1647
|
+
};
|
|
1648
|
+
_parse = new WeakSet();
|
|
1649
|
+
parse_fn = function(plugin, pluginManager, context) {
|
|
1650
|
+
const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
|
|
1651
|
+
setUniqueName(plugin.name, usedPluginNames);
|
|
1652
|
+
const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
1653
|
+
if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
|
|
1654
|
+
pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
|
|
1655
|
+
}
|
|
1656
|
+
if (!plugin.transform) {
|
|
1657
|
+
plugin.transform = function transform(code) {
|
|
1658
|
+
return code;
|
|
1659
|
+
};
|
|
1660
|
+
}
|
|
1661
|
+
if (plugin.api && typeof plugin.api === "function") {
|
|
1662
|
+
const api = plugin.api.call(context);
|
|
1663
|
+
return {
|
|
1664
|
+
...plugin,
|
|
1665
|
+
key,
|
|
1666
|
+
api
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
return {
|
|
1670
|
+
...plugin,
|
|
1671
|
+
key
|
|
1672
|
+
};
|
|
1544
1673
|
};
|
|
1545
1674
|
|
|
1546
1675
|
// src/build.ts
|
|
@@ -1548,13 +1677,13 @@ async function transformReducer(_previousCode, result, _plugin) {
|
|
|
1548
1677
|
return result;
|
|
1549
1678
|
}
|
|
1550
1679
|
async function build(options) {
|
|
1551
|
-
const { config,
|
|
1680
|
+
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
1552
1681
|
try {
|
|
1553
|
-
if (
|
|
1682
|
+
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
1554
1683
|
await read(config.input.path);
|
|
1555
1684
|
}
|
|
1556
1685
|
} catch (e) {
|
|
1557
|
-
if (
|
|
1686
|
+
if (isInputPath(config)) {
|
|
1558
1687
|
throw new Error(
|
|
1559
1688
|
"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
1689
|
{
|
|
@@ -1567,11 +1696,11 @@ async function build(options) {
|
|
|
1567
1696
|
await clean(config.output.path);
|
|
1568
1697
|
}
|
|
1569
1698
|
const queueTask = async (file) => {
|
|
1570
|
-
const { path } = file;
|
|
1571
|
-
let code =
|
|
1699
|
+
const { path: path3 } = file;
|
|
1700
|
+
let code = FileManager.getSource(file);
|
|
1572
1701
|
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1573
1702
|
hookName: "load",
|
|
1574
|
-
parameters: [
|
|
1703
|
+
parameters: [path3]
|
|
1575
1704
|
});
|
|
1576
1705
|
if (loadedResult && isPromise(loadedResult)) {
|
|
1577
1706
|
code = await loadedResult;
|
|
@@ -1582,28 +1711,53 @@ async function build(options) {
|
|
|
1582
1711
|
if (code) {
|
|
1583
1712
|
const transformedCode = await pluginManager.hookReduceArg0({
|
|
1584
1713
|
hookName: "transform",
|
|
1585
|
-
parameters: [code,
|
|
1714
|
+
parameters: [code, path3],
|
|
1586
1715
|
reduce: transformReducer
|
|
1587
1716
|
});
|
|
1588
1717
|
if (config.output.write || config.output.write === void 0) {
|
|
1589
|
-
|
|
1718
|
+
if (file.meta?.pluginKey) {
|
|
1719
|
+
return pluginManager.hookForPlugin({
|
|
1720
|
+
pluginKey: file.meta?.pluginKey,
|
|
1721
|
+
hookName: "writeFile",
|
|
1722
|
+
parameters: [transformedCode, path3]
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
return pluginManager.hookFirst({
|
|
1590
1726
|
hookName: "writeFile",
|
|
1591
|
-
parameters: [transformedCode,
|
|
1727
|
+
parameters: [transformedCode, path3]
|
|
1592
1728
|
});
|
|
1593
1729
|
}
|
|
1594
1730
|
}
|
|
1595
1731
|
};
|
|
1596
|
-
const pluginManager = new PluginManager(config, {
|
|
1732
|
+
const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
|
|
1597
1733
|
const { plugins, fileManager } = pluginManager;
|
|
1598
1734
|
pluginManager.on("execute", (executer) => {
|
|
1735
|
+
const { hookName, parameters, plugin } = executer;
|
|
1736
|
+
if (hookName === "writeFile" && logger.spinner) {
|
|
1737
|
+
const [code] = parameters;
|
|
1738
|
+
if (logger.logLevel === LogLevel.info) {
|
|
1739
|
+
logger.spinner.start(`\u{1F4BE} Writing`);
|
|
1740
|
+
}
|
|
1741
|
+
if (logger.logLevel === "debug") {
|
|
1742
|
+
logger.info(`PluginKey ${pc3.dim(JSON.stringify(plugin.key))}
|
|
1743
|
+
with source
|
|
1744
|
+
|
|
1745
|
+
${code}`);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
});
|
|
1749
|
+
pluginManager.on("executed", (executer) => {
|
|
1599
1750
|
const { hookName, plugin, output, parameters } = executer;
|
|
1600
1751
|
const messsage = `${randomPicoColour(plugin.name)} Executing ${hookName}`;
|
|
1601
|
-
if (logLevel === LogLevel.info) {
|
|
1602
|
-
if (
|
|
1752
|
+
if (logger.logLevel === LogLevel.info && logger.spinner) {
|
|
1753
|
+
if (hookName === "writeFile") {
|
|
1754
|
+
const [_code, path3] = parameters;
|
|
1755
|
+
logger.spinner.suffixText = pc3.dim(path3);
|
|
1756
|
+
} else {
|
|
1603
1757
|
logger.spinner.suffixText = messsage;
|
|
1604
1758
|
}
|
|
1605
1759
|
}
|
|
1606
|
-
if (logLevel === LogLevel.debug) {
|
|
1760
|
+
if (logger.logLevel === LogLevel.debug) {
|
|
1607
1761
|
logger.info(messsage);
|
|
1608
1762
|
const logs = [
|
|
1609
1763
|
parameters && `${pc3.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
|
|
@@ -1623,74 +1777,72 @@ async function build(options) {
|
|
|
1623
1777
|
parameters: [config]
|
|
1624
1778
|
});
|
|
1625
1779
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
return options;
|
|
1780
|
+
if (!fileManager.isExecuting && logger.spinner) {
|
|
1781
|
+
logger.spinner.suffixText = "";
|
|
1782
|
+
logger.spinner.succeed(`\u{1F4BE} Writing completed`);
|
|
1783
|
+
}
|
|
1784
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1632
1785
|
}
|
|
1633
1786
|
|
|
1634
|
-
// src/
|
|
1787
|
+
// src/Generator.ts
|
|
1788
|
+
var _options3, _context;
|
|
1635
1789
|
var Generator = class {
|
|
1636
|
-
#options = {};
|
|
1637
|
-
#context = {};
|
|
1638
1790
|
constructor(options, context) {
|
|
1791
|
+
__privateAdd(this, _options3, {});
|
|
1792
|
+
__privateAdd(this, _context, {});
|
|
1639
1793
|
if (context) {
|
|
1640
|
-
this
|
|
1794
|
+
__privateSet(this, _context, context);
|
|
1641
1795
|
}
|
|
1642
1796
|
if (options) {
|
|
1643
|
-
this
|
|
1797
|
+
__privateSet(this, _options3, options);
|
|
1644
1798
|
}
|
|
1645
1799
|
return this;
|
|
1646
1800
|
}
|
|
1647
1801
|
get options() {
|
|
1648
|
-
return this
|
|
1802
|
+
return __privateGet(this, _options3);
|
|
1649
1803
|
}
|
|
1650
1804
|
get context() {
|
|
1651
|
-
return this
|
|
1805
|
+
return __privateGet(this, _context);
|
|
1652
1806
|
}
|
|
1653
1807
|
set options(options) {
|
|
1654
|
-
this
|
|
1808
|
+
__privateSet(this, _options3, { ...__privateGet(this, _options3), ...options });
|
|
1655
1809
|
}
|
|
1656
1810
|
};
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
var
|
|
1660
|
-
|
|
1661
|
-
var PackageManager = class _PackageManager {
|
|
1662
|
-
static #cache = {};
|
|
1663
|
-
#cwd;
|
|
1664
|
-
#SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
|
|
1811
|
+
_options3 = new WeakMap();
|
|
1812
|
+
_context = new WeakMap();
|
|
1813
|
+
var _cache2, _cwd, _SLASHES;
|
|
1814
|
+
var _PackageManager = class _PackageManager {
|
|
1665
1815
|
constructor(workspace) {
|
|
1816
|
+
__privateAdd(this, _cwd, void 0);
|
|
1817
|
+
__privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
|
|
1666
1818
|
if (workspace) {
|
|
1667
|
-
this
|
|
1819
|
+
__privateSet(this, _cwd, workspace);
|
|
1668
1820
|
}
|
|
1669
1821
|
return this;
|
|
1670
1822
|
}
|
|
1671
1823
|
set workspace(workspace) {
|
|
1672
|
-
this
|
|
1824
|
+
__privateSet(this, _cwd, workspace);
|
|
1673
1825
|
}
|
|
1674
1826
|
get workspace() {
|
|
1675
|
-
return this
|
|
1827
|
+
return __privateGet(this, _cwd);
|
|
1676
1828
|
}
|
|
1677
1829
|
normalizeDirectory(directory) {
|
|
1678
|
-
if (!this
|
|
1830
|
+
if (!__privateGet(this, _SLASHES).has(directory[directory.length - 1])) {
|
|
1679
1831
|
return `${directory}/`;
|
|
1680
1832
|
}
|
|
1681
1833
|
return directory;
|
|
1682
1834
|
}
|
|
1683
|
-
getLocation(
|
|
1684
|
-
let location =
|
|
1685
|
-
if (this
|
|
1686
|
-
const require2 = mod.createRequire(this.normalizeDirectory(this
|
|
1687
|
-
location = require2.resolve(
|
|
1835
|
+
getLocation(path3) {
|
|
1836
|
+
let location = path3;
|
|
1837
|
+
if (__privateGet(this, _cwd)) {
|
|
1838
|
+
const require2 = mod.createRequire(this.normalizeDirectory(__privateGet(this, _cwd)));
|
|
1839
|
+
location = require2.resolve(path3);
|
|
1688
1840
|
}
|
|
1689
1841
|
return location;
|
|
1690
1842
|
}
|
|
1691
|
-
async import(
|
|
1843
|
+
async import(path3) {
|
|
1692
1844
|
try {
|
|
1693
|
-
let location = this.getLocation(
|
|
1845
|
+
let location = this.getLocation(path3);
|
|
1694
1846
|
if (os.platform() == "win32") {
|
|
1695
1847
|
location = pathToFileURL(location).href;
|
|
1696
1848
|
}
|
|
@@ -1703,7 +1855,7 @@ var PackageManager = class _PackageManager {
|
|
|
1703
1855
|
}
|
|
1704
1856
|
async getPackageJSON() {
|
|
1705
1857
|
const pkgPath = await findUp(["package.json"], {
|
|
1706
|
-
cwd: this
|
|
1858
|
+
cwd: __privateGet(this, _cwd)
|
|
1707
1859
|
});
|
|
1708
1860
|
if (!pkgPath) {
|
|
1709
1861
|
return void 0;
|
|
@@ -1712,7 +1864,7 @@ var PackageManager = class _PackageManager {
|
|
|
1712
1864
|
}
|
|
1713
1865
|
getPackageJSONSync() {
|
|
1714
1866
|
const pkgPath = findUpSync(["package.json"], {
|
|
1715
|
-
cwd: this
|
|
1867
|
+
cwd: __privateGet(this, _cwd)
|
|
1716
1868
|
});
|
|
1717
1869
|
if (!pkgPath) {
|
|
1718
1870
|
return void 0;
|
|
@@ -1720,11 +1872,11 @@ var PackageManager = class _PackageManager {
|
|
|
1720
1872
|
return __require(pkgPath);
|
|
1721
1873
|
}
|
|
1722
1874
|
static setVersion(dependency, version) {
|
|
1723
|
-
_PackageManager
|
|
1875
|
+
__privateGet(_PackageManager, _cache2)[dependency] = version;
|
|
1724
1876
|
}
|
|
1725
1877
|
async getVersion(dependency) {
|
|
1726
|
-
if (_PackageManager
|
|
1727
|
-
return _PackageManager
|
|
1878
|
+
if (__privateGet(_PackageManager, _cache2)[dependency]) {
|
|
1879
|
+
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
1728
1880
|
}
|
|
1729
1881
|
const packageJSON = await this.getPackageJSON();
|
|
1730
1882
|
if (!packageJSON) {
|
|
@@ -1733,8 +1885,8 @@ var PackageManager = class _PackageManager {
|
|
|
1733
1885
|
return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
|
|
1734
1886
|
}
|
|
1735
1887
|
getVersionSync(dependency) {
|
|
1736
|
-
if (_PackageManager
|
|
1737
|
-
return _PackageManager
|
|
1888
|
+
if (__privateGet(_PackageManager, _cache2)[dependency]) {
|
|
1889
|
+
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
1738
1890
|
}
|
|
1739
1891
|
const packageJSON = this.getPackageJSONSync();
|
|
1740
1892
|
if (!packageJSON) {
|
|
@@ -1765,10 +1917,19 @@ var PackageManager = class _PackageManager {
|
|
|
1765
1917
|
return satisfies(semVer, version);
|
|
1766
1918
|
}
|
|
1767
1919
|
};
|
|
1920
|
+
_cache2 = new WeakMap();
|
|
1921
|
+
_cwd = new WeakMap();
|
|
1922
|
+
_SLASHES = new WeakMap();
|
|
1923
|
+
__privateAdd(_PackageManager, _cache2, {});
|
|
1924
|
+
var PackageManager = _PackageManager;
|
|
1925
|
+
|
|
1926
|
+
// src/SchemaGenerator.ts
|
|
1927
|
+
var SchemaGenerator = class extends Generator {
|
|
1928
|
+
};
|
|
1768
1929
|
|
|
1769
1930
|
// src/index.ts
|
|
1770
1931
|
var src_default = build;
|
|
1771
1932
|
|
|
1772
|
-
export { FileManager,
|
|
1933
|
+
export { FileManager, Generator, KubbFile, PackageManager, ParallelPluginError, PluginError, PluginManager, PromiseManager, SchemaGenerator, SummaryError, ValidationPluginError, Warning, build, combineExports, combineImports, createPlugin, src_default as default, defineConfig, isInputPath, pluginName as name, pluginName };
|
|
1773
1934
|
//# sourceMappingURL=out.js.map
|
|
1774
1935
|
//# sourceMappingURL=index.js.map
|