@kubb/core 1.15.0-canary.20231027T200912 → 2.0.0-canary.20231027T203719
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1163 -1025
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +255 -313
- package/dist/index.d.ts +255 -313
- package/dist/index.js +1105 -958
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +1260 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +235 -0
- package/dist/utils.d.ts +235 -0
- package/dist/utils.js +1207 -0
- package/dist/utils.js.map +1 -0
- package/globals.d.ts +33 -16
- package/package.json +14 -9
package/dist/index.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,287 @@ 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 _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
675
|
+
var _FileManager = class _FileManager {
|
|
676
|
+
constructor(options) {
|
|
677
|
+
__privateAdd(this, _validate);
|
|
678
|
+
__privateAdd(this, _add);
|
|
679
|
+
__privateAdd(this, _addOrAppend);
|
|
680
|
+
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
|
|
681
|
+
__privateAdd(this, _task, void 0);
|
|
682
|
+
__privateAdd(this, _isWriting, false);
|
|
683
|
+
/**
|
|
684
|
+
* Timeout between writes
|
|
685
|
+
*/
|
|
686
|
+
__privateAdd(this, _timeout, 0);
|
|
687
|
+
__privateAdd(this, _queue, void 0);
|
|
688
|
+
if (options) {
|
|
689
|
+
__privateSet(this, _task, options.task);
|
|
690
|
+
__privateSet(this, _queue, options.queue);
|
|
691
|
+
__privateSet(this, _timeout, options.timeout || 0);
|
|
692
|
+
}
|
|
693
|
+
return this;
|
|
631
694
|
}
|
|
632
|
-
get
|
|
633
|
-
|
|
695
|
+
get files() {
|
|
696
|
+
const files = [];
|
|
697
|
+
__privateGet(this, _cache).forEach((item) => {
|
|
698
|
+
files.push(...item.flat(1));
|
|
699
|
+
});
|
|
700
|
+
return files;
|
|
634
701
|
}
|
|
635
|
-
get
|
|
636
|
-
return this
|
|
702
|
+
get isExecuting() {
|
|
703
|
+
return __privateGet(this, _queue)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
|
|
637
704
|
}
|
|
638
|
-
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
if (stringify) {
|
|
644
|
-
if (type !== "template") {
|
|
645
|
-
throw new Error("Type should be `template` when using stringiyf");
|
|
705
|
+
async add(...files) {
|
|
706
|
+
const promises = files.map((file) => {
|
|
707
|
+
__privateMethod(this, _validate, validate_fn).call(this, file);
|
|
708
|
+
if (file.override) {
|
|
709
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
646
710
|
}
|
|
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);
|
|
711
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
|
|
712
|
+
});
|
|
713
|
+
const resolvedFiles = await Promise.all(promises);
|
|
714
|
+
if (files.length > 1) {
|
|
715
|
+
return resolvedFiles;
|
|
667
716
|
}
|
|
668
|
-
return
|
|
717
|
+
return resolvedFiles[0];
|
|
669
718
|
}
|
|
670
|
-
|
|
671
|
-
const
|
|
672
|
-
const
|
|
673
|
-
if (!
|
|
719
|
+
async addIndexes({ root, extName = ".ts", meta, options = {} }) {
|
|
720
|
+
const barrelManager = new BarrelManager(options);
|
|
721
|
+
const files = barrelManager.getIndexes(root, extName);
|
|
722
|
+
if (!files) {
|
|
674
723
|
return void 0;
|
|
675
724
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
725
|
+
return await Promise.all(
|
|
726
|
+
files.map((file) => {
|
|
727
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
728
|
+
...file,
|
|
729
|
+
meta: meta ? meta : file.meta
|
|
730
|
+
});
|
|
731
|
+
})
|
|
732
|
+
);
|
|
683
733
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
return
|
|
734
|
+
getCacheByUUID(UUID) {
|
|
735
|
+
let cache;
|
|
736
|
+
__privateGet(this, _cache).forEach((files) => {
|
|
737
|
+
cache = files.find((item) => item.id === UUID);
|
|
738
|
+
});
|
|
739
|
+
return cache;
|
|
690
740
|
}
|
|
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";
|
|
741
|
+
get(path3) {
|
|
742
|
+
return __privateGet(this, _cache).get(path3);
|
|
698
743
|
}
|
|
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: []
|
|
744
|
+
remove(path3) {
|
|
745
|
+
const cacheItem = this.get(path3);
|
|
746
|
+
if (!cacheItem) {
|
|
747
|
+
return;
|
|
741
748
|
}
|
|
742
|
-
|
|
743
|
-
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...options });
|
|
744
|
-
if (!tree) {
|
|
745
|
-
return null;
|
|
749
|
+
__privateGet(this, _cache).delete(path3);
|
|
746
750
|
}
|
|
747
|
-
|
|
748
|
-
if (!
|
|
749
|
-
|
|
751
|
+
async write(...params) {
|
|
752
|
+
if (!__privateGet(this, _isWriting)) {
|
|
753
|
+
__privateSet(this, _isWriting, true);
|
|
754
|
+
const text = await write(...params);
|
|
755
|
+
__privateSet(this, _isWriting, false);
|
|
756
|
+
return text;
|
|
750
757
|
}
|
|
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
|
-
});
|
|
758
|
+
await timeout(__privateGet(this, _timeout));
|
|
759
|
+
return this.write(...params);
|
|
760
|
+
}
|
|
761
|
+
async read(...params) {
|
|
762
|
+
return read(...params);
|
|
763
|
+
}
|
|
764
|
+
// statics
|
|
765
|
+
static getSource(file) {
|
|
766
|
+
if (!_FileManager.isExtensionAllowed(file.baseName)) {
|
|
767
|
+
return file.source;
|
|
780
768
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
769
|
+
const exports = file.exports ? combineExports(file.exports) : [];
|
|
770
|
+
const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
|
|
771
|
+
const importNodes = imports.map((item) => factory.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
772
|
+
const exportNodes = exports.map(
|
|
773
|
+
(item) => factory.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias })
|
|
774
|
+
);
|
|
775
|
+
return [print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
776
|
+
}
|
|
777
|
+
static combineFiles(files) {
|
|
778
|
+
return files.filter(Boolean).reduce((acc, file) => {
|
|
779
|
+
const prevIndex = acc.findIndex((item) => item.path === file.path);
|
|
780
|
+
if (prevIndex === -1) {
|
|
781
|
+
return [...acc, file];
|
|
782
|
+
}
|
|
793
783
|
const prev = acc[prevIndex];
|
|
784
|
+
if (prev && file.override) {
|
|
785
|
+
acc[prevIndex] = {
|
|
786
|
+
imports: [],
|
|
787
|
+
exports: [],
|
|
788
|
+
...file
|
|
789
|
+
};
|
|
790
|
+
return acc;
|
|
791
|
+
}
|
|
794
792
|
if (prev) {
|
|
795
793
|
acc[prevIndex] = {
|
|
796
|
-
...
|
|
797
|
-
source: prev.source &&
|
|
798
|
-
${
|
|
799
|
-
imports: [...prev.imports || [], ...
|
|
800
|
-
exports: [...prev.exports || [], ...
|
|
801
|
-
env: { ...prev.env || {}, ...
|
|
794
|
+
...file,
|
|
795
|
+
source: prev.source && file.source ? `${prev.source}
|
|
796
|
+
${file.source}` : "",
|
|
797
|
+
imports: [...prev.imports || [], ...file.imports || []],
|
|
798
|
+
exports: [...prev.exports || [], ...file.exports || []],
|
|
799
|
+
env: { ...prev.env || {}, ...file.env || {} }
|
|
802
800
|
};
|
|
803
801
|
}
|
|
804
|
-
|
|
805
|
-
|
|
802
|
+
return acc;
|
|
803
|
+
}, []);
|
|
804
|
+
}
|
|
805
|
+
static getMode(path3) {
|
|
806
|
+
if (!path3) {
|
|
807
|
+
return "directory";
|
|
806
808
|
}
|
|
807
|
-
return
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
809
|
+
return extname(path3) ? "file" : "directory";
|
|
810
|
+
}
|
|
811
|
+
static get extensions() {
|
|
812
|
+
return [".js", ".ts", ".tsx"];
|
|
813
|
+
}
|
|
814
|
+
static isExtensionAllowed(baseName) {
|
|
815
|
+
return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
_cache = new WeakMap();
|
|
819
|
+
_task = new WeakMap();
|
|
820
|
+
_isWriting = new WeakMap();
|
|
821
|
+
_timeout = new WeakMap();
|
|
822
|
+
_queue = new WeakMap();
|
|
823
|
+
_validate = new WeakSet();
|
|
824
|
+
validate_fn = function(file) {
|
|
825
|
+
if (!file.validate) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
|
|
829
|
+
throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
_add = new WeakSet();
|
|
833
|
+
add_fn = async function(file) {
|
|
834
|
+
const controller = new AbortController();
|
|
835
|
+
const resolvedFile = { id: crypto2.randomUUID(), ...file };
|
|
836
|
+
__privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
837
|
+
if (__privateGet(this, _queue)) {
|
|
838
|
+
await __privateGet(this, _queue).run(
|
|
839
|
+
async () => {
|
|
840
|
+
var _a;
|
|
841
|
+
return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
|
|
842
|
+
},
|
|
843
|
+
{ controller }
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
return resolvedFile;
|
|
847
|
+
};
|
|
848
|
+
_addOrAppend = new WeakSet();
|
|
849
|
+
addOrAppend_fn = async function(file) {
|
|
850
|
+
const previousCaches = __privateGet(this, _cache).get(file.path);
|
|
851
|
+
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
852
|
+
if (previousCache) {
|
|
853
|
+
__privateGet(this, _cache).delete(previousCache.path);
|
|
854
|
+
return __privateMethod(this, _add, add_fn).call(this, {
|
|
855
|
+
...file,
|
|
856
|
+
source: previousCache.source && file.source ? `${previousCache.source}
|
|
857
|
+
${file.source}` : "",
|
|
858
|
+
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
859
|
+
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
860
|
+
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
864
|
+
};
|
|
865
|
+
var FileManager = _FileManager;
|
|
814
866
|
function combineExports(exports) {
|
|
815
|
-
|
|
867
|
+
const combinedExports = orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
816
868
|
const name = curr.name;
|
|
817
869
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
870
|
+
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly);
|
|
871
|
+
if (prevByPathAndIsTypeOnly) {
|
|
872
|
+
return prev;
|
|
873
|
+
}
|
|
818
874
|
const uniquePrev = prev.findLast(
|
|
819
875
|
(imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
820
876
|
);
|
|
@@ -836,12 +892,16 @@ function combineExports(exports) {
|
|
|
836
892
|
}
|
|
837
893
|
return [...prev, curr];
|
|
838
894
|
}, []);
|
|
895
|
+
return orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
839
896
|
}
|
|
840
897
|
function combineImports(imports, exports, source) {
|
|
841
|
-
|
|
898
|
+
const combinedImports = orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
842
899
|
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
843
900
|
const hasImportInSource = (importName) => {
|
|
844
|
-
|
|
901
|
+
if (!source) {
|
|
902
|
+
return true;
|
|
903
|
+
}
|
|
904
|
+
const checker = (name2) => name2 && !!source.includes(name2);
|
|
845
905
|
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
846
906
|
};
|
|
847
907
|
if (Array.isArray(name)) {
|
|
@@ -849,6 +909,10 @@ function combineImports(imports, exports, source) {
|
|
|
849
909
|
}
|
|
850
910
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
851
911
|
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
912
|
+
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly);
|
|
913
|
+
if (prevByPathNameAndIsTypeOnly) {
|
|
914
|
+
return prev;
|
|
915
|
+
}
|
|
852
916
|
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
853
917
|
return prev;
|
|
854
918
|
}
|
|
@@ -870,43 +934,7 @@ function combineImports(imports, exports, source) {
|
|
|
870
934
|
}
|
|
871
935
|
return [...prev, curr];
|
|
872
936
|
}, []);
|
|
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);
|
|
937
|
+
return orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
|
|
910
938
|
}
|
|
911
939
|
function getEnvSource(source, env) {
|
|
912
940
|
if (!env) {
|
|
@@ -923,132 +951,128 @@ function getEnvSource(source, env) {
|
|
|
923
951
|
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
924
952
|
}
|
|
925
953
|
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).*
|
|
954
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
955
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
928
956
|
`, "ig"), ""), replaceBy, key });
|
|
929
957
|
}
|
|
930
958
|
return prev;
|
|
931
959
|
}, source);
|
|
932
960
|
}
|
|
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;
|
|
961
|
+
var _emitter;
|
|
962
|
+
var EventEmitter = class {
|
|
963
|
+
constructor() {
|
|
964
|
+
__privateAdd(this, _emitter, new EventEmitter$1());
|
|
965
|
+
__privateGet(this, _emitter).setMaxListeners(100);
|
|
945
966
|
}
|
|
946
|
-
|
|
947
|
-
|
|
967
|
+
emit(eventName, ...eventArg) {
|
|
968
|
+
__privateGet(this, _emitter).emit(eventName, ...eventArg);
|
|
948
969
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
this.#cache.forEach((item) => {
|
|
952
|
-
files.push(...item.flat(1));
|
|
953
|
-
});
|
|
954
|
-
return files;
|
|
970
|
+
on(eventName, handler) {
|
|
971
|
+
__privateGet(this, _emitter).on(eventName, handler);
|
|
955
972
|
}
|
|
956
|
-
|
|
957
|
-
|
|
973
|
+
off(eventName, handler) {
|
|
974
|
+
__privateGet(this, _emitter).off(eventName, handler);
|
|
958
975
|
}
|
|
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;
|
|
976
|
+
removeAll() {
|
|
977
|
+
__privateGet(this, _emitter).removeAllListeners();
|
|
976
978
|
}
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
979
|
+
};
|
|
980
|
+
_emitter = new WeakMap();
|
|
981
|
+
var _queue2, _workerCount, _maxParallel, _debug, _work, work_fn;
|
|
982
|
+
var Queue = class {
|
|
983
|
+
constructor(maxParallel, debug = false) {
|
|
984
|
+
__privateAdd(this, _work);
|
|
985
|
+
__privateAdd(this, _queue2, []);
|
|
986
|
+
this.eventEmitter = new EventEmitter();
|
|
987
|
+
__privateAdd(this, _workerCount, 0);
|
|
988
|
+
__privateAdd(this, _maxParallel, void 0);
|
|
989
|
+
__privateAdd(this, _debug, false);
|
|
990
|
+
__privateSet(this, _maxParallel, maxParallel);
|
|
991
|
+
__privateSet(this, _debug, debug);
|
|
992
|
+
}
|
|
993
|
+
run(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
|
|
994
|
+
return new Promise((resolve2, reject) => {
|
|
995
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
996
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
997
|
+
__privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
|
|
998
|
+
reject("Aborted");
|
|
989
999
|
});
|
|
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]);
|
|
1000
|
+
__privateGet(this, _queue2).push(item);
|
|
1001
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
1002
|
+
});
|
|
1010
1003
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1004
|
+
runSync(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
|
|
1005
|
+
new Promise((resolve2, reject) => {
|
|
1006
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
1007
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
1008
|
+
__privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
|
|
1009
|
+
});
|
|
1010
|
+
__privateGet(this, _queue2).push(item);
|
|
1011
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
1015
1012
|
});
|
|
1016
|
-
return cache;
|
|
1017
1013
|
}
|
|
1018
|
-
get(
|
|
1019
|
-
return this
|
|
1014
|
+
get hasJobs() {
|
|
1015
|
+
return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue2).length > 0;
|
|
1020
1016
|
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
if (!cacheItem) {
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
this.#cache.delete(path);
|
|
1017
|
+
get count() {
|
|
1018
|
+
return __privateGet(this, _workerCount);
|
|
1027
1019
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1020
|
+
};
|
|
1021
|
+
_queue2 = new WeakMap();
|
|
1022
|
+
_workerCount = new WeakMap();
|
|
1023
|
+
_maxParallel = new WeakMap();
|
|
1024
|
+
_debug = new WeakMap();
|
|
1025
|
+
_work = new WeakSet();
|
|
1026
|
+
work_fn = function() {
|
|
1027
|
+
if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
__privateWrapper(this, _workerCount)._++;
|
|
1031
|
+
let entry;
|
|
1032
|
+
while (entry = __privateGet(this, _queue2).shift()) {
|
|
1033
|
+
const { reject, resolve: resolve2, job, name, description } = entry;
|
|
1034
|
+
if (__privateGet(this, _debug)) {
|
|
1035
|
+
performance.mark(name + "_start");
|
|
1036
|
+
}
|
|
1037
|
+
job().then((result) => {
|
|
1038
|
+
this.eventEmitter.emit("jobDone", result);
|
|
1039
|
+
resolve2(result);
|
|
1040
|
+
if (__privateGet(this, _debug)) {
|
|
1041
|
+
performance.mark(name + "_stop");
|
|
1042
|
+
performance.measure(description, name + "_start", name + "_stop");
|
|
1043
|
+
}
|
|
1044
|
+
}).catch((err) => {
|
|
1045
|
+
this.eventEmitter.emit("jobFailed", err);
|
|
1046
|
+
reject(err);
|
|
1047
|
+
});
|
|
1035
1048
|
}
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1049
|
+
__privateWrapper(this, _workerCount)._--;
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1052
|
+
// src/utils/uniqueName.ts
|
|
1053
|
+
function setUniqueName(originalName, data) {
|
|
1054
|
+
let used = data[originalName] || 0;
|
|
1055
|
+
if (used) {
|
|
1056
|
+
data[originalName] = ++used;
|
|
1057
|
+
return originalName;
|
|
1058
|
+
}
|
|
1059
|
+
data[originalName] = 1;
|
|
1060
|
+
return originalName;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// src/errors.ts
|
|
1064
|
+
var PluginError = class extends Error {
|
|
1065
|
+
constructor(message, options) {
|
|
1066
|
+
super(message, { cause: options.cause });
|
|
1067
|
+
this.name = "PluginError";
|
|
1068
|
+
this.cause = options.cause;
|
|
1069
|
+
this.pluginManager = options.pluginManager;
|
|
1043
1070
|
}
|
|
1044
1071
|
};
|
|
1045
|
-
|
|
1046
|
-
// src/managers/pluginManager/ParallelPluginError.ts
|
|
1047
1072
|
var ParallelPluginError = class extends Error {
|
|
1048
|
-
errors = [];
|
|
1049
|
-
pluginManager;
|
|
1050
1073
|
constructor(message, options) {
|
|
1051
1074
|
super(message, { cause: options.cause });
|
|
1075
|
+
this.errors = [];
|
|
1052
1076
|
this.name = "ParallelPluginError";
|
|
1053
1077
|
this.errors = options.errors;
|
|
1054
1078
|
this.pluginManager = options.pluginManager;
|
|
@@ -1068,30 +1092,54 @@ var ParallelPluginError = class extends Error {
|
|
|
1068
1092
|
})?.cause;
|
|
1069
1093
|
}
|
|
1070
1094
|
};
|
|
1071
|
-
|
|
1072
|
-
// src/managers/pluginManager/PluginError.ts
|
|
1073
|
-
var PluginError = class extends Error {
|
|
1074
|
-
pluginManager;
|
|
1075
|
-
cause;
|
|
1095
|
+
var SummaryError = class extends Error {
|
|
1076
1096
|
constructor(message, options) {
|
|
1077
1097
|
super(message, { cause: options.cause });
|
|
1078
|
-
this.name = "
|
|
1079
|
-
this.
|
|
1080
|
-
this.pluginManager = options.pluginManager;
|
|
1098
|
+
this.name = "SummaryError";
|
|
1099
|
+
this.summary = options.summary || [];
|
|
1081
1100
|
}
|
|
1082
1101
|
};
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1102
|
+
var Warning = class extends Error {
|
|
1103
|
+
constructor(message, options) {
|
|
1104
|
+
super(message, { cause: options?.cause });
|
|
1105
|
+
this.name = "Warning";
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
var ValidationPluginError = class extends Error {
|
|
1109
|
+
};
|
|
1110
|
+
|
|
1111
|
+
// src/utils/cache.ts
|
|
1112
|
+
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
1113
|
+
return {
|
|
1114
|
+
set(id, value) {
|
|
1115
|
+
Store[id] = [0, value];
|
|
1116
|
+
},
|
|
1117
|
+
get(id) {
|
|
1118
|
+
const item = Store[id];
|
|
1119
|
+
if (!item) {
|
|
1120
|
+
return null;
|
|
1121
|
+
}
|
|
1122
|
+
item[0] = 0;
|
|
1123
|
+
return item[1];
|
|
1124
|
+
},
|
|
1125
|
+
has(id) {
|
|
1126
|
+
const item = Store[id];
|
|
1127
|
+
if (!item) {
|
|
1128
|
+
return false;
|
|
1129
|
+
}
|
|
1130
|
+
item[0] = 0;
|
|
1131
|
+
return true;
|
|
1132
|
+
},
|
|
1133
|
+
delete(id) {
|
|
1134
|
+
return delete Store[id];
|
|
1093
1135
|
}
|
|
1094
|
-
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
// src/plugin.ts
|
|
1140
|
+
function createPlugin(factory2) {
|
|
1141
|
+
return (options) => {
|
|
1142
|
+
return factory2(options);
|
|
1095
1143
|
};
|
|
1096
1144
|
}
|
|
1097
1145
|
var pluginName = "core";
|
|
@@ -1100,6 +1148,8 @@ var definePlugin = createPlugin((options) => {
|
|
|
1100
1148
|
return {
|
|
1101
1149
|
name: pluginName,
|
|
1102
1150
|
options,
|
|
1151
|
+
key: ["controller", "core"],
|
|
1152
|
+
kind: "controller",
|
|
1103
1153
|
api() {
|
|
1104
1154
|
return {
|
|
1105
1155
|
get config() {
|
|
@@ -1108,18 +1158,18 @@ var definePlugin = createPlugin((options) => {
|
|
|
1108
1158
|
get plugins() {
|
|
1109
1159
|
return options.getPlugins();
|
|
1110
1160
|
},
|
|
1161
|
+
get plugin() {
|
|
1162
|
+
return options.plugin;
|
|
1163
|
+
},
|
|
1111
1164
|
logger,
|
|
1112
1165
|
fileManager,
|
|
1113
1166
|
pluginManager,
|
|
1114
1167
|
async addFile(...files) {
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
return fileManager.addOrAppend(file);
|
|
1121
|
-
})
|
|
1122
|
-
);
|
|
1168
|
+
const resolvedFiles = await fileManager.add(...files);
|
|
1169
|
+
if (!Array.isArray(resolvedFiles)) {
|
|
1170
|
+
return [resolvedFiles];
|
|
1171
|
+
}
|
|
1172
|
+
return resolvedFiles;
|
|
1123
1173
|
},
|
|
1124
1174
|
resolvePath,
|
|
1125
1175
|
resolveName,
|
|
@@ -1127,75 +1177,133 @@ var definePlugin = createPlugin((options) => {
|
|
|
1127
1177
|
};
|
|
1128
1178
|
},
|
|
1129
1179
|
resolvePath(baseName) {
|
|
1130
|
-
const root =
|
|
1131
|
-
return
|
|
1180
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
1181
|
+
return path.resolve(root, baseName);
|
|
1132
1182
|
},
|
|
1133
1183
|
resolveName(name) {
|
|
1134
1184
|
return name;
|
|
1135
1185
|
}
|
|
1136
1186
|
};
|
|
1137
1187
|
});
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1188
|
+
|
|
1189
|
+
// src/utils/executeStrategies.ts
|
|
1190
|
+
function hookSeq(promises) {
|
|
1191
|
+
return promises.reduce(
|
|
1192
|
+
(promise, func) => {
|
|
1193
|
+
if (!func || typeof func !== "function") {
|
|
1194
|
+
throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
1195
|
+
}
|
|
1196
|
+
return promise.then((result) => {
|
|
1197
|
+
const calledFunc = func();
|
|
1198
|
+
if (calledFunc) {
|
|
1199
|
+
return calledFunc.then(Array.prototype.concat.bind(result));
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
},
|
|
1203
|
+
Promise.resolve([])
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
// src/PromiseManager.ts
|
|
1208
|
+
var _options2;
|
|
1209
|
+
var PromiseManager = class {
|
|
1210
|
+
constructor(options = {}) {
|
|
1211
|
+
__privateAdd(this, _options2, {});
|
|
1212
|
+
__privateSet(this, _options2, options);
|
|
1213
|
+
return this;
|
|
1151
1214
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1215
|
+
run(strategy, promises) {
|
|
1216
|
+
if (strategy === "seq") {
|
|
1217
|
+
return hookSeq(promises);
|
|
1218
|
+
}
|
|
1219
|
+
throw new Error(`${strategy} not implemented`);
|
|
1154
1220
|
}
|
|
1155
1221
|
};
|
|
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
|
-
};
|
|
1222
|
+
_options2 = new WeakMap();
|
|
1223
|
+
function isPromise(result) {
|
|
1224
|
+
return !!result && typeof result?.then === "function";
|
|
1225
|
+
}
|
|
1226
|
+
function isPromiseRejectedResult(result) {
|
|
1227
|
+
return result.status === "rejected";
|
|
1173
1228
|
}
|
|
1174
1229
|
|
|
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);
|
|
1230
|
+
// src/PluginManager.ts
|
|
1231
|
+
var _core, _usedPluginNames, _promiseManager, _getSortedPlugins, getSortedPlugins_fn, _addExecutedToCallStack, addExecutedToCallStack_fn, _execute, execute_fn, _executeSync, executeSync_fn, _catcher, catcher_fn, _parse, parse_fn;
|
|
1187
1232
|
var PluginManager = class {
|
|
1188
|
-
plugins;
|
|
1189
|
-
fileManager;
|
|
1190
|
-
eventEmitter = new EventEmitter();
|
|
1191
|
-
queue;
|
|
1192
|
-
executed = [];
|
|
1193
|
-
logger;
|
|
1194
|
-
#core;
|
|
1195
1233
|
constructor(config, options) {
|
|
1234
|
+
__privateAdd(this, _getSortedPlugins);
|
|
1235
|
+
__privateAdd(this, _addExecutedToCallStack);
|
|
1236
|
+
/**
|
|
1237
|
+
* Run an async plugin hook and return the result.
|
|
1238
|
+
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
1239
|
+
* @param args Arguments passed to the plugin hook.
|
|
1240
|
+
* @param plugin The actual pluginObject to run.
|
|
1241
|
+
*/
|
|
1242
|
+
// Implementation signature
|
|
1243
|
+
__privateAdd(this, _execute);
|
|
1244
|
+
/**
|
|
1245
|
+
* Run a sync plugin hook and return the result.
|
|
1246
|
+
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
1247
|
+
* @param args Arguments passed to the plugin hook.
|
|
1248
|
+
* @param plugin The acutal plugin
|
|
1249
|
+
* @param replaceContext When passed, the plugin context can be overridden.
|
|
1250
|
+
*/
|
|
1251
|
+
__privateAdd(this, _executeSync);
|
|
1252
|
+
__privateAdd(this, _catcher);
|
|
1253
|
+
__privateAdd(this, _parse);
|
|
1254
|
+
this.eventEmitter = new EventEmitter();
|
|
1255
|
+
this.executed = [];
|
|
1256
|
+
__privateAdd(this, _core, void 0);
|
|
1257
|
+
__privateAdd(this, _usedPluginNames, {});
|
|
1258
|
+
__privateAdd(this, _promiseManager, void 0);
|
|
1259
|
+
this.resolvePath = (params) => {
|
|
1260
|
+
if (params.pluginKey) {
|
|
1261
|
+
const paths = this.hookForPluginSync({
|
|
1262
|
+
pluginKey: params.pluginKey,
|
|
1263
|
+
hookName: "resolvePath",
|
|
1264
|
+
parameters: [params.baseName, params.directory, params.options]
|
|
1265
|
+
});
|
|
1266
|
+
if (paths && paths?.length > 1) {
|
|
1267
|
+
throw new Error(
|
|
1268
|
+
`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1269
|
+
|
|
1270
|
+
Paths: ${JSON.stringify(paths, void 0, 2)}`
|
|
1271
|
+
);
|
|
1272
|
+
}
|
|
1273
|
+
return paths?.at(0);
|
|
1274
|
+
}
|
|
1275
|
+
return this.hookFirstSync({
|
|
1276
|
+
hookName: "resolvePath",
|
|
1277
|
+
parameters: [params.baseName, params.directory, params.options]
|
|
1278
|
+
}).result;
|
|
1279
|
+
};
|
|
1280
|
+
this.resolveName = (params) => {
|
|
1281
|
+
if (params.pluginKey) {
|
|
1282
|
+
const names = this.hookForPluginSync({
|
|
1283
|
+
pluginKey: params.pluginKey,
|
|
1284
|
+
hookName: "resolveName",
|
|
1285
|
+
parameters: [params.name, params.type]
|
|
1286
|
+
});
|
|
1287
|
+
if (names && names?.length > 1) {
|
|
1288
|
+
throw new Error(
|
|
1289
|
+
`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1290
|
+
|
|
1291
|
+
Names: ${JSON.stringify(names, void 0, 2)}`
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
return transformReservedWord(names?.at(0) || params.name);
|
|
1295
|
+
}
|
|
1296
|
+
const name = this.hookFirstSync({
|
|
1297
|
+
hookName: "resolveName",
|
|
1298
|
+
parameters: [params.name, params.type]
|
|
1299
|
+
}).result;
|
|
1300
|
+
return transformReservedWord(name);
|
|
1301
|
+
};
|
|
1196
1302
|
this.logger = options.logger;
|
|
1197
|
-
this.queue = new Queue(100,
|
|
1198
|
-
this.fileManager = new FileManager({ task: options.task, queue: this.queue });
|
|
1303
|
+
this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
|
|
1304
|
+
this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
|
|
1305
|
+
__privateSet(this, _promiseManager, new PromiseManager());
|
|
1306
|
+
const plugins = config.plugins || [];
|
|
1199
1307
|
const core = definePlugin({
|
|
1200
1308
|
config,
|
|
1201
1309
|
logger: this.logger,
|
|
@@ -1203,44 +1311,14 @@ var PluginManager = class {
|
|
|
1203
1311
|
fileManager: this.fileManager,
|
|
1204
1312
|
resolvePath: this.resolvePath.bind(this),
|
|
1205
1313
|
resolveName: this.resolveName.bind(this),
|
|
1206
|
-
getPlugins: this
|
|
1207
|
-
|
|
1314
|
+
getPlugins: __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).bind(this)
|
|
1315
|
+
});
|
|
1316
|
+
__privateSet(this, _core, __privateMethod(this, _parse, parse_fn).call(this, core, this, core.api.call(null)));
|
|
1317
|
+
this.plugins = [__privateGet(this, _core), ...plugins].map((plugin) => {
|
|
1318
|
+
return __privateMethod(this, _parse, parse_fn).call(this, plugin, this, __privateGet(this, _core).api);
|
|
1208
1319
|
});
|
|
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
1320
|
return this;
|
|
1215
1321
|
}
|
|
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
1322
|
on(eventName, handler) {
|
|
1245
1323
|
this.eventEmitter.on(eventName, handler);
|
|
1246
1324
|
}
|
|
@@ -1248,30 +1326,35 @@ var PluginManager = class {
|
|
|
1248
1326
|
* Run only hook for a specific plugin name
|
|
1249
1327
|
*/
|
|
1250
1328
|
hookForPlugin({
|
|
1251
|
-
|
|
1329
|
+
pluginKey,
|
|
1252
1330
|
hookName,
|
|
1253
1331
|
parameters
|
|
1254
1332
|
}) {
|
|
1255
|
-
const
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1333
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1334
|
+
const promises = plugins.map((plugin) => {
|
|
1335
|
+
return __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1336
|
+
strategy: "hookFirst",
|
|
1337
|
+
hookName,
|
|
1338
|
+
parameters,
|
|
1339
|
+
plugin
|
|
1340
|
+
});
|
|
1341
|
+
}).filter(Boolean);
|
|
1342
|
+
return Promise.all(promises);
|
|
1262
1343
|
}
|
|
1263
1344
|
hookForPluginSync({
|
|
1264
|
-
|
|
1345
|
+
pluginKey,
|
|
1265
1346
|
hookName,
|
|
1266
1347
|
parameters
|
|
1267
1348
|
}) {
|
|
1268
|
-
const
|
|
1269
|
-
return
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1349
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1350
|
+
return plugins.map((plugin) => {
|
|
1351
|
+
return __privateMethod(this, _executeSync, executeSync_fn).call(this, {
|
|
1352
|
+
strategy: "hookFirst",
|
|
1353
|
+
hookName,
|
|
1354
|
+
parameters,
|
|
1355
|
+
plugin
|
|
1356
|
+
});
|
|
1357
|
+
}).filter(Boolean);
|
|
1275
1358
|
}
|
|
1276
1359
|
/**
|
|
1277
1360
|
* Chains, first non-null result stops and returns
|
|
@@ -1282,7 +1365,7 @@ var PluginManager = class {
|
|
|
1282
1365
|
skipped
|
|
1283
1366
|
}) {
|
|
1284
1367
|
let promise = Promise.resolve(null);
|
|
1285
|
-
for (const plugin of this
|
|
1368
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1286
1369
|
if (skipped && skipped.has(plugin)) {
|
|
1287
1370
|
continue;
|
|
1288
1371
|
}
|
|
@@ -1290,7 +1373,7 @@ var PluginManager = class {
|
|
|
1290
1373
|
if (parseResult?.result != null) {
|
|
1291
1374
|
return parseResult;
|
|
1292
1375
|
}
|
|
1293
|
-
const value = await this
|
|
1376
|
+
const value = await __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1294
1377
|
strategy: "hookFirst",
|
|
1295
1378
|
hookName,
|
|
1296
1379
|
parameters,
|
|
@@ -1315,12 +1398,12 @@ var PluginManager = class {
|
|
|
1315
1398
|
skipped
|
|
1316
1399
|
}) {
|
|
1317
1400
|
let parseResult = null;
|
|
1318
|
-
for (const plugin of this
|
|
1401
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1319
1402
|
if (skipped && skipped.has(plugin)) {
|
|
1320
1403
|
continue;
|
|
1321
1404
|
}
|
|
1322
1405
|
parseResult = {
|
|
1323
|
-
result: this
|
|
1406
|
+
result: __privateMethod(this, _executeSync, executeSync_fn).call(this, {
|
|
1324
1407
|
strategy: "hookFirst",
|
|
1325
1408
|
hookName,
|
|
1326
1409
|
parameters,
|
|
@@ -1342,8 +1425,8 @@ var PluginManager = class {
|
|
|
1342
1425
|
parameters
|
|
1343
1426
|
}) {
|
|
1344
1427
|
const parallelPromises = [];
|
|
1345
|
-
for (const plugin of this
|
|
1346
|
-
const promise = this
|
|
1428
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1429
|
+
const promise = __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
|
|
1347
1430
|
if (promise) {
|
|
1348
1431
|
parallelPromises.push(promise);
|
|
1349
1432
|
}
|
|
@@ -1370,16 +1453,16 @@ var PluginManager = class {
|
|
|
1370
1453
|
}) {
|
|
1371
1454
|
const [argument0, ...rest] = parameters;
|
|
1372
1455
|
let promise = Promise.resolve(argument0);
|
|
1373
|
-
for (const plugin of this
|
|
1456
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1374
1457
|
promise = promise.then((arg0) => {
|
|
1375
|
-
const value = this
|
|
1458
|
+
const value = __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1376
1459
|
strategy: "hookReduceArg0",
|
|
1377
1460
|
hookName,
|
|
1378
1461
|
parameters: [arg0, ...rest],
|
|
1379
1462
|
plugin
|
|
1380
1463
|
});
|
|
1381
1464
|
return value;
|
|
1382
|
-
}).then((result) => reduce.call(this
|
|
1465
|
+
}).then((result) => reduce.call(__privateGet(this, _core).api, argument0, result, plugin));
|
|
1383
1466
|
}
|
|
1384
1467
|
return promise;
|
|
1385
1468
|
}
|
|
@@ -1387,160 +1470,192 @@ var PluginManager = class {
|
|
|
1387
1470
|
* Chains plugins
|
|
1388
1471
|
*/
|
|
1389
1472
|
hookSeq({ hookName, parameters }) {
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
parameters,
|
|
1397
|
-
plugin
|
|
1398
|
-
});
|
|
1473
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1474
|
+
return () => __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1475
|
+
strategy: "hookSeq",
|
|
1476
|
+
hookName,
|
|
1477
|
+
parameters,
|
|
1478
|
+
plugin
|
|
1399
1479
|
});
|
|
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;
|
|
1480
|
+
});
|
|
1481
|
+
return __privateGet(this, _promiseManager).run("seq", promises);
|
|
1409
1482
|
}
|
|
1410
|
-
|
|
1483
|
+
getPluginsByKey(hookName, pluginKey) {
|
|
1411
1484
|
const plugins = [...this.plugins];
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
|
|
1485
|
+
const [searchKind, searchPluginName, searchIdentifier] = pluginKey;
|
|
1486
|
+
const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
|
|
1487
|
+
const [kind, name, identifier] = item.key;
|
|
1488
|
+
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
1489
|
+
const kindCheck = kind === searchKind;
|
|
1490
|
+
const nameCheck = name === searchPluginName;
|
|
1491
|
+
if (searchIdentifier) {
|
|
1492
|
+
return identifierCheck && kindCheck && nameCheck;
|
|
1493
|
+
}
|
|
1494
|
+
return kindCheck && nameCheck;
|
|
1495
|
+
});
|
|
1496
|
+
if (!pluginByPluginName?.length) {
|
|
1497
|
+
const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
|
|
1498
|
+
if (this.logger.logLevel === "info") {
|
|
1499
|
+
if (corePlugin) {
|
|
1500
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
|
|
1501
|
+
} else {
|
|
1502
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
return corePlugin ? [corePlugin] : [];
|
|
1415
1506
|
}
|
|
1416
1507
|
return pluginByPluginName;
|
|
1417
1508
|
}
|
|
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;
|
|
1509
|
+
static getDependedPlugins(plugins, dependedPluginNames) {
|
|
1510
|
+
let pluginNames = [];
|
|
1511
|
+
if (typeof dependedPluginNames === "string") {
|
|
1512
|
+
pluginNames = [dependedPluginNames];
|
|
1513
|
+
} else {
|
|
1514
|
+
pluginNames = dependedPluginNames;
|
|
1441
1515
|
}
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
if (
|
|
1445
|
-
|
|
1446
|
-
if (isPromise(possiblePromiseResult)) {
|
|
1447
|
-
return Promise.resolve(possiblePromiseResult);
|
|
1448
|
-
}
|
|
1449
|
-
return possiblePromiseResult;
|
|
1516
|
+
return pluginNames.map((pluginName2) => {
|
|
1517
|
+
const plugin = plugins.find((plugin2) => plugin2.name === pluginName2);
|
|
1518
|
+
if (!plugin) {
|
|
1519
|
+
throw new ValidationPluginError(`This plugin depends on the ${pluginName2} plugin.`);
|
|
1450
1520
|
}
|
|
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
|
-
});
|
|
1521
|
+
return plugin;
|
|
1466
1522
|
});
|
|
1467
|
-
return task;
|
|
1468
1523
|
}
|
|
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;
|
|
1524
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
1525
|
+
static get hooks() {
|
|
1526
|
+
return ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
_core = new WeakMap();
|
|
1530
|
+
_usedPluginNames = new WeakMap();
|
|
1531
|
+
_promiseManager = new WeakMap();
|
|
1532
|
+
_getSortedPlugins = new WeakSet();
|
|
1533
|
+
getSortedPlugins_fn = function(hookName) {
|
|
1534
|
+
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1535
|
+
if (hookName) {
|
|
1536
|
+
if (this.logger.logLevel === "info") {
|
|
1537
|
+
const containsHookName = plugins.some((item) => item[hookName]);
|
|
1538
|
+
if (!containsHookName) {
|
|
1539
|
+
this.logger.warn(`No hook ${hookName} found`);
|
|
1493
1540
|
}
|
|
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
1541
|
}
|
|
1542
|
+
return plugins.filter((item) => item[hookName]);
|
|
1508
1543
|
}
|
|
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
|
-
}
|
|
1544
|
+
return plugins;
|
|
1516
1545
|
};
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1546
|
+
_addExecutedToCallStack = new WeakSet();
|
|
1547
|
+
addExecutedToCallStack_fn = function(executer) {
|
|
1548
|
+
if (executer) {
|
|
1549
|
+
this.eventEmitter.emit("executed", executer);
|
|
1550
|
+
this.executed.push(executer);
|
|
1551
|
+
}
|
|
1522
1552
|
};
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1553
|
+
_execute = new WeakSet();
|
|
1554
|
+
execute_fn = function({
|
|
1555
|
+
strategy,
|
|
1556
|
+
hookName,
|
|
1557
|
+
parameters,
|
|
1558
|
+
plugin
|
|
1559
|
+
}) {
|
|
1560
|
+
const hook = plugin[hookName];
|
|
1561
|
+
let output;
|
|
1562
|
+
if (!hook) {
|
|
1563
|
+
return null;
|
|
1564
|
+
}
|
|
1565
|
+
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1566
|
+
const task = Promise.resolve().then(() => {
|
|
1567
|
+
if (typeof hook === "function") {
|
|
1568
|
+
const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
1569
|
+
if (isPromise(possiblePromiseResult)) {
|
|
1570
|
+
return Promise.resolve(possiblePromiseResult);
|
|
1571
|
+
}
|
|
1572
|
+
return possiblePromiseResult;
|
|
1573
|
+
}
|
|
1574
|
+
return hook;
|
|
1575
|
+
}).then((result) => {
|
|
1576
|
+
output = result;
|
|
1577
|
+
return result;
|
|
1578
|
+
}).catch((e) => {
|
|
1579
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1580
|
+
return null;
|
|
1581
|
+
}).finally(() => {
|
|
1582
|
+
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1583
|
+
parameters,
|
|
1584
|
+
output,
|
|
1585
|
+
strategy,
|
|
1586
|
+
hookName,
|
|
1587
|
+
plugin
|
|
1588
|
+
});
|
|
1536
1589
|
});
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1590
|
+
return task;
|
|
1591
|
+
};
|
|
1592
|
+
_executeSync = new WeakSet();
|
|
1593
|
+
executeSync_fn = function({
|
|
1594
|
+
strategy,
|
|
1595
|
+
hookName,
|
|
1596
|
+
parameters,
|
|
1597
|
+
plugin
|
|
1598
|
+
}) {
|
|
1599
|
+
const hook = plugin[hookName];
|
|
1600
|
+
let output;
|
|
1601
|
+
if (!hook) {
|
|
1602
|
+
return null;
|
|
1603
|
+
}
|
|
1604
|
+
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1605
|
+
try {
|
|
1606
|
+
if (typeof hook === "function") {
|
|
1607
|
+
const fn = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
1608
|
+
output = fn;
|
|
1609
|
+
return fn;
|
|
1610
|
+
}
|
|
1611
|
+
output = hook;
|
|
1612
|
+
return hook;
|
|
1613
|
+
} catch (e) {
|
|
1614
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1615
|
+
return null;
|
|
1616
|
+
} finally {
|
|
1617
|
+
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1618
|
+
parameters,
|
|
1619
|
+
output,
|
|
1620
|
+
strategy,
|
|
1621
|
+
hookName,
|
|
1622
|
+
plugin
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
};
|
|
1626
|
+
_catcher = new WeakSet();
|
|
1627
|
+
catcher_fn = function(e, plugin, hookName) {
|
|
1628
|
+
const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
|
|
1629
|
+
`;
|
|
1630
|
+
const pluginError = new PluginError(text, { cause: e, pluginManager: this });
|
|
1631
|
+
this.eventEmitter.emit("error", pluginError);
|
|
1632
|
+
throw pluginError;
|
|
1633
|
+
};
|
|
1634
|
+
_parse = new WeakSet();
|
|
1635
|
+
parse_fn = function(plugin, pluginManager, context) {
|
|
1636
|
+
const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
|
|
1637
|
+
setUniqueName(plugin.name, usedPluginNames);
|
|
1638
|
+
const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
1639
|
+
if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
|
|
1640
|
+
pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
|
|
1641
|
+
}
|
|
1642
|
+
if (!plugin.transform) {
|
|
1643
|
+
plugin.transform = function transform(code) {
|
|
1644
|
+
return code;
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
if (plugin.api && typeof plugin.api === "function") {
|
|
1648
|
+
const api = plugin.api.call(context);
|
|
1649
|
+
return {
|
|
1650
|
+
...plugin,
|
|
1651
|
+
key,
|
|
1652
|
+
api
|
|
1653
|
+
};
|
|
1654
|
+
}
|
|
1655
|
+
return {
|
|
1656
|
+
...plugin,
|
|
1657
|
+
key
|
|
1658
|
+
};
|
|
1544
1659
|
};
|
|
1545
1660
|
|
|
1546
1661
|
// src/build.ts
|
|
@@ -1548,13 +1663,13 @@ async function transformReducer(_previousCode, result, _plugin) {
|
|
|
1548
1663
|
return result;
|
|
1549
1664
|
}
|
|
1550
1665
|
async function build(options) {
|
|
1551
|
-
const { config,
|
|
1666
|
+
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
1552
1667
|
try {
|
|
1553
|
-
if (
|
|
1668
|
+
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
1554
1669
|
await read(config.input.path);
|
|
1555
1670
|
}
|
|
1556
1671
|
} catch (e) {
|
|
1557
|
-
if (
|
|
1672
|
+
if (isInputPath(config)) {
|
|
1558
1673
|
throw new Error(
|
|
1559
1674
|
"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
1675
|
{
|
|
@@ -1567,11 +1682,11 @@ async function build(options) {
|
|
|
1567
1682
|
await clean(config.output.path);
|
|
1568
1683
|
}
|
|
1569
1684
|
const queueTask = async (file) => {
|
|
1570
|
-
const { path } = file;
|
|
1571
|
-
let code =
|
|
1685
|
+
const { path: path3 } = file;
|
|
1686
|
+
let code = FileManager.getSource(file);
|
|
1572
1687
|
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1573
1688
|
hookName: "load",
|
|
1574
|
-
parameters: [
|
|
1689
|
+
parameters: [path3]
|
|
1575
1690
|
});
|
|
1576
1691
|
if (loadedResult && isPromise(loadedResult)) {
|
|
1577
1692
|
code = await loadedResult;
|
|
@@ -1582,28 +1697,53 @@ async function build(options) {
|
|
|
1582
1697
|
if (code) {
|
|
1583
1698
|
const transformedCode = await pluginManager.hookReduceArg0({
|
|
1584
1699
|
hookName: "transform",
|
|
1585
|
-
parameters: [code,
|
|
1700
|
+
parameters: [code, path3],
|
|
1586
1701
|
reduce: transformReducer
|
|
1587
1702
|
});
|
|
1588
1703
|
if (config.output.write || config.output.write === void 0) {
|
|
1589
|
-
|
|
1704
|
+
if (file.meta?.pluginKey) {
|
|
1705
|
+
return pluginManager.hookForPlugin({
|
|
1706
|
+
pluginKey: file.meta?.pluginKey,
|
|
1707
|
+
hookName: "writeFile",
|
|
1708
|
+
parameters: [transformedCode, path3]
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
return pluginManager.hookFirst({
|
|
1590
1712
|
hookName: "writeFile",
|
|
1591
|
-
parameters: [transformedCode,
|
|
1713
|
+
parameters: [transformedCode, path3]
|
|
1592
1714
|
});
|
|
1593
1715
|
}
|
|
1594
1716
|
}
|
|
1595
1717
|
};
|
|
1596
|
-
const pluginManager = new PluginManager(config, {
|
|
1718
|
+
const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
|
|
1597
1719
|
const { plugins, fileManager } = pluginManager;
|
|
1598
1720
|
pluginManager.on("execute", (executer) => {
|
|
1721
|
+
const { hookName, parameters, plugin } = executer;
|
|
1722
|
+
if (hookName === "writeFile" && logger.spinner) {
|
|
1723
|
+
const [code] = parameters;
|
|
1724
|
+
if (logger.logLevel === LogLevel.info) {
|
|
1725
|
+
logger.spinner.start(`\u{1F4BE} Writing`);
|
|
1726
|
+
}
|
|
1727
|
+
if (logger.logLevel === "debug") {
|
|
1728
|
+
logger.info(`PluginKey ${pc3.dim(JSON.stringify(plugin.key))}
|
|
1729
|
+
with source
|
|
1730
|
+
|
|
1731
|
+
${code}`);
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
});
|
|
1735
|
+
pluginManager.on("executed", (executer) => {
|
|
1599
1736
|
const { hookName, plugin, output, parameters } = executer;
|
|
1600
1737
|
const messsage = `${randomPicoColour(plugin.name)} Executing ${hookName}`;
|
|
1601
|
-
if (logLevel === LogLevel.info) {
|
|
1602
|
-
if (
|
|
1738
|
+
if (logger.logLevel === LogLevel.info && logger.spinner) {
|
|
1739
|
+
if (hookName === "writeFile") {
|
|
1740
|
+
const [_code, path3] = parameters;
|
|
1741
|
+
logger.spinner.suffixText = pc3.dim(path3);
|
|
1742
|
+
} else {
|
|
1603
1743
|
logger.spinner.suffixText = messsage;
|
|
1604
1744
|
}
|
|
1605
1745
|
}
|
|
1606
|
-
if (logLevel === LogLevel.debug) {
|
|
1746
|
+
if (logger.logLevel === LogLevel.debug) {
|
|
1607
1747
|
logger.info(messsage);
|
|
1608
1748
|
const logs = [
|
|
1609
1749
|
parameters && `${pc3.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
|
|
@@ -1623,74 +1763,72 @@ async function build(options) {
|
|
|
1623
1763
|
parameters: [config]
|
|
1624
1764
|
});
|
|
1625
1765
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
return options;
|
|
1766
|
+
if (!fileManager.isExecuting && logger.spinner) {
|
|
1767
|
+
logger.spinner.suffixText = "";
|
|
1768
|
+
logger.spinner.succeed(`\u{1F4BE} Writing completed`);
|
|
1769
|
+
}
|
|
1770
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1632
1771
|
}
|
|
1633
1772
|
|
|
1634
|
-
// src/
|
|
1773
|
+
// src/Generator.ts
|
|
1774
|
+
var _options3, _context;
|
|
1635
1775
|
var Generator = class {
|
|
1636
|
-
#options = {};
|
|
1637
|
-
#context = {};
|
|
1638
1776
|
constructor(options, context) {
|
|
1777
|
+
__privateAdd(this, _options3, {});
|
|
1778
|
+
__privateAdd(this, _context, {});
|
|
1639
1779
|
if (context) {
|
|
1640
|
-
this
|
|
1780
|
+
__privateSet(this, _context, context);
|
|
1641
1781
|
}
|
|
1642
1782
|
if (options) {
|
|
1643
|
-
this
|
|
1783
|
+
__privateSet(this, _options3, options);
|
|
1644
1784
|
}
|
|
1645
1785
|
return this;
|
|
1646
1786
|
}
|
|
1647
1787
|
get options() {
|
|
1648
|
-
return this
|
|
1788
|
+
return __privateGet(this, _options3);
|
|
1649
1789
|
}
|
|
1650
1790
|
get context() {
|
|
1651
|
-
return this
|
|
1791
|
+
return __privateGet(this, _context);
|
|
1652
1792
|
}
|
|
1653
1793
|
set options(options) {
|
|
1654
|
-
this
|
|
1794
|
+
__privateSet(this, _options3, { ...__privateGet(this, _options3), ...options });
|
|
1655
1795
|
}
|
|
1656
1796
|
};
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
var
|
|
1660
|
-
|
|
1661
|
-
var PackageManager = class _PackageManager {
|
|
1662
|
-
static #cache = {};
|
|
1663
|
-
#cwd;
|
|
1664
|
-
#SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
|
|
1797
|
+
_options3 = new WeakMap();
|
|
1798
|
+
_context = new WeakMap();
|
|
1799
|
+
var _cache2, _cwd, _SLASHES;
|
|
1800
|
+
var _PackageManager = class _PackageManager {
|
|
1665
1801
|
constructor(workspace) {
|
|
1802
|
+
__privateAdd(this, _cwd, void 0);
|
|
1803
|
+
__privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
|
|
1666
1804
|
if (workspace) {
|
|
1667
|
-
this
|
|
1805
|
+
__privateSet(this, _cwd, workspace);
|
|
1668
1806
|
}
|
|
1669
1807
|
return this;
|
|
1670
1808
|
}
|
|
1671
1809
|
set workspace(workspace) {
|
|
1672
|
-
this
|
|
1810
|
+
__privateSet(this, _cwd, workspace);
|
|
1673
1811
|
}
|
|
1674
1812
|
get workspace() {
|
|
1675
|
-
return this
|
|
1813
|
+
return __privateGet(this, _cwd);
|
|
1676
1814
|
}
|
|
1677
1815
|
normalizeDirectory(directory) {
|
|
1678
|
-
if (!this
|
|
1816
|
+
if (!__privateGet(this, _SLASHES).has(directory[directory.length - 1])) {
|
|
1679
1817
|
return `${directory}/`;
|
|
1680
1818
|
}
|
|
1681
1819
|
return directory;
|
|
1682
1820
|
}
|
|
1683
|
-
getLocation(
|
|
1684
|
-
let location =
|
|
1685
|
-
if (this
|
|
1686
|
-
const require2 = mod.createRequire(this.normalizeDirectory(this
|
|
1687
|
-
location = require2.resolve(
|
|
1821
|
+
getLocation(path3) {
|
|
1822
|
+
let location = path3;
|
|
1823
|
+
if (__privateGet(this, _cwd)) {
|
|
1824
|
+
const require2 = mod.createRequire(this.normalizeDirectory(__privateGet(this, _cwd)));
|
|
1825
|
+
location = require2.resolve(path3);
|
|
1688
1826
|
}
|
|
1689
1827
|
return location;
|
|
1690
1828
|
}
|
|
1691
|
-
async import(
|
|
1829
|
+
async import(path3) {
|
|
1692
1830
|
try {
|
|
1693
|
-
let location = this.getLocation(
|
|
1831
|
+
let location = this.getLocation(path3);
|
|
1694
1832
|
if (os.platform() == "win32") {
|
|
1695
1833
|
location = pathToFileURL(location).href;
|
|
1696
1834
|
}
|
|
@@ -1703,7 +1841,7 @@ var PackageManager = class _PackageManager {
|
|
|
1703
1841
|
}
|
|
1704
1842
|
async getPackageJSON() {
|
|
1705
1843
|
const pkgPath = await findUp(["package.json"], {
|
|
1706
|
-
cwd: this
|
|
1844
|
+
cwd: __privateGet(this, _cwd)
|
|
1707
1845
|
});
|
|
1708
1846
|
if (!pkgPath) {
|
|
1709
1847
|
return void 0;
|
|
@@ -1712,7 +1850,7 @@ var PackageManager = class _PackageManager {
|
|
|
1712
1850
|
}
|
|
1713
1851
|
getPackageJSONSync() {
|
|
1714
1852
|
const pkgPath = findUpSync(["package.json"], {
|
|
1715
|
-
cwd: this
|
|
1853
|
+
cwd: __privateGet(this, _cwd)
|
|
1716
1854
|
});
|
|
1717
1855
|
if (!pkgPath) {
|
|
1718
1856
|
return void 0;
|
|
@@ -1720,11 +1858,11 @@ var PackageManager = class _PackageManager {
|
|
|
1720
1858
|
return __require(pkgPath);
|
|
1721
1859
|
}
|
|
1722
1860
|
static setVersion(dependency, version) {
|
|
1723
|
-
_PackageManager
|
|
1861
|
+
__privateGet(_PackageManager, _cache2)[dependency] = version;
|
|
1724
1862
|
}
|
|
1725
1863
|
async getVersion(dependency) {
|
|
1726
|
-
if (_PackageManager
|
|
1727
|
-
return _PackageManager
|
|
1864
|
+
if (__privateGet(_PackageManager, _cache2)[dependency]) {
|
|
1865
|
+
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
1728
1866
|
}
|
|
1729
1867
|
const packageJSON = await this.getPackageJSON();
|
|
1730
1868
|
if (!packageJSON) {
|
|
@@ -1733,8 +1871,8 @@ var PackageManager = class _PackageManager {
|
|
|
1733
1871
|
return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
|
|
1734
1872
|
}
|
|
1735
1873
|
getVersionSync(dependency) {
|
|
1736
|
-
if (_PackageManager
|
|
1737
|
-
return _PackageManager
|
|
1874
|
+
if (__privateGet(_PackageManager, _cache2)[dependency]) {
|
|
1875
|
+
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
1738
1876
|
}
|
|
1739
1877
|
const packageJSON = this.getPackageJSONSync();
|
|
1740
1878
|
if (!packageJSON) {
|
|
@@ -1765,10 +1903,19 @@ var PackageManager = class _PackageManager {
|
|
|
1765
1903
|
return satisfies(semVer, version);
|
|
1766
1904
|
}
|
|
1767
1905
|
};
|
|
1906
|
+
_cache2 = new WeakMap();
|
|
1907
|
+
_cwd = new WeakMap();
|
|
1908
|
+
_SLASHES = new WeakMap();
|
|
1909
|
+
__privateAdd(_PackageManager, _cache2, {});
|
|
1910
|
+
var PackageManager = _PackageManager;
|
|
1911
|
+
|
|
1912
|
+
// src/SchemaGenerator.ts
|
|
1913
|
+
var SchemaGenerator = class extends Generator {
|
|
1914
|
+
};
|
|
1768
1915
|
|
|
1769
1916
|
// src/index.ts
|
|
1770
1917
|
var src_default = build;
|
|
1771
1918
|
|
|
1772
|
-
export { FileManager,
|
|
1919
|
+
export { FileManager, Generator, PackageManager, ParallelPluginError, PluginError, PluginManager, PromiseManager, SchemaGenerator, SummaryError, ValidationPluginError, Warning, build, combineExports, combineImports, createPlugin, src_default as default, defineConfig, isInputPath, pluginName as name, pluginName };
|
|
1773
1920
|
//# sourceMappingURL=out.js.map
|
|
1774
1921
|
//# sourceMappingURL=index.js.map
|