@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.js CHANGED
@@ -27,6 +27,36 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
27
27
  return require.apply(this, arguments);
28
28
  throw Error('Dynamic require of "' + x + '" is not supported');
29
29
  });
30
+ var __accessCheck = (obj, member, msg) => {
31
+ if (!member.has(obj))
32
+ throw TypeError("Cannot " + msg);
33
+ };
34
+ var __privateGet = (obj, member, getter) => {
35
+ __accessCheck(obj, member, "read from private field");
36
+ return getter ? getter.call(obj) : member.get(obj);
37
+ };
38
+ var __privateAdd = (obj, member, value) => {
39
+ if (member.has(obj))
40
+ throw TypeError("Cannot add the same private member more than once");
41
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
42
+ };
43
+ var __privateSet = (obj, member, value, setter) => {
44
+ __accessCheck(obj, member, "write to private field");
45
+ setter ? setter.call(obj, value) : member.set(obj, value);
46
+ return value;
47
+ };
48
+ var __privateWrapper = (obj, member, setter, getter) => ({
49
+ set _(value) {
50
+ __privateSet(obj, member, value, setter);
51
+ },
52
+ get _() {
53
+ return __privateGet(obj, member, getter);
54
+ }
55
+ });
56
+ var __privateMethod = (obj, member, method) => {
57
+ __accessCheck(obj, member, "access private method");
58
+ return method;
59
+ };
30
60
  async function clean(path3) {
31
61
  return remove(path3);
32
62
  }
@@ -125,7 +155,6 @@ async function read(path3) {
125
155
  return reader(path3);
126
156
  }
