@kubb/core 1.15.0-canary.20231112T135011 → 2.0.0-alpha.10
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/README.md +1 -1
- package/dist/index.cjs +1253 -1088
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +396 -411
- package/dist/index.d.ts +396 -411
- package/dist/index.js +1194 -1018
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +1272 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +239 -0
- package/dist/utils.d.ts +239 -0
- package/dist/utils.js +1219 -0
- package/dist/utils.js.map +1 -0
- package/globals.d.ts +33 -16
- package/package.json +21 -14
- package/src/BarrelManager.ts +123 -0
- package/src/FileManager.ts +524 -0
- package/src/Generator.ts +34 -0
- package/src/PackageManager.ts +178 -0
- package/src/PluginManager.ts +629 -0
- package/src/PromiseManager.ts +51 -0
- package/src/SchemaGenerator.ts +8 -0
- package/src/build.ts +207 -0
- package/src/config.ts +22 -0
- package/src/errors.ts +12 -0
- package/src/index.ts +28 -0
- package/src/plugin.ts +80 -0
- package/src/types.ts +353 -0
- package/src/utils/EventEmitter.ts +24 -0
- package/src/utils/FunctionParams.ts +85 -0
- package/src/utils/Queue.ts +110 -0
- package/src/utils/TreeNode.ts +122 -0
- package/src/utils/URLPath.ts +133 -0
- package/src/utils/cache.ts +35 -0
- package/src/utils/clean.ts +5 -0
- package/src/utils/executeStrategies.ts +83 -0
- package/src/utils/index.ts +19 -0
- package/src/utils/logger.ts +76 -0
- package/src/utils/promise.ts +13 -0
- package/src/utils/randomColour.ts +39 -0
- package/src/utils/read.ts +68 -0
- package/src/utils/renderTemplate.ts +31 -0
- package/src/utils/throttle.ts +30 -0
- package/src/utils/timeout.ts +7 -0
- package/src/utils/transformers/combineCodes.ts +3 -0
- package/src/utils/transformers/createJSDocBlockText.ts +15 -0
- package/src/utils/transformers/escape.ts +31 -0
- package/src/utils/transformers/indent.ts +3 -0
- package/src/utils/transformers/index.ts +22 -0
- package/src/utils/transformers/nameSorter.ts +9 -0
- package/src/utils/transformers/searchAndReplace.ts +25 -0
- package/src/utils/transformers/transformReservedWord.ts +97 -0
- package/src/utils/transformers/trim.ts +3 -0
- package/src/utils/uniqueName.ts +20 -0
- package/src/utils/write.ts +63 -0
package/dist/index.cjs
CHANGED
|
@@ -3,18 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var pc3 = require('picocolors');
|
|
6
|
-
var crypto = require('crypto');
|
|
7
6
|
var fs2 = require('fs-extra');
|
|
8
|
-
var changeCase = require('change-case');
|
|
9
|
-
var naturalOrderby = require('natural-orderby');
|
|
10
|
-
var perf_hooks = require('perf_hooks');
|
|
11
7
|
var seedrandom = require('seedrandom');
|
|
12
|
-
var
|
|
8
|
+
var path4 = require('path');
|
|
13
9
|
var jsRuntime = require('js-runtime');
|
|
14
|
-
var
|
|
10
|
+
var changeCase = require('change-case');
|
|
11
|
+
var crypto2 = require('crypto');
|
|
15
12
|
var parser = require('@kubb/parser');
|
|
13
|
+
var factory = require('@kubb/parser/factory');
|
|
16
14
|
var isEqual = require('lodash.isequal');
|
|
15
|
+
var naturalOrderby = require('natural-orderby');
|
|
16
|
+
var dirTree = require('directory-tree');
|
|
17
17
|
var events = require('events');
|
|
18
|
+
var perf_hooks = require('perf_hooks');
|
|
18
19
|
var mod = require('module');
|
|
19
20
|
var os = require('os');
|
|
20
21
|
var url = require('url');
|
|
@@ -24,18 +25,39 @@ var semver = require('semver');
|
|
|
24
25
|
|
|
25
26
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
26
27
|
|
|
28
|
+
function _interopNamespace(e) {
|
|
29
|
+
if (e && e.__esModule) return e;
|
|
30
|
+
var n = Object.create(null);
|
|
31
|
+
if (e) {
|
|
32
|
+
Object.keys(e).forEach(function (k) {
|
|
33
|
+
if (k !== 'default') {
|
|
34
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
35
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return e[k]; }
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
n.default = e;
|
|
43
|
+
return Object.freeze(n);
|
|
44
|
+
}
|
|
45
|
+
|
|
27
46
|
var pc3__default = /*#__PURE__*/_interopDefault(pc3);
|
|
28
|
-
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
29
47
|
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
30
48
|
var seedrandom__default = /*#__PURE__*/_interopDefault(seedrandom);
|
|
31
|
-
var
|
|
32
|
-
var
|
|
49
|
+
var path4__default = /*#__PURE__*/_interopDefault(path4);
|
|
50
|
+
var crypto2__default = /*#__PURE__*/_interopDefault(crypto2);
|
|
51
|
+
var factory__namespace = /*#__PURE__*/_interopNamespace(factory);
|
|
33
52
|
var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
|
|
53
|
+
var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
|
|
34
54
|
var mod__default = /*#__PURE__*/_interopDefault(mod);
|
|
35
55
|
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
36
56
|
var process__default = /*#__PURE__*/_interopDefault(process);
|
|
37
57
|
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
38
58
|
|
|
59
|
+
var __defProp = Object.defineProperty;
|
|
60
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
39
61
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
40
62
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
41
63
|
}) : x)(function(x) {
|
|
@@ -43,110 +65,49 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
43
65
|
return require.apply(this, arguments);
|
|
44
66
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
45
67
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
set(id, value) {
|
|
51
|
-
Store[id] = [0, value];
|
|
52
|
-
},
|
|
53
|
-
get(id) {
|
|
54
|
-
const item = Store[id];
|
|
55
|
-
if (!item) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
item[0] = 0;
|
|
59
|
-
return item[1];
|
|
60
|
-
},
|
|
61
|
-
has(id) {
|
|
62
|
-
const item = Store[id];
|
|
63
|
-
if (!item) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
item[0] = 0;
|
|
67
|
-
return true;
|
|
68
|
-
},
|
|
69
|
-
delete(id) {
|
|
70
|
-
return delete Store[id];
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
async function clean(path3) {
|
|
75
|
-
return fs2.remove(path3);
|
|
76
|
-
}
|
|
77
|
-
var FunctionParams = class {
|
|
78
|
-
type;
|
|
79
|
-
items = [];
|
|
80
|
-
constructor(type) {
|
|
81
|
-
this.type = type;
|
|
82
|
-
return this;
|
|
83
|
-
}
|
|
84
|
-
add(item) {
|
|
85
|
-
if (!item) {
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
if (Array.isArray(item)) {
|
|
89
|
-
item.filter(Boolean).forEach((it) => this.items.push(it));
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
this.items.push(item);
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
toString() {
|
|
96
|
-
const sortedData = naturalOrderby.orderBy(this.items.filter(Boolean), [(v) => !v.default, (v) => v.required ?? true], ["desc", "desc"]);
|
|
97
|
-
return sortedData.filter(({ enabled = true }) => enabled).reduce((acc, { name, type, required = true, ...rest }) => {
|
|
98
|
-
if (!name) {
|
|
99
|
-
acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
100
|
-
return acc;
|
|
101
|
-
}
|
|
102
|
-
const parameterName = name.startsWith("{") ? name : changeCase.camelCase(name, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
103
|
-
if (type) {
|
|
104
|
-
if (required) {
|
|
105
|
-
acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
106
|
-
} else {
|
|
107
|
-
acc.push(`${parameterName}?: ${type}`);
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
acc.push(`${parameterName}`);
|
|
111
|
-
}
|
|
112
|
-
return acc;
|
|
113
|
-
}, []).join(", ");
|
|
114
|
-
}
|
|
68
|
+
var __publicField = (obj, key, value) => {
|
|
69
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
70
|
+
return value;
|
|
115
71
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
function createJSDocBlockText({ comments }) {
|
|
141
|
-
const filteredComments = comments.filter(Boolean);
|
|
142
|
-
if (!filteredComments.length) {
|
|
143
|
-
return "";
|
|
72
|
+
var __accessCheck = (obj, member, msg) => {
|
|
73
|
+
if (!member.has(obj))
|
|
74
|
+
throw TypeError("Cannot " + msg);
|
|
75
|
+
};
|
|
76
|
+
var __privateGet = (obj, member, getter) => {
|
|
77
|
+
__accessCheck(obj, member, "read from private field");
|
|
78
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
79
|
+
};
|
|
80
|
+
var __privateAdd = (obj, member, value) => {
|
|
81
|
+
if (member.has(obj))
|
|
82
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
83
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
84
|
+
};
|
|
85
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
86
|
+
__accessCheck(obj, member, "write to private field");
|
|
87
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
88
|
+
return value;
|
|
89
|
+
};
|
|
90
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
91
|
+
set _(value) {
|
|
92
|
+
__privateSet(obj, member, value, setter);
|
|
93
|
+
},
|
|
94
|
+
get _() {
|
|
95
|
+
return __privateGet(obj, member, getter);
|
|
144
96
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
97
|
+
});
|
|
98
|
+
var __privateMethod = (obj, member, method) => {
|
|
99
|
+
__accessCheck(obj, member, "access private method");
|
|
100
|
+
return method;
|
|
101
|
+
};
|
|
102
|
+
async function clean(path5) {
|
|
103
|
+
return fs2.remove(path5);
|
|
148
104
|
}
|
|
149
|
-
|
|
105
|
+
var LogLevel = {
|
|
106
|
+
silent: "silent",
|
|
107
|
+
info: "info",
|
|
108
|
+
debug: "debug"
|
|
109
|
+
};
|
|
110
|
+
function createLogger({ logLevel, name, spinner }) {
|
|
150
111
|
const logs = [];
|
|
151
112
|
const log = (message) => {
|
|
152
113
|
if (message && spinner) {
|
|
@@ -166,12 +127,14 @@ function createLogger(spinner) {
|
|
|
166
127
|
}
|
|
167
128
|
};
|
|
168
129
|
const info = (message) => {
|
|
169
|
-
if (message && spinner) {
|
|
130
|
+
if (message && spinner && logLevel !== LogLevel.silent) {
|
|
170
131
|
spinner.info(message);
|
|
171
132
|
logs.push(message);
|
|
172
133
|
}
|
|
173
134
|
};
|
|
174
135
|
const logger = {
|
|
136
|
+
name,
|
|
137
|
+
logLevel,
|
|
175
138
|
log,
|
|
176
139
|
error,
|
|
177
140
|
warn,
|
|
@@ -181,75 +144,6 @@ function createLogger(spinner) {
|
|
|
181
144
|
};
|
|
182
145
|
return logger;
|
|
183
146
|
}
|
|
184
|
-
|
|
185
|
-
// src/utils/nameSorter.ts
|
|
186
|
-
function nameSorter(a, b) {
|
|
187
|
-
if (a.name < b.name) {
|
|
188
|
-
return -1;
|
|
189
|
-
}
|
|
190
|
-
if (a.name > b.name) {
|
|
191
|
-
return 1;
|
|
192
|
-
}
|
|
193
|
-
return 0;
|
|
194
|
-
}
|
|
195
|
-
var Queue = class {
|
|
196
|
-
#queue = [];
|
|
197
|
-
#workerCount = 0;
|
|
198
|
-
#maxParallel;
|
|
199
|
-
#debug = false;
|
|
200
|
-
constructor(maxParallel, debug = false) {
|
|
201
|
-
this.#maxParallel = maxParallel;
|
|
202
|
-
this.#debug = debug;
|
|
203
|
-
}
|
|
204
|
-
run(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
|
|
205
|
-
return new Promise((resolve, reject) => {
|
|
206
|
-
const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
|
|
207
|
-
options.controller?.signal.addEventListener("abort", () => {
|
|
208
|
-
this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
|
|
209
|
-
reject("Aborted");
|
|
210
|
-
});
|
|
211
|
-
this.#queue.push(item);
|
|
212
|
-
this.#work();
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
runSync(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
|
|
216
|
-
new Promise((resolve, reject) => {
|
|
217
|
-
const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
|
|
218
|
-
options.controller?.signal.addEventListener("abort", () => {
|
|
219
|
-
this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
|
|
220
|
-
});
|
|
221
|
-
this.#queue.push(item);
|
|
222
|
-
this.#work();
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
get hasJobs() {
|
|
226
|
-
return this.#workerCount > 0 || this.#queue.length > 0;
|
|
227
|
-
}
|
|
228
|
-
get count() {
|
|
229
|
-
return this.#workerCount;
|
|
230
|
-
}
|
|
231
|
-
#work() {
|
|
232
|
-
if (this.#workerCount >= this.#maxParallel) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
this.#workerCount++;
|
|
236
|
-
let entry;
|
|
237
|
-
while (entry = this.#queue.shift()) {
|
|
238
|
-
const { reject, resolve, job, name, description } = entry;
|
|
239
|
-
if (this.#debug) {
|
|
240
|
-
perf_hooks.performance.mark(name + "_start");
|
|
241
|
-
}
|
|
242
|
-
job().then((result) => {
|
|
243
|
-
resolve(result);
|
|
244
|
-
if (this.#debug) {
|
|
245
|
-
perf_hooks.performance.mark(name + "_stop");
|
|
246
|
-
perf_hooks.performance.measure(description, name + "_start", name + "_stop");
|
|
247
|
-
}
|
|
248
|
-
}).catch((err) => reject(err));
|
|
249
|
-
}
|
|
250
|
-
this.#workerCount--;
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
147
|
var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
|
|
254
148
|
function randomColour(text, colours = defaultColours) {
|
|
255
149
|
if (!text) {
|
|
@@ -276,46 +170,22 @@ function randomPicoColour(text, colors = defaultColours) {
|
|
|
276
170
|
}
|
|
277
171
|
return formatter(text);
|
|
278
172
|
}
|
|
279
|
-
function slash(path3, platform = "linux") {
|
|
280
|
-
const isWindowsPath = /^\\\\\?\\/.test(path3);
|
|
281
|
-
if (["linux", "mac"].includes(platform) && !isWindowsPath) {
|
|
282
|
-
return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
283
|
-
}
|
|
284
|
-
return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
285
|
-
}
|
|
286
|
-
function getRelativePath(rootDir, filePath, platform = "linux") {
|
|
287
|
-
if (!rootDir || !filePath) {
|
|
288
|
-
throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
|
|
289
|
-
}
|
|
290
|
-
const relativePath = path2__default.default.relative(rootDir, filePath);
|
|
291
|
-
const path3 = slash(relativePath, platform);
|
|
292
|
-
if (path3.startsWith("../")) {
|
|
293
|
-
return path3.replace(path2__default.default.basename(path3), path2__default.default.basename(path3, path2__default.default.extname(filePath)));
|
|
294
|
-
}
|
|
295
|
-
return `./${path3.replace(path2__default.default.basename(path3), path2__default.default.basename(path3, path2__default.default.extname(filePath)))}`;
|
|
296
|
-
}
|
|
297
|
-
function getPathMode(path3) {
|
|
298
|
-
if (!path3) {
|
|
299
|
-
return "directory";
|
|
300
|
-
}
|
|
301
|
-
return path2__default.default.extname(path3) ? "file" : "directory";
|
|
302
|
-
}
|
|
303
173
|
var reader = jsRuntime.switcher(
|
|
304
174
|
{
|
|
305
|
-
node: async (
|
|
306
|
-
return fs2__default.default.readFile(
|
|
175
|
+
node: async (path5) => {
|
|
176
|
+
return fs2__default.default.readFile(path5, { encoding: "utf8" });
|
|
307
177
|
},
|
|
308
|
-
bun: async (
|
|
309
|
-
const file = Bun.file(
|
|
178
|
+
bun: async (path5) => {
|
|
179
|
+
const file = Bun.file(path5);
|
|
310
180
|
return file.text();
|
|
311
181
|
}
|
|
312
182
|
},
|
|
313
183
|
"node"
|
|
314
184
|
);
|
|
315
|
-
|
|
185
|
+
jsRuntime.switcher(
|
|
316
186
|
{
|
|
317
|
-
node: (
|
|
318
|
-
return fs2__default.default.readFileSync(
|
|
187
|
+
node: (path5) => {
|
|
188
|
+
return fs2__default.default.readFileSync(path5, { encoding: "utf8" });
|
|
319
189
|
},
|
|
320
190
|
bun: () => {
|
|
321
191
|
throw new Error("Bun cannot read sync");
|
|
@@ -323,79 +193,118 @@ var syncReader = jsRuntime.switcher(
|
|
|
323
193
|
},
|
|
324
194
|
"node"
|
|
325
195
|
);
|
|
326
|
-
async function read(
|
|
327
|
-
return reader(
|
|
328
|
-
}
|
|
329
|
-
function readSync(path3) {
|
|
330
|
-
return syncReader(path3);
|
|
196
|
+
async function read(path5) {
|
|
197
|
+
return reader(path5);
|
|
331
198
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
if (typeof value === "boolean") {
|
|
350
|
-
return `${value.toString()}` || "false";
|
|
199
|
+
var URLPath = class {
|
|
200
|
+
constructor(path5) {
|
|
201
|
+
this.path = path5;
|
|
202
|
+
return this;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
206
|
+
* @example /pet/{petId} => /pet/:petId
|
|
207
|
+
*/
|
|
208
|
+
get URL() {
|
|
209
|
+
return this.toURLPath();
|
|
210
|
+
}
|
|
211
|
+
get isURL() {
|
|
212
|
+
try {
|
|
213
|
+
const url = new URL(this.path);
|
|
214
|
+
if (url?.href) {
|
|
215
|
+
return true;
|
|
351
216
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
// src/utils/SummaryError.ts
|
|
358
|
-
var SummaryError = class extends Error {
|
|
359
|
-
summary;
|
|
360
|
-
constructor(message, options) {
|
|
361
|
-
super(message, { cause: options.cause });
|
|
362
|
-
this.name = "SummaryError";
|
|
363
|
-
this.summary = options.summary || [];
|
|
217
|
+
} catch (error) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
return false;
|
|
364
221
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
222
|
+
/**
|
|
223
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
224
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
225
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
226
|
+
* @example /account/userID => `/account/${userId}`
|
|
227
|
+
*/
|
|
228
|
+
get template() {
|
|
229
|
+
return this.toTemplateString();
|
|
230
|
+
}
|
|
231
|
+
get object() {
|
|
232
|
+
return this.toObject();
|
|
233
|
+
}
|
|
234
|
+
get params() {
|
|
235
|
+
return this.getParams();
|
|
236
|
+
}
|
|
237
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
238
|
+
const object = {
|
|
239
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
|
|
240
|
+
params: this.getParams()
|
|
241
|
+
};
|
|
242
|
+
if (stringify) {
|
|
243
|
+
if (type === "template") {
|
|
244
|
+
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
376
245
|
}
|
|
377
|
-
if (
|
|
378
|
-
return
|
|
246
|
+
if (object.params) {
|
|
247
|
+
return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
379
248
|
}
|
|
380
|
-
|
|
381
|
-
wait = true;
|
|
382
|
-
timeout2 = setTimeout(() => {
|
|
383
|
-
wait = false;
|
|
384
|
-
}, delay);
|
|
385
|
-
return val;
|
|
386
|
-
},
|
|
387
|
-
() => {
|
|
388
|
-
cancelled = true;
|
|
389
|
-
clearTimeout(timeout2);
|
|
249
|
+
return `{ url: '${object.url}' }`;
|
|
390
250
|
}
|
|
391
|
-
|
|
251
|
+
return object;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
255
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
256
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
257
|
+
* @example /account/userID => `/account/${userId}`
|
|
258
|
+
*/
|
|
259
|
+
toTemplateString(replacer) {
|
|
260
|
+
const regex = /{(\w|-)*}/g;
|
|
261
|
+
const found = this.path.match(regex);
|
|
262
|
+
let newPath = this.path.replaceAll("{", "${");
|
|
263
|
+
if (found) {
|
|
264
|
+
newPath = found.reduce((prev, curr) => {
|
|
265
|
+
const pathParam = replacer ? replacer(changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
266
|
+
const replacement = `\${${pathParam}}`;
|
|
267
|
+
return prev.replace(curr, replacement);
|
|
268
|
+
}, this.path);
|
|
269
|
+
}
|
|
270
|
+
return `\`${newPath}\``;
|
|
271
|
+
}
|
|
272
|
+
getParams(replacer) {
|
|
273
|
+
const regex = /{(\w|-)*}/g;
|
|
274
|
+
const found = this.path.match(regex);
|
|
275
|
+
if (!found) {
|
|
276
|
+
return void 0;
|
|
277
|
+
}
|
|
278
|
+
const params = {};
|
|
279
|
+
found.forEach((item) => {
|
|
280
|
+
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
281
|
+
const pathParam = replacer ? replacer(changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(item, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
282
|
+
params[pathParam] = pathParam;
|
|
283
|
+
}, this.path);
|
|
284
|
+
return params;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
288
|
+
* @example /pet/{petId} => /pet/:petId
|
|
289
|
+
*/
|
|
290
|
+
toURLPath() {
|
|
291
|
+
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
292
|
+
}
|
|
392
293
|
};
|
|
393
294
|
|
|
295
|
+
// src/config.ts
|
|
296
|
+
function defineConfig(options) {
|
|
297
|
+
return options;
|
|
298
|
+
}
|
|
299
|
+
function isInputPath(result) {
|
|
300
|
+
return !!result && "path" in result;
|
|
301
|
+
}
|
|
302
|
+
|
|
394
303
|
// src/utils/timeout.ts
|
|
395
304
|
async function timeout(ms) {
|
|
396
|
-
return new Promise((
|
|
305
|
+
return new Promise((resolve2) => {
|
|
397
306
|
setTimeout(() => {
|
|
398
|
-
|
|
307
|
+
resolve2(true);
|
|
399
308
|
}, ms);
|
|
400
309
|
});
|
|
401
310
|
}
|
|
@@ -405,6 +314,22 @@ function combineCodes(codes) {
|
|
|
405
314
|
return codes.join("\n");
|
|
406
315
|
}
|
|
407
316
|
|
|
317
|
+
// src/utils/transformers/createJSDocBlockText.ts
|
|
318
|
+
function createJSDocBlockText({ comments, newLine }) {
|
|
319
|
+
const filteredComments = comments.filter(Boolean);
|
|
320
|
+
if (!filteredComments.length) {
|
|
321
|
+
return "";
|
|
322
|
+
}
|
|
323
|
+
const source = `/**
|
|
324
|
+
* ${filteredComments.join("\n * ")}
|
|
325
|
+
*/`;
|
|
326
|
+
if (newLine) {
|
|
327
|
+
return `${source}
|
|
328
|
+
`;
|
|
329
|
+
}
|
|
330
|
+
return source;
|
|
331
|
+
}
|
|
332
|
+
|
|
408
333
|
// src/utils/transformers/escape.ts
|
|
409
334
|
function escape(text) {
|
|
410
335
|
return text ? text.replaceAll("`", "\\`") : "";
|
|
@@ -430,15 +355,48 @@ function jsStringEscape(input) {
|
|
|
430
355
|
});
|
|
431
356
|
}
|
|
432
357
|
|
|
433
|
-
// src/utils/transformers/
|
|
434
|
-
|
|
435
|
-
"
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
358
|
+
// src/utils/transformers/indent.ts
|
|
359
|
+
function createIndent(size) {
|
|
360
|
+
return Array.from({ length: size + 1 }).join(" ");
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/utils/transformers/nameSorter.ts
|
|
364
|
+
function nameSorter(a, b) {
|
|
365
|
+
if (a.name < b.name) {
|
|
366
|
+
return -1;
|
|
367
|
+
}
|
|
368
|
+
if (a.name > b.name) {
|
|
369
|
+
return 1;
|
|
370
|
+
}
|
|
371
|
+
return 0;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// src/utils/transformers/searchAndReplace.ts
|
|
375
|
+
function searchAndReplace(options) {
|
|
376
|
+
const { text, replaceBy, prefix = "", key } = options;
|
|
377
|
+
const searchValues = options.searchValues?.(prefix, key) || [
|
|
378
|
+
`${prefix}["${key}"]`,
|
|
379
|
+
`${prefix}['${key}']`,
|
|
380
|
+
`${prefix}[\`${key}\`]`,
|
|
381
|
+
`${prefix}"${key}"`,
|
|
382
|
+
`${prefix}'${key}'`,
|
|
383
|
+
`${prefix}\`${key}\``,
|
|
384
|
+
new RegExp(`${prefix}${key}`, "g")
|
|
385
|
+
];
|
|
386
|
+
return searchValues.reduce((prev, searchValue) => {
|
|
387
|
+
return prev.toString().replaceAll(searchValue, replaceBy);
|
|
388
|
+
}, text);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/utils/transformers/transformReservedWord.ts
|
|
392
|
+
var reservedWords = [
|
|
393
|
+
"abstract",
|
|
394
|
+
"arguments",
|
|
395
|
+
"boolean",
|
|
396
|
+
"break",
|
|
397
|
+
"byte",
|
|
398
|
+
"case",
|
|
399
|
+
"catch",
|
|
442
400
|
"char",
|
|
443
401
|
"class",
|
|
444
402
|
"const",
|
|
@@ -522,11 +480,89 @@ function transformReservedWord(word) {
|
|
|
522
480
|
}
|
|
523
481
|
return word;
|
|
524
482
|
}
|
|
483
|
+
|
|
484
|
+
// src/utils/transformers/trim.ts
|
|
485
|
+
function trim(text) {
|
|
486
|
+
return text.replaceAll(/\n/g, "").trim();
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// src/utils/transformers/index.ts
|
|
490
|
+
var transformers = {
|
|
491
|
+
combineCodes,
|
|
492
|
+
escape,
|
|
493
|
+
jsStringEscape,
|
|
494
|
+
createIndent,
|
|
495
|
+
transformReservedWord,
|
|
496
|
+
nameSorter,
|
|
497
|
+
searchAndReplace,
|
|
498
|
+
trim,
|
|
499
|
+
JSDoc: {
|
|
500
|
+
createJSDocBlockText
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
async function saveCreateDirectory(path5) {
|
|
504
|
+
const passedPath = path4.dirname(path4.resolve(path5));
|
|
505
|
+
await fs2__default.default.mkdir(passedPath, { recursive: true });
|
|
506
|
+
}
|
|
507
|
+
var writer = jsRuntime.switcher(
|
|
508
|
+
{
|
|
509
|
+
node: async (path5, data) => {
|
|
510
|
+
try {
|
|
511
|
+
await fs2__default.default.stat(path4.resolve(path5));
|
|
512
|
+
const oldContent = await fs2__default.default.readFile(path4.resolve(path5), { encoding: "utf-8" });
|
|
513
|
+
if (oldContent?.toString() === data?.toString()) {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
} catch (_err) {
|
|
517
|
+
}
|
|
518
|
+
await saveCreateDirectory(path5);
|
|
519
|
+
await fs2__default.default.writeFile(path4.resolve(path5), data, { encoding: "utf-8" });
|
|
520
|
+
const savedData = await fs2__default.default.readFile(path4.resolve(path5), { encoding: "utf-8" });
|
|
521
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
522
|
+
throw new Error(`Sanity check failed for ${path5}
|
|
523
|
+
|
|
524
|
+
Data[${data.length}]:
|
|
525
|
+
${data}
|
|
526
|
+
|
|
527
|
+
Saved[${savedData.length}]:
|
|
528
|
+
${savedData}
|
|
529
|
+
`);
|
|
530
|
+
}
|
|
531
|
+
return savedData;
|
|
532
|
+
},
|
|
533
|
+
bun: async (path5, data) => {
|
|
534
|
+
try {
|
|
535
|
+
await saveCreateDirectory(path5);
|
|
536
|
+
await Bun.write(path4.resolve(path5), data);
|
|
537
|
+
const file = Bun.file(path4.resolve(path5));
|
|
538
|
+
const savedData = await file.text();
|
|
539
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
540
|
+
throw new Error(`Sanity check failed for ${path5}
|
|
541
|
+
|
|
542
|
+
Data[${data.length}]:
|
|
543
|
+
${data}
|
|
544
|
+
|
|
545
|
+
Saved[${savedData.length}]:
|
|
546
|
+
${savedData}
|
|
547
|
+
`);
|
|
548
|
+
}
|
|
549
|
+
return savedData;
|
|
550
|
+
} catch (e) {
|
|
551
|
+
console.log(e, path4.resolve(path5));
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
"node"
|
|
556
|
+
);
|
|
557
|
+
async function write(data, path5) {
|
|
558
|
+
if (data.trim() === "") {
|
|
559
|
+
return void 0;
|
|
560
|
+
}
|
|
561
|
+
return writer(path5, data.trim());
|
|
562
|
+
}
|
|
525
563
|
var TreeNode = class _TreeNode {
|
|
526
|
-
data;
|
|
527
|
-
parent;
|
|
528
|
-
children = [];
|
|
529
564
|
constructor(data, parent) {
|
|
565
|
+
this.children = [];
|
|
530
566
|
this.data = data;
|
|
531
567
|
this.parent = parent;
|
|
532
568
|
return this;
|
|
@@ -586,16 +622,16 @@ var TreeNode = class _TreeNode {
|
|
|
586
622
|
}
|
|
587
623
|
return this;
|
|
588
624
|
}
|
|
589
|
-
static build(
|
|
625
|
+
static build(path5, options = {}) {
|
|
590
626
|
try {
|
|
591
627
|
const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
|
|
592
|
-
const filteredTree = dirTree__default.default(
|
|
628
|
+
const filteredTree = dirTree__default.default(path5, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
|
|
593
629
|
if (!filteredTree) {
|
|
594
630
|
return null;
|
|
595
631
|
}
|
|
596
|
-
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type ||
|
|
632
|
+
const treeNode = new _TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || FileManager.getMode(filteredTree.path) });
|
|
597
633
|
const recurse = (node, item) => {
|
|
598
|
-
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type ||
|
|
634
|
+
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || FileManager.getMode(item.path) });
|
|
599
635
|
if (item.children?.length) {
|
|
600
636
|
item.children?.forEach((child) => {
|
|
601
637
|
recurse(subNode, child);
|
|
@@ -610,227 +646,290 @@ var TreeNode = class _TreeNode {
|
|
|
610
646
|
}
|
|
611
647
|
};
|
|
612
648
|
|
|
613
|
-
// src/
|
|
614
|
-
var
|
|
615
|
-
var
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
this
|
|
649
|
+
// src/BarrelManager.ts
|
|
650
|
+
var _options;
|
|
651
|
+
var BarrelManager = class {
|
|
652
|
+
constructor(options = {}) {
|
|
653
|
+
__privateAdd(this, _options, {});
|
|
654
|
+
__privateSet(this, _options, options);
|
|
619
655
|
return this;
|
|
620
656
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
if (url?.href) {
|
|
632
|
-
return true;
|
|
657
|
+
getIndexes(root, extName) {
|
|
658
|
+
const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = __privateGet(this, _options);
|
|
659
|
+
const extMapper = {
|
|
660
|
+
".ts": {
|
|
661
|
+
extensions: /\.ts/,
|
|
662
|
+
exclude: [/schemas/, /json/]
|
|
663
|
+
},
|
|
664
|
+
".json": {
|
|
665
|
+
extensions: /\.json/,
|
|
666
|
+
exclude: []
|
|
633
667
|
}
|
|
634
|
-
}
|
|
635
|
-
|
|
668
|
+
};
|
|
669
|
+
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...treeNode });
|
|
670
|
+
if (!tree) {
|
|
671
|
+
return null;
|
|
636
672
|
}
|
|
637
|
-
|
|
673
|
+
const fileReducer = (files2, currentTree) => {
|
|
674
|
+
if (!currentTree.children) {
|
|
675
|
+
return [];
|
|
676
|
+
}
|
|
677
|
+
if (currentTree.children?.length > 1) {
|
|
678
|
+
const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
|
|
679
|
+
const exports = currentTree.children.filter(Boolean).map((file) => {
|
|
680
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
681
|
+
if (importPath.includes("index") && file.data.type === "file") {
|
|
682
|
+
return void 0;
|
|
683
|
+
}
|
|
684
|
+
return {
|
|
685
|
+
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
686
|
+
isTypeOnly
|
|
687
|
+
};
|
|
688
|
+
}).filter(Boolean);
|
|
689
|
+
files2.push({
|
|
690
|
+
path: indexPath,
|
|
691
|
+
baseName: "index.ts",
|
|
692
|
+
source: "",
|
|
693
|
+
exports: output ? exports?.filter((item) => {
|
|
694
|
+
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
695
|
+
}) : exports
|
|
696
|
+
});
|
|
697
|
+
} else {
|
|
698
|
+
currentTree.children?.forEach((child) => {
|
|
699
|
+
const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
|
|
700
|
+
const importPath = child.data.type === "directory" ? `./${child.data.name}/index` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
701
|
+
const exports = [
|
|
702
|
+
{
|
|
703
|
+
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
704
|
+
isTypeOnly
|
|
705
|
+
}
|
|
706
|
+
];
|
|
707
|
+
files2.push({
|
|
708
|
+
path: indexPath,
|
|
709
|
+
baseName: "index.ts",
|
|
710
|
+
source: "",
|
|
711
|
+
exports: output ? exports?.filter((item) => {
|
|
712
|
+
return item.path.endsWith(output.replace(/\.[^.]*$/, ""));
|
|
713
|
+
}) : exports
|
|
714
|
+
});
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
currentTree.children.forEach((childItem) => {
|
|
718
|
+
fileReducer(files2, childItem);
|
|
719
|
+
});
|
|
720
|
+
return files2;
|
|
721
|
+
};
|
|
722
|
+
const files = fileReducer([], tree).reverse();
|
|
723
|
+
const filteredFiles = filter ? files.filter(filter) : files;
|
|
724
|
+
return map ? filteredFiles.map(map) : filteredFiles;
|
|
638
725
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
726
|
+
};
|
|
727
|
+
_options = new WeakMap();
|
|
728
|
+
|
|
729
|
+
// src/FileManager.ts
|
|
730
|
+
exports.KubbFile = void 0;
|
|
731
|
+
((KubbFile2) => {
|
|
732
|
+
})(exports.KubbFile || (exports.KubbFile = {}));
|
|
733
|
+
var _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
734
|
+
var _FileManager = class _FileManager {
|
|
735
|
+
constructor(options) {
|
|
736
|
+
__privateAdd(this, _validate);
|
|
737
|
+
__privateAdd(this, _add);
|
|
738
|
+
__privateAdd(this, _addOrAppend);
|
|
739
|
+
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
|
|
740
|
+
__privateAdd(this, _task, void 0);
|
|
741
|
+
__privateAdd(this, _isWriting, false);
|
|
742
|
+
/**
|
|
743
|
+
* Timeout between writes
|
|
744
|
+
*/
|
|
745
|
+
__privateAdd(this, _timeout, 0);
|
|
746
|
+
__privateAdd(this, _queue, void 0);
|
|
747
|
+
if (options) {
|
|
748
|
+
__privateSet(this, _task, options.task);
|
|
749
|
+
__privateSet(this, _queue, options.queue);
|
|
750
|
+
__privateSet(this, _timeout, options.timeout || 0);
|
|
751
|
+
}
|
|
752
|
+
return this;
|
|
647
753
|
}
|
|
648
|
-
get
|
|
649
|
-
|
|
754
|
+
get files() {
|
|
755
|
+
const files = [];
|
|
756
|
+
__privateGet(this, _cache).forEach((item) => {
|
|
757
|
+
files.push(...item.flat(1));
|
|
758
|
+
});
|
|
759
|
+
return files;
|
|
650
760
|
}
|
|
651
|
-
get
|
|
652
|
-
return this
|
|
761
|
+
get isExecuting() {
|
|
762
|
+
return __privateGet(this, _queue)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
|
|
653
763
|
}
|
|
654
|
-
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
if (stringify) {
|
|
660
|
-
if (type !== "template") {
|
|
661
|
-
throw new Error("Type should be `template` when using stringiyf");
|
|
764
|
+
async add(...files) {
|
|
765
|
+
const promises = files.map((file) => {
|
|
766
|
+
__privateMethod(this, _validate, validate_fn).call(this, file);
|
|
767
|
+
if (file.override) {
|
|
768
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
662
769
|
}
|
|
663
|
-
return
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
669
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
670
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
671
|
-
* @example /account/userID => `/account/${userId}`
|
|
672
|
-
*/
|
|
673
|
-
toTemplateString(replacer) {
|
|
674
|
-
const regex = /{(\w|-)*}/g;
|
|
675
|
-
const found = this.path.match(regex);
|
|
676
|
-
let newPath = this.path.replaceAll("{", "${");
|
|
677
|
-
if (found) {
|
|
678
|
-
newPath = found.reduce((prev, curr) => {
|
|
679
|
-
const pathParam = replacer ? replacer(changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge })) : changeCase.camelCase(curr, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
|
|
680
|
-
const replacement = `\${${pathParam}}`;
|
|
681
|
-
return prev.replace(curr, replacement);
|
|
682
|
-
}, this.path);
|
|
770
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
|
|
771
|
+
});
|
|
772
|
+
const resolvedFiles = await Promise.all(promises);
|
|
773
|
+
if (files.length > 1) {
|
|
774
|
+
return resolvedFiles;
|
|
683
775
|
}
|
|
684
|
-
return
|
|
776
|
+
return resolvedFiles[0];
|
|
685
777
|
}
|
|
686
|
-
|
|
687
|
-
const
|
|
688
|
-
const
|
|
689
|
-
if (!
|
|
778
|
+
async addIndexes({ root, extName = ".ts", meta, options = {} }) {
|
|
779
|
+
const barrelManager = new BarrelManager(options);
|
|
780
|
+
const files = barrelManager.getIndexes(root, extName);
|
|
781
|
+
if (!files) {
|
|
690
782
|
return void 0;
|
|
691
783
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
784
|
+
return await Promise.all(
|
|
785
|
+
files.map((file) => {
|
|
786
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
787
|
+
...file,
|
|
788
|
+
meta: meta ? meta : file.meta
|
|
789
|
+
});
|
|
790
|
+
})
|
|
791
|
+
);
|
|
699
792
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
return
|
|
793
|
+
getCacheByUUID(UUID) {
|
|
794
|
+
let cache;
|
|
795
|
+
__privateGet(this, _cache).forEach((files) => {
|
|
796
|
+
cache = files.find((item) => item.id === UUID);
|
|
797
|
+
});
|
|
798
|
+
return cache;
|
|
706
799
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
// src/utils/Warning.ts
|
|
710
|
-
var Warning = class extends Error {
|
|
711
|
-
constructor(message, options) {
|
|
712
|
-
super(message, { cause: options?.cause });
|
|
713
|
-
this.name = "Warning";
|
|
800
|
+
get(path5) {
|
|
801
|
+
return __privateGet(this, _cache).get(path5);
|
|
714
802
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
}
|
|
720
|
-
var writer = jsRuntime.switcher(
|
|
721
|
-
{
|
|
722
|
-
node: async (path3, data) => {
|
|
723
|
-
try {
|
|
724
|
-
await fs2__default.default.stat(path3);
|
|
725
|
-
const oldContent = await fs2__default.default.readFile(path3, { encoding: "utf-8" });
|
|
726
|
-
if (oldContent?.toString() === data) {
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
} catch (_err) {
|
|
730
|
-
}
|
|
731
|
-
await saveCreateDirectory(path3);
|
|
732
|
-
return fs2__default.default.writeFile(path2__default.default.resolve(path3), data, { encoding: "utf-8" });
|
|
733
|
-
},
|
|
734
|
-
bun: async (path3, data) => {
|
|
735
|
-
try {
|
|
736
|
-
await saveCreateDirectory(path3);
|
|
737
|
-
await Bun.write(path2__default.default.resolve(path3), data);
|
|
738
|
-
} catch (e) {
|
|
739
|
-
console.log(e, path2__default.default.resolve(path3));
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
},
|
|
743
|
-
"node"
|
|
744
|
-
);
|
|
745
|
-
async function write(data, path3) {
|
|
746
|
-
return writer(path3, data);
|
|
747
|
-
}
|
|
748
|
-
function getIndexes(root, extName, options = {}) {
|
|
749
|
-
const extMapper = {
|
|
750
|
-
".ts": {
|
|
751
|
-
extensions: /\.ts/,
|
|
752
|
-
exclude: [/schemas/, /json/]
|
|
753
|
-
},
|
|
754
|
-
".json": {
|
|
755
|
-
extensions: /\.json/,
|
|
756
|
-
exclude: []
|
|
803
|
+
remove(path5) {
|
|
804
|
+
const cacheItem = this.get(path5);
|
|
805
|
+
if (!cacheItem) {
|
|
806
|
+
return;
|
|
757
807
|
}
|
|
758
|
-
|
|
759
|
-
const tree = TreeNode.build(root, { ...extMapper[extName] || {}, ...options });
|
|
760
|
-
if (!tree) {
|
|
761
|
-
return null;
|
|
808
|
+
__privateGet(this, _cache).delete(path5);
|
|
762
809
|
}
|
|
763
|
-
|
|
764
|
-
if (!
|
|
765
|
-
|
|
810
|
+
async write(...params) {
|
|
811
|
+
if (!__privateGet(this, _isWriting)) {
|
|
812
|
+
__privateSet(this, _isWriting, true);
|
|
813
|
+
const text = await write(...params);
|
|
814
|
+
__privateSet(this, _isWriting, false);
|
|
815
|
+
return text;
|
|
766
816
|
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
return { path: importPath };
|
|
778
|
-
}).filter(Boolean);
|
|
779
|
-
files2.push({
|
|
780
|
-
path: path3,
|
|
781
|
-
baseName: "index.ts",
|
|
782
|
-
source: "",
|
|
783
|
-
exports
|
|
784
|
-
});
|
|
785
|
-
} else {
|
|
786
|
-
currentTree.children?.forEach((child) => {
|
|
787
|
-
const path3 = path2__default.default.resolve(currentTree.data.path, "index.ts");
|
|
788
|
-
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
789
|
-
files2.push({
|
|
790
|
-
path: path3,
|
|
791
|
-
baseName: "index.ts",
|
|
792
|
-
source: "",
|
|
793
|
-
exports: [{ path: importPath }]
|
|
794
|
-
});
|
|
795
|
-
});
|
|
817
|
+
await timeout(__privateGet(this, _timeout));
|
|
818
|
+
return this.write(...params);
|
|
819
|
+
}
|
|
820
|
+
async read(...params) {
|
|
821
|
+
return read(...params);
|
|
822
|
+
}
|
|
823
|
+
// statics
|
|
824
|
+
static getSource(file) {
|
|
825
|
+
if (!_FileManager.isExtensionAllowed(file.baseName)) {
|
|
826
|
+
return file.source;
|
|
796
827
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
});
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
828
|
+
const exports = file.exports ? combineExports(file.exports) : [];
|
|
829
|
+
const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
|
|
830
|
+
const importNodes = imports.map((item) => factory__namespace.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
831
|
+
const exportNodes = exports.map(
|
|
832
|
+
(item) => factory__namespace.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias })
|
|
833
|
+
);
|
|
834
|
+
return [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
835
|
+
}
|
|
836
|
+
static combineFiles(files) {
|
|
837
|
+
return files.filter(Boolean).reduce((acc, file) => {
|
|
838
|
+
const prevIndex = acc.findIndex((item) => item.path === file.path);
|
|
839
|
+
if (prevIndex === -1) {
|
|
840
|
+
return [...acc, file];
|
|
841
|
+
}
|
|
809
842
|
const prev = acc[prevIndex];
|
|
843
|
+
if (prev && file.override) {
|
|
844
|
+
acc[prevIndex] = {
|
|
845
|
+
imports: [],
|
|
846
|
+
exports: [],
|
|
847
|
+
...file
|
|
848
|
+
};
|
|
849
|
+
return acc;
|
|
850
|
+
}
|
|
810
851
|
if (prev) {
|
|
811
852
|
acc[prevIndex] = {
|
|
812
|
-
...
|
|
813
|
-
source: prev.source &&
|
|
814
|
-
${
|
|
815
|
-
imports: [...prev.imports || [], ...
|
|
816
|
-
exports: [...prev.exports || [], ...
|
|
817
|
-
env: { ...prev.env || {}, ...
|
|
853
|
+
...file,
|
|
854
|
+
source: prev.source && file.source ? `${prev.source}
|
|
855
|
+
${file.source}` : "",
|
|
856
|
+
imports: [...prev.imports || [], ...file.imports || []],
|
|
857
|
+
exports: [...prev.exports || [], ...file.exports || []],
|
|
858
|
+
env: { ...prev.env || {}, ...file.env || {} }
|
|
818
859
|
};
|
|
819
860
|
}
|
|
820
|
-
|
|
821
|
-
|
|
861
|
+
return acc;
|
|
862
|
+
}, []);
|
|
863
|
+
}
|
|
864
|
+
static getMode(path5) {
|
|
865
|
+
if (!path5) {
|
|
866
|
+
return "directory";
|
|
822
867
|
}
|
|
823
|
-
return
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
868
|
+
return path4.extname(path5) ? "file" : "directory";
|
|
869
|
+
}
|
|
870
|
+
static get extensions() {
|
|
871
|
+
return [".js", ".ts", ".tsx"];
|
|
872
|
+
}
|
|
873
|
+
static isExtensionAllowed(baseName) {
|
|
874
|
+
return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
_cache = new WeakMap();
|
|
878
|
+
_task = new WeakMap();
|
|
879
|
+
_isWriting = new WeakMap();
|
|
880
|
+
_timeout = new WeakMap();
|
|
881
|
+
_queue = new WeakMap();
|
|
882
|
+
_validate = new WeakSet();
|
|
883
|
+
validate_fn = function(file) {
|
|
884
|
+
if (!file.validate) {
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
|
|
888
|
+
throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
_add = new WeakSet();
|
|
892
|
+
add_fn = async function(file) {
|
|
893
|
+
const controller = new AbortController();
|
|
894
|
+
const resolvedFile = { id: crypto2__default.default.randomUUID(), ...file };
|
|
895
|
+
__privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
896
|
+
if (__privateGet(this, _queue)) {
|
|
897
|
+
await __privateGet(this, _queue).run(
|
|
898
|
+
async () => {
|
|
899
|
+
var _a;
|
|
900
|
+
return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
|
|
901
|
+
},
|
|
902
|
+
{ controller }
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
return resolvedFile;
|
|
906
|
+
};
|
|
907
|
+
_addOrAppend = new WeakSet();
|
|
908
|
+
addOrAppend_fn = async function(file) {
|
|
909
|
+
const previousCaches = __privateGet(this, _cache).get(file.path);
|
|
910
|
+
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
911
|
+
if (previousCache) {
|
|
912
|
+
__privateGet(this, _cache).delete(previousCache.path);
|
|
913
|
+
return __privateMethod(this, _add, add_fn).call(this, {
|
|
914
|
+
...file,
|
|
915
|
+
source: previousCache.source && file.source ? `${previousCache.source}
|
|
916
|
+
${file.source}` : "",
|
|
917
|
+
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
918
|
+
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
919
|
+
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
923
|
+
};
|
|
924
|
+
var FileManager = _FileManager;
|
|
830
925
|
function combineExports(exports) {
|
|
831
|
-
|
|
926
|
+
const combinedExports = naturalOrderby.orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
832
927
|
const name = curr.name;
|
|
833
928
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
929
|
+
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
|
|
930
|
+
if (prevByPathAndIsTypeOnly) {
|
|
931
|
+
return prev;
|
|
932
|
+
}
|
|
834
933
|
const uniquePrev = prev.findLast(
|
|
835
934
|
(imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
836
935
|
);
|
|
@@ -852,12 +951,16 @@ function combineExports(exports) {
|
|
|
852
951
|
}
|
|
853
952
|
return [...prev, curr];
|
|
854
953
|
}, []);
|
|
954
|
+
return naturalOrderby.orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
|
|
855
955
|
}
|
|
856
956
|
function combineImports(imports, exports, source) {
|
|
857
|
-
|
|
957
|
+
const combinedImports = naturalOrderby.orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
858
958
|
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
859
959
|
const hasImportInSource = (importName) => {
|
|
860
|
-
|
|
960
|
+
if (!source) {
|
|
961
|
+
return true;
|
|
962
|
+
}
|
|
963
|
+
const checker = (name2) => name2 && !!source.includes(name2);
|
|
861
964
|
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
862
965
|
};
|
|
863
966
|
if (Array.isArray(name)) {
|
|
@@ -865,6 +968,10 @@ function combineImports(imports, exports, source) {
|
|
|
865
968
|
}
|
|
866
969
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
867
970
|
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
971
|
+
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly);
|
|
972
|
+
if (prevByPathNameAndIsTypeOnly) {
|
|
973
|
+
return prev;
|
|
974
|
+
}
|
|
868
975
|
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
869
976
|
return prev;
|
|
870
977
|
}
|
|
@@ -886,43 +993,7 @@ function combineImports(imports, exports, source) {
|
|
|
886
993
|
}
|
|
887
994
|
return [...prev, curr];
|
|
888
995
|
}, []);
|
|
889
|
-
|
|
890
|
-
function createFileSource(file) {
|
|
891
|
-
let { source } = file;
|
|
892
|
-
if (!isExtensionAllowed(file.baseName)) {
|
|
893
|
-
return file.source;
|
|
894
|
-
}
|
|
895
|
-
const exports = file.exports ? combineExports(file.exports) : [];
|
|
896
|
-
const imports = file.imports ? combineImports(file.imports, exports, source) : [];
|
|
897
|
-
const importNodes = imports.map((item) => parser.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
898
|
-
const importSource = parser.print(importNodes);
|
|
899
|
-
const exportNodes = exports.map((item) => parser.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias }));
|
|
900
|
-
const exportSource = parser.print(exportNodes);
|
|
901
|
-
source = getEnvSource(file.source, file.env);
|
|
902
|
-
if (importSource) {
|
|
903
|
-
source = `${importSource}
|
|
904
|
-
${source}`;
|
|
905
|
-
}
|
|
906
|
-
if (exportSource) {
|
|
907
|
-
source = `${exportSource}
|
|
908
|
-
${source}`;
|
|
909
|
-
}
|
|
910
|
-
return source;
|
|
911
|
-
}
|
|
912
|
-
function searchAndReplace(options) {
|
|
913
|
-
const { text, replaceBy, prefix = "", key } = options;
|
|
914
|
-
const searchValues = options.searchValues?.(prefix, key) || [
|
|
915
|
-
`${prefix}["${key}"]`,
|
|
916
|
-
`${prefix}['${key}']`,
|
|
917
|
-
`${prefix}[\`${key}\`]`,
|
|
918
|
-
`${prefix}"${key}"`,
|
|
919
|
-
`${prefix}'${key}'`,
|
|
920
|
-
`${prefix}\`${key}\``,
|
|
921
|
-
new RegExp(`${prefix}${key}`, "g")
|
|
922
|
-
];
|
|
923
|
-
return searchValues.reduce((prev, searchValue) => {
|
|
924
|
-
return prev.toString().replaceAll(searchValue, replaceBy);
|
|
925
|
-
}, text);
|
|
996
|
+
return naturalOrderby.orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
|
|
926
997
|
}
|
|
927
998
|
function getEnvSource(source, env) {
|
|
928
999
|
if (!env) {
|
|
@@ -939,175 +1010,157 @@ function getEnvSource(source, env) {
|
|
|
939
1010
|
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
940
1011
|
}
|
|
941
1012
|
if (typeof replaceBy === "string") {
|
|
942
|
-
prev = searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
943
|
-
prev = searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
1013
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
1014
|
+
prev = transformers.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
944
1015
|
`, "ig"), ""), replaceBy, key });
|
|
945
1016
|
}
|
|
946
1017
|
return prev;
|
|
947
1018
|
}, source);
|
|
948
1019
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
#queue;
|
|
955
|
-
constructor(options) {
|
|
956
|
-
if (options) {
|
|
957
|
-
this.#task = options.task;
|
|
958
|
-
this.#queue = options.queue;
|
|
959
|
-
}
|
|
960
|
-
return this;
|
|
1020
|
+
var _emitter;
|
|
1021
|
+
var EventEmitter = class {
|
|
1022
|
+
constructor() {
|
|
1023
|
+
__privateAdd(this, _emitter, new events.EventEmitter());
|
|
1024
|
+
__privateGet(this, _emitter).setMaxListeners(100);
|
|
961
1025
|
}
|
|
962
|
-
|
|
963
|
-
|
|
1026
|
+
emit(eventName, ...eventArg) {
|
|
1027
|
+
__privateGet(this, _emitter).emit(eventName, ...eventArg);
|
|
964
1028
|
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
this.#cache.forEach((item) => {
|
|
968
|
-
files.push(...item.flat(1));
|
|
969
|
-
});
|
|
970
|
-
return files;
|
|
1029
|
+
on(eventName, handler) {
|
|
1030
|
+
__privateGet(this, _emitter).on(eventName, handler);
|
|
971
1031
|
}
|
|
972
|
-
|
|
973
|
-
|
|
1032
|
+
off(eventName, handler) {
|
|
1033
|
+
__privateGet(this, _emitter).off(eventName, handler);
|
|
974
1034
|
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
const resolvedFile = { id: crypto__default.default.randomUUID(), ...file };
|
|
978
|
-
this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
979
|
-
if (this.#queue) {
|
|
980
|
-
try {
|
|
981
|
-
await this.#queue.run(
|
|
982
|
-
async () => {
|
|
983
|
-
return this.#task?.(resolvedFile);
|
|
984
|
-
},
|
|
985
|
-
{ controller }
|
|
986
|
-
);
|
|
987
|
-
} catch {
|
|
988
|
-
return resolvedFile;
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
return resolvedFile;
|
|
1035
|
+
removeAll() {
|
|
1036
|
+
__privateGet(this, _emitter).removeAllListeners();
|
|
992
1037
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1038
|
+
};
|
|
1039
|
+
_emitter = new WeakMap();
|
|
1040
|
+
var _queue2, _workerCount, _maxParallel, _debug, _work, work_fn;
|
|
1041
|
+
var Queue = class {
|
|
1042
|
+
constructor(maxParallel, debug = false) {
|
|
1043
|
+
__privateAdd(this, _work);
|
|
1044
|
+
__privateAdd(this, _queue2, []);
|
|
1045
|
+
this.eventEmitter = new EventEmitter();
|
|
1046
|
+
__privateAdd(this, _workerCount, 0);
|
|
1047
|
+
__privateAdd(this, _maxParallel, void 0);
|
|
1048
|
+
__privateAdd(this, _debug, false);
|
|
1049
|
+
__privateSet(this, _maxParallel, maxParallel);
|
|
1050
|
+
__privateSet(this, _debug, debug);
|
|
1051
|
+
}
|
|
1052
|
+
run(job, options = { controller: new AbortController(), name: crypto2__default.default.randomUUID(), description: "" }) {
|
|
1053
|
+
return new Promise((resolve2, reject) => {
|
|
1054
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
1055
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
1056
|
+
__privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
|
|
1057
|
+
reject("Aborted");
|
|
1005
1058
|
});
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
async addIndexes(root, extName = ".ts", options = {}) {
|
|
1010
|
-
const files = await getIndexes(root, extName, options);
|
|
1011
|
-
if (!files) {
|
|
1012
|
-
return void 0;
|
|
1013
|
-
}
|
|
1014
|
-
return Promise.all(
|
|
1015
|
-
files.map((file) => {
|
|
1016
|
-
if (file.override) {
|
|
1017
|
-
return this.add(file);
|
|
1018
|
-
}
|
|
1019
|
-
return this.addOrAppend(file);
|
|
1020
|
-
})
|
|
1021
|
-
);
|
|
1022
|
-
}
|
|
1023
|
-
#append(path3, file) {
|
|
1024
|
-
const previousFiles = this.#cache.get(path3) || [];
|
|
1025
|
-
this.#cache.set(path3, [...previousFiles, file]);
|
|
1059
|
+
__privateGet(this, _queue2).push(item);
|
|
1060
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
1061
|
+
});
|
|
1026
1062
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1063
|
+
runSync(job, options = { controller: new AbortController(), name: crypto2__default.default.randomUUID(), description: "" }) {
|
|
1064
|
+
new Promise((resolve2, reject) => {
|
|
1065
|
+
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
1066
|
+
options.controller?.signal.addEventListener("abort", () => {
|
|
1067
|
+
__privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
|
|
1068
|
+
});
|
|
1069
|
+
__privateGet(this, _queue2).push(item);
|
|
1070
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
1031
1071
|
});
|
|
1032
|
-
return cache;
|
|
1033
1072
|
}
|
|
1034
|
-
get(
|
|
1035
|
-
return this
|
|
1073
|
+
get hasJobs() {
|
|
1074
|
+
return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue2).length > 0;
|
|
1036
1075
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
if (!cacheItem) {
|
|
1040
|
-
return;
|
|
1041
|
-
}
|
|
1042
|
-
this.#cache.delete(path3);
|
|
1076
|
+
get count() {
|
|
1077
|
+
return __privateGet(this, _workerCount);
|
|
1043
1078
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1079
|
+
};
|
|
1080
|
+
_queue2 = new WeakMap();
|
|
1081
|
+
_workerCount = new WeakMap();
|
|
1082
|
+
_maxParallel = new WeakMap();
|
|
1083
|
+
_debug = new WeakMap();
|
|
1084
|
+
_work = new WeakSet();
|
|
1085
|
+
work_fn = function() {
|
|
1086
|
+
if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
|
|
1087
|
+
return;
|
|
1051
1088
|
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1089
|
+
__privateWrapper(this, _workerCount)._++;
|
|
1090
|
+
let entry;
|
|
1091
|
+
while (entry = __privateGet(this, _queue2).shift()) {
|
|
1092
|
+
const { reject, resolve: resolve2, job, name, description } = entry;
|
|
1093
|
+
if (__privateGet(this, _debug)) {
|
|
1094
|
+
perf_hooks.performance.mark(name + "_start");
|
|
1095
|
+
}
|
|
1096
|
+
job().then((result) => {
|
|
1097
|
+
this.eventEmitter.emit("jobDone", result);
|
|
1098
|
+
resolve2(result);
|
|
1099
|
+
if (__privateGet(this, _debug)) {
|
|
1100
|
+
perf_hooks.performance.mark(name + "_stop");
|
|
1101
|
+
perf_hooks.performance.measure(description, name + "_start", name + "_stop");
|
|
1102
|
+
}
|
|
1103
|
+
}).catch((err) => {
|
|
1104
|
+
this.eventEmitter.emit("jobFailed", err);
|
|
1105
|
+
reject(err);
|
|
1106
|
+
});
|
|
1059
1107
|
}
|
|
1108
|
+
__privateWrapper(this, _workerCount)._--;
|
|
1060
1109
|
};
|
|
1061
1110
|
|
|
1062
|
-
// src/
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1111
|
+
// src/utils/uniqueName.ts
|
|
1112
|
+
function setUniqueName(originalName, data) {
|
|
1113
|
+
let used = data[originalName] || 0;
|
|
1114
|
+
if (used) {
|
|
1115
|
+
data[originalName] = ++used;
|
|
1116
|
+
return originalName;
|
|
1117
|
+
}
|
|
1118
|
+
data[originalName] = 1;
|
|
1119
|
+
return originalName;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// src/errors.ts
|
|
1123
|
+
var Warning = class extends Error {
|
|
1066
1124
|
constructor(message, options) {
|
|
1067
|
-
super(message, { cause: options
|
|
1068
|
-
this.name = "
|
|
1069
|
-
this.errors = options.errors;
|
|
1070
|
-
this.pluginManager = options.pluginManager;
|
|
1125
|
+
super(message, { cause: options?.cause });
|
|
1126
|
+
this.name = "Warning";
|
|
1071
1127
|
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1128
|
+
};
|
|
1129
|
+
var ValidationPluginError = class extends Error {
|
|
1130
|
+
};
|
|
1131
|
+
|
|
1132
|
+
// src/utils/cache.ts
|
|
1133
|
+
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
1134
|
+
return {
|
|
1135
|
+
set(id, value) {
|
|
1136
|
+
Store[id] = [0, value];
|
|
1137
|
+
},
|
|
1138
|
+
get(id) {
|
|
1139
|
+
const item = Store[id];
|
|
1140
|
+
if (!item) {
|
|
1141
|
+
return null;
|
|
1142
|
+
}
|
|
1143
|
+
item[0] = 0;
|
|
1144
|
+
return item[1];
|
|
1145
|
+
},
|
|
1146
|
+
has(id) {
|
|
1147
|
+
const item = Store[id];
|
|
1148
|
+
if (!item) {
|
|
1149
|
+
return false;
|
|
1082
1150
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1151
|
+
item[0] = 0;
|
|
1152
|
+
return true;
|
|
1153
|
+
},
|
|
1154
|
+
delete(id) {
|
|
1155
|
+
return delete Store[id];
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1087
1159
|
|
|
1088
|
-
// src/
|
|
1089
|
-
|
|
1090
|
-
pluginManager;
|
|
1091
|
-
cause;
|
|
1092
|
-
constructor(message, options) {
|
|
1093
|
-
super(message, { cause: options.cause });
|
|
1094
|
-
this.name = "PluginError";
|
|
1095
|
-
this.cause = options.cause;
|
|
1096
|
-
this.pluginManager = options.pluginManager;
|
|
1097
|
-
}
|
|
1098
|
-
};
|
|
1099
|
-
function createPlugin(factory) {
|
|
1160
|
+
// src/plugin.ts
|
|
1161
|
+
function createPlugin(factory2) {
|
|
1100
1162
|
return (options) => {
|
|
1101
|
-
|
|
1102
|
-
if (Array.isArray(plugin)) {
|
|
1103
|
-
throw new Error("Not implemented");
|
|
1104
|
-
}
|
|
1105
|
-
if (!plugin.transform) {
|
|
1106
|
-
plugin.transform = function transform(code) {
|
|
1107
|
-
return code;
|
|
1108
|
-
};
|
|
1109
|
-
}
|
|
1110
|
-
return plugin;
|
|
1163
|
+
return factory2(options);
|
|
1111
1164
|
};
|
|
1112
1165
|
}
|
|
1113
1166
|
var pluginName = "core";
|
|
@@ -1116,6 +1169,8 @@ var definePlugin = createPlugin((options) => {
|
|
|
1116
1169
|
return {
|
|
1117
1170
|
name: pluginName,
|
|
1118
1171
|
options,
|
|
1172
|
+
key: ["controller", "core"],
|
|
1173
|
+
kind: "controller",
|
|
1119
1174
|
api() {
|
|
1120
1175
|
return {
|
|
1121
1176
|
get config() {
|
|
@@ -1124,18 +1179,18 @@ var definePlugin = createPlugin((options) => {
|
|
|
1124
1179
|
get plugins() {
|
|
1125
1180
|
return options.getPlugins();
|
|
1126
1181
|
},
|
|
1182
|
+
get plugin() {
|
|
1183
|
+
return options.plugin;
|
|
1184
|
+
},
|
|
1127
1185
|
logger,
|
|
1128
1186
|
fileManager,
|
|
1129
1187
|
pluginManager,
|
|
1130
1188
|
async addFile(...files) {
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
return fileManager.addOrAppend(file);
|
|
1137
|
-
})
|
|
1138
|
-
);
|
|
1189
|
+
const resolvedFiles = await fileManager.add(...files);
|
|
1190
|
+
if (!Array.isArray(resolvedFiles)) {
|
|
1191
|
+
return [resolvedFiles];
|
|
1192
|
+
}
|
|
1193
|
+
return resolvedFiles;
|
|
1139
1194
|
},
|
|
1140
1195
|
resolvePath,
|
|
1141
1196
|
resolveName,
|
|
@@ -1143,75 +1198,156 @@ var definePlugin = createPlugin((options) => {
|
|
|
1143
1198
|
};
|
|
1144
1199
|
},
|
|
1145
1200
|
resolvePath(baseName) {
|
|
1146
|
-
const root =
|
|
1147
|
-
return
|
|
1201
|
+
const root = path4__default.default.resolve(this.config.root, this.config.output.path);
|
|
1202
|
+
return path4__default.default.resolve(root, baseName);
|
|
1148
1203
|
},
|
|
1149
1204
|
resolveName(name) {
|
|
1150
1205
|
return name;
|
|
1151
1206
|
}
|
|
1152
1207
|
};
|
|
1153
1208
|
});
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1209
|
+
|
|
1210
|
+
// src/utils/executeStrategies.ts
|
|
1211
|
+
function hookSeq(promises) {
|
|
1212
|
+
return promises.filter(Boolean).reduce(
|
|
1213
|
+
(promise, func) => {
|
|
1214
|
+
if (typeof func !== "function") {
|
|
1215
|
+
throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
1216
|
+
}
|
|
1217
|
+
return promise.then((state) => {
|
|
1218
|
+
const calledFunc = func(state);
|
|
1219
|
+
if (calledFunc) {
|
|
1220
|
+
return calledFunc.then(Array.prototype.concat.bind(state));
|
|
1221
|
+
}
|
|
1222
|
+
});
|
|
1223
|
+
},
|
|
1224
|
+
Promise.resolve([])
|
|
1225
|
+
);
|
|
1226
|
+
}
|
|
1227
|
+
function hookFirst(promises, nullCheck = (state) => state !== null) {
|
|
1228
|
+
let promise = Promise.resolve(null);
|
|
1229
|
+
for (const func of promises.filter(Boolean)) {
|
|
1230
|
+
promise = promise.then((state) => {
|
|
1231
|
+
if (nullCheck(state)) {
|
|
1232
|
+
return state;
|
|
1233
|
+
}
|
|
1234
|
+
const calledFunc = func(state);
|
|
1235
|
+
return calledFunc;
|
|
1236
|
+
});
|
|
1164
1237
|
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1238
|
+
return promise;
|
|
1239
|
+
}
|
|
1240
|
+
function hookParallel(promises) {
|
|
1241
|
+
return Promise.allSettled(promises.filter(Boolean).map((promise) => promise()));
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
// src/PromiseManager.ts
|
|
1245
|
+
var _options2;
|
|
1246
|
+
var PromiseManager = class {
|
|
1247
|
+
constructor(options = {}) {
|
|
1248
|
+
__privateAdd(this, _options2, {});
|
|
1249
|
+
__privateSet(this, _options2, options);
|
|
1250
|
+
return this;
|
|
1167
1251
|
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1252
|
+
run(strategy, promises) {
|
|
1253
|
+
if (strategy === "seq") {
|
|
1254
|
+
return hookSeq(promises);
|
|
1255
|
+
}
|
|
1256
|
+
if (strategy === "first") {
|
|
1257
|
+
return hookFirst(promises, __privateGet(this, _options2).nullCheck);
|
|
1258
|
+
}
|
|
1259
|
+
if (strategy === "parallel") {
|
|
1260
|
+
return hookParallel(promises);
|
|
1261
|
+
}
|
|
1262
|
+
throw new Error(`${strategy} not implemented`);
|
|
1170
1263
|
}
|
|
1171
1264
|
};
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
const api = plugin.api.call(context);
|
|
1179
|
-
return {
|
|
1180
|
-
...plugin,
|
|
1181
|
-
key,
|
|
1182
|
-
api
|
|
1183
|
-
};
|
|
1184
|
-
}
|
|
1185
|
-
return {
|
|
1186
|
-
...plugin,
|
|
1187
|
-
key
|
|
1188
|
-
};
|
|
1265
|
+
_options2 = new WeakMap();
|
|
1266
|
+
function isPromise(result) {
|
|
1267
|
+
return !!result && typeof result?.then === "function";
|
|
1268
|
+
}
|
|
1269
|
+
function isPromiseRejectedResult(result) {
|
|
1270
|
+
return result.status === "rejected";
|
|
1189
1271
|
}
|
|
1190
1272
|
|
|
1191
|
-
// src/
|
|
1192
|
-
var
|
|
1193
|
-
validate: 1,
|
|
1194
|
-
buildStart: 1,
|
|
1195
|
-
resolvePath: 1,
|
|
1196
|
-
resolveName: 1,
|
|
1197
|
-
load: 1,
|
|
1198
|
-
transform: 1,
|
|
1199
|
-
writeFile: 1,
|
|
1200
|
-
buildEnd: 1
|
|
1201
|
-
};
|
|
1202
|
-
var hooks = Object.keys(hookNames);
|
|
1273
|
+
// src/PluginManager.ts
|
|
1274
|
+
var _core, _usedPluginNames, _promiseManager, _getSortedPlugins, getSortedPlugins_fn, _addExecutedToCallStack, addExecutedToCallStack_fn, _execute, execute_fn, _executeSync, executeSync_fn, _catcher, catcher_fn, _parse, parse_fn;
|
|
1203
1275
|
var PluginManager = class {
|
|
1204
|
-
plugins;
|
|
1205
|
-
fileManager;
|
|
1206
|
-
eventEmitter = new EventEmitter();
|
|
1207
|
-
queue;
|
|
1208
|
-
executed = [];
|
|
1209
|
-
logger;
|
|
1210
|
-
#core;
|
|
1211
1276
|
constructor(config, options) {
|
|
1277
|
+
__privateAdd(this, _getSortedPlugins);
|
|
1278
|
+
__privateAdd(this, _addExecutedToCallStack);
|
|
1279
|
+
/**
|
|
1280
|
+
* Run an async plugin hook and return the result.
|
|
1281
|
+
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
1282
|
+
* @param args Arguments passed to the plugin hook.
|
|
1283
|
+
* @param plugin The actual pluginObject to run.
|
|
1284
|
+
*/
|
|
1285
|
+
// Implementation signature
|
|
1286
|
+
__privateAdd(this, _execute);
|
|
1287
|
+
/**
|
|
1288
|
+
* Run a sync plugin hook and return the result.
|
|
1289
|
+
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
1290
|
+
* @param args Arguments passed to the plugin hook.
|
|
1291
|
+
* @param plugin The acutal plugin
|
|
1292
|
+
* @param replaceContext When passed, the plugin context can be overridden.
|
|
1293
|
+
*/
|
|
1294
|
+
__privateAdd(this, _executeSync);
|
|
1295
|
+
__privateAdd(this, _catcher);
|
|
1296
|
+
__privateAdd(this, _parse);
|
|
1297
|
+
this.eventEmitter = new EventEmitter();
|
|
1298
|
+
this.executed = [];
|
|
1299
|
+
__privateAdd(this, _core, void 0);
|
|
1300
|
+
__privateAdd(this, _usedPluginNames, {});
|
|
1301
|
+
__privateAdd(this, _promiseManager, void 0);
|
|
1302
|
+
this.resolvePath = (params) => {
|
|
1303
|
+
if (params.pluginKey) {
|
|
1304
|
+
const paths = this.hookForPluginSync({
|
|
1305
|
+
pluginKey: params.pluginKey,
|
|
1306
|
+
hookName: "resolvePath",
|
|
1307
|
+
parameters: [params.baseName, params.directory, params.options]
|
|
1308
|
+
});
|
|
1309
|
+
if (paths && paths?.length > 1) {
|
|
1310
|
+
throw new Error(
|
|
1311
|
+
`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1312
|
+
|
|
1313
|
+
Paths: ${JSON.stringify(paths, void 0, 2)}`
|
|
1314
|
+
);
|
|
1315
|
+
}
|
|
1316
|
+
return paths?.at(0);
|
|
1317
|
+
}
|
|
1318
|
+
return this.hookFirstSync({
|
|
1319
|
+
hookName: "resolvePath",
|
|
1320
|
+
parameters: [params.baseName, params.directory, params.options]
|
|
1321
|
+
}).result;
|
|
1322
|
+
};
|
|
1323
|
+
this.resolveName = (params) => {
|
|
1324
|
+
if (params.pluginKey) {
|
|
1325
|
+
const names = this.hookForPluginSync({
|
|
1326
|
+
pluginKey: params.pluginKey,
|
|
1327
|
+
hookName: "resolveName",
|
|
1328
|
+
parameters: [params.name, params.type]
|
|
1329
|
+
});
|
|
1330
|
+
if (names && names?.length > 1) {
|
|
1331
|
+
throw new Error(
|
|
1332
|
+
`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1333
|
+
|
|
1334
|
+
Names: ${JSON.stringify(names, void 0, 2)}`
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
return transformReservedWord(names?.at(0) || params.name);
|
|
1338
|
+
}
|
|
1339
|
+
const name = this.hookFirstSync({
|
|
1340
|
+
hookName: "resolveName",
|
|
1341
|
+
parameters: [params.name, params.type]
|
|
1342
|
+
}).result;
|
|
1343
|
+
return transformReservedWord(name);
|
|
1344
|
+
};
|
|
1345
|
+
this.config = config;
|
|
1212
1346
|
this.logger = options.logger;
|
|
1213
|
-
this.queue = new Queue(100,
|
|
1214
|
-
this.fileManager = new FileManager({ task: options.task, queue: this.queue });
|
|
1347
|
+
this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
|
|
1348
|
+
this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
|
|
1349
|
+
__privateSet(this, _promiseManager, new PromiseManager({ nullCheck: (state) => !!state?.result }));
|
|
1350
|
+
const plugins = config.plugins || [];
|
|
1215
1351
|
const core = definePlugin({
|
|
1216
1352
|
config,
|
|
1217
1353
|
logger: this.logger,
|
|
@@ -1219,44 +1355,14 @@ var PluginManager = class {
|
|
|
1219
1355
|
fileManager: this.fileManager,
|
|
1220
1356
|
resolvePath: this.resolvePath.bind(this),
|
|
1221
1357
|
resolveName: this.resolveName.bind(this),
|
|
1222
|
-
getPlugins: this
|
|
1223
|
-
|
|
1358
|
+
getPlugins: __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).bind(this)
|
|
1359
|
+
});
|
|
1360
|
+
__privateSet(this, _core, __privateMethod(this, _parse, parse_fn).call(this, core, this, core.api.call(null)));
|
|
1361
|
+
this.plugins = [__privateGet(this, _core), ...plugins].map((plugin) => {
|
|
1362
|
+
return __privateMethod(this, _parse, parse_fn).call(this, plugin, this, __privateGet(this, _core).api);
|
|
1224
1363
|
});
|
|
1225
|
-
this.#core = pluginParser(core, core.api.call(null));
|
|
1226
|
-
this.plugins = [this.#core, ...config.plugins || []].reduce((prev, plugin) => {
|
|
1227
|
-
const convertedApi = pluginParser(plugin, this.#core?.api);
|
|
1228
|
-
return [...prev, convertedApi];
|
|
1229
|
-
}, []);
|
|
1230
1364
|
return this;
|
|
1231
1365
|
}
|
|
1232
|
-
resolvePath = (params) => {
|
|
1233
|
-
if (params.pluginName) {
|
|
1234
|
-
return this.hookForPluginSync({
|
|
1235
|
-
pluginName: params.pluginName,
|
|
1236
|
-
hookName: "resolvePath",
|
|
1237
|
-
parameters: [params.baseName, params.directory, params.options]
|
|
1238
|
-
});
|
|
1239
|
-
}
|
|
1240
|
-
return this.hookFirstSync({
|
|
1241
|
-
hookName: "resolvePath",
|
|
1242
|
-
parameters: [params.baseName, params.directory, params.options]
|
|
1243
|
-
}).result;
|
|
1244
|
-
};
|
|
1245
|
-
resolveName = (params) => {
|
|
1246
|
-
if (params.pluginName) {
|
|
1247
|
-
const name2 = this.hookForPluginSync({
|
|
1248
|
-
pluginName: params.pluginName,
|
|
1249
|
-
hookName: "resolveName",
|
|
1250
|
-
parameters: [params.name, params.type]
|
|
1251
|
-
});
|
|
1252
|
-
return transformReservedWord(name2 || params.name);
|
|
1253
|
-
}
|
|
1254
|
-
const name = this.hookFirstSync({
|
|
1255
|
-
hookName: "resolveName",
|
|
1256
|
-
parameters: [params.name, params.type]
|
|
1257
|
-
}).result;
|
|
1258
|
-
return transformReservedWord(name);
|
|
1259
|
-
};
|
|
1260
1366
|
on(eventName, handler) {
|
|
1261
1367
|
this.eventEmitter.on(eventName, handler);
|
|
1262
1368
|
}
|
|
@@ -1264,49 +1370,49 @@ var PluginManager = class {
|
|
|
1264
1370
|
* Run only hook for a specific plugin name
|
|
1265
1371
|
*/
|
|
1266
1372
|
hookForPlugin({
|
|
1267
|
-
|
|
1373
|
+
pluginKey,
|
|
1268
1374
|
hookName,
|
|
1269
1375
|
parameters
|
|
1270
1376
|
}) {
|
|
1271
|
-
const
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1377
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1378
|
+
const promises = plugins.map((plugin) => {
|
|
1379
|
+
return __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1380
|
+
strategy: "hookFirst",
|
|
1381
|
+
hookName,
|
|
1382
|
+
parameters,
|
|
1383
|
+
plugin
|
|
1384
|
+
});
|
|
1385
|
+
}).filter(Boolean);
|
|
1386
|
+
return Promise.all(promises);
|
|
1278
1387
|
}
|
|
1279
1388
|
hookForPluginSync({
|
|
1280
|
-
|
|
1389
|
+
pluginKey,
|
|
1281
1390
|
hookName,
|
|
1282
1391
|
parameters
|
|
1283
1392
|
}) {
|
|
1284
|
-
const
|
|
1285
|
-
return
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1393
|
+
const plugins = this.getPluginsByKey(hookName, pluginKey);
|
|
1394
|
+
return plugins.map((plugin) => {
|
|
1395
|
+
return __privateMethod(this, _executeSync, executeSync_fn).call(this, {
|
|
1396
|
+
strategy: "hookFirst",
|
|
1397
|
+
hookName,
|
|
1398
|
+
parameters,
|
|
1399
|
+
plugin
|
|
1400
|
+
});
|
|
1401
|
+
}).filter(Boolean);
|
|
1291
1402
|
}
|
|
1292
1403
|
/**
|
|
1293
1404
|
* Chains, first non-null result stops and returns
|
|
1294
1405
|
*/
|
|
1295
|
-
hookFirst({
|
|
1406
|
+
async hookFirst({
|
|
1296
1407
|
hookName,
|
|
1297
1408
|
parameters,
|
|
1298
1409
|
skipped
|
|
1299
1410
|
}) {
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
promise = promise.then(async (parseResult) => {
|
|
1306
|
-
if (parseResult?.result != null) {
|
|
1307
|
-
return parseResult;
|
|
1308
|
-
}
|
|
1309
|
-
const value = await this.#execute({
|
|
1411
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).filter((plugin) => {
|
|
1412
|
+
return skipped ? skipped.has(plugin) : true;
|
|
1413
|
+
}).map((plugin) => {
|
|
1414
|
+
return async () => {
|
|
1415
|
+
const value = await __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1310
1416
|
strategy: "hookFirst",
|
|
1311
1417
|
hookName,
|
|
1312
1418
|
parameters,
|
|
@@ -1318,9 +1424,9 @@ var PluginManager = class {
|
|
|
1318
1424
|
result: value
|
|
1319
1425
|
}
|
|
1320
1426
|
);
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
return
|
|
1427
|
+
};
|
|
1428
|
+
});
|
|
1429
|
+
return __privateGet(this, _promiseManager).run("first", promises);
|
|
1324
1430
|
}
|
|
1325
1431
|
/**
|
|
1326
1432
|
* Chains, first non-null result stops and returns
|
|
@@ -1331,12 +1437,12 @@ var PluginManager = class {
|
|
|
1331
1437
|
skipped
|
|
1332
1438
|
}) {
|
|
1333
1439
|
let parseResult = null;
|
|
1334
|
-
for (const plugin of this
|
|
1440
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1335
1441
|
if (skipped && skipped.has(plugin)) {
|
|
1336
1442
|
continue;
|
|
1337
1443
|
}
|
|
1338
1444
|
parseResult = {
|
|
1339
|
-
result: this
|
|
1445
|
+
result: __privateMethod(this, _executeSync, executeSync_fn).call(this, {
|
|
1340
1446
|
strategy: "hookFirst",
|
|
1341
1447
|
hookName,
|
|
1342
1448
|
parameters,
|
|
@@ -1357,23 +1463,16 @@ var PluginManager = class {
|
|
|
1357
1463
|
hookName,
|
|
1358
1464
|
parameters
|
|
1359
1465
|
}) {
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
const errors = results.map((result) => {
|
|
1369
|
-
if (isPromiseRejectedResult(result) && result.reason instanceof PluginError) {
|
|
1370
|
-
return result.reason;
|
|
1466
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1467
|
+
return () => __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
|
|
1468
|
+
});
|
|
1469
|
+
const results = await __privateGet(this, _promiseManager).run("parallel", promises);
|
|
1470
|
+
results.forEach((result, index) => {
|
|
1471
|
+
if (isPromiseRejectedResult(result)) {
|
|
1472
|
+
const plugin = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)[index];
|
|
1473
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, result.reason, plugin, hookName);
|
|
1371
1474
|
}
|
|
1372
|
-
|
|
1373
|
-
}).filter(Boolean);
|
|
1374
|
-
if (errors.length) {
|
|
1375
|
-
throw new ParallelPluginError("Error", { errors, pluginManager: this });
|
|
1376
|
-
}
|
|
1475
|
+
});
|
|
1377
1476
|
return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
1378
1477
|
}
|
|
1379
1478
|
/**
|
|
@@ -1386,191 +1485,220 @@ var PluginManager = class {
|
|
|
1386
1485
|
}) {
|
|
1387
1486
|
const [argument0, ...rest] = parameters;
|
|
1388
1487
|
let promise = Promise.resolve(argument0);
|
|
1389
|
-
for (const plugin of this
|
|
1488
|
+
for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
|
|
1390
1489
|
promise = promise.then((arg0) => {
|
|
1391
|
-
const value = this
|
|
1490
|
+
const value = __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1392
1491
|
strategy: "hookReduceArg0",
|
|
1393
1492
|
hookName,
|
|
1394
1493
|
parameters: [arg0, ...rest],
|
|
1395
1494
|
plugin
|
|
1396
1495
|
});
|
|
1397
1496
|
return value;
|
|
1398
|
-
}).then((result) => reduce.call(this
|
|
1497
|
+
}).then((result) => reduce.call(__privateGet(this, _core).api, argument0, result, plugin));
|
|
1399
1498
|
}
|
|
1400
1499
|
return promise;
|
|
1401
1500
|
}
|
|
1402
1501
|
/**
|
|
1403
1502
|
* Chains plugins
|
|
1404
1503
|
*/
|
|
1405
|
-
hookSeq({ hookName, parameters }) {
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
parameters,
|
|
1413
|
-
plugin
|
|
1414
|
-
});
|
|
1504
|
+
async hookSeq({ hookName, parameters }) {
|
|
1505
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1506
|
+
return () => __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1507
|
+
strategy: "hookSeq",
|
|
1508
|
+
hookName,
|
|
1509
|
+
parameters,
|
|
1510
|
+
plugin
|
|
1415
1511
|
});
|
|
1416
|
-
}
|
|
1417
|
-
return
|
|
1418
|
-
}
|
|
1419
|
-
#getSortedPlugins(hookName) {
|
|
1420
|
-
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1421
|
-
if (hookName) {
|
|
1422
|
-
return plugins.filter((item) => item[hookName]);
|
|
1423
|
-
}
|
|
1424
|
-
return plugins;
|
|
1512
|
+
});
|
|
1513
|
+
return __privateGet(this, _promiseManager).run("seq", promises);
|
|
1425
1514
|
}
|
|
1426
|
-
|
|
1515
|
+
getPluginsByKey(hookName, pluginKey) {
|
|
1427
1516
|
const plugins = [...this.plugins];
|
|
1428
|
-
const
|
|
1429
|
-
|
|
1430
|
-
|
|
1517
|
+
const [searchKind, searchPluginName, searchIdentifier] = pluginKey;
|
|
1518
|
+
const pluginByPluginName = plugins.filter((plugin) => plugin[hookName]).filter((item) => {
|
|
1519
|
+
const [kind, name, identifier] = item.key;
|
|
1520
|
+
const identifierCheck = identifier?.toString() === searchIdentifier?.toString();
|
|
1521
|
+
const kindCheck = kind === searchKind;
|
|
1522
|
+
const nameCheck = name === searchPluginName;
|
|
1523
|
+
if (searchIdentifier) {
|
|
1524
|
+
return identifierCheck && kindCheck && nameCheck;
|
|
1525
|
+
}
|
|
1526
|
+
return kindCheck && nameCheck;
|
|
1527
|
+
});
|
|
1528
|
+
if (!pluginByPluginName?.length) {
|
|
1529
|
+
const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
|
|
1530
|
+
if (this.logger.logLevel === "info") {
|
|
1531
|
+
if (corePlugin) {
|
|
1532
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
|
|
1533
|
+
} else {
|
|
1534
|
+
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, no fallback found in the '@kubb/core' plugin`);
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
return corePlugin ? [corePlugin] : [];
|
|
1431
1538
|
}
|
|
1432
1539
|
return pluginByPluginName;
|
|
1433
1540
|
}
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
/**
|
|
1441
|
-
* Run an async plugin hook and return the result.
|
|
1442
|
-
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
1443
|
-
* @param args Arguments passed to the plugin hook.
|
|
1444
|
-
* @param plugin The actual pluginObject to run.
|
|
1445
|
-
*/
|
|
1446
|
-
// Implementation signature
|
|
1447
|
-
#execute({
|
|
1448
|
-
strategy,
|
|
1449
|
-
hookName,
|
|
1450
|
-
parameters,
|
|
1451
|
-
plugin
|
|
1452
|
-
}) {
|
|
1453
|
-
const hook = plugin[hookName];
|
|
1454
|
-
let output;
|
|
1455
|
-
if (!hook) {
|
|
1456
|
-
return null;
|
|
1541
|
+
static getDependedPlugins(plugins, dependedPluginNames) {
|
|
1542
|
+
let pluginNames = [];
|
|
1543
|
+
if (typeof dependedPluginNames === "string") {
|
|
1544
|
+
pluginNames = [dependedPluginNames];
|
|
1545
|
+
} else {
|
|
1546
|
+
pluginNames = dependedPluginNames;
|
|
1457
1547
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
if (
|
|
1461
|
-
|
|
1462
|
-
if (isPromise(possiblePromiseResult)) {
|
|
1463
|
-
return Promise.resolve(possiblePromiseResult);
|
|
1464
|
-
}
|
|
1465
|
-
return possiblePromiseResult;
|
|
1548
|
+
return pluginNames.map((pluginName2) => {
|
|
1549
|
+
const plugin = plugins.find((plugin2) => plugin2.name === pluginName2);
|
|
1550
|
+
if (!plugin) {
|
|
1551
|
+
throw new ValidationPluginError(`This plugin depends on the ${pluginName2} plugin.`);
|
|
1466
1552
|
}
|
|
1467
|
-
return
|
|
1468
|
-
}).then((result) => {
|
|
1469
|
-
output = result;
|
|
1470
|
-
return result;
|
|
1471
|
-
}).catch((e) => {
|
|
1472
|
-
this.#catcher(e, plugin, hookName);
|
|
1473
|
-
return null;
|
|
1474
|
-
}).finally(() => {
|
|
1475
|
-
this.#addExecutedToCallStack({
|
|
1476
|
-
parameters,
|
|
1477
|
-
output,
|
|
1478
|
-
strategy,
|
|
1479
|
-
hookName,
|
|
1480
|
-
plugin
|
|
1481
|
-
});
|
|
1553
|
+
return plugin;
|
|
1482
1554
|
});
|
|
1483
|
-
return task;
|
|
1484
1555
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1556
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
1557
|
+
static get hooks() {
|
|
1558
|
+
return ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
_core = new WeakMap();
|
|
1562
|
+
_usedPluginNames = new WeakMap();
|
|
1563
|
+
_promiseManager = new WeakMap();
|
|
1564
|
+
_getSortedPlugins = new WeakSet();
|
|
1565
|
+
getSortedPlugins_fn = function(hookName) {
|
|
1566
|
+
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1567
|
+
if (hookName) {
|
|
1568
|
+
if (this.logger.logLevel === "info") {
|
|
1569
|
+
const containsHookName = plugins.some((item) => item[hookName]);
|
|
1570
|
+
if (!containsHookName) {
|
|
1571
|
+
this.logger.warn(`No hook ${hookName} found`);
|
|
1572
|
+
}
|
|
1502
1573
|
}
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1574
|
+
return plugins.filter((item) => item[hookName]);
|
|
1575
|
+
}
|
|
1576
|
+
return plugins;
|
|
1577
|
+
};
|
|
1578
|
+
_addExecutedToCallStack = new WeakSet();
|
|
1579
|
+
addExecutedToCallStack_fn = function(executer) {
|
|
1580
|
+
if (executer) {
|
|
1581
|
+
this.eventEmitter.emit("executed", executer);
|
|
1582
|
+
this.executed.push(executer);
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
_execute = new WeakSet();
|
|
1586
|
+
execute_fn = function({
|
|
1587
|
+
strategy,
|
|
1588
|
+
hookName,
|
|
1589
|
+
parameters,
|
|
1590
|
+
plugin
|
|
1591
|
+
}) {
|
|
1592
|
+
const hook = plugin[hookName];
|
|
1593
|
+
let output;
|
|
1594
|
+
if (!hook) {
|
|
1595
|
+
return null;
|
|
1596
|
+
}
|
|
1597
|
+
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1598
|
+
const task = Promise.resolve().then(() => {
|
|
1599
|
+
if (typeof hook === "function") {
|
|
1600
|
+
const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
1601
|
+
if (isPromise(possiblePromiseResult)) {
|
|
1602
|
+
return Promise.resolve(possiblePromiseResult);
|
|
1509
1603
|
}
|
|
1510
|
-
|
|
1511
|
-
return hook;
|
|
1512
|
-
} catch (e) {
|
|
1513
|
-
this.#catcher(e, plugin, hookName);
|
|
1514
|
-
return null;
|
|
1515
|
-
} finally {
|
|
1516
|
-
this.#addExecutedToCallStack({
|
|
1517
|
-
parameters,
|
|
1518
|
-
output,
|
|
1519
|
-
strategy,
|
|
1520
|
-
hookName,
|
|
1521
|
-
plugin
|
|
1522
|
-
});
|
|
1604
|
+
return possiblePromiseResult;
|
|
1523
1605
|
}
|
|
1606
|
+
return hook;
|
|
1607
|
+
}).then((result) => {
|
|
1608
|
+
output = result;
|
|
1609
|
+
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1610
|
+
parameters,
|
|
1611
|
+
output,
|
|
1612
|
+
strategy,
|
|
1613
|
+
hookName,
|
|
1614
|
+
plugin
|
|
1615
|
+
});
|
|
1616
|
+
return result;
|
|
1617
|
+
}).catch((e) => {
|
|
1618
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1619
|
+
return null;
|
|
1620
|
+
});
|
|
1621
|
+
return task;
|
|
1622
|
+
};
|
|
1623
|
+
_executeSync = new WeakSet();
|
|
1624
|
+
executeSync_fn = function({
|
|
1625
|
+
strategy,
|
|
1626
|
+
hookName,
|
|
1627
|
+
parameters,
|
|
1628
|
+
plugin
|
|
1629
|
+
}) {
|
|
1630
|
+
const hook = plugin[hookName];
|
|
1631
|
+
let output;
|
|
1632
|
+
if (!hook) {
|
|
1633
|
+
return null;
|
|
1524
1634
|
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1635
|
+
this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
|
|
1636
|
+
try {
|
|
1637
|
+
if (typeof hook === "function") {
|
|
1638
|
+
const fn = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
|
|
1639
|
+
output = fn;
|
|
1640
|
+
return fn;
|
|
1641
|
+
}
|
|
1642
|
+
output = hook;
|
|
1643
|
+
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1644
|
+
parameters,
|
|
1645
|
+
output,
|
|
1646
|
+
strategy,
|
|
1647
|
+
hookName,
|
|
1648
|
+
plugin
|
|
1649
|
+
});
|
|
1650
|
+
return hook;
|
|
1651
|
+
} catch (e) {
|
|
1652
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1653
|
+
return null;
|
|
1531
1654
|
}
|
|
1532
1655
|
};
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1656
|
+
_catcher = new WeakSet();
|
|
1657
|
+
catcher_fn = function(e, plugin, hookName) {
|
|
1658
|
+
const text = `${e.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})
|
|
1659
|
+
`;
|
|
1660
|
+
this.logger.error(text);
|
|
1661
|
+
this.eventEmitter.emit("error", e);
|
|
1538
1662
|
};
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1663
|
+
_parse = new WeakSet();
|
|
1664
|
+
parse_fn = function(plugin, pluginManager, context) {
|
|
1665
|
+
const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
|
|
1666
|
+
setUniqueName(plugin.name, usedPluginNames);
|
|
1667
|
+
const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
1668
|
+
if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
|
|
1669
|
+
pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
|
|
1670
|
+
}
|
|
1671
|
+
if (!plugin.transform) {
|
|
1672
|
+
plugin.transform = function transform(code) {
|
|
1673
|
+
return code;
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
if (plugin.api && typeof plugin.api === "function") {
|
|
1677
|
+
const api = plugin.api.call(context);
|
|
1678
|
+
return {
|
|
1679
|
+
...plugin,
|
|
1680
|
+
key,
|
|
1681
|
+
api
|
|
1682
|
+
};
|
|
1683
|
+
}
|
|
1684
|
+
return {
|
|
1685
|
+
...plugin,
|
|
1686
|
+
key
|
|
1687
|
+
};
|
|
1560
1688
|
};
|
|
1561
1689
|
|
|
1562
1690
|
// src/build.ts
|
|
1563
1691
|
async function transformReducer(_previousCode, result, _plugin) {
|
|
1564
1692
|
return result;
|
|
1565
1693
|
}
|
|
1566
|
-
async function
|
|
1567
|
-
const { config,
|
|
1694
|
+
async function setup(options) {
|
|
1695
|
+
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
1568
1696
|
try {
|
|
1569
|
-
if (
|
|
1697
|
+
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
1570
1698
|
await read(config.input.path);
|
|
1571
1699
|
}
|
|
1572
1700
|
} catch (e) {
|
|
1573
|
-
if (
|
|
1701
|
+
if (isInputPath(config)) {
|
|
1574
1702
|
throw new Error(
|
|
1575
1703
|
"Cannot read file/URL defined in `input.path` or set with `kubb generate PATH` in the CLI of your Kubb config " + pc3__default.default.dim(config.input.path),
|
|
1576
1704
|
{
|
|
@@ -1583,11 +1711,11 @@ async function build(options) {
|
|
|
1583
1711
|
await clean(config.output.path);
|
|
1584
1712
|
}
|
|
1585
1713
|
const queueTask = async (file) => {
|
|
1586
|
-
const { path:
|
|
1587
|
-
let code =
|
|
1714
|
+
const { path: path5 } = file;
|
|
1715
|
+
let code = FileManager.getSource(file);
|
|
1588
1716
|
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1589
1717
|
hookName: "load",
|
|
1590
|
-
parameters: [
|
|
1718
|
+
parameters: [path5]
|
|
1591
1719
|
});
|
|
1592
1720
|
if (loadedResult && isPromise(loadedResult)) {
|
|
1593
1721
|
code = await loadedResult;
|
|
@@ -1598,28 +1726,52 @@ async function build(options) {
|
|
|
1598
1726
|
if (code) {
|
|
1599
1727
|
const transformedCode = await pluginManager.hookReduceArg0({
|
|
1600
1728
|
hookName: "transform",
|
|
1601
|
-
parameters: [code,
|
|
1729
|
+
parameters: [code, path5],
|
|
1602
1730
|
reduce: transformReducer
|
|
1603
1731
|
});
|
|
1604
1732
|
if (config.output.write || config.output.write === void 0) {
|
|
1605
|
-
|
|
1733
|
+
if (file.meta?.pluginKey) {
|
|
1734
|
+
return pluginManager.hookForPlugin({
|
|
1735
|
+
pluginKey: file.meta?.pluginKey,
|
|
1736
|
+
hookName: "writeFile",
|
|
1737
|
+
parameters: [transformedCode, path5]
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1740
|
+
return pluginManager.hookFirst({
|
|
1606
1741
|
hookName: "writeFile",
|
|
1607
|
-
parameters: [transformedCode,
|
|
1742
|
+
parameters: [transformedCode, path5]
|
|
1608
1743
|
});
|
|
1609
1744
|
}
|
|
1610
1745
|
}
|
|
1611
1746
|
};
|
|
1612
|
-
const pluginManager = new PluginManager(config, {
|
|
1613
|
-
const { plugins, fileManager } = pluginManager;
|
|
1747
|
+
const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
|
|
1614
1748
|
pluginManager.on("execute", (executer) => {
|
|
1749
|
+
const { hookName, parameters, plugin } = executer;
|
|
1750
|
+
if (hookName === "writeFile" && logger.spinner) {
|
|
1751
|
+
const [code] = parameters;
|
|
1752
|
+
if (logger.logLevel === LogLevel.info) {
|
|
1753
|
+
logger.spinner.start(`\u{1F4BE} Writing`);
|
|
1754
|
+
}
|
|
1755
|
+
if (logger.logLevel === "debug") {
|
|
1756
|
+
logger.info(`PluginKey ${pc3__default.default.dim(JSON.stringify(plugin.key))}
|
|
1757
|
+
with source
|
|
1758
|
+
|
|
1759
|
+
${code}`);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
});
|
|
1763
|
+
pluginManager.on("executed", (executer) => {
|
|
1615
1764
|
const { hookName, plugin, output, parameters } = executer;
|
|
1616
1765
|
const messsage = `${randomPicoColour(plugin.name)} Executing ${hookName}`;
|
|
1617
|
-
if (logLevel === LogLevel.info) {
|
|
1618
|
-
if (
|
|
1766
|
+
if (logger.logLevel === LogLevel.info && logger.spinner) {
|
|
1767
|
+
if (hookName === "writeFile") {
|
|
1768
|
+
const [_code, path5] = parameters;
|
|
1769
|
+
logger.spinner.suffixText = pc3__default.default.dim(path5);
|
|
1770
|
+
} else {
|
|
1619
1771
|
logger.spinner.suffixText = messsage;
|
|
1620
1772
|
}
|
|
1621
1773
|
}
|
|
1622
|
-
if (logLevel === LogLevel.debug) {
|
|
1774
|
+
if (logger.logLevel === LogLevel.debug) {
|
|
1623
1775
|
logger.info(messsage);
|
|
1624
1776
|
const logs = [
|
|
1625
1777
|
parameters && `${pc3__default.default.bgWhite(`Parameters`)} ${randomPicoColour(plugin.name)} ${hookName}`,
|
|
@@ -1630,102 +1782,131 @@ async function build(options) {
|
|
|
1630
1782
|
console.log(logs.join("\n"));
|
|
1631
1783
|
}
|
|
1632
1784
|
});
|
|
1785
|
+
return pluginManager;
|
|
1786
|
+
}
|
|
1787
|
+
async function build(options) {
|
|
1788
|
+
const pluginManager = await setup(options);
|
|
1789
|
+
const { fileManager, logger } = pluginManager;
|
|
1633
1790
|
await pluginManager.hookParallel({
|
|
1634
1791
|
hookName: "validate",
|
|
1635
|
-
parameters: [plugins]
|
|
1792
|
+
parameters: [pluginManager.plugins]
|
|
1636
1793
|
});
|
|
1637
1794
|
await pluginManager.hookParallel({
|
|
1638
1795
|
hookName: "buildStart",
|
|
1639
|
-
parameters: [config]
|
|
1796
|
+
parameters: [options.config]
|
|
1640
1797
|
});
|
|
1641
1798
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1642
|
-
|
|
1799
|
+
if (!fileManager.isExecuting && logger.spinner) {
|
|
1800
|
+
logger.spinner.suffixText = "";
|
|
1801
|
+
logger.spinner.succeed(`\u{1F4BE} Writing completed`);
|
|
1802
|
+
}
|
|
1803
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1643
1804
|
}
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1805
|
+
async function safeBuild(options) {
|
|
1806
|
+
const pluginManager = await setup(options);
|
|
1807
|
+
const { fileManager, logger } = pluginManager;
|
|
1808
|
+
try {
|
|
1809
|
+
await pluginManager.hookParallel({
|
|
1810
|
+
hookName: "validate",
|
|
1811
|
+
parameters: [pluginManager.plugins]
|
|
1812
|
+
});
|
|
1813
|
+
await pluginManager.hookParallel({
|
|
1814
|
+
hookName: "buildStart",
|
|
1815
|
+
parameters: [options.config]
|
|
1816
|
+
});
|
|
1817
|
+
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1818
|
+
if (!fileManager.isExecuting && logger.spinner) {
|
|
1819
|
+
logger.spinner.suffixText = "";
|
|
1820
|
+
logger.spinner.succeed(`\u{1F4BE} Writing completed`);
|
|
1821
|
+
}
|
|
1822
|
+
} catch (e) {
|
|
1823
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager, error: e };
|
|
1824
|
+
}
|
|
1825
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1648
1826
|
}
|
|
1649
1827
|
|
|
1650
|
-
// src/
|
|
1828
|
+
// src/Generator.ts
|
|
1829
|
+
var _options3, _context;
|
|
1651
1830
|
var Generator = class {
|
|
1652
|
-
#options = {};
|
|
1653
|
-
#context = {};
|
|
1654
1831
|
constructor(options, context) {
|
|
1832
|
+
__privateAdd(this, _options3, {});
|
|
1833
|
+
__privateAdd(this, _context, {});
|
|
1655
1834
|
if (context) {
|
|
1656
|
-
this
|
|
1835
|
+
__privateSet(this, _context, context);
|
|
1657
1836
|
}
|
|
1658
1837
|
if (options) {
|
|
1659
|
-
this
|
|
1838
|
+
__privateSet(this, _options3, options);
|
|
1660
1839
|
}
|
|
1661
1840
|
return this;
|
|
1662
1841
|
}
|
|
1663
1842
|
get options() {
|
|
1664
|
-
return this
|
|
1843
|
+
return __privateGet(this, _options3);
|
|
1665
1844
|
}
|
|
1666
1845
|
get context() {
|
|
1667
|
-
return this
|
|
1846
|
+
return __privateGet(this, _context);
|
|
1668
1847
|
}
|
|
1669
1848
|
set options(options) {
|
|
1670
|
-
this
|
|
1849
|
+
__privateSet(this, _options3, { ...__privateGet(this, _options3), ...options });
|
|
1671
1850
|
}
|
|
1672
1851
|
};
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
var SchemaGenerator = class extends Generator {
|
|
1676
|
-
};
|
|
1852
|
+
_options3 = new WeakMap();
|
|
1853
|
+
_context = new WeakMap();
|
|
1677
1854
|
|
|
1678
1855
|
// ../../node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
|
|
1679
1856
|
var Node = class {
|
|
1680
|
-
value;
|
|
1681
|
-
next;
|
|
1682
1857
|
constructor(value) {
|
|
1858
|
+
__publicField(this, "value");
|
|
1859
|
+
__publicField(this, "next");
|
|
1683
1860
|
this.value = value;
|
|
1684
1861
|
}
|
|
1685
1862
|
};
|
|
1863
|
+
var _head, _tail, _size;
|
|
1686
1864
|
var Queue2 = class {
|
|
1687
|
-
#head;
|
|
1688
|
-
#tail;
|
|
1689
|
-
#size;
|
|
1690
1865
|
constructor() {
|
|
1866
|
+
__privateAdd(this, _head, void 0);
|
|
1867
|
+
__privateAdd(this, _tail, void 0);
|
|
1868
|
+
__privateAdd(this, _size, void 0);
|
|
1691
1869
|
this.clear();
|
|
1692
1870
|
}
|
|
1693
1871
|
enqueue(value) {
|
|
1694
1872
|
const node = new Node(value);
|
|
1695
|
-
if (this
|
|
1696
|
-
this
|
|
1697
|
-
this
|
|
1873
|
+
if (__privateGet(this, _head)) {
|
|
1874
|
+
__privateGet(this, _tail).next = node;
|
|
1875
|
+
__privateSet(this, _tail, node);
|
|
1698
1876
|
} else {
|
|
1699
|
-
this
|
|
1700
|
-
this
|
|
1877
|
+
__privateSet(this, _head, node);
|
|
1878
|
+
__privateSet(this, _tail, node);
|
|
1701
1879
|
}
|
|
1702
|
-
this
|
|
1880
|
+
__privateWrapper(this, _size)._++;
|
|
1703
1881
|
}
|
|
1704
1882
|
dequeue() {
|
|
1705
|
-
const current = this
|
|
1883
|
+
const current = __privateGet(this, _head);
|
|
1706
1884
|
if (!current) {
|
|
1707
1885
|
return;
|
|
1708
1886
|
}
|
|
1709
|
-
this
|
|
1710
|
-
this
|
|
1887
|
+
__privateSet(this, _head, __privateGet(this, _head).next);
|
|
1888
|
+
__privateWrapper(this, _size)._--;
|
|
1711
1889
|
return current.value;
|
|
1712
1890
|
}
|
|
1713
1891
|
clear() {
|
|
1714
|
-
this
|
|
1715
|
-
this
|
|
1716
|
-
this
|
|
1892
|
+
__privateSet(this, _head, void 0);
|
|
1893
|
+
__privateSet(this, _tail, void 0);
|
|
1894
|
+
__privateSet(this, _size, 0);
|
|
1717
1895
|
}
|
|
1718
1896
|
get size() {
|
|
1719
|
-
return this
|
|
1897
|
+
return __privateGet(this, _size);
|
|
1720
1898
|
}
|
|
1721
1899
|
*[Symbol.iterator]() {
|
|
1722
|
-
let current = this
|
|
1900
|
+
let current = __privateGet(this, _head);
|
|
1723
1901
|
while (current) {
|
|
1724
1902
|
yield current.value;
|
|
1725
1903
|
current = current.next;
|
|
1726
1904
|
}
|
|
1727
1905
|
}
|
|
1728
1906
|
};
|
|
1907
|
+
_head = new WeakMap();
|
|
1908
|
+
_tail = new WeakMap();
|
|
1909
|
+
_size = new WeakMap();
|
|
1729
1910
|
|
|
1730
1911
|
// ../../node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
|
|
1731
1912
|
function pLimit(concurrency) {
|
|
@@ -1740,18 +1921,18 @@ function pLimit(concurrency) {
|
|
|
1740
1921
|
queue.dequeue()();
|
|
1741
1922
|
}
|
|
1742
1923
|
};
|
|
1743
|
-
const run = async (fn,
|
|
1924
|
+
const run = async (fn, resolve2, args) => {
|
|
1744
1925
|
activeCount++;
|
|
1745
1926
|
const result = (async () => fn(...args))();
|
|
1746
|
-
|
|
1927
|
+
resolve2(result);
|
|
1747
1928
|
try {
|
|
1748
1929
|
await result;
|
|
1749
1930
|
} catch {
|
|
1750
1931
|
}
|
|
1751
1932
|
next();
|
|
1752
1933
|
};
|
|
1753
|
-
const enqueue = (fn,
|
|
1754
|
-
queue.enqueue(run.bind(void 0, fn,
|
|
1934
|
+
const enqueue = (fn, resolve2, args) => {
|
|
1935
|
+
queue.enqueue(run.bind(void 0, fn, resolve2, args));
|
|
1755
1936
|
(async () => {
|
|
1756
1937
|
await Promise.resolve();
|
|
1757
1938
|
if (activeCount < concurrency && queue.size > 0) {
|
|
@@ -1759,8 +1940,8 @@ function pLimit(concurrency) {
|
|
|
1759
1940
|
}
|
|
1760
1941
|
})();
|
|
1761
1942
|
};
|
|
1762
|
-
const generator = (fn, ...args) => new Promise((
|
|
1763
|
-
enqueue(fn,
|
|
1943
|
+
const generator = (fn, ...args) => new Promise((resolve2) => {
|
|
1944
|
+
enqueue(fn, resolve2, args);
|
|
1764
1945
|
});
|
|
1765
1946
|
Object.defineProperties(generator, {
|
|
1766
1947
|
activeCount: {
|
|
@@ -1835,7 +2016,7 @@ async function locatePath(paths, {
|
|
|
1835
2016
|
const statFunction = allowSymlinks ? fs3.promises.stat : fs3.promises.lstat;
|
|
1836
2017
|
return pLocate(paths, async (path_) => {
|
|
1837
2018
|
try {
|
|
1838
|
-
const stat = await statFunction(
|
|
2019
|
+
const stat = await statFunction(path4__default.default.resolve(cwd, path_));
|
|
1839
2020
|
return matchType(type, stat);
|
|
1840
2021
|
} catch {
|
|
1841
2022
|
return false;
|
|
@@ -1852,7 +2033,7 @@ function locatePathSync(paths, {
|
|
|
1852
2033
|
const statFunction = allowSymlinks ? fs3__default.default.statSync : fs3__default.default.lstatSync;
|
|
1853
2034
|
for (const path_ of paths) {
|
|
1854
2035
|
try {
|
|
1855
|
-
const stat = statFunction(
|
|
2036
|
+
const stat = statFunction(path4__default.default.resolve(cwd, path_), {
|
|
1856
2037
|
throwIfNoEntry: false
|
|
1857
2038
|
});
|
|
1858
2039
|
if (!stat) {
|
|
@@ -1870,9 +2051,9 @@ function locatePathSync(paths, {
|
|
|
1870
2051
|
var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? url.fileURLToPath(urlOrPath) : urlOrPath;
|
|
1871
2052
|
var findUpStop = Symbol("findUpStop");
|
|
1872
2053
|
async function findUpMultiple(name, options = {}) {
|
|
1873
|
-
let directory =
|
|
1874
|
-
const { root } =
|
|
1875
|
-
const stopAt =
|
|
2054
|
+
let directory = path4__default.default.resolve(toPath2(options.cwd) || "");
|
|
2055
|
+
const { root } = path4__default.default.parse(directory);
|
|
2056
|
+
const stopAt = path4__default.default.resolve(directory, options.stopAt || root);
|
|
1876
2057
|
const limit = options.limit || Number.POSITIVE_INFINITY;
|
|
1877
2058
|
const paths = [name].flat();
|
|
1878
2059
|
const runMatcher = async (locateOptions) => {
|
|
@@ -1892,18 +2073,18 @@ async function findUpMultiple(name, options = {}) {
|
|
|
1892
2073
|
break;
|
|
1893
2074
|
}
|
|
1894
2075
|
if (foundPath) {
|
|
1895
|
-
matches.push(
|
|
2076
|
+
matches.push(path4__default.default.resolve(directory, foundPath));
|
|
1896
2077
|
}
|
|
1897
2078
|
if (directory === stopAt || matches.length >= limit) {
|
|
1898
2079
|
break;
|
|
1899
2080
|
}
|
|
1900
|
-
directory =
|
|
2081
|
+
directory = path4__default.default.dirname(directory);
|
|
1901
2082
|
}
|
|
1902
2083
|
return matches;
|
|
1903
2084
|
}
|
|
1904
2085
|
function findUpMultipleSync(name, options = {}) {
|
|
1905
|
-
let directory =
|
|
1906
|
-
const { root } =
|
|
2086
|
+
let directory = path4__default.default.resolve(toPath2(options.cwd) || "");
|
|
2087
|
+
const { root } = path4__default.default.parse(directory);
|
|
1907
2088
|
const stopAt = options.stopAt || root;
|
|
1908
2089
|
const limit = options.limit || Number.POSITIVE_INFINITY;
|
|
1909
2090
|
const paths = [name].flat();
|
|
@@ -1924,12 +2105,12 @@ function findUpMultipleSync(name, options = {}) {
|
|
|
1924
2105
|
break;
|
|
1925
2106
|
}
|
|
1926
2107
|
if (foundPath) {
|
|
1927
|
-
matches.push(
|
|
2108
|
+
matches.push(path4__default.default.resolve(directory, foundPath));
|
|
1928
2109
|
}
|
|
1929
2110
|
if (directory === stopAt || matches.length >= limit) {
|
|
1930
2111
|
break;
|
|
1931
2112
|
}
|
|
1932
|
-
directory =
|
|
2113
|
+
directory = path4__default.default.dirname(directory);
|
|
1933
2114
|
}
|
|
1934
2115
|
return matches;
|
|
1935
2116
|
}
|
|
@@ -1941,39 +2122,40 @@ function findUpSync(name, options = {}) {
|
|
|
1941
2122
|
const matches = findUpMultipleSync(name, { ...options, limit: 1 });
|
|
1942
2123
|
return matches[0];
|
|
1943
2124
|
}
|
|
1944
|
-
var
|
|
1945
|
-
|
|
1946
|
-
#cwd;
|
|
1947
|
-
#SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
|
|
2125
|
+
var _cache2, _cwd, _SLASHES, _match, match_fn;
|
|
2126
|
+
var _PackageManager = class _PackageManager {
|
|
1948
2127
|
constructor(workspace) {
|
|
2128
|
+
__privateAdd(this, _match);
|
|
2129
|
+
__privateAdd(this, _cwd, void 0);
|
|
2130
|
+
__privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
|
|
1949
2131
|
if (workspace) {
|
|
1950
|
-
this
|
|
2132
|
+
__privateSet(this, _cwd, workspace);
|
|
1951
2133
|
}
|
|
1952
2134
|
return this;
|
|
1953
2135
|
}
|
|
1954
2136
|
set workspace(workspace) {
|
|
1955
|
-
this
|
|
2137
|
+
__privateSet(this, _cwd, workspace);
|
|
1956
2138
|
}
|
|
1957
2139
|
get workspace() {
|
|
1958
|
-
return this
|
|
2140
|
+
return __privateGet(this, _cwd);
|
|
1959
2141
|
}
|
|
1960
2142
|
normalizeDirectory(directory) {
|
|
1961
|
-
if (!this
|
|
2143
|
+
if (!__privateGet(this, _SLASHES).has(directory[directory.length - 1])) {
|
|
1962
2144
|
return `${directory}/`;
|
|
1963
2145
|
}
|
|
1964
2146
|
return directory;
|
|
1965
2147
|
}
|
|
1966
|
-
getLocation(
|
|
1967
|
-
let location =
|
|
1968
|
-
if (this
|
|
1969
|
-
const require2 = mod__default.default.createRequire(this.normalizeDirectory(this
|
|
1970
|
-
location = require2.resolve(
|
|
2148
|
+
getLocation(path5) {
|
|
2149
|
+
let location = path5;
|
|
2150
|
+
if (__privateGet(this, _cwd)) {
|
|
2151
|
+
const require2 = mod__default.default.createRequire(this.normalizeDirectory(__privateGet(this, _cwd)));
|
|
2152
|
+
location = require2.resolve(path5);
|
|
1971
2153
|
}
|
|
1972
2154
|
return location;
|
|
1973
2155
|
}
|
|
1974
|
-
async import(
|
|
2156
|
+
async import(path5) {
|
|
1975
2157
|
try {
|
|
1976
|
-
let location = this.getLocation(
|
|
2158
|
+
let location = this.getLocation(path5);
|
|
1977
2159
|
if (os__default.default.platform() == "win32") {
|
|
1978
2160
|
location = url.pathToFileURL(location).href;
|
|
1979
2161
|
}
|
|
@@ -1986,7 +2168,7 @@ var PackageManager = class _PackageManager {
|
|
|
1986
2168
|
}
|
|
1987
2169
|
async getPackageJSON() {
|
|
1988
2170
|
const pkgPath = await findUp(["package.json"], {
|
|
1989
|
-
cwd: this
|
|
2171
|
+
cwd: __privateGet(this, _cwd)
|
|
1990
2172
|
});
|
|
1991
2173
|
if (!pkgPath) {
|
|
1992
2174
|
return void 0;
|
|
@@ -1995,7 +2177,7 @@ var PackageManager = class _PackageManager {
|
|
|
1995
2177
|
}
|
|
1996
2178
|
getPackageJSONSync() {
|
|
1997
2179
|
const pkgPath = findUpSync(["package.json"], {
|
|
1998
|
-
cwd: this
|
|
2180
|
+
cwd: __privateGet(this, _cwd)
|
|
1999
2181
|
});
|
|
2000
2182
|
if (!pkgPath) {
|
|
2001
2183
|
return void 0;
|
|
@@ -2003,33 +2185,36 @@ var PackageManager = class _PackageManager {
|
|
|
2003
2185
|
return __require(pkgPath);
|
|
2004
2186
|
}
|
|
2005
2187
|
static setVersion(dependency, version) {
|
|
2006
|
-
_PackageManager
|
|
2188
|
+
__privateGet(_PackageManager, _cache2)[dependency] = version;
|
|
2007
2189
|
}
|
|
2008
2190
|
async getVersion(dependency) {
|
|
2009
|
-
if (_PackageManager
|
|
2010
|
-
return _PackageManager
|
|
2191
|
+
if (typeof dependency === "string" && __privateGet(_PackageManager, _cache2)[dependency]) {
|
|
2192
|
+
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
2011
2193
|
}
|
|
2012
2194
|
const packageJSON = await this.getPackageJSON();
|
|
2013
2195
|
if (!packageJSON) {
|
|
2014
2196
|
return void 0;
|
|
2015
2197
|
}
|
|
2016
|
-
return
|
|
2198
|
+
return __privateMethod(this, _match, match_fn).call(this, packageJSON, dependency);
|
|
2017
2199
|
}
|
|
2018
2200
|
getVersionSync(dependency) {
|
|
2019
|
-
if (_PackageManager
|
|
2020
|
-
return _PackageManager
|
|
2201
|
+
if (typeof dependency === "string" && __privateGet(_PackageManager, _cache2)[dependency]) {
|
|
2202
|
+
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
2021
2203
|
}
|
|
2022
2204
|
const packageJSON = this.getPackageJSONSync();
|
|
2023
2205
|
if (!packageJSON) {
|
|
2024
2206
|
return void 0;
|
|
2025
2207
|
}
|
|
2026
|
-
return
|
|
2208
|
+
return __privateMethod(this, _match, match_fn).call(this, packageJSON, dependency);
|
|
2027
2209
|
}
|
|
2028
2210
|
async isValid(dependency, version) {
|
|
2029
2211
|
const packageVersion = await this.getVersion(dependency);
|
|
2030
2212
|
if (!packageVersion) {
|
|
2031
2213
|
return false;
|
|
2032
2214
|
}
|
|
2215
|
+
if (packageVersion === version) {
|
|
2216
|
+
return true;
|
|
2217
|
+
}
|
|
2033
2218
|
const semVer = semver.coerce(packageVersion);
|
|
2034
2219
|
if (!semVer) {
|
|
2035
2220
|
throw new Error(`${packageVersion} is not valid`);
|
|
@@ -2048,68 +2233,48 @@ var PackageManager = class _PackageManager {
|
|
|
2048
2233
|
return semver.satisfies(semVer, version);
|
|
2049
2234
|
}
|
|
2050
2235
|
};
|
|
2236
|
+
_cache2 = new WeakMap();
|
|
2237
|
+
_cwd = new WeakMap();
|
|
2238
|
+
_SLASHES = new WeakMap();
|
|
2239
|
+
_match = new WeakSet();
|
|
2240
|
+
match_fn = function(packageJSON, dependency) {
|
|
2241
|
+
const dependencies = {
|
|
2242
|
+
...packageJSON["dependencies"] || {},
|
|
2243
|
+
...packageJSON["devDependencies"] || {}
|
|
2244
|
+
};
|
|
2245
|
+
if (typeof dependency === "string" && dependencies[dependency]) {
|
|
2246
|
+
return dependencies[dependency];
|
|
2247
|
+
}
|
|
2248
|
+
const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
|
|
2249
|
+
return matchedDependency ? dependencies[matchedDependency] : void 0;
|
|
2250
|
+
};
|
|
2251
|
+
__privateAdd(_PackageManager, _cache2, {});
|
|
2252
|
+
var PackageManager = _PackageManager;
|
|
2253
|
+
|
|
2254
|
+
// src/SchemaGenerator.ts
|
|
2255
|
+
var SchemaGenerator = class extends Generator {
|
|
2256
|
+
};
|
|
2051
2257
|
|
|
2052
2258
|
// src/index.ts
|
|
2053
2259
|
var src_default = build;
|
|
2054
2260
|
|
|
2055
|
-
Object.defineProperty(exports, 'pc', {
|
|
2056
|
-
enumerable: true,
|
|
2057
|
-
get: function () { return pc3__default.default; }
|
|
2058
|
-
});
|
|
2059
2261
|
exports.FileManager = FileManager;
|
|
2060
|
-
exports.FunctionParams = FunctionParams;
|
|
2061
2262
|
exports.Generator = Generator;
|
|
2062
|
-
exports.LogLevel = LogLevel;
|
|
2063
2263
|
exports.PackageManager = PackageManager;
|
|
2064
|
-
exports.ParallelPluginError = ParallelPluginError;
|
|
2065
|
-
exports.PluginError = PluginError;
|
|
2066
2264
|
exports.PluginManager = PluginManager;
|
|
2067
|
-
exports.
|
|
2265
|
+
exports.PromiseManager = PromiseManager;
|
|
2068
2266
|
exports.SchemaGenerator = SchemaGenerator;
|
|
2069
|
-
exports.SummaryError = SummaryError;
|
|
2070
|
-
exports.TreeNode = TreeNode;
|
|
2071
|
-
exports.URLPath = URLPath;
|
|
2072
2267
|
exports.ValidationPluginError = ValidationPluginError;
|
|
2073
2268
|
exports.Warning = Warning;
|
|
2074
2269
|
exports.build = build;
|
|
2075
|
-
exports.clean = clean;
|
|
2076
|
-
exports.combineCodes = combineCodes;
|
|
2077
2270
|
exports.combineExports = combineExports;
|
|
2078
|
-
exports.combineFiles = combineFiles;
|
|
2079
2271
|
exports.combineImports = combineImports;
|
|
2080
|
-
exports.createFileSource = createFileSource;
|
|
2081
|
-
exports.createJSDocBlockText = createJSDocBlockText;
|
|
2082
|
-
exports.createLogger = createLogger;
|
|
2083
2272
|
exports.createPlugin = createPlugin;
|
|
2084
|
-
exports.createPluginCache = createPluginCache;
|
|
2085
2273
|
exports.default = src_default;
|
|
2086
|
-
exports.defaultColours = defaultColours;
|
|
2087
2274
|
exports.defineConfig = defineConfig;
|
|
2088
|
-
exports.
|
|
2089
|
-
exports.extensions = extensions;
|
|
2090
|
-
exports.getDependedPlugins = getDependedPlugins;
|
|
2091
|
-
exports.getIndexes = getIndexes;
|
|
2092
|
-
exports.getPathMode = getPathMode;
|
|
2093
|
-
exports.getRelativePath = getRelativePath;
|
|
2094
|
-
exports.getUniqueName = getUniqueName;
|
|
2095
|
-
exports.hooks = hooks;
|
|
2096
|
-
exports.isExtensionAllowed = isExtensionAllowed;
|
|
2097
|
-
exports.isPromise = isPromise;
|
|
2098
|
-
exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
|
|
2099
|
-
exports.isPromiseRejectedResult = isPromiseRejectedResult;
|
|
2100
|
-
exports.jsStringEscape = jsStringEscape;
|
|
2275
|
+
exports.isInputPath = isInputPath;
|
|
2101
2276
|
exports.name = pluginName;
|
|
2102
|
-
exports.nameSorter = nameSorter;
|
|
2103
2277
|
exports.pluginName = pluginName;
|
|
2104
|
-
exports.
|
|
2105
|
-
exports.randomPicoColour = randomPicoColour;
|
|
2106
|
-
exports.read = read;
|
|
2107
|
-
exports.readSync = readSync;
|
|
2108
|
-
exports.renderTemplate = renderTemplate;
|
|
2109
|
-
exports.throttle = throttle;
|
|
2110
|
-
exports.timeout = timeout;
|
|
2111
|
-
exports.transformReservedWord = transformReservedWord;
|
|
2112
|
-
exports.uniqueIdFactory = uniqueIdFactory;
|
|
2113
|
-
exports.write = write;
|
|
2278
|
+
exports.safeBuild = safeBuild;
|
|
2114
2279
|
//# sourceMappingURL=out.js.map
|
|
2115
2280
|
//# sourceMappingURL=index.cjs.map
|