bun-plugin-dtsx 0.21.2 → 0.21.3

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
@@ -1,2716 +1,6 @@
1
1
  // @bun
2
- // node_modules/@stacksjs/dtsx/dist/index.js
3
- import l1 from "process";
4
- import { resolve as nq } from "path";
5
- import rq from "process";
6
- import { mkdir as hZ, rm as uZ } from "fs/promises";
7
- import { dirname as mZ, join as dZ, parse as cZ, relative as lZ } from "path";
8
- import Dq, { posix as I1 } from "path";
9
- import { readdir as vZ } from "fs/promises";
10
- import { extname as gZ, join as hq } from "path";
11
- var lq = Object.create;
12
- var { getPrototypeOf: pq, defineProperty: d1, getOwnPropertyNames: iq } = Object;
13
- var sq = Object.prototype.hasOwnProperty;
14
- var K1 = (q, $, J) => {
15
- J = q != null ? lq(pq(q)) : {};
16
- let Z = $ || !q || !q.__esModule ? d1(J, "default", { value: q, enumerable: true }) : J;
17
- for (let Y of iq(q))
18
- if (!sq.call(Z, Y))
19
- d1(Z, Y, { get: () => q[Y], enumerable: true });
20
- return Z;
21
- };
22
- var y = (q, $) => () => ($ || q(($ = { exports: {} }).exports, $), $.exports);
23
- var A1 = y((Q0) => {
24
- Object.defineProperty(Q0, "__esModule", { value: true });
25
- Q0.normalizePath = Q0.convertSlashes = Q0.cleanPath = undefined;
26
- var E1 = import.meta.require("path");
27
- function j0(q) {
28
- let $ = E1.normalize(q);
29
- if ($.length > 1 && $[$.length - 1] === E1.sep)
30
- $ = $.substring(0, $.length - 1);
31
- return $;
32
- }
33
- Q0.cleanPath = j0;
34
- var v$ = /[\\/]/g;
35
- function X0(q, $) {
36
- return q.replace(v$, $);
37
- }
38
- Q0.convertSlashes = X0;
39
- function g$(q, $) {
40
- let { resolvePaths: J, normalizePath: Z, pathSeparator: Y } = $, j = process.platform === "win32" && q.includes("/") || q.startsWith(".");
41
- if (J)
42
- q = E1.resolve(q);
43
- if (Z || j)
44
- q = j0(q);
45
- if (q === ".")
46
- return "";
47
- let Q = q[q.length - 1] !== Y;
48
- return X0(Q ? q + Y : q, Y);
49
- }
50
- Q0.normalizePath = g$;
51
- });
52
- var K0 = y((G0) => {
53
- Object.defineProperty(G0, "__esModule", { value: true });
54
- G0.build = G0.joinDirectoryPath = G0.joinPathWithBasePath = undefined;
55
- var m$ = import.meta.require("path"), d$ = A1();
56
- function z0(q, $) {
57
- return $ + q;
58
- }
59
- G0.joinPathWithBasePath = z0;
60
- function c$(q, $) {
61
- return function(J, Z) {
62
- if (Z.startsWith(q))
63
- return Z.replace(q, "") + J;
64
- else
65
- return d$.convertSlashes(m$.relative(q, Z), $.pathSeparator) + $.pathSeparator + J;
66
- };
67
- }
68
- function l$(q) {
69
- return q;
70
- }
71
- function p$(q, $, J) {
72
- return $ + q + J;
73
- }
74
- G0.joinDirectoryPath = p$;
75
- function i$(q, $) {
76
- let { relativePaths: J, includeBasePath: Z } = $;
77
- return J && q ? c$(q, $) : Z ? z0 : l$;
78
- }
79
- G0.build = i$;
80
- });
81
- var M0 = y((B0) => {
82
- Object.defineProperty(B0, "__esModule", { value: true });
83
- B0.build = undefined;
84
- function r$(q) {
85
- return function($, J) {
86
- J.push($.substring(q.length) || ".");
87
- };
88
- }
89
- function o$(q) {
90
- return function($, J, Z) {
91
- let Y = $.substring(q.length) || ".";
92
- if (Z.every((j) => j(Y, true)))
93
- J.push(Y);
94
- };
95
- }
96
- var a$ = (q, $) => {
97
- $.push(q || ".");
98
- }, t$ = (q, $, J) => {
99
- let Z = q || ".";
100
- if (J.every((Y) => Y(Z, true)))
101
- $.push(Z);
102
- }, e$ = () => {
103
- };
104
- function qJ(q, $) {
105
- let { includeDirs: J, filters: Z, relativePaths: Y } = $;
106
- if (!J)
107
- return e$;
108
- if (Y)
109
- return Z && Z.length ? o$(q) : r$(q);
110
- return Z && Z.length ? t$ : a$;
111
- }
112
- B0.build = qJ;
113
- });
114
- var H0 = y((V0) => {
115
- Object.defineProperty(V0, "__esModule", { value: true });
116
- V0.build = undefined;
117
- var $J = (q, $, J, Z) => {
118
- if (Z.every((Y) => Y(q, false)))
119
- J.files++;
120
- }, JJ = (q, $, J, Z) => {
121
- if (Z.every((Y) => Y(q, false)))
122
- $.push(q);
123
- }, ZJ = (q, $, J, Z) => {
124
- J.files++;
125
- }, YJ = (q, $) => {
126
- $.push(q);
127
- }, jJ = () => {
128
- };
129
- function XJ(q) {
130
- let { excludeFiles: $, filters: J, onlyCounts: Z } = q;
131
- if ($)
132
- return jJ;
133
- if (J && J.length)
134
- return Z ? $J : JJ;
135
- else if (Z)
136
- return ZJ;
137
- else
138
- return YJ;
139
- }
140
- V0.build = XJ;
141
- });
142
- var _0 = y((I0) => {
143
- Object.defineProperty(I0, "__esModule", { value: true });
144
- I0.build = undefined;
145
- var QJ = (q) => {
146
- return q;
147
- }, UJ = () => {
148
- return [""].slice(0, 0);
149
- };
150
- function zJ(q) {
151
- return q.group ? UJ : QJ;
152
- }
153
- I0.build = zJ;
154
- });
155
- var P0 = y((O0) => {
156
- Object.defineProperty(O0, "__esModule", { value: true });
157
- O0.build = undefined;
158
- var GJ = (q, $, J) => {
159
- q.push({ directory: $, files: J, dir: $ });
160
- }, FJ = () => {
161
- };
162
- function KJ(q) {
163
- return q.group ? GJ : FJ;
164
- }
165
- O0.build = KJ;
166
- });
167
- var A0 = y((J1) => {
168
- var BJ = J1 && J1.__importDefault || function(q) {
169
- return q && q.__esModule ? q : { default: q };
170
- };
171
- Object.defineProperty(J1, "__esModule", { value: true });
172
- J1.build = undefined;
173
- var M1 = BJ(import.meta.require("fs")), f0 = import.meta.require("path"), wJ = function(q, $, J) {
174
- let { queue: Z, options: { suppressErrors: Y } } = $;
175
- Z.enqueue(), M1.default.realpath(q, (j, Q) => {
176
- if (j)
177
- return Z.dequeue(Y ? null : j, $);
178
- M1.default.stat(Q, (X, U) => {
179
- if (X)
180
- return Z.dequeue(Y ? null : X, $);
181
- if (U.isDirectory() && E0(q, Q, $))
182
- return Z.dequeue(null, $);
183
- J(U, Q), Z.dequeue(null, $);
184
- });
185
- });
186
- }, MJ = function(q, $, J) {
187
- let { queue: Z, options: { suppressErrors: Y } } = $;
188
- Z.enqueue();
189
- try {
190
- let j = M1.default.realpathSync(q), Q = M1.default.statSync(j);
191
- if (Q.isDirectory() && E0(q, j, $))
192
- return;
193
- J(Q, j);
194
- } catch (j) {
195
- if (!Y)
196
- throw j;
197
- }
198
- };
199
- function VJ(q, $) {
200
- if (!q.resolveSymlinks || q.excludeSymlinks)
201
- return null;
202
- return $ ? MJ : wJ;
203
- }
204
- J1.build = VJ;
205
- function E0(q, $, J) {
206
- if (J.options.useRealPaths)
207
- return NJ($, J);
208
- let Z = f0.dirname(q), Y = 1;
209
- while (Z !== J.root && Y < 2) {
210
- let j = J.symlinks.get(Z);
211
- if (!!j && (j === $ || j.startsWith($) || $.startsWith(j)))
212
- Y++;
213
- else
214
- Z = f0.dirname(Z);
215
- }
216
- return J.symlinks.set(q, $), Y > 1;
217
- }
218
- function NJ(q, $) {
219
- return $.visited.includes(q + $.options.pathSeparator);
220
- }
221
- });
222
- var x0 = y((T0) => {
223
- Object.defineProperty(T0, "__esModule", { value: true });
224
- T0.build = undefined;
225
- var HJ = (q) => {
226
- return q.counts;
227
- }, IJ = (q) => {
228
- return q.groups;
229
- }, WJ = (q) => {
230
- return q.paths;
231
- }, _J = (q) => {
232
- return q.paths.slice(0, q.options.maxFiles);
233
- }, OJ = (q, $, J) => {
234
- return V1($, J, q.counts, q.options.suppressErrors), null;
235
- }, RJ = (q, $, J) => {
236
- return V1($, J, q.paths, q.options.suppressErrors), null;
237
- }, PJ = (q, $, J) => {
238
- return V1($, J, q.paths.slice(0, q.options.maxFiles), q.options.suppressErrors), null;
239
- }, fJ = (q, $, J) => {
240
- return V1($, J, q.groups, q.options.suppressErrors), null;
241
- };
242
- function V1(q, $, J, Z) {
243
- if (q && !Z)
244
- $(q, J);
245
- else
246
- $(null, J);
247
- }
248
- function EJ(q, $) {
249
- let { onlyCounts: J, group: Z, maxFiles: Y } = q;
250
- if (J)
251
- return $ ? HJ : OJ;
252
- else if (Z)
253
- return $ ? IJ : fJ;
254
- else if (Y)
255
- return $ ? _J : PJ;
256
- else
257
- return $ ? WJ : RJ;
258
- }
259
- T0.build = EJ;
260
- });
261
- var D0 = y((Z1) => {
262
- var AJ = Z1 && Z1.__importDefault || function(q) {
263
- return q && q.__esModule ? q : { default: q };
264
- };
265
- Object.defineProperty(Z1, "__esModule", { value: true });
266
- Z1.build = undefined;
267
- var y0 = AJ(import.meta.require("fs")), C0 = { withFileTypes: true }, TJ = (q, $, J, Z, Y) => {
268
- if (Z < 0)
269
- return q.queue.dequeue(null, q);
270
- q.visited.push($), q.counts.directories++, q.queue.enqueue(), y0.default.readdir($ || ".", C0, (j, Q = []) => {
271
- Y(Q, J, Z), q.queue.dequeue(q.options.suppressErrors ? null : j, q);
272
- });
273
- }, SJ = (q, $, J, Z, Y) => {
274
- if (Z < 0)
275
- return;
276
- q.visited.push($), q.counts.directories++;
277
- let j = [];
278
- try {
279
- j = y0.default.readdirSync($ || ".", C0);
280
- } catch (Q) {
281
- if (!q.options.suppressErrors)
282
- throw Q;
283
- }
284
- Y(j, J, Z);
285
- };
286
- function xJ(q) {
287
- return q ? SJ : TJ;
288
- }
289
- Z1.build = xJ;
290
- });
291
- var v0 = y((L0) => {
292
- Object.defineProperty(L0, "__esModule", { value: true });
293
- L0.Queue = undefined;
294
-
295
- class k0 {
296
- onQueueEmpty;
297
- count = 0;
298
- constructor(q) {
299
- this.onQueueEmpty = q;
300
- }
301
- enqueue() {
302
- this.count++;
303
- }
304
- dequeue(q, $) {
305
- if (--this.count <= 0 || q)
306
- this.onQueueEmpty(q, $);
307
- }
308
- }
309
- L0.Queue = k0;
310
- });
311
- var m0 = y((h0) => {
312
- Object.defineProperty(h0, "__esModule", { value: true });
313
- h0.Counter = undefined;
314
-
315
- class g0 {
316
- _files = 0;
317
- _directories = 0;
318
- set files(q) {
319
- this._files = q;
320
- }
321
- get files() {
322
- return this._files;
323
- }
324
- set directories(q) {
325
- this._directories = q;
326
- }
327
- get directories() {
328
- return this._directories;
329
- }
330
- get dirs() {
331
- return this._directories;
332
- }
333
- }
334
- h0.Counter = g0;
335
- });
336
- var x1 = y((i) => {
337
- var yJ = i && i.__createBinding || (Object.create ? function(q, $, J, Z) {
338
- if (Z === undefined)
339
- Z = J;
340
- var Y = Object.getOwnPropertyDescriptor($, J);
341
- if (!Y || ("get" in Y ? !$.__esModule : Y.writable || Y.configurable))
342
- Y = { enumerable: true, get: function() {
343
- return $[J];
344
- } };
345
- Object.defineProperty(q, Z, Y);
346
- } : function(q, $, J, Z) {
347
- if (Z === undefined)
348
- Z = J;
349
- q[Z] = $[J];
350
- }), CJ = i && i.__setModuleDefault || (Object.create ? function(q, $) {
351
- Object.defineProperty(q, "default", { enumerable: true, value: $ });
352
- } : function(q, $) {
353
- q.default = $;
354
- }), a = i && i.__importStar || function(q) {
355
- if (q && q.__esModule)
356
- return q;
357
- var $ = {};
358
- if (q != null) {
359
- for (var J in q)
360
- if (J !== "default" && Object.prototype.hasOwnProperty.call(q, J))
361
- yJ($, q, J);
362
- }
363
- return CJ($, q), $;
364
- };
365
- Object.defineProperty(i, "__esModule", { value: true });
366
- i.Walker = undefined;
367
- var d0 = import.meta.require("path"), T1 = A1(), S1 = a(K0()), DJ = a(M0()), kJ = a(H0()), LJ = a(_0()), bJ = a(P0()), vJ = a(A0()), gJ = a(x0()), hJ = a(D0()), uJ = v0(), mJ = m0();
368
-
369
- class c0 {
370
- root;
371
- isSynchronous;
372
- state;
373
- joinPath;
374
- pushDirectory;
375
- pushFile;
376
- getArray;
377
- groupFiles;
378
- resolveSymlink;
379
- walkDirectory;
380
- callbackInvoker;
381
- constructor(q, $, J) {
382
- this.isSynchronous = !J, this.callbackInvoker = gJ.build($, this.isSynchronous), this.root = T1.normalizePath(q, $), this.state = { root: this.root.slice(0, -1), paths: [""].slice(0, 0), groups: [], counts: new mJ.Counter, options: $, queue: new uJ.Queue((Z, Y) => this.callbackInvoker(Y, Z, J)), symlinks: new Map, visited: [""].slice(0, 0) }, this.joinPath = S1.build(this.root, $), this.pushDirectory = DJ.build(this.root, $), this.pushFile = kJ.build($), this.getArray = LJ.build($), this.groupFiles = bJ.build($), this.resolveSymlink = vJ.build($, this.isSynchronous), this.walkDirectory = hJ.build(this.isSynchronous);
383
- }
384
- start() {
385
- return this.walkDirectory(this.state, this.root, this.root, this.state.options.maxDepth, this.walk), this.isSynchronous ? this.callbackInvoker(this.state, null) : null;
386
- }
387
- walk = (q, $, J) => {
388
- let { paths: Z, options: { filters: Y, resolveSymlinks: j, excludeSymlinks: Q, exclude: X, maxFiles: U, signal: z, useRealPaths: G, pathSeparator: V } } = this.state;
389
- if (z && z.aborted || U && Z.length > U)
390
- return;
391
- this.pushDirectory($, Z, Y);
392
- let H = this.getArray(this.state.paths);
393
- for (let W = 0;W < q.length; ++W) {
394
- let I = q[W];
395
- if (I.isFile() || I.isSymbolicLink() && !j && !Q) {
396
- let _ = this.joinPath(I.name, $);
397
- this.pushFile(_, H, this.state.counts, Y);
398
- } else if (I.isDirectory()) {
399
- let _ = S1.joinDirectoryPath(I.name, $, this.state.options.pathSeparator);
400
- if (X && X(I.name, _))
401
- continue;
402
- this.walkDirectory(this.state, _, _, J - 1, this.walk);
403
- } else if (I.isSymbolicLink() && this.resolveSymlink) {
404
- let _ = S1.joinPathWithBasePath(I.name, $);
405
- this.resolveSymlink(_, this.state, (S, E) => {
406
- if (S.isDirectory()) {
407
- if (E = T1.normalizePath(E, this.state.options), X && X(I.name, E))
408
- return;
409
- this.walkDirectory(this.state, E, G ? E : _ + V, J - 1, this.walk);
410
- } else {
411
- E = G ? E : _;
412
- let A = d0.basename(E), m = T1.normalizePath(d0.dirname(E), this.state.options);
413
- E = this.joinPath(A, m), this.pushFile(E, H, this.state.counts, Y);
414
- }
415
- });
416
- }
417
- }
418
- this.groupFiles(this.state.groups, $, H);
419
- };
420
- }
421
- i.Walker = c0;
422
- });
423
- var s0 = y((p0) => {
424
- Object.defineProperty(p0, "__esModule", { value: true });
425
- p0.callback = p0.promise = undefined;
426
- var dJ = x1();
427
- function cJ(q, $) {
428
- return new Promise((J, Z) => {
429
- l0(q, $, (Y, j) => {
430
- if (Y)
431
- return Z(Y);
432
- J(j);
433
- });
434
- });
435
- }
436
- p0.promise = cJ;
437
- function l0(q, $, J) {
438
- new dJ.Walker(q, $, J).start();
439
- }
440
- p0.callback = l0;
441
- });
442
- var o0 = y((n0) => {
443
- Object.defineProperty(n0, "__esModule", { value: true });
444
- n0.sync = undefined;
445
- var pJ = x1();
446
- function iJ(q, $) {
447
- return new pJ.Walker(q, $).start();
448
- }
449
- n0.sync = iJ;
450
- });
451
- var $q = y((e0) => {
452
- Object.defineProperty(e0, "__esModule", { value: true });
453
- e0.APIBuilder = undefined;
454
- var a0 = s0(), sJ = o0();
455
-
456
- class t0 {
457
- root;
458
- options;
459
- constructor(q, $) {
460
- this.root = q, this.options = $;
461
- }
462
- withPromise() {
463
- return a0.promise(this.root, this.options);
464
- }
465
- withCallback(q) {
466
- a0.callback(this.root, this.options, q);
467
- }
468
- sync() {
469
- return sJ.sync(this.root, this.options);
470
- }
471
- }
472
- e0.APIBuilder = t0;
473
- });
474
- var j1 = y((I8, Zq) => {
475
- var Jq = { DOT_LITERAL: "\\.", PLUS_LITERAL: "\\+", QMARK_LITERAL: "\\?", SLASH_LITERAL: "\\/", ONE_CHAR: "(?=.)", QMARK: "[^/]", END_ANCHOR: "(?:\\/|$)", DOTS_SLASH: "\\.{1,2}(?:\\/|$)", NO_DOT: "(?!\\.)", NO_DOTS: "(?!(?:^|\\/)\\.{1,2}(?:\\/|$))", NO_DOT_SLASH: "(?!\\.{0,1}(?:\\/|$))", NO_DOTS_SLASH: "(?!\\.{1,2}(?:\\/|$))", QMARK_NO_DOT: "[^.\\/]", STAR: "[^/]*?", START_ANCHOR: "(?:^|\\/)", SEP: "/" }, nJ = { ...Jq, SLASH_LITERAL: "[\\\\/]", QMARK: "[^\\\\/]", STAR: "[^\\\\/]*?", DOTS_SLASH: "\\.{1,2}(?:[\\\\/]|$)", NO_DOT: "(?!\\.)", NO_DOTS: "(?!(?:^|[\\\\/])\\.{1,2}(?:[\\\\/]|$))", NO_DOT_SLASH: "(?!\\.{0,1}(?:[\\\\/]|$))", NO_DOTS_SLASH: "(?!\\.{1,2}(?:[\\\\/]|$))", QMARK_NO_DOT: "[^.\\\\/]", START_ANCHOR: "(?:^|[\\\\/])", END_ANCHOR: "(?:[\\\\/]|$)", SEP: "\\" }, rJ = { alnum: "a-zA-Z0-9", alpha: "a-zA-Z", ascii: "\\x00-\\x7F", blank: " \\t", cntrl: "\\x00-\\x1F\\x7F", digit: "0-9", graph: "\\x21-\\x7E", lower: "a-z", print: "\\x20-\\x7E ", punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~', space: " \\t\\r\\n\\v\\f", upper: "A-Z", word: "A-Za-z0-9_", xdigit: "A-Fa-f0-9" };
476
- Zq.exports = { MAX_LENGTH: 65536, POSIX_REGEX_SOURCE: rJ, REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g, REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/, REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/, REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g, REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g, REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g, REPLACEMENTS: { "***": "*", "**/**": "**", "**/**/**": "**" }, CHAR_0: 48, CHAR_9: 57, CHAR_UPPERCASE_A: 65, CHAR_LOWERCASE_A: 97, CHAR_UPPERCASE_Z: 90, CHAR_LOWERCASE_Z: 122, CHAR_LEFT_PARENTHESES: 40, CHAR_RIGHT_PARENTHESES: 41, CHAR_ASTERISK: 42, CHAR_AMPERSAND: 38, CHAR_AT: 64, CHAR_BACKWARD_SLASH: 92, CHAR_CARRIAGE_RETURN: 13, CHAR_CIRCUMFLEX_ACCENT: 94, CHAR_COLON: 58, CHAR_COMMA: 44, CHAR_DOT: 46, CHAR_DOUBLE_QUOTE: 34, CHAR_EQUAL: 61, CHAR_EXCLAMATION_MARK: 33, CHAR_FORM_FEED: 12, CHAR_FORWARD_SLASH: 47, CHAR_GRAVE_ACCENT: 96, CHAR_HASH: 35, CHAR_HYPHEN_MINUS: 45, CHAR_LEFT_ANGLE_BRACKET: 60, CHAR_LEFT_CURLY_BRACE: 123, CHAR_LEFT_SQUARE_BRACKET: 91, CHAR_LINE_FEED: 10, CHAR_NO_BREAK_SPACE: 160, CHAR_PERCENT: 37, CHAR_PLUS: 43, CHAR_QUESTION_MARK: 63, CHAR_RIGHT_ANGLE_BRACKET: 62, CHAR_RIGHT_CURLY_BRACE: 125, CHAR_RIGHT_SQUARE_BRACKET: 93, CHAR_SEMICOLON: 59, CHAR_SINGLE_QUOTE: 39, CHAR_SPACE: 32, CHAR_TAB: 9, CHAR_UNDERSCORE: 95, CHAR_VERTICAL_LINE: 124, CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279, extglobChars(q) {
477
- return { "!": { type: "negate", open: "(?:(?!(?:", close: `))${q.STAR})` }, "?": { type: "qmark", open: "(?:", close: ")?" }, "+": { type: "plus", open: "(?:", close: ")+" }, "*": { type: "star", open: "(?:", close: ")*" }, "@": { type: "at", open: "(?:", close: ")" } };
478
- }, globChars(q) {
479
- return q === true ? nJ : Jq;
480
- } };
481
- });
482
- var X1 = y((qZ) => {
483
- var { REGEX_BACKSLASH: oJ, REGEX_REMOVE_BACKSLASH: aJ, REGEX_SPECIAL_CHARS: tJ, REGEX_SPECIAL_CHARS_GLOBAL: eJ } = j1();
484
- qZ.isObject = (q) => q !== null && typeof q === "object" && !Array.isArray(q);
485
- qZ.hasRegexChars = (q) => tJ.test(q);
486
- qZ.isRegexChar = (q) => q.length === 1 && qZ.hasRegexChars(q);
487
- qZ.escapeRegex = (q) => q.replace(eJ, "\\$1");
488
- qZ.toPosixSlashes = (q) => q.replace(oJ, "/");
489
- qZ.isWindows = () => {
490
- if (typeof navigator !== "undefined" && navigator.platform) {
491
- let q = navigator.platform.toLowerCase();
492
- return q === "win32" || q === "windows";
493
- }
494
- if (typeof process !== "undefined" && process.platform)
495
- return process.platform === "win32";
496
- return false;
497
- };
498
- qZ.removeBackslashes = (q) => {
499
- return q.replace(aJ, ($) => {
500
- return $ === "\\" ? "" : $;
501
- });
502
- };
503
- qZ.escapeLast = (q, $, J) => {
504
- let Z = q.lastIndexOf($, J);
505
- if (Z === -1)
506
- return q;
507
- if (q[Z - 1] === "\\")
508
- return qZ.escapeLast(q, $, Z - 1);
509
- return `${q.slice(0, Z)}\\${q.slice(Z)}`;
510
- };
511
- qZ.removePrefix = (q, $ = {}) => {
512
- let J = q;
513
- if (J.startsWith("./"))
514
- J = J.slice(2), $.prefix = "./";
515
- return J;
516
- };
517
- qZ.wrapOutput = (q, $ = {}, J = {}) => {
518
- let Z = J.contains ? "" : "^", Y = J.contains ? "" : "$", j = `${Z}(?:${q})${Y}`;
519
- if ($.negated === true)
520
- j = `(?:^(?!${j}).*$)`;
521
- return j;
522
- };
523
- qZ.basename = (q, { windows: $ } = {}) => {
524
- let J = q.split($ ? /[\\/]/ : "/"), Z = J[J.length - 1];
525
- if (Z === "")
526
- return J[J.length - 2];
527
- return Z;
528
- };
529
- });
530
- var Bq = y((_8, Kq) => {
531
- var Xq = X1(), { CHAR_ASTERISK: y1, CHAR_AT: GZ, CHAR_BACKWARD_SLASH: Q1, CHAR_COMMA: FZ, CHAR_DOT: C1, CHAR_EXCLAMATION_MARK: D1, CHAR_FORWARD_SLASH: Fq, CHAR_LEFT_CURLY_BRACE: k1, CHAR_LEFT_PARENTHESES: L1, CHAR_LEFT_SQUARE_BRACKET: KZ, CHAR_PLUS: BZ, CHAR_QUESTION_MARK: Qq, CHAR_RIGHT_CURLY_BRACE: wZ, CHAR_RIGHT_PARENTHESES: Uq, CHAR_RIGHT_SQUARE_BRACKET: MZ } = j1(), zq = (q) => {
532
- return q === Fq || q === Q1;
533
- }, Gq = (q) => {
534
- if (q.isPrefix !== true)
535
- q.depth = q.isGlobstar ? 1 / 0 : 1;
536
- }, VZ = (q, $) => {
537
- let J = $ || {}, Z = q.length - 1, Y = J.parts === true || J.scanToEnd === true, j = [], Q = [], X = [], U = q, z = -1, G = 0, V = 0, H = false, W = false, I = false, _ = false, S = false, E = false, A = false, m = false, t = false, h = false, g = 0, c, O, P = { value: "", depth: 0, isGlob: false }, B = () => z >= Z, d = () => U.charCodeAt(z + 1), b = () => {
538
- return c = O, U.charCodeAt(++z);
539
- };
540
- while (z < Z) {
541
- O = b();
542
- let T;
543
- if (O === Q1) {
544
- if (A = P.backslashes = true, O = b(), O === k1)
545
- E = true;
546
- continue;
547
- }
548
- if (E === true || O === k1) {
549
- g++;
550
- while (B() !== true && (O = b())) {
551
- if (O === Q1) {
552
- A = P.backslashes = true, b();
553
- continue;
554
- }
555
- if (O === k1) {
556
- g++;
557
- continue;
558
- }
559
- if (E !== true && O === C1 && (O = b()) === C1) {
560
- if (H = P.isBrace = true, I = P.isGlob = true, h = true, Y === true)
561
- continue;
562
- break;
563
- }
564
- if (E !== true && O === FZ) {
565
- if (H = P.isBrace = true, I = P.isGlob = true, h = true, Y === true)
566
- continue;
567
- break;
568
- }
569
- if (O === wZ) {
570
- if (g--, g === 0) {
571
- E = false, H = P.isBrace = true, h = true;
572
- break;
573
- }
574
- }
575
- }
576
- if (Y === true)
577
- continue;
578
- break;
579
- }
580
- if (O === Fq) {
581
- if (j.push(z), Q.push(P), P = { value: "", depth: 0, isGlob: false }, h === true)
582
- continue;
583
- if (c === C1 && z === G + 1) {
584
- G += 2;
585
- continue;
586
- }
587
- V = z + 1;
588
- continue;
589
- }
590
- if (J.noext !== true) {
591
- if ((O === BZ || O === GZ || O === y1 || O === Qq || O === D1) === true && d() === L1) {
592
- if (I = P.isGlob = true, _ = P.isExtglob = true, h = true, O === D1 && z === G)
593
- t = true;
594
- if (Y === true) {
595
- while (B() !== true && (O = b())) {
596
- if (O === Q1) {
597
- A = P.backslashes = true, O = b();
598
- continue;
599
- }
600
- if (O === Uq) {
601
- I = P.isGlob = true, h = true;
602
- break;
603
- }
604
- }
605
- continue;
606
- }
607
- break;
608
- }
609
- }
610
- if (O === y1) {
611
- if (c === y1)
612
- S = P.isGlobstar = true;
613
- if (I = P.isGlob = true, h = true, Y === true)
614
- continue;
615
- break;
616
- }
617
- if (O === Qq) {
618
- if (I = P.isGlob = true, h = true, Y === true)
619
- continue;
620
- break;
621
- }
622
- if (O === KZ) {
623
- while (B() !== true && (T = b())) {
624
- if (T === Q1) {
625
- A = P.backslashes = true, b();
626
- continue;
627
- }
628
- if (T === MZ) {
629
- W = P.isBracket = true, I = P.isGlob = true, h = true;
630
- break;
631
- }
632
- }
633
- if (Y === true)
634
- continue;
635
- break;
636
- }
637
- if (J.nonegate !== true && O === D1 && z === G) {
638
- m = P.negated = true, G++;
639
- continue;
640
- }
641
- if (J.noparen !== true && O === L1) {
642
- if (I = P.isGlob = true, Y === true) {
643
- while (B() !== true && (O = b())) {
644
- if (O === L1) {
645
- A = P.backslashes = true, O = b();
646
- continue;
647
- }
648
- if (O === Uq) {
649
- h = true;
650
- break;
651
- }
652
- }
653
- continue;
654
- }
655
- break;
656
- }
657
- if (I === true) {
658
- if (h = true, Y === true)
659
- continue;
660
- break;
661
- }
662
- }
663
- if (J.noext === true)
664
- _ = false, I = false;
665
- let k = U, F = "", K = "";
666
- if (G > 0)
667
- F = U.slice(0, G), U = U.slice(G), V -= G;
668
- if (k && I === true && V > 0)
669
- k = U.slice(0, V), K = U.slice(V);
670
- else if (I === true)
671
- k = "", K = U;
672
- else
673
- k = U;
674
- if (k && k !== "" && k !== "/" && k !== U) {
675
- if (zq(k.charCodeAt(k.length - 1)))
676
- k = k.slice(0, -1);
677
- }
678
- if (J.unescape === true) {
679
- if (K)
680
- K = Xq.removeBackslashes(K);
681
- if (k && A === true)
682
- k = Xq.removeBackslashes(k);
683
- }
684
- let l = { prefix: F, input: q, start: G, base: k, glob: K, isBrace: H, isBracket: W, isGlob: I, isExtglob: _, isGlobstar: S, negated: m, negatedExtglob: t };
685
- if (J.tokens === true) {
686
- if (l.maxDepth = 0, !zq(O))
687
- Q.push(P);
688
- l.tokens = Q;
689
- }
690
- if (J.parts === true || J.tokens === true) {
691
- let T;
692
- for (let C = 0;C < j.length; C++) {
693
- let n = T ? T + 1 : G, p = j[C], o = q.slice(n, p);
694
- if (J.tokens) {
695
- if (C === 0 && G !== 0)
696
- Q[C].isPrefix = true, Q[C].value = F;
697
- else
698
- Q[C].value = o;
699
- Gq(Q[C]), l.maxDepth += Q[C].depth;
700
- }
701
- if (C !== 0 || o !== "")
702
- X.push(o);
703
- T = p;
704
- }
705
- if (T && T + 1 < q.length) {
706
- let C = q.slice(T + 1);
707
- if (X.push(C), J.tokens)
708
- Q[Q.length - 1].value = C, Gq(Q[Q.length - 1]), l.maxDepth += Q[Q.length - 1].depth;
709
- }
710
- l.slashes = j, l.parts = X;
711
- }
712
- return l;
713
- };
714
- Kq.exports = VZ;
715
- });
716
- var Vq = y((O8, Mq) => {
717
- var N1 = j1(), s = X1(), { MAX_LENGTH: H1, POSIX_REGEX_SOURCE: NZ, REGEX_NON_SPECIAL_CHARS: HZ, REGEX_SPECIAL_CHARS_BACKREF: IZ, REPLACEMENTS: wq } = N1, WZ = (q, $) => {
718
- if (typeof $.expandRange === "function")
719
- return $.expandRange(...q, $);
720
- q.sort();
721
- let J = `[${q.join("-")}]`;
722
- try {
723
- new RegExp(J);
724
- } catch (Z) {
725
- return q.map((Y) => s.escapeRegex(Y)).join("..");
726
- }
727
- return J;
728
- }, Y1 = (q, $) => {
729
- return `Missing ${q}: "${$}" - use "\\\\${$}" to match literal characters`;
730
- }, b1 = (q, $) => {
731
- if (typeof q !== "string")
732
- throw new TypeError("Expected a string");
733
- q = wq[q] || q;
734
- let J = { ...$ }, Z = typeof J.maxLength === "number" ? Math.min(H1, J.maxLength) : H1, Y = q.length;
735
- if (Y > Z)
736
- throw new SyntaxError(`Input length: ${Y}, exceeds maximum allowed length: ${Z}`);
737
- let j = { type: "bos", value: "", output: J.prepend || "" }, Q = [j], X = J.capture ? "" : "?:", U = N1.globChars(J.windows), z = N1.extglobChars(U), { DOT_LITERAL: G, PLUS_LITERAL: V, SLASH_LITERAL: H, ONE_CHAR: W, DOTS_SLASH: I, NO_DOT: _, NO_DOT_SLASH: S, NO_DOTS_SLASH: E, QMARK: A, QMARK_NO_DOT: m, STAR: t, START_ANCHOR: h } = U, g = (N) => {
738
- return `(${X}(?:(?!${h}${N.dot ? I : G}).)*?)`;
739
- }, c = J.dot ? "" : _, O = J.dot ? A : m, P = J.bash === true ? g(J) : t;
740
- if (J.capture)
741
- P = `(${P})`;
742
- if (typeof J.noext === "boolean")
743
- J.noextglob = J.noext;
744
- let B = { input: q, index: -1, start: 0, dot: J.dot === true, consumed: "", output: "", prefix: "", backtrack: false, negated: false, brackets: 0, braces: 0, parens: 0, quotes: 0, globstar: false, tokens: Q };
745
- q = s.removePrefix(q, B), Y = q.length;
746
- let d = [], b = [], k = [], F = j, K, l = () => B.index === Y - 1, T = B.peek = (N = 1) => q[B.index + N], C = B.advance = () => q[++B.index] || "", n = () => q.slice(B.index + 1), p = (N = "", x = 0) => {
747
- B.consumed += N, B.index += x;
748
- }, o = (N) => {
749
- B.output += N.output != null ? N.output : N.value, p(N.value);
750
- }, dq = () => {
751
- let N = 1;
752
- while (T() === "!" && (T(2) !== "(" || T(3) === "?"))
753
- C(), B.start++, N++;
754
- if (N % 2 === 0)
755
- return false;
756
- return B.negated = true, B.start++, true;
757
- }, z1 = (N) => {
758
- B[N]++, k.push(N);
759
- }, e = (N) => {
760
- B[N]--, k.pop();
761
- }, f = (N) => {
762
- if (F.type === "globstar") {
763
- let x = B.braces > 0 && (N.type === "comma" || N.type === "brace"), M = N.extglob === true || d.length && (N.type === "pipe" || N.type === "paren");
764
- if (N.type !== "slash" && N.type !== "paren" && !x && !M)
765
- B.output = B.output.slice(0, -F.output.length), F.type = "star", F.value = "*", F.output = P, B.output += F.output;
766
- }
767
- if (d.length && N.type !== "paren")
768
- d[d.length - 1].inner += N.value;
769
- if (N.value || N.output)
770
- o(N);
771
- if (F && F.type === "text" && N.type === "text") {
772
- F.output = (F.output || F.value) + N.value, F.value += N.value;
773
- return;
774
- }
775
- N.prev = F, Q.push(N), F = N;
776
- }, G1 = (N, x) => {
777
- let M = { ...z[x], conditions: 1, inner: "" };
778
- M.prev = F, M.parens = B.parens, M.output = B.output;
779
- let R = (J.capture ? "(" : "") + M.open;
780
- z1("parens"), f({ type: N, value: x, output: B.output ? "" : W }), f({ type: "paren", extglob: true, value: C(), output: R }), d.push(M);
781
- }, cq = (N) => {
782
- let x = N.close + (J.capture ? ")" : ""), M;
783
- if (N.type === "negate") {
784
- let R = P;
785
- if (N.inner && N.inner.length > 1 && N.inner.includes("/"))
786
- R = g(J);
787
- if (R !== P || l() || /^\)+$/.test(n()))
788
- x = N.close = `)$))${R}`;
789
- if (N.inner.includes("*") && (M = n()) && /^\.[^\\/.]+$/.test(M)) {
790
- let D = b1(M, { ...$, fastpaths: false }).output;
791
- x = N.close = `)${D})${R})`;
792
- }
793
- if (N.prev.type === "bos")
794
- B.negatedExtglob = true;
795
- }
796
- f({ type: "paren", extglob: true, value: K, output: x }), e("parens");
797
- };
798
- if (J.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(q)) {
799
- let N = false, x = q.replace(IZ, (M, R, D, u, v, W1) => {
800
- if (u === "\\")
801
- return N = true, M;
802
- if (u === "?") {
803
- if (R)
804
- return R + u + (v ? A.repeat(v.length) : "");
805
- if (W1 === 0)
806
- return O + (v ? A.repeat(v.length) : "");
807
- return A.repeat(D.length);
808
- }
809
- if (u === ".")
810
- return G.repeat(D.length);
811
- if (u === "*") {
812
- if (R)
813
- return R + u + (v ? P : "");
814
- return P;
815
- }
816
- return R ? M : `\\${M}`;
817
- });
818
- if (N === true)
819
- if (J.unescape === true)
820
- x = x.replace(/\\/g, "");
821
- else
822
- x = x.replace(/\\+/g, (M) => {
823
- return M.length % 2 === 0 ? "\\\\" : M ? "\\" : "";
824
- });
825
- if (x === q && J.contains === true)
826
- return B.output = q, B;
827
- return B.output = s.wrapOutput(x, B, $), B;
828
- }
829
- while (!l()) {
830
- if (K = C(), K === "\0")
831
- continue;
832
- if (K === "\\") {
833
- let M = T();
834
- if (M === "/" && J.bash !== true)
835
- continue;
836
- if (M === "." || M === ";")
837
- continue;
838
- if (!M) {
839
- K += "\\", f({ type: "text", value: K });
840
- continue;
841
- }
842
- let R = /^\\+/.exec(n()), D = 0;
843
- if (R && R[0].length > 2) {
844
- if (D = R[0].length, B.index += D, D % 2 !== 0)
845
- K += "\\";
846
- }
847
- if (J.unescape === true)
848
- K = C();
849
- else
850
- K += C();
851
- if (B.brackets === 0) {
852
- f({ type: "text", value: K });
853
- continue;
854
- }
855
- }
856
- if (B.brackets > 0 && (K !== "]" || F.value === "[" || F.value === "[^")) {
857
- if (J.posix !== false && K === ":") {
858
- let M = F.value.slice(1);
859
- if (M.includes("[")) {
860
- if (F.posix = true, M.includes(":")) {
861
- let R = F.value.lastIndexOf("["), D = F.value.slice(0, R), u = F.value.slice(R + 2), v = NZ[u];
862
- if (v) {
863
- if (F.value = D + v, B.backtrack = true, C(), !j.output && Q.indexOf(F) === 1)
864
- j.output = W;
865
- continue;
866
- }
867
- }
868
- }
869
- }
870
- if (K === "[" && T() !== ":" || K === "-" && T() === "]")
871
- K = `\\${K}`;
872
- if (K === "]" && (F.value === "[" || F.value === "[^"))
873
- K = `\\${K}`;
874
- if (J.posix === true && K === "!" && F.value === "[")
875
- K = "^";
876
- F.value += K, o({ value: K });
877
- continue;
878
- }
879
- if (B.quotes === 1 && K !== '"') {
880
- K = s.escapeRegex(K), F.value += K, o({ value: K });
881
- continue;
882
- }
883
- if (K === '"') {
884
- if (B.quotes = B.quotes === 1 ? 0 : 1, J.keepQuotes === true)
885
- f({ type: "text", value: K });
886
- continue;
887
- }
888
- if (K === "(") {
889
- z1("parens"), f({ type: "paren", value: K });
890
- continue;
891
- }
892
- if (K === ")") {
893
- if (B.parens === 0 && J.strictBrackets === true)
894
- throw new SyntaxError(Y1("opening", "("));
895
- let M = d[d.length - 1];
896
- if (M && B.parens === M.parens + 1) {
897
- cq(d.pop());
898
- continue;
899
- }
900
- f({ type: "paren", value: K, output: B.parens ? ")" : "\\)" }), e("parens");
901
- continue;
902
- }
903
- if (K === "[") {
904
- if (J.nobracket === true || !n().includes("]")) {
905
- if (J.nobracket !== true && J.strictBrackets === true)
906
- throw new SyntaxError(Y1("closing", "]"));
907
- K = `\\${K}`;
908
- } else
909
- z1("brackets");
910
- f({ type: "bracket", value: K });
911
- continue;
912
- }
913
- if (K === "]") {
914
- if (J.nobracket === true || F && F.type === "bracket" && F.value.length === 1) {
915
- f({ type: "text", value: K, output: `\\${K}` });
916
- continue;
917
- }
918
- if (B.brackets === 0) {
919
- if (J.strictBrackets === true)
920
- throw new SyntaxError(Y1("opening", "["));
921
- f({ type: "text", value: K, output: `\\${K}` });
922
- continue;
923
- }
924
- e("brackets");
925
- let M = F.value.slice(1);
926
- if (F.posix !== true && M[0] === "^" && !M.includes("/"))
927
- K = `/${K}`;
928
- if (F.value += K, o({ value: K }), J.literalBrackets === false || s.hasRegexChars(M))
929
- continue;
930
- let R = s.escapeRegex(F.value);
931
- if (B.output = B.output.slice(0, -F.value.length), J.literalBrackets === true) {
932
- B.output += R, F.value = R;
933
- continue;
934
- }
935
- F.value = `(${X}${R}|${F.value})`, B.output += F.value;
936
- continue;
937
- }
938
- if (K === "{" && J.nobrace !== true) {
939
- z1("braces");
940
- let M = { type: "brace", value: K, output: "(", outputIndex: B.output.length, tokensIndex: B.tokens.length };
941
- b.push(M), f(M);
942
- continue;
943
- }
944
- if (K === "}") {
945
- let M = b[b.length - 1];
946
- if (J.nobrace === true || !M) {
947
- f({ type: "text", value: K, output: K });
948
- continue;
949
- }
950
- let R = ")";
951
- if (M.dots === true) {
952
- let D = Q.slice(), u = [];
953
- for (let v = D.length - 1;v >= 0; v--) {
954
- if (Q.pop(), D[v].type === "brace")
955
- break;
956
- if (D[v].type !== "dots")
957
- u.unshift(D[v].value);
958
- }
959
- R = WZ(u, J), B.backtrack = true;
960
- }
961
- if (M.comma !== true && M.dots !== true) {
962
- let D = B.output.slice(0, M.outputIndex), u = B.tokens.slice(M.tokensIndex);
963
- M.value = M.output = "\\{", K = R = "\\}", B.output = D;
964
- for (let v of u)
965
- B.output += v.output || v.value;
966
- }
967
- f({ type: "brace", value: K, output: R }), e("braces"), b.pop();
968
- continue;
969
- }
970
- if (K === "|") {
971
- if (d.length > 0)
972
- d[d.length - 1].conditions++;
973
- f({ type: "text", value: K });
974
- continue;
975
- }
976
- if (K === ",") {
977
- let M = K, R = b[b.length - 1];
978
- if (R && k[k.length - 1] === "braces")
979
- R.comma = true, M = "|";
980
- f({ type: "comma", value: K, output: M });
981
- continue;
982
- }
983
- if (K === "/") {
984
- if (F.type === "dot" && B.index === B.start + 1) {
985
- B.start = B.index + 1, B.consumed = "", B.output = "", Q.pop(), F = j;
986
- continue;
987
- }
988
- f({ type: "slash", value: K, output: H });
989
- continue;
990
- }
991
- if (K === ".") {
992
- if (B.braces > 0 && F.type === "dot") {
993
- if (F.value === ".")
994
- F.output = G;
995
- let M = b[b.length - 1];
996
- F.type = "dots", F.output += K, F.value += K, M.dots = true;
997
- continue;
998
- }
999
- if (B.braces + B.parens === 0 && F.type !== "bos" && F.type !== "slash") {
1000
- f({ type: "text", value: K, output: G });
1001
- continue;
1002
- }
1003
- f({ type: "dot", value: K, output: G });
1004
- continue;
1005
- }
1006
- if (K === "?") {
1007
- if (!(F && F.value === "(") && J.noextglob !== true && T() === "(" && T(2) !== "?") {
1008
- G1("qmark", K);
1009
- continue;
1010
- }
1011
- if (F && F.type === "paren") {
1012
- let R = T(), D = K;
1013
- if (F.value === "(" && !/[!=<:]/.test(R) || R === "<" && !/<([!=]|\w+>)/.test(n()))
1014
- D = `\\${K}`;
1015
- f({ type: "text", value: K, output: D });
1016
- continue;
1017
- }
1018
- if (J.dot !== true && (F.type === "slash" || F.type === "bos")) {
1019
- f({ type: "qmark", value: K, output: m });
1020
- continue;
1021
- }
1022
- f({ type: "qmark", value: K, output: A });
1023
- continue;
1024
- }
1025
- if (K === "!") {
1026
- if (J.noextglob !== true && T() === "(") {
1027
- if (T(2) !== "?" || !/[!=<:]/.test(T(3))) {
1028
- G1("negate", K);
1029
- continue;
1030
- }
1031
- }
1032
- if (J.nonegate !== true && B.index === 0) {
1033
- dq();
1034
- continue;
1035
- }
1036
- }
1037
- if (K === "+") {
1038
- if (J.noextglob !== true && T() === "(" && T(2) !== "?") {
1039
- G1("plus", K);
1040
- continue;
1041
- }
1042
- if (F && F.value === "(" || J.regex === false) {
1043
- f({ type: "plus", value: K, output: V });
1044
- continue;
1045
- }
1046
- if (F && (F.type === "bracket" || F.type === "paren" || F.type === "brace") || B.parens > 0) {
1047
- f({ type: "plus", value: K });
1048
- continue;
1049
- }
1050
- f({ type: "plus", value: V });
1051
- continue;
1052
- }
1053
- if (K === "@") {
1054
- if (J.noextglob !== true && T() === "(" && T(2) !== "?") {
1055
- f({ type: "at", extglob: true, value: K, output: "" });
1056
- continue;
1057
- }
1058
- f({ type: "text", value: K });
1059
- continue;
1060
- }
1061
- if (K !== "*") {
1062
- if (K === "$" || K === "^")
1063
- K = `\\${K}`;
1064
- let M = HZ.exec(n());
1065
- if (M)
1066
- K += M[0], B.index += M[0].length;
1067
- f({ type: "text", value: K });
1068
- continue;
1069
- }
1070
- if (F && (F.type === "globstar" || F.star === true)) {
1071
- F.type = "star", F.star = true, F.value += K, F.output = P, B.backtrack = true, B.globstar = true, p(K);
1072
- continue;
1073
- }
1074
- let N = n();
1075
- if (J.noextglob !== true && /^\([^?]/.test(N)) {
1076
- G1("star", K);
1077
- continue;
1078
- }
1079
- if (F.type === "star") {
1080
- if (J.noglobstar === true) {
1081
- p(K);
1082
- continue;
1083
- }
1084
- let M = F.prev, R = M.prev, D = M.type === "slash" || M.type === "bos", u = R && (R.type === "star" || R.type === "globstar");
1085
- if (J.bash === true && (!D || N[0] && N[0] !== "/")) {
1086
- f({ type: "star", value: K, output: "" });
1087
- continue;
1088
- }
1089
- let v = B.braces > 0 && (M.type === "comma" || M.type === "brace"), W1 = d.length && (M.type === "pipe" || M.type === "paren");
1090
- if (!D && M.type !== "paren" && !v && !W1) {
1091
- f({ type: "star", value: K, output: "" });
1092
- continue;
1093
- }
1094
- while (N.slice(0, 3) === "/**") {
1095
- let F1 = q[B.index + 4];
1096
- if (F1 && F1 !== "/")
1097
- break;
1098
- N = N.slice(3), p("/**", 3);
1099
- }
1100
- if (M.type === "bos" && l()) {
1101
- F.type = "globstar", F.value += K, F.output = g(J), B.output = F.output, B.globstar = true, p(K);
1102
- continue;
1103
- }
1104
- if (M.type === "slash" && M.prev.type !== "bos" && !u && l()) {
1105
- B.output = B.output.slice(0, -(M.output + F.output).length), M.output = `(?:${M.output}`, F.type = "globstar", F.output = g(J) + (J.strictSlashes ? ")" : "|$)"), F.value += K, B.globstar = true, B.output += M.output + F.output, p(K);
1106
- continue;
1107
- }
1108
- if (M.type === "slash" && M.prev.type !== "bos" && N[0] === "/") {
1109
- let F1 = N[1] !== undefined ? "|$" : "";
1110
- B.output = B.output.slice(0, -(M.output + F.output).length), M.output = `(?:${M.output}`, F.type = "globstar", F.output = `${g(J)}${H}|${H}${F1})`, F.value += K, B.output += M.output + F.output, B.globstar = true, p(K + C()), f({ type: "slash", value: "/", output: "" });
1111
- continue;
1112
- }
1113
- if (M.type === "bos" && N[0] === "/") {
1114
- F.type = "globstar", F.value += K, F.output = `(?:^|${H}|${g(J)}${H})`, B.output = F.output, B.globstar = true, p(K + C()), f({ type: "slash", value: "/", output: "" });
1115
- continue;
1116
- }
1117
- B.output = B.output.slice(0, -F.output.length), F.type = "globstar", F.output = g(J), F.value += K, B.output += F.output, B.globstar = true, p(K);
1118
- continue;
1119
- }
1120
- let x = { type: "star", value: K, output: P };
1121
- if (J.bash === true) {
1122
- if (x.output = ".*?", F.type === "bos" || F.type === "slash")
1123
- x.output = c + x.output;
1124
- f(x);
1125
- continue;
1126
- }
1127
- if (F && (F.type === "bracket" || F.type === "paren") && J.regex === true) {
1128
- x.output = K, f(x);
1129
- continue;
1130
- }
1131
- if (B.index === B.start || F.type === "slash" || F.type === "dot") {
1132
- if (F.type === "dot")
1133
- B.output += S, F.output += S;
1134
- else if (J.dot === true)
1135
- B.output += E, F.output += E;
1136
- else
1137
- B.output += c, F.output += c;
1138
- if (T() !== "*")
1139
- B.output += W, F.output += W;
1140
- }
1141
- f(x);
1142
- }
1143
- while (B.brackets > 0) {
1144
- if (J.strictBrackets === true)
1145
- throw new SyntaxError(Y1("closing", "]"));
1146
- B.output = s.escapeLast(B.output, "["), e("brackets");
1147
- }
1148
- while (B.parens > 0) {
1149
- if (J.strictBrackets === true)
1150
- throw new SyntaxError(Y1("closing", ")"));
1151
- B.output = s.escapeLast(B.output, "("), e("parens");
1152
- }
1153
- while (B.braces > 0) {
1154
- if (J.strictBrackets === true)
1155
- throw new SyntaxError(Y1("closing", "}"));
1156
- B.output = s.escapeLast(B.output, "{"), e("braces");
1157
- }
1158
- if (J.strictSlashes !== true && (F.type === "star" || F.type === "bracket"))
1159
- f({ type: "maybe_slash", value: "", output: `${H}?` });
1160
- if (B.backtrack === true) {
1161
- B.output = "";
1162
- for (let N of B.tokens)
1163
- if (B.output += N.output != null ? N.output : N.value, N.suffix)
1164
- B.output += N.suffix;
1165
- }
1166
- return B;
1167
- };
1168
- b1.fastpaths = (q, $) => {
1169
- let J = { ...$ }, Z = typeof J.maxLength === "number" ? Math.min(H1, J.maxLength) : H1, Y = q.length;
1170
- if (Y > Z)
1171
- throw new SyntaxError(`Input length: ${Y}, exceeds maximum allowed length: ${Z}`);
1172
- q = wq[q] || q;
1173
- let { DOT_LITERAL: j, SLASH_LITERAL: Q, ONE_CHAR: X, DOTS_SLASH: U, NO_DOT: z, NO_DOTS: G, NO_DOTS_SLASH: V, STAR: H, START_ANCHOR: W } = N1.globChars(J.windows), I = J.dot ? G : z, _ = J.dot ? V : z, S = J.capture ? "" : "?:", E = { negated: false, prefix: "" }, A = J.bash === true ? ".*?" : H;
1174
- if (J.capture)
1175
- A = `(${A})`;
1176
- let m = (c) => {
1177
- if (c.noglobstar === true)
1178
- return A;
1179
- return `(${S}(?:(?!${W}${c.dot ? U : j}).)*?)`;
1180
- }, t = (c) => {
1181
- switch (c) {
1182
- case "*":
1183
- return `${I}${X}${A}`;
1184
- case ".*":
1185
- return `${j}${X}${A}`;
1186
- case "*.*":
1187
- return `${I}${A}${j}${X}${A}`;
1188
- case "*/*":
1189
- return `${I}${A}${Q}${X}${_}${A}`;
1190
- case "**":
1191
- return I + m(J);
1192
- case "**/*":
1193
- return `(?:${I}${m(J)}${Q})?${_}${X}${A}`;
1194
- case "**/*.*":
1195
- return `(?:${I}${m(J)}${Q})?${_}${A}${j}${X}${A}`;
1196
- case "**/.*":
1197
- return `(?:${I}${m(J)}${Q})?${j}${X}${A}`;
1198
- default: {
1199
- let O = /^(.*?)\.(\w+)$/.exec(c);
1200
- if (!O)
1201
- return;
1202
- let P = t(O[1]);
1203
- if (!P)
1204
- return;
1205
- return P + j + O[2];
1206
- }
1207
- }
1208
- }, h = s.removePrefix(q, E), g = t(h);
1209
- if (g && J.strictSlashes !== true)
1210
- g += `${Q}?`;
1211
- return g;
1212
- };
1213
- Mq.exports = b1;
1214
- });
1215
- var Iq = y((R8, Hq) => {
1216
- var _Z = Bq(), v1 = Vq(), Nq = X1(), OZ = j1(), RZ = (q) => q && typeof q === "object" && !Array.isArray(q), L = (q, $, J = false) => {
1217
- if (Array.isArray(q)) {
1218
- let G = q.map((H) => L(H, $, J));
1219
- return (H) => {
1220
- for (let W of G) {
1221
- let I = W(H);
1222
- if (I)
1223
- return I;
1224
- }
1225
- return false;
1226
- };
1227
- }
1228
- let Z = RZ(q) && q.tokens && q.input;
1229
- if (q === "" || typeof q !== "string" && !Z)
1230
- throw new TypeError("Expected pattern to be a non-empty string");
1231
- let Y = $ || {}, j = Y.windows, Q = Z ? L.compileRe(q, $) : L.makeRe(q, $, false, true), X = Q.state;
1232
- delete Q.state;
1233
- let U = () => false;
1234
- if (Y.ignore) {
1235
- let G = { ...$, ignore: null, onMatch: null, onResult: null };
1236
- U = L(Y.ignore, G, J);
1237
- }
1238
- let z = (G, V = false) => {
1239
- let { isMatch: H, match: W, output: I } = L.test(G, Q, $, { glob: q, posix: j }), _ = { glob: q, state: X, regex: Q, posix: j, input: G, output: I, match: W, isMatch: H };
1240
- if (typeof Y.onResult === "function")
1241
- Y.onResult(_);
1242
- if (H === false)
1243
- return _.isMatch = false, V ? _ : false;
1244
- if (U(G)) {
1245
- if (typeof Y.onIgnore === "function")
1246
- Y.onIgnore(_);
1247
- return _.isMatch = false, V ? _ : false;
1248
- }
1249
- if (typeof Y.onMatch === "function")
1250
- Y.onMatch(_);
1251
- return V ? _ : true;
1252
- };
1253
- if (J)
1254
- z.state = X;
1255
- return z;
1256
- };
1257
- L.test = (q, $, J, { glob: Z, posix: Y } = {}) => {
1258
- if (typeof q !== "string")
1259
- throw new TypeError("Expected input to be a string");
1260
- if (q === "")
1261
- return { isMatch: false, output: "" };
1262
- let j = J || {}, Q = j.format || (Y ? Nq.toPosixSlashes : null), X = q === Z, U = X && Q ? Q(q) : q;
1263
- if (X === false)
1264
- U = Q ? Q(q) : q, X = U === Z;
1265
- if (X === false || j.capture === true)
1266
- if (j.matchBase === true || j.basename === true)
1267
- X = L.matchBase(q, $, J, Y);
1268
- else
1269
- X = $.exec(U);
1270
- return { isMatch: Boolean(X), match: X, output: U };
1271
- };
1272
- L.matchBase = (q, $, J) => {
1273
- return ($ instanceof RegExp ? $ : L.makeRe($, J)).test(Nq.basename(q));
1274
- };
1275
- L.isMatch = (q, $, J) => L($, J)(q);
1276
- L.parse = (q, $) => {
1277
- if (Array.isArray(q))
1278
- return q.map((J) => L.parse(J, $));
1279
- return v1(q, { ...$, fastpaths: false });
1280
- };
1281
- L.scan = (q, $) => _Z(q, $);
1282
- L.compileRe = (q, $, J = false, Z = false) => {
1283
- if (J === true)
1284
- return q.output;
1285
- let Y = $ || {}, j = Y.contains ? "" : "^", Q = Y.contains ? "" : "$", X = `${j}(?:${q.output})${Q}`;
1286
- if (q && q.negated === true)
1287
- X = `^(?!${X}).*$`;
1288
- let U = L.toRegex(X, $);
1289
- if (Z === true)
1290
- U.state = q;
1291
- return U;
1292
- };
1293
- L.makeRe = (q, $ = {}, J = false, Z = false) => {
1294
- if (!q || typeof q !== "string")
1295
- throw new TypeError("Expected a non-empty string");
1296
- let Y = { negated: false, fastpaths: true };
1297
- if ($.fastpaths !== false && (q[0] === "." || q[0] === "*"))
1298
- Y.output = v1.fastpaths(q, $);
1299
- if (!Y.output)
1300
- Y = v1(q, $);
1301
- return L.compileRe(Y, $, J, Z);
1302
- };
1303
- L.toRegex = (q, $) => {
1304
- try {
1305
- let J = $ || {};
1306
- return new RegExp(q, J.flags || (J.nocase ? "i" : ""));
1307
- } catch (J) {
1308
- if ($ && $.debug === true)
1309
- throw J;
1310
- return /$^/;
1311
- }
1312
- };
1313
- L.constants = OZ;
1314
- Hq.exports = L;
1315
- });
1316
- var U1 = y((P8, Oq) => {
1317
- var Wq = Iq(), PZ = X1();
1318
- function _q(q, $, J = false) {
1319
- if ($ && ($.windows === null || $.windows === undefined))
1320
- $ = { ...$, windows: PZ.isWindows() };
1321
- return Wq(q, $, J);
1322
- }
1323
- Object.assign(_q, Wq);
1324
- Oq.exports = _q;
1325
- });
1326
- var Tq = y((Eq) => {
1327
- Object.defineProperty(Eq, "__esModule", { value: true });
1328
- Eq.Builder = undefined;
1329
- var fZ = import.meta.require("path"), Rq = $q(), Pq = null;
1330
- try {
1331
- import.meta.require.resolve("picomatch"), Pq = U1();
1332
- } catch (q) {
1333
- }
1334
-
1335
- class fq {
1336
- globCache = {};
1337
- options = { maxDepth: 1 / 0, suppressErrors: true, pathSeparator: fZ.sep, filters: [] };
1338
- globFunction;
1339
- constructor(q) {
1340
- this.options = { ...this.options, ...q }, this.globFunction = this.options.globFunction;
1341
- }
1342
- group() {
1343
- return this.options.group = true, this;
1344
- }
1345
- withPathSeparator(q) {
1346
- return this.options.pathSeparator = q, this;
1347
- }
1348
- withBasePath() {
1349
- return this.options.includeBasePath = true, this;
1350
- }
1351
- withRelativePaths() {
1352
- return this.options.relativePaths = true, this;
1353
- }
1354
- withDirs() {
1355
- return this.options.includeDirs = true, this;
1356
- }
1357
- withMaxDepth(q) {
1358
- return this.options.maxDepth = q, this;
1359
- }
1360
- withMaxFiles(q) {
1361
- return this.options.maxFiles = q, this;
1362
- }
1363
- withFullPaths() {
1364
- return this.options.resolvePaths = true, this.options.includeBasePath = true, this;
1365
- }
1366
- withErrors() {
1367
- return this.options.suppressErrors = false, this;
1368
- }
1369
- withSymlinks({ resolvePaths: q = true } = {}) {
1370
- return this.options.resolveSymlinks = true, this.options.useRealPaths = q, this.withFullPaths();
1371
- }
1372
- withAbortSignal(q) {
1373
- return this.options.signal = q, this;
1374
- }
1375
- normalize() {
1376
- return this.options.normalizePath = true, this;
1377
- }
1378
- filter(q) {
1379
- return this.options.filters.push(q), this;
1380
- }
1381
- onlyDirs() {
1382
- return this.options.excludeFiles = true, this.options.includeDirs = true, this;
1383
- }
1384
- exclude(q) {
1385
- return this.options.exclude = q, this;
1386
- }
1387
- onlyCounts() {
1388
- return this.options.onlyCounts = true, this;
1389
- }
1390
- crawl(q) {
1391
- return new Rq.APIBuilder(q || ".", this.options);
1392
- }
1393
- withGlobFunction(q) {
1394
- return this.globFunction = q, this;
1395
- }
1396
- crawlWithOptions(q, $) {
1397
- return this.options = { ...this.options, ...$ }, new Rq.APIBuilder(q || ".", this.options);
1398
- }
1399
- glob(...q) {
1400
- if (this.globFunction)
1401
- return this.globWithOptions(q);
1402
- return this.globWithOptions(q, ...[{ dot: true }]);
1403
- }
1404
- globWithOptions(q, ...$) {
1405
- let J = this.globFunction || Pq;
1406
- if (!J)
1407
- throw new Error("Please specify a glob function to use glob matching.");
1408
- var Z = this.globCache[q.join("\0")];
1409
- if (!Z)
1410
- Z = J(q, ...$), this.globCache[q.join("\0")] = Z;
1411
- return this.options.filters.push((Y) => Z(Y)), this;
1412
- }
1413
- }
1414
- Eq.Builder = fq;
1415
- });
1416
- var xq = y((Sq) => {
1417
- Object.defineProperty(Sq, "__esModule", { value: true });
1418
- });
1419
- var yq = y((r) => {
1420
- var EZ = r && r.__createBinding || (Object.create ? function(q, $, J, Z) {
1421
- if (Z === undefined)
1422
- Z = J;
1423
- var Y = Object.getOwnPropertyDescriptor($, J);
1424
- if (!Y || ("get" in Y ? !$.__esModule : Y.writable || Y.configurable))
1425
- Y = { enumerable: true, get: function() {
1426
- return $[J];
1427
- } };
1428
- Object.defineProperty(q, Z, Y);
1429
- } : function(q, $, J, Z) {
1430
- if (Z === undefined)
1431
- Z = J;
1432
- q[Z] = $[J];
1433
- }), AZ = r && r.__exportStar || function(q, $) {
1434
- for (var J in q)
1435
- if (J !== "default" && !Object.prototype.hasOwnProperty.call($, J))
1436
- EZ($, q, J);
1437
- };
1438
- Object.defineProperty(r, "__esModule", { value: true });
1439
- r.fdir = undefined;
1440
- var TZ = Tq();
1441
- Object.defineProperty(r, "fdir", { enumerable: true, get: function() {
1442
- return TZ.Builder;
1443
- } });
1444
- AZ(xq(), r);
1445
- });
1446
- function _1(q, ...$) {
1447
- if (!$.length)
1448
- return q;
1449
- let J = $.shift();
1450
- if (B1(q) && B1(J)) {
1451
- for (let Z in J)
1452
- if (Object.prototype.hasOwnProperty.call(J, Z)) {
1453
- let Y = J[Z];
1454
- if (B1(Y) && B1(q[Z]))
1455
- q[Z] = _1(q[Z], Y);
1456
- else
1457
- q[Z] = Y;
1458
- }
1459
- }
1460
- return _1(q, ...$);
1461
- }
1462
- function B1(q) {
1463
- return q && typeof q === "object" && !Array.isArray(q);
1464
- }
1465
- async function c1({ name: q, cwd: $, defaultConfig: J }) {
1466
- let Z = $ ?? rq.cwd(), Y = nq(Z, `${q}.config`);
1467
- try {
1468
- let j = await import(Y), Q = j.default || j;
1469
- return _1(J, Q);
1470
- } catch (j) {
1471
- return console.error(`Error loading config from ${Y}:`, j), J;
1472
- }
1473
- }
1474
- var q1 = await c1({ name: "dts", cwd: l1.cwd(), defaultConfig: { cwd: l1.cwd(), root: "./src", entrypoints: ["**/*.ts"], outdir: "./dist", keepComments: true, clean: true, tsconfigPath: "./tsconfig.json", verbose: false } });
1475
- function O1(q) {
1476
- if (w("params", `Cleaning parameters: ${q}`), !q.trim())
1477
- return "";
1478
- let $ = [], J = "", Z = 0, Y = false, j = "", Q = false;
1479
- for (let U of q) {
1480
- if (U === '"' || U === "\'" || U === "`") {
1481
- if (!Y)
1482
- Y = true, j = U;
1483
- else if (U === j)
1484
- Y = false;
1485
- }
1486
- if (!Y) {
1487
- if (U === "{")
1488
- Q = true, Z++;
1489
- if (U === "}")
1490
- Q = false, Z--;
1491
- if (U === "<" || U === "(")
1492
- Z++;
1493
- if (U === ">" || U === ")")
1494
- Z--;
1495
- if (U === "," && Z === 0 && !Q) {
1496
- if (J.trim())
1497
- $.push(p1(J));
1498
- J = "";
1499
- continue;
1500
- }
1501
- }
1502
- J += U;
1503
- }
1504
- if (J.trim())
1505
- $.push(p1(J));
1506
- let X = $.join(", ");
1507
- return w("params", `Cleaned parameters: ${X}`), X;
1508
- }
1509
- function p1(q) {
1510
- w("param-clean", `Cleaning parameter: ${q}`);
1511
- let $ = q.match(/^([^:]+):\s*([^=]+)(?:=\s*.+)?$/);
1512
- if ($) {
1513
- let [, Z, Y] = $, j = Y.replace(/\s*&\s*/g, " & ").replace(/\s{2,}/g, " ").trim(), Q = `${Z.trim()}: ${j}`;
1514
- return w("param-clean", `Cleaned to: ${Q}`), Q;
1515
- }
1516
- let J = q.match(/^([^=]+)=\s*(.+)$/);
1517
- if (J) {
1518
- let [, Z, Y] = J, j = G$(Y.trim()), Q = `${Z.trim()}: ${j}`;
1519
- return w("param-clean", `Inferred type: ${Q}`), Q;
1520
- }
1521
- return q.trim();
1522
- }
1523
- async function o1(q) {
1524
- try {
1525
- let $ = await Bun.file(q).text();
1526
- return oq($);
1527
- } catch ($) {
1528
- throw console.error("Failed to extract types:", $), new Error("Failed to extract and generate .d.ts file");
1529
- }
1530
- }
1531
- function oq(q) {
1532
- let $ = X$();
1533
- q.split("\n").forEach((Z) => {
1534
- if (Z.includes("import "))
1535
- q0(Z, $.importTracking);
1536
- }), A$(q, $), $.dtsLines.forEach((Z) => {
1537
- if (Z.trim() && !Z.startsWith("import"))
1538
- D$(Z, $.importTracking), k$(Z, $.importTracking);
1539
- });
1540
- let J = J$($.importTracking);
1541
- return $.dtsLines = [...J.map((Z) => `${Z};`), "", ...$.dtsLines.filter((Z) => !Z.trim().startsWith("import"))], Y$($);
1542
- }
1543
- function aq(q) {
1544
- w("signature-start", `Processing declaration: ${q}`);
1545
- let $ = S$(q);
1546
- w("signature-clean", `Clean declaration: ${$}`);
1547
- let J = tq($), Z = $.slice($.indexOf(J) + J.length).trim();
1548
- w("signature-content", `Content after name: ${Z}`);
1549
- let { generics: Y, rest: j } = eq(Z);
1550
- Z = j.trim(), w("signature-after-generics", `Remaining content: ${Z}`);
1551
- let { params: Q, rest: X } = q$(Z);
1552
- Z = X.trim(), w("signature-after-params", `Remaining content: ${Z}`);
1553
- let { returnType: U } = $$(Z);
1554
- w("signature-return", `Extracted return type: ${U}`);
1555
- let z = { name: J, generics: Y, params: Q, returnType: U };
1556
- return w("signature-final", `Final signature object: ${JSON.stringify(z, null, 2)}`), z;
1557
- }
1558
- function tq(q) {
1559
- let $ = q.match(/^(?:export\s+)?(?:async\s+)?function\s*\*?\s*([^(<\s]+)/);
1560
- if (!$)
1561
- throw new Error("Invalid function declaration");
1562
- return $[1];
1563
- }
1564
- function eq(q) {
1565
- let $ = "";
1566
- if (q.startsWith("<")) {
1567
- let J = 1, Z = 0, Y = "<", j = false, Q = "";
1568
- w("generics-input", `Starting generic extraction with: ${q}`);
1569
- for (let X = 1;X < q.length; X++) {
1570
- let U = q[X], z = X < q.length - 1 ? q[X + 1] : "", G = X > 0 ? q[X - 1] : "";
1571
- if (w("generics-char", `Processing char: ${U}, next char: ${z}, depth: ${J}, pos: ${X}`), (U === '"' || U === "\'" || U === "`") && G !== "\\") {
1572
- if (!j)
1573
- j = true, Q = U, w("generics-string", `Entering string with ${Q}`);
1574
- else if (U === Q)
1575
- j = false, w("generics-string", "Exiting string");
1576
- }
1577
- if (!j) {
1578
- if (U === "<")
1579
- J++, w("generics-depth", `Increasing depth to ${J} at pos ${X}`);
1580
- else if (U === ">") {
1581
- if (J--, w("generics-depth", `Decreasing depth to ${J} at pos ${X}`), J === 0 && z === ">") {
1582
- Y += ">>", Z = X + 1, w("generics-complete", `Found double closing bracket at pos ${X}, final buffer: ${Y}`);
1583
- break;
1584
- } else if (J === 0) {
1585
- Y += ">", Z = X, w("generics-complete", `Found single closing bracket at pos ${X}, final buffer: ${Y}`);
1586
- break;
1587
- }
1588
- }
1589
- }
1590
- if (J > 0)
1591
- Y += U, w("generics-buffer", `Current buffer: ${Y}`);
1592
- }
1593
- if (Y)
1594
- $ = Y, q = q.slice(Z + 1), w("generics-success", `Successfully extracted generics: ${$}`), w("generics-rest", `Remaining text: ${q}`);
1595
- else
1596
- w("generics-fail", `Failed to extract generics from: ${q}`);
1597
- }
1598
- return { generics: $, rest: q };
1599
- }
1600
- function q$(q) {
1601
- let $ = "";
1602
- if (q.includes("(")) {
1603
- let J = q.indexOf("("), Z = 1, Y = J + 1, j = "";
1604
- w("params-extraction-start", `Starting params extraction from pos ${Y}: ${q}`);
1605
- for (;Y < q.length; Y++) {
1606
- let Q = q[Y];
1607
- if (Q === "(")
1608
- Z++;
1609
- if (Q === ")") {
1610
- if (Z--, Z === 0) {
1611
- w("params-depth-zero", `Found closing parenthesis at pos ${Y}`);
1612
- break;
1613
- }
1614
- }
1615
- j += Q;
1616
- }
1617
- $ = j.trim(), q = q.slice(Y + 1).trim(), w("signature-params", `Extracted params: ${$}`);
1618
- }
1619
- return { params: $, rest: q };
1620
- }
1621
- function $$(q) {
1622
- let $ = "void";
1623
- if (q.startsWith(":")) {
1624
- w("return-start", `Starting return type extraction with: ${q}`), q = q.slice(1).trim();
1625
- let J = 0, Z = "", Y = 0, j = false, Q = "", X = false;
1626
- w("return-extraction", "Starting character-by-character extraction");
1627
- while (Y < q.length && !X) {
1628
- let U = q[Y], z = Y > 0 ? q[Y - 1] : "";
1629
- if (w("return-char", `Pos ${Y}: Char "${U}", Depth ${J}, InString ${j}, Buffer length ${Z.length}`), (U === '"' || U === "\'" || U === "`") && z !== "\\") {
1630
- if (!j)
1631
- j = true, Q = U, w("return-string", `Entering string with ${Q}`);
1632
- else if (U === Q)
1633
- j = false, w("return-string", "Exiting string");
1634
- }
1635
- if (!j) {
1636
- if (U === "{" || U === "<" || U === "(")
1637
- J++, w("return-depth", `Opening bracket, increasing depth to ${J}`);
1638
- else if (U === "}" || U === ">" || U === ")") {
1639
- if (J--, w("return-depth", `Closing bracket, decreasing depth to ${J}`), J === 0 && U === "}") {
1640
- if (Z += U, q.slice(Y + 1).trim()[0] === "{") {
1641
- w("return-end", `Found end of return type at pos ${Y}, next char is function body`), X = true;
1642
- break;
1643
- }
1644
- }
1645
- }
1646
- if (J === 0 && U === ";") {
1647
- w("return-end", "Found semicolon at depth 0"), X = true;
1648
- break;
1649
- }
1650
- }
1651
- Z += U, w("return-buffer", `Updated buffer: ${Z}`), Y++;
1652
- }
1653
- $ = Z.trim(), w("return-final", `Final extracted return type: ${$}`);
1654
- }
1655
- return { returnType: $ };
1656
- }
1657
- function f1(q) {
1658
- w("extract-function", `Extracting function type from: ${q}`);
1659
- let $ = q.trim(), J = 0, Z = $.length;
1660
- if (!$.startsWith("(")) {
1661
- let H = $.match(/^function\s*\w*\s*\((.*?)\)/s);
1662
- if (H) {
1663
- let [, W] = H, I = O1(W || ""), _ = $.match(/\):\s*([^{;]+)(?:[{;]|$)/), S = _ ? L$(_[1]) : "unknown";
1664
- return `(${I}) => ${S}`;
1665
- }
1666
- return null;
1667
- }
1668
- J++;
1669
- let Y = 1, j = J, Q = false, X = "";
1670
- for (;J < Z; J++) {
1671
- let H = $[J], W = J > 0 ? $[J - 1] : "";
1672
- if (Q) {
1673
- if (H === X && W !== "\\")
1674
- Q = false;
1675
- else if (H === "\\")
1676
- J++;
1677
- } else if (H === '"' || H === "\'" || H === "`")
1678
- Q = true, X = H;
1679
- else if (H === "(")
1680
- Y++;
1681
- else if (H === ")") {
1682
- if (Y--, Y === 0)
1683
- break;
1684
- }
1685
- }
1686
- if (Y !== 0)
1687
- return w("extract-function", "Unbalanced parentheses in function parameters"), null;
1688
- let U = J, z = $.slice(j, U);
1689
- J++;
1690
- while (J < Z && /\s/.test($[J]))
1691
- J++;
1692
- let G = "unknown";
1693
- if ($[J] === ":") {
1694
- J++;
1695
- while (J < Z && /\s/.test($[J]))
1696
- J++;
1697
- let H = J;
1698
- while (J < Z && !$.startsWith("=>", J) && $[J] !== "{")
1699
- J++;
1700
- let W = J;
1701
- G = $.slice(H, W).trim();
1702
- }
1703
- while (J < Z && /\s/.test($[J]))
1704
- J++;
1705
- if ($.startsWith("=>", J))
1706
- J += 2;
1707
- else
1708
- return w("extract-function", 'Function expression missing "=>"'), null;
1709
- let V = O1(z || "");
1710
- return w("extract-function", `Extracted function type: (${V}) => ${G}`), `(${V}) => ${G}`;
1711
- }
1712
- function J$(q) {
1713
- let $ = [], J = new Set;
1714
- w("import-gen", `Generating optimized imports. ${q.exportedTypes.size} exported types`);
1715
- for (let [Z, Y] of q.typeImports) {
1716
- w("import-type-check", `Checking types from ${Z}: ${Array.from(Y).join(", ")}`);
1717
- let j = Array.from(Y).filter((Q) => {
1718
- let X = q.exportedTypes.has(Q) || q.usedTypes.has(Q);
1719
- return w("import-type-filter", `Type ${Q}: exported=${q.exportedTypes.has(Q)}, used=${q.usedTypes.has(Q)}`), X;
1720
- }).map((Q) => {
1721
- let X = q.valueAliases.get(Q);
1722
- return X ? `${Q} as ${X}` : Q;
1723
- }).sort();
1724
- if (j.length > 0) {
1725
- let Q = `import type { ${j.join(", ")} } from '${Z}'`;
1726
- if (!J.has(Q))
1727
- $.push(Q), J.add(Q), w("import-add-type", `Added type import: ${Q}`);
1728
- }
1729
- }
1730
- for (let [Z, Y] of q.valueImports) {
1731
- let j = new Map, Q = Array.from(Y).filter((X) => {
1732
- let U = Array.from(q.valueAliases.entries()).find(([G, V]) => V === X)?.[0], z = q.exportedValues.has(X) || q.usedValues.has(X) || X === q.defaultExportValue || U && (q.exportedValues.has(U) || U === q.defaultExportValue);
1733
- if (z && U)
1734
- j.set(X, U);
1735
- return z;
1736
- }).map((X) => {
1737
- let U = j.get(X);
1738
- return U ? `${X} as ${U}` : X;
1739
- }).sort();
1740
- if (Q.length > 0) {
1741
- let X = `import { ${Q.join(", ")} } from '${Z}'`;
1742
- if (!J.has(X))
1743
- $.push(X), J.add(X), w("import-add-value", `Added value import: ${X}`);
1744
- }
1745
- }
1746
- return $.sort();
1747
- }
1748
- function Z$(q) {
1749
- let $ = q.trim();
1750
- if (!$.startsWith("{"))
1751
- return null;
1752
- let J = 0, Z = false, Y = "";
1753
- for (let j = 0;j < $.length; j++) {
1754
- let Q = $[j], X = j > 0 ? $[j - 1] : "";
1755
- if ((Q === '"' || Q === "\'" || Q === "`") && X !== "\\") {
1756
- if (!Z)
1757
- Z = true, Y = Q;
1758
- else if (Q === Y)
1759
- Z = false;
1760
- continue;
1761
- }
1762
- if (!Z) {
1763
- if (Q === "{")
1764
- J++;
1765
- else if (Q === "}") {
1766
- if (J--, J === 0)
1767
- return $.slice(0, j + 1);
1768
- }
1769
- }
1770
- }
1771
- return null;
1772
- }
1773
- function Y$(q) {
1774
- let $ = new Set;
1775
- q.dtsLines.filter((j) => j.startsWith("import")).forEach((j) => $.add(j.replace(/;+$/, "")));
1776
- let J = q.dtsLines.filter((j) => !j.startsWith("import")).map((j) => {
1777
- let Q = j.trim();
1778
- if (!Q)
1779
- return "";
1780
- if (Q.startsWith("export *") || Q.endsWith(";"))
1781
- return Q;
1782
- if (Q.startsWith("export type"))
1783
- return `${Q};`;
1784
- return Q.replace(/;+$/, ";");
1785
- }), Z = Array.from(q.defaultExports).map((j) => j.trim().replace(/;+$/, ";"));
1786
- return `${[...Array.from($).map((j) => `${j};`), "", ...J.filter(Boolean), "", ...Z].map((j) => j.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "")).filter((j) => j.trim() || j === "").join("\n")}`.trim();
1787
- }
1788
- function j$(q) {
1789
- let $ = q.split("\n"), J = 0;
1790
- while (J < $.length) {
1791
- let Z = $[J].trim();
1792
- if (Z.startsWith("//") || Z.startsWith("/*") || Z.startsWith("*") || Z === "")
1793
- J++;
1794
- else
1795
- break;
1796
- }
1797
- return $.slice(J).join("\n");
1798
- }
1799
- function X$() {
1800
- return { dtsLines: [], imports: [], usedTypes: new Set, typeSources: new Map, defaultExport: null, exportAllStatements: [], currentDeclaration: "", lastCommentBlock: "", bracketCount: 0, isMultiLineDeclaration: false, moduleImports: new Map, availableTypes: new Map, availableValues: new Map, currentIndentation: "", declarationBuffer: null, importTracking: Q$(), defaultExports: new Set, currentScope: "top" };
1801
- }
1802
- function Q$() {
1803
- return { typeImports: new Map, valueImports: new Map, usedTypes: new Set, usedValues: new Set, exportedTypes: new Set, exportedValues: new Set, valueAliases: new Map, importSources: new Map, typeExportSources: new Map, defaultExportValue: undefined };
1804
- }
1805
- function i1(q, $, J) {
1806
- let Z = q.split("\n");
1807
- if (Z.length === 1)
1808
- return `${$}${q}${J ? "" : " |"}`;
1809
- let Y = [], j = false, Q = 0;
1810
- return Z.forEach((U) => {
1811
- let z = U.trim();
1812
- if (z.startsWith("Array<"))
1813
- Q = 0;
1814
- if (z === "}" || z.startsWith("> |") || z === ">")
1815
- j = Q === 1;
1816
- if (z && !z.startsWith("Array<") && !z.endsWith(">") && !z.startsWith("{") && !z.endsWith("}"))
1817
- Q++;
1818
- }), Z.map((U, z) => {
1819
- let G = U.trim();
1820
- if (!G)
1821
- return "";
1822
- let V = $;
1823
- if (z > 0) {
1824
- let _ = Y.reduce((S, E) => S + E.depth, 0);
1825
- if (V = $ + " ".repeat(_), G.match(/^['"]/))
1826
- V += " ";
1827
- if ((G.startsWith("}") || G.startsWith(">") || G.startsWith("> |")) && Y.length > 0)
1828
- V = $ + " ".repeat(Math.max(0, _ - 1));
1829
- }
1830
- let H = G.match(/[{<[]/g) || [], W = G.match(/[}\]>]/g) || [];
1831
- if (H.forEach((_) => {
1832
- let S = G.startsWith("Array") && _ === "<";
1833
- Y.push({ char: _, indent: V, isArray: S, depth: 1, isSingleElement: j });
1834
- }), W.length > 0) {
1835
- for (let _ = 0;_ < W.length; _++)
1836
- if (Y.length > 0)
1837
- Y.pop();
1838
- }
1839
- let I = false;
1840
- if (!J && z === Z.length - 1 && !G.endsWith(" |") && !G.endsWith(";"))
1841
- I = true;
1842
- if (G === "}") {
1843
- if ([...Y].reverse().find((S) => S.isArray)?.isSingleElement)
1844
- I = false;
1845
- }
1846
- if (G.endsWith(" |"))
1847
- I = false;
1848
- return `${V}${G}${I ? " |" : ""}`;
1849
- }).filter(Boolean).join("\n");
1850
- }
1851
- function U$(q) {
1852
- let $ = q.split("\n").map((Z) => Z.trim()).join(" ");
1853
- if (/^['"`].*['"`]$/.test($))
1854
- return $;
1855
- if (!Number.isNaN(Number($)))
1856
- return $;
1857
- if ($ === "true" || $ === "false")
1858
- return $;
1859
- let J = $.match(/\([^)]*\)\s*:\s*([^=>{]+)/);
1860
- if (J)
1861
- return J[1].trim();
1862
- if ($.includes("=>"))
1863
- return "(...args: any[]) => unknown";
1864
- return "unknown";
1865
- }
1866
- function w1(q, $, J = false) {
1867
- let Z = q.slice(1, -1).trim(), Y = q.trim().endsWith("as const");
1868
- if (!Z)
1869
- return Y ? "readonly unknown[]" : "unknown[]";
1870
- let j = Y0(Z);
1871
- if (Y || j.some((z) => z.includes("as const"))) {
1872
- let z = j.map((G) => {
1873
- let V = G.trim().replace(/\s*as\s*const\s*$/, "").trim();
1874
- return a1(V, $);
1875
- });
1876
- if (B$(z))
1877
- return `readonly [\n${z.map((V, H) => i1(V, " ", H === z.length - 1)).join("\n")}\n ]`;
1878
- return `readonly [${z.join(", ")}]`;
1879
- }
1880
- let X = j.map((z) => {
1881
- let G = z.trim();
1882
- if (G.startsWith("["))
1883
- return w1(G, $);
1884
- else if (G.startsWith("{"))
1885
- return $1(G, $);
1886
- else if (G.includes("=>") || G.includes("function")) {
1887
- let V = f1(G);
1888
- return V ? `(${V})` : "((...args: any[]) => unknown)";
1889
- } else
1890
- return w$(G);
1891
- }).filter(Boolean);
1892
- if (X.some((z) => z.includes("\n") || z.includes("{") || z.length > 40 || X.join(" | ").length > 60) && J)
1893
- return `Array<\n${X.map((G, V) => i1(G, " ", V === X.length - 1)).join("\n")}\n >`;
1894
- return `Array<${X.join(" | ")}>`;
1895
- }
1896
- function $1(q, $, J = 0) {
1897
- let Z = Z$(q);
1898
- if (!Z)
1899
- return "Record<string, unknown>";
1900
- let Y = " ".repeat(J), j = " ".repeat(J + 1), Q = Y, X = C$(Z, $, J);
1901
- if (!X.length)
1902
- return "{}";
1903
- return `{\n${X.map(({ key: z, value: G }) => {
1904
- return `${j}${z}: ${G}`;
1905
- }).join(";\n")}\n${Q}}`;
1906
- }
1907
- function a1(q, $) {
1908
- if (/^['"`].*['"`]$/.test(q))
1909
- return `'${q.replace(/\]\s*as\s*cons.*$/, "").replace(/^['"`]|['"`]$/g, "")}'`;
1910
- if (q.startsWith("[")) {
1911
- let Z = q.slice(1, -1).trim();
1912
- return `readonly [${Y0(Z).map((Q) => {
1913
- let X = Q.trim();
1914
- if (X.includes("] as cons") || X.includes("] as const"))
1915
- X = X.replace(/\]\s*as\s*cons.*$/, "").replace(/\]\s*as\s*const.*$/, "").trim();
1916
- if (X.startsWith("["))
1917
- return a1(X, $);
1918
- if (X.startsWith("{"))
1919
- return $1(X, $).replace(/^\{/, "{ readonly").replace(/;\s+/g, "; readonly ");
1920
- if (/^['"`].*['"`]$/.test(X))
1921
- return `'${X.replace(/^['"`]|['"`]$/g, "")}'`;
1922
- if (!Number.isNaN(Number(X)))
1923
- return X;
1924
- if (X === "true" || X === "false")
1925
- return X;
1926
- return `'${X.replace(/\]\s*as\s*cons.*$/, "").replace(/\]\s*as\s*const.*$/, "").replace(/^['"`]|['"`]$/g, "").trim()}'`;
1927
- }).join(", ")}]`;
1928
- }
1929
- return `'${q.replace(/\]\s*as\s*cons.*$/, "").replace(/\]\s*as\s*const.*$/, "").replace(/^['"`]|['"`]$/g, "").trim()}'`;
1930
- }
1931
- function z$(q, $) {
1932
- if (q.startsWith("{"))
1933
- return $1(q, $);
1934
- if (q.startsWith("["))
1935
- return w1(q, $, true);
1936
- return q;
1937
- }
1938
- function G$(q) {
1939
- if (/^['"`].*['"`]$/.test(q))
1940
- return "string";
1941
- if (!Number.isNaN(Number(q)))
1942
- return "number";
1943
- if (q === "true" || q === "false")
1944
- return "boolean";
1945
- if (q.startsWith("["))
1946
- return "unknown[]";
1947
- if (q.startsWith("{"))
1948
- return "object";
1949
- if (q === "null")
1950
- return "null";
1951
- if (q === "undefined")
1952
- return "undefined";
1953
- return "unknown";
1954
- }
1955
- function t1(q) {
1956
- return q.trim().startsWith("export default");
1957
- }
1958
- function F$(q) {
1959
- if (K$(q))
1960
- return false;
1961
- let $ = q.trim();
1962
- if (/^(?:export\s+)?(?:async\s+)?function\s*\*?\s*[a-zA-Z_$][\w$]*/.test($))
1963
- return true;
1964
- return $.startsWith("export ") || $.startsWith("interface ") || $.startsWith("type ") || $.startsWith("const ") || $.startsWith("function ") || $.startsWith("async function ") || $.startsWith("declare ") || $.startsWith("declare module") || /^export\s+(?:interface|type|const|function\*?|async\s+function\*?)/.test($);
1965
- }
1966
- function K$(q) {
1967
- return q.includes("\\") || q.includes("[^") || q.includes("(?:") || q.includes("(?=") || q.includes("(?!") || q.includes("\\s*") || q.includes("\\w+") || q.includes("\\d+") || q.includes("(?<") || q.includes("(?!") || q.includes("(?<=") || q.includes("(?<!");
1968
- }
1969
- function e1(q, $) {
1970
- let J = q.trim();
1971
- return $.currentScope === "function" && (J.startsWith("const ") || J.startsWith("let ") || J.startsWith("var ") || /^(?:const|let|var)\s+[a-zA-Z_$][\w$]*\s*(?::|=)/.test(J));
1972
- }
1973
- function B$(q) {
1974
- return q.some(($) => $.includes("\n") || $.includes("{") || $.length > 40 || q.join(" | ").length > 60);
1975
- }
1976
- function w$(q) {
1977
- if (q.includes("=>") || q.match(/\bfunction\b/))
1978
- return "((...args: any[]) => unknown)";
1979
- if (q.match(/\w+\s*\([^)]*\)/))
1980
- return "unknown";
1981
- if (q.startsWith("new "))
1982
- return "unknown";
1983
- if (q.includes("."))
1984
- return "unknown";
1985
- if (/^[a-z_$][\w$]*$/i.test(q) && !["unknown", "string", "number", "boolean", "null", "undefined", "any", "never", "void"].includes(q) && !/^['"`]|^\d/.test(q) && q !== "true" && q !== "false")
1986
- return "unknown";
1987
- return q;
1988
- }
1989
- function R1(q, $, J) {
1990
- w("block-processing", "Starting block processing");
1991
- let Z = [], Y = 0, j = 0, Q = 0, X = false, U = q.length;
1992
- w("block-scan", `Total available lines: ${U}`);
1993
- while (Q < U) {
1994
- let V = q[Q], H = V.trim(), W = (V.match(/\{/g) || []).length, I = (V.match(/\}/g) || []).length, _ = (V.match(/</g) || []).length, S = (V.match(/>/g) || []).length;
1995
- if (w("block-scan-details", `Scanning line ${Q + 1}: "${H}" Current depths - Bracket: ${Y}, Angle: ${j} Found body: ${X} Changes - Curly: +${W}/-${I}, Angle: +${_}/-${S}`), Z.push(V), Y += W - I, j += _ - S, H.includes("{"))
1996
- X = true, w("block-scan", `Found body start at line ${Q + 1}`);
1997
- if (w("block-collection", `Line ${Q + 1}: "${H}" Updated depths - Bracket: ${Y}, Angle: ${j} Found body: ${X}`), Y === 0 && (j === 0 || X) && H.endsWith("}") && X) {
1998
- w("block-scan", `Found complete block at line ${Q + 1}`);
1999
- break;
2000
- }
2001
- Q++;
2002
- }
2003
- let z = Z.join("\n");
2004
- w("block-scan", `Collected block:\n${z}`);
2005
- let G = j$(z).trim();
2006
- if (w("block-processing", `Full block content:\n${G}`), !G) {
2007
- w("block-processing", "Empty declaration block");
2008
- return;
2009
- }
2010
- if (e1(G, J)) {
2011
- w("block-processing", "Skipping variable declaration inside function");
2012
- return;
2013
- }
2014
- if (G.startsWith("interface") || G.startsWith("export interface")) {
2015
- if (w("block-processing", "Processing interface declaration using interface block processor"), N$(G, z, J)) {
2016
- w("block-processing", "Interface successfully processed");
2017
- return;
2018
- }
2019
- }
2020
- if (G.includes("\n\nexport function") || G.includes("\n\nfunction")) {
2021
- let V = b$(G);
2022
- if (V.length > 1) {
2023
- w("block-processing", `Found ${V.length} function declarations to process`), V.forEach((H) => {
2024
- let W = H.split("\n");
2025
- R1(W, $, J);
2026
- });
2027
- return;
2028
- }
2029
- }
2030
- if (V$(G, J))
2031
- return;
2032
- if (M$(G, q, J))
2033
- return;
2034
- if (H$(G, z, J))
2035
- return;
2036
- if (I$(G, J))
2037
- return;
2038
- if (W$(G, J))
2039
- return;
2040
- if (_$(G, z, J))
2041
- return;
2042
- if (E$(G, z, J))
2043
- return;
2044
- w("processing", `Unhandled declaration type: ${G.split("\n")[0]}`);
2045
- }
2046
- function M$(q, $, J) {
2047
- if (!q.match(/^(?:export\s+)?(const|let|var)\s+/))
2048
- return false;
2049
- if (e1(q, J))
2050
- return w("variable-processing", "Skipping variable inside function"), true;
2051
- let Y = q.startsWith("export");
2052
- if (J.currentScope === "top") {
2053
- let j = $.join("\n");
2054
- J.dtsLines.push(J0(j, Y, J));
2055
- } else
2056
- w("block-processing", "Skipping variable declared inside a function");
2057
- return true;
2058
- }
2059
- function V$(q, $) {
2060
- if (w("function-processing", `Processing potential function block: ${q.slice(0, 100)}...`), /^(?:export\s+)?(?:async\s+)?function\s*\*/.test(q)) {
2061
- w("block-processing", "Processing generator function declaration");
2062
- let z = x$(q);
2063
- if (z)
2064
- return $.dtsLines.push(z), true;
2065
- }
2066
- if (!/^(?:export\s+)?(?:async\s+)?function\s+[a-zA-Z_$][\w$]*/.test(q))
2067
- return false;
2068
- w("block-processing", "Processing function declaration");
2069
- let J = q.split(/[\n;]/).map((z) => z.trim()).filter((z) => z.startsWith("export function") || z.startsWith("function"));
2070
- if (J.length > 1)
2071
- return J.forEach((z) => {
2072
- if (!z.endsWith("{")) {
2073
- let G = P1(z, $.usedTypes, z.startsWith("export"));
2074
- if (G)
2075
- $.dtsLines.push(G);
2076
- }
2077
- }), true;
2078
- let Z = 0, Y = 0, j = 0;
2079
- for (let z = 0;z < q.length; z++) {
2080
- let G = q[z];
2081
- if (G === "(")
2082
- Y++;
2083
- if (G === ")")
2084
- Y--;
2085
- if (G === "<")
2086
- j++;
2087
- if (G === ">")
2088
- j--;
2089
- if (G === "{") {
2090
- if (Y === 0 && j === 0) {
2091
- Z = z;
2092
- break;
2093
- }
2094
- }
2095
- }
2096
- if (Z === 0)
2097
- Z = q.length;
2098
- let Q = q.slice(0, Z).trim();
2099
- w("signature-extraction", `Extracted signature: ${Q}`);
2100
- let X = Q.startsWith("export"), U = P1(Q, $.usedTypes, X);
2101
- if (U)
2102
- w("function-processed", `Generated declaration: ${U}`), $.dtsLines.push(U);
2103
- return true;
2104
- }
2105
- function N$(q, $, J) {
2106
- if (w("interface-processing", `Starting interface processing with declaration: ${q.slice(0, 100)}...`), !q.startsWith("interface") && !q.startsWith("export interface"))
2107
- return w("interface-processing", "Not an interface declaration, skipping"), false;
2108
- let Z = $.split("\n"), Y = 0, j = 0, Q = [], X = true, U = false;
2109
- w("interface-processing", `Processing ${Z.length} lines`);
2110
- for (let H = 0;H < Z.length; H++) {
2111
- let W = Z[H], I = W.trim(), _ = (W.match(/\{/g) || []).length, S = (W.match(/\}/g) || []).length, E = (W.match(/</g) || []).length, A = (W.match(/>/g) || []).length;
2112
- if (Y += _ - S, j += E - A, I.includes("{"))
2113
- U = true;
2114
- if (w("interface-depth", `Line ${H + 1}: "${I}" Bracket depth: ${Y}, Angle depth: ${j}, Has started body: ${U}`), X) {
2115
- let m = I.startsWith("export") ? "export declare" : "declare";
2116
- Q.push(W.replace(/^(\s*)(?:export\s+)?interface/, `$1${m} interface`)), X = false;
2117
- } else
2118
- Q.push(W);
2119
- }
2120
- let z = Q.join("\n"), G = z.includes("{") && z.includes("}");
2121
- if (Y === 0 && (j === 0 || z.includes(">")) && G)
2122
- return w("interface-processing", `Successfully processed interface:\n${z}`), J.dtsLines.push(z), true;
2123
- return w("interface-processing", `Interface processing incomplete. Bracket depth: ${Y}, Angle depth: ${j}, Has started body: ${U}`), false;
2124
- }
2125
- function H$(q, $, J) {
2126
- if (!q.startsWith("type") && !q.startsWith("export type"))
2127
- return false;
2128
- let Z = q.startsWith("export");
2129
- return J.dtsLines.push($0($, Z)), true;
2130
- }
2131
- function I$(q, $) {
2132
- if (!t1(q))
2133
- return false;
2134
- let J = q.replace(/^export\s+default\s+/, "").replace(/;$/, "");
2135
- $.importTracking.defaultExportValue = J;
2136
- let Z = q.endsWith(";") ? q : `${q};`;
2137
- return $.defaultExports.add(Z), true;
2138
- }
2139
- function W$(q, $) {
2140
- if (!q.startsWith("export *"))
2141
- return false;
2142
- return $.exportAllStatements.push(q), $.dtsLines.push(q), true;
2143
- }
2144
- function _$(q, $, J) {
2145
- if (!q.startsWith("export"))
2146
- return false;
2147
- if (R$(q, J))
2148
- return true;
2149
- if (P$(q, J))
2150
- return true;
2151
- if (f$(q, J))
2152
- return true;
2153
- if (q.startsWith("export {"))
2154
- return J.dtsLines.push($), true;
2155
- return w("processing", `Unhandled exported declaration type: ${q.split("\n")[0]}`), true;
2156
- }
2157
- function O$(q, $) {
2158
- w("export-processing", `Processing export: ${q}`);
2159
- let J = q.match(/export\s*\{([^}]+)\}(?:\s*from\s*['"]([^'"]+)['"])?/);
2160
- if (!J) {
2161
- w("export-error", "Failed to match export pattern");
2162
- return;
2163
- }
2164
- let [, Z, Y] = J;
2165
- w("export-found", `Found exports: ${Z}, source: ${Y || "local"}`), Z.split(",").forEach((j) => {
2166
- let [Q, X] = j.trim().split(/\s+as\s+/).map((U) => U.trim());
2167
- if (Q.startsWith("type ")) {
2168
- let U = Q.replace(/^type\s+/, "").trim(), z = X || U;
2169
- if ($.importTracking.exportedTypes.add(z), Y)
2170
- $.importTracking.typeExportSources.set(z, Y);
2171
- w("export-type-processed", `Added exported type: ${z}`);
2172
- } else {
2173
- let U = X || Q;
2174
- $.importTracking.exportedValues.add(U), w("export-value-processed", `Added exported value: ${U}`);
2175
- }
2176
- });
2177
- }
2178
- function R$(q, $) {
2179
- if (!q.startsWith("export class") && !q.startsWith("export abstract class"))
2180
- return false;
2181
- let J = `export declare ${q.replace(/^export\s+/, "")}`;
2182
- return $.dtsLines.push(J), true;
2183
- }
2184
- function P$(q, $) {
2185
- if (!q.startsWith("export enum") && !q.startsWith("export const enum"))
2186
- return false;
2187
- let J = `export declare ${q.replace(/^export\s+/, "")}`;
2188
- return $.dtsLines.push(J), true;
2189
- }
2190
- function f$(q, $) {
2191
- if (!q.startsWith("export namespace"))
2192
- return false;
2193
- let J = `export declare ${q.replace(/^export\s+/, "")}`;
2194
- return $.dtsLines.push(J), true;
2195
- }
2196
- function E$(q, $, J) {
2197
- if (!q.startsWith("declare module"))
2198
- return false;
2199
- let Z = Z0($);
2200
- return J.dtsLines.push(Z), true;
2201
- }
2202
- function A$(q, $) {
2203
- let J = q.split("\n"), Z = [], Y = [], j = 0, Q = 0, X = false;
2204
- $.currentScope = "top", w("source-processing", `Processing source file with ${J.length} lines`);
2205
- for (let U = 0;U < J.length; U++) {
2206
- let z = J[U], G = z.trim();
2207
- if (w("source-scan", `First pass - Line ${U + 1}: ${G}`), z.includes("import "))
2208
- q0(z, $.importTracking), w("import", `Processed import: ${z}`);
2209
- if (G.startsWith("export type {")) {
2210
- w("type-export", `Found type export: ${G}`), T$(G, $), $.dtsLines.push(z);
2211
- continue;
2212
- }
2213
- if (G.startsWith("export {")) {
2214
- w("mixed-export", `Found mixed export: ${G}`), O$(G, $), $.dtsLines.push(z);
2215
- continue;
2216
- }
2217
- }
2218
- for (let U = 0;U < J.length; U++) {
2219
- let z = J[U], G = z.trim();
2220
- if (G.startsWith("import ") || G.startsWith("export type {") || G.startsWith("export {"))
2221
- continue;
2222
- if (G.startsWith("/*") || G.startsWith("//")) {
2223
- Y.push(z);
2224
- continue;
2225
- }
2226
- let V = (z.match(/\{/g) || []).length, H = (z.match(/\}/g) || []).length, W = (z.match(/</g) || []).length, I = (z.match(/>/g) || []).length;
2227
- if (!X && F$(G)) {
2228
- w("declaration", `Found declaration start: ${G}`), X = true, Z = [z], j = V - H, Q = W - I;
2229
- continue;
2230
- }
2231
- if (X) {
2232
- Z.push(z), j += V - H, Q += W - I;
2233
- let _ = j === 0 && Q === 0 && G.endsWith("}"), S = U < J.length - 1 ? J[U + 1]?.trim() : "";
2234
- if (!(j > 0 || Q > 0 || S && !S.startsWith("export") && !S.startsWith("interface")) || _)
2235
- w("declaration-complete", `Declaration complete at line ${U + 1}`), R1(Z, Y, $), Z = [], Y = [], X = false, j = 0, Q = 0;
2236
- }
2237
- }
2238
- if (Z.length > 0)
2239
- R1(Z, Y, $);
2240
- }
2241
- function q0(q, $) {
2242
- w("import-processing", `Processing import line: ${q}`);
2243
- let J = q.match(/import\s+type\s*(?:\{([^}]+)\}|([^;\s]+))\s*from\s*['"]([^'"]+)['"]/);
2244
- if (J) {
2245
- let [, Y, j, Q] = J, X = Y || j;
2246
- if (w("import-type", `Found type imports from ${Q}: ${X}`), !$.typeImports.has(Q))
2247
- $.typeImports.set(Q, new Set);
2248
- if (X)
2249
- X.split(",").forEach((U) => {
2250
- let [z, G] = U.trim().split(/\s+as\s+/).map((V) => V.trim());
2251
- if ($.typeImports.get(Q).add(z), $.typeExportSources.set(z, Q), w("import-type-tracking", `Tracking type ${z} from ${Q}`), G)
2252
- $.valueAliases.set(G, z), w("import-alias", `Registered type alias: ${z} as ${G}`);
2253
- });
2254
- return;
2255
- }
2256
- let Z = q.match(/import\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]/);
2257
- if (Z) {
2258
- let [, Y, j] = Z;
2259
- if (w("import-value", `Found value imports from ${j}: ${Y}`), !$.valueImports.has(j))
2260
- $.valueImports.set(j, new Set);
2261
- Y.split(",").forEach((Q) => {
2262
- let [X, U] = Q.trim().split(/\s+as\s+/).map((z) => z.trim());
2263
- if (X.startsWith("type ")) {
2264
- let z = X.replace(/^type\s+/, "").trim();
2265
- if (!$.typeImports.has(j))
2266
- $.typeImports.set(j, new Set);
2267
- $.typeImports.get(j).add(z), $.typeExportSources.set(z, j), w("import-type-in-value", `Found inline type import: ${z} from ${j}`);
2268
- } else if ($.valueImports.get(j).add(X), $.importSources.set(X, j), U) {
2269
- if ($.valueAliases.set(U, X), U === $.defaultExportValue)
2270
- $.usedValues.add(X);
2271
- $.valueImports.get(j).add(X), w("import-alias", `Registered value alias: ${X} as ${U}`);
2272
- }
2273
- });
2274
- }
2275
- }
2276
- function $0(q, $ = true) {
2277
- let J = q.split("\n");
2278
- if (J[0].trim().startsWith("export type {"))
2279
- return q;
2280
- let Y = $ ? "export declare" : "declare";
2281
- return [J[0].replace(/^(\s*)(?:export\s+)?type(?!\s*\{)/, `$1${Y} type`), ...J.slice(1)].join("\n");
2282
- }
2283
- function T$(q, $) {
2284
- w("type-export-processing", `Processing type export: ${q}`);
2285
- let J = q.match(/export\s+type\s*\{([^}]+)\}(?:\s*from\s*['"]([^'"]+)['"])?/);
2286
- if (!J) {
2287
- w("type-export-error", "Failed to match type export pattern");
2288
- return;
2289
- }
2290
- let [, Z, Y] = J;
2291
- w("type-export-found", `Found types: ${Z}, source: ${Y || "local"}`), Z.split(",").forEach((j) => {
2292
- let [Q, X] = j.trim().split(/\s+as\s+/).map((z) => z.trim()), U = X || Q;
2293
- if ($.importTracking.exportedTypes.add(U), Y)
2294
- $.importTracking.typeExportSources.set(U, Y);
2295
- w("type-export-processed", `Added exported type: ${U}`);
2296
- });
2297
- }
2298
- function J0(q, $, J) {
2299
- let Z = q.includes("let ") ? "let" : q.includes("var ") ? "var" : "const", Y = q.match(/(?:export\s+)?(?:const|let|var)\s+([^:\s]+)\s*:\s*([^=]+)=/);
2300
- if (Y) {
2301
- let [, V, H] = Y;
2302
- return `${$ ? "export " : ""}declare ${Z} ${V}: ${H.trim()};`;
2303
- }
2304
- let j = q.match(/(?:export\s+)?(?:const|let|var)\s+([^=\s]+)\s*=\s*([\s\S]+)$/);
2305
- if (!j)
2306
- return q;
2307
- let [, Q, X] = j, U = X.trim(), z = U.match(/^\(\s*.*?\)\s*:\s*([^=>\s{]).*=>/);
2308
- if (z) {
2309
- let V = z[1];
2310
- return `${$ ? "export " : ""}declare ${Z} ${Q}: ${V};`;
2311
- }
2312
- let G;
2313
- if (U.includes("as const")) {
2314
- let V = U.replace(/\s*as\s*const\s*$/, "");
2315
- G = z$(V, J);
2316
- } else if (U.startsWith("{"))
2317
- G = $1(U, J);
2318
- else if (U.startsWith("["))
2319
- G = w1(U, J);
2320
- else if (U.includes("=>") || U.includes("function"))
2321
- G = f1(U) || "(...args: any[]) => unknown";
2322
- else
2323
- G = U$(U);
2324
- return `${$ ? "export " : ""}declare ${Z} ${Q}: ${G};`;
2325
- }
2326
- function P1(q, $, J = true) {
2327
- w("process-function-start", `Starting to process: ${q}`);
2328
- let Z = q.split("\n").map((X) => X.trim()).join(" ").replace(/\s+/g, " ").replace(/;$/, "");
2329
- w("process-function-normalized", `Normalized declaration: ${Z}`);
2330
- let Y = aq(Z);
2331
- if (w("process-function-signature", `Extracted signature: ${JSON.stringify(Y, null, 2)}`), !Y.params && Z.includes("("))
2332
- w("process-function-warning", "Found parentheses but no params extracted");
2333
- if (Y.returnType === "void" && Z.includes("):"))
2334
- w("process-function-warning", "Found return type indicator but extracted void");
2335
- let Q = [J ? "export " : "", "declare function ", Y.name, Y.generics, `(${Y.params})`, Y.returnType ? `: ${Y.returnType}` : "", ";"].filter(Boolean).join("");
2336
- return w("process-function-final", `Final declaration: ${Q}`), Q;
2337
- }
2338
- function S$(q) {
2339
- let $ = q.split("\n"), J = 0;
2340
- while (J < $.length) {
2341
- let Z = $[J].trim();
2342
- if (!Z.startsWith("//") && !Z.startsWith("/*") && !Z.startsWith("*") && Z !== "")
2343
- break;
2344
- J++;
2345
- }
2346
- return $.slice(J).join("\n").trim();
2347
- }
2348
- function x$(q) {
2349
- w("generator-function", `Processing generator function: ${q}`);
2350
- let $ = q.replace(/^export\s+/, "").replace(/^async\s+/, "").trim(), J = $.match(/function\*\s+([^(<\s]+)/);
2351
- if (!J)
2352
- return w("generator-function", "Failed to match generator function name"), "";
2353
- let [, Z] = J, Y = $.slice($.indexOf(Z) + Z.length).trim(), j = "";
2354
- if (Y.startsWith("<")) {
2355
- let U = 1, z = 1;
2356
- for (;z < Y.length && U > 0; z++) {
2357
- if (Y[z] === "<")
2358
- U++;
2359
- if (Y[z] === ">")
2360
- U--;
2361
- }
2362
- j = Y.slice(0, z), Y = Y.slice(z).trim();
2363
- }
2364
- let Q = "";
2365
- if (Y.startsWith("(")) {
2366
- let U = 1, z = 1;
2367
- for (;z < Y.length && U > 0; z++) {
2368
- if (Y[z] === "(")
2369
- U++;
2370
- if (Y[z] === ")")
2371
- U--;
2372
- }
2373
- Q = Y.slice(1, z - 1).trim(), Y = Y.slice(z).trim();
2374
- }
2375
- let X = "any";
2376
- if (Y.startsWith(":")) {
2377
- Y = Y.slice(1).trim();
2378
- let U = Y.match(/([^{;]+)/);
2379
- if (U)
2380
- X = U[1].trim();
2381
- }
2382
- return ["export declare function ", Z, j ? `${j}` : "", `(${Q})`, ": ", X].filter(Boolean).join("").concat(";");
2383
- }
2384
- function Z0(q) {
2385
- let $ = q.split("\n"), J = " ", Z = 0;
2386
- return $.map((j, Q) => {
2387
- let X = j.trim();
2388
- if (!X)
2389
- return "";
2390
- if (X.startsWith("}"))
2391
- Z--;
2392
- let U = " ".repeat(Math.max(0, Z)), z = Q === 0 ? X : `${U}${X}`;
2393
- if (X.endsWith("{"))
2394
- Z++;
2395
- if (X.includes("}") && X.includes("{"))
2396
- Z = Math.max(0, Z);
2397
- return z;
2398
- }).join("\n");
2399
- }
2400
- function s1(q) {
2401
- let $ = /^(?:async\s+)?(\w+)\s*(<[^>]*>)?\s*\(([^)]*)\)\s*(?::\s*([^ {][^;{]*))?/, J = q.match($);
2402
- if (!J)
2403
- return { name: q.split("(")[0].trim().replace(/^async\s+/, ""), signature: "() => unknown" };
2404
- let [, Z, Y = "", j, Q = "void"] = J, X = Q.trim();
2405
- if (/^async\s+/.test(q) && !/^Promise<.*>$/.test(X))
2406
- X = `Promise<${X}>`;
2407
- let z = O1(j || ""), G = [Y ? `${Y}` : "", `(${z})`, "=>", X].filter(Boolean).join(" ").trim();
2408
- return { name: Z, signature: G };
2409
- }
2410
- function C$(q, $, J = 0) {
2411
- let Z = [], Y = q.slice(1, -1).trim();
2412
- if (!Y)
2413
- return Z;
2414
- let j = "", Q = 0, X = false, U = "", z = "", G = true, V = false;
2415
- for (let H = 0;H < Y.length; H++) {
2416
- let W = Y[H], I = H > 0 ? Y[H - 1] : "";
2417
- if ((W === '"' || W === "\'" || W === "`") && I !== "\\") {
2418
- if (!X)
2419
- X = true, U = W;
2420
- else if (W === U)
2421
- X = false;
2422
- }
2423
- if (!X) {
2424
- if (W === "{" || W === "[" || W === "(")
2425
- Q++;
2426
- else if (W === "}" || W === "]" || W === ")")
2427
- Q--;
2428
- else if (Q === 0) {
2429
- if (W === ":" && !V) {
2430
- V = true, z = j.trim(), j = "", G = false;
2431
- continue;
2432
- } else if ((W === "," || W === ";") && !G) {
2433
- if (z) {
2434
- let _ = j.trim();
2435
- if (z.includes("(") || z.match(/^\s*(?:async\s+)?\w+\s*(?:<[^>]+>)?\s*\(/)) {
2436
- let { name: E, signature: A } = s1(z);
2437
- Z.push({ key: E, value: A });
2438
- } else {
2439
- let E = n1(_, J + 1, $);
2440
- Z.push({ key: r1(z), value: E });
2441
- }
2442
- }
2443
- j = "", z = "", G = true, V = false;
2444
- continue;
2445
- }
2446
- }
2447
- }
2448
- j += W;
2449
- }
2450
- if (z && !G && j.trim()) {
2451
- let H = j.trim();
2452
- if (z.includes("(") || z.match(/^\s*(?:async\s+)?\w+\s*(?:<[^>]+>)?\s*\(/)) {
2453
- let { name: I, signature: _ } = s1(z);
2454
- Z.push({ key: I, value: _ });
2455
- } else {
2456
- let I = n1(H, J + 1, $);
2457
- Z.push({ key: r1(z), value: I });
2458
- }
2459
- }
2460
- return Z;
2461
- }
2462
- function n1(q, $, J) {
2463
- let Z = q.trim();
2464
- if (Z.startsWith("{") && Z.includes("(") && Z.includes(")") && Z.includes(":"))
2465
- return $1(Z, J, $);
2466
- if (Z.startsWith("["))
2467
- return w1(Z, J, true);
2468
- if (Z.startsWith("{"))
2469
- return $1(Z, J, $);
2470
- if (Z.includes("=>") || Z.includes("function"))
2471
- return f1(Z) || "(...args: any[]) => unknown";
2472
- if (/^(['"`]).*\1$/.test(Z) || !Number.isNaN(Number(Z)) || Z === "true" || Z === "false")
2473
- return Z;
2474
- return "unknown";
2475
- }
2476
- function D$(q, $) {
2477
- let J = /(?:extends|implements|:|<)\s*([A-Z][a-zA-Z0-9]*(?:<[^>]+>)?)/g, Z;
2478
- while ((Z = J.exec(q)) !== null) {
2479
- let Y = Z[1].split("<")[0];
2480
- $.usedTypes.add(Y);
2481
- }
2482
- }
2483
- function k$(q, $) {
2484
- let J = q.match(/export\s*\{([^}]+)\}/);
2485
- if (J)
2486
- J[1].split(",").map((j) => j.trim()).forEach((j) => {
2487
- let [Q] = j.split(/\s+as\s+/);
2488
- $.exportedValues.add(Q.trim());
2489
- });
2490
- let Z = [/export\s+declare\s+\{\s*([^}\s]+)(?:\s*,\s*[^}\s]+)*\s*\}/g, /export\s+declare\s+(?:const|function|class)\s+([a-zA-Z_$][\w$]*)/g, /export\s+\{\s*([^}\s]+)(?:\s*,\s*[^}\s]+)*\s*\}/g];
2491
- for (let Y of Z) {
2492
- let j;
2493
- while ((j = Y.exec(q)) !== null)
2494
- j[1].split(",").map((X) => X.trim()).forEach((X) => {
2495
- if (!["type", "interface", "declare", "extends", "implements", "function", "const", "let", "var"].includes(X))
2496
- $.usedValues.add(X);
2497
- });
2498
- }
2499
- }
2500
- function w(q, $) {
2501
- if (q1.verbose)
2502
- console.debug(`[dtsx:${q}] ${$}`);
2503
- }
2504
- function L$(q) {
2505
- return q.replace(/\s+/g, " ").replace(/\s*([<>])\s*/g, "$1").replace(/\s*,\s*/g, ", ").trim();
2506
- }
2507
- function r1(q) {
2508
- let $ = q.replace(/^['"`]|['"`]$/g, "");
2509
- if (!/^[a-z_$][\w$]*$/i.test($))
2510
- return `'${$}'`;
2511
- return $;
2512
- }
2513
- function Y0(q) {
2514
- let $ = [], J = "", Z = 0, Y = false, j = "";
2515
- for (let X = 0;X < q.length; X++) {
2516
- let U = q[X], z = X > 0 ? q[X - 1] : "";
2517
- if ((U === '"' || U === "\'" || U === "`") && z !== "\\") {
2518
- if (!Y)
2519
- Y = true, j = U;
2520
- else if (U === j)
2521
- Y = false;
2522
- }
2523
- if (!Y) {
2524
- if (U === "[" || U === "{" || U === "(")
2525
- Z++;
2526
- else if (U === "]" || U === "}" || U === ")")
2527
- Z--;
2528
- else if (U === "," && Z === 0) {
2529
- let G = J.trim();
2530
- if (G)
2531
- $.push(G);
2532
- J = "";
2533
- continue;
2534
- }
2535
- }
2536
- J += U;
2537
- }
2538
- let Q = J.trim();
2539
- if (Q)
2540
- $.push(Q);
2541
- return $;
2542
- }
2543
- function b$(q) {
2544
- let $ = [], J = q.split("\n"), Z = [];
2545
- for (let Y = 0;Y < J.length; Y++) {
2546
- let j = J[Y].trim();
2547
- if ((j.startsWith("export function") || j.startsWith("function")) && Z.length > 0)
2548
- $.push(Z.join("\n")), Z = [];
2549
- Z.push(J[Y]);
2550
- }
2551
- if (Z.length > 0)
2552
- $.push(Z.join("\n"));
2553
- return $;
2554
- }
2555
- var kq = K1(yq(), 1);
2556
- var h1 = K1(U1(), 1);
2557
- var Lq = K1(U1(), 1);
2558
- var SZ = /\\(?![()[\]{}!+@])/g;
2559
- function xZ(q) {
2560
- return bq(q);
2561
- }
2562
- function yZ(q) {
2563
- return vq(q).replace(SZ, "/");
2564
- }
2565
- var S8 = process.platform === "win32" ? yZ : xZ;
2566
- var CZ = /(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/g;
2567
- var DZ = /(?<!\\)([()[\]{}]|^!|[!+@](?=\())/g;
2568
- var bq = (q) => q.replace(CZ, "\\$&");
2569
- var vq = (q) => q.replace(DZ, "\\$&");
2570
- var x8 = process.platform === "win32" ? vq : bq;
2571
- function kZ(q, $) {
2572
- if (($ == null ? undefined : $.caseSensitiveMatch) === false)
2573
- return true;
2574
- let J = Lq.default.scan(q);
2575
- return J.isGlob || J.negated;
2576
- }
2577
- function g1(q, $, J, Z, Y) {
2578
- var j;
2579
- let Q = q;
2580
- if (q.endsWith("/"))
2581
- Q = q.slice(0, -1);
2582
- if (!Q.endsWith("*") && $)
2583
- Q += "/**";
2584
- if (Dq.isAbsolute(Q.replace(/\\(?=[()[\]{}!*+?@|])/g, "")))
2585
- Q = I1.relative(J, Q);
2586
- else
2587
- Q = I1.normalize(Q);
2588
- let X = /^(\/?\.\.)+/.exec(Q);
2589
- if (X == null ? undefined : X[0]) {
2590
- let U = I1.join(J, X[0]);
2591
- if (Z.root.length > U.length)
2592
- Z.root = U, Z.depthOffset = -(X[0].length + 1) / 3;
2593
- } else if (!Y && Z.depthOffset >= 0) {
2594
- let U = Q.split("/");
2595
- (j = Z.commonPath) != null || (Z.commonPath = U);
2596
- let z = [];
2597
- for (let G = 0;G < Math.min(Z.commonPath.length, U.length); G++) {
2598
- let V = U[G];
2599
- if (V === "**" && !U[G + 1]) {
2600
- z.pop();
2601
- break;
2602
- }
2603
- if (V !== Z.commonPath[G] || kZ(V) || G === U.length - 1)
2604
- break;
2605
- z.push(V);
2606
- }
2607
- Z.depthOffset = z.length, Z.commonPath = z, Z.root = z.length > 0 ? `${J}/${z.join("/")}` : J;
2608
- }
2609
- return Q;
2610
- }
2611
- function LZ({ patterns: q, ignore: $ = [], expandDirectories: J = true }, Z, Y) {
2612
- if (typeof q === "string")
2613
- q = [q];
2614
- else if (!q)
2615
- q = ["**/*"];
2616
- if (typeof $ === "string")
2617
- $ = [$];
2618
- let j = [], Q = [];
2619
- for (let X of $)
2620
- if (!X.startsWith("!") || X[1] === "(") {
2621
- let U = g1(X, J, Z, Y, true);
2622
- Q.push(U);
2623
- }
2624
- for (let X of q)
2625
- if (!X.startsWith("!") || X[1] === "(") {
2626
- let U = g1(X, J, Z, Y, false);
2627
- j.push(U);
2628
- } else if (X[1] !== "!" || X[2] === "(") {
2629
- let U = g1(X.slice(1), J, Z, Y, true);
2630
- Q.push(U);
2631
- }
2632
- return { match: j, ignore: Q };
2633
- }
2634
- function u1(q, $, J) {
2635
- return I1.relative($, `${J}/${q}`);
2636
- }
2637
- function Cq(q, $, J, Z, Y) {
2638
- let j = Y ? q.slice(J.length + 1) || "." : q;
2639
- if (J === $)
2640
- return Z && j !== "." ? j.slice(0, -1) : j;
2641
- return u1(j, $, J);
2642
- }
2643
- function bZ(q, $, J) {
2644
- let Z = { root: $, commonPath: null, depthOffset: 0 }, Y = LZ(q, $, Z), j = h1.default(Y.match, { dot: q.dot, nocase: q.caseSensitiveMatch === false, ignore: Y.ignore }), Q = h1.default(Y.ignore, { dot: q.dot, nocase: q.caseSensitiveMatch === false }), X = { filters: [(z, G) => j(Cq(z, $, Z.root, G, q.absolute))], exclude: (z, G) => Q(Cq(G, $, Z.root, true, true)), pathSeparator: "/", relativePaths: true, resolveSymlinks: true };
2645
- if (q.deep)
2646
- X.maxDepth = Math.round(q.deep - Z.depthOffset);
2647
- if (q.absolute)
2648
- X.relativePaths = false, X.resolvePaths = true, X.includeBasePath = true;
2649
- if (q.followSymbolicLinks === false)
2650
- X.resolveSymlinks = false, X.excludeSymlinks = true;
2651
- if (q.onlyDirectories)
2652
- X.excludeFiles = true, X.includeDirs = true;
2653
- else if (q.onlyFiles === false)
2654
- X.includeDirs = true;
2655
- Z.root = Z.root.replace(/\\/g, "");
2656
- let U = new kq.fdir(X).crawl(Z.root);
2657
- if ($ === Z.root || q.absolute)
2658
- return J ? U.sync() : U.withPromise();
2659
- return J ? U.sync().map((z) => u1(z, $, Z.root) + (!z || z.endsWith("/") ? "/" : "")) : U.withPromise().then((z) => z.map((G) => u1(G, $, Z.root) + (!G || G.endsWith("/") ? "/" : "")));
2660
- }
2661
- async function gq(q, $) {
2662
- if (q && ($ == null ? undefined : $.patterns))
2663
- throw new Error("Cannot pass patterns as both an argument and an option");
2664
- let J = Array.isArray(q) || typeof q === "string" ? { ...$, patterns: q } : q, Z = J.cwd ? Dq.resolve(J.cwd).replace(/\\/g, "/") : process.cwd().replace(/\\/g, "/");
2665
- return bZ(J, Z, false);
2666
- }
2667
- async function uq(q, $) {
2668
- await Bun.write(q, $);
2669
- }
2670
- async function m1(q) {
2671
- let $ = q ?? q1.root, J = await vZ($, { withFileTypes: true }), Z = await Promise.all(J.map((Y) => {
2672
- let j = hq($, Y.name);
2673
- return Y.isDirectory() ? m1(j) : j;
2674
- }));
2675
- return Array.prototype.concat(...Z).filter((Y) => gZ(Y) === ".ts");
2676
- }
2677
- async function mq(q) {
2678
- try {
2679
- return (await import(q?.tsconfigPath || hq(q?.cwd ?? "./", "tsconfig.json"))).compilerOptions?.isolatedDeclarations === true;
2680
- } catch ($) {
2681
- return console.log("Error reading tsconfig.json:", $), false;
2682
- }
2683
- }
2684
- async function pZ(q) {
2685
- try {
2686
- if (!await mq(q)) {
2687
- console.error("Error: isolatedModules must be set to true in your tsconfig.json. Ensure `tsc --noEmit` does not output any errors.");
2688
- return;
2689
- }
2690
- if (q?.clean)
2691
- await uZ(q.outdir, { recursive: true, force: true });
2692
- let J;
2693
- if (q?.entrypoints)
2694
- J = await gq(q.entrypoints, { cwd: q.root ?? `${q.cwd}/src`, absolute: true });
2695
- else
2696
- J = await m1(q?.root ?? `${q?.cwd}/src`);
2697
- for (let Z of J) {
2698
- let Y = await o1(Z);
2699
- if (Y) {
2700
- let j = lZ(q?.root ?? "./src", Z), Q = cZ(j), X = dZ(q?.outdir ?? "./dist", `${Q.name}.d.ts`);
2701
- await hZ(mZ(X), { recursive: true }), await uq(X, Y);
2702
- } else
2703
- console.warn(`No declarations extracted for ${Z}`);
2704
- }
2705
- } catch ($) {
2706
- console.error("Error generating declarations:", $);
2707
- }
2708
- }
2709
- async function d8(q) {
2710
- await pZ({ ...q1, ...q });
2711
- }
2712
-
2713
2
  // src/index.ts
3
+ import { generate } from "@stacksjs/dtsx";
2714
4
  function dts(options) {
2715
5
  return {
2716
6
  name: "bun-plugin-dtsx",
@@ -2721,7 +11,7 @@ function dts(options) {
2721
11
  const outdir = options?.outdir || build.config.outdir;
2722
12
  const clean = options?.clean;
2723
13
  const tsconfigPath = options?.tsconfigPath;
2724
- await d8({
14
+ await generate({
2725
15
  ...options,
2726
16
  cwd,
2727
17
  root,
@@ -2735,7 +25,6 @@ function dts(options) {
2735
25
  }
2736
26
  var src_default = dts;
2737
27
  export {
2738
- d8 as generate,
2739
28
  dts,
2740
29
  src_default as default
2741
30
  };