127
157
  var URLPath = class {
128
- path;
129
158
  constructor(path3) {
130
159
  this.path = path3;
131
160
  return this;
@@ -476,10 +505,8 @@ async function write(data, path3) {
476
505
  return writer(path3, data.trim());
477
506
  }
478
507
  var TreeNode = class _TreeNode {
479
- data;
480
- parent;
481
- children = [];
482
508
  constructor(data, parent) {
509
+ this.children = [];
483
510
  this.data = data;
484
511
  this.parent = parent;
485
512
  return this;
@@ -564,14 +591,15 @@ var TreeNode = class _TreeNode {
564
591
  };
565
592
 
566
593
  // src/BarrelManager.ts
594
+ var _options;
567
595
  var BarrelManager = class {
568
- #options = {};
569
596
  constructor(options = {}) {
570
- this.#options = options;
597
+ __privateAdd(this, _options, {});
598
+ __privateSet(this, _options, options);
571
599
  return this;
572
600
  }
573
601
  getIndexes(root, extName) {
574
- const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = this.#options;
602
+ const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = __privateGet(this, _options);
575
603
  const extMapper = {
576
604
  ".ts": {
577
605
  extensions: /\.ts/,
@@ -640,50 +668,47 @@ var BarrelManager = class {
640
668
  return map ? filteredFiles.map(map) : filteredFiles;
641
669
  }
642
670
  };
671
+ _options = new WeakMap();
643
672
 
644
673
  // src/FileManager.ts
645
- var FileManager = class _FileManager {
646
- #cache = /* @__PURE__ */ new Map();
647
- #task;
648
- #isWriting = false;
649
- /**
650
- * Timeout between writes
651
- */
652
- #timeout = 0;
653
- #queue;
674
+ var _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
675
+ var _FileManager = class _FileManager {
654
676
  constructor(options) {
677
+ __privateAdd(this, _validate);
678
+ __privateAdd(this, _add);
679
+ __privateAdd(this, _addOrAppend);
680
+ __privateAdd(this, _cache, /* @__PURE__ */ new Map());
681
+ __privateAdd(this, _task, void 0);
682
+ __privateAdd(this, _isWriting, false);
683
+ /**
684
+ * Timeout between writes
685
+ */
686
+ __privateAdd(this, _timeout, 0);
687
+ __privateAdd(this, _queue, void 0);
655
688
  if (options) {
656
- this.#task = options.task;
657
- this.#queue = options.queue;
658
- this.#timeout = options.timeout || 0;
689
+ __privateSet(this, _task, options.task);
690
+ __privateSet(this, _queue, options.queue);
691
+ __privateSet(this, _timeout, options.timeout || 0);
659
692
  }
660
693
  return this;
661
694
  }
662
695
  get files() {
663
696
  const files = [];
664
- this.#cache.forEach((item) => {
697
+ __privateGet(this, _cache).forEach((item) => {
665
698
  files.push(...item.flat(1));
666
699
  });
667
700
  return files;
668
701
  }
669
702
  get isExecuting() {
670
- return this.#queue?.hasJobs ?? this.#isWriting ?? false;
671
- }
672
- #validate(file) {
673
- if (!file.validate) {
674
- return;
675
- }
676
- if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
677
- throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
678
- }
703
+ return __privateGet(this, _queue)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
679
704
  }
680
705
  async add(...files) {
681
706
  const promises = files.map((file) => {
682
- this.#validate(file);
707
+ __privateMethod(this, _validate, validate_fn).call(this, file);
683
708
  if (file.override) {
684
- return this.#add(file);
709
+ return __privateMethod(this, _add, add_fn).call(this, file);
685
710
  }
686
- return this.#addOrAppend(file);
711
+ return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
687
712
  });
688
713
  const resolvedFiles = await Promise.all(promises);
689
714
  if (files.length > 1) {
@@ -691,36 +716,6 @@ var FileManager = class _FileManager {
691
716
  }
692
717
  return resolvedFiles[0];
693
718
  }
694
- async #add(file) {
695
- const controller = new AbortController();
696
- const resolvedFile = { id: crypto2.randomUUID(), ...file };
697
- this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
698
- if (this.#queue) {
699
- await this.#queue.run(
700
- async () => {
701
- return this.#task?.(resolvedFile);
702
- },
703
- { controller }
704
- );
705
- }
706
- return resolvedFile;
707
- }
708
- async #addOrAppend(file) {
709
- const previousCaches = this.#cache.get(file.path);
710
- const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
711
- if (previousCache) {
712
- this.#cache.delete(previousCache.path);
713
- return this.#add({
714
- ...file,
715
- source: previousCache.source && file.source ? `${previousCache.source}
716
- ${file.source}` : "",
717
- imports: [...previousCache.imports || [], ...file.imports || []],
718
- exports: [...previousCache.exports || [], ...file.exports || []],
719
- env: { ...previousCache.env || {}, ...file.env || {} }
720
- });
721
- }
722
- return this.#add(file);
723
- }
724
719
  async addIndexes({ root, extName = ".ts", meta, options = {} }) {
725
720
  const barrelManager = new BarrelManager(options);
726
721
  const files = barrelManager.getIndexes(root, extName);
@@ -729,7 +724,7 @@ ${file.source}` : "",
729
724
  }
730
725
  return await Promise.all(
731
726
  files.map((file) => {
732
- return this.#addOrAppend({
727
+ return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
733
728
  ...file,
734
729
  meta: meta ? meta : file.meta
735
730
  });
@@ -738,29 +733,29 @@ ${file.source}` : "",
738
733
  }
739
734
  getCacheByUUID(UUID) {
740
735
  let cache;
741
- this.#cache.forEach((files) => {
736
+ __privateGet(this, _cache).forEach((files) => {
742
737
  cache = files.find((item) => item.id === UUID);
743
738
  });
744
739
  return cache;
745
740
  }
746
741
  get(path3) {
747
- return this.#cache.get(path3);
742
+ return __privateGet(this, _cache).get(path3);
748
743
  }
749
744
  remove(path3) {
750
745
  const cacheItem = this.get(path3);
751
746
  if (!cacheItem) {
752
747
  return;
753
748
  }
754
- this.#cache.delete(path3);
749
+ __privateGet(this, _cache).delete(path3);
755
750
  }
756
751
  async write(...params) {
757
- if (!this.#isWriting) {
758
- this.#isWriting = true;
752
+ if (!__privateGet(this, _isWriting)) {
753
+ __privateSet(this, _isWriting, true);
759
754
  const text = await write(...params);
760
- this.#isWriting = false;
755
+ __privateSet(this, _isWriting, false);
761
756
  return text;
762
757
  }
763
- await timeout(this.#timeout);
758
+ await timeout(__privateGet(this, _timeout));
764
759
  return this.write(...params);
765
760
  }
766
761
  async read(...params) {
@@ -820,6 +815,54 @@ ${file.source}` : "",
820
815
  return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
821
816
  }
822
817
  };
818
+ _cache = new WeakMap();
819
+ _task = new WeakMap();
820
+ _isWriting = new WeakMap();
821
+ _timeout = new WeakMap();
822
+ _queue = new WeakMap();
823
+ _validate = new WeakSet();
824
+ validate_fn = function(file) {
825
+ if (!file.validate) {
826
+ return;
827
+ }
828
+ if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
829
+ throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
830
+ }
831
+ };
832
+ _add = new WeakSet();
833
+ add_fn = async function(file) {
834
+ const controller = new AbortController();
835
+ const resolvedFile = { id: crypto2.randomUUID(), ...file };
836
+ __privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
837
+ if (__privateGet(this, _queue)) {
838
+ await __privateGet(this, _queue).run(
839
+ async () => {
840
+ var _a;
841
+ return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
842
+ },
843
+ { controller }
844
+ );
845
+ }
846
+ return resolvedFile;
847
+ };
848
+ _addOrAppend = new WeakSet();
849
+ addOrAppend_fn = async function(file) {
850
+ const previousCaches = __privateGet(this, _cache).get(file.path);
851
+ const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
852
+ if (previousCache) {
853
+ __privateGet(this, _cache).delete(previousCache.path);
854
+ return __privateMethod(this, _add, add_fn).call(this, {
855
+ ...file,
856
+ source: previousCache.source && file.source ? `${previousCache.source}
857
+ ${file.source}` : "",
858
+ imports: [...previousCache.imports || [], ...file.imports || []],
859
+ exports: [...previousCache.exports || [], ...file.exports || []],
860
+ env: { ...previousCache.env || {}, ...file.env || {} }
861
+ });
862
+ }
863
+ return __privateMethod(this, _add, add_fn).call(this, file);
864
+ };
865
+ var FileManager = _FileManager;
823
866
  function combineExports(exports) {
824
867
  const combinedExports = orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
825
868
  const name = curr.name;
@@ -915,86 +958,95 @@ function getEnvSource(source, env) {
915
958
  return prev;
916
959
  }, source);
917
960
  }
961
+ var _emitter;
918
962
  var EventEmitter = class {
919
963
  constructor() {
920
- this.#emitter.setMaxListeners(100);
964
+ __privateAdd(this, _emitter, new EventEmitter$1());
965
+ __privateGet(this, _emitter).setMaxListeners(100);
921
966
  }
922
- #emitter = new EventEmitter$1();
923
967
  emit(eventName, ...eventArg) {
924
- this.#emitter.emit(eventName, ...eventArg);
968
+ __privateGet(this, _emitter).emit(eventName, ...eventArg);
925
969
  }
926
970
  on(eventName, handler) {
927
- this.#emitter.on(eventName, handler);
971
+ __privateGet(this, _emitter).on(eventName, handler);
928
972
  }
929
973
  off(eventName, handler) {
930
- this.#emitter.off(eventName, handler);
974
+ __privateGet(this, _emitter).off(eventName, handler);
931
975
  }
932
976
  removeAll() {
933
- this.#emitter.removeAllListeners();
977
+ __privateGet(this, _emitter).removeAllListeners();
934
978
  }
935
979
  };
980
+ _emitter = new WeakMap();
981
+ var _queue2, _workerCount, _maxParallel, _debug, _work, work_fn;
936
982
  var Queue = class {
937
- #queue = [];
938
- eventEmitter = new EventEmitter();
939
- #workerCount = 0;
940
- #maxParallel;
941
- #debug = false;
942
983
  constructor(maxParallel, debug = false) {
943
- this.#maxParallel = maxParallel;
944
- this.#debug = debug;
984
+ __privateAdd(this, _work);
985
+ __privateAdd(this, _queue2, []);
986
+ this.eventEmitter = new EventEmitter();
987
+ __privateAdd(this, _workerCount, 0);
988
+ __privateAdd(this, _maxParallel, void 0);
989
+ __privateAdd(this, _debug, false);
990
+ __privateSet(this, _maxParallel, maxParallel);
991
+ __privateSet(this, _debug, debug);
945
992
  }
946
993
  run(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
947
994
  return new Promise((resolve2, reject) => {
948
995
  const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
949
996
  options.controller?.signal.addEventListener("abort", () => {
950
- this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
997
+ __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
951
998
  reject("Aborted");
952
999
  });
953
- this.#queue.push(item);
954
- this.#work();
1000
+ __privateGet(this, _queue2).push(item);
1001
+ __privateMethod(this, _work, work_fn).call(this);
955
1002
  });
956
1003
  }
957
1004
  runSync(job, options = { controller: new AbortController(), name: crypto2.randomUUID(), description: "" }) {
958
1005
  new Promise((resolve2, reject) => {
959
1006
  const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
960
1007
  options.controller?.signal.addEventListener("abort", () => {
961
- this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
1008
+ __privateSet(this, _queue2, __privateGet(this, _queue2).filter((queueItem) => queueItem.name === item.name));
962
1009
  });
963
- this.#queue.push(item);
964
- this.#work();
1010
+ __privateGet(this, _queue2).push(item);
1011
+ __privateMethod(this, _work, work_fn).call(this);
965
1012
  });
966
1013
  }
967
1014
  get hasJobs() {
968
- return this.#workerCount > 0 || this.#queue.length > 0;
1015
+ return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue2).length > 0;
969
1016
  }
970
1017
  get count() {
971
- return this.#workerCount;
1018
+ return __privateGet(this, _workerCount);
972
1019
  }
973
- #work() {
974
- if (this.#workerCount >= this.#maxParallel) {
975
- return;
976
- }
977
- this.#workerCount++;
978
- let entry;
979
- while (entry = this.#queue.shift()) {
980
- const { reject, resolve: resolve2, job, name, description } = entry;
981
- if (this.#debug) {
982
- performance.mark(name + "_start");
1020
+ };
1021
+ _queue2 = new WeakMap();
1022
+ _workerCount = new WeakMap();
1023
+ _maxParallel = new WeakMap();
1024
+ _debug = new WeakMap();
1025
+ _work = new WeakSet();
1026
+ work_fn = function() {
1027
+ if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
1028
+ return;
1029
+ }
1030
+ __privateWrapper(this, _workerCount)._++;
1031
+ let entry;
1032
+ while (entry = __privateGet(this, _queue2).shift()) {
1033
+ const { reject, resolve: resolve2, job, name, description } = entry;
1034
+ if (__privateGet(this, _debug)) {
1035
+ performance.mark(name + "_start");
1036
+ }
1037
+ job().then((result) => {
1038
+ this.eventEmitter.emit("jobDone", result);
1039
+ resolve2(result);
1040
+ if (__privateGet(this, _debug)) {
1041
+ performance.mark(name + "_stop");
1042
+ performance.measure(description, name + "_start", name + "_stop");
983
1043
  }
984
- job().then((result) => {
985
- this.eventEmitter.emit("jobDone", result);
986
- resolve2(result);
987
- if (this.#debug) {
988
- performance.mark(name + "_stop");
989
- performance.measure(description, name + "_start", name + "_stop");
990
- }
991
- }).catch((err) => {
992
- this.eventEmitter.emit("jobFailed", err);
993
- reject(err);
994
- });
995
- }
996
- this.#workerCount--;
1044
+ }).catch((err) => {
1045
+ this.eventEmitter.emit("jobFailed", err);
1046
+ reject(err);
1047
+ });
997
1048
  }
1049
+ __privateWrapper(this, _workerCount)._--;
998
1050
  };
999
1051
 
1000
1052
  // src/utils/uniqueName.ts
@@ -1010,8 +1062,6 @@ function setUniqueName(originalName, data) {
1010
1062
 
1011
1063
  // src/errors.ts
1012
1064
  var PluginError = class extends Error {
1013
- pluginManager;
1014
- cause;
1015
1065
  constructor(message, options) {
1016
1066
  super(message, { cause: options.cause });
1017
1067
  this.name = "PluginError";
@@ -1020,10 +1070,9 @@ var PluginError = class extends Error {
1020
1070
  }
1021
1071
  };
1022
1072
  var ParallelPluginError = class extends Error {
1023
- errors = [];
1024
- pluginManager;
1025
1073
  constructor(message, options) {
1026
1074
  super(message, { cause: options.cause });
1075
+ this.errors = [];
1027
1076
  this.name = "ParallelPluginError";
1028
1077
  this.errors = options.errors;
1029
1078
  this.pluginManager = options.pluginManager;
@@ -1044,7 +1093,6 @@ var ParallelPluginError = class extends Error {
1044
1093
  }
1045
1094
  };
1046
1095
  var SummaryError = class extends Error {
1047
- summary;
1048
1096
  constructor(message, options) {
1049
1097
  super(message, { cause: options.cause });
1050
1098
  this.name = "SummaryError";
@@ -1157,10 +1205,11 @@ function hookSeq(promises) {
1157
1205
  }
1158
1206
 
1159
1207
  // src/PromiseManager.ts
1208
+ var _options2;
1160
1209
  var PromiseManager = class {
1161
- #options = {};
1162
1210
  constructor(options = {}) {
1163
- this.#options = options;
1211
+ __privateAdd(this, _options2, {});
1212
+ __privateSet(this, _options2, options);
1164
1213
  return this;
1165
1214
  }
1166
1215
  run(strategy, promises) {
@@ -1170,6 +1219,7 @@ var PromiseManager = class {
1170
1219
  throw new Error(`${strategy} not implemented`);
1171
1220
  }
1172
1221
  };
1222
+ _options2 = new WeakMap();
1173
1223
  function isPromise(result) {
1174
1224
  return !!result && typeof result?.then === "function";
1175
1225
  }
@@ -1178,21 +1228,81 @@ function isPromiseRejectedResult(result) {
1178
1228
  }
1179
1229
 
1180
1230
  // src/PluginManager.ts
1231
+ var _core, _usedPluginNames, _promiseManager, _getSortedPlugins, getSortedPlugins_fn, _addExecutedToCallStack, addExecutedToCallStack_fn, _execute, execute_fn, _executeSync, executeSync_fn, _catcher, catcher_fn, _parse, parse_fn;
1181
1232
  var PluginManager = class {
1182
- plugins;
1183
- fileManager;
1184
- eventEmitter = new EventEmitter();
1185
- queue;
1186
- executed = [];
1187
- logger;
1188
- #core;
1189
- #usedPluginNames = {};
1190
- #promiseManager;
1191
1233
  constructor(config, options) {
1234
+ __privateAdd(this, _getSortedPlugins);
1235
+ __privateAdd(this, _addExecutedToCallStack);
1236
+ /**
1237
+ * Run an async plugin hook and return the result.
1238
+ * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
1239
+ * @param args Arguments passed to the plugin hook.
1240
+ * @param plugin The actual pluginObject to run.
1241
+ */
1242
+ // Implementation signature
1243
+ __privateAdd(this, _execute);
1244
+ /**
1245
+ * Run a sync plugin hook and return the result.
1246
+ * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
1247
+ * @param args Arguments passed to the plugin hook.
1248
+ * @param plugin The acutal plugin
1249
+ * @param replaceContext When passed, the plugin context can be overridden.
1250
+ */
1251
+ __privateAdd(this, _executeSync);
1252
+ __privateAdd(this, _catcher);
1253
+ __privateAdd(this, _parse);
1254
+ this.eventEmitter = new EventEmitter();
1255
+ this.executed = [];
1256
+ __privateAdd(this, _core, void 0);
1257
+ __privateAdd(this, _usedPluginNames, {});
1258
+ __privateAdd(this, _promiseManager, void 0);
1259
+ this.resolvePath = (params) => {
1260
+ if (params.pluginKey) {
1261
+ const paths = this.hookForPluginSync({
1262
+ pluginKey: params.pluginKey,
1263
+ hookName: "resolvePath",
1264
+ parameters: [params.baseName, params.directory, params.options]
1265
+ });
1266
+ if (paths && paths?.length > 1) {
1267
+ throw new Error(
1268
+ `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1269
+
1270
+ Paths: ${JSON.stringify(paths, void 0, 2)}`
1271
+ );
1272
+ }
1273
+ return paths?.at(0);
1274
+ }
1275
+ return this.hookFirstSync({
1276
+ hookName: "resolvePath",
1277
+ parameters: [params.baseName, params.directory, params.options]
1278
+ }).result;
1279
+ };
1280
+ this.resolveName = (params) => {
1281
+ if (params.pluginKey) {
1282
+ const names = this.hookForPluginSync({
1283
+ pluginKey: params.pluginKey,
1284
+ hookName: "resolveName",
1285
+ parameters: [params.name, params.type]
1286
+ });
1287
+ if (names && names?.length > 1) {
1288
+ throw new Error(
1289
+ `Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1290
+
1291
+ Names: ${JSON.stringify(names, void 0, 2)}`
1292
+ );
1293
+ }
1294
+ return transformReservedWord(names?.at(0) || params.name);
1295
+ }
1296
+ const name = this.hookFirstSync({
1297
+ hookName: "resolveName",
1298
+ parameters: [params.name, params.type]
1299
+ }).result;
1300
+ return transformReservedWord(name);
1301
+ };
1192
1302
  this.logger = options.logger;
1193
1303
  this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
1194
1304
  this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
1195
- this.#promiseManager = new PromiseManager();
1305
+ __privateSet(this, _promiseManager, new PromiseManager());
1196
1306
  const plugins = config.plugins || [];
1197
1307
  const core = definePlugin({
1198
1308
  config,
@@ -1201,57 +1311,14 @@ var PluginManager = class {
1201
1311
  fileManager: this.fileManager,
1202
1312
  resolvePath: this.resolvePath.bind(this),
1203
1313
  resolveName: this.resolveName.bind(this),
1204
- getPlugins: this.#getSortedPlugins.bind(this)
1314
+ getPlugins: __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).bind(this)
1205
1315
  });
1206
- this.#core = this.#parse(core, this, core.api.call(null));
1207
- this.plugins = [this.#core, ...plugins].map((plugin) => {
1208
- return this.#parse(plugin, this, this.#core.api);
1316
+ __privateSet(this, _core, __privateMethod(this, _parse, parse_fn).call(this, core, this, core.api.call(null)));
1317
+ this.plugins = [__privateGet(this, _core), ...plugins].map((plugin) => {
1318
+ return __privateMethod(this, _parse, parse_fn).call(this, plugin, this, __privateGet(this, _core).api);
1209
1319
  });
1210
1320
  return this;
1211
1321
  }
1212
- resolvePath = (params) => {
1213
- if (params.pluginKey) {
1214
- const paths = this.hookForPluginSync({
1215
- pluginKey: params.pluginKey,
1216
- hookName: "resolvePath",
1217
- parameters: [params.baseName, params.directory, params.options]
1218
- });
1219
- if (paths && paths?.length > 1) {
1220
- throw new Error(
1221
- `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1222
-
1223
- Paths: ${JSON.stringify(paths, void 0, 2)}`
1224
- );
1225
- }
1226
- return paths?.at(0);
1227
- }
1228
- return this.hookFirstSync({
1229
- hookName: "resolvePath",
1230
- parameters: [params.baseName, params.directory, params.options]
1231
- }).result;
1232
- };
1233
- resolveName = (params) => {
1234
- if (params.pluginKey) {
1235
- const names = this.hookForPluginSync({
1236
- pluginKey: params.pluginKey,
1237
- hookName: "resolveName",
1238
- parameters: [params.name, params.type]
1239
- });
1240
- if (names && names?.length > 1) {
1241
- throw new Error(
1242
- `Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
1243
-
1244
- Names: ${JSON.stringify(names, void 0, 2)}`
1245
- );
1246
- }
1247
- return transformReservedWord(names?.at(0) || params.name);
1248
- }
1249
- const name = this.hookFirstSync({
1250
- hookName: "resolveName",
1251
- parameters: [params.name, params.type]
1252
- }).result;
1253
- return transformReservedWord(name);
1254
- };
1255
1322
  on(eventName, handler) {
1256
1323
  this.eventEmitter.on(eventName, handler);
1257
1324
  }
@@ -1265,7 +1332,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1265
1332
  }) {
1266
1333
  const plugins = this.getPluginsByKey(hookName, pluginKey);
1267
1334
  const promises = plugins.map((plugin) => {
1268
- return this.#execute({
1335
+ return __privateMethod(this, _execute, execute_fn).call(this, {
1269
1336
  strategy: "hookFirst",
1270
1337
  hookName,
1271
1338
  parameters,
@@ -1281,7 +1348,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1281
1348
  }) {
1282
1349
  const plugins = this.getPluginsByKey(hookName, pluginKey);
1283
1350
  return plugins.map((plugin) => {
1284
- return this.#executeSync({
1351
+ return __privateMethod(this, _executeSync, executeSync_fn).call(this, {
1285
1352
  strategy: "hookFirst",
1286
1353
  hookName,
1287
1354
  parameters,
@@ -1298,7 +1365,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1298
1365
  skipped
1299
1366
  }) {
1300
1367
  let promise = Promise.resolve(null);
1301
- for (const plugin of this.#getSortedPlugins()) {
1368
+ for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
1302
1369
  if (skipped && skipped.has(plugin)) {
1303
1370
  continue;
1304
1371
  }
@@ -1306,7 +1373,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1306
1373
  if (parseResult?.result != null) {
1307
1374
  return parseResult;
1308
1375
  }
1309
- const value = await this.#execute({
1376
+ const value = await __privateMethod(this, _execute, execute_fn).call(this, {
1310
1377
  strategy: "hookFirst",
1311
1378
  hookName,
1312
1379
  parameters,
@@ -1331,12 +1398,12 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1331
1398
  skipped
1332
1399
  }) {
1333
1400
  let parseResult = null;
1334
- for (const plugin of this.#getSortedPlugins()) {
1401
+ for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
1335
1402
  if (skipped && skipped.has(plugin)) {
1336
1403
  continue;
1337
1404
  }
1338
1405
  parseResult = {
1339
- result: this.#executeSync({
1406
+ result: __privateMethod(this, _executeSync, executeSync_fn).call(this, {
1340
1407
  strategy: "hookFirst",
1341
1408
  hookName,
1342
1409
  parameters,
@@ -1358,8 +1425,8 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1358
1425
  parameters
1359
1426
  }) {
1360
1427
  const parallelPromises = [];
1361
- for (const plugin of this.#getSortedPlugins()) {
1362
- const promise = this.#execute({ strategy: "hookParallel", hookName, parameters, plugin });
1428
+ for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
1429
+ const promise = __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
1363
1430
  if (promise) {
1364
1431
  parallelPromises.push(promise);
1365
1432
  }
@@ -1386,16 +1453,16 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1386
1453
  }) {
1387
1454
  const [argument0, ...rest] = parameters;
1388
1455
  let promise = Promise.resolve(argument0);
1389
- for (const plugin of this.#getSortedPlugins()) {
1456
+ for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
1390
1457
  promise = promise.then((arg0) => {
1391
- const value = this.#execute({
1458
+ const value = __privateMethod(this, _execute, execute_fn).call(this, {
1392
1459
  strategy: "hookReduceArg0",
1393
1460
  hookName,
1394
1461
  parameters: [arg0, ...rest],
1395
1462
  plugin
1396
1463
  });
1397
1464
  return value;
1398
- }).then((result) => reduce.call(this.#core.api, argument0, result, plugin));
1465
+ }).then((result) => reduce.call(__privateGet(this, _core).api, argument0, result, plugin));
1399
1466
  }
1400
1467
  return promise;
1401
1468
  }
@@ -1403,28 +1470,15 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1403
1470
  * Chains plugins
1404
1471
  */
1405
1472
  hookSeq({ hookName, parameters }) {
1406
- const promises = this.#getSortedPlugins().map((plugin) => {
1407
- return () => this.#execute({
1473
+ const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
1474
+ return () => __privateMethod(this, _execute, execute_fn).call(this, {
1408
1475
  strategy: "hookSeq",
1409
1476
  hookName,
1410
1477
  parameters,
1411
1478
  plugin
1412
1479
  });
1413
1480
  });
1414
- return this.#promiseManager.run("seq", promises);
1415
- }
1416
- #getSortedPlugins(hookName) {
1417
- const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
1418
- if (hookName) {
1419
- if (this.logger.logLevel === "info") {
1420
- const containsHookName = plugins.some((item) => item[hookName]);
1421
- if (!containsHookName) {
1422
- this.logger.warn(`No hook ${hookName} found`);
1423
- }
1424
- }
1425
- return plugins.filter((item) => item[hookName]);
1426
- }
1427
- return plugins;
1481
+ return __privateGet(this, _promiseManager).run("seq", promises);
1428
1482
  }
1429
1483
  getPluginsByKey(hookName, pluginKey) {
1430
1484
  const plugins = [...this.plugins];
@@ -1452,129 +1506,6 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1452
1506
  }
1453
1507
  return pluginByPluginName;
1454
1508
  }
1455
- #addExecutedToCallStack(executer) {
1456
- if (executer) {
1457
- this.eventEmitter.emit("executed", executer);
1458
- this.executed.push(executer);
1459
- }
1460
- }
1461
- /**
1462
- * Run an async plugin hook and return the result.
1463
- * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
1464
- * @param args Arguments passed to the plugin hook.
1465
- * @param plugin The actual pluginObject to run.
1466
- */
1467
- // Implementation signature
1468
- #execute({
1469
- strategy,
1470
- hookName,
1471
- parameters,
1472
- plugin
1473
- }) {
1474
- const hook = plugin[hookName];
1475
- let output;
1476
- if (!hook) {
1477
- return null;
1478
- }
1479
- this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1480
- const task = Promise.resolve().then(() => {
1481
- if (typeof hook === "function") {
1482
- const possiblePromiseResult = hook.apply({ ...this.#core.api, plugin }, parameters);
1483
- if (isPromise(possiblePromiseResult)) {
1484
- return Promise.resolve(possiblePromiseResult);
1485
- }
1486
- return possiblePromiseResult;
1487
- }
1488
- return hook;
1489
- }).then((result) => {
1490
- output = result;
1491
- return result;
1492
- }).catch((e) => {
1493
- this.#catcher(e, plugin, hookName);
1494
- return null;
1495
- }).finally(() => {
1496
- this.#addExecutedToCallStack({
1497
- parameters,
1498
- output,
1499
- strategy,
1500
- hookName,
1501
- plugin
1502
- });
1503
- });
1504
- return task;
1505
- }
1506
- /**
1507
- * Run a sync plugin hook and return the result.
1508
- * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
1509
- * @param args Arguments passed to the plugin hook.
1510
- * @param plugin The acutal plugin
1511
- * @param replaceContext When passed, the plugin context can be overridden.
1512
- */
1513
- #executeSync({
1514
- strategy,
1515
- hookName,
1516
- parameters,
1517
- plugin
1518
- }) {
1519
- const hook = plugin[hookName];
1520
- let output;
1521
- if (!hook) {
1522
- return null;
1523
- }
1524
- this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1525
- try {
1526
- if (typeof hook === "function") {
1527
- const fn = hook.apply({ ...this.#core.api, plugin }, parameters);
1528
- output = fn;
1529
- return fn;
1530
- }
1531
- output = hook;
1532
- return hook;
1533
- } catch (e) {
1534
- this.#catcher(e, plugin, hookName);
1535
- return null;
1536
- } finally {
1537
- this.#addExecutedToCallStack({
1538
- parameters,
1539
- output,
1540
- strategy,
1541
- hookName,
1542
- plugin
1543
- });
1544
- }
1545
- }
1546
- #catcher(e, plugin, hookName) {
1547
- const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
1548
- `;
1549
- const pluginError = new PluginError(text, { cause: e, pluginManager: this });
1550
- this.eventEmitter.emit("error", pluginError);
1551
- throw pluginError;
1552
- }
1553
- #parse(plugin, pluginManager, context) {
1554
- const usedPluginNames = pluginManager.#usedPluginNames;
1555
- setUniqueName(plugin.name, usedPluginNames);
1556
- const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
1557
- if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
1558
- pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
1559
- }
1560
- if (!plugin.transform) {
1561
- plugin.transform = function transform(code) {
1562
- return code;
1563
- };
1564
- }
1565
- if (plugin.api && typeof plugin.api === "function") {
1566
- const api = plugin.api.call(context);
1567
- return {
1568
- ...plugin,
1569
- key,
1570
- api
1571
- };
1572
- }
1573
- return {
1574
- ...plugin,
1575
- key
1576
- };
1577
- }
1578
1509
  static getDependedPlugins(plugins, dependedPluginNames) {
1579
1510
  let pluginNames = [];
1580
1511
  if (typeof dependedPluginNames === "string") {
@@ -1595,6 +1526,137 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1595
1526
  return ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
1596
1527
  }
1597
1528
  };
1529
+ _core = new WeakMap();
1530
+ _usedPluginNames = new WeakMap();
1531
+ _promiseManager = new WeakMap();
1532
+ _getSortedPlugins = new WeakSet();
1533
+ getSortedPlugins_fn = function(hookName) {
1534
+ const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
1535
+ if (hookName) {
1536
+ if (this.logger.logLevel === "info") {
1537
+ const containsHookName = plugins.some((item) => item[hookName]);
1538
+ if (!containsHookName) {
1539
+ this.logger.warn(`No hook ${hookName} found`);
1540
+ }
1541
+ }
1542
+ return plugins.filter((item) => item[hookName]);
1543
+ }
1544
+ return plugins;
1545
+ };
1546
+ _addExecutedToCallStack = new WeakSet();
1547
+ addExecutedToCallStack_fn = function(executer) {
1548
+ if (executer) {
1549
+ this.eventEmitter.emit("executed", executer);
1550
+ this.executed.push(executer);
1551
+ }
1552
+ };
1553
+ _execute = new WeakSet();
1554
+ execute_fn = function({
1555
+ strategy,
1556
+ hookName,
1557
+ parameters,
1558
+ plugin
1559
+ }) {
1560
+ const hook = plugin[hookName];
1561
+ let output;
1562
+ if (!hook) {
1563
+ return null;
1564
+ }
1565
+ this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1566
+ const task = Promise.resolve().then(() => {
1567
+ if (typeof hook === "function") {
1568
+ const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
1569
+ if (isPromise(possiblePromiseResult)) {
1570
+ return Promise.resolve(possiblePromiseResult);
1571
+ }
1572
+ return possiblePromiseResult;
1573
+ }
1574
+ return hook;
1575
+ }).then((result) => {
1576
+ output = result;
1577
+ return result;
1578
+ }).catch((e) => {
1579
+ __privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
1580
+ return null;
1581
+ }).finally(() => {
1582
+ __privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
1583
+ parameters,
1584
+ output,
1585
+ strategy,
1586
+ hookName,
1587
+ plugin
1588
+ });
1589
+ });
1590
+ return task;
1591
+ };
1592
+ _executeSync = new WeakSet();
1593
+ executeSync_fn = function({
1594
+ strategy,
1595
+ hookName,
1596
+ parameters,
1597
+ plugin
1598
+ }) {
1599
+ const hook = plugin[hookName];
1600
+ let output;
1601
+ if (!hook) {
1602
+ return null;
1603
+ }
1604
+ this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1605
+ try {
1606
+ if (typeof hook === "function") {
1607
+ const fn = hook.apply({ ...__privateGet(this, _core).api, plugin }, parameters);
1608
+ output = fn;
1609
+ return fn;
1610
+ }
1611
+ output = hook;
1612
+ return hook;
1613
+ } catch (e) {
1614
+ __privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
1615
+ return null;
1616
+ } finally {
1617
+ __privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
1618
+ parameters,
1619
+ output,
1620
+ strategy,
1621
+ hookName,
1622
+ plugin
1623
+ });
1624
+ }
1625
+ };
1626
+ _catcher = new WeakSet();
1627
+ catcher_fn = function(e, plugin, hookName) {
1628
+ const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
1629
+ `;
1630
+ const pluginError = new PluginError(text, { cause: e, pluginManager: this });
1631
+ this.eventEmitter.emit("error", pluginError);
1632
+ throw pluginError;
1633
+ };
1634
+ _parse = new WeakSet();
1635
+ parse_fn = function(plugin, pluginManager, context) {
1636
+ const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
1637
+ setUniqueName(plugin.name, usedPluginNames);
1638
+ const key = plugin.key || [plugin.kind, plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
1639
+ if (plugin.name !== "core" && usedPluginNames[plugin.name] >= 2) {
1640
+ pluginManager.logger.warn("Using multiple of the same plugin is an experimental feature");
1641
+ }
1642
+ if (!plugin.transform) {
1643
+ plugin.transform = function transform(code) {
1644
+ return code;
1645
+ };
1646
+ }
1647
+ if (plugin.api && typeof plugin.api === "function") {
1648
+ const api = plugin.api.call(context);
1649
+ return {
1650
+ ...plugin,
1651
+ key,
1652
+ api
1653
+ };
1654
+ }
1655
+ return {
1656
+ ...plugin,
1657
+ key
1658
+ };
1659
+ };
1598
1660
 
1599
1661
  // src/build.ts
1600
1662
  async function transformReducer(_previousCode, result, _plugin) {
@@ -1709,54 +1771,57 @@ ${code}`);
1709
1771
  }
