@openpkg-ts/extract 0.18.0 → 0.18.1

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/bin/tspec.js CHANGED
@@ -1,517 +1,30 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  extract
4
- } from "../shared/chunk-c3pkvc28.js";
4
+ } from "../shared/chunk-j81wegen.js";
5
5
 
6
6
  // src/cli/spec.ts
7
7
  import * as fs from "node:fs";
8
8
  import * as path from "node:path";
9
+ import { normalize, validateSpec } from "@openpkg-ts/spec";
10
+ import { Command } from "commander";
9
11
 
10
- // ../../node_modules/chalk/source/vendor/ansi-styles/index.js
11
- var ANSI_BACKGROUND_OFFSET = 10;
12
- var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
13
- var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
14
- var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
15
- var styles = {
16
- modifier: {
17
- reset: [0, 0],
18
- bold: [1, 22],
19
- dim: [2, 22],
20
- italic: [3, 23],
21
- underline: [4, 24],
22
- overline: [53, 55],
23
- inverse: [7, 27],
24
- hidden: [8, 28],
25
- strikethrough: [9, 29]
26
- },
27
- color: {
28
- black: [30, 39],
29
- red: [31, 39],
30
- green: [32, 39],
31
- yellow: [33, 39],
32
- blue: [34, 39],
33
- magenta: [35, 39],
34
- cyan: [36, 39],
35
- white: [37, 39],
36
- blackBright: [90, 39],
37
- gray: [90, 39],
38
- grey: [90, 39],
39
- redBright: [91, 39],
40
- greenBright: [92, 39],
41
- yellowBright: [93, 39],
42
- blueBright: [94, 39],
43
- magentaBright: [95, 39],
44
- cyanBright: [96, 39],
45
- whiteBright: [97, 39]
46
- },
47
- bgColor: {
48
- bgBlack: [40, 49],
49
- bgRed: [41, 49],
50
- bgGreen: [42, 49],
51
- bgYellow: [43, 49],
52
- bgBlue: [44, 49],
53
- bgMagenta: [45, 49],
54
- bgCyan: [46, 49],
55
- bgWhite: [47, 49],
56
- bgBlackBright: [100, 49],
57
- bgGray: [100, 49],
58
- bgGrey: [100, 49],
59
- bgRedBright: [101, 49],
60
- bgGreenBright: [102, 49],
61
- bgYellowBright: [103, 49],
62
- bgBlueBright: [104, 49],
63
- bgMagentaBright: [105, 49],
64
- bgCyanBright: [106, 49],
65
- bgWhiteBright: [107, 49]
66
- }
67
- };
68
- var modifierNames = Object.keys(styles.modifier);
69
- var foregroundColorNames = Object.keys(styles.color);
70
- var backgroundColorNames = Object.keys(styles.bgColor);
71
- var colorNames = [...foregroundColorNames, ...backgroundColorNames];
72
- function assembleStyles() {
73
- const codes = new Map;
74
- for (const [groupName, group] of Object.entries(styles)) {
75
- for (const [styleName, style] of Object.entries(group)) {
76
- styles[styleName] = {
77
- open: `\x1B[${style[0]}m`,
78
- close: `\x1B[${style[1]}m`
79
- };
80
- group[styleName] = styles[styleName];
81
- codes.set(style[0], style[1]);
82
- }
83
- Object.defineProperty(styles, groupName, {
84
- value: group,
85
- enumerable: false
86
- });
87
- }
88
- Object.defineProperty(styles, "codes", {
89
- value: codes,
90
- enumerable: false
91
- });
92
- styles.color.close = "\x1B[39m";
93
- styles.bgColor.close = "\x1B[49m";
94
- styles.color.ansi = wrapAnsi16();
95
- styles.color.ansi256 = wrapAnsi256();
96
- styles.color.ansi16m = wrapAnsi16m();
97
- styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
98
- styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
99
- styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
100
- Object.defineProperties(styles, {
101
- rgbToAnsi256: {
102
- value(red, green, blue) {
103
- if (red === green && green === blue) {
104
- if (red < 8) {
105
- return 16;
106
- }
107
- if (red > 248) {
108
- return 231;
109
- }
110
- return Math.round((red - 8) / 247 * 24) + 232;
111
- }
112
- return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
113
- },
114
- enumerable: false
115
- },
116
- hexToRgb: {
117
- value(hex) {
118
- const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
119
- if (!matches) {
120
- return [0, 0, 0];
121
- }
122
- let [colorString] = matches;
123
- if (colorString.length === 3) {
124
- colorString = [...colorString].map((character) => character + character).join("");
125
- }
126
- const integer = Number.parseInt(colorString, 16);
127
- return [
128
- integer >> 16 & 255,
129
- integer >> 8 & 255,
130
- integer & 255
131
- ];
132
- },
133
- enumerable: false
134
- },
135
- hexToAnsi256: {
136
- value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
137
- enumerable: false
138
- },
139
- ansi256ToAnsi: {
140
- value(code) {
141
- if (code < 8) {
142
- return 30 + code;
143
- }
144
- if (code < 16) {
145
- return 90 + (code - 8);
146
- }
147
- let red;
148
- let green;
149
- let blue;
150
- if (code >= 232) {
151
- red = ((code - 232) * 10 + 8) / 255;
152
- green = red;
153
- blue = red;
154
- } else {
155
- code -= 16;
156
- const remainder = code % 36;
157
- red = Math.floor(code / 36) / 5;
158
- green = Math.floor(remainder / 6) / 5;
159
- blue = remainder % 6 / 5;
160
- }
161
- const value = Math.max(red, green, blue) * 2;
162
- if (value === 0) {
163
- return 30;
164
- }
165
- let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
166
- if (value === 2) {
167
- result += 60;
168
- }
169
- return result;
170
- },
171
- enumerable: false
172
- },
173
- rgbToAnsi: {
174
- value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
175
- enumerable: false
176
- },
177
- hexToAnsi: {
178
- value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
179
- enumerable: false
180
- }
181
- });
182
- return styles;
183
- }
184
- var ansiStyles = assembleStyles();
185
- var ansi_styles_default = ansiStyles;
186
-
187
- // ../../node_modules/chalk/source/vendor/supports-color/index.js
188
- import process2 from "node:process";
189
- import os from "node:os";
190
- import tty from "node:tty";
191
- function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
192
- const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
193
- const position = argv.indexOf(prefix + flag);
194
- const terminatorPosition = argv.indexOf("--");
195
- return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
196
- }
197
- var { env } = process2;
198
- var flagForceColor;
199
- if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
200
- flagForceColor = 0;
201
- } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
202
- flagForceColor = 1;
203
- }
204
- function envForceColor() {
205
- if ("FORCE_COLOR" in env) {
206
- if (env.FORCE_COLOR === "true") {
207
- return 1;
208
- }
209
- if (env.FORCE_COLOR === "false") {
210
- return 0;
211
- }
212
- return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
213
- }
214
- }
215
- function translateLevel(level) {
216
- if (level === 0) {
217
- return false;
218
- }
219
- return {
220
- level,
221
- hasBasic: true,
222
- has256: level >= 2,
223
- has16m: level >= 3
224
- };
225
- }
226
- function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
227
- const noFlagForceColor = envForceColor();
228
- if (noFlagForceColor !== undefined) {
229
- flagForceColor = noFlagForceColor;
230
- }
231
- const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
232
- if (forceColor === 0) {
233
- return 0;
234
- }
235
- if (sniffFlags) {
236
- if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
237
- return 3;
238
- }
239
- if (hasFlag("color=256")) {
240
- return 2;
241
- }
242
- }
243
- if ("TF_BUILD" in env && "AGENT_NAME" in env) {
244
- return 1;
245
- }
246
- if (haveStream && !streamIsTTY && forceColor === undefined) {
247
- return 0;
248
- }
249
- const min = forceColor || 0;
250
- if (env.TERM === "dumb") {
251
- return min;
252
- }
253
- if (process2.platform === "win32") {
254
- const osRelease = os.release().split(".");
255
- if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
256
- return Number(osRelease[2]) >= 14931 ? 3 : 2;
257
- }
258
- return 1;
259
- }
260
- if ("CI" in env) {
261
- if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => (key in env))) {
262
- return 3;
263
- }
264
- if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
265
- return 1;
266
- }
267
- return min;
268
- }
269
- if ("TEAMCITY_VERSION" in env) {
270
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
271
- }
272
- if (env.COLORTERM === "truecolor") {
273
- return 3;
274
- }
275
- if (env.TERM === "xterm-kitty") {
276
- return 3;
277
- }
278
- if (env.TERM === "xterm-ghostty") {
279
- return 3;
280
- }
281
- if (env.TERM === "wezterm") {
282
- return 3;
283
- }
284
- if ("TERM_PROGRAM" in env) {
285
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
286
- switch (env.TERM_PROGRAM) {
287
- case "iTerm.app": {
288
- return version >= 3 ? 3 : 2;
289
- }
290
- case "Apple_Terminal": {
291
- return 2;
292
- }
293
- }
294
- }
295
- if (/-256(color)?$/i.test(env.TERM)) {
296
- return 2;
297
- }
298
- if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
299
- return 1;
300
- }
301
- if ("COLORTERM" in env) {
302
- return 1;
303
- }
304
- return min;
305
- }
306
- function createSupportsColor(stream, options = {}) {
307
- const level = _supportsColor(stream, {
308
- streamIsTTY: stream && stream.isTTY,
309
- ...options
310
- });
311
- return translateLevel(level);
312
- }
313
- var supportsColor = {
314
- stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
315
- stderr: createSupportsColor({ isTTY: tty.isatty(2) })
316
- };
317
- var supports_color_default = supportsColor;
318
-
319
- // ../../node_modules/chalk/source/utilities.js
320
- function stringReplaceAll(string, substring, replacer) {
321
- let index = string.indexOf(substring);
322
- if (index === -1) {
323
- return string;
324
- }
325
- const substringLength = substring.length;
326
- let endIndex = 0;
327
- let returnValue = "";
328
- do {
329
- returnValue += string.slice(endIndex, index) + substring + replacer;
330
- endIndex = index + substringLength;
331
- index = string.indexOf(substring, endIndex);
332
- } while (index !== -1);
333
- returnValue += string.slice(endIndex);
334
- return returnValue;
335
- }
336
- function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
337
- let endIndex = 0;
338
- let returnValue = "";
339
- do {
340
- const gotCR = string[index - 1] === "\r";
341
- returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? `\r
342
- ` : `
343
- `) + postfix;
344
- endIndex = index + 1;
345
- index = string.indexOf(`
346
- `, endIndex);
347
- } while (index !== -1);
348
- returnValue += string.slice(endIndex);
349
- return returnValue;
350
- }
351
-
352
- // ../../node_modules/chalk/source/index.js
353
- var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
354
- var GENERATOR = Symbol("GENERATOR");
355
- var STYLER = Symbol("STYLER");
356
- var IS_EMPTY = Symbol("IS_EMPTY");
357
- var levelMapping = [
358
- "ansi",
359
- "ansi",
360
- "ansi256",
361
- "ansi16m"
362
- ];
363
- var styles2 = Object.create(null);
364
- var applyOptions = (object, options = {}) => {
365
- if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
366
- throw new Error("The `level` option should be an integer from 0 to 3");
367
- }
368
- const colorLevel = stdoutColor ? stdoutColor.level : 0;
369
- object.level = options.level === undefined ? colorLevel : options.level;
370
- };
371
- var chalkFactory = (options) => {
372
- const chalk = (...strings) => strings.join(" ");
373
- applyOptions(chalk, options);
374
- Object.setPrototypeOf(chalk, createChalk.prototype);
375
- return chalk;
376
- };
377
- function createChalk(options) {
378
- return chalkFactory(options);
379
- }
380
- Object.setPrototypeOf(createChalk.prototype, Function.prototype);
381
- for (const [styleName, style] of Object.entries(ansi_styles_default)) {
382
- styles2[styleName] = {
383
- get() {
384
- const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
385
- Object.defineProperty(this, styleName, { value: builder });
386
- return builder;
387
- }
388
- };
389
- }
390
- styles2.visible = {
391
- get() {
392
- const builder = createBuilder(this, this[STYLER], true);
393
- Object.defineProperty(this, "visible", { value: builder });
394
- return builder;
395
- }
396
- };
397
- var getModelAnsi = (model, level, type, ...arguments_) => {
398
- if (model === "rgb") {
399
- if (level === "ansi16m") {
400
- return ansi_styles_default[type].ansi16m(...arguments_);
401
- }
402
- if (level === "ansi256") {
403
- return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
404
- }
405
- return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
406
- }
407
- if (model === "hex") {
408
- return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
409
- }
410
- return ansi_styles_default[type][model](...arguments_);
411
- };
412
- var usedModels = ["rgb", "hex", "ansi256"];
413
- for (const model of usedModels) {
414
- styles2[model] = {
415
- get() {
416
- const { level } = this;
417
- return function(...arguments_) {
418
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
419
- return createBuilder(this, styler, this[IS_EMPTY]);
420
- };
421
- }
422
- };
423
- const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
424
- styles2[bgModel] = {
425
- get() {
426
- const { level } = this;
427
- return function(...arguments_) {
428
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
429
- return createBuilder(this, styler, this[IS_EMPTY]);
430
- };
431
- }
432
- };
433
- }
434
- var proto = Object.defineProperties(() => {}, {
435
- ...styles2,
436
- level: {
437
- enumerable: true,
438
- get() {
439
- return this[GENERATOR].level;
440
- },
441
- set(level) {
442
- this[GENERATOR].level = level;
443
- }
444
- }
445
- });
446
- var createStyler = (open, close, parent) => {
447
- let openAll;
448
- let closeAll;
449
- if (parent === undefined) {
450
- openAll = open;
451
- closeAll = close;
452
- } else {
453
- openAll = parent.openAll + open;
454
- closeAll = close + parent.closeAll;
455
- }
456
- return {
457
- open,
458
- close,
459
- openAll,
460
- closeAll,
461
- parent
462
- };
463
- };
464
- var createBuilder = (self, _styler, _isEmpty) => {
465
- const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
466
- Object.setPrototypeOf(builder, proto);
467
- builder[GENERATOR] = self;
468
- builder[STYLER] = _styler;
469
- builder[IS_EMPTY] = _isEmpty;
470
- return builder;
471
- };
472
- var applyStyle = (self, string) => {
473
- if (self.level <= 0 || !string) {
474
- return self[IS_EMPTY] ? "" : string;
475
- }
476
- let styler = self[STYLER];
477
- if (styler === undefined) {
478
- return string;
479
- }
480
- const { openAll, closeAll } = styler;
481
- if (string.includes("\x1B")) {
482
- while (styler !== undefined) {
483
- string = stringReplaceAll(string, styler.close, styler.open);
484
- styler = styler.parent;
485
- }
486
- }
487
- const lfIndex = string.indexOf(`
488
- `);
489
- if (lfIndex !== -1) {
490
- string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
491
- }
492
- return openAll + string + closeAll;
493
- };
494
- Object.defineProperties(createChalk.prototype, styles2);
495
- var chalk = createChalk();
496
- var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
497
- var source_default = chalk;
498
-
499
- // ../cli-utils/dist/index.js
500
- import { Worker } from "node:worker_threads";
12
+ // src/utils/progress/colors.ts
13
+ import chalk from "chalk";
501
14
  var colors = {
502
- success: source_default.green,
503
- error: source_default.red,
504
- warning: source_default.yellow,
505
- info: source_default.cyan,
506
- muted: source_default.gray,
507
- bold: source_default.bold,
508
- dim: source_default.dim,
509
- underline: source_default.underline,
510
- primary: source_default.cyan,
511
- secondary: source_default.magenta,
512
- path: source_default.cyan,
513
- number: source_default.yellow,
514
- code: source_default.gray
15
+ success: chalk.green,
16
+ error: chalk.red,
17
+ warning: chalk.yellow,
18
+ info: chalk.cyan,
19
+ muted: chalk.gray,
20
+ bold: chalk.bold,
21
+ dim: chalk.dim,
22
+ underline: chalk.underline,
23
+ primary: chalk.cyan,
24
+ secondary: chalk.magenta,
25
+ path: chalk.cyan,
26
+ number: chalk.yellow,
27
+ code: chalk.gray
515
28
  };
