@kubb/core 1.15.0-canary.20231026T131818 → 1.15.0-canary.20231026T182312
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +451 -371
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +422 -352
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +167 -115
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js +166 -115
- package/dist/utils.js.map +1 -1
- package/package.json +2 -2
package/dist/utils.js
CHANGED
|
@@ -17,6 +17,36 @@ import isEqual from 'lodash.isequal';
|
|
|
17
17
|
|
|
18
18
|
createRequire(import.meta.url);
|
|
19
19
|
|
|
20
|
+
var __accessCheck = (obj, member, msg) => {
|
|
21
|
+
if (!member.has(obj))
|
|
22
|
+
throw TypeError("Cannot " + msg);
|
|
23
|
+
};
|
|
24
|
+
var __privateGet = (obj, member, getter) => {
|
|
25
|
+
__accessCheck(obj, member, "read from private field");
|
|
26
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
27
|
+
};
|
|
28
|
+
var __privateAdd = (obj, member, value) => {
|
|
29
|
+
if (member.has(obj))
|
|
30
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
31
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
32
|
+
};
|
|
33
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
34
|
+
__accessCheck(obj, member, "write to private field");
|
|
35
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
38
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
39
|
+
set _(value) {
|
|
40
|
+
__privateSet(obj, member, value, setter);
|
|
41
|
+
},
|
|
42
|
+
get _() {
|
|
43
|
+
return __privateGet(obj, member, getter);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
var __privateMethod = (obj, member, method) => {
|
|
47
|
+
__accessCheck(obj, member, "access private method");
|
|
48
|
+
return method;
|
|
49
|
+
};
|
|
20
50
|
|
|
21
51
|
// src/utils/cache.ts
|
|
22
52
|
function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
|
|
@@ -49,9 +79,8 @@ async function clean(path2) {
|
|
|
49
79
|
return remove(path2);
|
|
50
80
|
}
|
|
51
81
|
var FunctionParams = class {
|
|
52
|
-
type;
|
|
53
|
-
items = [];
|
|
54
82
|
constructor(type) {
|
|
83
|
+
this.items = [];
|
|
55
84
|
this.type = type;
|
|
56
85
|
return this;
|
|
57
86
|
}
|
|
@@ -140,88 +169,97 @@ function isPromiseFulfilledResult(result) {
|
|
|
140
169
|
function isPromiseRejectedResult(result) {
|
|
141
170
|
return result.status === "rejected";
|
|
142
171
|
}
|
|
172
|
+
var _emitter;
|
|
143
173
|
var EventEmitter = class {
|
|
144
174
|
constructor() {
|
|
145
|
-
this
|
|
175
|
+
__privateAdd(this, _emitter, new EventEmitter$1());
|
|
176
|
+
__privateGet(this, _emitter).setMaxListeners(100);
|
|
146
177
|
}
|
|
147
|
-
#emitter = new EventEmitter$1();
|
|
148
178
|
emit(eventName, ...eventArg) {
|
|
149
|
-
this
|
|
179
|
+
__privateGet(this, _emitter).emit(eventName, ...eventArg);
|
|
150
180
|
}
|
|
151
181
|
on(eventName, handler) {
|
|
152
|
-
this
|
|
182
|
+
__privateGet(this, _emitter).on(eventName, handler);
|
|
153
183
|
}
|
|
154
184
|
off(eventName, handler) {
|
|
155
|
-
this
|
|
185
|
+
__privateGet(this, _emitter).off(eventName, handler);
|
|
156
186
|
}
|
|
157
187
|
removeAll() {
|
|
158
|
-
this
|
|
188
|
+
__privateGet(this, _emitter).removeAllListeners();
|
|
159
189
|
}
|
|
160
190
|
};
|
|
191
|
+
_emitter = new WeakMap();
|
|
161
192
|
|
|
162
193
|
// src/utils/Queue.ts
|
|
194
|
+
var _queue, _workerCount, _maxParallel, _debug, _work, work_fn;
|
|
163
195
|
var Queue = class {
|
|
164
|
-
#queue = [];
|
|
165
|
-
eventEmitter = new EventEmitter();
|
|
166
|
-
#workerCount = 0;
|
|
167
|
-
#maxParallel;
|
|
168
|
-
#debug = false;
|
|
169
196
|
constructor(maxParallel, debug = false) {
|
|
170
|
-
this
|
|
171
|
-
this
|
|
197
|
+
__privateAdd(this, _work);
|
|
198
|
+
__privateAdd(this, _queue, []);
|
|
199
|
+
this.eventEmitter = new EventEmitter();
|
|
200
|
+
__privateAdd(this, _workerCount, 0);
|
|
201
|
+
__privateAdd(this, _maxParallel, void 0);
|
|
202
|
+
__privateAdd(this, _debug, false);
|
|
203
|
+
__privateSet(this, _maxParallel, maxParallel);
|
|
204
|
+
__privateSet(this, _debug, debug);
|
|
172
205
|
}
|
|
173
206
|
run(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
|
|
174
207
|
return new Promise((resolve2, reject) => {
|
|
175
208
|
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
176
209
|
options.controller?.signal.addEventListener("abort", () => {
|
|
177
|
-
this
|
|
210
|
+
__privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
|
|
178
211
|
reject("Aborted");
|
|
179
212
|
});
|
|
180
|
-
this
|
|
181
|
-
this
|
|
213
|
+
__privateGet(this, _queue).push(item);
|
|
214
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
182
215
|
});
|
|
183
216
|
}
|
|
184
217
|
runSync(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
|
|
185
218
|
new Promise((resolve2, reject) => {
|
|
186
219
|
const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
|
|
187
220
|
options.controller?.signal.addEventListener("abort", () => {
|
|
188
|
-
this
|
|
221
|
+
__privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
|
|
189
222
|
});
|
|
190
|
-
this
|
|
191
|
-
this
|
|
223
|
+
__privateGet(this, _queue).push(item);
|
|
224
|
+
__privateMethod(this, _work, work_fn).call(this);
|
|
192
225
|
});
|
|
193
226
|
}
|
|
194
227
|
get hasJobs() {
|
|
195
|
-
return this
|
|
228
|
+
return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue).length > 0;
|
|
196
229
|
}
|
|
197
230
|
get count() {
|
|
198
|
-
return this
|
|
231
|
+
return __privateGet(this, _workerCount);
|
|
199
232
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
233
|
+
};
|
|
234
|
+
_queue = new WeakMap();
|
|
235
|
+
_workerCount = new WeakMap();
|
|
236
|
+
_maxParallel = new WeakMap();
|
|
237
|
+
_debug = new WeakMap();
|
|
238
|
+
_work = new WeakSet();
|
|
239
|
+
work_fn = function() {
|
|
240
|
+
if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
__privateWrapper(this, _workerCount)._++;
|
|
244
|
+
let entry;
|
|
245
|
+
while (entry = __privateGet(this, _queue).shift()) {
|
|
246
|
+
const { reject, resolve: resolve2, job, name, description } = entry;
|
|
247
|
+
if (__privateGet(this, _debug)) {
|
|
248
|
+
performance.mark(name + "_start");
|
|
203
249
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
performance.
|
|
250
|
+
job().then((result) => {
|
|
251
|
+
this.eventEmitter.emit("jobDone", result);
|
|
252
|
+
resolve2(result);
|
|
253
|
+
if (__privateGet(this, _debug)) {
|
|
254
|
+
performance.mark(name + "_stop");
|
|
255
|
+
performance.measure(description, name + "_start", name + "_stop");
|
|
210
256
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
performance.mark(name + "_stop");
|
|
216
|
-
performance.measure(description, name + "_start", name + "_stop");
|
|
217
|
-
}
|
|
218
|
-
}).catch((err) => {
|
|
219
|
-
this.eventEmitter.emit("jobFailed", err);
|
|
220
|
-
reject(err);
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
this.#workerCount--;
|
|
257
|
+
}).catch((err) => {
|
|
258
|
+
this.eventEmitter.emit("jobFailed", err);
|
|
259
|
+
reject(err);
|
|
260
|
+
});
|
|
224
261
|
}
|
|
262
|
+
__privateWrapper(this, _workerCount)._--;
|
|
225
263
|
};
|
|
226
264
|
var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
|
|
227
265
|
function randomColour(text, colours = defaultColours) {
|
|
@@ -597,14 +635,15 @@ async function write(data, path2) {
|
|
|
597
635
|
}
|
|
598
636
|
return writer(path2, data.trim());
|
|
599
637
|
}
|
|
638
|
+
var _options;
|
|
600
639
|
var BarrelManager = class {
|
|
601
|
-
#options = {};
|
|
602
640
|
constructor(options = {}) {
|
|
603
|
-
this
|
|
641
|
+
__privateAdd(this, _options, {});
|
|
642
|
+
__privateSet(this, _options, options);
|
|
604
643
|
return this;
|
|
605
644
|
}
|
|
606
645
|
getIndexes(root, extName) {
|
|
607
|
-
const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = this
|
|
646
|
+
const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = __privateGet(this, _options);
|
|
608
647
|
const extMapper = {
|
|
609
648
|
".ts": {
|
|
610
649
|
extensions: /\.ts/,
|
|
@@ -673,50 +712,47 @@ var BarrelManager = class {
|
|
|
673
712
|
return map ? filteredFiles.map(map) : filteredFiles;
|
|
674
713
|
}
|
|
675
714
|
};
|
|
715
|
+
_options = new WeakMap();
|
|
676
716
|
|
|
677
717
|
// src/FileManager.ts
|
|
678
|
-
var
|
|
679
|
-
|
|
680
|
-
#task;
|
|
681
|
-
#isWriting = false;
|
|
682
|
-
/**
|
|
683
|
-
* Timeout between writes
|
|
684
|
-
*/
|
|
685
|
-
#timeout = 0;
|
|
686
|
-
#queue;
|
|
718
|
+
var _cache, _task, _isWriting, _timeout, _queue2, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
719
|
+
var _FileManager = class _FileManager {
|
|
687
720
|
constructor(options) {
|
|
721
|
+
__privateAdd(this, _validate);
|
|
722
|
+
__privateAdd(this, _add);
|
|
723
|
+
__privateAdd(this, _addOrAppend);
|
|
724
|
+
__privateAdd(this, _cache, /* @__PURE__ */ new Map());
|
|
725
|
+
__privateAdd(this, _task, void 0);
|
|
726
|
+
__privateAdd(this, _isWriting, false);
|
|
727
|
+
/**
|
|
728
|
+
* Timeout between writes
|
|
729
|
+
*/
|
|
730
|
+
__privateAdd(this, _timeout, 0);
|
|
731
|
+
__privateAdd(this, _queue2, void 0);
|
|
688
732
|
if (options) {
|
|
689
|
-
this
|
|
690
|
-
this
|
|
691
|
-
this
|
|
733
|
+
__privateSet(this, _task, options.task);
|
|
734
|
+
__privateSet(this, _queue2, options.queue);
|
|
735
|
+
__privateSet(this, _timeout, options.timeout || 0);
|
|
692
736
|
}
|
|
693
737
|
return this;
|
|
694
738
|
}
|
|
695
739
|
get files() {
|
|
696
740
|
const files = [];
|
|
697
|
-
this
|
|
741
|
+
__privateGet(this, _cache).forEach((item) => {
|
|
698
742
|
files.push(...item.flat(1));
|
|
699
743
|
});
|
|
700
744
|
return files;
|
|
701
745
|
}
|
|
702
746
|
get isExecuting() {
|
|
703
|
-
return this
|
|
704
|
-
}
|
|
705
|
-
#validate(file) {
|
|
706
|
-
if (!file.validate) {
|
|
707
|
-
return;
|
|
708
|
-
}
|
|
709
|
-
if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
|
|
710
|
-
throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
|
|
711
|
-
}
|
|
747
|
+
return __privateGet(this, _queue2)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
|
|
712
748
|
}
|
|
713
749
|
async add(...files) {
|
|
714
750
|
const promises = files.map((file) => {
|
|
715
|
-
this
|
|
751
|
+
__privateMethod(this, _validate, validate_fn).call(this, file);
|
|
716
752
|
if (file.override) {
|
|
717
|
-
return this
|
|
753
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
718
754
|
}
|
|
719
|
-
return this
|
|
755
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
|
|
720
756
|
});
|
|
721
757
|
const resolvedFiles = await Promise.all(promises);
|
|
722
758
|
if (files.length > 1) {
|
|
@@ -724,36 +760,6 @@ var FileManager = class _FileManager {
|
|
|
724
760
|
}
|
|
725
761
|
return resolvedFiles[0];
|
|
726
762
|
}
|
|
727
|
-
async #add(file) {
|
|
728
|
-
const controller = new AbortController();
|
|
729
|
-
const resolvedFile = { id: crypto.randomUUID(), ...file };
|
|
730
|
-
this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
731
|
-
if (this.#queue) {
|
|
732
|
-
await this.#queue.run(
|
|
733
|
-
async () => {
|
|
734
|
-
return this.#task?.(resolvedFile);
|
|
735
|
-
},
|
|
736
|
-
{ controller }
|
|
737
|
-
);
|
|
738
|
-
}
|
|
739
|
-
return resolvedFile;
|
|
740
|
-
}
|
|
741
|
-
async #addOrAppend(file) {
|
|
742
|
-
const previousCaches = this.#cache.get(file.path);
|
|
743
|
-
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
744
|
-
if (previousCache) {
|
|
745
|
-
this.#cache.delete(previousCache.path);
|
|
746
|
-
return this.#add({
|
|
747
|
-
...file,
|
|
748
|
-
source: previousCache.source && file.source ? `${previousCache.source}
|
|
749
|
-
${file.source}` : "",
|
|
750
|
-
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
751
|
-
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
752
|
-
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
return this.#add(file);
|
|
756
|
-
}
|
|
757
763
|
async addIndexes({ root, extName = ".ts", meta, options = {} }) {
|
|
758
764
|
const barrelManager = new BarrelManager(options);
|
|
759
765
|
const files = barrelManager.getIndexes(root, extName);
|
|
@@ -762,7 +768,7 @@ ${file.source}` : "",
|
|
|
762
768
|
}
|
|
763
769
|
return await Promise.all(
|
|
764
770
|
files.map((file) => {
|
|
765
|
-
return this
|
|
771
|
+
return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
|
|
766
772
|
...file,
|
|
767
773
|
meta: meta ? meta : file.meta
|
|
768
774
|
});
|
|
@@ -771,29 +777,29 @@ ${file.source}` : "",
|
|
|
771
777
|
}
|
|
772
778
|
getCacheByUUID(UUID) {
|
|
773
779
|
let cache;
|
|
774
|
-
this
|
|
780
|
+
__privateGet(this, _cache).forEach((files) => {
|
|
775
781
|
cache = files.find((item) => item.id === UUID);
|
|
776
782
|
});
|
|
777
783
|
return cache;
|
|
778
784
|
}
|
|
779
785
|
get(path2) {
|
|
780
|
-
return this
|
|
786
|
+
return __privateGet(this, _cache).get(path2);
|
|
781
787
|
}
|
|
782
788
|
remove(path2) {
|
|
783
789
|
const cacheItem = this.get(path2);
|
|
784
790
|
if (!cacheItem) {
|
|
785
791
|
return;
|
|
786
792
|
}
|
|
787
|
-
this
|
|
793
|
+
__privateGet(this, _cache).delete(path2);
|
|
788
794
|
}
|
|
789
795
|
async write(...params) {
|
|
790
|
-
if (!this
|
|
791
|
-
this
|
|
796
|
+
if (!__privateGet(this, _isWriting)) {
|
|
797
|
+
__privateSet(this, _isWriting, true);
|
|
792
798
|
const text = await write(...params);
|
|
793
|
-
this
|
|
799
|
+
__privateSet(this, _isWriting, false);
|
|
794
800
|
return text;
|
|
795
801
|
}
|
|
796
|
-
await timeout(this
|
|
802
|
+
await timeout(__privateGet(this, _timeout));
|
|
797
803
|
return this.write(...params);
|
|
798
804
|
}
|
|
799
805
|
async read(...params) {
|
|
@@ -853,6 +859,54 @@ ${file.source}` : "",
|
|
|
853
859
|
return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
|
|
854
860
|
}
|
|
855
861
|
};
|
|
862
|
+
_cache = new WeakMap();
|
|
863
|
+
_task = new WeakMap();
|
|
864
|
+
_isWriting = new WeakMap();
|
|
865
|
+
_timeout = new WeakMap();
|
|
866
|
+
_queue2 = new WeakMap();
|
|
867
|
+
_validate = new WeakSet();
|
|
868
|
+
validate_fn = function(file) {
|
|
869
|
+
if (!file.validate) {
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
|
|
873
|
+
throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
_add = new WeakSet();
|
|
877
|
+
add_fn = async function(file) {
|
|
878
|
+
const controller = new AbortController();
|
|
879
|
+
const resolvedFile = { id: crypto.randomUUID(), ...file };
|
|
880
|
+
__privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
|
|
881
|
+
if (__privateGet(this, _queue2)) {
|
|
882
|
+
await __privateGet(this, _queue2).run(
|
|
883
|
+
async () => {
|
|
884
|
+
var _a;
|
|
885
|
+
return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
|
|
886
|
+
},
|
|
887
|
+
{ controller }
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
return resolvedFile;
|
|
891
|
+
};
|
|
892
|
+
_addOrAppend = new WeakSet();
|
|
893
|
+
addOrAppend_fn = async function(file) {
|
|
894
|
+
const previousCaches = __privateGet(this, _cache).get(file.path);
|
|
895
|
+
const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
|
|
896
|
+
if (previousCache) {
|
|
897
|
+
__privateGet(this, _cache).delete(previousCache.path);
|
|
898
|
+
return __privateMethod(this, _add, add_fn).call(this, {
|
|
899
|
+
...file,
|
|
900
|
+
source: previousCache.source && file.source ? `${previousCache.source}
|
|
901
|
+
${file.source}` : "",
|
|
902
|
+
imports: [...previousCache.imports || [], ...file.imports || []],
|
|
903
|
+
exports: [...previousCache.exports || [], ...file.exports || []],
|
|
904
|
+
env: { ...previousCache.env || {}, ...file.env || {} }
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
908
|
+
};
|
|
909
|
+
var FileManager = _FileManager;
|
|
856
910
|
function combineExports(exports) {
|
|
857
911
|
const combinedExports = orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
|
|
858
912
|
const name = curr.name;
|
|
@@ -951,10 +1005,8 @@ function getEnvSource(source, env) {
|
|
|
951
1005
|
|
|
952
1006
|
// src/utils/TreeNode.ts
|
|
953
1007
|
var TreeNode = class _TreeNode {
|
|
954
|
-
data;
|
|
955
|
-
parent;
|
|
956
|
-
children = [];
|
|
957
1008
|
constructor(data, parent) {
|
|
1009
|
+
this.children = [];
|
|
958
1010
|
this.data = data;
|
|
959
1011
|
this.parent = parent;
|
|
960
1012
|
return this;
|
|
@@ -1058,7 +1110,6 @@ function setUniqueName(originalName, data) {
|
|
|
1058
1110
|
return originalName;
|
|
1059
1111
|
}
|
|
1060
1112
|
var URLPath = class {
|
|
1061
|
-
path;
|
|
1062
1113
|
constructor(path2) {
|
|
1063
1114
|
this.path = path2;
|
|
1064
1115
|
return this;
|