@spikers/next-openapi-json-generator 1.0.1 → 1.0.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.cjs +51 -1638
- package/dist/index.js +51 -1667
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
8
|
var __export = (target, all) => {
|
|
12
9
|
for (var name in all)
|
|
13
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -30,253 +27,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
27
|
));
|
|
31
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
29
|
|
|
33
|
-
// node_modules/balanced-match/index.js
|
|
34
|
-
var require_balanced_match = __commonJS({
|
|
35
|
-
"node_modules/balanced-match/index.js"(exports2, module2) {
|
|
36
|
-
"use strict";
|
|
37
|
-
module2.exports = balanced;
|
|
38
|
-
function balanced(a, b, str) {
|
|
39
|
-
if (a instanceof RegExp) a = maybeMatch(a, str);
|
|
40
|
-
if (b instanceof RegExp) b = maybeMatch(b, str);
|
|
41
|
-
var r = range(a, b, str);
|
|
42
|
-
return r && {
|
|
43
|
-
start: r[0],
|
|
44
|
-
end: r[1],
|
|
45
|
-
pre: str.slice(0, r[0]),
|
|
46
|
-
body: str.slice(r[0] + a.length, r[1]),
|
|
47
|
-
post: str.slice(r[1] + b.length)
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function maybeMatch(reg, str) {
|
|
51
|
-
var m = str.match(reg);
|
|
52
|
-
return m ? m[0] : null;
|
|
53
|
-
}
|
|
54
|
-
balanced.range = range;
|
|
55
|
-
function range(a, b, str) {
|
|
56
|
-
var begs, beg, left, right, result;
|
|
57
|
-
var ai = str.indexOf(a);
|
|
58
|
-
var bi = str.indexOf(b, ai + 1);
|
|
59
|
-
var i = ai;
|
|
60
|
-
if (ai >= 0 && bi > 0) {
|
|
61
|
-
if (a === b) {
|
|
62
|
-
return [ai, bi];
|
|
63
|
-
}
|
|
64
|
-
begs = [];
|
|
65
|
-
left = str.length;
|
|
66
|
-
while (i >= 0 && !result) {
|
|
67
|
-
if (i == ai) {
|
|
68
|
-
begs.push(i);
|
|
69
|
-
ai = str.indexOf(a, i + 1);
|
|
70
|
-
} else if (begs.length == 1) {
|
|
71
|
-
result = [begs.pop(), bi];
|
|
72
|
-
} else {
|
|
73
|
-
beg = begs.pop();
|
|
74
|
-
if (beg < left) {
|
|
75
|
-
left = beg;
|
|
76
|
-
right = bi;
|
|
77
|
-
}
|
|
78
|
-
bi = str.indexOf(b, i + 1);
|
|
79
|
-
}
|
|
80
|
-
i = ai < bi && ai >= 0 ? ai : bi;
|
|
81
|
-
}
|
|
82
|
-
if (begs.length) {
|
|
83
|
-
result = [left, right];
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// node_modules/brace-expansion/index.js
|
|
92
|
-
var require_brace_expansion = __commonJS({
|
|
93
|
-
"node_modules/brace-expansion/index.js"(exports2, module2) {
|
|
94
|
-
"use strict";
|
|
95
|
-
var balanced = require_balanced_match();
|
|
96
|
-
module2.exports = expandTop;
|
|
97
|
-
var escSlash = "\0SLASH" + Math.random() + "\0";
|
|
98
|
-
var escOpen = "\0OPEN" + Math.random() + "\0";
|
|
99
|
-
var escClose = "\0CLOSE" + Math.random() + "\0";
|
|
100
|
-
var escComma = "\0COMMA" + Math.random() + "\0";
|
|
101
|
-
var escPeriod = "\0PERIOD" + Math.random() + "\0";
|
|
102
|
-
function numeric(str) {
|
|
103
|
-
return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
|
|
104
|
-
}
|
|
105
|
-
function escapeBraces(str) {
|
|
106
|
-
return str.split("\\\\").join(escSlash).split("\\{").join(escOpen).split("\\}").join(escClose).split("\\,").join(escComma).split("\\.").join(escPeriod);
|
|
107
|
-
}
|
|
108
|
-
function unescapeBraces(str) {
|
|
109
|
-
return str.split(escSlash).join("\\").split(escOpen).join("{").split(escClose).join("}").split(escComma).join(",").split(escPeriod).join(".");
|
|
110
|
-
}
|
|
111
|
-
function parseCommaParts(str) {
|
|
112
|
-
if (!str)
|
|
113
|
-
return [""];
|
|
114
|
-
var parts = [];
|
|
115
|
-
var m = balanced("{", "}", str);
|
|
116
|
-
if (!m)
|
|
117
|
-
return str.split(",");
|
|
118
|
-
var pre = m.pre;
|
|
119
|
-
var body = m.body;
|
|
120
|
-
var post = m.post;
|
|
121
|
-
var p = pre.split(",");
|
|
122
|
-
p[p.length - 1] += "{" + body + "}";
|
|
123
|
-
var postParts = parseCommaParts(post);
|
|
124
|
-
if (post.length) {
|
|
125
|
-
p[p.length - 1] += postParts.shift();
|
|
126
|
-
p.push.apply(p, postParts);
|
|
127
|
-
}
|
|
128
|
-
parts.push.apply(parts, p);
|
|
129
|
-
return parts;
|
|
130
|
-
}
|
|
131
|
-
function expandTop(str) {
|
|
132
|
-
if (!str)
|
|
133
|
-
return [];
|
|
134
|
-
if (str.substr(0, 2) === "{}") {
|
|
135
|
-
str = "\\{\\}" + str.substr(2);
|
|
136
|
-
}
|
|
137
|
-
return expand2(escapeBraces(str), true).map(unescapeBraces);
|
|
138
|
-
}
|
|
139
|
-
function embrace(str) {
|
|
140
|
-
return "{" + str + "}";
|
|
141
|
-
}
|
|
142
|
-
function isPadded(el) {
|
|
143
|
-
return /^-?0\d/.test(el);
|
|
144
|
-
}
|
|
145
|
-
function lte(i, y) {
|
|
146
|
-
return i <= y;
|
|
147
|
-
}
|
|
148
|
-
function gte(i, y) {
|
|
149
|
-
return i >= y;
|
|
150
|
-
}
|
|
151
|
-
function expand2(str, isTop) {
|
|
152
|
-
var expansions = [];
|
|
153
|
-
var m = balanced("{", "}", str);
|
|
154
|
-
if (!m) return [str];
|
|
155
|
-
var pre = m.pre;
|
|
156
|
-
var post = m.post.length ? expand2(m.post, false) : [""];
|
|
157
|
-
if (/\$$/.test(m.pre)) {
|
|
158
|
-
for (var k = 0; k < post.length; k++) {
|
|
159
|
-
var expansion = pre + "{" + m.body + "}" + post[k];
|
|
160
|
-
expansions.push(expansion);
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
163
|
-
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
164
|
-
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
165
|
-
var isSequence = isNumericSequence || isAlphaSequence;
|
|
166
|
-
var isOptions = m.body.indexOf(",") >= 0;
|
|
167
|
-
if (!isSequence && !isOptions) {
|
|
168
|
-
if (m.post.match(/,.*\}/)) {
|
|
169
|
-
str = m.pre + "{" + m.body + escClose + m.post;
|
|
170
|
-
return expand2(str);
|
|
171
|
-
}
|
|
172
|
-
return [str];
|
|
173
|
-
}
|
|
174
|
-
var n;
|
|
175
|
-
if (isSequence) {
|
|
176
|
-
n = m.body.split(/\.\./);
|
|
177
|
-
} else {
|
|
178
|
-
n = parseCommaParts(m.body);
|
|
179
|
-
if (n.length === 1) {
|
|
180
|
-
n = expand2(n[0], false).map(embrace);
|
|
181
|
-
if (n.length === 1) {
|
|
182
|
-
return post.map(function(p) {
|
|
183
|
-
return m.pre + n[0] + p;
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
var N;
|
|
189
|
-
if (isSequence) {
|
|
190
|
-
var x = numeric(n[0]);
|
|
191
|
-
var y = numeric(n[1]);
|
|
192
|
-
var width = Math.max(n[0].length, n[1].length);
|
|
193
|
-
var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
|
|
194
|
-
var test = lte;
|
|
195
|
-
var reverse = y < x;
|
|
196
|
-
if (reverse) {
|
|
197
|
-
incr *= -1;
|
|
198
|
-
test = gte;
|
|
199
|
-
}
|
|
200
|
-
var pad = n.some(isPadded);
|
|
201
|
-
N = [];
|
|
202
|
-
for (var i = x; test(i, y); i += incr) {
|
|
203
|
-
var c;
|
|
204
|
-
if (isAlphaSequence) {
|
|
205
|
-
c = String.fromCharCode(i);
|
|
206
|
-
if (c === "\\")
|
|
207
|
-
c = "";
|
|
208
|
-
} else {
|
|
209
|
-
c = String(i);
|
|
210
|
-
if (pad) {
|
|
211
|
-
var need = width - c.length;
|
|
212
|
-
if (need > 0) {
|
|
213
|
-
var z = new Array(need + 1).join("0");
|
|
214
|
-
if (i < 0)
|
|
215
|
-
c = "-" + z + c.slice(1);
|
|
216
|
-
else
|
|
217
|
-
c = z + c;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
N.push(c);
|
|
222
|
-
}
|
|
223
|
-
} else {
|
|
224
|
-
N = [];
|
|
225
|
-
for (var j = 0; j < n.length; j++) {
|
|
226
|
-
N.push.apply(N, expand2(n[j], false));
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
for (var j = 0; j < N.length; j++) {
|
|
230
|
-
for (var k = 0; k < post.length; k++) {
|
|
231
|
-
var expansion = pre + N[j] + post[k];
|
|
232
|
-
if (!isTop || isSequence || expansion)
|
|
233
|
-
expansions.push(expansion);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return expansions;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
|
|
242
30
|
// src/index.ts
|
|
243
|
-
var
|
|
244
|
-
__export(
|
|
245
|
-
default: () =>
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
default: () => index_default
|
|
246
34
|
});
|
|
247
|
-
module.exports = __toCommonJS(
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
248
36
|
|
|
249
37
|
// src/core/generateOpenApiSpec.ts
|
|
250
|
-
var
|
|
251
|
-
|
|
252
|
-
// node_modules/@omer-x/package-metadata/dist/index.js
|
|
253
|
-
var import_node_fs = __toESM(require("fs"), 1);
|
|
254
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
255
|
-
function capitalize(text) {
|
|
256
|
-
return text.split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
257
|
-
}
|
|
258
|
-
function getScopeName(packageName) {
|
|
259
|
-
const scopeRegex = /^@([^/]+)\//;
|
|
260
|
-
const match2 = packageName.match(scopeRegex);
|
|
261
|
-
return match2 ? `@${match2[1]}` : null;
|
|
262
|
-
}
|
|
263
|
-
function getModuleName(packageName) {
|
|
264
|
-
return packageName.split("/").pop() ?? null;
|
|
265
|
-
}
|
|
266
|
-
function getPackageMetadata() {
|
|
267
|
-
const filePath = import_node_path.default.resolve(process.cwd(), "package.json");
|
|
268
|
-
const content = import_node_fs.default.readFileSync(filePath, "utf-8");
|
|
269
|
-
const data = JSON.parse(content);
|
|
270
|
-
const packageName = data.name ?? "unnamed-app";
|
|
271
|
-
const moduleName = getModuleName(packageName) ?? "unknown-package";
|
|
272
|
-
return {
|
|
273
|
-
scope: getScopeName(packageName),
|
|
274
|
-
packageName,
|
|
275
|
-
moduleName,
|
|
276
|
-
serviceName: capitalize(moduleName.replace(/-/g, " ")),
|
|
277
|
-
version: data.version ?? "1.0.0"
|
|
278
|
-
};
|
|
279
|
-
}
|
|
38
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
39
|
+
var import_package_metadata = __toESM(require("@omer-x/package-metadata"), 1);
|
|
280
40
|
|
|
281
41
|
// src/utils/object.ts
|
|
282
42
|
function omit(object, ...keys) {
|
|
@@ -311,1339 +71,8 @@ function clearUnusedSchemas({
|
|
|
311
71
|
// src/core/dir.ts
|
|
312
72
|
var import_fs = require("fs");
|
|
313
73
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
314
|
-
var
|
|
315
|
-
|
|
316
|
-
// node_modules/minimatch/dist/esm/index.js
|
|
317
|
-
var import_brace_expansion = __toESM(require_brace_expansion(), 1);
|
|
318
|
-
|
|
319
|
-
// node_modules/minimatch/dist/esm/assert-valid-pattern.js
|
|
320
|
-
var MAX_PATTERN_LENGTH = 1024 * 64;
|
|
321
|
-
var assertValidPattern = (pattern) => {
|
|
322
|
-
if (typeof pattern !== "string") {
|
|
323
|
-
throw new TypeError("invalid pattern");
|
|
324
|
-
}
|
|
325
|
-
if (pattern.length > MAX_PATTERN_LENGTH) {
|
|
326
|
-
throw new TypeError("pattern is too long");
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
// node_modules/minimatch/dist/esm/brace-expressions.js
|
|
331
|
-
var posixClasses = {
|
|
332
|
-
"[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
|
|
333
|
-
"[:alpha:]": ["\\p{L}\\p{Nl}", true],
|
|
334
|
-
"[:ascii:]": ["\\x00-\\x7f", false],
|
|
335
|
-
"[:blank:]": ["\\p{Zs}\\t", true],
|
|
336
|
-
"[:cntrl:]": ["\\p{Cc}", true],
|
|
337
|
-
"[:digit:]": ["\\p{Nd}", true],
|
|
338
|
-
"[:graph:]": ["\\p{Z}\\p{C}", true, true],
|
|
339
|
-
"[:lower:]": ["\\p{Ll}", true],
|
|
340
|
-
"[:print:]": ["\\p{C}", true],
|
|
341
|
-
"[:punct:]": ["\\p{P}", true],
|
|
342
|
-
"[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true],
|
|
343
|
-
"[:upper:]": ["\\p{Lu}", true],
|
|
344
|
-
"[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true],
|
|
345
|
-
"[:xdigit:]": ["A-Fa-f0-9", false]
|
|
346
|
-
};
|
|
347
|
-
var braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&");
|
|
348
|
-
var regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
349
|
-
var rangesToString = (ranges) => ranges.join("");
|
|
350
|
-
var parseClass = (glob, position) => {
|
|
351
|
-
const pos = position;
|
|
352
|
-
if (glob.charAt(pos) !== "[") {
|
|
353
|
-
throw new Error("not in a brace expression");
|
|
354
|
-
}
|
|
355
|
-
const ranges = [];
|
|
356
|
-
const negs = [];
|
|
357
|
-
let i = pos + 1;
|
|
358
|
-
let sawStart = false;
|
|
359
|
-
let uflag = false;
|
|
360
|
-
let escaping = false;
|
|
361
|
-
let negate = false;
|
|
362
|
-
let endPos = pos;
|
|
363
|
-
let rangeStart = "";
|
|
364
|
-
WHILE: while (i < glob.length) {
|
|
365
|
-
const c = glob.charAt(i);
|
|
366
|
-
if ((c === "!" || c === "^") && i === pos + 1) {
|
|
367
|
-
negate = true;
|
|
368
|
-
i++;
|
|
369
|
-
continue;
|
|
370
|
-
}
|
|
371
|
-
if (c === "]" && sawStart && !escaping) {
|
|
372
|
-
endPos = i + 1;
|
|
373
|
-
break;
|
|
374
|
-
}
|
|
375
|
-
sawStart = true;
|
|
376
|
-
if (c === "\\") {
|
|
377
|
-
if (!escaping) {
|
|
378
|
-
escaping = true;
|
|
379
|
-
i++;
|
|
380
|
-
continue;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
if (c === "[" && !escaping) {
|
|
384
|
-
for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
|
|
385
|
-
if (glob.startsWith(cls, i)) {
|
|
386
|
-
if (rangeStart) {
|
|
387
|
-
return ["$.", false, glob.length - pos, true];
|
|
388
|
-
}
|
|
389
|
-
i += cls.length;
|
|
390
|
-
if (neg)
|
|
391
|
-
negs.push(unip);
|
|
392
|
-
else
|
|
393
|
-
ranges.push(unip);
|
|
394
|
-
uflag = uflag || u;
|
|
395
|
-
continue WHILE;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
escaping = false;
|
|
400
|
-
if (rangeStart) {
|
|
401
|
-
if (c > rangeStart) {
|
|
402
|
-
ranges.push(braceEscape(rangeStart) + "-" + braceEscape(c));
|
|
403
|
-
} else if (c === rangeStart) {
|
|
404
|
-
ranges.push(braceEscape(c));
|
|
405
|
-
}
|
|
406
|
-
rangeStart = "";
|
|
407
|
-
i++;
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
if (glob.startsWith("-]", i + 1)) {
|
|
411
|
-
ranges.push(braceEscape(c + "-"));
|
|
412
|
-
i += 2;
|
|
413
|
-
continue;
|
|
414
|
-
}
|
|
415
|
-
if (glob.startsWith("-", i + 1)) {
|
|
416
|
-
rangeStart = c;
|
|
417
|
-
i += 2;
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
ranges.push(braceEscape(c));
|
|
421
|
-
i++;
|
|
422
|
-
}
|
|
423
|
-
if (endPos < i) {
|
|
424
|
-
return ["", false, 0, false];
|
|
425
|
-
}
|
|
426
|
-
if (!ranges.length && !negs.length) {
|
|
427
|
-
return ["$.", false, glob.length - pos, true];
|
|
428
|
-
}
|
|
429
|
-
if (negs.length === 0 && ranges.length === 1 && /^\\?.$/.test(ranges[0]) && !negate) {
|
|
430
|
-
const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
|
|
431
|
-
return [regexpEscape(r), false, endPos - pos, false];
|
|
432
|
-
}
|
|
433
|
-
const sranges = "[" + (negate ? "^" : "") + rangesToString(ranges) + "]";
|
|
434
|
-
const snegs = "[" + (negate ? "" : "^") + rangesToString(negs) + "]";
|
|
435
|
-
const comb = ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs;
|
|
436
|
-
return [comb, uflag, endPos - pos, true];
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
// node_modules/minimatch/dist/esm/unescape.js
|
|
440
|
-
var unescape = (s, { windowsPathsNoEscape = false } = {}) => {
|
|
441
|
-
return windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1");
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
// node_modules/minimatch/dist/esm/ast.js
|
|
445
|
-
var types = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]);
|
|
446
|
-
var isExtglobType = (c) => types.has(c);
|
|
447
|
-
var startNoTraversal = "(?!(?:^|/)\\.\\.?(?:$|/))";
|
|
448
|
-
var startNoDot = "(?!\\.)";
|
|
449
|
-
var addPatternStart = /* @__PURE__ */ new Set(["[", "."]);
|
|
450
|
-
var justDots = /* @__PURE__ */ new Set(["..", "."]);
|
|
451
|
-
var reSpecials = new Set("().*{}+?[]^$\\!");
|
|
452
|
-
var regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
453
|
-
var qmark = "[^/]";
|
|
454
|
-
var star = qmark + "*?";
|
|
455
|
-
var starNoEmpty = qmark + "+?";
|
|
456
|
-
var AST = class _AST {
|
|
457
|
-
type;
|
|
458
|
-
#root;
|
|
459
|
-
#hasMagic;
|
|
460
|
-
#uflag = false;
|
|
461
|
-
#parts = [];
|
|
462
|
-
#parent;
|
|
463
|
-
#parentIndex;
|
|
464
|
-
#negs;
|
|
465
|
-
#filledNegs = false;
|
|
466
|
-
#options;
|
|
467
|
-
#toString;
|
|
468
|
-
// set to true if it's an extglob with no children
|
|
469
|
-
// (which really means one child of '')
|
|
470
|
-
#emptyExt = false;
|
|
471
|
-
constructor(type, parent, options = {}) {
|
|
472
|
-
this.type = type;
|
|
473
|
-
if (type)
|
|
474
|
-
this.#hasMagic = true;
|
|
475
|
-
this.#parent = parent;
|
|
476
|
-
this.#root = this.#parent ? this.#parent.#root : this;
|
|
477
|
-
this.#options = this.#root === this ? options : this.#root.#options;
|
|
478
|
-
this.#negs = this.#root === this ? [] : this.#root.#negs;
|
|
479
|
-
if (type === "!" && !this.#root.#filledNegs)
|
|
480
|
-
this.#negs.push(this);
|
|
481
|
-
this.#parentIndex = this.#parent ? this.#parent.#parts.length : 0;
|
|
482
|
-
}
|
|
483
|
-
get hasMagic() {
|
|
484
|
-
if (this.#hasMagic !== void 0)
|
|
485
|
-
return this.#hasMagic;
|
|
486
|
-
for (const p of this.#parts) {
|
|
487
|
-
if (typeof p === "string")
|
|
488
|
-
continue;
|
|
489
|
-
if (p.type || p.hasMagic)
|
|
490
|
-
return this.#hasMagic = true;
|
|
491
|
-
}
|
|
492
|
-
return this.#hasMagic;
|
|
493
|
-
}
|
|
494
|
-
// reconstructs the pattern
|
|
495
|
-
toString() {
|
|
496
|
-
if (this.#toString !== void 0)
|
|
497
|
-
return this.#toString;
|
|
498
|
-
if (!this.type) {
|
|
499
|
-
return this.#toString = this.#parts.map((p) => String(p)).join("");
|
|
500
|
-
} else {
|
|
501
|
-
return this.#toString = this.type + "(" + this.#parts.map((p) => String(p)).join("|") + ")";
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
#fillNegs() {
|
|
505
|
-
if (this !== this.#root)
|
|
506
|
-
throw new Error("should only call on root");
|
|
507
|
-
if (this.#filledNegs)
|
|
508
|
-
return this;
|
|
509
|
-
this.toString();
|
|
510
|
-
this.#filledNegs = true;
|
|
511
|
-
let n;
|
|
512
|
-
while (n = this.#negs.pop()) {
|
|
513
|
-
if (n.type !== "!")
|
|
514
|
-
continue;
|
|
515
|
-
let p = n;
|
|
516
|
-
let pp = p.#parent;
|
|
517
|
-
while (pp) {
|
|
518
|
-
for (let i = p.#parentIndex + 1; !pp.type && i < pp.#parts.length; i++) {
|
|
519
|
-
for (const part of n.#parts) {
|
|
520
|
-
if (typeof part === "string") {
|
|
521
|
-
throw new Error("string part in extglob AST??");
|
|
522
|
-
}
|
|
523
|
-
part.copyIn(pp.#parts[i]);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
p = pp;
|
|
527
|
-
pp = p.#parent;
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
return this;
|
|
531
|
-
}
|
|
532
|
-
push(...parts) {
|
|
533
|
-
for (const p of parts) {
|
|
534
|
-
if (p === "")
|
|
535
|
-
continue;
|
|
536
|
-
if (typeof p !== "string" && !(p instanceof _AST && p.#parent === this)) {
|
|
537
|
-
throw new Error("invalid part: " + p);
|
|
538
|
-
}
|
|
539
|
-
this.#parts.push(p);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
toJSON() {
|
|
543
|
-
const ret = this.type === null ? this.#parts.slice().map((p) => typeof p === "string" ? p : p.toJSON()) : [this.type, ...this.#parts.map((p) => p.toJSON())];
|
|
544
|
-
if (this.isStart() && !this.type)
|
|
545
|
-
ret.unshift([]);
|
|
546
|
-
if (this.isEnd() && (this === this.#root || this.#root.#filledNegs && this.#parent?.type === "!")) {
|
|
547
|
-
ret.push({});
|
|
548
|
-
}
|
|
549
|
-
return ret;
|
|
550
|
-
}
|
|
551
|
-
isStart() {
|
|
552
|
-
if (this.#root === this)
|
|
553
|
-
return true;
|
|
554
|
-
if (!this.#parent?.isStart())
|
|
555
|
-
return false;
|
|
556
|
-
if (this.#parentIndex === 0)
|
|
557
|
-
return true;
|
|
558
|
-
const p = this.#parent;
|
|
559
|
-
for (let i = 0; i < this.#parentIndex; i++) {
|
|
560
|
-
const pp = p.#parts[i];
|
|
561
|
-
if (!(pp instanceof _AST && pp.type === "!")) {
|
|
562
|
-
return false;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
return true;
|
|
566
|
-
}
|
|
567
|
-
isEnd() {
|
|
568
|
-
if (this.#root === this)
|
|
569
|
-
return true;
|
|
570
|
-
if (this.#parent?.type === "!")
|
|
571
|
-
return true;
|
|
572
|
-
if (!this.#parent?.isEnd())
|
|
573
|
-
return false;
|
|
574
|
-
if (!this.type)
|
|
575
|
-
return this.#parent?.isEnd();
|
|
576
|
-
const pl = this.#parent ? this.#parent.#parts.length : 0;
|
|
577
|
-
return this.#parentIndex === pl - 1;
|
|
578
|
-
}
|
|
579
|
-
copyIn(part) {
|
|
580
|
-
if (typeof part === "string")
|
|
581
|
-
this.push(part);
|
|
582
|
-
else
|
|
583
|
-
this.push(part.clone(this));
|
|
584
|
-
}
|
|
585
|
-
clone(parent) {
|
|
586
|
-
const c = new _AST(this.type, parent);
|
|
587
|
-
for (const p of this.#parts) {
|
|
588
|
-
c.copyIn(p);
|
|
589
|
-
}
|
|
590
|
-
return c;
|
|
591
|
-
}
|
|
592
|
-
static #parseAST(str, ast, pos, opt) {
|
|
593
|
-
let escaping = false;
|
|
594
|
-
let inBrace = false;
|
|
595
|
-
let braceStart = -1;
|
|
596
|
-
let braceNeg = false;
|
|
597
|
-
if (ast.type === null) {
|
|
598
|
-
let i2 = pos;
|
|
599
|
-
let acc2 = "";
|
|
600
|
-
while (i2 < str.length) {
|
|
601
|
-
const c = str.charAt(i2++);
|
|
602
|
-
if (escaping || c === "\\") {
|
|
603
|
-
escaping = !escaping;
|
|
604
|
-
acc2 += c;
|
|
605
|
-
continue;
|
|
606
|
-
}
|
|
607
|
-
if (inBrace) {
|
|
608
|
-
if (i2 === braceStart + 1) {
|
|
609
|
-
if (c === "^" || c === "!") {
|
|
610
|
-
braceNeg = true;
|
|
611
|
-
}
|
|
612
|
-
} else if (c === "]" && !(i2 === braceStart + 2 && braceNeg)) {
|
|
613
|
-
inBrace = false;
|
|
614
|
-
}
|
|
615
|
-
acc2 += c;
|
|
616
|
-
continue;
|
|
617
|
-
} else if (c === "[") {
|
|
618
|
-
inBrace = true;
|
|
619
|
-
braceStart = i2;
|
|
620
|
-
braceNeg = false;
|
|
621
|
-
acc2 += c;
|
|
622
|
-
continue;
|
|
623
|
-
}
|
|
624
|
-
if (!opt.noext && isExtglobType(c) && str.charAt(i2) === "(") {
|
|
625
|
-
ast.push(acc2);
|
|
626
|
-
acc2 = "";
|
|
627
|
-
const ext2 = new _AST(c, ast);
|
|
628
|
-
i2 = _AST.#parseAST(str, ext2, i2, opt);
|
|
629
|
-
ast.push(ext2);
|
|
630
|
-
continue;
|
|
631
|
-
}
|
|
632
|
-
acc2 += c;
|
|
633
|
-
}
|
|
634
|
-
ast.push(acc2);
|
|
635
|
-
return i2;
|
|
636
|
-
}
|
|
637
|
-
let i = pos + 1;
|
|
638
|
-
let part = new _AST(null, ast);
|
|
639
|
-
const parts = [];
|
|
640
|
-
let acc = "";
|
|
641
|
-
while (i < str.length) {
|
|
642
|
-
const c = str.charAt(i++);
|
|
643
|
-
if (escaping || c === "\\") {
|
|
644
|
-
escaping = !escaping;
|
|
645
|
-
acc += c;
|
|
646
|
-
continue;
|
|
647
|
-
}
|
|
648
|
-
if (inBrace) {
|
|
649
|
-
if (i === braceStart + 1) {
|
|
650
|
-
if (c === "^" || c === "!") {
|
|
651
|
-
braceNeg = true;
|
|
652
|
-
}
|
|
653
|
-
} else if (c === "]" && !(i === braceStart + 2 && braceNeg)) {
|
|
654
|
-
inBrace = false;
|
|
655
|
-
}
|
|
656
|
-
acc += c;
|
|
657
|
-
continue;
|
|
658
|
-
} else if (c === "[") {
|
|
659
|
-
inBrace = true;
|
|
660
|
-
braceStart = i;
|
|
661
|
-
braceNeg = false;
|
|
662
|
-
acc += c;
|
|
663
|
-
continue;
|
|
664
|
-
}
|
|
665
|
-
if (isExtglobType(c) && str.charAt(i) === "(") {
|
|
666
|
-
part.push(acc);
|
|
667
|
-
acc = "";
|
|
668
|
-
const ext2 = new _AST(c, part);
|
|
669
|
-
part.push(ext2);
|
|
670
|
-
i = _AST.#parseAST(str, ext2, i, opt);
|
|
671
|
-
continue;
|
|
672
|
-
}
|
|
673
|
-
if (c === "|") {
|
|
674
|
-
part.push(acc);
|
|
675
|
-
acc = "";
|
|
676
|
-
parts.push(part);
|
|
677
|
-
part = new _AST(null, ast);
|
|
678
|
-
continue;
|
|
679
|
-
}
|
|
680
|
-
if (c === ")") {
|
|
681
|
-
if (acc === "" && ast.#parts.length === 0) {
|
|
682
|
-
ast.#emptyExt = true;
|
|
683
|
-
}
|
|
684
|
-
part.push(acc);
|
|
685
|
-
acc = "";
|
|
686
|
-
ast.push(...parts, part);
|
|
687
|
-
return i;
|
|
688
|
-
}
|
|
689
|
-
acc += c;
|
|
690
|
-
}
|
|
691
|
-
ast.type = null;
|
|
692
|
-
ast.#hasMagic = void 0;
|
|
693
|
-
ast.#parts = [str.substring(pos - 1)];
|
|
694
|
-
return i;
|
|
695
|
-
}
|
|
696
|
-
static fromGlob(pattern, options = {}) {
|
|
697
|
-
const ast = new _AST(null, void 0, options);
|
|
698
|
-
_AST.#parseAST(pattern, ast, 0, options);
|
|
699
|
-
return ast;
|
|
700
|
-
}
|
|
701
|
-
// returns the regular expression if there's magic, or the unescaped
|
|
702
|
-
// string if not.
|
|
703
|
-
toMMPattern() {
|
|
704
|
-
if (this !== this.#root)
|
|
705
|
-
return this.#root.toMMPattern();
|
|
706
|
-
const glob = this.toString();
|
|
707
|
-
const [re, body, hasMagic, uflag] = this.toRegExpSource();
|
|
708
|
-
const anyMagic = hasMagic || this.#hasMagic || this.#options.nocase && !this.#options.nocaseMagicOnly && glob.toUpperCase() !== glob.toLowerCase();
|
|
709
|
-
if (!anyMagic) {
|
|
710
|
-
return body;
|
|
711
|
-
}
|
|
712
|
-
const flags = (this.#options.nocase ? "i" : "") + (uflag ? "u" : "");
|
|
713
|
-
return Object.assign(new RegExp(`^${re}$`, flags), {
|
|
714
|
-
_src: re,
|
|
715
|
-
_glob: glob
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
get options() {
|
|
719
|
-
return this.#options;
|
|
720
|
-
}
|
|
721
|
-
// returns the string match, the regexp source, whether there's magic
|
|
722
|
-
// in the regexp (so a regular expression is required) and whether or
|
|
723
|
-
// not the uflag is needed for the regular expression (for posix classes)
|
|
724
|
-
// TODO: instead of injecting the start/end at this point, just return
|
|
725
|
-
// the BODY of the regexp, along with the start/end portions suitable
|
|
726
|
-
// for binding the start/end in either a joined full-path makeRe context
|
|
727
|
-
// (where we bind to (^|/), or a standalone matchPart context (where
|
|
728
|
-
// we bind to ^, and not /). Otherwise slashes get duped!
|
|
729
|
-
//
|
|
730
|
-
// In part-matching mode, the start is:
|
|
731
|
-
// - if not isStart: nothing
|
|
732
|
-
// - if traversal possible, but not allowed: ^(?!\.\.?$)
|
|
733
|
-
// - if dots allowed or not possible: ^
|
|
734
|
-
// - if dots possible and not allowed: ^(?!\.)
|
|
735
|
-
// end is:
|
|
736
|
-
// - if not isEnd(): nothing
|
|
737
|
-
// - else: $
|
|
738
|
-
//
|
|
739
|
-
// In full-path matching mode, we put the slash at the START of the
|
|
740
|
-
// pattern, so start is:
|
|
741
|
-
// - if first pattern: same as part-matching mode
|
|
742
|
-
// - if not isStart(): nothing
|
|
743
|
-
// - if traversal possible, but not allowed: /(?!\.\.?(?:$|/))
|
|
744
|
-
// - if dots allowed or not possible: /
|
|
745
|
-
// - if dots possible and not allowed: /(?!\.)
|
|
746
|
-
// end is:
|
|
747
|
-
// - if last pattern, same as part-matching mode
|
|
748
|
-
// - else nothing
|
|
749
|
-
//
|
|
750
|
-
// Always put the (?:$|/) on negated tails, though, because that has to be
|
|
751
|
-
// there to bind the end of the negated pattern portion, and it's easier to
|
|
752
|
-
// just stick it in now rather than try to inject it later in the middle of
|
|
753
|
-
// the pattern.
|
|
754
|
-
//
|
|
755
|
-
// We can just always return the same end, and leave it up to the caller
|
|
756
|
-
// to know whether it's going to be used joined or in parts.
|
|
757
|
-
// And, if the start is adjusted slightly, can do the same there:
|
|
758
|
-
// - if not isStart: nothing
|
|
759
|
-
// - if traversal possible, but not allowed: (?:/|^)(?!\.\.?$)
|
|
760
|
-
// - if dots allowed or not possible: (?:/|^)
|
|
761
|
-
// - if dots possible and not allowed: (?:/|^)(?!\.)
|
|
762
|
-
//
|
|
763
|
-
// But it's better to have a simpler binding without a conditional, for
|
|
764
|
-
// performance, so probably better to return both start options.
|
|
765
|
-
//
|
|
766
|
-
// Then the caller just ignores the end if it's not the first pattern,
|
|
767
|
-
// and the start always gets applied.
|
|
768
|
-
//
|
|
769
|
-
// But that's always going to be $ if it's the ending pattern, or nothing,
|
|
770
|
-
// so the caller can just attach $ at the end of the pattern when building.
|
|
771
|
-
//
|
|
772
|
-
// So the todo is:
|
|
773
|
-
// - better detect what kind of start is needed
|
|
774
|
-
// - return both flavors of starting pattern
|
|
775
|
-
// - attach $ at the end of the pattern when creating the actual RegExp
|
|
776
|
-
//
|
|
777
|
-
// Ah, but wait, no, that all only applies to the root when the first pattern
|
|
778
|
-
// is not an extglob. If the first pattern IS an extglob, then we need all
|
|
779
|
-
// that dot prevention biz to live in the extglob portions, because eg
|
|
780
|
-
// +(*|.x*) can match .xy but not .yx.
|
|
781
|
-
//
|
|
782
|
-
// So, return the two flavors if it's #root and the first child is not an
|
|
783
|
-
// AST, otherwise leave it to the child AST to handle it, and there,
|
|
784
|
-
// use the (?:^|/) style of start binding.
|
|
785
|
-
//
|
|
786
|
-
// Even simplified further:
|
|
787
|
-
// - Since the start for a join is eg /(?!\.) and the start for a part
|
|
788
|
-
// is ^(?!\.), we can just prepend (?!\.) to the pattern (either root
|
|
789
|
-
// or start or whatever) and prepend ^ or / at the Regexp construction.
|
|
790
|
-
toRegExpSource(allowDot) {
|
|
791
|
-
const dot = allowDot ?? !!this.#options.dot;
|
|
792
|
-
if (this.#root === this)
|
|
793
|
-
this.#fillNegs();
|
|
794
|
-
if (!this.type) {
|
|
795
|
-
const noEmpty = this.isStart() && this.isEnd();
|
|
796
|
-
const src = this.#parts.map((p) => {
|
|
797
|
-
const [re, _, hasMagic, uflag] = typeof p === "string" ? _AST.#parseGlob(p, this.#hasMagic, noEmpty) : p.toRegExpSource(allowDot);
|
|
798
|
-
this.#hasMagic = this.#hasMagic || hasMagic;
|
|
799
|
-
this.#uflag = this.#uflag || uflag;
|
|
800
|
-
return re;
|
|
801
|
-
}).join("");
|
|
802
|
-
let start2 = "";
|
|
803
|
-
if (this.isStart()) {
|
|
804
|
-
if (typeof this.#parts[0] === "string") {
|
|
805
|
-
const dotTravAllowed = this.#parts.length === 1 && justDots.has(this.#parts[0]);
|
|
806
|
-
if (!dotTravAllowed) {
|
|
807
|
-
const aps = addPatternStart;
|
|
808
|
-
const needNoTrav = (
|
|
809
|
-
// dots are allowed, and the pattern starts with [ or .
|
|
810
|
-
dot && aps.has(src.charAt(0)) || // the pattern starts with \., and then [ or .
|
|
811
|
-
src.startsWith("\\.") && aps.has(src.charAt(2)) || // the pattern starts with \.\., and then [ or .
|
|
812
|
-
src.startsWith("\\.\\.") && aps.has(src.charAt(4))
|
|
813
|
-
);
|
|
814
|
-
const needNoDot = !dot && !allowDot && aps.has(src.charAt(0));
|
|
815
|
-
start2 = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : "";
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
let end = "";
|
|
820
|
-
if (this.isEnd() && this.#root.#filledNegs && this.#parent?.type === "!") {
|
|
821
|
-
end = "(?:$|\\/)";
|
|
822
|
-
}
|
|
823
|
-
const final2 = start2 + src + end;
|
|
824
|
-
return [
|
|
825
|
-
final2,
|
|
826
|
-
unescape(src),
|
|
827
|
-
this.#hasMagic = !!this.#hasMagic,
|
|
828
|
-
this.#uflag
|
|
829
|
-
];
|
|
830
|
-
}
|
|
831
|
-
const repeated = this.type === "*" || this.type === "+";
|
|
832
|
-
const start = this.type === "!" ? "(?:(?!(?:" : "(?:";
|
|
833
|
-
let body = this.#partsToRegExp(dot);
|
|
834
|
-
if (this.isStart() && this.isEnd() && !body && this.type !== "!") {
|
|
835
|
-
const s = this.toString();
|
|
836
|
-
this.#parts = [s];
|
|
837
|
-
this.type = null;
|
|
838
|
-
this.#hasMagic = void 0;
|
|
839
|
-
return [s, unescape(this.toString()), false, false];
|
|
840
|
-
}
|
|
841
|
-
let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot ? "" : this.#partsToRegExp(true);
|
|
842
|
-
if (bodyDotAllowed === body) {
|
|
843
|
-
bodyDotAllowed = "";
|
|
844
|
-
}
|
|
845
|
-
if (bodyDotAllowed) {
|
|
846
|
-
body = `(?:${body})(?:${bodyDotAllowed})*?`;
|
|
847
|
-
}
|
|
848
|
-
let final = "";
|
|
849
|
-
if (this.type === "!" && this.#emptyExt) {
|
|
850
|
-
final = (this.isStart() && !dot ? startNoDot : "") + starNoEmpty;
|
|
851
|
-
} else {
|
|
852
|
-
const close = this.type === "!" ? (
|
|
853
|
-
// !() must match something,but !(x) can match ''
|
|
854
|
-
"))" + (this.isStart() && !dot && !allowDot ? startNoDot : "") + star + ")"
|
|
855
|
-
) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && bodyDotAllowed ? ")" : this.type === "*" && bodyDotAllowed ? `)?` : `)${this.type}`;
|
|
856
|
-
final = start + body + close;
|
|
857
|
-
}
|
|
858
|
-
return [
|
|
859
|
-
final,
|
|
860
|
-
unescape(body),
|
|
861
|
-
this.#hasMagic = !!this.#hasMagic,
|
|
862
|
-
this.#uflag
|
|
863
|
-
];
|
|
864
|
-
}
|
|
865
|
-
#partsToRegExp(dot) {
|
|
866
|
-
return this.#parts.map((p) => {
|
|
867
|
-
if (typeof p === "string") {
|
|
868
|
-
throw new Error("string type in extglob ast??");
|
|
869
|
-
}
|
|
870
|
-
const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot);
|
|
871
|
-
this.#uflag = this.#uflag || uflag;
|
|
872
|
-
return re;
|
|
873
|
-
}).filter((p) => !(this.isStart() && this.isEnd()) || !!p).join("|");
|
|
874
|
-
}
|
|
875
|
-
static #parseGlob(glob, hasMagic, noEmpty = false) {
|
|
876
|
-
let escaping = false;
|
|
877
|
-
let re = "";
|
|
878
|
-
let uflag = false;
|
|
879
|
-
for (let i = 0; i < glob.length; i++) {
|
|
880
|
-
const c = glob.charAt(i);
|
|
881
|
-
if (escaping) {
|
|
882
|
-
escaping = false;
|
|
883
|
-
re += (reSpecials.has(c) ? "\\" : "") + c;
|
|
884
|
-
continue;
|
|
885
|
-
}
|
|
886
|
-
if (c === "\\") {
|
|
887
|
-
if (i === glob.length - 1) {
|
|
888
|
-
re += "\\\\";
|
|
889
|
-
} else {
|
|
890
|
-
escaping = true;
|
|
891
|
-
}
|
|
892
|
-
continue;
|
|
893
|
-
}
|
|
894
|
-
if (c === "[") {
|
|
895
|
-
const [src, needUflag, consumed, magic] = parseClass(glob, i);
|
|
896
|
-
if (consumed) {
|
|
897
|
-
re += src;
|
|
898
|
-
uflag = uflag || needUflag;
|
|
899
|
-
i += consumed - 1;
|
|
900
|
-
hasMagic = hasMagic || magic;
|
|
901
|
-
continue;
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
if (c === "*") {
|
|
905
|
-
if (noEmpty && glob === "*")
|
|
906
|
-
re += starNoEmpty;
|
|
907
|
-
else
|
|
908
|
-
re += star;
|
|
909
|
-
hasMagic = true;
|
|
910
|
-
continue;
|
|
911
|
-
}
|
|
912
|
-
if (c === "?") {
|
|
913
|
-
re += qmark;
|
|
914
|
-
hasMagic = true;
|
|
915
|
-
continue;
|
|
916
|
-
}
|
|
917
|
-
re += regExpEscape(c);
|
|
918
|
-
}
|
|
919
|
-
return [re, unescape(glob), !!hasMagic, uflag];
|
|
920
|
-
}
|
|
921
|
-
};
|
|
922
|
-
|
|
923
|
-
// node_modules/minimatch/dist/esm/escape.js
|
|
924
|
-
var escape = (s, { windowsPathsNoEscape = false } = {}) => {
|
|
925
|
-
return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
|
|
926
|
-
};
|
|
927
|
-
|
|
928
|
-
// node_modules/minimatch/dist/esm/index.js
|
|
929
|
-
var minimatch = (p, pattern, options = {}) => {
|
|
930
|
-
assertValidPattern(pattern);
|
|
931
|
-
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
932
|
-
return false;
|
|
933
|
-
}
|
|
934
|
-
return new Minimatch(pattern, options).match(p);
|
|
935
|
-
};
|
|
936
|
-
var starDotExtRE = /^\*+([^+@!?\*\[\(]*)$/;
|
|
937
|
-
var starDotExtTest = (ext2) => (f) => !f.startsWith(".") && f.endsWith(ext2);
|
|
938
|
-
var starDotExtTestDot = (ext2) => (f) => f.endsWith(ext2);
|
|
939
|
-
var starDotExtTestNocase = (ext2) => {
|
|
940
|
-
ext2 = ext2.toLowerCase();
|
|
941
|
-
return (f) => !f.startsWith(".") && f.toLowerCase().endsWith(ext2);
|
|
942
|
-
};
|
|
943
|
-
var starDotExtTestNocaseDot = (ext2) => {
|
|
944
|
-
ext2 = ext2.toLowerCase();
|
|
945
|
-
return (f) => f.toLowerCase().endsWith(ext2);
|
|
946
|
-
};
|
|
947
|
-
var starDotStarRE = /^\*+\.\*+$/;
|
|
948
|
-
var starDotStarTest = (f) => !f.startsWith(".") && f.includes(".");
|
|
949
|
-
var starDotStarTestDot = (f) => f !== "." && f !== ".." && f.includes(".");
|
|
950
|
-
var dotStarRE = /^\.\*+$/;
|
|
951
|
-
var dotStarTest = (f) => f !== "." && f !== ".." && f.startsWith(".");
|
|
952
|
-
var starRE = /^\*+$/;
|
|
953
|
-
var starTest = (f) => f.length !== 0 && !f.startsWith(".");
|
|
954
|
-
var starTestDot = (f) => f.length !== 0 && f !== "." && f !== "..";
|
|
955
|
-
var qmarksRE = /^\?+([^+@!?\*\[\(]*)?$/;
|
|
956
|
-
var qmarksTestNocase = ([$0, ext2 = ""]) => {
|
|
957
|
-
const noext = qmarksTestNoExt([$0]);
|
|
958
|
-
if (!ext2)
|
|
959
|
-
return noext;
|
|
960
|
-
ext2 = ext2.toLowerCase();
|
|
961
|
-
return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
|
|
962
|
-
};
|
|
963
|
-
var qmarksTestNocaseDot = ([$0, ext2 = ""]) => {
|
|
964
|
-
const noext = qmarksTestNoExtDot([$0]);
|
|
965
|
-
if (!ext2)
|
|
966
|
-
return noext;
|
|
967
|
-
ext2 = ext2.toLowerCase();
|
|
968
|
-
return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
|
|
969
|
-
};
|
|
970
|
-
var qmarksTestDot = ([$0, ext2 = ""]) => {
|
|
971
|
-
const noext = qmarksTestNoExtDot([$0]);
|
|
972
|
-
return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
|
|
973
|
-
};
|
|
974
|
-
var qmarksTest = ([$0, ext2 = ""]) => {
|
|
975
|
-
const noext = qmarksTestNoExt([$0]);
|
|
976
|
-
return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
|
|
977
|
-
};
|
|
978
|
-
var qmarksTestNoExt = ([$0]) => {
|
|
979
|
-
const len = $0.length;
|
|
980
|
-
return (f) => f.length === len && !f.startsWith(".");
|
|
981
|
-
};
|
|
982
|
-
var qmarksTestNoExtDot = ([$0]) => {
|
|
983
|
-
const len = $0.length;
|
|
984
|
-
return (f) => f.length === len && f !== "." && f !== "..";
|
|
985
|
-
};
|
|
986
|
-
var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
987
|
-
var path2 = {
|
|
988
|
-
win32: { sep: "\\" },
|
|
989
|
-
posix: { sep: "/" }
|
|
990
|
-
};
|
|
991
|
-
var sep = defaultPlatform === "win32" ? path2.win32.sep : path2.posix.sep;
|
|
992
|
-
minimatch.sep = sep;
|
|
993
|
-
var GLOBSTAR = Symbol("globstar **");
|
|
994
|
-
minimatch.GLOBSTAR = GLOBSTAR;
|
|
995
|
-
var qmark2 = "[^/]";
|
|
996
|
-
var star2 = qmark2 + "*?";
|
|
997
|
-
var twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
|
|
998
|
-
var twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?";
|
|
999
|
-
var filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options);
|
|
1000
|
-
minimatch.filter = filter;
|
|
1001
|
-
var ext = (a, b = {}) => Object.assign({}, a, b);
|
|
1002
|
-
var defaults = (def) => {
|
|
1003
|
-
if (!def || typeof def !== "object" || !Object.keys(def).length) {
|
|
1004
|
-
return minimatch;
|
|
1005
|
-
}
|
|
1006
|
-
const orig = minimatch;
|
|
1007
|
-
const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
|
|
1008
|
-
return Object.assign(m, {
|
|
1009
|
-
Minimatch: class Minimatch extends orig.Minimatch {
|
|
1010
|
-
constructor(pattern, options = {}) {
|
|
1011
|
-
super(pattern, ext(def, options));
|
|
1012
|
-
}
|
|
1013
|
-
static defaults(options) {
|
|
1014
|
-
return orig.defaults(ext(def, options)).Minimatch;
|
|
1015
|
-
}
|
|
1016
|
-
},
|
|
1017
|
-
AST: class AST extends orig.AST {
|
|
1018
|
-
/* c8 ignore start */
|
|
1019
|
-
constructor(type, parent, options = {}) {
|
|
1020
|
-
super(type, parent, ext(def, options));
|
|
1021
|
-
}
|
|
1022
|
-
/* c8 ignore stop */
|
|
1023
|
-
static fromGlob(pattern, options = {}) {
|
|
1024
|
-
return orig.AST.fromGlob(pattern, ext(def, options));
|
|
1025
|
-
}
|
|
1026
|
-
},
|
|
1027
|
-
unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
|
|
1028
|
-
escape: (s, options = {}) => orig.escape(s, ext(def, options)),
|
|
1029
|
-
filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
|
|
1030
|
-
defaults: (options) => orig.defaults(ext(def, options)),
|
|
1031
|
-
makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)),
|
|
1032
|
-
braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
|
|
1033
|
-
match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
|
|
1034
|
-
sep: orig.sep,
|
|
1035
|
-
GLOBSTAR
|
|
1036
|
-
});
|
|
1037
|
-
};
|
|
1038
|
-
minimatch.defaults = defaults;
|
|
1039
|
-
var braceExpand = (pattern, options = {}) => {
|
|
1040
|
-
assertValidPattern(pattern);
|
|
1041
|
-
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
|
|
1042
|
-
return [pattern];
|
|
1043
|
-
}
|
|
1044
|
-
return (0, import_brace_expansion.default)(pattern);
|
|
1045
|
-
};
|
|
1046
|
-
minimatch.braceExpand = braceExpand;
|
|
1047
|
-
var makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe();
|
|
1048
|
-
minimatch.makeRe = makeRe;
|
|
1049
|
-
var match = (list, pattern, options = {}) => {
|
|
1050
|
-
const mm = new Minimatch(pattern, options);
|
|
1051
|
-
list = list.filter((f) => mm.match(f));
|
|
1052
|
-
if (mm.options.nonull && !list.length) {
|
|
1053
|
-
list.push(pattern);
|
|
1054
|
-
}
|
|
1055
|
-
return list;
|
|
1056
|
-
};
|
|
1057
|
-
minimatch.match = match;
|
|
1058
|
-
var globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
|
|
1059
|
-
var regExpEscape2 = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
1060
|
-
var Minimatch = class {
|
|
1061
|
-
options;
|
|
1062
|
-
set;
|
|
1063
|
-
pattern;
|
|
1064
|
-
windowsPathsNoEscape;
|
|
1065
|
-
nonegate;
|
|
1066
|
-
negate;
|
|
1067
|
-
comment;
|
|
1068
|
-
empty;
|
|
1069
|
-
preserveMultipleSlashes;
|
|
1070
|
-
partial;
|
|
1071
|
-
globSet;
|
|
1072
|
-
globParts;
|
|
1073
|
-
nocase;
|
|
1074
|
-
isWindows;
|
|
1075
|
-
platform;
|
|
1076
|
-
windowsNoMagicRoot;
|
|
1077
|
-
regexp;
|
|
1078
|
-
constructor(pattern, options = {}) {
|
|
1079
|
-
assertValidPattern(pattern);
|
|
1080
|
-
options = options || {};
|
|
1081
|
-
this.options = options;
|
|
1082
|
-
this.pattern = pattern;
|
|
1083
|
-
this.platform = options.platform || defaultPlatform;
|
|
1084
|
-
this.isWindows = this.platform === "win32";
|
|
1085
|
-
this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options.allowWindowsEscape === false;
|
|
1086
|
-
if (this.windowsPathsNoEscape) {
|
|
1087
|
-
this.pattern = this.pattern.replace(/\\/g, "/");
|
|
1088
|
-
}
|
|
1089
|
-
this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
|
|
1090
|
-
this.regexp = null;
|
|
1091
|
-
this.negate = false;
|
|
1092
|
-
this.nonegate = !!options.nonegate;
|
|
1093
|
-
this.comment = false;
|
|
1094
|
-
this.empty = false;
|
|
1095
|
-
this.partial = !!options.partial;
|
|
1096
|
-
this.nocase = !!this.options.nocase;
|
|
1097
|
-
this.windowsNoMagicRoot = options.windowsNoMagicRoot !== void 0 ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
|
|
1098
|
-
this.globSet = [];
|
|
1099
|
-
this.globParts = [];
|
|
1100
|
-
this.set = [];
|
|
1101
|
-
this.make();
|
|
1102
|
-
}
|
|
1103
|
-
hasMagic() {
|
|
1104
|
-
if (this.options.magicalBraces && this.set.length > 1) {
|
|
1105
|
-
return true;
|
|
1106
|
-
}
|
|
1107
|
-
for (const pattern of this.set) {
|
|
1108
|
-
for (const part of pattern) {
|
|
1109
|
-
if (typeof part !== "string")
|
|
1110
|
-
return true;
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
return false;
|
|
1114
|
-
}
|
|
1115
|
-
debug(..._) {
|
|
1116
|
-
}
|
|
1117
|
-
make() {
|
|
1118
|
-
const pattern = this.pattern;
|
|
1119
|
-
const options = this.options;
|
|
1120
|
-
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
1121
|
-
this.comment = true;
|
|
1122
|
-
return;
|
|
1123
|
-
}
|
|
1124
|
-
if (!pattern) {
|
|
1125
|
-
this.empty = true;
|
|
1126
|
-
return;
|
|
1127
|
-
}
|
|
1128
|
-
this.parseNegate();
|
|
1129
|
-
this.globSet = [...new Set(this.braceExpand())];
|
|
1130
|
-
if (options.debug) {
|
|
1131
|
-
this.debug = (...args) => console.error(...args);
|
|
1132
|
-
}
|
|
1133
|
-
this.debug(this.pattern, this.globSet);
|
|
1134
|
-
const rawGlobParts = this.globSet.map((s) => this.slashSplit(s));
|
|
1135
|
-
this.globParts = this.preprocess(rawGlobParts);
|
|
1136
|
-
this.debug(this.pattern, this.globParts);
|
|
1137
|
-
let set = this.globParts.map((s, _, __) => {
|
|
1138
|
-
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
1139
|
-
const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]);
|
|
1140
|
-
const isDrive = /^[a-z]:/i.test(s[0]);
|
|
1141
|
-
if (isUNC) {
|
|
1142
|
-
return [...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss))];
|
|
1143
|
-
} else if (isDrive) {
|
|
1144
|
-
return [s[0], ...s.slice(1).map((ss) => this.parse(ss))];
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
return s.map((ss) => this.parse(ss));
|
|
1148
|
-
});
|
|
1149
|
-
this.debug(this.pattern, set);
|
|
1150
|
-
this.set = set.filter((s) => s.indexOf(false) === -1);
|
|
1151
|
-
if (this.isWindows) {
|
|
1152
|
-
for (let i = 0; i < this.set.length; i++) {
|
|
1153
|
-
const p = this.set[i];
|
|
1154
|
-
if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && typeof p[3] === "string" && /^[a-z]:$/i.test(p[3])) {
|
|
1155
|
-
p[2] = "?";
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
this.debug(this.pattern, this.set);
|
|
1160
|
-
}
|
|
1161
|
-
// various transforms to equivalent pattern sets that are
|
|
1162
|
-
// faster to process in a filesystem walk. The goal is to
|
|
1163
|
-
// eliminate what we can, and push all ** patterns as far
|
|
1164
|
-
// to the right as possible, even if it increases the number
|
|
1165
|
-
// of patterns that we have to process.
|
|
1166
|
-
preprocess(globParts) {
|
|
1167
|
-
if (this.options.noglobstar) {
|
|
1168
|
-
for (let i = 0; i < globParts.length; i++) {
|
|
1169
|
-
for (let j = 0; j < globParts[i].length; j++) {
|
|
1170
|
-
if (globParts[i][j] === "**") {
|
|
1171
|
-
globParts[i][j] = "*";
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
const { optimizationLevel = 1 } = this.options;
|
|
1177
|
-
if (optimizationLevel >= 2) {
|
|
1178
|
-
globParts = this.firstPhasePreProcess(globParts);
|
|
1179
|
-
globParts = this.secondPhasePreProcess(globParts);
|
|
1180
|
-
} else if (optimizationLevel >= 1) {
|
|
1181
|
-
globParts = this.levelOneOptimize(globParts);
|
|
1182
|
-
} else {
|
|
1183
|
-
globParts = this.adjascentGlobstarOptimize(globParts);
|
|
1184
|
-
}
|
|
1185
|
-
return globParts;
|
|
1186
|
-
}
|
|
1187
|
-
// just get rid of adjascent ** portions
|
|
1188
|
-
adjascentGlobstarOptimize(globParts) {
|
|
1189
|
-
return globParts.map((parts) => {
|
|
1190
|
-
let gs = -1;
|
|
1191
|
-
while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
|
|
1192
|
-
let i = gs;
|
|
1193
|
-
while (parts[i + 1] === "**") {
|
|
1194
|
-
i++;
|
|
1195
|
-
}
|
|
1196
|
-
if (i !== gs) {
|
|
1197
|
-
parts.splice(gs, i - gs);
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
return parts;
|
|
1201
|
-
});
|
|
1202
|
-
}
|
|
1203
|
-
// get rid of adjascent ** and resolve .. portions
|
|
1204
|
-
levelOneOptimize(globParts) {
|
|
1205
|
-
return globParts.map((parts) => {
|
|
1206
|
-
parts = parts.reduce((set, part) => {
|
|
1207
|
-
const prev = set[set.length - 1];
|
|
1208
|
-
if (part === "**" && prev === "**") {
|
|
1209
|
-
return set;
|
|
1210
|
-
}
|
|
1211
|
-
if (part === "..") {
|
|
1212
|
-
if (prev && prev !== ".." && prev !== "." && prev !== "**") {
|
|
1213
|
-
set.pop();
|
|
1214
|
-
return set;
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
set.push(part);
|
|
1218
|
-
return set;
|
|
1219
|
-
}, []);
|
|
1220
|
-
return parts.length === 0 ? [""] : parts;
|
|
1221
|
-
});
|
|
1222
|
-
}
|
|
1223
|
-
levelTwoFileOptimize(parts) {
|
|
1224
|
-
if (!Array.isArray(parts)) {
|
|
1225
|
-
parts = this.slashSplit(parts);
|
|
1226
|
-
}
|
|
1227
|
-
let didSomething = false;
|
|
1228
|
-
do {
|
|
1229
|
-
didSomething = false;
|
|
1230
|
-
if (!this.preserveMultipleSlashes) {
|
|
1231
|
-
for (let i = 1; i < parts.length - 1; i++) {
|
|
1232
|
-
const p = parts[i];
|
|
1233
|
-
if (i === 1 && p === "" && parts[0] === "")
|
|
1234
|
-
continue;
|
|
1235
|
-
if (p === "." || p === "") {
|
|
1236
|
-
didSomething = true;
|
|
1237
|
-
parts.splice(i, 1);
|
|
1238
|
-
i--;
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
1242
|
-
didSomething = true;
|
|
1243
|
-
parts.pop();
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
let dd = 0;
|
|
1247
|
-
while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
|
|
1248
|
-
const p = parts[dd - 1];
|
|
1249
|
-
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
1250
|
-
didSomething = true;
|
|
1251
|
-
parts.splice(dd - 1, 2);
|
|
1252
|
-
dd -= 2;
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
} while (didSomething);
|
|
1256
|
-
return parts.length === 0 ? [""] : parts;
|
|
1257
|
-
}
|
|
1258
|
-
// First phase: single-pattern processing
|
|
1259
|
-
// <pre> is 1 or more portions
|
|
1260
|
-
// <rest> is 1 or more portions
|
|
1261
|
-
// <p> is any portion other than ., .., '', or **
|
|
1262
|
-
// <e> is . or ''
|
|
1263
|
-
//
|
|
1264
|
-
// **/.. is *brutal* for filesystem walking performance, because
|
|
1265
|
-
// it effectively resets the recursive walk each time it occurs,
|
|
1266
|
-
// and ** cannot be reduced out by a .. pattern part like a regexp
|
|
1267
|
-
// or most strings (other than .., ., and '') can be.
|
|
1268
|
-
//
|
|
1269
|
-
// <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
|
|
1270
|
-
// <pre>/<e>/<rest> -> <pre>/<rest>
|
|
1271
|
-
// <pre>/<p>/../<rest> -> <pre>/<rest>
|
|
1272
|
-
// **/**/<rest> -> **/<rest>
|
|
1273
|
-
//
|
|
1274
|
-
// **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
|
|
1275
|
-
// this WOULD be allowed if ** did follow symlinks, or * didn't
|
|
1276
|
-
firstPhasePreProcess(globParts) {
|
|
1277
|
-
let didSomething = false;
|
|
1278
|
-
do {
|
|
1279
|
-
didSomething = false;
|
|
1280
|
-
for (let parts of globParts) {
|
|
1281
|
-
let gs = -1;
|
|
1282
|
-
while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
|
|
1283
|
-
let gss = gs;
|
|
1284
|
-
while (parts[gss + 1] === "**") {
|
|
1285
|
-
gss++;
|
|
1286
|
-
}
|
|
1287
|
-
if (gss > gs) {
|
|
1288
|
-
parts.splice(gs + 1, gss - gs);
|
|
1289
|
-
}
|
|
1290
|
-
let next = parts[gs + 1];
|
|
1291
|
-
const p = parts[gs + 2];
|
|
1292
|
-
const p2 = parts[gs + 3];
|
|
1293
|
-
if (next !== "..")
|
|
1294
|
-
continue;
|
|
1295
|
-
if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") {
|
|
1296
|
-
continue;
|
|
1297
|
-
}
|
|
1298
|
-
didSomething = true;
|
|
1299
|
-
parts.splice(gs, 1);
|
|
1300
|
-
const other = parts.slice(0);
|
|
1301
|
-
other[gs] = "**";
|
|
1302
|
-
globParts.push(other);
|
|
1303
|
-
gs--;
|
|
1304
|
-
}
|
|
1305
|
-
if (!this.preserveMultipleSlashes) {
|
|
1306
|
-
for (let i = 1; i < parts.length - 1; i++) {
|
|
1307
|
-
const p = parts[i];
|
|
1308
|
-
if (i === 1 && p === "" && parts[0] === "")
|
|
1309
|
-
continue;
|
|
1310
|
-
if (p === "." || p === "") {
|
|
1311
|
-
didSomething = true;
|
|
1312
|
-
parts.splice(i, 1);
|
|
1313
|
-
i--;
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
1317
|
-
didSomething = true;
|
|
1318
|
-
parts.pop();
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
let dd = 0;
|
|
1322
|
-
while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
|
|
1323
|
-
const p = parts[dd - 1];
|
|
1324
|
-
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
1325
|
-
didSomething = true;
|
|
1326
|
-
const needDot = dd === 1 && parts[dd + 1] === "**";
|
|
1327
|
-
const splin = needDot ? ["."] : [];
|
|
1328
|
-
parts.splice(dd - 1, 2, ...splin);
|
|
1329
|
-
if (parts.length === 0)
|
|
1330
|
-
parts.push("");
|
|
1331
|
-
dd -= 2;
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
} while (didSomething);
|
|
1336
|
-
return globParts;
|
|
1337
|
-
}
|
|
1338
|
-
// second phase: multi-pattern dedupes
|
|
1339
|
-
// {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
|
|
1340
|
-
// {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
|
|
1341
|
-
// {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
|
|
1342
|
-
//
|
|
1343
|
-
// {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
|
|
1344
|
-
// ^-- not valid because ** doens't follow symlinks
|
|
1345
|
-
secondPhasePreProcess(globParts) {
|
|
1346
|
-
for (let i = 0; i < globParts.length - 1; i++) {
|
|
1347
|
-
for (let j = i + 1; j < globParts.length; j++) {
|
|
1348
|
-
const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);
|
|
1349
|
-
if (matched) {
|
|
1350
|
-
globParts[i] = [];
|
|
1351
|
-
globParts[j] = matched;
|
|
1352
|
-
break;
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
return globParts.filter((gs) => gs.length);
|
|
1357
|
-
}
|
|
1358
|
-
partsMatch(a, b, emptyGSMatch = false) {
|
|
1359
|
-
let ai = 0;
|
|
1360
|
-
let bi = 0;
|
|
1361
|
-
let result = [];
|
|
1362
|
-
let which = "";
|
|
1363
|
-
while (ai < a.length && bi < b.length) {
|
|
1364
|
-
if (a[ai] === b[bi]) {
|
|
1365
|
-
result.push(which === "b" ? b[bi] : a[ai]);
|
|
1366
|
-
ai++;
|
|
1367
|
-
bi++;
|
|
1368
|
-
} else if (emptyGSMatch && a[ai] === "**" && b[bi] === a[ai + 1]) {
|
|
1369
|
-
result.push(a[ai]);
|
|
1370
|
-
ai++;
|
|
1371
|
-
} else if (emptyGSMatch && b[bi] === "**" && a[ai] === b[bi + 1]) {
|
|
1372
|
-
result.push(b[bi]);
|
|
1373
|
-
bi++;
|
|
1374
|
-
} else if (a[ai] === "*" && b[bi] && (this.options.dot || !b[bi].startsWith(".")) && b[bi] !== "**") {
|
|
1375
|
-
if (which === "b")
|
|
1376
|
-
return false;
|
|
1377
|
-
which = "a";
|
|
1378
|
-
result.push(a[ai]);
|
|
1379
|
-
ai++;
|
|
1380
|
-
bi++;
|
|
1381
|
-
} else if (b[bi] === "*" && a[ai] && (this.options.dot || !a[ai].startsWith(".")) && a[ai] !== "**") {
|
|
1382
|
-
if (which === "a")
|
|
1383
|
-
return false;
|
|
1384
|
-
which = "b";
|
|
1385
|
-
result.push(b[bi]);
|
|
1386
|
-
ai++;
|
|
1387
|
-
bi++;
|
|
1388
|
-
} else {
|
|
1389
|
-
return false;
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
return a.length === b.length && result;
|
|
1393
|
-
}
|
|
1394
|
-
parseNegate() {
|
|
1395
|
-
if (this.nonegate)
|
|
1396
|
-
return;
|
|
1397
|
-
const pattern = this.pattern;
|
|
1398
|
-
let negate = false;
|
|
1399
|
-
let negateOffset = 0;
|
|
1400
|
-
for (let i = 0; i < pattern.length && pattern.charAt(i) === "!"; i++) {
|
|
1401
|
-
negate = !negate;
|
|
1402
|
-
negateOffset++;
|
|
1403
|
-
}
|
|
1404
|
-
if (negateOffset)
|
|
1405
|
-
this.pattern = pattern.slice(negateOffset);
|
|
1406
|
-
this.negate = negate;
|
|
1407
|
-
}
|
|
1408
|
-
// set partial to true to test if, for example,
|
|
1409
|
-
// "/a/b" matches the start of "/*/b/*/d"
|
|
1410
|
-
// Partial means, if you run out of file before you run
|
|
1411
|
-
// out of pattern, then that's fine, as long as all
|
|
1412
|
-
// the parts match.
|
|
1413
|
-
matchOne(file, pattern, partial = false) {
|
|
1414
|
-
const options = this.options;
|
|
1415
|
-
if (this.isWindows) {
|
|
1416
|
-
const fileDrive = typeof file[0] === "string" && /^[a-z]:$/i.test(file[0]);
|
|
1417
|
-
const fileUNC = !fileDrive && file[0] === "" && file[1] === "" && file[2] === "?" && /^[a-z]:$/i.test(file[3]);
|
|
1418
|
-
const patternDrive = typeof pattern[0] === "string" && /^[a-z]:$/i.test(pattern[0]);
|
|
1419
|
-
const patternUNC = !patternDrive && pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
|
|
1420
|
-
const fdi = fileUNC ? 3 : fileDrive ? 0 : void 0;
|
|
1421
|
-
const pdi = patternUNC ? 3 : patternDrive ? 0 : void 0;
|
|
1422
|
-
if (typeof fdi === "number" && typeof pdi === "number") {
|
|
1423
|
-
const [fd, pd] = [file[fdi], pattern[pdi]];
|
|
1424
|
-
if (fd.toLowerCase() === pd.toLowerCase()) {
|
|
1425
|
-
pattern[pdi] = fd;
|
|
1426
|
-
if (pdi > fdi) {
|
|
1427
|
-
pattern = pattern.slice(pdi);
|
|
1428
|
-
} else if (fdi > pdi) {
|
|
1429
|
-
file = file.slice(fdi);
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
const { optimizationLevel = 1 } = this.options;
|
|
1435
|
-
if (optimizationLevel >= 2) {
|
|
1436
|
-
file = this.levelTwoFileOptimize(file);
|
|
1437
|
-
}
|
|
1438
|
-
this.debug("matchOne", this, { file, pattern });
|
|
1439
|
-
this.debug("matchOne", file.length, pattern.length);
|
|
1440
|
-
for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
|
|
1441
|
-
this.debug("matchOne loop");
|
|
1442
|
-
var p = pattern[pi];
|
|
1443
|
-
var f = file[fi];
|
|
1444
|
-
this.debug(pattern, p, f);
|
|
1445
|
-
if (p === false) {
|
|
1446
|
-
return false;
|
|
1447
|
-
}
|
|
1448
|
-
if (p === GLOBSTAR) {
|
|
1449
|
-
this.debug("GLOBSTAR", [pattern, p, f]);
|
|
1450
|
-
var fr = fi;
|
|
1451
|
-
var pr = pi + 1;
|
|
1452
|
-
if (pr === pl) {
|
|
1453
|
-
this.debug("** at the end");
|
|
1454
|
-
for (; fi < fl; fi++) {
|
|
1455
|
-
if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".")
|
|
1456
|
-
return false;
|
|
1457
|
-
}
|
|
1458
|
-
return true;
|
|
1459
|
-
}
|
|
1460
|
-
while (fr < fl) {
|
|
1461
|
-
var swallowee = file[fr];
|
|
1462
|
-
this.debug("\nglobstar while", file, fr, pattern, pr, swallowee);
|
|
1463
|
-
if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
|
|
1464
|
-
this.debug("globstar found match!", fr, fl, swallowee);
|
|
1465
|
-
return true;
|
|
1466
|
-
} else {
|
|
1467
|
-
if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
|
|
1468
|
-
this.debug("dot detected!", file, fr, pattern, pr);
|
|
1469
|
-
break;
|
|
1470
|
-
}
|
|
1471
|
-
this.debug("globstar swallow a segment, and continue");
|
|
1472
|
-
fr++;
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
if (partial) {
|
|
1476
|
-
this.debug("\n>>> no match, partial?", file, fr, pattern, pr);
|
|
1477
|
-
if (fr === fl) {
|
|
1478
|
-
return true;
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
return false;
|
|
1482
|
-
}
|
|
1483
|
-
let hit;
|
|
1484
|
-
if (typeof p === "string") {
|
|
1485
|
-
hit = f === p;
|
|
1486
|
-
this.debug("string match", p, f, hit);
|
|
1487
|
-
} else {
|
|
1488
|
-
hit = p.test(f);
|
|
1489
|
-
this.debug("pattern match", p, f, hit);
|
|
1490
|
-
}
|
|
1491
|
-
if (!hit)
|
|
1492
|
-
return false;
|
|
1493
|
-
}
|
|
1494
|
-
if (fi === fl && pi === pl) {
|
|
1495
|
-
return true;
|
|
1496
|
-
} else if (fi === fl) {
|
|
1497
|
-
return partial;
|
|
1498
|
-
} else if (pi === pl) {
|
|
1499
|
-
return fi === fl - 1 && file[fi] === "";
|
|
1500
|
-
} else {
|
|
1501
|
-
throw new Error("wtf?");
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
braceExpand() {
|
|
1505
|
-
return braceExpand(this.pattern, this.options);
|
|
1506
|
-
}
|
|
1507
|
-
parse(pattern) {
|
|
1508
|
-
assertValidPattern(pattern);
|
|
1509
|
-
const options = this.options;
|
|
1510
|
-
if (pattern === "**")
|
|
1511
|
-
return GLOBSTAR;
|
|
1512
|
-
if (pattern === "")
|
|
1513
|
-
return "";
|
|
1514
|
-
let m;
|
|
1515
|
-
let fastTest = null;
|
|
1516
|
-
if (m = pattern.match(starRE)) {
|
|
1517
|
-
fastTest = options.dot ? starTestDot : starTest;
|
|
1518
|
-
} else if (m = pattern.match(starDotExtRE)) {
|
|
1519
|
-
fastTest = (options.nocase ? options.dot ? starDotExtTestNocaseDot : starDotExtTestNocase : options.dot ? starDotExtTestDot : starDotExtTest)(m[1]);
|
|
1520
|
-
} else if (m = pattern.match(qmarksRE)) {
|
|
1521
|
-
fastTest = (options.nocase ? options.dot ? qmarksTestNocaseDot : qmarksTestNocase : options.dot ? qmarksTestDot : qmarksTest)(m);
|
|
1522
|
-
} else if (m = pattern.match(starDotStarRE)) {
|
|
1523
|
-
fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
|
|
1524
|
-
} else if (m = pattern.match(dotStarRE)) {
|
|
1525
|
-
fastTest = dotStarTest;
|
|
1526
|
-
}
|
|
1527
|
-
const re = AST.fromGlob(pattern, this.options).toMMPattern();
|
|
1528
|
-
if (fastTest && typeof re === "object") {
|
|
1529
|
-
Reflect.defineProperty(re, "test", { value: fastTest });
|
|
1530
|
-
}
|
|
1531
|
-
return re;
|
|
1532
|
-
}
|
|
1533
|
-
makeRe() {
|
|
1534
|
-
if (this.regexp || this.regexp === false)
|
|
1535
|
-
return this.regexp;
|
|
1536
|
-
const set = this.set;
|
|
1537
|
-
if (!set.length) {
|
|
1538
|
-
this.regexp = false;
|
|
1539
|
-
return this.regexp;
|
|
1540
|
-
}
|
|
1541
|
-
const options = this.options;
|
|
1542
|
-
const twoStar = options.noglobstar ? star2 : options.dot ? twoStarDot : twoStarNoDot;
|
|
1543
|
-
const flags = new Set(options.nocase ? ["i"] : []);
|
|
1544
|
-
let re = set.map((pattern) => {
|
|
1545
|
-
const pp = pattern.map((p) => {
|
|
1546
|
-
if (p instanceof RegExp) {
|
|
1547
|
-
for (const f of p.flags.split(""))
|
|
1548
|
-
flags.add(f);
|
|
1549
|
-
}
|
|
1550
|
-
return typeof p === "string" ? regExpEscape2(p) : p === GLOBSTAR ? GLOBSTAR : p._src;
|
|
1551
|
-
});
|
|
1552
|
-
pp.forEach((p, i) => {
|
|
1553
|
-
const next = pp[i + 1];
|
|
1554
|
-
const prev = pp[i - 1];
|
|
1555
|
-
if (p !== GLOBSTAR || prev === GLOBSTAR) {
|
|
1556
|
-
return;
|
|
1557
|
-
}
|
|
1558
|
-
if (prev === void 0) {
|
|
1559
|
-
if (next !== void 0 && next !== GLOBSTAR) {
|
|
1560
|
-
pp[i + 1] = "(?:\\/|" + twoStar + "\\/)?" + next;
|
|
1561
|
-
} else {
|
|
1562
|
-
pp[i] = twoStar;
|
|
1563
|
-
}
|
|
1564
|
-
} else if (next === void 0) {
|
|
1565
|
-
pp[i - 1] = prev + "(?:\\/|" + twoStar + ")?";
|
|
1566
|
-
} else if (next !== GLOBSTAR) {
|
|
1567
|
-
pp[i - 1] = prev + "(?:\\/|\\/" + twoStar + "\\/)" + next;
|
|
1568
|
-
pp[i + 1] = GLOBSTAR;
|
|
1569
|
-
}
|
|
1570
|
-
});
|
|
1571
|
-
return pp.filter((p) => p !== GLOBSTAR).join("/");
|
|
1572
|
-
}).join("|");
|
|
1573
|
-
const [open, close] = set.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
1574
|
-
re = "^" + open + re + close + "$";
|
|
1575
|
-
if (this.negate)
|
|
1576
|
-
re = "^(?!" + re + ").+$";
|
|
1577
|
-
try {
|
|
1578
|
-
this.regexp = new RegExp(re, [...flags].join(""));
|
|
1579
|
-
} catch (ex) {
|
|
1580
|
-
this.regexp = false;
|
|
1581
|
-
}
|
|
1582
|
-
return this.regexp;
|
|
1583
|
-
}
|
|
1584
|
-
slashSplit(p) {
|
|
1585
|
-
if (this.preserveMultipleSlashes) {
|
|
1586
|
-
return p.split("/");
|
|
1587
|
-
} else if (this.isWindows && /^\/\/[^\/]+/.test(p)) {
|
|
1588
|
-
return ["", ...p.split(/\/+/)];
|
|
1589
|
-
} else {
|
|
1590
|
-
return p.split(/\/+/);
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
match(f, partial = this.partial) {
|
|
1594
|
-
this.debug("match", f, this.pattern);
|
|
1595
|
-
if (this.comment) {
|
|
1596
|
-
return false;
|
|
1597
|
-
}
|
|
1598
|
-
if (this.empty) {
|
|
1599
|
-
return f === "";
|
|
1600
|
-
}
|
|
1601
|
-
if (f === "/" && partial) {
|
|
1602
|
-
return true;
|
|
1603
|
-
}
|
|
1604
|
-
const options = this.options;
|
|
1605
|
-
if (this.isWindows) {
|
|
1606
|
-
f = f.split("\\").join("/");
|
|
1607
|
-
}
|
|
1608
|
-
const ff = this.slashSplit(f);
|
|
1609
|
-
this.debug(this.pattern, "split", ff);
|
|
1610
|
-
const set = this.set;
|
|
1611
|
-
this.debug(this.pattern, "set", set);
|
|
1612
|
-
let filename = ff[ff.length - 1];
|
|
1613
|
-
if (!filename) {
|
|
1614
|
-
for (let i = ff.length - 2; !filename && i >= 0; i--) {
|
|
1615
|
-
filename = ff[i];
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
for (let i = 0; i < set.length; i++) {
|
|
1619
|
-
const pattern = set[i];
|
|
1620
|
-
let file = ff;
|
|
1621
|
-
if (options.matchBase && pattern.length === 1) {
|
|
1622
|
-
file = [filename];
|
|
1623
|
-
}
|
|
1624
|
-
const hit = this.matchOne(file, pattern, partial);
|
|
1625
|
-
if (hit) {
|
|
1626
|
-
if (options.flipNegate) {
|
|
1627
|
-
return true;
|
|
1628
|
-
}
|
|
1629
|
-
return !this.negate;
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
if (options.flipNegate) {
|
|
1633
|
-
return false;
|
|
1634
|
-
}
|
|
1635
|
-
return this.negate;
|
|
1636
|
-
}
|
|
1637
|
-
static defaults(def) {
|
|
1638
|
-
return minimatch.defaults(def).Minimatch;
|
|
1639
|
-
}
|
|
1640
|
-
};
|
|
1641
|
-
minimatch.AST = AST;
|
|
1642
|
-
minimatch.Minimatch = Minimatch;
|
|
1643
|
-
minimatch.escape = escape;
|
|
1644
|
-
minimatch.unescape = unescape;
|
|
1645
|
-
|
|
1646
|
-
// src/core/dir.ts
|
|
74
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
75
|
+
var import_minimatch = require("minimatch");
|
|
1647
76
|
async function directoryExists(dirPath) {
|
|
1648
77
|
try {
|
|
1649
78
|
await import_promises.default.access(dirPath, import_fs.constants.F_OK);
|
|
@@ -1656,7 +85,7 @@ async function getDirectoryItems(dirPath, targetFileName) {
|
|
|
1656
85
|
const collection = [];
|
|
1657
86
|
const files = await import_promises.default.readdir(dirPath);
|
|
1658
87
|
for (const itemName of files) {
|
|
1659
|
-
const itemPath =
|
|
88
|
+
const itemPath = import_node_path.default.resolve(dirPath, itemName);
|
|
1660
89
|
const stats = await import_promises.default.stat(itemPath);
|
|
1661
90
|
if (stats.isDirectory()) {
|
|
1662
91
|
const children = await getDirectoryItems(itemPath, targetFileName);
|
|
@@ -1668,10 +97,10 @@ async function getDirectoryItems(dirPath, targetFileName) {
|
|
|
1668
97
|
return collection;
|
|
1669
98
|
}
|
|
1670
99
|
function filterDirectoryItems(rootPath, items, include, exclude) {
|
|
1671
|
-
const includedPatterns = include.map((pattern) => new Minimatch(pattern));
|
|
1672
|
-
const excludedPatterns = exclude.map((pattern) => new Minimatch(pattern));
|
|
100
|
+
const includedPatterns = include.map((pattern) => new import_minimatch.Minimatch(pattern));
|
|
101
|
+
const excludedPatterns = exclude.map((pattern) => new import_minimatch.Minimatch(pattern));
|
|
1673
102
|
return items.filter((item) => {
|
|
1674
|
-
const relativePath =
|
|
103
|
+
const relativePath = import_node_path.default.relative(rootPath, item);
|
|
1675
104
|
const isIncluded = includedPatterns.some((pattern) => pattern.match(relativePath));
|
|
1676
105
|
const isExcluded = excludedPatterns.some((pattern) => pattern.match(relativePath));
|
|
1677
106
|
return (isIncluded || !include.length) && !isExcluded;
|
|
@@ -1680,9 +109,9 @@ function filterDirectoryItems(rootPath, items, include, exclude) {
|
|
|
1680
109
|
|
|
1681
110
|
// src/core/isDocumentedRoute.ts
|
|
1682
111
|
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
1683
|
-
async function isDocumentedRoute(
|
|
112
|
+
async function isDocumentedRoute(routePath2) {
|
|
1684
113
|
try {
|
|
1685
|
-
const rawCode = await import_promises2.default.readFile(
|
|
114
|
+
const rawCode = await import_promises2.default.readFile(routePath2, "utf-8");
|
|
1686
115
|
return rawCode.includes("@omer-x/next-openapi-route-handler");
|
|
1687
116
|
} catch {
|
|
1688
117
|
return false;
|
|
@@ -1691,7 +120,7 @@ async function isDocumentedRoute(routePath) {
|
|
|
1691
120
|
|
|
1692
121
|
// src/core/next.ts
|
|
1693
122
|
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
1694
|
-
var
|
|
123
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
1695
124
|
|
|
1696
125
|
// src/utils/generateRandomString.ts
|
|
1697
126
|
function generateRandomString(length) {
|
|
@@ -1699,9 +128,9 @@ function generateRandomString(length) {
|
|
|
1699
128
|
}
|
|
1700
129
|
|
|
1701
130
|
// src/utils/string-preservation.ts
|
|
1702
|
-
function preserveStrings(
|
|
131
|
+
function preserveStrings(code2) {
|
|
1703
132
|
let replacements = {};
|
|
1704
|
-
const output =
|
|
133
|
+
const output = code2.replace(/(['"`])((?:\\.|(?!\1).)*)\1/g, (match, quote, content) => {
|
|
1705
134
|
const replacementId = generateRandomString(32);
|
|
1706
135
|
replacements = {
|
|
1707
136
|
...replacements,
|
|
@@ -1711,69 +140,64 @@ function preserveStrings(code) {
|
|
|
1711
140
|
});
|
|
1712
141
|
return { output, replacements };
|
|
1713
142
|
}
|
|
1714
|
-
function restoreStrings(
|
|
1715
|
-
return
|
|
143
|
+
function restoreStrings(code2, replacements) {
|
|
144
|
+
return code2.replace(/<@~(.*?)~@>/g, (_, replacementId) => {
|
|
1716
145
|
return replacements[replacementId];
|
|
1717
146
|
});
|
|
1718
147
|
}
|
|
1719
148
|
|
|
1720
149
|
// src/core/injectSchemas.ts
|
|
1721
|
-
function injectSchemas(
|
|
1722
|
-
const { output: preservedCode, replacements } = preserveStrings(
|
|
150
|
+
function injectSchemas(code2, refName) {
|
|
151
|
+
const { output: preservedCode, replacements } = preserveStrings(code2);
|
|
1723
152
|
const preservedCodeWithSchemasInjected = preservedCode.replace(new RegExp(`\\b${refName}\\.`, "g"), `global.schemas[${refName}].`).replace(new RegExp(`\\b${refName}\\b`, "g"), `"${refName}"`).replace(new RegExp(`queryParams:\\s*['"\`]${refName}['"\`]`, "g"), `queryParams: global.schemas["${refName}"]`).replace(new RegExp(`pathParams:\\s*['"\`]${refName}['"\`]`, "g"), `pathParams: global.schemas["${refName}"]`);
|
|
1724
153
|
return restoreStrings(preservedCodeWithSchemasInjected, replacements);
|
|
1725
154
|
}
|
|
1726
155
|
|
|
1727
156
|
// src/core/middleware.ts
|
|
1728
|
-
function detectMiddlewareName(
|
|
1729
|
-
const
|
|
1730
|
-
return
|
|
157
|
+
function detectMiddlewareName(code2) {
|
|
158
|
+
const match = code2.match(/middleware:\s*(\w+)/);
|
|
159
|
+
return match ? match[1] : null;
|
|
1731
160
|
}
|
|
1732
161
|
|
|
1733
162
|
// src/core/transpile.ts
|
|
1734
163
|
var import_typescript = require("typescript");
|
|
1735
164
|
|
|
1736
165
|
// src/utils/removeImports.ts
|
|
1737
|
-
function removeImports(
|
|
1738
|
-
return
|
|
166
|
+
function removeImports(code2) {
|
|
167
|
+
return code2.replace(/(^import\s+[^;]+;?$|^import\s+[^;]*\sfrom\s.+;?$)/gm, "").replace(/(^import\s+{[\s\S]+?}\s+from\s+["'][^"']+["'];?)/gm, "").trim();
|
|
1739
168
|
}
|
|
1740
169
|
|
|
1741
170
|
// src/core/transpile.ts
|
|
1742
|
-
function fixExports(
|
|
171
|
+
function fixExports(code2) {
|
|
1743
172
|
const validMethods = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
1744
|
-
const
|
|
173
|
+
const exportFixer1 = validMethods.map((method) => `exports.${method} = void 0;
|
|
1745
174
|
`);
|
|
1746
|
-
const
|
|
1747
|
-
return `${
|
|
1748
|
-
${
|
|
1749
|
-
${
|
|
175
|
+
const exportFixer2 = `module.exports = { ${validMethods.map((m) => `${m}: exports.${m}`).join(", ")} }`;
|
|
176
|
+
return `${exportFixer1}
|
|
177
|
+
${code2}
|
|
178
|
+
${exportFixer2}`;
|
|
1750
179
|
}
|
|
1751
180
|
function injectMiddlewareFixer(middlewareName) {
|
|
1752
181
|
return `const ${middlewareName} = (handler) => handler;`;
|
|
1753
182
|
}
|
|
1754
183
|
function transpile(rawCode, routeDefinerName, middlewareName) {
|
|
1755
|
-
const
|
|
184
|
+
const code2 = fixExports(removeImports(rawCode));
|
|
1756
185
|
const parts = [
|
|
1757
|
-
`
|
|
1758
|
-
"
|
|
186
|
+
`import ${routeDefinerName} from '@omer-x/next-openapi-route-handler';`,
|
|
187
|
+
"import z from 'zod';",
|
|
1759
188
|
middlewareName ? injectMiddlewareFixer(middlewareName) : "",
|
|
1760
|
-
|
|
189
|
+
code2
|
|
1761
190
|
];
|
|
1762
|
-
return (0, import_typescript.transpile)(parts.join("\n")
|
|
1763
|
-
module: 1,
|
|
1764
|
-
// CommonJS
|
|
1765
|
-
target: 99
|
|
1766
|
-
// ESNext
|
|
1767
|
-
});
|
|
191
|
+
return (0, import_typescript.transpile)(parts.join("\n"));
|
|
1768
192
|
}
|
|
1769
193
|
|
|
1770
194
|
// src/core/next.ts
|
|
1771
195
|
async function findAppFolderPath() {
|
|
1772
|
-
const inSrc =
|
|
196
|
+
const inSrc = import_node_path2.default.resolve(process.cwd(), "src", "app");
|
|
1773
197
|
if (await directoryExists(inSrc)) {
|
|
1774
198
|
return inSrc;
|
|
1775
199
|
}
|
|
1776
|
-
const inRoot =
|
|
200
|
+
const inRoot = import_node_path2.default.resolve(process.cwd(), "app");
|
|
1777
201
|
if (await directoryExists(inRoot)) {
|
|
1778
202
|
return inRoot;
|
|
1779
203
|
}
|
|
@@ -1781,30 +205,19 @@ async function findAppFolderPath() {
|
|
|
1781
205
|
}
|
|
1782
206
|
function safeEval(code, routePath) {
|
|
1783
207
|
try {
|
|
1784
|
-
|
|
1785
|
-
const module = { exports: {} };
|
|
1786
|
-
const exports = module.exports;
|
|
1787
|
-
|
|
1788
|
-
const NextResponse = { json: () => ({}) };
|
|
1789
|
-
const next = { server: { NextResponse } };
|
|
1790
|
-
|
|
1791
|
-
${code}
|
|
1792
|
-
|
|
1793
|
-
return module.exports;
|
|
1794
|
-
`);
|
|
1795
|
-
return fn(global, require);
|
|
208
|
+
return eval(code);
|
|
1796
209
|
} catch (error) {
|
|
1797
210
|
console.log(`An error occured while evaluating the route exports from "${routePath}"`);
|
|
1798
211
|
throw error;
|
|
1799
212
|
}
|
|
1800
213
|
}
|
|
1801
|
-
async function getRouteExports(
|
|
1802
|
-
const rawCode = await import_promises3.default.readFile(
|
|
214
|
+
async function getRouteExports(routePath2, routeDefinerName, schemas) {
|
|
215
|
+
const rawCode = await import_promises3.default.readFile(routePath2, "utf-8");
|
|
1803
216
|
const middlewareName = detectMiddlewareName(rawCode);
|
|
1804
|
-
const
|
|
1805
|
-
const fixedCode = Object.keys(schemas).reduce(injectSchemas,
|
|
217
|
+
const code2 = transpile(rawCode, routeDefinerName, middlewareName);
|
|
218
|
+
const fixedCode = Object.keys(schemas).reduce(injectSchemas, code2);
|
|
1806
219
|
global.schemas = schemas;
|
|
1807
|
-
const result = safeEval(fixedCode,
|
|
220
|
+
const result = safeEval(fixedCode, routePath2);
|
|
1808
221
|
delete global.schemas;
|
|
1809
222
|
return result;
|
|
1810
223
|
}
|
|
@@ -1830,10 +243,10 @@ function verifyOptions(include, exclude) {
|
|
|
1830
243
|
}
|
|
1831
244
|
|
|
1832
245
|
// src/core/getRoutePathName.ts
|
|
1833
|
-
var
|
|
246
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
1834
247
|
function getRoutePathName(filePath, rootPath) {
|
|
1835
|
-
const dirName =
|
|
1836
|
-
|
|
248
|
+
const dirName = import_node_path3.default.dirname(filePath);
|
|
249
|
+
import_node_path3.default.relative(rootPath, dirName).replaceAll("[", "{").replaceAll("]", "}").replaceAll("\\", "/").replace(/\([^)]+\)\/|\/\([^)]+\)|\([^)]+\)/g, "");
|
|
1837
250
|
}
|
|
1838
251
|
|
|
1839
252
|
// src/utils/deepEqual.ts
|
|
@@ -2030,7 +443,7 @@ async function generateOpenApiSpec(schemas, {
|
|
|
2030
443
|
const verifiedOptions = verifyOptions(includeOption, excludeOption);
|
|
2031
444
|
const appFolderPath = await findAppFolderPath();
|
|
2032
445
|
if (!appFolderPath) throw new Error("This is not a Next.js application!");
|
|
2033
|
-
const rootPath = additionalRootPath ?
|
|
446
|
+
const rootPath = additionalRootPath ? import_node_path4.default.resolve(appFolderPath, "./" + additionalRootPath) : appFolderPath;
|
|
2034
447
|
const routes = await getDirectoryItems(rootPath, "route.ts");
|
|
2035
448
|
const verifiedRoutes = filterDirectoryItems(rootPath, routes, verifiedOptions.include, verifiedOptions.exclude);
|
|
2036
449
|
const validRoutes = [];
|
|
@@ -2048,7 +461,7 @@ async function generateOpenApiSpec(schemas, {
|
|
|
2048
461
|
));
|
|
2049
462
|
}
|
|
2050
463
|
}
|
|
2051
|
-
const metadata =
|
|
464
|
+
const metadata = (0, import_package_metadata.default)();
|
|
2052
465
|
const pathsAndComponents = {
|
|
2053
466
|
paths: bundlePaths(validRoutes, schemas),
|
|
2054
467
|
components: {
|
|
@@ -2071,4 +484,4 @@ async function generateOpenApiSpec(schemas, {
|
|
|
2071
484
|
}
|
|
2072
485
|
|
|
2073
486
|
// src/index.ts
|
|
2074
|
-
var
|
|
487
|
+
var index_default = generateOpenApiSpec;
|