1710
1772
 
1711
1773
  // src/Generator.ts
1774
+ var _options3, _context;
1712
1775
  var Generator = class {
1713
- #options = {};
1714
- #context = {};
1715
1776
  constructor(options, context) {
1777
+ __privateAdd(this, _options3, {});
1778
+ __privateAdd(this, _context, {});
1716
1779
  if (context) {
1717
- this.#context = context;
1780
+ __privateSet(this, _context, context);
1718
1781
  }
1719
1782
  if (options) {
1720
- this.#options = options;
1783
+ __privateSet(this, _options3, options);
1721
1784
  }
1722
1785
  return this;
1723
1786
  }
1724
1787
  get options() {
1725
- return this.#options;
1788
+ return __privateGet(this, _options3);
1726
1789
  }
1727
1790
  get context() {
1728
- return this.#context;
1791
+ return __privateGet(this, _context);
1729
1792
  }
1730
1793
  set options(options) {
1731
- this.#options = { ...this.#options, ...options };
1794
+ __privateSet(this, _options3, { ...__privateGet(this, _options3), ...options });
1732
1795
  }
1733
1796
  };
1734
- var PackageManager = class _PackageManager {
1735
- static #cache = {};
1736
- #cwd;
1737
- #SLASHES = /* @__PURE__ */ new Set(["/", "\\"]);
1797
+ _options3 = new WeakMap();
1798
+ _context = new WeakMap();
1799
+ var _cache2, _cwd, _SLASHES;
1800
+ var _PackageManager = class _PackageManager {
1738
1801
  constructor(workspace) {
1802
+ __privateAdd(this, _cwd, void 0);
1803
+ __privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
1739
1804
  if (workspace) {
1740
- this.#cwd = workspace;
1805
+ __privateSet(this, _cwd, workspace);
1741
1806
  }
1742
1807
  return this;
1743
1808
  }
1744
1809
  set workspace(workspace) {
1745
- this.#cwd = workspace;
1810
+ __privateSet(this, _cwd, workspace);
1746
1811
  }
1747
1812
  get workspace() {
1748
- return this.#cwd;
1813
+ return __privateGet(this, _cwd);
1749
1814
  }
1750
1815
  normalizeDirectory(directory) {
1751
- if (!this.#SLASHES.has(directory[directory.length - 1])) {
1816
+ if (!__privateGet(this, _SLASHES).has(directory[directory.length - 1])) {
1752
1817
  return `${directory}/`;
1753
1818
  }
1754
1819
  return directory;
1755
1820
  }
1756
1821
  getLocation(path3) {
1757
1822
  let location = path3;
1758
- if (this.#cwd) {
1759
- const require2 = mod.createRequire(this.normalizeDirectory(this.#cwd));
1823
+ if (__privateGet(this, _cwd)) {
1824
+ const require2 = mod.createRequire(this.normalizeDirectory(__privateGet(this, _cwd)));
1760
1825
  location = require2.resolve(path3);
1761
1826
  }
1762
1827
  return location;
@@ -1776,7 +1841,7 @@ var PackageManager = class _PackageManager {
1776
1841
  }
1777
1842
  async getPackageJSON() {
1778
1843
  const pkgPath = await findUp(["package.json"], {
1779
- cwd: this.#cwd
1844
+ cwd: __privateGet(this, _cwd)
1780
1845
  });
1781
1846
  if (!pkgPath) {
1782
1847
  return void 0;
@@ -1785,7 +1850,7 @@ var PackageManager = class _PackageManager {
1785
1850
  }
1786
1851
  getPackageJSONSync() {
1787
1852
  const pkgPath = findUpSync(["package.json"], {
1788
- cwd: this.#cwd
1853
+ cwd: __privateGet(this, _cwd)
1789
1854
  });
1790
1855
  if (!pkgPath) {
1791
1856
  return void 0;
@@ -1793,11 +1858,11 @@ var PackageManager = class _PackageManager {
1793
1858
  return __require(pkgPath);
1794
1859
  }
1795
1860
  static setVersion(dependency, version) {
1796
- _PackageManager.#cache[dependency] = version;
1861
+ __privateGet(_PackageManager, _cache2)[dependency] = version;
1797
1862
  }
1798
1863
  async getVersion(dependency) {
1799
- if (_PackageManager.#cache[dependency]) {
1800
- return _PackageManager.#cache[dependency];
1864
+ if (__privateGet(_PackageManager, _cache2)[dependency]) {
1865
+ return __privateGet(_PackageManager, _cache2)[dependency];
1801
1866
  }
1802
1867
  const packageJSON = await this.getPackageJSON();
1803
1868
  if (!packageJSON) {
@@ -1806,8 +1871,8 @@ var PackageManager = class _PackageManager {
1806
1871
  return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
1807
1872
  }
1808
1873
  getVersionSync(dependency) {
1809
- if (_PackageManager.#cache[dependency]) {
1810
- return _PackageManager.#cache[dependency];
1874
+ if (__privateGet(_PackageManager, _cache2)[dependency]) {
1875
+ return __privateGet(_PackageManager, _cache2)[dependency];
1811
1876
  }
1812
1877
  const packageJSON = this.getPackageJSONSync();
1813
1878
  if (!packageJSON) {
@@ -1838,6 +1903,11 @@ var PackageManager = class _PackageManager {
1838
1903
  return satisfies(semVer, version);
1839
1904
  }
1840
1905
  };
1906
+ _cache2 = new WeakMap();
1907
+ _cwd = new WeakMap();
1908
+ _SLASHES = new WeakMap();
1909
+ __privateAdd(_PackageManager, _cache2, {});
1910
+ var PackageManager = _PackageManager;
1841
1911
 
1842
1912
  // src/SchemaGenerator.ts
1843
1913
  var SchemaGenerator = class extends Generator {