@hey-api/codegen-core 0.5.3 → 0.5.5

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 CHANGED
@@ -38,6 +38,53 @@ const fileBrand = "heyapi.file";
38
38
  const nodeBrand = "heyapi.node";
39
39
  const symbolBrand = "heyapi.symbol";
40
40
 
41
+ //#endregion
42
+ //#region src/config/interactive.ts
43
+ /**
44
+ * Detect if the current session is interactive based on TTY status and environment variables.
45
+ * This is used as a fallback when the user doesn't explicitly set the interactive option.
46
+ * @internal
47
+ */
48
+ function detectInteractiveSession() {
49
+ return Boolean(process.stdin.isTTY && process.stdout.isTTY && !process.env.CI && !process.env.NO_INTERACTIVE && !process.env.NO_INTERACTION);
50
+ }
51
+
52
+ //#endregion
53
+ //#region src/config/merge.ts
54
+ function isPlainObject(value) {
55
+ return typeof value === "object" && value !== null && !Array.isArray(value);
56
+ }
57
+ function mergeConfigs(configA, configB) {
58
+ const a = configA || {};
59
+ const b = configB || {};
60
+ const result = { ...a };
61
+ for (const key of Object.keys(b)) {
62
+ const valueA = a[key];
63
+ const valueB = b[key];
64
+ if (isPlainObject(valueA) && isPlainObject(valueB)) result[key] = mergeConfigs(valueA, valueB);
65
+ else result[key] = valueB;
66
+ }
67
+ return result;
68
+ }
69
+
70
+ //#endregion
71
+ //#region src/config/load.ts
72
+ async function loadConfigFile({ configFile, logger, name, userConfig }) {
73
+ const eventC12 = logger.timeEvent("c12");
74
+ const { loadConfig } = await import("c12");
75
+ const { config: fileConfig, configFile: loadedConfigFile } = await loadConfig({
76
+ configFile,
77
+ name
78
+ });
79
+ eventC12.timeEnd();
80
+ const fileConfigs = fileConfig instanceof Array ? fileConfig : [fileConfig];
81
+ return {
82
+ configFile: loadedConfigFile,
83
+ configs: fileConfigs.map((config) => mergeConfigs(config, userConfig)),
84
+ foundConfig: fileConfigs.some((config) => Object.keys(config).length > 0)
85
+ };
86
+ }
87
+
41
88
  //#endregion
42
89
  //#region src/log.ts
43
90
  ansi_colors.default.enabled = (0, color_support.default)().hasBasic;
@@ -342,6 +389,144 @@ const defaultNameConflictResolvers = {
342
389
  ruby: underscoreNameConflictResolver
343
390
  };
344
391
 
