@kubb/core 1.13.0 → 1.14.0-canary.20231020T164632

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
@@ -194,61 +194,61 @@ async function timeout(ms) {
194
194
  });
195
195
  }
196
196
  var Queue = class {
197
- queue = [];
198
- workerCount = 0;
199
- maxParallel;
200
- debug = false;
197
+ #queue = [];
198
+ #workerCount = 0;
199
+ #maxParallel;
200
+ #debug = false;
201
201
  constructor(maxParallel, debug = false) {
202
- this.maxParallel = maxParallel;
203
- this.debug = debug;
202
+ this.#maxParallel = maxParallel;
203
+ this.#debug = debug;
204
204
  }
205
205
  run(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
206
206
  return new Promise((resolve, reject) => {
207
207
  const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
208
208
  options.controller?.signal.addEventListener("abort", () => {
209
- this.queue = this.queue.filter((queueItem) => queueItem.name === item.name);
209
+ this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
210
210
  reject("Aborted");
211
211
  });
212
- this.queue.push(item);
213
- this.work();
212
+ this.#queue.push(item);
213
+ this.#work();
214
214
  });
215
215
  }
216
216
  runSync(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
217
217
  new Promise((resolve, reject) => {
218
218
  const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
219
219
  options.controller?.signal.addEventListener("abort", () => {
220
- this.queue = this.queue.filter((queueItem) => queueItem.name === item.name);
220
+ this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
221
221
  });
222
- this.queue.push(item);
223
- this.work();
222
+ this.#queue.push(item);
223
+ this.#work();
224
224
  });
225
225
  }
226
226
  get hasJobs() {
227
- return this.workerCount > 0 || this.queue.length > 0;
227
+ return this.#workerCount > 0 || this.#queue.length > 0;
228
228
  }
229
229
  get count() {
230
- return this.workerCount;
230
+ return this.#workerCount;
231
231
  }
232
- work() {
233
- if (this.workerCount >= this.maxParallel) {
232
+ #work() {
233
+ if (this.#workerCount >= this.#maxParallel) {
234
234
  return;
235
235
  }
236
- this.workerCount++;
236
+ this.#workerCount++;
237
237
  let entry;
238
- while (entry = this.queue.shift()) {
238
+ while (entry = this.#queue.shift()) {
239
239
  const { reject, resolve, job, name, description } = entry;
240
- if (this.debug) {
240
+ if (this.#debug) {
241
241
  performance.mark(name + "_start");
242
242
  }
243
243
  job().then((result) => {
244
244
  resolve(result);
245
- if (this.debug) {
245
+ if (this.#debug) {
246
246
  performance.mark(name + "_stop");
247
247
  performance.measure(description, name + "_start", name + "_stop");
248
248
  }
249
249
  }).catch((err) => reject(err));
250
250
  }
251
- this.workerCount--;
251
+ this.#workerCount--;
252
252
  }
253
253
  };
254
254
 
@@ -971,13 +971,13 @@ function getEnvSource(source, env) {
971
971
 
972
972
  // src/managers/fileManager/FileManager.ts
973
973
  var FileManager = class {
974
- cache = /* @__PURE__ */ new Map();
975
- task;
976
- queue;
974
+ #cache = /* @__PURE__ */ new Map();
975
+ #task;
976
+ #queue;
977
977
  constructor(options) {
978
978
  if (options) {
979
- this.task = options.task;
980
- this.queue = options.queue;
979
+ this.#task = options.task;
980
+ this.#queue = options.queue;
981
981
  }
982
982
  }
983
983
  get extensions() {
@@ -985,23 +985,23 @@ var FileManager = class {
985
985
  }
986
986
  get files() {
987
987
  const files = [];
988
- this.cache.forEach((item) => {
988
+ this.#cache.forEach((item) => {
989
989
  files.push(...item.flat(1));
990
990
  });
991
991
  return files;
992
992
  }
993
993
  get isExecuting() {
994
- return this.queue?.hasJobs ?? false;
994
+ return this.#queue?.hasJobs ?? false;
995
995
  }
996
996
  async add(file) {
997
997
  const controller = new AbortController();
998
998
  const resolvedFile = { id: crypto.randomUUID(), ...file };
999
- this.cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
1000
- if (this.queue) {
999
+ this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
1000
+ if (this.#queue) {
1001
1001
  try {
1002
- await this.queue.run(
1002
+ await this.#queue.run(
1003
1003
  async () => {
1004
- return this.task?.(resolvedFile);
1004
+ return this.#task?.(resolvedFile);
1005
1005
  },
1006
1006
  { controller }
1007
1007
  );
@@ -1012,10 +1012,10 @@ var FileManager = class {
1012
1012
  return resolvedFile;
1013
1013
  }
1014
1014
  addOrAppend(file) {
1015
- const previousCaches = this.cache.get(file.path);
1015
+ const previousCaches = this.#cache.get(file.path);
1016
1016
  const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
1017
1017
  if (previousCache) {
1018
- this.cache.delete(previousCache.path);
1018
+ this.#cache.delete(previousCache.path);
1019
1019
  return this.add({
1020
1020
  ...file,
1021
1021
  source: previousCache.source && file.source ? `${previousCache.source}
@@ -1027,38 +1027,38 @@ ${file.source}` : "",
1027
1027
  }
1028
1028
  return this.add(file);
1029
1029
  }
1030
- append(path, file) {
1031
- const previousFiles = this.cache.get(path) || [];
1032
- this.cache.set(path, [...previousFiles, file]);
1030
+ #append(path, file) {
1031
+ const previousFiles = this.#cache.get(path) || [];
1032
+ this.#cache.set(path, [...previousFiles, file]);
1033
1033
  }
1034
1034
  getCacheByUUID(UUID) {
1035
1035
  let cache;
1036
- this.cache.forEach((files) => {
1036
+ this.#cache.forEach((files) => {
1037
1037
  cache = files.find((item) => item.id === UUID);
1038
1038
  });
1039
1039
  return cache;
1040
1040
  }
1041
1041
  get(path) {
1042
- return this.cache.get(path);
1042
+ return this.#cache.get(path);
1043
1043
  }
1044
1044
  remove(path) {
1045
1045
  const cacheItem = this.get(path);
1046
1046
  if (!cacheItem) {
1047
1047
  return;
1048
1048
  }
1049
- this.cache.delete(path);
1049
+ this.#cache.delete(path);
1050
1050
  }
1051
1051
  async write(...params) {
1052
- if (this.queue) {
1053
- return this.queue.run(async () => {
1052
+ if (this.#queue) {
1053
+ return this.#queue.run(async () => {
1054
1054
  return write(...params);
1055
1055
  });
1056
1056
  }
1057
1057
  return write(...params);
1058
1058
  }
1059
1059
  async read(...params) {
1060
- if (this.queue) {
1061
- return this.queue.run(async () => {
1060
+ if (this.#queue) {
1061
+ return this.#queue.run(async () => {
1062
1062
  return read(...params);
1063
1063
  });
1064
1064
  }
@@ -1122,20 +1122,20 @@ var definePlugin = createPlugin((options) => {
1122
1122
  });
1123
1123
  var EventEmitter = class {
1124
1124
  constructor() {
1125
- this.emitter.setMaxListeners(100);
1125
+ this.#emitter.setMaxListeners(100);
1126
1126
  }
1127
- emitter = new EventEmitter$1();
1127
+ #emitter = new EventEmitter$1();
1128
1128
  emit(eventName, ...eventArg) {
1129
- this.emitter.emit(eventName, ...eventArg);
1129
+ this.#emitter.emit(eventName, ...eventArg);
1130
1130
  }
1131
1131
  on(eventName, handler) {
1132
- this.emitter.on(eventName, handler);
1132
+ this.#emitter.on(eventName, handler);
1133
1133
  }
1134
1134
  off(eventName, handler) {
1135
- this.emitter.off(eventName, handler);
1135
+ this.#emitter.off(eventName, handler);
1136
1136
  }
1137
1137
  removeAll() {
1138
- this.emitter.removeAllListeners();
1138
+ this.#emitter.removeAllListeners();
1139
1139
  }
1140
1140
  };
1141
1141
 
@@ -1208,7 +1208,7 @@ var PluginManager = class {
1208
1208
  queue;
1209
1209
  executed = [];
1210
1210
  logger;
1211
- core;
1211
+ #core;
1212
1212
  constructor(config, options) {
1213
1213
  this.logger = options.logger;
1214
1214
  this.queue = new Queue(100, options.debug);
@@ -1220,11 +1220,11 @@ var PluginManager = class {
1220
1220
  fileManager: this.fileManager,
1221
1221
  resolvePath: this.resolvePath.bind(this),
1222
1222
  resolveName: this.resolveName.bind(this),
1223
- getPlugins: this.getSortedPlugins.bind(this)
1223
+ getPlugins: this.#getSortedPlugins.bind(this)
1224
1224
  });
1225
- this.core = pluginParser(core, core.api.call(null));
1226
- this.plugins = [this.core, ...config.plugins || []].reduce((prev, plugin) => {
1227
- const convertedApi = pluginParser(plugin, this.core?.api);
1225
+ this.#core = pluginParser(core, core.api.call(null));
1226
+ this.plugins = [this.#core, ...config.plugins || []].reduce((prev, plugin) => {
1227
+ const convertedApi = pluginParser(plugin, this.#core?.api);
1228
1228
  if (convertedApi) {
1229
1229
  return [...prev, convertedApi];
1230
1230
  }
@@ -1272,7 +1272,7 @@ var PluginManager = class {
1272
1272
  parameters
1273
1273
  }) {
1274
1274
  const plugin = this.getPlugin(hookName, pluginName2);
1275
- return this.execute({
1275
+ return this.#execute({
1276
1276
  strategy: "hookFirst",
1277
1277
  hookName,
1278
1278
  parameters,
@@ -1285,7 +1285,7 @@ var PluginManager = class {
1285
1285
  parameters
1286
1286
  }) {
1287
1287
  const plugin = this.getPlugin(hookName, pluginName2);
1288
- return this.executeSync({
1288
+ return this.#executeSync({
1289
1289
  strategy: "hookFirst",
1290
1290
  hookName,
1291
1291
  parameters,
@@ -1302,7 +1302,7 @@ var PluginManager = class {
1302
1302
  skipped
1303
1303
  }) {
1304
1304
  let promise = Promise.resolve(null);
1305
- for (const plugin of this.getSortedPlugins()) {
1305
+ for (const plugin of this.#getSortedPlugins()) {
1306
1306
  if (skipped && skipped.has(plugin)) {
1307
1307
  continue;
1308
1308
  }
@@ -1310,7 +1310,7 @@ var PluginManager = class {
1310
1310
  if (parseResult?.result != null) {
1311
1311
  return parseResult;
1312
1312
  }
1313
- const value = await this.execute({
1313
+ const value = await this.#execute({
1314
1314
  strategy: "hookFirst",
1315
1315
  hookName,
1316
1316
  parameters,
@@ -1334,12 +1334,12 @@ var PluginManager = class {
1334
1334
  skipped
1335
1335
  }) {
1336
1336
  let parseResult = null;
1337
- for (const plugin of this.getSortedPlugins()) {
1337
+ for (const plugin of this.#getSortedPlugins()) {
1338
1338
  if (skipped && skipped.has(plugin)) {
1339
1339
  continue;
1340
1340
  }
1341
1341
  parseResult = {
1342
- result: this.executeSync({
1342
+ result: this.#executeSync({
1343
1343
  strategy: "hookFirst",
1344
1344
  hookName,
1345
1345
  parameters,
@@ -1362,8 +1362,8 @@ var PluginManager = class {
1362
1362
  parameters
1363
1363
  }) {
1364
1364
  const parallelPromises = [];
1365
- for (const plugin of this.getSortedPlugins()) {
1366
- const promise = this.execute({ strategy: "hookParallel", hookName, parameters, plugin });
1365
+ for (const plugin of this.#getSortedPlugins()) {
1366
+ const promise = this.#execute({ strategy: "hookParallel", hookName, parameters, plugin });
1367
1367
  if (promise) {
1368
1368
  parallelPromises.push(promise);
1369
1369
  }
@@ -1391,16 +1391,16 @@ var PluginManager = class {
1391
1391
  }) {
1392
1392
  const [argument0, ...rest] = parameters;
1393
1393
  let promise = Promise.resolve(argument0);
1394
- for (const plugin of this.getSortedPlugins()) {
1394
+ for (const plugin of this.#getSortedPlugins()) {
1395
1395
  promise = promise.then((arg0) => {
1396
- const value = this.execute({
1396
+ const value = this.#execute({
1397
1397
  strategy: "hookReduceArg0",
1398
1398
  hookName,
1399
1399
  parameters: [arg0, ...rest],
1400
1400
  plugin
1401
1401
  });
1402
1402
  return value;
1403
- }).then((result) => reduce.call(this.core.api, argument0, result, plugin));
1403
+ }).then((result) => reduce.call(this.#core.api, argument0, result, plugin));
1404
1404
  }
1405
1405
  return promise;
1406
1406
  }
@@ -1409,9 +1409,9 @@ var PluginManager = class {
1409
1409
  */
1410
1410
  hookSeq({ hookName, parameters }) {
1411
1411
  let promise = Promise.resolve();
1412
- for (const plugin of this.getSortedPlugins()) {
1412
+ for (const plugin of this.#getSortedPlugins()) {
1413
1413
  promise = promise.then(
1414
- () => this.execute({
1414
+ () => this.#execute({
1415
1415
  strategy: "hookSeq",
1416
1416
  hookName,
1417
1417
  parameters,
@@ -1421,7 +1421,7 @@ var PluginManager = class {
1421
1421
  }
1422
1422
  return promise.then(noReturn);
1423
1423
  }
1424
- getSortedPlugins(hookName) {
1424
+ #getSortedPlugins(hookName) {
1425
1425
  const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
1426
1426
  if (hookName) {
1427
1427
  return plugins.filter((item) => item[hookName]);
@@ -1432,11 +1432,11 @@ var PluginManager = class {
1432
1432
  const plugins = [...this.plugins];
1433
1433
  const pluginByPluginName = plugins.find((item) => item.name === pluginName2 && item[hookName]);
1434
1434
  if (!pluginByPluginName) {
1435
- return this.core;
1435
+ return this.#core;
1436
1436
  }
1437
1437
  return pluginByPluginName;
1438
1438
  }
1439
- addExecutedToCallStack(executer) {
1439
+ #addExecutedToCallStack(executer) {
1440
1440
  if (executer) {
1441
1441
  this.eventEmitter.emit("execute", executer);
1442
1442
  this.executed.push(executer);
@@ -1449,7 +1449,7 @@ var PluginManager = class {
1449
1449
  * @param plugin The actual pluginObject to run.
1450
1450
  */
1451
1451
  // Implementation signature
1452
- execute({
1452
+ #execute({
1453
1453
  strategy,
1454
1454
  hookName,
1455
1455
  parameters,
@@ -1463,7 +1463,7 @@ var PluginManager = class {
1463
1463
  this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1464
1464
  const task = Promise.resolve().then(() => {
1465
1465
  if (typeof hook === "function") {
1466
- const possiblePromiseResult = hook.apply(this.core.api, parameters);
1466
+ const possiblePromiseResult = hook.apply(this.#core.api, parameters);
1467
1467
  if (isPromise(possiblePromiseResult)) {
1468
1468
  return Promise.resolve(possiblePromiseResult);
1469
1469
  }
@@ -1474,10 +1474,10 @@ var PluginManager = class {
1474
1474
  output = result;
1475
1475
  return result;
1476
1476
  }).catch((e) => {
1477
- this.catcher(e, plugin, hookName);
1477
+ this.#catcher(e, plugin, hookName);
1478
1478
  return null;
1479
1479
  }).finally(() => {
1480
- this.addExecutedToCallStack({
1480
+ this.#addExecutedToCallStack({
1481
1481
  parameters,
1482
1482
  output,
1483
1483
  strategy,
@@ -1494,7 +1494,7 @@ var PluginManager = class {
1494
1494
  * @param plugin The acutal plugin
1495
1495
  * @param replaceContext When passed, the plugin context can be overridden.
1496
1496
  */
1497
- executeSync({
1497
+ #executeSync({
1498
1498
  strategy,
1499
1499
  hookName,
1500
1500
  parameters,
@@ -1508,17 +1508,17 @@ var PluginManager = class {
1508
1508
  this.eventEmitter.emit("execute", { strategy, hookName, parameters, plugin });
1509
1509
  try {
1510
1510
  if (typeof hook === "function") {
1511
- const fn = hook.apply(this.core.api, parameters);
1511
+ const fn = hook.apply(this.#core.api, parameters);
1512
1512
  output = fn;
1513
1513
  return fn;
1514
1514
  }
1515
1515
  output = hook;
1516
1516
  return hook;
1517
1517
  } catch (e) {
1518
- this.catcher(e, plugin, hookName);
1518
+ this.#catcher(e, plugin, hookName);
1519
1519
  return null;
1520
1520
  } finally {
1521
- this.addExecutedToCallStack({
1521
+ this.#addExecutedToCallStack({
1522
1522
  parameters,
1523
1523
  output,
1524
1524
  strategy,
@@ -1527,7 +1527,7 @@ var PluginManager = class {
1527
1527
  });
1528
1528
  }
1529
1529
  }
1530
- catcher(e, plugin, hookName) {
1530
+ #catcher(e, plugin, hookName) {
1531
1531
  const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
1532
1532
  `;
1533
1533
  const pluginError = new PluginError(text, { cause: e, pluginManager: this });
@@ -1652,14 +1652,14 @@ function defineConfig(options) {
1652
1652
  return options;
1653
1653
  }
1654
1654
  var PackageManager = class {
1655
- cwd;
1655
+ #cwd;
1656
1656
  constructor(workspace = process.cwd()) {
1657
- this.cwd = workspace;
1657
+ this.#cwd = workspace;
1658
1658
  return this;
1659
1659
  }
1660
1660
  async getPackageJSON() {
1661
1661
  const pkgPath = await findUp(["package.json"], {
1662
- cwd: this.cwd
1662
+ cwd: this.#cwd
1663
1663
  });
1664
1664
  if (!pkgPath) {
1665
1665
  return void 0;
@@ -1668,7 +1668,7 @@ var PackageManager = class {
1668
1668
  }
1669
1669
  getPackageJSONSync() {
1670
1670
  const pkgPath = findUpSync(["package.json"], {
1671
- cwd: this.cwd
1671
+ cwd: this.#cwd
1672
1672
  });
1673
1673
  if (!pkgPath) {
1674
1674
  return void 0;
@@ -1715,18 +1715,25 @@ var PackageManager = class {
1715
1715
 
1716
1716
  // src/generators/Generator.ts
1717
1717
  var Generator = class {
1718
- _options = {};
1719
- constructor(options = {}) {
1718
+ #options = {};
1719
+ #context = {};
1720
+ constructor(options, context) {
1721
+ if (context) {
1722
+ this.#context = context;
1723
+ }
1720
1724
  if (options) {
1721
- this._options = {
1722
- ...this._options,
1723
- ...options
1724
- };
1725
+ this.#options = options;
1725
1726
  }
1726
1727
  return this;
1727
1728
  }
1728
1729
  get options() {
1729
- return this._options;
1730
+ return this.#options;
1731
+ }
1732
+ get context() {
1733
+ return this.#context;
1734
+ }
1735
+ set options(options) {
1736
+ this.#options = { ...this.#options, ...options };
1730
1737
  }
1731
1738
  };
1732
1739