516
29
  var symbols = {
517
30
  success: "✓",
@@ -550,6 +63,10 @@ var prefix = {
550
63
  warning: colors.warning(symbols.warning),
551
64
  info: colors.info(symbols.info)
552
65
  };
66
+ // src/utils/progress/spinner.ts
67
+ import chalk2 from "chalk";
68
+
69
+ // src/utils/progress/utils.ts
553
70
  function isTTY() {
554
71
  return Boolean(process.stdout.isTTY);
555
72
  }
@@ -571,18 +88,6 @@ function getTerminalWidth() {
571
88
  const width = process.stdout.columns || DEFAULT_TERMINAL_WIDTH;
572
89
  return Math.max(width, MIN_TERMINAL_WIDTH);
573
90
  }
574
- function formatDuration(ms) {
575
- if (ms < 1000) {
576
- return `${ms}ms`;
577
- }
578
- const seconds = ms / 1000;
579
- if (seconds < 60) {
580
- return `${seconds.toFixed(1)}s`;
581
- }
582
- const minutes = Math.floor(seconds / 60);
583
- const remainingSeconds = Math.floor(seconds % 60);
584
- return `${minutes}m ${remainingSeconds}s`;
585
- }
586
91
  var cursor = {
587
92
  hide: "\x1B[?25l",
588
93
  show: "\x1B[?25h",
@@ -601,11 +106,6 @@ function clearLine() {
601
106
  process.stdout.write(cursor.clearLine + cursor.left);
602
107
  }
603
108
  }
604
- function moveCursorUp(lines = 1) {
605
- if (isTTY()) {
606
- process.stdout.write(cursor.up(lines));
607
- }
608
- }
609
109
  function hideCursor() {
610
110
  if (isTTY()) {
611
111
  process.stdout.write(cursor.hide);
@@ -626,391 +126,15 @@ function stripAnsi(text) {
626
126
  return text.replace(ANSI_REGEX, "");
627
127
  }
628
128
 
629
- class MultiProgress {
630
- bars = new Map;
631
- barOrder = [];
632
- options;
633
- spinnerFrames;
634
- spinnerIndex = 0;
635
- timer = null;
636
- lastRenderedLines = 0;
637
- symbols = getSymbols(supportsUnicode());
638
- sigintHandler = null;
639
- filledChar;
640
- emptyChar;
641
- constructor(options = {}) {
642
- this.options = {
643
- barWidth: options.barWidth,
644
- showPercent: options.showPercent ?? true,
645
- showCount: options.showCount ?? true,
646
- spinnerInterval: options.spinnerInterval ?? 80
647
- };
648
- this.spinnerFrames = supportsUnicode() ? ["◐", "◓", "◑", "◒"] : ["-", "\\", "|", "/"];
649
- const unicode = supportsUnicode();
650
- this.filledChar = unicode ? "█" : "#";
651
- this.emptyChar = unicode ? "░" : "-";
652
- }
653
- start() {
654
- if (!isInteractive())
655
- return this;
656
- hideCursor();
657
- this.setupSignalHandler();
658
- this.timer = setInterval(() => {
659
- if (this.bars.size > 0 && [...this.bars.values()].some((b) => b.status === "active")) {
660
- this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;
661
- this.render();
662
- }
663
- }, this.options.spinnerInterval);
664
- return this;
665
- }
666
- add(config) {
667
- const state = {
668
- id: config.id,
669
- label: config.label,
670
- total: config.total ?? 100,
671
- current: config.current ?? 0,
672
- status: "active",
673
- startTime: Date.now()
674
- };
675
- this.bars.set(config.id, state);
676
- if (!this.barOrder.includes(config.id)) {
677
- this.barOrder.push(config.id);
678
- }
679
- if (!isInteractive()) {
680
- console.log(`${this.symbols.bullet} ${config.label}`);
681
- } else {
682
- this.render();
683
- }
684
- return this;
685
- }
686
- update(id, current, label) {
687
- const bar = this.bars.get(id);
688
- if (!bar)
689
- return this;
690
- bar.current = Math.min(current, bar.total);
691
- if (label !== undefined)
692
- bar.label = label;
693
- if (isInteractive()) {
694
- this.render();
695
- }
696
- return this;
697
- }
698
- increment(id, amount = 1) {
699
- const bar = this.bars.get(id);
700
- if (!bar)
701
- return this;
702
- return this.update(id, bar.current + amount);
703
- }
704
- complete(id, label) {
705
- const bar = this.bars.get(id);
706
- if (!bar)
707
- return this;
708
- bar.status = "completed";
709
- bar.current = bar.total;
710
- if (label !== undefined)
711
- bar.label = label;
712
- if (!isInteractive()) {
713
- console.log(`${colors.success(this.symbols.success)} ${bar.label}`);
714
- } else {
715
- this.render();
716
- }
717
- return this;
718
- }
719
- fail(id, label) {
720
- const bar = this.bars.get(id);
721
- if (!bar)
722
- return this;
723
- bar.status = "failed";
724
- if (label !== undefined)
725
- bar.label = label;
726
- if (!isInteractive()) {
727
- console.log(`${colors.error(this.symbols.error)} ${bar.label}`);
728
- } else {
729
- this.render();
730
- }
731
- return this;
732
- }
733
- remove(id) {
734
- this.bars.delete(id);
735
- this.barOrder = this.barOrder.filter((i) => i !== id);
736
- if (isInteractive()) {
737
- this.render();
738
- }
739
- return this;
740
- }
741
- get(id) {
742
- return this.bars.get(id);
743
- }
744
- get allDone() {
745
- if (this.bars.size === 0)
746
- return true;
747
- return [...this.bars.values()].every((b) => b.status !== "active");
748
- }
749
- stop() {
750
- if (this.timer) {
751
- clearInterval(this.timer);
752
- this.timer = null;
753
- }
754
- this.cleanup();
755
- return this;
756
- }
757
- render() {
758
- if (!isTTY())
759
- return;
760
- this.clearOutput();
761
- const width = getTerminalWidth();
762
- const lines = [];
763
- for (const id of this.barOrder) {
764
- const bar = this.bars.get(id);
765
- if (!bar)
766
- continue;
767
- const line = this.renderBar(bar, width);
768
- lines.push(line);
769
- }
770
- if (lines.length > 0) {
771
- process.stdout.write(lines.join(`
772
- `));
773
- this.lastRenderedLines = lines.length;
774
- }
775
- }
776
- renderBar(bar, termWidth) {
777
- const parts = [];
778
- let symbol;
779
- switch (bar.status) {
780
- case "completed":
781
- symbol = colors.success(this.symbols.success);
782
- break;
783
- case "failed":
784
- symbol = colors.error(this.symbols.error);
785
- break;
786
- default:
787
- symbol = colors.primary(this.spinnerFrames[this.spinnerIndex]);
788
- }
789
- parts.push(symbol);
790
- parts.push(bar.label);
791
- const suffixParts = [];
792
- if (this.options.showPercent) {
793
- const pct = bar.total === 0 ? 0 : Math.round(bar.current / bar.total * 100);
794
- suffixParts.push(`${pct}%`);
795
- }
796
- if (this.options.showCount) {
797
- suffixParts.push(`${bar.current}/${bar.total}`);
798
- }
799
- const suffix = suffixParts.length > 0 ? ` ${suffixParts.join(" ")}` : "";
800
- const labelLen = stripAnsi(parts.join(" ")).length + 1;
801
- const bracketLen = 2;
802
- const suffixLen = stripAnsi(suffix).length;
803
- const minBarWidth = 10;
804
- const availableWidth = termWidth - labelLen - bracketLen - suffixLen - 1;
805
- const barWidth = this.options.barWidth ?? Math.max(minBarWidth, Math.min(30, availableWidth));
806
- const filledWidth = Math.round(bar.current / bar.total * barWidth);
807
- const emptyWidth = barWidth - filledWidth;
808
- const barViz = `[${this.filledChar.repeat(filledWidth)}${this.emptyChar.repeat(emptyWidth)}]`;
809
- parts.push(barViz);
810
- return truncate(parts.join(" ") + suffix, termWidth);
811
- }
812
- clearOutput() {
813
- if (!isTTY() || this.lastRenderedLines === 0)
814
- return;
815
- for (let i = 0;i < this.lastRenderedLines; i++) {
816
- if (i > 0)
817
- process.stdout.write(cursor.up(1));
818
- clearLine();
819
- }
820
- this.lastRenderedLines = 0;
821
- }
822
- setupSignalHandler() {
823
- this.sigintHandler = () => {
824
- this.cleanup();
825
- process.exit(130);
826
- };
827
- process.on("SIGINT", this.sigintHandler);
828
- }
829
- cleanup() {
830
- if (this.sigintHandler) {
831
- process.removeListener("SIGINT", this.sigintHandler);
832
- this.sigintHandler = null;
833
- }
834
- showCursor();
835
- if (isTTY() && this.lastRenderedLines > 0) {
836
- process.stdout.write(`
837
- `);
838
- }
839
- }
840
- }
841
- class ProgressBar {
842
- total;
843
- current;
844
- label;
845
- width;
846
- showPercent;
847
- showCount;
848
- showETA;
849
- filledChar;
850
- emptyChar;
851
- startTime = null;
852
- lastRender = "";
853
- symbols = getSymbols(supportsUnicode());
854
- sigintHandler = null;
855
- isComplete = false;
856
- constructor(options = {}) {
857
- this.total = options.total ?? 100;
858
- this.current = options.current ?? 0;
859
- this.label = options.label ?? "";
860
- this.width = options.width;
861
- this.showPercent = options.showPercent ?? true;
862
- this.showCount = options.showCount ?? true;
863
- this.showETA = options.showETA ?? true;
864
- const unicode = supportsUnicode();
865
- this.filledChar = options.chars?.filled ?? (unicode ? "█" : "#");
866
- this.emptyChar = options.chars?.empty ?? (unicode ? "░" : "-");
867
- }
868
- start(label) {
869
- if (label !== undefined)
870
- this.label = label;
871
- this.startTime = Date.now();
872
- this.current = 0;
873
- this.isComplete = false;
874
- if (!isInteractive()) {
875
- console.log(`${this.symbols.bullet} ${this.label}`);
876
- return this;
877
- }
878
- hideCursor();
879
- this.setupSignalHandler();
880
- this.render();
881
- return this;
882
- }
883
- update(current) {
884
- this.current = Math.min(current, this.total);
885
- if (isInteractive()) {
886
- this.render();
887
- }
888
- return this;
889
- }
890
- increment(amount = 1) {
891
- return this.update(this.current + amount);
892
- }
893
- setLabel(label) {
894
- this.label = label;
895
- if (isInteractive()) {
896
- this.render();
897
- }
898
- return this;
899
- }
900
- setTotal(total) {
901
- this.total = total;
902
- if (isInteractive()) {
903
- this.render();
904
- }
905
- return this;
906
- }
907
- complete(label) {
908
- if (label !== undefined)
909
- this.label = label;
910
- this.current = this.total;
911
- this.isComplete = true;
912
- if (!isInteractive()) {
913
- console.log(`${colors.success(this.symbols.success)} ${this.label}`);
914
- } else {
915
- clearLine();
916
- process.stdout.write(`${colors.success(this.symbols.success)} ${this.label}
917
- `);
918
- }
919
- this.cleanup();
920
- return this;
921
- }
922
- fail(label) {
923
- if (label !== undefined)
924
- this.label = label;
925
- this.isComplete = true;
926
- if (!isInteractive()) {
927
- console.log(`${colors.error(this.symbols.error)} ${this.label}`);
928
- } else {
929
- clearLine();
930
- process.stdout.write(`${colors.error(this.symbols.error)} ${this.label}
931
- `);
932
- }
933
- this.cleanup();
934
- return this;
935
- }
936
- get percentage() {
937
- return this.total === 0 ? 0 : Math.round(this.current / this.total * 100);
938
- }
939
- get isDone() {
940
- return this.isComplete || this.current >= this.total;
941
- }
942
- render() {
943
- if (!isTTY())
944
- return;
945
- const termWidth = getTerminalWidth();
946
- const parts = [];
947
- if (this.label) {
948
- parts.push(this.label);
949
- }
950
- const suffixParts = [];
951
- if (this.showPercent) {
952
- suffixParts.push(`${this.percentage}%`);
953
- }
954
- if (this.showCount) {
955
- suffixParts.push(`${this.current}/${this.total}`);
956
- }
957
- if (this.showETA && this.startTime) {
958
- const eta = this.calculateETA();
959
- if (eta)
960
- suffixParts.push(eta);
961
- }
962
- const suffix = suffixParts.length > 0 ? ` ${suffixParts.join(" ")}` : "";
963
- const labelLen = this.label ? stripAnsi(this.label).length + 1 : 0;
964
- const bracketLen = 2;
965
- const suffixLen = stripAnsi(suffix).length;
966
- const minBarWidth = 10;
967
- const availableWidth = termWidth - labelLen - bracketLen - suffixLen - 1;
968
- const barWidth = this.width ?? Math.max(minBarWidth, Math.min(40, availableWidth));
969
- const filledWidth = Math.round(this.current / this.total * barWidth);
970
- const emptyWidth = barWidth - filledWidth;
971
- const bar = `[${this.filledChar.repeat(filledWidth)}${this.emptyChar.repeat(emptyWidth)}]`;
972
- parts.push(bar);
973
- const line = truncate(parts.join(" ") + suffix, termWidth);
974
- if (line !== this.lastRender) {
975
- clearLine();
976
- process.stdout.write(line);
977
- this.lastRender = line;
978
- }
979
- }
980
- calculateETA() {
981
- if (!this.startTime || this.current === 0)
982
- return null;
983
- const elapsed = Date.now() - this.startTime;
984
- if (elapsed < 1000)
985
- return null;
986
- const rate = this.current / elapsed;
987
- const remaining = this.total - this.current;
988
- const etaMs = remaining / rate;
989
- return `ETA ${formatDuration(etaMs)}`;
990
- }
991
- setupSignalHandler() {
992
- this.sigintHandler = () => {
993
- this.cleanup();
994
- process.exit(130);
995
- };
996
- process.on("SIGINT", this.sigintHandler);
997
- }
998
- cleanup() {
999
- if (this.sigintHandler) {
1000
- process.removeListener("SIGINT", this.sigintHandler);
1001
- this.sigintHandler = null;
1002
- }
1003
- showCursor();
1004
- }
1005
- }
129
+ // src/utils/progress/spinner.ts
1006
130
  var spinnerColors = {
1007
- cyan: source_default.cyan,
1008
- yellow: source_default.yellow,
1009
- green: source_default.green,
1010
- red: source_default.red,
1011
- magenta: source_default.magenta,
1012
- blue: source_default.blue,
1013
- white: source_default.white
131
+ cyan: chalk2.cyan,
132
+ yellow: chalk2.yellow,
133
+ green: chalk2.green,
134
+ red: chalk2.red,
135
+ magenta: chalk2.magenta,
136
+ blue: chalk2.blue,
137
+ white: chalk2.white
1014
138
  };
1015
139
  var FRAME_SETS = {
1016
140
  dots: ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
@@ -1030,13 +154,11 @@ class Spinner {
1030
154
  symbols = getSymbols(supportsUnicode());
1031
155
  lastRenderedLines = 0;
1032
156
  sigintHandler = null;
1033
- animate;
1034
157
  constructor(options = {}) {
1035
158
  this.label = options.label ?? "";
1036
159
  this.detail = options.detail;
1037
160
  this.interval = options.interval ?? 80;
1038
161
  this.colorFn = spinnerColors[options.color ?? "cyan"];
1039
- this.animate = options.animate ?? true;
1040
162
  const style = options.style ?? "circle";
1041
163
  this.frames = supportsUnicode() ? FRAME_SETS[style] : ASCII_FRAME_SET;
1042
164
  }
@@ -1048,7 +170,7 @@ class Spinner {
1048
170
  this.state = "spinning";
1049
171
  this.frameIndex = 0;
1050
172
  this.lastRenderedLines = 0;
1051
- if (!isInteractive() || !this.animate) {
173
+ if (!isInteractive()) {
1052
174
  console.log(`${this.symbols.bullet} ${this.label}`);
1053
175
  return this;
1054
176
  }
@@ -1106,12 +228,14 @@ class Spinner {
1106
228
  this.timer = null;
1107
229
  }
1108
230
  this.state = state;
1109
- const symbol = state === "success" ? this.symbols.success : this.symbols.error;
1110
- const colorFn = state === "success" ? colors.success : colors.error;
1111
- if (!isInteractive() || !this.animate) {
231
+ if (!isInteractive()) {
232
+ const symbol = state === "success" ? this.symbols.success : this.symbols.error;
233
+ const colorFn = state === "success" ? colors.success : colors.error;
1112
234
  console.log(`${colorFn(symbol)} ${this.label}`);
1113
235
  } else {
1114
236
  this.clearOutput();
237
+ const symbol = state === "success" ? this.symbols.success : this.symbols.error;
238
+ const colorFn = state === "success" ? colors.success : colors.error;
1115
239
  process.stdout.write(`${colorFn(symbol)} ${this.label}
1116
240
  `);
1117
241
  }
@@ -1161,206 +285,7 @@ ${detailLine}`);
1161
285
  function spinner(label, options) {
1162
286
  return new Spinner({ ...options, label }).start();
1163
287
  }
1164
-
1165
- class StepProgress {
1166
- steps = [];
1167
- showNumbers;
1168
- spinnerInterval;
1169
- spinnerFrames;
1170
- spinnerIndex = 0;
1171
- timer = null;
1172
- symbols = getSymbols(supportsUnicode());
1173
- lastRenderedLines = 0;
1174
- sigintHandler = null;
1175
- constructor(options = {}) {
1176
- this.showNumbers = options.showNumbers ?? true;
1177
- this.spinnerInterval = options.spinnerInterval ?? 80;
1178
- this.spinnerFrames = supportsUnicode() ? ["◐", "◓", "◑", "◒"] : ["-", "\\", "|", "/"];
1179
- if (options.steps) {
1180
- this.steps = options.steps.map((label) => ({ label, status: "pending" }));
1181
- }
1182
- }
1183
- start() {
1184
- if (!isInteractive())
1185
- return this;
1186
- hideCursor();
1187
- this.setupSignalHandler();
1188
- this.render();
1189
- this.timer = setInterval(() => {
1190
- if (this.steps.some((s) => s.status === "active")) {
1191
- this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;
1192
- this.render();
1193
- }
1194
- }, this.spinnerInterval);
1195
- return this;
1196
- }
1197
- addStep(label) {
1198
- this.steps.push({ label, status: "pending" });
1199
- if (isInteractive())
1200
- this.render();
1201
- return this;
1202
- }
1203
- startStep(index) {
1204
- if (index >= 0 && index < this.steps.length) {
1205
- this.steps[index].status = "active";
1206
- this.steps[index].startTime = Date.now();
1207
- if (isInteractive()) {
1208
- this.render();
1209
- } else {
1210
- const step = this.steps[index];
1211
- const prefix2 = this.showNumbers ? `[${index + 1}/${this.steps.length}] ` : "";
1212
- console.log(`${this.symbols.bullet} ${prefix2}${step.label}...`);
1213
- }
1214
- }
1215
- return this;
1216
- }
1217
- completeStep(index) {
1218
- if (index >= 0 && index < this.steps.length) {
1219
- this.steps[index].status = "completed";
1220
- this.steps[index].endTime = Date.now();
1221
- if (isInteractive()) {
1222
- this.render();
1223
- } else {
1224
- const step = this.steps[index];
1225
- const duration = this.getStepDuration(step);
1226
- const prefix2 = this.showNumbers ? `[${index + 1}/${this.steps.length}] ` : "";
1227
- console.log(`${colors.success(this.symbols.success)} ${prefix2}${step.label}${duration}`);
1228
- }
1229
- }
1230
- return this;
1231
- }
1232
- failStep(index) {
1233
- if (index >= 0 && index < this.steps.length) {
1234
- this.steps[index].status = "failed";
1235
- this.steps[index].endTime = Date.now();
1236
- if (isInteractive()) {
1237
- this.render();
1238
- } else {
1239
- const step = this.steps[index];
1240
- const prefix2 = this.showNumbers ? `[${index + 1}/${this.steps.length}] ` : "";
1241
- console.log(`${colors.error(this.symbols.error)} ${prefix2}${step.label}`);
1242
- }
1243
- }
1244
- return this;
1245
- }
1246
- skipStep(index) {
1247
- if (index >= 0 && index < this.steps.length) {
1248
- this.steps[index].status = "skipped";
1249
- if (isInteractive())
1250
- this.render();
1251
- }
1252
- return this;
1253
- }
1254
- async run(tasks) {
1255
- this.steps = tasks.map((t) => ({ label: t.label, status: "pending" }));
1256
- this.start();
1257
- const results = [];
1258
- let failed = false;
1259
- for (let i = 0;i < tasks.length; i++) {
1260
- if (failed) {
1261
- this.skipStep(i);
1262
- continue;
1263
- }
1264
- this.startStep(i);
1265
- try {
1266
- results.push(await tasks[i].task());
1267
- this.completeStep(i);
1268
- } catch {
1269
- this.failStep(i);
1270
- failed = true;
1271
- }
1272
- }
1273
- this.stop();
1274
- return { results, failed };
1275
- }
1276
- stop() {
1277
- if (this.timer) {
1278
- clearInterval(this.timer);
1279
- this.timer = null;
1280
- }
1281
- this.cleanup();
1282
- return this;
1283
- }
1284
- get currentStepIndex() {
1285
- const activeIdx = this.steps.findIndex((s) => s.status === "active");
1286
- if (activeIdx >= 0)
1287
- return activeIdx;
1288
- return this.steps.findIndex((s) => s.status === "pending");
1289
- }
1290
- render() {
1291
- if (!isTTY())
1292
- return;
1293
- if (this.lastRenderedLines > 0) {
1294
- moveCursorUp(this.lastRenderedLines - 1);
1295
- for (let i = 0;i < this.lastRenderedLines; i++) {
1296
- clearLine();
1297
- if (i < this.lastRenderedLines - 1) {
1298
- process.stdout.write(cursor.down(1));
1299
- }
1300
- }
1301
- moveCursorUp(this.lastRenderedLines - 1);
1302
- }
1303
- const width = getTerminalWidth();
1304
- const lines = [];
1305
- for (let i = 0;i < this.steps.length; i++) {
1306
- const step = this.steps[i];
1307
- const prefix2 = this.showNumbers ? `[${i + 1}/${this.steps.length}] ` : "";
1308
- const duration = this.getStepDuration(step);
1309
- let symbol;
1310
- let text;
1311
- switch (step.status) {
1312
- case "completed":
1313
- symbol = colors.success(this.symbols.success);
1314
- text = `${prefix2}${step.label}${duration}`;
1315
- break;
1316
- case "failed":
1317
- symbol = colors.error(this.symbols.error);
1318
- text = `${prefix2}${step.label}`;
1319
- break;
1320
- case "active":
1321
- symbol = colors.primary(this.spinnerFrames[this.spinnerIndex]);
1322
- text = `${prefix2}${step.label}`;
1323
- break;
1324
- case "skipped":
1325
- symbol = colors.muted(this.symbols.bullet);
1326
- text = colors.muted(`${prefix2}${step.label} (skipped)`);
1327
- break;
1328
- default:
1329
- symbol = colors.muted("○");
1330
- text = colors.muted(`${prefix2}${step.label}`);
1331
- }
1332
- lines.push(truncate(`${symbol} ${text}`, width));
1333
- }
1334
- process.stdout.write(lines.join(`
1335
- `));
1336
- this.lastRenderedLines = lines.length;
1337
- }
1338
- getStepDuration(step) {
1339
- if (step.startTime && step.endTime) {
1340
- const ms = step.endTime - step.startTime;
1341
- return colors.muted(` (${formatDuration(ms)})`);
1342
- }
1343
- return "";
1344
- }
1345
- setupSignalHandler() {
1346
- this.sigintHandler = () => {
1347
- this.cleanup();
1348
- process.exit(130);
1349
- };
1350
- process.on("SIGINT", this.sigintHandler);
1351
- }
1352
- cleanup() {
1353
- if (this.sigintHandler) {
1354
- process.removeListener("SIGINT", this.sigintHandler);
1355
- this.sigintHandler = null;
1356
- }
1357
- showCursor();
1358
- if (isTTY() && this.lastRenderedLines > 0) {
1359
- process.stdout.write(`
1360
- `);
1361
- }
1362
- }
1363
- }
288
+ // src/utils/progress/summary.ts
1364
289
  class Summary {
1365
290
  items = [];
1366
291
  title;
@@ -1483,10 +408,7 @@ class Summary {
1483
408
  function summary(options) {
1484
409
  return new Summary(options);
1485
410
  }
1486
-
1487
411
  // src/cli/spec.ts
1488
- import { normalize, validateSpec } from "@openpkg-ts/spec";
1489
- import { Command } from "commander";
1490
412
  function createProgram() {
1491
413
  const program = new Command("tspec").description("Extract TypeScript package API to OpenPkg spec").argument("[entry]", "Entry point file").option("-o, --output <file>", "Output file", "openpkg.json").option("--max-depth <n>", "Max type depth (default: 4)").option("--skip-resolve", "Skip external type resolution").option("--runtime", "Enable Standard Schema runtime extraction").option("--only <exports>", "Only extract these exports (comma-separated, supports * wildcards)").option("--ignore <exports>", "Ignore these exports (comma-separated, supports * wildcards)").option("-v, --verbose", "Show detailed output").action(async (entry, options) => {
1492
414
  let entryFile;
@@ -1589,7 +1589,7 @@ var BUILTIN_TYPES2 = new Set([
1589
1589
  function matchesPattern(name, pattern) {
1590
1590
  if (!pattern.includes("*"))
1591
1591
  return name === pattern;
1592
- const regex = new RegExp("^" + pattern.replace(/\*/g, ".*") + "$");
1592
+ const regex = new RegExp(`^${pattern.replace(/\*/g, ".*")}$`);
1593
1593
  return regex.test(name);
1594
1594
  }
1595
1595
  function shouldIncludeExport(name, only, ignore) {
package/dist/src/index.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  serializeTypeAlias,
27
27
  serializeVariable,
28
28
  withDescription
29
- } from "../shared/chunk-c3pkvc28.js";
29
+ } from "../shared/chunk-j81wegen.js";
30
30
  // src/schema/registry.ts
31
31
  function isTypeReference(type) {
32
32
  return !!(type.flags & 524288 && type.objectFlags && type.objectFlags & 4);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/extract",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "TypeScript export extraction to OpenPkg spec",
5
5
  "keywords": [
6
6
  "openpkg",
@@ -40,13 +40,13 @@
40
40
  "format": "biome format --write src/"
41
41
  },
42
42
  "dependencies": {
43
- "@openpkg-ts/spec": "^0.12.0",
43
+ "@openpkg-ts/spec": "workspace:*",
44
+ "chalk": "^5.4.1",
44
45
  "commander": "^12.0.0",
45
46
  "tree-sitter-wasms": "^0.1.13",
46
47
  "typescript": "^5.0.0"
47
48
  },
48
49
  "devDependencies": {
49
- "cli-utils": "workspace:*",
50
50
  "@types/bun": "latest",
51
51
  "@types/node": "^20.0.0",
52
52
  "bunup": "latest"