@kubb/core 3.0.0-alpha.3 → 3.0.0-alpha.31
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 +13 -4
- package/dist/{FileManager-BW--rO8q.d.ts → FileManager-Dnafk2I5.d.ts} +146 -92
- package/dist/{FileManager-Bw-FNS3q.d.cts → FileManager-U5yCmg00.d.cts} +146 -92
- package/dist/chunk-2EU7DMPM.js +96 -0
- package/dist/chunk-2EU7DMPM.js.map +1 -0
- package/dist/{chunk-34BPAXR2.cjs → chunk-2UQARE2O.cjs} +54 -37
- package/dist/chunk-2UQARE2O.cjs.map +1 -0
- package/dist/chunk-4X5FFJPJ.js +8 -13
- package/dist/chunk-4X5FFJPJ.js.map +1 -1
- package/dist/{chunk-3OXCZ5DJ.js → chunk-E6CN2CZC.js} +63 -54
- package/dist/chunk-E6CN2CZC.js.map +1 -0
- package/dist/{chunk-25NKJ3DV.js → chunk-HBQM723K.js} +13 -27
- package/dist/chunk-HBQM723K.js.map +1 -0
- package/dist/{chunk-LM2YQC3T.cjs → chunk-LLKRRIBF.cjs} +81 -51
- package/dist/chunk-LLKRRIBF.cjs.map +1 -0
- package/dist/chunk-MD2LDZ3Z.js +889 -0
- package/dist/chunk-MD2LDZ3Z.js.map +1 -0
- package/dist/chunk-OX2X7B4Z.cjs +101 -0
- package/dist/chunk-OX2X7B4Z.cjs.map +1 -0
- package/dist/{chunk-67C6RBGQ.cjs → chunk-RIW2LFFQ.cjs} +28 -29
- package/dist/chunk-RIW2LFFQ.cjs.map +1 -0
- package/dist/chunk-SX5FHSVT.cjs +1532 -0
- package/dist/chunk-SX5FHSVT.cjs.map +1 -0
- package/dist/chunk-VBGWLAET.cjs +42 -0
- package/dist/chunk-VBGWLAET.cjs.map +1 -0
- package/dist/index.cjs +553 -619
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -22
- package/dist/index.d.ts +7 -22
- package/dist/index.js +444 -525
- package/dist/index.js.map +1 -1
- package/dist/{logger-DChjnJMn.d.cts → logger-DvbHXjIO.d.cts} +29 -19
- package/dist/{logger-DChjnJMn.d.ts → logger-DvbHXjIO.d.ts} +29 -19
- package/dist/logger.cjs +25 -15
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -2
- package/dist/logger.d.ts +1 -2
- package/dist/logger.js +3 -15
- package/dist/logger.js.map +1 -1
- package/dist/mocks.cjs +42 -31
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +7 -9
- package/dist/mocks.d.ts +7 -9
- package/dist/mocks.js +35 -33
- package/dist/mocks.js.map +1 -1
- package/dist/{prompt-6FWP747F.cjs → prompt-2PN2F25D.cjs} +89 -89
- package/dist/prompt-2PN2F25D.cjs.map +1 -0
- package/dist/{prompt-HK3MWREM.js → prompt-WQQUN22Z.js} +9 -15
- package/dist/prompt-WQQUN22Z.js.map +1 -0
- package/dist/transformers.cjs +216 -49
- package/dist/transformers.cjs.map +1 -1
- package/dist/transformers.d.cts +2 -4
- package/dist/transformers.d.ts +2 -4
- package/dist/transformers.js +149 -35
- package/dist/transformers.js.map +1 -1
- package/dist/utils.cjs +65 -26
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +29 -3
- package/dist/utils.d.ts +29 -3
- package/dist/utils.js +3 -26
- package/dist/utils.js.map +1 -1
- package/package.json +11 -14
- package/src/BarrelManager.ts +95 -109
- package/src/{Generator.ts → BaseGenerator.ts} +1 -1
- package/src/FileManager.ts +199 -304
- package/src/PackageManager.ts +1 -1
- package/src/PluginManager.ts +152 -93
- package/src/PromiseManager.ts +1 -1
- package/src/__snapshots__/barrel.json +73 -0
- package/src/__snapshots__/grouped.json +120 -0
- package/src/__snapshots__/ordered.json +68 -0
- package/src/build.ts +86 -131
- package/src/config.ts +2 -4
- package/src/errors.ts +0 -11
- package/src/index.ts +2 -3
- package/src/logger.ts +76 -34
- package/src/plugin.ts +2 -5
- package/src/transformers/escape.ts +0 -10
- package/src/transformers/index.ts +2 -3
- package/src/transformers/stringify.ts +1 -1
- package/src/transformers/trim.ts +0 -4
- package/src/types.ts +77 -22
- package/src/utils/TreeNode.ts +132 -50
- package/src/utils/executeStrategies.ts +3 -3
- package/src/utils/index.ts +2 -1
- package/src/utils/parser.ts +156 -0
- package/dist/chunk-25NKJ3DV.js.map +0 -1
- package/dist/chunk-34BPAXR2.cjs.map +0 -1
- package/dist/chunk-3OXCZ5DJ.js.map +0 -1
- package/dist/chunk-5JZNFPUP.js +0 -309
- package/dist/chunk-5JZNFPUP.js.map +0 -1
- package/dist/chunk-67C6RBGQ.cjs.map +0 -1
- package/dist/chunk-ADC5UNZ5.cjs +0 -1227
- package/dist/chunk-ADC5UNZ5.cjs.map +0 -1
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-HMLY7DHA.js.map +0 -1
- package/dist/chunk-JKZG2IJR.js +0 -283
- package/dist/chunk-JKZG2IJR.js.map +0 -1
- package/dist/chunk-LM2YQC3T.cjs.map +0 -1
- package/dist/chunk-PZT4CTBV.cjs +0 -299
- package/dist/chunk-PZT4CTBV.cjs.map +0 -1
- package/dist/chunk-SA2GZKXS.js +0 -596
- package/dist/chunk-SA2GZKXS.js.map +0 -1
- package/dist/chunk-XCPFG6DO.cjs +0 -66
- package/dist/chunk-XCPFG6DO.cjs.map +0 -1
- package/dist/chunk-YTSNYMHW.cjs +0 -320
- package/dist/chunk-YTSNYMHW.cjs.map +0 -1
- package/dist/prompt-6FWP747F.cjs.map +0 -1
- package/dist/prompt-HK3MWREM.js.map +0 -1
- package/schema.json +0 -86
- package/src/utils/cache.ts +0 -35
- package/src/utils/getParser.ts +0 -17
|
@@ -0,0 +1,1532 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkRIW2LFFQ_cjs = require('./chunk-RIW2LFFQ.cjs');
|
|
4
|
+
var chunkVBGWLAET_cjs = require('./chunk-VBGWLAET.cjs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var fs = require('@kubb/fs');
|
|
7
|
+
var hash = require('object-hash');
|
|
8
|
+
var remeda = require('remeda');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
13
|
+
var hash__default = /*#__PURE__*/_interopDefault(hash);
|
|
14
|
+
|
|
15
|
+
// ../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js
|
|
16
|
+
var require_eventemitter3 = chunkVBGWLAET_cjs.__commonJS({
|
|
17
|
+
"../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js"(exports, module) {
|
|
18
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
19
|
+
var has = Object.prototype.hasOwnProperty;
|
|
20
|
+
var prefix = "~";
|
|
21
|
+
function Events() {
|
|
22
|
+
}
|
|
23
|
+
if (Object.create) {
|
|
24
|
+
Events.prototype = /* @__PURE__ */ Object.create(null);
|
|
25
|
+
if (!new Events().__proto__) prefix = false;
|
|
26
|
+
}
|
|
27
|
+
function EE(fn, context, once) {
|
|
28
|
+
this.fn = fn;
|
|
29
|
+
this.context = context;
|
|
30
|
+
this.once = once || false;
|
|
31
|
+
}
|
|
32
|
+
function addListener(emitter, event, fn, context, once) {
|
|
33
|
+
if (typeof fn !== "function") {
|
|
34
|
+
throw new TypeError("The listener must be a function");
|
|
35
|
+
}
|
|
36
|
+
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
|
|
37
|
+
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
38
|
+
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
39
|
+
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
40
|
+
return emitter;
|
|
41
|
+
}
|
|
42
|
+
function clearEvent(emitter, evt) {
|
|
43
|
+
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
44
|
+
else delete emitter._events[evt];
|
|
45
|
+
}
|
|
46
|
+
function EventEmitter2() {
|
|
47
|
+
this._events = new Events();
|
|
48
|
+
this._eventsCount = 0;
|
|
49
|
+
}
|
|
50
|
+
EventEmitter2.prototype.eventNames = function eventNames() {
|
|
51
|
+
var names = [], events, name;
|
|
52
|
+
if (this._eventsCount === 0) return names;
|
|
53
|
+
for (name in events = this._events) {
|
|
54
|
+
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
55
|
+
}
|
|
56
|
+
if (Object.getOwnPropertySymbols) {
|
|
57
|
+
return names.concat(Object.getOwnPropertySymbols(events));
|
|
58
|
+
}
|
|
59
|
+
return names;
|
|
60
|
+
};
|
|
61
|
+
EventEmitter2.prototype.listeners = function listeners(event) {
|
|
62
|
+
var evt = prefix ? prefix + event : event, handlers = this._events[evt];
|
|
63
|
+
if (!handlers) return [];
|
|
64
|
+
if (handlers.fn) return [handlers.fn];
|
|
65
|
+
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
66
|
+
ee[i] = handlers[i].fn;
|
|
67
|
+
}
|
|
68
|
+
return ee;
|
|
69
|
+
};
|
|
70
|
+
EventEmitter2.prototype.listenerCount = function listenerCount(event) {
|
|
71
|
+
var evt = prefix ? prefix + event : event, listeners = this._events[evt];
|
|
72
|
+
if (!listeners) return 0;
|
|
73
|
+
if (listeners.fn) return 1;
|
|
74
|
+
return listeners.length;
|
|
75
|
+
};
|
|
76
|
+
EventEmitter2.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
77
|
+
var evt = prefix ? prefix + event : event;
|
|
78
|
+
if (!this._events[evt]) return false;
|
|
79
|
+
var listeners = this._events[evt], len = arguments.length, args, i;
|
|
80
|
+
if (listeners.fn) {
|
|
81
|
+
if (listeners.once) this.removeListener(event, listeners.fn, void 0, true);
|
|
82
|
+
switch (len) {
|
|
83
|
+
case 1:
|
|
84
|
+
return listeners.fn.call(listeners.context), true;
|
|
85
|
+
case 2:
|
|
86
|
+
return listeners.fn.call(listeners.context, a1), true;
|
|
87
|
+
case 3:
|
|
88
|
+
return listeners.fn.call(listeners.context, a1, a2), true;
|
|
89
|
+
case 4:
|
|
90
|
+
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
91
|
+
case 5:
|
|
92
|
+
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
93
|
+
case 6:
|
|
94
|
+
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
95
|
+
}
|
|
96
|
+
for (i = 1, args = new Array(len - 1); i < len; i++) {
|
|
97
|
+
args[i - 1] = arguments[i];
|
|
98
|
+
}
|
|
99
|
+
listeners.fn.apply(listeners.context, args);
|
|
100
|
+
} else {
|
|
101
|
+
var length = listeners.length, j;
|
|
102
|
+
for (i = 0; i < length; i++) {
|
|
103
|
+
if (listeners[i].once) this.removeListener(event, listeners[i].fn, void 0, true);
|
|
104
|
+
switch (len) {
|
|
105
|
+
case 1:
|
|
106
|
+
listeners[i].fn.call(listeners[i].context);
|
|
107
|
+
break;
|
|
108
|
+
case 2:
|
|
109
|
+
listeners[i].fn.call(listeners[i].context, a1);
|
|
110
|
+
break;
|
|
111
|
+
case 3:
|
|
112
|
+
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
113
|
+
break;
|
|
114
|
+
case 4:
|
|
115
|
+
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
116
|
+
break;
|
|
117
|
+
default:
|
|
118
|
+
if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
|
|
119
|
+
args[j - 1] = arguments[j];
|
|
120
|
+
}
|
|
121
|
+
listeners[i].fn.apply(listeners[i].context, args);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
};
|
|
127
|
+
EventEmitter2.prototype.on = function on(event, fn, context) {
|
|
128
|
+
return addListener(this, event, fn, context, false);
|
|
129
|
+
};
|
|
130
|
+
EventEmitter2.prototype.once = function once(event, fn, context) {
|
|
131
|
+
return addListener(this, event, fn, context, true);
|
|
132
|
+
};
|
|
133
|
+
EventEmitter2.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
134
|
+
var evt = prefix ? prefix + event : event;
|
|
135
|
+
if (!this._events[evt]) return this;
|
|
136
|
+
if (!fn) {
|
|
137
|
+
clearEvent(this, evt);
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
var listeners = this._events[evt];
|
|
141
|
+
if (listeners.fn) {
|
|
142
|
+
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
|
|
143
|
+
clearEvent(this, evt);
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
147
|
+
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
|
|
148
|
+
events.push(listeners[i]);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
152
|
+
else clearEvent(this, evt);
|
|
153
|
+
}
|
|
154
|
+
return this;
|
|
155
|
+
};
|
|
156
|
+
EventEmitter2.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
157
|
+
var evt;
|
|
158
|
+
if (event) {
|
|
159
|
+
evt = prefix ? prefix + event : event;
|
|
160
|
+
if (this._events[evt]) clearEvent(this, evt);
|
|
161
|
+
} else {
|
|
162
|
+
this._events = new Events();
|
|
163
|
+
this._eventsCount = 0;
|
|
164
|
+
}
|
|
165
|
+
return this;
|
|
166
|
+
};
|
|
167
|
+
EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener;
|
|
168
|
+
EventEmitter2.prototype.addListener = EventEmitter2.prototype.on;
|
|
169
|
+
EventEmitter2.prefixed = prefix;
|
|
170
|
+
EventEmitter2.EventEmitter = EventEmitter2;
|
|
171
|
+
if ("undefined" !== typeof module) {
|
|
172
|
+
module.exports = EventEmitter2;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// src/utils/index.ts
|
|
178
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
179
|
+
|
|
180
|
+
// src/utils/FunctionParams.ts
|
|
181
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
182
|
+
var FunctionParams = class _FunctionParams {
|
|
183
|
+
#items = [];
|
|
184
|
+
constructor() {
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
get items() {
|
|
188
|
+
return this.#items.flat();
|
|
189
|
+
}
|
|
190
|
+
add(item) {
|
|
191
|
+
if (!item) {
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
if (Array.isArray(item)) {
|
|
195
|
+
item.filter(Boolean).forEach((it) => this.#items.push(it));
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
this.#items.push(item);
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
static #orderItems(items) {
|
|
202
|
+
return chunkRIW2LFFQ_cjs.orderBy(
|
|
203
|
+
items.filter(Boolean),
|
|
204
|
+
[
|
|
205
|
+
(v) => {
|
|
206
|
+
if (Array.isArray(v)) {
|
|
207
|
+
return void 0;
|
|
208
|
+
}
|
|
209
|
+
return !v.default;
|
|
210
|
+
},
|
|
211
|
+
(v) => {
|
|
212
|
+
if (Array.isArray(v)) {
|
|
213
|
+
return void 0;
|
|
214
|
+
}
|
|
215
|
+
return v.required ?? true;
|
|
216
|
+
}
|
|
217
|
+
],
|
|
218
|
+
["desc", "desc"]
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
static #addParams(acc, item) {
|
|
222
|
+
const { enabled = true, name, type, required = true, ...rest } = item;
|
|
223
|
+
if (!enabled) {
|
|
224
|
+
return acc;
|
|
225
|
+
}
|
|
226
|
+
if (!name) {
|
|
227
|
+
acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
228
|
+
return acc;
|
|
229
|
+
}
|
|
230
|
+
const parameterName = name.startsWith("{") ? name : chunkRIW2LFFQ_cjs.camelCase(name);
|
|
231
|
+
if (type) {
|
|
232
|
+
if (required) {
|
|
233
|
+
acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
234
|
+
} else {
|
|
235
|
+
acc.push(`${parameterName}?: ${type}`);
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
acc.push(`${parameterName}`);
|
|
239
|
+
}
|
|
240
|
+
return acc;
|
|
241
|
+
}
|
|
242
|
+
static toObject(items) {
|
|
243
|
+
let type = [];
|
|
244
|
+
let name = [];
|
|
245
|
+
const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true;
|
|
246
|
+
const required = items.every((item) => item.required) ?? true;
|
|
247
|
+
items.forEach((item) => {
|
|
248
|
+
name = _FunctionParams.#addParams(name, { ...item, type: void 0 });
|
|
249
|
+
if (items.some((item2) => item2.type)) {
|
|
250
|
+
type = _FunctionParams.#addParams(type, item);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
return {
|
|
254
|
+
name: `{ ${name.join(", ")} }`,
|
|
255
|
+
type: type.length ? `{ ${type.join("; ")} }` : void 0,
|
|
256
|
+
enabled,
|
|
257
|
+
required
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
static toString(items) {
|
|
261
|
+
const sortedData = _FunctionParams.#orderItems(items);
|
|
262
|
+
return sortedData.reduce((acc, item) => {
|
|
263
|
+
if (Array.isArray(item)) {
|
|
264
|
+
if (item.length <= 0) {
|
|
265
|
+
return acc;
|
|
266
|
+
}
|
|
267
|
+
const subItems = _FunctionParams.#orderItems(item);
|
|
268
|
+
const objectItem = _FunctionParams.toObject(subItems);
|
|
269
|
+
return _FunctionParams.#addParams(acc, objectItem);
|
|
270
|
+
}
|
|
271
|
+
return _FunctionParams.#addParams(acc, item);
|
|
272
|
+
}, []).join(", ");
|
|
273
|
+
}
|
|
274
|
+
toObject() {
|
|
275
|
+
const items = _FunctionParams.#orderItems(this.#items).flat();
|
|
276
|
+
return _FunctionParams.toObject(items);
|
|
277
|
+
}
|
|
278
|
+
toString() {
|
|
279
|
+
const items = _FunctionParams.#orderItems(this.#items);
|
|
280
|
+
return _FunctionParams.toString(items);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// src/utils/promise.ts
|
|
285
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
286
|
+
function isPromise(result) {
|
|
287
|
+
return !!result && typeof result?.then === "function";
|
|
288
|
+
}
|
|
289
|
+
function isPromiseFulfilledResult(result) {
|
|
290
|
+
return result.status === "fulfilled";
|
|
291
|
+
}
|
|
292
|
+
function isPromiseRejectedResult(result) {
|
|
293
|
+
return result.status === "rejected";
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/utils/renderTemplate.ts
|
|
297
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
298
|
+
function renderTemplate(template, data = void 0) {
|
|
299
|
+
if (!data || !Object.keys(data).length) {
|
|
300
|
+
return template.replace(/{{(.*?)}}/g, "");
|
|
301
|
+
}
|
|
302
|
+
const matches = template.match(/{{(.*?)}}/g);
|
|
303
|
+
return matches?.reduce((prev, curr) => {
|
|
304
|
+
const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
|
|
305
|
+
if (index === void 0) {
|
|
306
|
+
return prev;
|
|
307
|
+
}
|
|
308
|
+
const value = data[index];
|
|
309
|
+
if (value === void 0) {
|
|
310
|
+
return prev;
|
|
311
|
+
}
|
|
312
|
+
return prev.replace(curr, () => {
|
|
313
|
+
if (typeof value === "boolean") {
|
|
314
|
+
return `${value.toString()}` || "false";
|
|
315
|
+
}
|
|
316
|
+
return value || "";
|
|
317
|
+
}).trim();
|
|
318
|
+
}, template) || "";
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// src/utils/timeout.ts
|
|
322
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
323
|
+
async function timeout(ms) {
|
|
324
|
+
return new Promise((resolve) => {
|
|
325
|
+
setTimeout(() => {
|
|
326
|
+
resolve(true);
|
|
327
|
+
}, ms);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// src/utils/uniqueName.ts
|
|
332
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
333
|
+
function getUniqueName(originalName, data) {
|
|
334
|
+
let used = data[originalName] || 0;
|
|
335
|
+
if (used) {
|
|
336
|
+
data[originalName] = ++used;
|
|
337
|
+
originalName += used;
|
|
338
|
+
}
|
|
339
|
+
data[originalName] = 1;
|
|
340
|
+
return originalName;
|
|
341
|
+
}
|
|
342
|
+
function setUniqueName(originalName, data) {
|
|
343
|
+
let used = data[originalName] || 0;
|
|
344
|
+
if (used) {
|
|
345
|
+
data[originalName] = ++used;
|
|
346
|
+
return originalName;
|
|
347
|
+
}
|
|
348
|
+
data[originalName] = 1;
|
|
349
|
+
return originalName;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// src/utils/URLPath.ts
|
|
353
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
354
|
+
var URLPath = class {
|
|
355
|
+
path;
|
|
356
|
+
constructor(path2) {
|
|
357
|
+
this.path = path2;
|
|
358
|
+
return this;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
362
|
+
* @example /pet/{petId} => /pet/:petId
|
|
363
|
+
*/
|
|
364
|
+
get URL() {
|
|
365
|
+
return this.toURLPath();
|
|
366
|
+
}
|
|
367
|
+
get isURL() {
|
|
368
|
+
try {
|
|
369
|
+
const url = new URL(this.path);
|
|
370
|
+
if (url?.href) {
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
} catch (error) {
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
380
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
381
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
382
|
+
* @example /account/userID => `/account/${userId}`
|
|
383
|
+
*/
|
|
384
|
+
get template() {
|
|
385
|
+
return this.toTemplateString();
|
|
386
|
+
}
|
|
387
|
+
get object() {
|
|
388
|
+
return this.toObject();
|
|
389
|
+
}
|
|
390
|
+
get params() {
|
|
391
|
+
return this.getParams();
|
|
392
|
+
}
|
|
393
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
394
|
+
const object = {
|
|
395
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
|
|
396
|
+
params: this.getParams()
|
|
397
|
+
};
|
|
398
|
+
if (stringify) {
|
|
399
|
+
if (type === "template") {
|
|
400
|
+
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
401
|
+
}
|
|
402
|
+
if (object.params) {
|
|
403
|
+
return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
404
|
+
}
|
|
405
|
+
return `{ url: '${object.url}' }`;
|
|
406
|
+
}
|
|
407
|
+
return object;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
411
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
412
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
413
|
+
* @example /account/userID => `/account/${userId}`
|
|
414
|
+
*/
|
|
415
|
+
toTemplateString(replacer) {
|
|
416
|
+
const regex = /{(\w|-)*}/g;
|
|
417
|
+
const found = this.path.match(regex);
|
|
418
|
+
let newPath = this.path.replaceAll("{", "${");
|
|
419
|
+
if (found) {
|
|
420
|
+
newPath = found.reduce((prev, curr) => {
|
|
421
|
+
const pathParam = replacer ? replacer(chunkRIW2LFFQ_cjs.camelCase(curr)) : chunkRIW2LFFQ_cjs.camelCase(curr);
|
|
422
|
+
const replacement = `\${${pathParam}}`;
|
|
423
|
+
return prev.replace(curr, replacement);
|
|
424
|
+
}, this.path);
|
|
425
|
+
}
|
|
426
|
+
return `\`${newPath}\``;
|
|
427
|
+
}
|
|
428
|
+
getParams(replacer) {
|
|
429
|
+
const regex = /{(\w|-)*}/g;
|
|
430
|
+
const found = this.path.match(regex);
|
|
431
|
+
if (!found) {
|
|
432
|
+
return void 0;
|
|
433
|
+
}
|
|
434
|
+
const params = {};
|
|
435
|
+
found.forEach((item) => {
|
|
436
|
+
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
437
|
+
const pathParam = replacer ? replacer(chunkRIW2LFFQ_cjs.camelCase(item)) : chunkRIW2LFFQ_cjs.camelCase(item);
|
|
438
|
+
params[pathParam] = pathParam;
|
|
439
|
+
}, this.path);
|
|
440
|
+
return params;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
444
|
+
* @example /pet/{petId} => /pet/:petId
|
|
445
|
+
*/
|
|
446
|
+
toURLPath() {
|
|
447
|
+
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
// src/utils/parser.ts
|
|
452
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
453
|
+
|
|
454
|
+
// src/FileManager.ts
|
|
455
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
456
|
+
|
|
457
|
+
// src/BarrelManager.ts
|
|
458
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
459
|
+
|
|
460
|
+
// src/utils/TreeNode.ts
|
|
461
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
462
|
+
var TreeNode = class _TreeNode {
|
|
463
|
+
data;
|
|
464
|
+
parent;
|
|
465
|
+
children = [];
|
|
466
|
+
#cachedLeaves = void 0;
|
|
467
|
+
constructor(data, parent) {
|
|
468
|
+
this.data = data;
|
|
469
|
+
this.parent = parent;
|
|
470
|
+
return this;
|
|
471
|
+
}
|
|
472
|
+
addChild(data) {
|
|
473
|
+
const child = new _TreeNode(data, this);
|
|
474
|
+
if (!this.children) {
|
|
475
|
+
this.children = [];
|
|
476
|
+
}
|
|
477
|
+
this.children.push(child);
|
|
478
|
+
return child;
|
|
479
|
+
}
|
|
480
|
+
get root() {
|
|
481
|
+
if (!this.parent) {
|
|
482
|
+
return this;
|
|
483
|
+
}
|
|
484
|
+
return this.parent.root;
|
|
485
|
+
}
|
|
486
|
+
get leaves() {
|
|
487
|
+
if (!this.children || this.children.length === 0) {
|
|
488
|
+
return [this];
|
|
489
|
+
}
|
|
490
|
+
if (this.#cachedLeaves) {
|
|
491
|
+
return this.#cachedLeaves;
|
|
492
|
+
}
|
|
493
|
+
const leaves = [];
|
|
494
|
+
if (this.children) {
|
|
495
|
+
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
496
|
+
leaves.push.apply(leaves, this.children[i].leaves);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
this.#cachedLeaves = leaves;
|
|
500
|
+
return leaves;
|
|
501
|
+
}
|
|
502
|
+
forEach(callback) {
|
|
503
|
+
if (typeof callback !== "function") {
|
|
504
|
+
throw new TypeError("forEach() callback must be a function");
|
|
505
|
+
}
|
|
506
|
+
callback(this);
|
|
507
|
+
if (this.children) {
|
|
508
|
+
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
509
|
+
this.children[i]?.forEach(callback);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return this;
|
|
513
|
+
}
|
|
514
|
+
findDeep(predicate) {
|
|
515
|
+
if (typeof predicate !== "function") {
|
|
516
|
+
throw new TypeError("find() predicate must be a function");
|
|
517
|
+
}
|
|
518
|
+
return this.leaves.find(predicate);
|
|
519
|
+
}
|
|
520
|
+
forEachDeep(callback) {
|
|
521
|
+
if (typeof callback !== "function") {
|
|
522
|
+
throw new TypeError("forEach() callback must be a function");
|
|
523
|
+
}
|
|
524
|
+
this.leaves.forEach(callback);
|
|
525
|
+
}
|
|
526
|
+
filterDeep(callback) {
|
|
527
|
+
if (typeof callback !== "function") {
|
|
528
|
+
throw new TypeError("filter() callback must be a function");
|
|
529
|
+
}
|
|
530
|
+
return this.leaves.filter(callback);
|
|
531
|
+
}
|
|
532
|
+
mapDeep(callback) {
|
|
533
|
+
if (typeof callback !== "function") {
|
|
534
|
+
throw new TypeError("map() callback must be a function");
|
|
535
|
+
}
|
|
536
|
+
return this.leaves.map(callback);
|
|
537
|
+
}
|
|
538
|
+
static build(files, root) {
|
|
539
|
+
try {
|
|
540
|
+
const filteredTree = buildDirectoryTree(files, root);
|
|
541
|
+
if (!filteredTree) {
|
|
542
|
+
return null;
|
|
543
|
+
}
|
|
544
|
+
const treeNode = new _TreeNode({
|
|
545
|
+
name: filteredTree.name,
|
|
546
|
+
path: filteredTree.path,
|
|
547
|
+
file: filteredTree.file,
|
|
548
|
+
type: FileManager.getMode(filteredTree.path)
|
|
549
|
+
});
|
|
550
|
+
const recurse = (node, item) => {
|
|
551
|
+
const subNode = node.addChild({
|
|
552
|
+
name: item.name,
|
|
553
|
+
path: item.path,
|
|
554
|
+
file: item.file,
|
|
555
|
+
type: FileManager.getMode(item.path)
|
|
556
|
+
});
|
|
557
|
+
if (item.children?.length) {
|
|
558
|
+
item.children?.forEach((child) => {
|
|
559
|
+
recurse(subNode, child);
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
filteredTree.children?.forEach((child) => recurse(treeNode, child));
|
|
564
|
+
return treeNode;
|
|
565
|
+
} catch (e) {
|
|
566
|
+
throw new Error("Something went wrong with creating barrel files with the TreeNode class", { cause: e });
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
function buildDirectoryTree(files, rootFolder = "") {
|
|
571
|
+
const rootPrefix = rootFolder.endsWith("/") ? rootFolder : `${rootFolder}/`;
|
|
572
|
+
const filteredFiles = files.filter((file) => rootFolder ? file.path.startsWith(rootPrefix) && !file.path.endsWith(".json") : !file.path.endsWith(".json"));
|
|
573
|
+
if (filteredFiles.length === 0) {
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
const root = {
|
|
577
|
+
name: rootFolder || "",
|
|
578
|
+
path: rootFolder || "",
|
|
579
|
+
children: []
|
|
580
|
+
};
|
|
581
|
+
filteredFiles.forEach((file) => {
|
|
582
|
+
const path2 = file.path.slice(rootFolder.length);
|
|
583
|
+
const parts = path2.split("/");
|
|
584
|
+
let currentLevel = root.children;
|
|
585
|
+
let currentPath = rootFolder;
|
|
586
|
+
parts.forEach((part, index) => {
|
|
587
|
+
if (index !== 0) {
|
|
588
|
+
currentPath += `/${part}`;
|
|
589
|
+
} else {
|
|
590
|
+
currentPath += `${part}`;
|
|
591
|
+
}
|
|
592
|
+
let existingNode = currentLevel.find((node) => node.name === part);
|
|
593
|
+
if (!existingNode) {
|
|
594
|
+
if (index === parts.length - 1) {
|
|
595
|
+
existingNode = {
|
|
596
|
+
name: part,
|
|
597
|
+
file,
|
|
598
|
+
path: currentPath
|
|
599
|
+
};
|
|
600
|
+
} else {
|
|
601
|
+
existingNode = {
|
|
602
|
+
name: part,
|
|
603
|
+
path: currentPath,
|
|
604
|
+
children: []
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
currentLevel.push(existingNode);
|
|
608
|
+
}
|
|
609
|
+
if (!existingNode.file) {
|
|
610
|
+
currentLevel = existingNode.children;
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
});
|
|
614
|
+
return root;
|
|
615
|
+
}
|
|
616
|
+
var BarrelManager = class {
|
|
617
|
+
#options;
|
|
618
|
+
constructor(options = {}) {
|
|
619
|
+
this.#options = options;
|
|
620
|
+
return this;
|
|
621
|
+
}
|
|
622
|
+
getFiles({ files: generatedFiles, root, meta }) {
|
|
623
|
+
const { logger } = this.#options;
|
|
624
|
+
const cachedFiles = /* @__PURE__ */ new Map();
|
|
625
|
+
logger?.emit("debug", { date: /* @__PURE__ */ new Date(), logs: [`Start barrel generation for pluginKey ${meta?.pluginKey?.join(".")} and root '${root}'`] });
|
|
626
|
+
TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
|
|
627
|
+
if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) {
|
|
628
|
+
return void 0;
|
|
629
|
+
}
|
|
630
|
+
const barrelFile = {
|
|
631
|
+
path: path.join(treeNode.parent?.data.path, "index.ts"),
|
|
632
|
+
baseName: "index.ts",
|
|
633
|
+
exports: [],
|
|
634
|
+
sources: []
|
|
635
|
+
};
|
|
636
|
+
const previousBarrelFile = cachedFiles.get(barrelFile.path);
|
|
637
|
+
const leaves = treeNode.leaves;
|
|
638
|
+
leaves.forEach((item) => {
|
|
639
|
+
if (!item.data.name) {
|
|
640
|
+
return void 0;
|
|
641
|
+
}
|
|
642
|
+
const sources = item.data.file?.sources || [];
|
|
643
|
+
if (!sources.some((source) => source.isIndexable)) {
|
|
644
|
+
logger?.emit(
|
|
645
|
+
"warning",
|
|
646
|
+
`No isIndexable source found(source should have a name and isIndexable):
|
|
647
|
+
File: ${JSON.stringify(item.data.file, void 0, 2)}`
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
sources.forEach((source) => {
|
|
651
|
+
if (!item.data.file?.path || !source.isIndexable || !source.name) {
|
|
652
|
+
return void 0;
|
|
653
|
+
}
|
|
654
|
+
const alreadyContainInPreviousBarrelFile = previousBarrelFile?.sources.some((item2) => item2.name === source.name);
|
|
655
|
+
if (alreadyContainInPreviousBarrelFile) {
|
|
656
|
+
return void 0;
|
|
657
|
+
}
|
|
658
|
+
if (!barrelFile.exports) {
|
|
659
|
+
barrelFile.exports = [];
|
|
660
|
+
}
|
|
661
|
+
const isSubExport = !!treeNode.parent?.data.path?.split?.("/")?.length;
|
|
662
|
+
if (isSubExport) {
|
|
663
|
+
barrelFile.exports.push({
|
|
664
|
+
name: [source.name],
|
|
665
|
+
path: fs.getRelativePath(treeNode.parent?.data.path, item.data.path),
|
|
666
|
+
isTypeOnly: source.isTypeOnly
|
|
667
|
+
});
|
|
668
|
+
} else {
|
|
669
|
+
barrelFile.exports.push({
|
|
670
|
+
name: [source.name],
|
|
671
|
+
path: `./${item.data.file.baseName}`,
|
|
672
|
+
isTypeOnly: source.isTypeOnly
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
barrelFile.sources.push({
|
|
676
|
+
name: source.name,
|
|
677
|
+
isTypeOnly: source.isTypeOnly,
|
|
678
|
+
//TODO use parser to generate import
|
|
679
|
+
value: "",
|
|
680
|
+
isExportable: false,
|
|
681
|
+
isIndexable: false
|
|
682
|
+
});
|
|
683
|
+
});
|
|
684
|
+
});
|
|
685
|
+
logger?.emit("debug", {
|
|
686
|
+
date: /* @__PURE__ */ new Date(),
|
|
687
|
+
logs: [
|
|
688
|
+
`Generating barrelFile '${fs.getRelativePath(root, barrelFile.path)}' for '${fs.getRelativePath(root, treeNode.data?.path)}' with ${barrelFile.sources.length} indexable exports: '${barrelFile.sources?.map((source) => source.name).join(", ")}'`
|
|
689
|
+
]
|
|
690
|
+
});
|
|
691
|
+
logger?.emit("debug", {
|
|
692
|
+
date: /* @__PURE__ */ new Date(),
|
|
693
|
+
logs: [
|
|
694
|
+
`Generated barrelFile '${fs.getRelativePath(root, barrelFile.path)}' for '${fs.getRelativePath(root, treeNode.data?.path)}' with exports: '${cachedFiles.get(barrelFile.path)?.sources?.map((source) => source.name).join(", ")}'`
|
|
695
|
+
]
|
|
696
|
+
});
|
|
697
|
+
if (previousBarrelFile) {
|
|
698
|
+
previousBarrelFile.sources.push(...barrelFile.sources);
|
|
699
|
+
previousBarrelFile.exports?.push(...barrelFile.exports || []);
|
|
700
|
+
} else {
|
|
701
|
+
cachedFiles.set(barrelFile.path, barrelFile);
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
return [...cachedFiles.values()];
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
// ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/index.js
|
|
709
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
710
|
+
|
|
711
|
+
// ../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.mjs
|
|
712
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
713
|
+
var import_index = chunkVBGWLAET_cjs.__toESM(require_eventemitter3(), 1);
|
|
714
|
+
|
|
715
|
+
// ../../node_modules/.pnpm/p-timeout@6.1.2/node_modules/p-timeout/index.js
|
|
716
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
717
|
+
var TimeoutError = class extends Error {
|
|
718
|
+
constructor(message) {
|
|
719
|
+
super(message);
|
|
720
|
+
this.name = "TimeoutError";
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
var AbortError = class extends Error {
|
|
724
|
+
constructor(message) {
|
|
725
|
+
super();
|
|
726
|
+
this.name = "AbortError";
|
|
727
|
+
this.message = message;
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
var getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new AbortError(errorMessage) : new DOMException(errorMessage);
|
|
731
|
+
var getAbortedReason = (signal) => {
|
|
732
|
+
const reason = signal.reason === void 0 ? getDOMException("This operation was aborted.") : signal.reason;
|
|
733
|
+
return reason instanceof Error ? reason : getDOMException(reason);
|
|
734
|
+
};
|
|
735
|
+
function pTimeout(promise, options) {
|
|
736
|
+
const {
|
|
737
|
+
milliseconds,
|
|
738
|
+
fallback,
|
|
739
|
+
message,
|
|
740
|
+
customTimers = { setTimeout, clearTimeout }
|
|
741
|
+
} = options;
|
|
742
|
+
let timer;
|
|
743
|
+
const wrappedPromise = new Promise((resolve, reject) => {
|
|
744
|
+
if (typeof milliseconds !== "number" || Math.sign(milliseconds) !== 1) {
|
|
745
|
+
throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
|
|
746
|
+
}
|
|
747
|
+
if (options.signal) {
|
|
748
|
+
const { signal } = options;
|
|
749
|
+
if (signal.aborted) {
|
|
750
|
+
reject(getAbortedReason(signal));
|
|
751
|
+
}
|
|
752
|
+
signal.addEventListener("abort", () => {
|
|
753
|
+
reject(getAbortedReason(signal));
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
757
|
+
promise.then(resolve, reject);
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
const timeoutError = new TimeoutError();
|
|
761
|
+
timer = customTimers.setTimeout.call(void 0, () => {
|
|
762
|
+
if (fallback) {
|
|
763
|
+
try {
|
|
764
|
+
resolve(fallback());
|
|
765
|
+
} catch (error) {
|
|
766
|
+
reject(error);
|
|
767
|
+
}
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if (typeof promise.cancel === "function") {
|
|
771
|
+
promise.cancel();
|
|
772
|
+
}
|
|
773
|
+
if (message === false) {
|
|
774
|
+
resolve();
|
|
775
|
+
} else if (message instanceof Error) {
|
|
776
|
+
reject(message);
|
|
777
|
+
} else {
|
|
778
|
+
timeoutError.message = message ?? `Promise timed out after ${milliseconds} milliseconds`;
|
|
779
|
+
reject(timeoutError);
|
|
780
|
+
}
|
|
781
|
+
}, milliseconds);
|
|
782
|
+
(async () => {
|
|
783
|
+
try {
|
|
784
|
+
resolve(await promise);
|
|
785
|
+
} catch (error) {
|
|
786
|
+
reject(error);
|
|
787
|
+
}
|
|
788
|
+
})();
|
|
789
|
+
});
|
|
790
|
+
const cancelablePromise = wrappedPromise.finally(() => {
|
|
791
|
+
cancelablePromise.clear();
|
|
792
|
+
});
|
|
793
|
+
cancelablePromise.clear = () => {
|
|
794
|
+
customTimers.clearTimeout.call(void 0, timer);
|
|
795
|
+
timer = void 0;
|
|
796
|
+
};
|
|
797
|
+
return cancelablePromise;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/priority-queue.js
|
|
801
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
802
|
+
|
|
803
|
+
// ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/lower-bound.js
|
|
804
|
+
chunkVBGWLAET_cjs.init_cjs_shims();
|
|
805
|
+
function lowerBound(array, value, comparator) {
|
|
806
|
+
let first = 0;
|
|
807
|
+
let count = array.length;
|
|
808
|
+
while (count > 0) {
|
|
809
|
+
const step = Math.trunc(count / 2);
|
|
810
|
+
let it = first + step;
|
|
811
|
+
if (comparator(array[it], value) <= 0) {
|
|
812
|
+
first = ++it;
|
|
813
|
+
count -= step + 1;
|
|
814
|
+
} else {
|
|
815
|
+
count = step;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
return first;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
// ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/priority-queue.js
|
|
822
|
+
var PriorityQueue = class {
|
|
823
|
+
#queue = [];
|
|
824
|
+
enqueue(run, options) {
|
|
825
|
+
options = {
|
|
826
|
+
priority: 0,
|
|
827
|
+
...options
|
|
828
|
+
};
|
|
829
|
+
const element = {
|
|
830
|
+
priority: options.priority,
|
|
831
|
+
run
|
|
832
|
+
};
|
|
833
|
+
if (this.size && this.#queue[this.size - 1].priority >= options.priority) {
|
|
834
|
+
this.#queue.push(element);
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
const index = lowerBound(this.#queue, element, (a, b) => b.priority - a.priority);
|
|
838
|
+
this.#queue.splice(index, 0, element);
|
|
839
|
+
}
|
|
840
|
+
dequeue() {
|
|
841
|
+
const item = this.#queue.shift();
|
|
842
|
+
return item?.run;
|
|
843
|
+
}
|
|
844
|
+
filter(options) {
|
|
845
|
+
return this.#queue.filter((element) => element.priority === options.priority).map((element) => element.run);
|
|
846
|
+
}
|
|
847
|
+
get size() {
|
|
848
|
+
return this.#queue.length;
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
|
|
852
|
+
// ../../node_modules/.pnpm/p-queue@8.0.1/node_modules/p-queue/dist/index.js
|
|
853
|
+
var PQueue = class extends import_index.default {
|
|
854
|
+
#carryoverConcurrencyCount;
|
|
855
|
+
#isIntervalIgnored;
|
|
856
|
+
#intervalCount = 0;
|
|
857
|
+
#intervalCap;
|
|
858
|
+
#interval;
|
|
859
|
+
#intervalEnd = 0;
|
|
860
|
+
#intervalId;
|
|
861
|
+
#timeoutId;
|
|
862
|
+
#queue;
|
|
863
|
+
#queueClass;
|
|
864
|
+
#pending = 0;
|
|
865
|
+
// The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194
|
|
866
|
+
#concurrency;
|
|
867
|
+
#isPaused;
|
|
868
|
+
#throwOnTimeout;
|
|
869
|
+
/**
|
|
870
|
+
Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
|
|
871
|
+
|
|
872
|
+
Applies to each future operation.
|
|
873
|
+
*/
|
|
874
|
+
timeout;
|
|
875
|
+
// TODO: The `throwOnTimeout` option should affect the return types of `add()` and `addAll()`
|
|
876
|
+
constructor(options) {
|
|
877
|
+
super();
|
|
878
|
+
options = {
|
|
879
|
+
carryoverConcurrencyCount: false,
|
|
880
|
+
intervalCap: Number.POSITIVE_INFINITY,
|
|
881
|
+
interval: 0,
|
|
882
|
+
concurrency: Number.POSITIVE_INFINITY,
|
|
883
|
+
autoStart: true,
|
|
884
|
+
queueClass: PriorityQueue,
|
|
885
|
+
...options
|
|
886
|
+
};
|
|
887
|
+
if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) {
|
|
888
|
+
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${options.intervalCap?.toString() ?? ""}\` (${typeof options.intervalCap})`);
|
|
889
|
+
}
|
|
890
|
+
if (options.interval === void 0 || !(Number.isFinite(options.interval) && options.interval >= 0)) {
|
|
891
|
+
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${options.interval?.toString() ?? ""}\` (${typeof options.interval})`);
|
|
892
|
+
}
|
|
893
|
+
this.#carryoverConcurrencyCount = options.carryoverConcurrencyCount;
|
|
894
|
+
this.#isIntervalIgnored = options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0;
|
|
895
|
+
this.#intervalCap = options.intervalCap;
|
|
896
|
+
this.#interval = options.interval;
|
|
897
|
+
this.#queue = new options.queueClass();
|
|
898
|
+
this.#queueClass = options.queueClass;
|
|
899
|
+
this.concurrency = options.concurrency;
|
|
900
|
+
this.timeout = options.timeout;
|
|
901
|
+
this.#throwOnTimeout = options.throwOnTimeout === true;
|
|
902
|
+
this.#isPaused = options.autoStart === false;
|
|
903
|
+
}
|
|
904
|
+
get #doesIntervalAllowAnother() {
|
|
905
|
+
return this.#isIntervalIgnored || this.#intervalCount < this.#intervalCap;
|
|
906
|
+
}
|
|
907
|
+
get #doesConcurrentAllowAnother() {
|
|
908
|
+
return this.#pending < this.#concurrency;
|
|
909
|
+
}
|
|
910
|
+
#next() {
|
|
911
|
+
this.#pending--;
|
|
912
|
+
this.#tryToStartAnother();
|
|
913
|
+
this.emit("next");
|
|
914
|
+
}
|
|
915
|
+
#onResumeInterval() {
|
|
916
|
+
this.#onInterval();
|
|
917
|
+
this.#initializeIntervalIfNeeded();
|
|
918
|
+
this.#timeoutId = void 0;
|
|
919
|
+
}
|
|
920
|
+
get #isIntervalPaused() {
|
|
921
|
+
const now = Date.now();
|
|
922
|
+
if (this.#intervalId === void 0) {
|
|
923
|
+
const delay = this.#intervalEnd - now;
|
|
924
|
+
if (delay < 0) {
|
|
925
|
+
this.#intervalCount = this.#carryoverConcurrencyCount ? this.#pending : 0;
|
|
926
|
+
} else {
|
|
927
|
+
if (this.#timeoutId === void 0) {
|
|
928
|
+
this.#timeoutId = setTimeout(() => {
|
|
929
|
+
this.#onResumeInterval();
|
|
930
|
+
}, delay);
|
|
931
|
+
}
|
|
932
|
+
return true;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return false;
|
|
936
|
+
}
|
|
937
|
+
#tryToStartAnother() {
|
|
938
|
+
if (this.#queue.size === 0) {
|
|
939
|
+
if (this.#intervalId) {
|
|
940
|
+
clearInterval(this.#intervalId);
|
|
941
|
+
}
|
|
942
|
+
this.#intervalId = void 0;
|
|
943
|
+
this.emit("empty");
|
|
944
|
+
if (this.#pending === 0) {
|
|
945
|
+
this.emit("idle");
|
|
946
|
+
}
|
|
947
|
+
return false;
|
|
948
|
+
}
|
|
949
|
+
if (!this.#isPaused) {
|
|
950
|
+
const canInitializeInterval = !this.#isIntervalPaused;
|
|
951
|
+
if (this.#doesIntervalAllowAnother && this.#doesConcurrentAllowAnother) {
|
|
952
|
+
const job = this.#queue.dequeue();
|
|
953
|
+
if (!job) {
|
|
954
|
+
return false;
|
|
955
|
+
}
|
|
956
|
+
this.emit("active");
|
|
957
|
+
job();
|
|
958
|
+
if (canInitializeInterval) {
|
|
959
|
+
this.#initializeIntervalIfNeeded();
|
|
960
|
+
}
|
|
961
|
+
return true;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
return false;
|
|
965
|
+
}
|
|
966
|
+
#initializeIntervalIfNeeded() {
|
|
967
|
+
if (this.#isIntervalIgnored || this.#intervalId !== void 0) {
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
this.#intervalId = setInterval(() => {
|
|
971
|
+
this.#onInterval();
|
|
972
|
+
}, this.#interval);
|
|
973
|
+
this.#intervalEnd = Date.now() + this.#interval;
|
|
974
|
+
}
|
|
975
|
+
#onInterval() {
|
|
976
|
+
if (this.#intervalCount === 0 && this.#pending === 0 && this.#intervalId) {
|
|
977
|
+
clearInterval(this.#intervalId);
|
|
978
|
+
this.#intervalId = void 0;
|
|
979
|
+
}
|
|
980
|
+
this.#intervalCount = this.#carryoverConcurrencyCount ? this.#pending : 0;
|
|
981
|
+
this.#processQueue();
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
Executes all queued functions until it reaches the limit.
|
|
985
|
+
*/
|
|
986
|
+
#processQueue() {
|
|
987
|
+
while (this.#tryToStartAnother()) {
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
get concurrency() {
|
|
991
|
+
return this.#concurrency;
|
|
992
|
+
}
|
|
993
|
+
set concurrency(newConcurrency) {
|
|
994
|
+
if (!(typeof newConcurrency === "number" && newConcurrency >= 1)) {
|
|
995
|
+
throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`);
|
|
996
|
+
}
|
|
997
|
+
this.#concurrency = newConcurrency;
|
|
998
|
+
this.#processQueue();
|
|
999
|
+
}
|
|
1000
|
+
async #throwOnAbort(signal) {
|
|
1001
|
+
return new Promise((_resolve, reject) => {
|
|
1002
|
+
signal.addEventListener("abort", () => {
|
|
1003
|
+
reject(signal.reason);
|
|
1004
|
+
}, { once: true });
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
async add(function_, options = {}) {
|
|
1008
|
+
options = {
|
|
1009
|
+
timeout: this.timeout,
|
|
1010
|
+
throwOnTimeout: this.#throwOnTimeout,
|
|
1011
|
+
...options
|
|
1012
|
+
};
|
|
1013
|
+
return new Promise((resolve, reject) => {
|
|
1014
|
+
this.#queue.enqueue(async () => {
|
|
1015
|
+
this.#pending++;
|
|
1016
|
+
this.#intervalCount++;
|
|
1017
|
+
try {
|
|
1018
|
+
options.signal?.throwIfAborted();
|
|
1019
|
+
let operation = function_({ signal: options.signal });
|
|
1020
|
+
if (options.timeout) {
|
|
1021
|
+
operation = pTimeout(Promise.resolve(operation), { milliseconds: options.timeout });
|
|
1022
|
+
}
|
|
1023
|
+
if (options.signal) {
|
|
1024
|
+
operation = Promise.race([operation, this.#throwOnAbort(options.signal)]);
|
|
1025
|
+
}
|
|
1026
|
+
const result = await operation;
|
|
1027
|
+
resolve(result);
|
|
1028
|
+
this.emit("completed", result);
|
|
1029
|
+
} catch (error) {
|
|
1030
|
+
if (error instanceof TimeoutError && !options.throwOnTimeout) {
|
|
1031
|
+
resolve();
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
reject(error);
|
|
1035
|
+
this.emit("error", error);
|
|
1036
|
+
} finally {
|
|
1037
|
+
this.#next();
|
|
1038
|
+
}
|
|
1039
|
+
}, options);
|
|
1040
|
+
this.emit("add");
|
|
1041
|
+
this.#tryToStartAnother();
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
async addAll(functions, options) {
|
|
1045
|
+
return Promise.all(functions.map(async (function_) => this.add(function_, options)));
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.)
|
|
1049
|
+
*/
|
|
1050
|
+
start() {
|
|
1051
|
+
if (!this.#isPaused) {
|
|
1052
|
+
return this;
|
|
1053
|
+
}
|
|
1054
|
+
this.#isPaused = false;
|
|
1055
|
+
this.#processQueue();
|
|
1056
|
+
return this;
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
Put queue execution on hold.
|
|
1060
|
+
*/
|
|
1061
|
+
pause() {
|
|
1062
|
+
this.#isPaused = true;
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
Clear the queue.
|
|
1066
|
+
*/
|
|
1067
|
+
clear() {
|
|
1068
|
+
this.#queue = new this.#queueClass();
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
Can be called multiple times. Useful if you for example add additional items at a later time.
|
|
1072
|
+
|
|
1073
|
+
@returns A promise that settles when the queue becomes empty.
|
|
1074
|
+
*/
|
|
1075
|
+
async onEmpty() {
|
|
1076
|
+
if (this.#queue.size === 0) {
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
await this.#onEvent("empty");
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
@returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`.
|
|
1083
|
+
|
|
1084
|
+
If you want to avoid having the queue grow beyond a certain size you can `await queue.onSizeLessThan()` before adding a new item.
|
|
1085
|
+
|
|
1086
|
+
Note that this only limits the number of items waiting to start. There could still be up to `concurrency` jobs already running that this call does not include in its calculation.
|
|
1087
|
+
*/
|
|
1088
|
+
async onSizeLessThan(limit) {
|
|
1089
|
+
if (this.#queue.size < limit) {
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
await this.#onEvent("next", () => this.#queue.size < limit);
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet.
|
|
1096
|
+
|
|
1097
|
+
@returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
|
|
1098
|
+
*/
|
|
1099
|
+
async onIdle() {
|
|
1100
|
+
if (this.#pending === 0 && this.#queue.size === 0) {
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
await this.#onEvent("idle");
|
|
1104
|
+
}
|
|
1105
|
+
async #onEvent(event, filter) {
|
|
1106
|
+
return new Promise((resolve) => {
|
|
1107
|
+
const listener = () => {
|
|
1108
|
+
if (filter && !filter()) {
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
this.off(event, listener);
|
|
1112
|
+
resolve();
|
|
1113
|
+
};
|
|
1114
|
+
this.on(event, listener);
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
Size of the queue, the number of queued items waiting to run.
|
|
1119
|
+
*/
|
|
1120
|
+
get size() {
|
|
1121
|
+
return this.#queue.size;
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
Size of the queue, filtered by the given options.
|
|
1125
|
+
|
|
1126
|
+
For example, this can be used to find the number of items remaining in the queue with a specific priority level.
|
|
1127
|
+
*/
|
|
1128
|
+
sizeBy(options) {
|
|
1129
|
+
return this.#queue.filter(options).length;
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
Number of running items (no longer in the queue).
|
|
1133
|
+
*/
|
|
1134
|
+
get pending() {
|
|
1135
|
+
return this.#pending;
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
Whether the queue is currently paused.
|
|
1139
|
+
*/
|
|
1140
|
+
get isPaused() {
|
|
1141
|
+
return this.#isPaused;
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
|
|
1145
|
+
// src/FileManager.ts
|
|
1146
|
+
var FileManager = class {
|
|
1147
|
+
#filesByPath = /* @__PURE__ */ new Map();
|
|
1148
|
+
constructor() {
|
|
1149
|
+
return this;
|
|
1150
|
+
}
|
|
1151
|
+
get files() {
|
|
1152
|
+
return [...this.#filesByPath.values()];
|
|
1153
|
+
}
|
|
1154
|
+
get orderedFiles() {
|
|
1155
|
+
return chunkRIW2LFFQ_cjs.orderBy(
|
|
1156
|
+
[...this.#filesByPath.values()],
|
|
1157
|
+
[
|
|
1158
|
+
(v) => v?.meta && "pluginKey" in v.meta && !v.meta.pluginKey,
|
|
1159
|
+
(v) => v.path.length,
|
|
1160
|
+
(v) => fs.trimExtName(v.path).endsWith("index"),
|
|
1161
|
+
(v) => fs.trimExtName(v.baseName),
|
|
1162
|
+
(v) => v.path.split(".").pop()
|
|
1163
|
+
]
|
|
1164
|
+
);
|
|
1165
|
+
}
|
|
1166
|
+
get groupedFiles() {
|
|
1167
|
+
return buildDirectoryTree([...this.#filesByPath.values()]);
|
|
1168
|
+
}
|
|
1169
|
+
get treeNode() {
|
|
1170
|
+
return TreeNode.build([...this.#filesByPath.values()]);
|
|
1171
|
+
}
|
|
1172
|
+
async add(...files) {
|
|
1173
|
+
const promises = files.map((file) => {
|
|
1174
|
+
if (file.override) {
|
|
1175
|
+
return this.#add(file);
|
|
1176
|
+
}
|
|
1177
|
+
return this.#addOrAppend(file);
|
|
1178
|
+
});
|
|
1179
|
+
const resolvedFiles = await Promise.all(promises);
|
|
1180
|
+
if (files.length > 1) {
|
|
1181
|
+
return resolvedFiles;
|
|
1182
|
+
}
|
|
1183
|
+
return resolvedFiles[0];
|
|
1184
|
+
}
|
|
1185
|
+
async #add(file) {
|
|
1186
|
+
const resolvedFile = createFile(file);
|
|
1187
|
+
this.#filesByPath.set(resolvedFile.path, resolvedFile);
|
|
1188
|
+
return resolvedFile;
|
|
1189
|
+
}
|
|
1190
|
+
clear() {
|
|
1191
|
+
this.#filesByPath.clear();
|
|
1192
|
+
}
|
|
1193
|
+
async #addOrAppend(file) {
|
|
1194
|
+
const previousFile = this.#filesByPath.get(file.path);
|
|
1195
|
+
if (previousFile) {
|
|
1196
|
+
this.#filesByPath.delete(previousFile.path);
|
|
1197
|
+
return this.#add(mergeFile(previousFile, file));
|
|
1198
|
+
}
|
|
1199
|
+
return this.#add(file);
|
|
1200
|
+
}
|
|
1201
|
+
getCacheById(id) {
|
|
1202
|
+
return [...this.#filesByPath.values()].find((file) => file.id === id);
|
|
1203
|
+
}
|
|
1204
|
+
getByPath(path2) {
|
|
1205
|
+
return this.#filesByPath.get(path2);
|
|
1206
|
+
}
|
|
1207
|
+
deleteByPath(path2) {
|
|
1208
|
+
const cacheItem = this.getByPath(path2);
|
|
1209
|
+
if (!cacheItem) {
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
this.#filesByPath.delete(path2);
|
|
1213
|
+
}
|
|
1214
|
+
async getBarrelFiles({ type, files, meta = {}, root, output, logger }) {
|
|
1215
|
+
if (!type) {
|
|
1216
|
+
return [];
|
|
1217
|
+
}
|
|
1218
|
+
const barrelManager = new BarrelManager({ logger });
|
|
1219
|
+
const pathToBuildFrom = path.join(root, output.path);
|
|
1220
|
+
if (fs.trimExtName(pathToBuildFrom).endsWith("index")) {
|
|
1221
|
+
logger?.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
|
|
1222
|
+
return [];
|
|
1223
|
+
}
|
|
1224
|
+
const barrelFiles = barrelManager.getFiles({ files, root: pathToBuildFrom, meta });
|
|
1225
|
+
if (type === "all") {
|
|
1226
|
+
return barrelFiles.map((file) => {
|
|
1227
|
+
return {
|
|
1228
|
+
...file,
|
|
1229
|
+
exports: file.exports?.map((exportItem) => {
|
|
1230
|
+
return {
|
|
1231
|
+
...exportItem,
|
|
1232
|
+
name: void 0
|
|
1233
|
+
};
|
|
1234
|
+
})
|
|
1235
|
+
};
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
return barrelFiles.map((indexFile) => {
|
|
1239
|
+
return {
|
|
1240
|
+
...indexFile,
|
|
1241
|
+
meta
|
|
1242
|
+
};
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
async write(...params) {
|
|
1246
|
+
return fs.write(...params);
|
|
1247
|
+
}
|
|
1248
|
+
async read(...params) {
|
|
1249
|
+
return fs.read(...params);
|
|
1250
|
+
}
|
|
1251
|
+
// statics
|
|
1252
|
+
static getMode(path2) {
|
|
1253
|
+
if (!path2) {
|
|
1254
|
+
return "split";
|
|
1255
|
+
}
|
|
1256
|
+
return path.extname(path2) ? "single" : "split";
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
async function getSource(file, { logger, extname: extname2 } = {}) {
|
|
1260
|
+
const parser = await getFileParser(file.extname);
|
|
1261
|
+
const source = await parser.print(file, { logger, extname: extname2 });
|
|
1262
|
+
return parser.format(source);
|
|
1263
|
+
}
|
|
1264
|
+
function mergeFile(a, b) {
|
|
1265
|
+
return {
|
|
1266
|
+
...a,
|
|
1267
|
+
sources: [...a.sources || [], ...b.sources || []],
|
|
1268
|
+
imports: [...a.imports || [], ...b.imports || []],
|
|
1269
|
+
exports: [...a.exports || [], ...b.exports || []]
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
function combineSources(sources) {
|
|
1273
|
+
return sources.reduce(
|
|
1274
|
+
(prev, curr) => {
|
|
1275
|
+
const prevByName = prev.findLast((imp) => imp.name && imp.name === curr.name);
|
|
1276
|
+
const prevByPathAndIsExportable = prev.findLast((imp) => imp.name === curr.name && imp.isExportable);
|
|
1277
|
+
if (prevByPathAndIsExportable) {
|
|
1278
|
+
return [...prev, curr];
|
|
1279
|
+
}
|
|
1280
|
+
if (prevByName) {
|
|
1281
|
+
prevByName.value = curr.value;
|
|
1282
|
+
prevByName.isExportable = curr.isExportable;
|
|
1283
|
+
prevByName.isTypeOnly = curr.isTypeOnly;
|
|
1284
|
+
prevByName.isIndexable = curr.isIndexable;
|
|
1285
|
+
return prev;
|
|
1286
|
+
}
|
|
1287
|
+
return [...prev, curr];
|
|
1288
|
+
},
|
|
1289
|
+
[]
|
|
1290
|
+
);
|
|
1291
|
+
}
|
|
1292
|
+
function combineExports(exports) {
|
|
1293
|
+
return chunkRIW2LFFQ_cjs.orderBy(exports, [
|
|
1294
|
+
(v) => !!Array.isArray(v.name),
|
|
1295
|
+
(v) => !v.isTypeOnly,
|
|
1296
|
+
(v) => v.path,
|
|
1297
|
+
(v) => !!v.name,
|
|
1298
|
+
(v) => Array.isArray(v.name) ? chunkRIW2LFFQ_cjs.orderBy(v.name) : v.name
|
|
1299
|
+
]).reduce(
|
|
1300
|
+
(prev, curr) => {
|
|
1301
|
+
const name = curr.name;
|
|
1302
|
+
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
1303
|
+
const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && remeda.isDeepEqual(imp.name, name) && imp.isTypeOnly);
|
|
1304
|
+
if (prevByPathAndIsTypeOnly) {
|
|
1305
|
+
return prev;
|
|
1306
|
+
}
|
|
1307
|
+
const uniquePrev = prev.findLast(
|
|
1308
|
+
(imp) => imp.path === curr.path && remeda.isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
1309
|
+
);
|
|
1310
|
+
if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) {
|
|
1311
|
+
return prev;
|
|
1312
|
+
}
|
|
1313
|
+
if (!prevByPath) {
|
|
1314
|
+
return [
|
|
1315
|
+
...prev,
|
|
1316
|
+
{
|
|
1317
|
+
...curr,
|
|
1318
|
+
name: Array.isArray(name) ? [...new Set(name)] : name
|
|
1319
|
+
}
|
|
1320
|
+
];
|
|
1321
|
+
}
|
|
1322
|
+
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
1323
|
+
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...curr.name])];
|
|
1324
|
+
return prev;
|
|
1325
|
+
}
|
|
1326
|
+
return [...prev, curr];
|
|
1327
|
+
},
|
|
1328
|
+
[]
|
|
1329
|
+
);
|
|
1330
|
+
}
|
|
1331
|
+
function combineImports(imports, exports, source) {
|
|
1332
|
+
return chunkRIW2LFFQ_cjs.orderBy(imports, [
|
|
1333
|
+
(v) => !!Array.isArray(v.name),
|
|
1334
|
+
(v) => !v.isTypeOnly,
|
|
1335
|
+
(v) => v.path,
|
|
1336
|
+
(v) => !!v.name,
|
|
1337
|
+
(v) => Array.isArray(v.name) ? chunkRIW2LFFQ_cjs.orderBy(v.name) : v.name
|
|
1338
|
+
]).reduce(
|
|
1339
|
+
(prev, curr) => {
|
|
1340
|
+
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
1341
|
+
const hasImportInSource = (importName) => {
|
|
1342
|
+
if (!source) {
|
|
1343
|
+
return true;
|
|
1344
|
+
}
|
|
1345
|
+
const checker = (name2) => {
|
|
1346
|
+
return name2 && !!source.includes(name2);
|
|
1347
|
+
};
|
|
1348
|
+
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
1349
|
+
};
|
|
1350
|
+
if (curr.path === curr.root) {
|
|
1351
|
+
return prev;
|
|
1352
|
+
}
|
|
1353
|
+
if (Array.isArray(name)) {
|
|
1354
|
+
name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
|
|
1355
|
+
}
|
|
1356
|
+
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
1357
|
+
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && remeda.isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
1358
|
+
const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && remeda.isDeepEqual(imp.name, name) && imp.isTypeOnly);
|
|
1359
|
+
if (prevByPathNameAndIsTypeOnly) {
|
|
1360
|
+
return prev;
|
|
1361
|
+
}
|
|
1362
|
+
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
1363
|
+
return prev;
|
|
1364
|
+
}
|
|
1365
|
+
if (!prevByPath) {
|
|
1366
|
+
return [
|
|
1367
|
+
...prev,
|
|
1368
|
+
{
|
|
1369
|
+
...curr,
|
|
1370
|
+
name
|
|
1371
|
+
}
|
|
1372
|
+
];
|
|
1373
|
+
}
|
|
1374
|
+
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
1375
|
+
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...name])];
|
|
1376
|
+
return prev;
|
|
1377
|
+
}
|
|
1378
|
+
if (!Array.isArray(name) && name && !hasImportInSource(name)) {
|
|
1379
|
+
return prev;
|
|
1380
|
+
}
|
|
1381
|
+
return [...prev, curr];
|
|
1382
|
+
},
|
|
1383
|
+
[]
|
|
1384
|
+
);
|
|
1385
|
+
}
|
|
1386
|
+
var queue = new PQueue({ concurrency: 100 });
|
|
1387
|
+
async function processFiles({ dryRun, config, logger, files }) {
|
|
1388
|
+
const orderedFiles = chunkRIW2LFFQ_cjs.orderBy(files, [
|
|
1389
|
+
(v) => v?.meta && "pluginKey" in v.meta && !v.meta.pluginKey,
|
|
1390
|
+
(v) => v.path.length,
|
|
1391
|
+
(v) => fs.trimExtName(v.path).endsWith("index")
|
|
1392
|
+
]);
|
|
1393
|
+
logger.emit("debug", {
|
|
1394
|
+
date: /* @__PURE__ */ new Date(),
|
|
1395
|
+
logs: [JSON.stringify({ files: orderedFiles }, null, 2)],
|
|
1396
|
+
fileName: "kubb-files.log"
|
|
1397
|
+
});
|
|
1398
|
+
if (!dryRun) {
|
|
1399
|
+
const size = orderedFiles.length;
|
|
1400
|
+
logger.emit("progress_start", { id: "files", size, message: "Writing files ..." });
|
|
1401
|
+
const promises = orderedFiles.map(async (file) => {
|
|
1402
|
+
await queue.add(async () => {
|
|
1403
|
+
const message = file ? `Writing ${path.relative(config.root, file.path)}` : "";
|
|
1404
|
+
const extnames = config.output.extension?.({});
|
|
1405
|
+
const extname2 = extnames?.[file.extname];
|
|
1406
|
+
const source = await getSource(file, { logger, extname: extname2 });
|
|
1407
|
+
await fs.write(file.path, source, { sanity: false });
|
|
1408
|
+
logger.emit("progressed", { id: "files", message });
|
|
1409
|
+
});
|
|
1410
|
+
});
|
|
1411
|
+
await Promise.all(promises);
|
|
1412
|
+
logger.emit("progress_stop", { id: "files" });
|
|
1413
|
+
}
|
|
1414
|
+
return files;
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
// src/utils/parser.ts
|
|
1418
|
+
function createFile(file) {
|
|
1419
|
+
const extname2 = path__default.default.extname(file.baseName);
|
|
1420
|
+
if (!extname2) {
|
|
1421
|
+
throw new Error(`No extname found for ${file.baseName}`);
|
|
1422
|
+
}
|
|
1423
|
+
const source = file.sources.map((item) => item.value).join("\n\n");
|
|
1424
|
+
const exports = file.exports ? combineExports(file.exports) : [];
|
|
1425
|
+
const imports = file.imports && source ? combineImports(file.imports, exports, source) : [];
|
|
1426
|
+
const sources = file.sources ? combineSources(file.sources) : [];
|
|
1427
|
+
return {
|
|
1428
|
+
...file,
|
|
1429
|
+
id: hash__default.default({ path: file.path }),
|
|
1430
|
+
name: trimExtName2(file.baseName),
|
|
1431
|
+
extname: extname2,
|
|
1432
|
+
imports: imports.map((item) => createFileImport(item)),
|
|
1433
|
+
exports: exports.map((item) => createFileExport(item)),
|
|
1434
|
+
sources: sources.map((item) => createFileSource(item)),
|
|
1435
|
+
meta: file.meta || {}
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
function createFileSource(source) {
|
|
1439
|
+
return source;
|
|
1440
|
+
}
|
|
1441
|
+
function createFileImport(imp) {
|
|
1442
|
+
return {
|
|
1443
|
+
...imp
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
function createFileExport(exp) {
|
|
1447
|
+
return {
|
|
1448
|
+
...exp
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
function createFileParser(parser) {
|
|
1452
|
+
return parser;
|
|
1453
|
+
}
|
|
1454
|
+
var typeScriptParser = createFileParser({
|
|
1455
|
+
async format(source) {
|
|
1456
|
+
const module = await import('@kubb/parser-ts');
|
|
1457
|
+
return module.format(source);
|
|
1458
|
+
},
|
|
1459
|
+
async print(file, options = { extname: ".ts" }) {
|
|
1460
|
+
const module = await import('@kubb/parser-ts');
|
|
1461
|
+
const source = file.sources.map((item) => item.value).join("\n\n");
|
|
1462
|
+
const importNodes = file.imports.map((item) => {
|
|
1463
|
+
const importPath = item.root ? fs.getRelativePath(item.root, item.path) : item.path;
|
|
1464
|
+
const hasExtname = !!path__default.default.extname(importPath);
|
|
1465
|
+
return module.factory.createImportDeclaration({
|
|
1466
|
+
name: item.name,
|
|
1467
|
+
path: options.extname && hasExtname ? `${trimExtName2(importPath)}${options.extname}` : trimExtName2(importPath),
|
|
1468
|
+
isTypeOnly: item.isTypeOnly
|
|
1469
|
+
});
|
|
1470
|
+
}).filter(Boolean);
|
|
1471
|
+
const exportNodes = file.exports.map((item) => {
|
|
1472
|
+
const exportPath = item.path;
|
|
1473
|
+
const hasExtname = !!path__default.default.extname(exportPath);
|
|
1474
|
+
return module.factory.createExportDeclaration({
|
|
1475
|
+
name: item.name,
|
|
1476
|
+
path: options.extname && hasExtname ? `${trimExtName2(item.path)}${options.extname}` : trimExtName2(item.path),
|
|
1477
|
+
isTypeOnly: item.isTypeOnly,
|
|
1478
|
+
asAlias: item.asAlias
|
|
1479
|
+
});
|
|
1480
|
+
}).filter(Boolean);
|
|
1481
|
+
return [file.banner, module.print([...importNodes, ...exportNodes]), source, file.footer].join("\n");
|
|
1482
|
+
}
|
|
1483
|
+
});
|
|
1484
|
+
var defaultParser = createFileParser({
|
|
1485
|
+
async format(source) {
|
|
1486
|
+
return source;
|
|
1487
|
+
},
|
|
1488
|
+
async print(file) {
|
|
1489
|
+
return file.sources.map((item) => item.value).join("\n\n");
|
|
1490
|
+
}
|
|
1491
|
+
});
|
|
1492
|
+
var parsers = {
|
|
1493
|
+
".ts": typeScriptParser,
|
|
1494
|
+
".js": typeScriptParser,
|
|
1495
|
+
".jsx": typeScriptParser,
|
|
1496
|
+
".tsx": typeScriptParser,
|
|
1497
|
+
".json": defaultParser
|
|
1498
|
+
};
|
|
1499
|
+
async function getFileParser(extname2) {
|
|
1500
|
+
if (!extname2) {
|
|
1501
|
+
return defaultParser;
|
|
1502
|
+
}
|
|
1503
|
+
const parser = parsers[extname2];
|
|
1504
|
+
if (!parser) {
|
|
1505
|
+
console.warn(`[parser] No parser found for ${extname2}, default parser will be used`);
|
|
1506
|
+
}
|
|
1507
|
+
return parser || defaultParser;
|
|
1508
|
+
}
|
|
1509
|
+
function trimExtName2(text) {
|
|
1510
|
+
const extname2 = text.split(".").pop();
|
|
1511
|
+
return text.replace(`.${extname2}`, "");
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
exports.FileManager = FileManager;
|
|
1515
|
+
exports.FunctionParams = FunctionParams;
|
|
1516
|
+
exports.URLPath = URLPath;
|
|
1517
|
+
exports.createFile = createFile;
|
|
1518
|
+
exports.createFileExport = createFileExport;
|
|
1519
|
+
exports.createFileImport = createFileImport;
|
|
1520
|
+
exports.createFileParser = createFileParser;
|
|
1521
|
+
exports.getFileParser = getFileParser;
|
|
1522
|
+
exports.getSource = getSource;
|
|
1523
|
+
exports.getUniqueName = getUniqueName;
|
|
1524
|
+
exports.isPromise = isPromise;
|
|
1525
|
+
exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
|
|
1526
|
+
exports.isPromiseRejectedResult = isPromiseRejectedResult;
|
|
1527
|
+
exports.processFiles = processFiles;
|
|
1528
|
+
exports.renderTemplate = renderTemplate;
|
|
1529
|
+
exports.setUniqueName = setUniqueName;
|
|
1530
|
+
exports.timeout = timeout;
|
|
1531
|
+
//# sourceMappingURL=chunk-SX5FHSVT.cjs.map
|
|
1532
|
+
//# sourceMappingURL=chunk-SX5FHSVT.cjs.map
|