392
+ //#endregion
393
+ //#region src/logger.ts
394
+ let loggerCounter = 0;
395
+ const nameToId = (name) => `${name}-${loggerCounter++}`;
396
+ const idEnd = (id) => `${id}-end`;
397
+ const idLength = (id) => `${id}-length`;
398
+ const idStart = (id) => `${id}-start`;
399
+ const getSeverity = (duration, percentage) => {
400
+ if (duration > 200) return {
401
+ color: ansi_colors.default.red,
402
+ type: "duration"
403
+ };
404
+ if (percentage > 30) return {
405
+ color: ansi_colors.default.red,
406
+ type: "percentage"
407
+ };
408
+ if (duration > 50) return {
409
+ color: ansi_colors.default.yellow,
410
+ type: "duration"
411
+ };
412
+ if (percentage > 10) return {
413
+ color: ansi_colors.default.yellow,
414
+ type: "percentage"
415
+ };
416
+ };
417
+ var Logger = class {
418
+ events = [];
419
+ end(result) {
420
+ let event;
421
+ let events = this.events;
422
+ for (const index of result.position) {
423
+ event = events[index];
424
+ if (event?.events) events = event.events;
425
+ }
426
+ if (event && !event.end) event.end = performance.mark(idEnd(event.id));
427
+ }
428
+ /**
429
+ * Recursively end all unended events in the event tree.
430
+ * This ensures all events have end marks before measuring.
431
+ */
432
+ endAllEvents(events) {
433
+ for (const event of events) {
434
+ if (!event.end) event.end = performance.mark(idEnd(event.id));
435
+ if (event.events.length > 0) this.endAllEvents(event.events);
436
+ }
437
+ }
438
+ report(print = true) {
439
+ const firstEvent = this.events[0];
440
+ if (!firstEvent) return;
441
+ this.endAllEvents(this.events);
442
+ const lastEvent = this.events[this.events.length - 1];
443
+ const name = "root";
444
+ const id = nameToId(name);
445
+ try {
446
+ const measure = performance.measure(idLength(id), idStart(firstEvent.id), idEnd(lastEvent.id));
447
+ if (print) this.reportEvent({
448
+ end: lastEvent.end,
449
+ events: this.events,
450
+ id,
451
+ indent: 0,
452
+ measure,
453
+ name,
454
+ start: firstEvent.start
455
+ });
456
+ return measure;
457
+ } catch {
458
+ return;
459
+ }
460
+ }
461
+ reportEvent({ indent, ...parent }) {
462
+ const color = !indent ? ansi_colors.default.cyan : ansi_colors.default.gray;
463
+ const lastIndex = parent.events.length - 1;
464
+ parent.events.forEach((event, index) => {
465
+ try {
466
+ const measure = performance.measure(idLength(event.id), idStart(event.id), idEnd(event.id));
467
+ const duration = Math.ceil(measure.duration * 100) / 100;
468
+ const percentage = Math.ceil(measure.duration / parent.measure.duration * 100 * 100) / 100;
469
+ const severity = indent ? getSeverity(duration, percentage) : void 0;
470
+ let durationLabel = `${duration.toFixed(2).padStart(8)}ms`;
471
+ if (severity?.type === "duration") durationLabel = severity.color(durationLabel);
472
+ const branch = index === lastIndex ? "└─ " : "├─ ";
473
+ const prefix = !indent ? "" : "│ ".repeat(indent - 1) + branch;
474
+ const maxLength = 38 - prefix.length;
475
+ const percentageBranch = !indent ? "" : "↳ ";
476
+ let percentageLabel = `${indent ? " ".repeat(indent - 1) + percentageBranch : ""}${percentage.toFixed(2)}%`;
477
+ if (severity?.type === "percentage") percentageLabel = severity.color(percentageLabel);
478
+ const jobPrefix = ansi_colors.default.gray("[root] ");
479
+ console.log(`${jobPrefix}${ansi_colors.default.gray(prefix)}${color(`${event.name.padEnd(maxLength)} ${durationLabel} (${percentageLabel})`)}`);
480
+ this.reportEvent({
481
+ ...event,
482
+ indent: indent + 1,
483
+ measure
484
+ });
485
+ } catch {}
486
+ });
487
+ }
488
+ start(id) {
489
+ return performance.mark(idStart(id));
490
+ }
491
+ storeEvent({ result, ...event }) {
492
+ const lastEventIndex = event.events.length - 1;
493
+ const lastEvent = event.events[lastEventIndex];
494
+ if (lastEvent && !lastEvent.end) {
495
+ result.position = [...result.position, lastEventIndex];
496
+ this.storeEvent({
497
+ ...event,
498
+ events: lastEvent.events,
499
+ result
500
+ });
501
+ return;
502
+ }
503
+ const length = event.events.push({
504
+ ...event,
505
+ events: []
506
+ });
507
+ result.position = [...result.position, length - 1];
508
+ }
509
+ timeEvent(name) {
510
+ const id = nameToId(name);
511
+ const start = this.start(id);
512
+ const event = {
513
+ events: this.events,
514
+ id,
515
+ name,
516
+ start
517
+ };
518
+ const result = { position: [] };
519
+ this.storeEvent({
520
+ ...event,
521
+ result
522
+ });
523
+ return {
524
+ mark: start,
525
+ timeEnd: () => this.end(result)
526
+ };
527
+ }
528
+ };
529
+
345
530
  //#endregion
346
531
  //#region src/files/registry.ts
347
532
  var FileRegistry = class {
@@ -1597,12 +1782,14 @@ var StructureModel = class {
1597
1782
 
1598
1783
  //#endregion
1599
1784
  exports.File = File;
1785
+ exports.Logger = Logger;
1600
1786
  exports.Project = Project;
1601
1787
  exports.StructureModel = StructureModel;
1602
1788
  exports.StructureNode = StructureNode;
1603
1789
  exports.Symbol = Symbol$1;
1604
1790
  exports.defaultExtensions = defaultExtensions;
1605
1791
  exports.defaultNameConflictResolvers = defaultNameConflictResolvers;
1792
+ exports.detectInteractiveSession = detectInteractiveSession;
1606
1793
  exports.fromRef = fromRef;
1607
1794
  exports.fromRefs = fromRefs;
1608
1795
  exports.isNode = isNode;
@@ -1610,7 +1797,9 @@ exports.isNodeRef = isNodeRef;
1610
1797
  exports.isRef = isRef;
1611
1798
  exports.isSymbol = isSymbol;
1612
1799
  exports.isSymbolRef = isSymbolRef;
1800
+ exports.loadConfigFile = loadConfigFile;
1613
1801
  exports.log = log;
1802
+ exports.mergeConfigs = mergeConfigs;
1614
1803
  exports.nodeBrand = nodeBrand;
1615
1804
  exports.ref = ref;
1616
1805
  exports.refs = refs;