@outerlayer/cli 0.34.0-next.20261024180339 → 0.34.0-next.20261024231715
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/README.md +5 -5
- package/dist/{agent-setup-FBAT5LGX.js → agent-setup-HEJM3D3V.js} +9 -9
- package/dist/build-info.json +1 -1
- package/dist/{check-HCKDHD2R.js → check-OOUGS65D.js} +20 -20
- package/dist/{chunk-SVLFZLTE.js → chunk-272AKVRP.js} +5 -5
- package/dist/{chunk-B5MSDF5B.js → chunk-2AIOOU3A.js} +4 -4
- package/dist/{chunk-BTHH5H5H.js → chunk-3IH6K7KG.js} +2 -2
- package/dist/{chunk-XFAJQZN2.js → chunk-4P6QGMPN.js} +2 -2
- package/dist/{chunk-43ZOV4OR.js → chunk-4Y54SQXH.js} +10 -10
- package/dist/{chunk-MHGIN2X6.js → chunk-5HZGLLNW.js} +2 -2
- package/dist/{chunk-74Q24R3B.js → chunk-5QBUX5YZ.js} +7 -7
- package/dist/{chunk-6AQLRSYU.js → chunk-62LXQM7U.js} +2 -2
- package/dist/{chunk-SHIGGHZO.js → chunk-65AKMFBH.js} +2 -2
- package/dist/{chunk-OHJDH5GV.js → chunk-6NUPXDAA.js} +1 -1
- package/dist/{chunk-ZADIXMKT.js → chunk-7WM7K2DY.js} +1 -1
- package/dist/{chunk-XLJHFZRL.js → chunk-ACRRO3MB.js} +7 -7
- package/dist/{chunk-OLCIPTST.js → chunk-AP2K4LPI.js} +4 -4
- package/dist/{chunk-YPCDDQFU.js → chunk-DQ6YO7FH.js} +1 -1
- package/dist/{chunk-5HLA7KPK.js → chunk-E4ASIOVL.js} +1 -1
- package/dist/{chunk-NVDPSH72.js → chunk-EE2ZZGQV.js} +1 -1
- package/dist/{chunk-GWF3ZRUX.js → chunk-EN3YWO7Q.js} +1 -1
- package/dist/{chunk-CQRPR4WZ.js → chunk-FGXT5OXS.js} +56 -126
- package/dist/{chunk-3KT2IWV3.js → chunk-FVKH3PMV.js} +49 -9
- package/dist/{chunk-UF2FU3CM.js → chunk-JWNH4ZTF.js} +2 -2
- package/dist/{chunk-2G7PJAJZ.js → chunk-K5Q6T7SE.js} +1 -1
- package/dist/{chunk-TIRHZC2M.js → chunk-NKOM4JKY.js} +2 -2
- package/dist/{chunk-B44BFR2Q.js → chunk-O6DYCIVW.js} +3 -3
- package/dist/{chunk-YREGBU3O.js → chunk-QDVGOMSC.js} +1 -1
- package/dist/{chunk-5XZ6BUPH.js → chunk-QMWUPRYQ.js} +1 -1
- package/dist/{chunk-HMCBX3PL.js → chunk-RCRE42V6.js} +1 -1
- package/dist/{chunk-R2CLQJA2.js → chunk-TDAQHYM4.js} +1 -1
- package/dist/{chunk-SMAZA7DM.js → chunk-XFFUXXI4.js} +2 -2
- package/dist/{chunk-TFKROYY2.js → chunk-YEVPRO7L.js} +3 -3
- package/dist/{chunk-HBVHRC3A.js → chunk-YGSY2NWU.js} +2 -2
- package/dist/{chunk-PBIYM2Z6.js → chunk-YIBFGAYI.js} +2 -2
- package/dist/{chunk-HIGP4WOC.js → chunk-Z4KWHSO4.js} +3 -3
- package/dist/{chunk-ZGB4ZJ5E.js → chunk-ZQSANKS4.js} +1 -1
- package/dist/{chunk-5WCBFLES.js → chunk-ZW6L275N.js} +7 -7
- package/dist/{claude-launcher-YXRS4EZE.js → claude-launcher-MORG66PJ.js} +4 -4
- package/dist/{cli-ADIMCYPF.js → cli-XI7RUSC5.js} +90 -94
- package/dist/{command-YQBQDIAM.js → command-BJSHY6OB.js} +10 -10
- package/dist/{connect-cmd-42JHZKWN.js → connect-cmd-YAUOCX4X.js} +4 -4
- package/dist/{container-start-W4VEGRL5.js → container-start-QADK3YGL.js} +17 -17
- package/dist/{context-cleanup-YGWYIFFV.js → context-cleanup-LUBEZB3L.js} +2 -2
- package/dist/{context-show-cmd-LIWHRWVT.js → context-show-cmd-VHY3OBIA.js} +5 -5
- package/dist/{control-plane-launch-AXBWT5CC.js → control-plane-launch-QSBWTA2V.js} +5 -5
- package/dist/{doctor-AZZJBJYO.js → doctor-UR76MCGI.js} +11 -11
- package/dist/{emit-artifact-cmd-NU5JURAA.js → emit-artifact-cmd-DP2EQ54N.js} +9 -9
- package/dist/{emit-cmd-A4CB7BEC.js → emit-cmd-7NMNKDK7.js} +5 -5
- package/dist/{emit-criteria-cmd-RAU3PDEK.js → emit-criteria-cmd-TTFBN6RK.js} +6 -6
- package/dist/{emit-demo-cmd-524A54D5.js → emit-demo-cmd-Z7YGLEBJ.js} +10 -10
- package/dist/{emit-finding-cmd-LE3HFQWL.js → emit-finding-cmd-IQRD3J2X.js} +6 -6
- package/dist/{emit-result-cmd-XT2VEPAJ.js → emit-result-cmd-GIWB6UHH.js} +8 -8
- package/dist/{emit-step-cmd-LXOKBFQE.js → emit-step-cmd-PU5TTU6C.js} +6 -6
- package/dist/{findings-cmd-O5HUK26I.js → findings-cmd-7J5SHCUO.js} +6 -6
- package/dist/{fleet-readiness-VAKMSSWI.js → fleet-readiness-G63D76EX.js} +6 -6
- package/dist/{governing-source-FNSH4V4A.js → governing-source-DLESDP6T.js} +9 -9
- package/dist/{hook-fast-WENTLDMA.js → hook-fast-VQXRDS6E.js} +1 -1
- package/dist/index.js +4 -4
- package/dist/{init-RUIWHKLE.js → init-67R7LO4C.js} +10 -10
- package/dist/{init-LQDKX2XL.js → init-KSXU4PA7.js} +10 -10
- package/dist/{init-cmd-2OTTULTI.js → init-cmd-MNOVMADM.js} +14 -14
- package/dist/{init-update-TN2W4EN6.js → init-update-6KEXRCJH.js} +13 -13
- package/dist/{layout-NAPG4SX2.js → layout-7B3O3FT3.js} +3 -3
- package/dist/{loop-X3ANDLQU.js → loop-KUEOPBKX.js} +20 -20
- package/dist/{machine-IEYKRHRK.js → machine-EQEAPT76.js} +10 -10
- package/dist/{machine-skills-2TT3RXMJ.js → machine-skills-3FEGR376.js} +3 -3
- package/dist/{runner-key-QKZZTKLY.js → runner-key-ML7R33HF.js} +10 -10
- package/dist/{session-sender-IH44FURK.js → session-sender-A43GZQ7T.js} +9 -9
- package/dist/{spec-cmd-2LRTOTAO.js → spec-cmd-VVUJZSG2.js} +7 -7
- package/dist/{starter-pack-5D4BANFU.js → starter-pack-LEL3Q2DB.js} +4 -4
- package/dist/{status-6ISCZDBX.js → status-4G6K7I2C.js} +15 -15
- package/dist/{sync-cmd-MIID2ANV.js → sync-cmd-ZEC65ABJ.js} +8 -8
- package/dist/{update-steps-4M2GIB4A.js → update-steps-XLO7734I.js} +16 -16
- package/dist/{watch-K5UUKCPB.js → watch-QB4AMWR3.js} +8 -8
- package/dist/{work-claim-cmd-2LD2JQKI.js → work-claim-cmd-6W3GBHRS.js} +8 -8
- package/dist/{work-cmd-NR53YCXJ.js → work-cmd-LTZXOPPN.js} +6 -6
- package/dist/{work-comment-cmd-PC4HNM45.js → work-comment-cmd-LDZBUO6M.js} +7 -7
- package/dist/{work-demo-cmd-S5EJXBVH.js → work-demo-cmd-77LISWQ3.js} +6 -6
- package/dist/{work-logs-cmd-5F6MDBLQ.js → work-logs-cmd-FK7HE7PC.js} +6 -6
- package/dist/{work-open-pr-cmd-SWVFDSMY.js → work-open-pr-cmd-WVONEHZL.js} +7 -7
- package/dist/{work-pr-cmd-DXW4RXG4.js → work-pr-cmd-6IPXWJEH.js} +6 -6
- package/dist/{work-proofs-cmd-UVTSPFLL.js → work-proofs-cmd-TGIAP5IO.js} +7 -7
- package/dist/work-proofs-record-XPAU7N57.js +2382 -0
- package/dist/{work-stop-cmd-HL6FZL5X.js → work-stop-cmd-UJ45EV3A.js} +6 -6
- package/package.json +2 -1
- package/skill-pack/maintained/outerlayer-amend/SKILL.md +1 -2
- package/skill-pack/maintained/outerlayer-build/SKILL.md +4 -3
- package/skill-pack/maintained/outerlayer-build/references/agent-briefs.md +33 -28
- package/skill-pack/maintained/outerlayer-build/references/evidence.md +22 -20
- package/skill-pack/maintained/outerlayer-evidence/SKILL.md +1 -1
- package/dist/chunk-RT6VNM3S.js +0 -148
- package/dist/work-proofs-init-GNGI7PZU.js +0 -35
- package/dist/work-proofs-record-HTWSMEDG.js +0 -402
|
@@ -0,0 +1,2382 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { runWorkComment } from './chunk-EN3YWO7Q.js';
|
|
4
|
+
import { resolveProofsItem, ownPullRequest, proofsCommentId, otherPullRequestHeads, classifyProofsAt, kindProblem, proofsCommentBody, runWorkProofs } from './chunk-FVKH3PMV.js';
|
|
5
|
+
import { runEmitDemo } from './chunk-3IH6K7KG.js';
|
|
6
|
+
import { readNewestDemo } from './chunk-ER6KQCVJ.js';
|
|
7
|
+
import { runEmitArtifact } from './chunk-5HZGLLNW.js';
|
|
8
|
+
import { runSync } from './chunk-YGSY2NWU.js';
|
|
9
|
+
import './chunk-QMWUPRYQ.js';
|
|
10
|
+
import './chunk-ESVW4MJY.js';
|
|
11
|
+
import './chunk-TBT347UY.js';
|
|
12
|
+
import './chunk-2PGI6RDE.js';
|
|
13
|
+
import './chunk-ES4ULBAL.js';
|
|
14
|
+
import { WorkCommandError, resolveCredentials, getJson } from './chunk-Z4KWHSO4.js';
|
|
15
|
+
import './chunk-IP7BIBXJ.js';
|
|
16
|
+
import './chunk-6NUPXDAA.js';
|
|
17
|
+
import './chunk-EE2ZZGQV.js';
|
|
18
|
+
import './chunk-MECW77XP.js';
|
|
19
|
+
import { resolveRepoIdentity } from './chunk-6ZFY2L2T.js';
|
|
20
|
+
import './chunk-NKOM4JKY.js';
|
|
21
|
+
import './chunk-Y5YCX6AL.js';
|
|
22
|
+
import './chunk-G2JWZDFA.js';
|
|
23
|
+
import './chunk-ANPNT6PM.js';
|
|
24
|
+
import { defaultFetch } from './chunk-6RKD7YZ6.js';
|
|
25
|
+
import './chunk-PJDQPF5N.js';
|
|
26
|
+
import './chunk-SOI6K5DY.js';
|
|
27
|
+
import './chunk-PA6CK6WQ.js';
|
|
28
|
+
import './chunk-BALIE3BA.js';
|
|
29
|
+
import './chunk-65AKMFBH.js';
|
|
30
|
+
import './chunk-ZJSNLVCE.js';
|
|
31
|
+
import './chunk-2O5KA67H.js';
|
|
32
|
+
import './chunk-BKO6JEZI.js';
|
|
33
|
+
import './chunk-HCVLP7XA.js';
|
|
34
|
+
import './chunk-BJ3KTMDH.js';
|
|
35
|
+
import './chunk-ZQSANKS4.js';
|
|
36
|
+
import './chunk-5BHIBJDA.js';
|
|
37
|
+
import './chunk-CDDED64E.js';
|
|
38
|
+
import './chunk-RA3O54FC.js';
|
|
39
|
+
import './chunk-T2Q7ISPE.js';
|
|
40
|
+
import './chunk-WZBHBH3J.js';
|
|
41
|
+
import './chunk-CRB3POP4.js';
|
|
42
|
+
import './chunk-URIZRCRY.js';
|
|
43
|
+
import './chunk-TUSYOL2O.js';
|
|
44
|
+
import { parseProofsConfig } from './chunk-FGXT5OXS.js';
|
|
45
|
+
import { ARTIFACT_MAX_CAPTION_LENGTH } from './chunk-EOTMDIYC.js';
|
|
46
|
+
import './chunk-VNVZDWO3.js';
|
|
47
|
+
import './chunk-HACGUL52.js';
|
|
48
|
+
import './chunk-MESOOLF4.js';
|
|
49
|
+
import './chunk-Z5GEFMRW.js';
|
|
50
|
+
import { spawnSync, spawn } from 'child_process';
|
|
51
|
+
import { mkdtempSync, rmSync, openSync, closeSync, readdirSync, readFileSync } from 'fs';
|
|
52
|
+
import { tmpdir } from 'os';
|
|
53
|
+
import { join } from 'path';
|
|
54
|
+
|
|
55
|
+
createRequire(import.meta.url);
|
|
56
|
+
var runShell = (command, params) => {
|
|
57
|
+
const logPath = join(params.logDir, `${params.groups.length}-${Date.now()}.log`);
|
|
58
|
+
const fd = openSync(logPath, "w");
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
const child = spawn("sh", ["-c", command], { cwd: params.cwd, env: params.env, detached: true, stdio: ["ignore", fd, fd] });
|
|
61
|
+
closeSync(fd);
|
|
62
|
+
if (child.pid !== void 0) params.groups.push(child.pid);
|
|
63
|
+
let timedOut = false;
|
|
64
|
+
const timer = setTimeout(() => {
|
|
65
|
+
timedOut = true;
|
|
66
|
+
try {
|
|
67
|
+
process.kill(-child.pid, "SIGKILL");
|
|
68
|
+
} catch {
|
|
69
|
+
}
|
|
70
|
+
}, params.timeoutMs);
|
|
71
|
+
const finish = (status) => {
|
|
72
|
+
clearTimeout(timer);
|
|
73
|
+
let text = "";
|
|
74
|
+
try {
|
|
75
|
+
text = readFileSync(logPath, "utf8");
|
|
76
|
+
} catch {
|
|
77
|
+
}
|
|
78
|
+
resolve({ status, timedOut, tail: text.trimEnd().split("\n").slice(-8).join("\n") });
|
|
79
|
+
};
|
|
80
|
+
child.on("error", () => finish(null));
|
|
81
|
+
child.on("exit", (status) => finish(status));
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// ../../node_modules/balanced-match/dist/esm/index.js
|
|
86
|
+
var balanced = (a, b, str) => {
|
|
87
|
+
const ma = a instanceof RegExp ? maybeMatch(a, str) : a;
|
|
88
|
+
const mb = b instanceof RegExp ? maybeMatch(b, str) : b;
|
|
89
|
+
const r = ma !== null && mb != null && range(ma, mb, str);
|
|
90
|
+
return r && {
|
|
91
|
+
start: r[0],
|
|
92
|
+
end: r[1],
|
|
93
|
+
pre: str.slice(0, r[0]),
|
|
94
|
+
body: str.slice(r[0] + ma.length, r[1]),
|
|
95
|
+
post: str.slice(r[1] + mb.length)
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
var maybeMatch = (reg, str) => {
|
|
99
|
+
const m = str.match(reg);
|
|
100
|
+
return m ? m[0] : null;
|
|
101
|
+
};
|
|
102
|
+
var range = (a, b, str) => {
|
|
103
|
+
let begs, beg, left, right = void 0, result;
|
|
104
|
+
let ai = str.indexOf(a);
|
|
105
|
+
let bi = str.indexOf(b, ai + 1);
|
|
106
|
+
let i = ai;
|
|
107
|
+
if (ai >= 0 && bi > 0) {
|
|
108
|
+
if (a === b) {
|
|
109
|
+
return [ai, bi];
|
|
110
|
+
}
|
|
111
|
+
begs = [];
|
|
112
|
+
left = str.length;
|
|
113
|
+
while (i >= 0 && !result) {
|
|
114
|
+
if (i === ai) {
|
|
115
|
+
begs.push(i);
|
|
116
|
+
ai = str.indexOf(a, i + 1);
|
|
117
|
+
} else if (begs.length === 1) {
|
|
118
|
+
const r = begs.pop();
|
|
119
|
+
if (r !== void 0)
|
|
120
|
+
result = [r, bi];
|
|
121
|
+
} else {
|
|
122
|
+
beg = begs.pop();
|
|
123
|
+
if (beg !== void 0 && beg < left) {
|
|
124
|
+
left = beg;
|
|
125
|
+
right = bi;
|
|
126
|
+
}
|
|
127
|
+
bi = str.indexOf(b, i + 1);
|
|
128
|
+
}
|
|
129
|
+
i = ai < bi && ai >= 0 ? ai : bi;
|
|
130
|
+
}
|
|
131
|
+
if (begs.length && right !== void 0) {
|
|
132
|
+
result = [left, right];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// ../../node_modules/brace-expansion/dist/esm/index.js
|
|
139
|
+
var escSlash = "\0SLASH" + Math.random() + "\0";
|
|
140
|
+
var escOpen = "\0OPEN" + Math.random() + "\0";
|
|
141
|
+
var escClose = "\0CLOSE" + Math.random() + "\0";
|
|
142
|
+
var escComma = "\0COMMA" + Math.random() + "\0";
|
|
143
|
+
var escPeriod = "\0PERIOD" + Math.random() + "\0";
|
|
144
|
+
var escSlashPattern = new RegExp(escSlash, "g");
|
|
145
|
+
var escOpenPattern = new RegExp(escOpen, "g");
|
|
146
|
+
var escClosePattern = new RegExp(escClose, "g");
|
|
147
|
+
var escCommaPattern = new RegExp(escComma, "g");
|
|
148
|
+
var escPeriodPattern = new RegExp(escPeriod, "g");
|
|
149
|
+
var slashPattern = /\\\\/g;
|
|
150
|
+
var openPattern = /\\{/g;
|
|
151
|
+
var closePattern = /\\}/g;
|
|
152
|
+
var commaPattern = /\\,/g;
|
|
153
|
+
var periodPattern = /\\\./g;
|
|
154
|
+
var EXPANSION_MAX = 1e5;
|
|
155
|
+
var EXPANSION_MAX_LENGTH = 4e6;
|
|
156
|
+
var EXPANSION_MAX_DEPTH = 1e3;
|
|
157
|
+
var EXPANSION_MAX_REWRITES = 1e3;
|
|
158
|
+
function numeric(str) {
|
|
159
|
+
return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
|
|
160
|
+
}
|
|
161
|
+
function escapeBraces(str) {
|
|
162
|
+
return str.replace(slashPattern, escSlash).replace(openPattern, escOpen).replace(closePattern, escClose).replace(commaPattern, escComma).replace(periodPattern, escPeriod);
|
|
163
|
+
}
|
|
164
|
+
function unescapeBraces(str) {
|
|
165
|
+
return str.replace(escSlashPattern, "\\").replace(escOpenPattern, "{").replace(escClosePattern, "}").replace(escCommaPattern, ",").replace(escPeriodPattern, ".");
|
|
166
|
+
}
|
|
167
|
+
function pushAll(target, items) {
|
|
168
|
+
for (let i = 0; i < items.length; i++) {
|
|
169
|
+
target.push(items[i]);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function parseCommaParts(str) {
|
|
173
|
+
const parts = [];
|
|
174
|
+
let carry = "";
|
|
175
|
+
for (; ; ) {
|
|
176
|
+
const m = balanced("{", "}", str);
|
|
177
|
+
if (!m) {
|
|
178
|
+
const tail = str.split(",");
|
|
179
|
+
tail[0] = carry + tail[0];
|
|
180
|
+
pushAll(parts, tail);
|
|
181
|
+
return parts;
|
|
182
|
+
}
|
|
183
|
+
const { pre, body, post } = m;
|
|
184
|
+
const p = pre.split(",");
|
|
185
|
+
p[0] = carry + p[0];
|
|
186
|
+
p[p.length - 1] += "{" + body + "}";
|
|
187
|
+
if (!post.length) {
|
|
188
|
+
pushAll(parts, p);
|
|
189
|
+
return parts;
|
|
190
|
+
}
|
|
191
|
+
carry = p.pop();
|
|
192
|
+
pushAll(parts, p);
|
|
193
|
+
str = post;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function expand(str, options = {}) {
|
|
197
|
+
if (!str) {
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH, maxDepth = EXPANSION_MAX_DEPTH, maxRewrites = EXPANSION_MAX_REWRITES } = options;
|
|
201
|
+
if (str.slice(0, 2) === "{}") {
|
|
202
|
+
str = "\\{\\}" + str.slice(2);
|
|
203
|
+
}
|
|
204
|
+
return expand_(escapeBraces(str), max, maxLength, maxDepth, 0, maxRewrites, true).map(unescapeBraces);
|
|
205
|
+
}
|
|
206
|
+
function embrace(str) {
|
|
207
|
+
return "{" + str + "}";
|
|
208
|
+
}
|
|
209
|
+
function isPadded(el) {
|
|
210
|
+
return /^-?0\d/.test(el);
|
|
211
|
+
}
|
|
212
|
+
function lte(i, y) {
|
|
213
|
+
return i <= y;
|
|
214
|
+
}
|
|
215
|
+
function gte(i, y) {
|
|
216
|
+
return i >= y;
|
|
217
|
+
}
|
|
218
|
+
function combine(acc, pre, values, max, maxLength, dropEmpties) {
|
|
219
|
+
const out = [];
|
|
220
|
+
let length = 0;
|
|
221
|
+
for (let a = 0; a < acc.length; a++) {
|
|
222
|
+
for (let v = 0; v < values.length; v++) {
|
|
223
|
+
if (out.length >= max)
|
|
224
|
+
return out;
|
|
225
|
+
const expansion = acc[a] + pre + values[v];
|
|
226
|
+
if (dropEmpties && !expansion)
|
|
227
|
+
continue;
|
|
228
|
+
if (length + expansion.length > maxLength)
|
|
229
|
+
return out;
|
|
230
|
+
out.push(expansion);
|
|
231
|
+
length += expansion.length;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return out;
|
|
235
|
+
}
|
|
236
|
+
function expandSequence(body, isAlphaSequence, max, maxLength) {
|
|
237
|
+
const n = body.split(/\.\./);
|
|
238
|
+
const N = [];
|
|
239
|
+
if (n[0] === void 0 || n[1] === void 0) {
|
|
240
|
+
return N;
|
|
241
|
+
}
|
|
242
|
+
const x = numeric(n[0]);
|
|
243
|
+
const y = numeric(n[1]);
|
|
244
|
+
const width = Math.max(n[0].length, n[1].length);
|
|
245
|
+
let incr = n.length === 3 && n[2] !== void 0 ? Math.max(Math.abs(numeric(n[2])), 1) : 1;
|
|
246
|
+
let test = lte;
|
|
247
|
+
const reverse = y < x;
|
|
248
|
+
if (reverse) {
|
|
249
|
+
incr *= -1;
|
|
250
|
+
test = gte;
|
|
251
|
+
}
|
|
252
|
+
const pad = n.some(isPadded);
|
|
253
|
+
let length = 0;
|
|
254
|
+
for (let i = x; test(i, y) && N.length < max; i += incr) {
|
|
255
|
+
let c;
|
|
256
|
+
if (isAlphaSequence) {
|
|
257
|
+
c = String.fromCharCode(i);
|
|
258
|
+
if (c === "\\") {
|
|
259
|
+
c = "";
|
|
260
|
+
}
|
|
261
|
+
} else {
|
|
262
|
+
c = String(i);
|
|
263
|
+
if (pad) {
|
|
264
|
+
const need = width - c.length;
|
|
265
|
+
if (need > 0) {
|
|
266
|
+
const z = new Array(need + 1).join("0");
|
|
267
|
+
if (i < 0) {
|
|
268
|
+
c = "-" + z + c.slice(1);
|
|
269
|
+
} else {
|
|
270
|
+
c = z + c;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (length + c.length > maxLength)
|
|
276
|
+
break;
|
|
277
|
+
N.push(c);
|
|
278
|
+
length += c.length;
|
|
279
|
+
}
|
|
280
|
+
return N;
|
|
281
|
+
}
|
|
282
|
+
function expand_(str, max, maxLength, maxDepth, depth, maxRewrites, isTop) {
|
|
283
|
+
if (depth > maxDepth) {
|
|
284
|
+
return [str];
|
|
285
|
+
}
|
|
286
|
+
let acc = [""];
|
|
287
|
+
let rewrites = 0;
|
|
288
|
+
let dropEmpties = false;
|
|
289
|
+
let firstGroup = true;
|
|
290
|
+
for (; ; ) {
|
|
291
|
+
const m = balanced("{", "}", str);
|
|
292
|
+
if (!m) {
|
|
293
|
+
return combine(acc, str, [""], max, maxLength, dropEmpties);
|
|
294
|
+
}
|
|
295
|
+
const pre = m.pre;
|
|
296
|
+
if (/\$$/.test(pre)) {
|
|
297
|
+
acc = combine(acc, pre + "{" + m.body + "}", [""], max, maxLength, dropEmpties && !m.post.length);
|
|
298
|
+
firstGroup = false;
|
|
299
|
+
if (!m.post.length)
|
|
300
|
+
break;
|
|
301
|
+
str = m.post;
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
305
|
+
const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
306
|
+
const isSequence = isNumericSequence || isAlphaSequence;
|
|
307
|
+
const isOptions = m.body.indexOf(",") >= 0;
|
|
308
|
+
if (!isSequence && !isOptions) {
|
|
309
|
+
if (rewrites < maxRewrites && m.post.match(/,(?!,).*\}/)) {
|
|
310
|
+
rewrites++;
|
|
311
|
+
str = m.pre + "{" + m.body + escClose + m.post;
|
|
312
|
+
isTop = true;
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
return combine(acc, pre + "{" + m.body + "}" + m.post, [""], max, maxLength, dropEmpties);
|
|
316
|
+
}
|
|
317
|
+
if (firstGroup) {
|
|
318
|
+
dropEmpties = isTop && !isSequence;
|
|
319
|
+
firstGroup = false;
|
|
320
|
+
}
|
|
321
|
+
let values;
|
|
322
|
+
if (isSequence) {
|
|
323
|
+
values = expandSequence(m.body, isAlphaSequence, max, maxLength);
|
|
324
|
+
} else {
|
|
325
|
+
let n = parseCommaParts(m.body);
|
|
326
|
+
if (n.length === 1 && n[0] !== void 0) {
|
|
327
|
+
n = expand_(n[0], max, maxLength, maxDepth, depth + 1, maxRewrites, false).map(embrace);
|
|
328
|
+
if (n.length === 1) {
|
|
329
|
+
acc = combine(acc, pre + n[0], [""], max, maxLength, dropEmpties && !m.post.length);
|
|
330
|
+
if (!m.post.length)
|
|
331
|
+
break;
|
|
332
|
+
str = m.post;
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
let dropsEmpties = dropEmpties && !m.post.length && !pre;
|
|
337
|
+
for (let d = 0; dropsEmpties && d < acc.length; d++) {
|
|
338
|
+
if (acc[d]) {
|
|
339
|
+
dropsEmpties = false;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
values = [];
|
|
343
|
+
let valuesLength = 0;
|
|
344
|
+
outer: for (let j = 0; j < n.length; j++) {
|
|
345
|
+
const expanded = expand_(n[j], max, maxLength, maxDepth, depth + 1, maxRewrites, false);
|
|
346
|
+
for (let k = 0; k < expanded.length; k++) {
|
|
347
|
+
const v = expanded[k];
|
|
348
|
+
if (dropsEmpties && !v)
|
|
349
|
+
continue;
|
|
350
|
+
if (values.length >= max || valuesLength + v.length > maxLength) {
|
|
351
|
+
break outer;
|
|
352
|
+
}
|
|
353
|
+
values.push(v);
|
|
354
|
+
valuesLength += v.length;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length);
|
|
359
|
+
if (!m.post.length)
|
|
360
|
+
break;
|
|
361
|
+
str = m.post;
|
|
362
|
+
}
|
|
363
|
+
return acc;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// ../../node_modules/minimatch/dist/esm/assert-valid-pattern.js
|
|
367
|
+
var MAX_PATTERN_LENGTH = 1024 * 64;
|
|
368
|
+
var assertValidPattern = (pattern) => {
|
|
369
|
+
if (typeof pattern !== "string") {
|
|
370
|
+
throw new TypeError("invalid pattern");
|
|
371
|
+
}
|
|
372
|
+
if (pattern.length > MAX_PATTERN_LENGTH) {
|
|
373
|
+
throw new TypeError("pattern is too long");
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
// ../../node_modules/minimatch/dist/esm/brace-expressions.js
|
|
378
|
+
var posixClasses = {
|
|
379
|
+
"[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
|
|
380
|
+
"[:alpha:]": ["\\p{L}\\p{Nl}", true],
|
|
381
|
+
"[:ascii:]": ["\\x00-\\x7f", false],
|
|
382
|
+
"[:blank:]": ["\\p{Zs}\\t", true],
|
|
383
|
+
"[:cntrl:]": ["\\p{Cc}", true],
|
|
384
|
+
"[:digit:]": ["\\p{Nd}", true],
|
|
385
|
+
"[:graph:]": ["\\p{Z}\\p{C}", true, true],
|
|
386
|
+
"[:lower:]": ["\\p{Ll}", true],
|
|
387
|
+
"[:print:]": ["\\p{C}", true],
|
|
388
|
+
"[:punct:]": ["\\p{P}", true],
|
|
389
|
+
"[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true],
|
|
390
|
+
"[:upper:]": ["\\p{Lu}", true],
|
|
391
|
+
"[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true],
|
|
392
|
+
"[:xdigit:]": ["A-Fa-f0-9", false]
|
|
393
|
+
};
|
|
394
|
+
var braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&");
|
|
395
|
+
var regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
396
|
+
var rangesToString = (ranges) => ranges.join("");
|
|
397
|
+
var parseClass = (glob, position) => {
|
|
398
|
+
const pos = position;
|
|
399
|
+
if (glob.charAt(pos) !== "[") {
|
|
400
|
+
throw new Error("not in a brace expression");
|
|
401
|
+
}
|
|
402
|
+
const ranges = [];
|
|
403
|
+
const negs = [];
|
|
404
|
+
let i = pos + 1;
|
|
405
|
+
let sawStart = false;
|
|
406
|
+
let uflag = false;
|
|
407
|
+
let escaping = false;
|
|
408
|
+
let negate = false;
|
|
409
|
+
let endPos = pos;
|
|
410
|
+
let rangeStart = "";
|
|
411
|
+
WHILE: while (i < glob.length) {
|
|
412
|
+
const c = glob.charAt(i);
|
|
413
|
+
if ((c === "!" || c === "^") && i === pos + 1) {
|
|
414
|
+
negate = true;
|
|
415
|
+
i++;
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (c === "]" && sawStart && !escaping) {
|
|
419
|
+
endPos = i + 1;
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
sawStart = true;
|
|
423
|
+
if (c === "\\") {
|
|
424
|
+
if (!escaping) {
|
|
425
|
+
escaping = true;
|
|
426
|
+
i++;
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (c === "[" && !escaping) {
|
|
431
|
+
for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
|
|
432
|
+
if (glob.startsWith(cls, i)) {
|
|
433
|
+
if (rangeStart) {
|
|
434
|
+
return ["$.", false, glob.length - pos, true];
|
|
435
|
+
}
|
|
436
|
+
i += cls.length;
|
|
437
|
+
if (neg)
|
|
438
|
+
negs.push(unip);
|
|
439
|
+
else
|
|
440
|
+
ranges.push(unip);
|
|
441
|
+
uflag = uflag || u;
|
|
442
|
+
continue WHILE;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
escaping = false;
|
|
447
|
+
if (rangeStart) {
|
|
448
|
+
if (c > rangeStart) {
|
|
449
|
+
ranges.push(braceEscape(rangeStart) + "-" + braceEscape(c));
|
|
450
|
+
} else if (c === rangeStart) {
|
|
451
|
+
ranges.push(braceEscape(c));
|
|
452
|
+
}
|
|
453
|
+
rangeStart = "";
|
|
454
|
+
i++;
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if (glob.startsWith("-]", i + 1)) {
|
|
458
|
+
ranges.push(braceEscape(c + "-"));
|
|
459
|
+
i += 2;
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
if (glob.startsWith("-", i + 1)) {
|
|
463
|
+
rangeStart = c;
|
|
464
|
+
i += 2;
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
ranges.push(braceEscape(c));
|
|
468
|
+
i++;
|
|
469
|
+
}
|
|
470
|
+
if (endPos < i) {
|
|
471
|
+
return ["", false, 0, false];
|
|
472
|
+
}
|
|
473
|
+
if (!ranges.length && !negs.length) {
|
|
474
|
+
return ["$.", false, glob.length - pos, true];
|
|
475
|
+
}
|
|
476
|
+
if (negs.length === 0 && ranges.length === 1 && /^\\?.$/.test(ranges[0]) && !negate) {
|
|
477
|
+
const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
|
|
478
|
+
return [regexpEscape(r), false, endPos - pos, false];
|
|
479
|
+
}
|
|
480
|
+
const sranges = "[" + (negate ? "^" : "") + rangesToString(ranges) + "]";
|
|
481
|
+
const snegs = "[" + (negate ? "" : "^") + rangesToString(negs) + "]";
|
|
482
|
+
const comb = ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs;
|
|
483
|
+
return [comb, uflag, endPos - pos, true];
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// ../../node_modules/minimatch/dist/esm/unescape.js
|
|
487
|
+
var unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true } = {}) => {
|
|
488
|
+
if (magicalBraces) {
|
|
489
|
+
return windowsPathsNoEscape ? s.replace(/\[([^/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\])\]/g, "$1$2").replace(/\\([^/])/g, "$1");
|
|
490
|
+
}
|
|
491
|
+
return windowsPathsNoEscape ? s.replace(/\[([^/\\{}])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\{}])\]/g, "$1$2").replace(/\\([^/{}])/g, "$1");
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
// ../../node_modules/minimatch/dist/esm/ast.js
|
|
495
|
+
var _a;
|
|
496
|
+
var types = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]);
|
|
497
|
+
var isExtglobType = (c) => types.has(c);
|
|
498
|
+
var isExtglobAST = (c) => isExtglobType(c.type);
|
|
499
|
+
var adoptionMap = /* @__PURE__ */ new Map([
|
|
500
|
+
["!", ["@"]],
|
|
501
|
+
["?", ["?", "@"]],
|
|
502
|
+
["@", ["@"]],
|
|
503
|
+
["*", ["*", "+", "?", "@"]],
|
|
504
|
+
["+", ["+", "@"]]
|
|
505
|
+
]);
|
|
506
|
+
var adoptionWithSpaceMap = /* @__PURE__ */ new Map([
|
|
507
|
+
["!", ["?"]],
|
|
508
|
+
["@", ["?"]],
|
|
509
|
+
["+", ["?", "*"]]
|
|
510
|
+
]);
|
|
511
|
+
var adoptionAnyMap = /* @__PURE__ */ new Map([
|
|
512
|
+
["!", ["?", "@"]],
|
|
513
|
+
["?", ["?", "@"]],
|
|
514
|
+
["@", ["?", "@"]],
|
|
515
|
+
["*", ["*", "+", "?", "@"]],
|
|
516
|
+
["+", ["+", "@", "?", "*"]]
|
|
517
|
+
]);
|
|
518
|
+
var usurpMap = /* @__PURE__ */ new Map([
|
|
519
|
+
["!", /* @__PURE__ */ new Map([["!", "@"]])],
|
|
520
|
+
[
|
|
521
|
+
"?",
|
|
522
|
+
/* @__PURE__ */ new Map([
|
|
523
|
+
["*", "*"],
|
|
524
|
+
["+", "*"]
|
|
525
|
+
])
|
|
526
|
+
],
|
|
527
|
+
[
|
|
528
|
+
"@",
|
|
529
|
+
/* @__PURE__ */ new Map([
|
|
530
|
+
["!", "!"],
|
|
531
|
+
["?", "?"],
|
|
532
|
+
["@", "@"],
|
|
533
|
+
["*", "*"],
|
|
534
|
+
["+", "+"]
|
|
535
|
+
])
|
|
536
|
+
],
|
|
537
|
+
[
|
|
538
|
+
"+",
|
|
539
|
+
/* @__PURE__ */ new Map([
|
|
540
|
+
["?", "*"],
|
|
541
|
+
["*", "*"]
|
|
542
|
+
])
|
|
543
|
+
]
|
|
544
|
+
]);
|
|
545
|
+
var startNoTraversal = "(?!(?:^|/)\\.\\.?(?:$|/))";
|
|
546
|
+
var startNoDot = "(?!\\.)";
|
|
547
|
+
var addPatternStart = /* @__PURE__ */ new Set(["[", "."]);
|
|
548
|
+
var justDots = /* @__PURE__ */ new Set(["..", "."]);
|
|
549
|
+
var reSpecials = new Set("().*{}+?[]^$\\!");
|
|
550
|
+
var regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
551
|
+
var qmark = "[^/]";
|
|
552
|
+
var star = qmark + "*?";
|
|
553
|
+
var starNoEmpty = qmark + "+?";
|
|
554
|
+
var ID = 0;
|
|
555
|
+
var AST = class {
|
|
556
|
+
type;
|
|
557
|
+
#root;
|
|
558
|
+
#hasMagic;
|
|
559
|
+
#uflag = false;
|
|
560
|
+
#parts = [];
|
|
561
|
+
#parent;
|
|
562
|
+
#parentIndex;
|
|
563
|
+
#negs;
|
|
564
|
+
#filledNegs = false;
|
|
565
|
+
#options;
|
|
566
|
+
#toString;
|
|
567
|
+
// set to true if it's an extglob with no children
|
|
568
|
+
// (which really means one child of '')
|
|
569
|
+
#emptyExt = false;
|
|
570
|
+
id = ++ID;
|
|
571
|
+
get depth() {
|
|
572
|
+
return (this.#parent?.depth ?? -1) + 1;
|
|
573
|
+
}
|
|
574
|
+
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
575
|
+
return {
|
|
576
|
+
"@@type": "AST",
|
|
577
|
+
id: this.id,
|
|
578
|
+
type: this.type,
|
|
579
|
+
root: this.#root.id,
|
|
580
|
+
parent: this.#parent?.id,
|
|
581
|
+
depth: this.depth,
|
|
582
|
+
partsLength: this.#parts.length,
|
|
583
|
+
parts: this.#parts
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
constructor(type, parent, options = {}) {
|
|
587
|
+
this.type = type;
|
|
588
|
+
if (type)
|
|
589
|
+
this.#hasMagic = true;
|
|
590
|
+
this.#parent = parent;
|
|
591
|
+
this.#root = this.#parent ? this.#parent.#root : this;
|
|
592
|
+
this.#options = this.#root === this ? options : this.#root.#options;
|
|
593
|
+
this.#negs = this.#root === this ? [] : this.#root.#negs;
|
|
594
|
+
if (type === "!" && !this.#root.#filledNegs)
|
|
595
|
+
this.#negs.push(this);
|
|
596
|
+
this.#parentIndex = this.#parent ? this.#parent.#parts.length : 0;
|
|
597
|
+
}
|
|
598
|
+
get hasMagic() {
|
|
599
|
+
if (this.#hasMagic !== void 0)
|
|
600
|
+
return this.#hasMagic;
|
|
601
|
+
for (const p of this.#parts) {
|
|
602
|
+
if (typeof p === "string")
|
|
603
|
+
continue;
|
|
604
|
+
if (p.type || p.hasMagic)
|
|
605
|
+
return this.#hasMagic = true;
|
|
606
|
+
}
|
|
607
|
+
return this.#hasMagic;
|
|
608
|
+
}
|
|
609
|
+
// reconstructs the pattern
|
|
610
|
+
toString() {
|
|
611
|
+
return this.#toString !== void 0 ? this.#toString : !this.type ? this.#toString = this.#parts.map((p) => String(p)).join("") : this.#toString = this.type + "(" + this.#parts.map((p) => String(p)).join("|") + ")";
|
|
612
|
+
}
|
|
613
|
+
#fillNegs() {
|
|
614
|
+
if (this !== this.#root)
|
|
615
|
+
throw new Error("should only call on root");
|
|
616
|
+
if (this.#filledNegs)
|
|
617
|
+
return this;
|
|
618
|
+
this.toString();
|
|
619
|
+
this.#filledNegs = true;
|
|
620
|
+
let n;
|
|
621
|
+
while (n = this.#negs.pop()) {
|
|
622
|
+
if (n.type !== "!")
|
|
623
|
+
continue;
|
|
624
|
+
let p = n;
|
|
625
|
+
let pp = p.#parent;
|
|
626
|
+
while (pp) {
|
|
627
|
+
for (let i = p.#parentIndex + 1; !pp.type && i < pp.#parts.length; i++) {
|
|
628
|
+
for (const part of n.#parts) {
|
|
629
|
+
if (typeof part === "string") {
|
|
630
|
+
throw new Error("string part in extglob AST??");
|
|
631
|
+
}
|
|
632
|
+
part.copyIn(pp.#parts[i]);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
p = pp;
|
|
636
|
+
pp = p.#parent;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
return this;
|
|
640
|
+
}
|
|
641
|
+
push(...parts) {
|
|
642
|
+
for (const p of parts) {
|
|
643
|
+
if (p === "")
|
|
644
|
+
continue;
|
|
645
|
+
if (typeof p !== "string" && !(p instanceof _a && p.#parent === this)) {
|
|
646
|
+
throw new Error("invalid part: " + p);
|
|
647
|
+
}
|
|
648
|
+
this.#parts.push(p);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
toJSON() {
|
|
652
|
+
const ret = this.type === null ? this.#parts.slice().map((p) => typeof p === "string" ? p : p.toJSON()) : [this.type, ...this.#parts.map((p) => p.toJSON())];
|
|
653
|
+
if (this.isStart() && !this.type)
|
|
654
|
+
ret.unshift([]);
|
|
655
|
+
if (this.isEnd() && (this === this.#root || this.#root.#filledNegs && this.#parent?.type === "!")) {
|
|
656
|
+
ret.push({});
|
|
657
|
+
}
|
|
658
|
+
return ret;
|
|
659
|
+
}
|
|
660
|
+
isStart() {
|
|
661
|
+
if (this.#root === this)
|
|
662
|
+
return true;
|
|
663
|
+
if (!this.#parent?.isStart())
|
|
664
|
+
return false;
|
|
665
|
+
if (this.#parentIndex === 0)
|
|
666
|
+
return true;
|
|
667
|
+
const p = this.#parent;
|
|
668
|
+
for (let i = 0; i < this.#parentIndex; i++) {
|
|
669
|
+
const pp = p.#parts[i];
|
|
670
|
+
if (!(pp instanceof _a && pp.type === "!")) {
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return true;
|
|
675
|
+
}
|
|
676
|
+
isEnd() {
|
|
677
|
+
if (this.#root === this)
|
|
678
|
+
return true;
|
|
679
|
+
if (this.#parent?.type === "!")
|
|
680
|
+
return true;
|
|
681
|
+
if (!this.#parent?.isEnd())
|
|
682
|
+
return false;
|
|
683
|
+
if (!this.type)
|
|
684
|
+
return this.#parent?.isEnd();
|
|
685
|
+
const pl = this.#parent ? this.#parent.#parts.length : 0;
|
|
686
|
+
return this.#parentIndex === pl - 1;
|
|
687
|
+
}
|
|
688
|
+
copyIn(part) {
|
|
689
|
+
if (typeof part === "string")
|
|
690
|
+
this.push(part);
|
|
691
|
+
else
|
|
692
|
+
this.push(part.clone(this));
|
|
693
|
+
}
|
|
694
|
+
clone(parent) {
|
|
695
|
+
const c = new _a(this.type, parent);
|
|
696
|
+
for (const p of this.#parts) {
|
|
697
|
+
c.copyIn(p);
|
|
698
|
+
}
|
|
699
|
+
return c;
|
|
700
|
+
}
|
|
701
|
+
static #parseAST(str, ast, pos, opt, extDepth) {
|
|
702
|
+
const maxDepth = opt.maxExtglobRecursion ?? 2;
|
|
703
|
+
let escaping = false;
|
|
704
|
+
let inBrace = false;
|
|
705
|
+
let braceStart = -1;
|
|
706
|
+
let braceNeg = false;
|
|
707
|
+
if (ast.type === null) {
|
|
708
|
+
let i2 = pos;
|
|
709
|
+
let acc2 = "";
|
|
710
|
+
while (i2 < str.length) {
|
|
711
|
+
const c = str.charAt(i2++);
|
|
712
|
+
if (escaping || c === "\\") {
|
|
713
|
+
escaping = !escaping;
|
|
714
|
+
acc2 += c;
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
if (inBrace) {
|
|
718
|
+
if (i2 === braceStart + 1) {
|
|
719
|
+
if (c === "^" || c === "!") {
|
|
720
|
+
braceNeg = true;
|
|
721
|
+
}
|
|
722
|
+
} else if (c === "]" && !(i2 === braceStart + 2 && braceNeg)) {
|
|
723
|
+
inBrace = false;
|
|
724
|
+
}
|
|
725
|
+
acc2 += c;
|
|
726
|
+
continue;
|
|
727
|
+
} else if (c === "[") {
|
|
728
|
+
inBrace = true;
|
|
729
|
+
braceStart = i2;
|
|
730
|
+
braceNeg = false;
|
|
731
|
+
acc2 += c;
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
const doRecurse = !opt.noext && isExtglobType(c) && str.charAt(i2) === "(" && extDepth <= maxDepth;
|
|
735
|
+
if (doRecurse) {
|
|
736
|
+
ast.push(acc2);
|
|
737
|
+
acc2 = "";
|
|
738
|
+
const ext2 = new _a(c, ast);
|
|
739
|
+
i2 = _a.#parseAST(str, ext2, i2, opt, extDepth + 1);
|
|
740
|
+
ast.push(ext2);
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
acc2 += c;
|
|
744
|
+
}
|
|
745
|
+
ast.push(acc2);
|
|
746
|
+
return i2;
|
|
747
|
+
}
|
|
748
|
+
let i = pos + 1;
|
|
749
|
+
let part = new _a(null, ast);
|
|
750
|
+
const parts = [];
|
|
751
|
+
let acc = "";
|
|
752
|
+
while (i < str.length) {
|
|
753
|
+
const c = str.charAt(i++);
|
|
754
|
+
if (escaping || c === "\\") {
|
|
755
|
+
escaping = !escaping;
|
|
756
|
+
acc += c;
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
if (inBrace) {
|
|
760
|
+
if (i === braceStart + 1) {
|
|
761
|
+
if (c === "^" || c === "!") {
|
|
762
|
+
braceNeg = true;
|
|
763
|
+
}
|
|
764
|
+
} else if (c === "]" && !(i === braceStart + 2 && braceNeg)) {
|
|
765
|
+
inBrace = false;
|
|
766
|
+
}
|
|
767
|
+
acc += c;
|
|
768
|
+
continue;
|
|
769
|
+
} else if (c === "[") {
|
|
770
|
+
inBrace = true;
|
|
771
|
+
braceStart = i;
|
|
772
|
+
braceNeg = false;
|
|
773
|
+
acc += c;
|
|
774
|
+
continue;
|
|
775
|
+
}
|
|
776
|
+
const doRecurse = !opt.noext && isExtglobType(c) && str.charAt(i) === "(" && /* c8 ignore start - the maxDepth is sufficient here */
|
|
777
|
+
(extDepth <= maxDepth || ast && ast.#canAdoptType(c));
|
|
778
|
+
if (doRecurse) {
|
|
779
|
+
const depthAdd = ast && ast.#canAdoptType(c) ? 0 : 1;
|
|
780
|
+
part.push(acc);
|
|
781
|
+
acc = "";
|
|
782
|
+
const ext2 = new _a(c, part);
|
|
783
|
+
part.push(ext2);
|
|
784
|
+
i = _a.#parseAST(str, ext2, i, opt, extDepth + depthAdd);
|
|
785
|
+
continue;
|
|
786
|
+
}
|
|
787
|
+
if (c === "|") {
|
|
788
|
+
part.push(acc);
|
|
789
|
+
acc = "";
|
|
790
|
+
parts.push(part);
|
|
791
|
+
part = new _a(null, ast);
|
|
792
|
+
continue;
|
|
793
|
+
}
|
|
794
|
+
if (c === ")") {
|
|
795
|
+
if (acc === "" && ast.#parts.length === 0) {
|
|
796
|
+
ast.#emptyExt = true;
|
|
797
|
+
}
|
|
798
|
+
part.push(acc);
|
|
799
|
+
acc = "";
|
|
800
|
+
ast.push(...parts, part);
|
|
801
|
+
return i;
|
|
802
|
+
}
|
|
803
|
+
acc += c;
|
|
804
|
+
}
|
|
805
|
+
ast.type = null;
|
|
806
|
+
ast.#hasMagic = void 0;
|
|
807
|
+
ast.#parts = [str.substring(pos - 1)];
|
|
808
|
+
return i;
|
|
809
|
+
}
|
|
810
|
+
#canAdoptWithSpace(child) {
|
|
811
|
+
return this.#canAdopt(child, adoptionWithSpaceMap);
|
|
812
|
+
}
|
|
813
|
+
#canAdopt(child, map = adoptionMap) {
|
|
814
|
+
if (!child || typeof child !== "object" || child.type !== null || child.#parts.length !== 1 || this.type === null) {
|
|
815
|
+
return false;
|
|
816
|
+
}
|
|
817
|
+
const gc = child.#parts[0];
|
|
818
|
+
if (!gc || typeof gc !== "object" || gc.type === null) {
|
|
819
|
+
return false;
|
|
820
|
+
}
|
|
821
|
+
return this.#canAdoptType(gc.type, map);
|
|
822
|
+
}
|
|
823
|
+
#canAdoptType(c, map = adoptionAnyMap) {
|
|
824
|
+
return !!map.get(this.type)?.includes(c);
|
|
825
|
+
}
|
|
826
|
+
#adoptWithSpace(child, index) {
|
|
827
|
+
const gc = child.#parts[0];
|
|
828
|
+
const blank = new _a(null, gc, this.options);
|
|
829
|
+
blank.#parts.push("");
|
|
830
|
+
gc.push(blank);
|
|
831
|
+
this.#adopt(child, index);
|
|
832
|
+
}
|
|
833
|
+
#adopt(child, index) {
|
|
834
|
+
const gc = child.#parts[0];
|
|
835
|
+
this.#parts.splice(index, 1, ...gc.#parts);
|
|
836
|
+
for (const p of gc.#parts) {
|
|
837
|
+
if (typeof p === "object")
|
|
838
|
+
p.#parent = this;
|
|
839
|
+
}
|
|
840
|
+
this.#toString = void 0;
|
|
841
|
+
}
|
|
842
|
+
#canUsurpType(c) {
|
|
843
|
+
const m = usurpMap.get(this.type);
|
|
844
|
+
return !!m?.has(c);
|
|
845
|
+
}
|
|
846
|
+
#canUsurp(child) {
|
|
847
|
+
if (!child || typeof child !== "object" || child.type !== null || child.#parts.length !== 1 || this.type === null || this.#parts.length !== 1) {
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
850
|
+
const gc = child.#parts[0];
|
|
851
|
+
if (!gc || typeof gc !== "object" || gc.type === null) {
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
return this.#canUsurpType(gc.type);
|
|
855
|
+
}
|
|
856
|
+
#usurp(child) {
|
|
857
|
+
const m = usurpMap.get(this.type);
|
|
858
|
+
const gc = child.#parts[0];
|
|
859
|
+
const nt = m?.get(gc.type);
|
|
860
|
+
if (!nt)
|
|
861
|
+
return false;
|
|
862
|
+
this.#parts = gc.#parts;
|
|
863
|
+
for (const p of this.#parts) {
|
|
864
|
+
if (typeof p === "object") {
|
|
865
|
+
p.#parent = this;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
this.type = nt;
|
|
869
|
+
this.#toString = void 0;
|
|
870
|
+
this.#emptyExt = false;
|
|
871
|
+
}
|
|
872
|
+
static fromGlob(pattern, options = {}) {
|
|
873
|
+
const ast = new _a(null, void 0, options);
|
|
874
|
+
_a.#parseAST(pattern, ast, 0, options, 0);
|
|
875
|
+
return ast;
|
|
876
|
+
}
|
|
877
|
+
// returns the regular expression if there's magic, or the unescaped
|
|
878
|
+
// string if not.
|
|
879
|
+
toMMPattern() {
|
|
880
|
+
if (this !== this.#root)
|
|
881
|
+
return this.#root.toMMPattern();
|
|
882
|
+
const glob = this.toString();
|
|
883
|
+
const [re, body, hasMagic, uflag] = this.toRegExpSource();
|
|
884
|
+
const anyMagic = hasMagic || this.#hasMagic || this.#options.nocase && !this.#options.nocaseMagicOnly && glob.toUpperCase() !== glob.toLowerCase();
|
|
885
|
+
if (!anyMagic) {
|
|
886
|
+
return body;
|
|
887
|
+
}
|
|
888
|
+
const flags = (this.#options.nocase ? "i" : "") + (uflag ? "u" : "");
|
|
889
|
+
return Object.assign(new RegExp(`^${re}$`, flags), {
|
|
890
|
+
_src: re,
|
|
891
|
+
_glob: glob
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
get options() {
|
|
895
|
+
return this.#options;
|
|
896
|
+
}
|
|
897
|
+
// returns the string match, the regexp source, whether there's magic
|
|
898
|
+
// in the regexp (so a regular expression is required) and whether or
|
|
899
|
+
// not the uflag is needed for the regular expression (for posix classes)
|
|
900
|
+
// TODO: instead of injecting the start/end at this point, just return
|
|
901
|
+
// the BODY of the regexp, along with the start/end portions suitable
|
|
902
|
+
// for binding the start/end in either a joined full-path makeRe context
|
|
903
|
+
// (where we bind to (^|/), or a standalone matchPart context (where
|
|
904
|
+
// we bind to ^, and not /). Otherwise slashes get duped!
|
|
905
|
+
//
|
|
906
|
+
// In part-matching mode, the start is:
|
|
907
|
+
// - if not isStart: nothing
|
|
908
|
+
// - if traversal possible, but not allowed: ^(?!\.\.?$)
|
|
909
|
+
// - if dots allowed or not possible: ^
|
|
910
|
+
// - if dots possible and not allowed: ^(?!\.)
|
|
911
|
+
// end is:
|
|
912
|
+
// - if not isEnd(): nothing
|
|
913
|
+
// - else: $
|
|
914
|
+
//
|
|
915
|
+
// In full-path matching mode, we put the slash at the START of the
|
|
916
|
+
// pattern, so start is:
|
|
917
|
+
// - if first pattern: same as part-matching mode
|
|
918
|
+
// - if not isStart(): nothing
|
|
919
|
+
// - if traversal possible, but not allowed: /(?!\.\.?(?:$|/))
|
|
920
|
+
// - if dots allowed or not possible: /
|
|
921
|
+
// - if dots possible and not allowed: /(?!\.)
|
|
922
|
+
// end is:
|
|
923
|
+
// - if last pattern, same as part-matching mode
|
|
924
|
+
// - else nothing
|
|
925
|
+
//
|
|
926
|
+
// Always put the (?:$|/) on negated tails, though, because that has to be
|
|
927
|
+
// there to bind the end of the negated pattern portion, and it's easier to
|
|
928
|
+
// just stick it in now rather than try to inject it later in the middle of
|
|
929
|
+
// the pattern.
|
|
930
|
+
//
|
|
931
|
+
// We can just always return the same end, and leave it up to the caller
|
|
932
|
+
// to know whether it's going to be used joined or in parts.
|
|
933
|
+
// And, if the start is adjusted slightly, can do the same there:
|
|
934
|
+
// - if not isStart: nothing
|
|
935
|
+
// - if traversal possible, but not allowed: (?:/|^)(?!\.\.?$)
|
|
936
|
+
// - if dots allowed or not possible: (?:/|^)
|
|
937
|
+
// - if dots possible and not allowed: (?:/|^)(?!\.)
|
|
938
|
+
//
|
|
939
|
+
// But it's better to have a simpler binding without a conditional, for
|
|
940
|
+
// performance, so probably better to return both start options.
|
|
941
|
+
//
|
|
942
|
+
// Then the caller just ignores the end if it's not the first pattern,
|
|
943
|
+
// and the start always gets applied.
|
|
944
|
+
//
|
|
945
|
+
// But that's always going to be $ if it's the ending pattern, or nothing,
|
|
946
|
+
// so the caller can just attach $ at the end of the pattern when building.
|
|
947
|
+
//
|
|
948
|
+
// So the todo is:
|
|
949
|
+
// - better detect what kind of start is needed
|
|
950
|
+
// - return both flavors of starting pattern
|
|
951
|
+
// - attach $ at the end of the pattern when creating the actual RegExp
|
|
952
|
+
//
|
|
953
|
+
// Ah, but wait, no, that all only applies to the root when the first pattern
|
|
954
|
+
// is not an extglob. If the first pattern IS an extglob, then we need all
|
|
955
|
+
// that dot prevention biz to live in the extglob portions, because eg
|
|
956
|
+
// +(*|.x*) can match .xy but not .yx.
|
|
957
|
+
//
|
|
958
|
+
// So, return the two flavors if it's #root and the first child is not an
|
|
959
|
+
// AST, otherwise leave it to the child AST to handle it, and there,
|
|
960
|
+
// use the (?:^|/) style of start binding.
|
|
961
|
+
//
|
|
962
|
+
// Even simplified further:
|
|
963
|
+
// - Since the start for a join is eg /(?!\.) and the start for a part
|
|
964
|
+
// is ^(?!\.), we can just prepend (?!\.) to the pattern (either root
|
|
965
|
+
// or start or whatever) and prepend ^ or / at the Regexp construction.
|
|
966
|
+
toRegExpSource(allowDot) {
|
|
967
|
+
const dot = allowDot ?? !!this.#options.dot;
|
|
968
|
+
if (this.#root === this) {
|
|
969
|
+
this.#flatten();
|
|
970
|
+
this.#fillNegs();
|
|
971
|
+
}
|
|
972
|
+
if (!isExtglobAST(this)) {
|
|
973
|
+
const noEmpty = this.isStart() && this.isEnd() && !this.#parts.some((s) => typeof s !== "string");
|
|
974
|
+
const src = this.#parts.map((p) => {
|
|
975
|
+
const [re, _, hasMagic, uflag] = typeof p === "string" ? _a.#parseGlob(p, this.#hasMagic, noEmpty) : p.toRegExpSource(allowDot);
|
|
976
|
+
this.#hasMagic = this.#hasMagic || hasMagic;
|
|
977
|
+
this.#uflag = this.#uflag || uflag;
|
|
978
|
+
return re;
|
|
979
|
+
}).join("");
|
|
980
|
+
let start2 = "";
|
|
981
|
+
if (this.isStart()) {
|
|
982
|
+
if (typeof this.#parts[0] === "string") {
|
|
983
|
+
const dotTravAllowed = this.#parts.length === 1 && justDots.has(this.#parts[0]);
|
|
984
|
+
if (!dotTravAllowed) {
|
|
985
|
+
const aps = addPatternStart;
|
|
986
|
+
const needNoTrav = (
|
|
987
|
+
// dots are allowed, and the pattern starts with [ or .
|
|
988
|
+
dot && aps.has(src.charAt(0)) || // the pattern starts with \., and then [ or .
|
|
989
|
+
src.startsWith("\\.") && aps.has(src.charAt(2)) || // the pattern starts with \.\., and then [ or .
|
|
990
|
+
src.startsWith("\\.\\.") && aps.has(src.charAt(4))
|
|
991
|
+
);
|
|
992
|
+
const needNoDot = !dot && !allowDot && aps.has(src.charAt(0));
|
|
993
|
+
start2 = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : "";
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
let end = "";
|
|
998
|
+
if (this.isEnd() && this.#root.#filledNegs && this.#parent?.type === "!") {
|
|
999
|
+
end = "(?:$|\\/)";
|
|
1000
|
+
}
|
|
1001
|
+
const final2 = start2 + src + end;
|
|
1002
|
+
return [
|
|
1003
|
+
final2,
|
|
1004
|
+
unescape(src),
|
|
1005
|
+
this.#hasMagic = !!this.#hasMagic,
|
|
1006
|
+
this.#uflag
|
|
1007
|
+
];
|
|
1008
|
+
}
|
|
1009
|
+
const repeated = this.type === "*" || this.type === "+";
|
|
1010
|
+
const start = this.type === "!" ? "(?:(?!(?:" : "(?:";
|
|
1011
|
+
let body = this.#partsToRegExp(dot);
|
|
1012
|
+
if (this.isStart() && this.isEnd() && !body && this.type !== "!") {
|
|
1013
|
+
const s = this.toString();
|
|
1014
|
+
const me = this;
|
|
1015
|
+
me.#parts = [s];
|
|
1016
|
+
me.type = null;
|
|
1017
|
+
me.#hasMagic = void 0;
|
|
1018
|
+
return [s, unescape(this.toString()), false, false];
|
|
1019
|
+
}
|
|
1020
|
+
let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot ? "" : this.#partsToRegExp(true);
|
|
1021
|
+
if (bodyDotAllowed === body) {
|
|
1022
|
+
bodyDotAllowed = "";
|
|
1023
|
+
}
|
|
1024
|
+
if (bodyDotAllowed) {
|
|
1025
|
+
body = `(?:${body})(?:${bodyDotAllowed})*?`;
|
|
1026
|
+
}
|
|
1027
|
+
let final = "";
|
|
1028
|
+
if (this.type === "!" && this.#emptyExt) {
|
|
1029
|
+
final = (this.isStart() && !dot ? startNoDot : "") + starNoEmpty;
|
|
1030
|
+
} else {
|
|
1031
|
+
const close = this.type === "!" ? (
|
|
1032
|
+
// !() must match something,but !(x) can match ''
|
|
1033
|
+
"))" + (this.isStart() && !dot && !allowDot ? startNoDot : "") + star + ")"
|
|
1034
|
+
) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && bodyDotAllowed ? ")" : this.type === "*" && bodyDotAllowed ? `)?` : `)${this.type}`;
|
|
1035
|
+
final = start + body + close;
|
|
1036
|
+
}
|
|
1037
|
+
return [
|
|
1038
|
+
final,
|
|
1039
|
+
unescape(body),
|
|
1040
|
+
this.#hasMagic = !!this.#hasMagic,
|
|
1041
|
+
this.#uflag
|
|
1042
|
+
];
|
|
1043
|
+
}
|
|
1044
|
+
#flatten() {
|
|
1045
|
+
if (!isExtglobAST(this)) {
|
|
1046
|
+
for (const p of this.#parts) {
|
|
1047
|
+
if (typeof p === "object") {
|
|
1048
|
+
p.#flatten();
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
} else {
|
|
1052
|
+
let iterations = 0;
|
|
1053
|
+
let done = false;
|
|
1054
|
+
do {
|
|
1055
|
+
done = true;
|
|
1056
|
+
for (let i = 0; i < this.#parts.length; i++) {
|
|
1057
|
+
const c = this.#parts[i];
|
|
1058
|
+
if (typeof c === "object") {
|
|
1059
|
+
c.#flatten();
|
|
1060
|
+
if (this.#canAdopt(c)) {
|
|
1061
|
+
done = false;
|
|
1062
|
+
this.#adopt(c, i);
|
|
1063
|
+
} else if (this.#canAdoptWithSpace(c)) {
|
|
1064
|
+
done = false;
|
|
1065
|
+
this.#adoptWithSpace(c, i);
|
|
1066
|
+
} else if (this.#canUsurp(c)) {
|
|
1067
|
+
done = false;
|
|
1068
|
+
this.#usurp(c);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
} while (!done && ++iterations < 10);
|
|
1073
|
+
}
|
|
1074
|
+
this.#toString = void 0;
|
|
1075
|
+
}
|
|
1076
|
+
#partsToRegExp(dot) {
|
|
1077
|
+
return this.#parts.map((p) => {
|
|
1078
|
+
if (typeof p === "string") {
|
|
1079
|
+
throw new Error("string type in extglob ast??");
|
|
1080
|
+
}
|
|
1081
|
+
const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot);
|
|
1082
|
+
this.#uflag = this.#uflag || uflag;
|
|
1083
|
+
return re;
|
|
1084
|
+
}).filter((p) => !(this.isStart() && this.isEnd()) || !!p).join("|");
|
|
1085
|
+
}
|
|
1086
|
+
static #parseGlob(glob, hasMagic, noEmpty = false) {
|
|
1087
|
+
let escaping = false;
|
|
1088
|
+
let re = "";
|
|
1089
|
+
let uflag = false;
|
|
1090
|
+
let inStar = false;
|
|
1091
|
+
for (let i = 0; i < glob.length; i++) {
|
|
1092
|
+
const c = glob.charAt(i);
|
|
1093
|
+
if (escaping) {
|
|
1094
|
+
escaping = false;
|
|
1095
|
+
re += (reSpecials.has(c) ? "\\" : "") + c;
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
if (c === "*") {
|
|
1099
|
+
if (inStar)
|
|
1100
|
+
continue;
|
|
1101
|
+
inStar = true;
|
|
1102
|
+
re += noEmpty && /^[*]+$/.test(glob) ? starNoEmpty : star;
|
|
1103
|
+
hasMagic = true;
|
|
1104
|
+
continue;
|
|
1105
|
+
} else {
|
|
1106
|
+
inStar = false;
|
|
1107
|
+
}
|
|
1108
|
+
if (c === "\\") {
|
|
1109
|
+
if (i === glob.length - 1) {
|
|
1110
|
+
re += "\\\\";
|
|
1111
|
+
} else {
|
|
1112
|
+
escaping = true;
|
|
1113
|
+
}
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
if (c === "[") {
|
|
1117
|
+
const [src, needUflag, consumed, magic] = parseClass(glob, i);
|
|
1118
|
+
if (consumed) {
|
|
1119
|
+
re += src;
|
|
1120
|
+
uflag = uflag || needUflag;
|
|
1121
|
+
i += consumed - 1;
|
|
1122
|
+
hasMagic = hasMagic || magic;
|
|
1123
|
+
continue;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
if (c === "?") {
|
|
1127
|
+
re += qmark;
|
|
1128
|
+
hasMagic = true;
|
|
1129
|
+
continue;
|
|
1130
|
+
}
|
|
1131
|
+
re += regExpEscape(c);
|
|
1132
|
+
}
|
|
1133
|
+
return [re, unescape(glob), !!hasMagic, uflag];
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
_a = AST;
|
|
1137
|
+
|
|
1138
|
+
// ../../node_modules/minimatch/dist/esm/escape.js
|
|
1139
|
+
var escape = (s, { windowsPathsNoEscape = false, magicalBraces = false } = {}) => {
|
|
1140
|
+
if (magicalBraces) {
|
|
1141
|
+
return windowsPathsNoEscape ? s.replace(/[?*()[\]{}]/g, "[$&]") : s.replace(/[?*()[\]\\{}]/g, "\\$&");
|
|
1142
|
+
}
|
|
1143
|
+
return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
// ../../node_modules/minimatch/dist/esm/index.js
|
|
1147
|
+
var minimatch = (p, pattern, options = {}) => {
|
|
1148
|
+
assertValidPattern(pattern);
|
|
1149
|
+
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
1150
|
+
return false;
|
|
1151
|
+
}
|
|
1152
|
+
return new Minimatch(pattern, options).match(p);
|
|
1153
|
+
};
|
|
1154
|
+
var starDotExtRE = /^\*+([^+@!?*[(]*)$/;
|
|
1155
|
+
var starDotExtTest = (ext2) => (f) => !f.startsWith(".") && f.endsWith(ext2);
|
|
1156
|
+
var starDotExtTestDot = (ext2) => (f) => f.endsWith(ext2);
|
|
1157
|
+
var starDotExtTestNocase = (ext2) => {
|
|
1158
|
+
ext2 = ext2.toLowerCase();
|
|
1159
|
+
return (f) => !f.startsWith(".") && f.toLowerCase().endsWith(ext2);
|
|
1160
|
+
};
|
|
1161
|
+
var starDotExtTestNocaseDot = (ext2) => {
|
|
1162
|
+
ext2 = ext2.toLowerCase();
|
|
1163
|
+
return (f) => f.toLowerCase().endsWith(ext2);
|
|
1164
|
+
};
|
|
1165
|
+
var starDotStarRE = /^\*+\.\*+$/;
|
|
1166
|
+
var starDotStarTest = (f) => !f.startsWith(".") && f.includes(".");
|
|
1167
|
+
var starDotStarTestDot = (f) => f !== "." && f !== ".." && f.includes(".");
|
|
1168
|
+
var dotStarRE = /^\.\*+$/;
|
|
1169
|
+
var dotStarTest = (f) => f !== "." && f !== ".." && f.startsWith(".");
|
|
1170
|
+
var starRE = /^\*+$/;
|
|
1171
|
+
var starTest = (f) => f.length !== 0 && !f.startsWith(".");
|
|
1172
|
+
var starTestDot = (f) => f.length !== 0 && f !== "." && f !== "..";
|
|
1173
|
+
var qmarksRE = /^\?+([^+@!?*[(]*)?$/;
|
|
1174
|
+
var qmarksTestNocase = ([$0, ext2 = ""]) => {
|
|
1175
|
+
const noext = qmarksTestNoExt([$0]);
|
|
1176
|
+
if (!ext2)
|
|
1177
|
+
return noext;
|
|
1178
|
+
ext2 = ext2.toLowerCase();
|
|
1179
|
+
return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
|
|
1180
|
+
};
|
|
1181
|
+
var qmarksTestNocaseDot = ([$0, ext2 = ""]) => {
|
|
1182
|
+
const noext = qmarksTestNoExtDot([$0]);
|
|
1183
|
+
if (!ext2)
|
|
1184
|
+
return noext;
|
|
1185
|
+
ext2 = ext2.toLowerCase();
|
|
1186
|
+
return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
|
|
1187
|
+
};
|
|
1188
|
+
var qmarksTestDot = ([$0, ext2 = ""]) => {
|
|
1189
|
+
const noext = qmarksTestNoExtDot([$0]);
|
|
1190
|
+
return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
|
|
1191
|
+
};
|
|
1192
|
+
var qmarksTest = ([$0, ext2 = ""]) => {
|
|
1193
|
+
const noext = qmarksTestNoExt([$0]);
|
|
1194
|
+
return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
|
|
1195
|
+
};
|
|
1196
|
+
var qmarksTestNoExt = ([$0]) => {
|
|
1197
|
+
const len = $0.length;
|
|
1198
|
+
return (f) => f.length === len && !f.startsWith(".");
|
|
1199
|
+
};
|
|
1200
|
+
var qmarksTestNoExtDot = ([$0]) => {
|
|
1201
|
+
const len = $0.length;
|
|
1202
|
+
return (f) => f.length === len && f !== "." && f !== "..";
|
|
1203
|
+
};
|
|
1204
|
+
var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
1205
|
+
var path = {
|
|
1206
|
+
win32: { sep: "\\" },
|
|
1207
|
+
posix: { sep: "/" }
|
|
1208
|
+
};
|
|
1209
|
+
var sep = defaultPlatform === "win32" ? path.win32.sep : path.posix.sep;
|
|
1210
|
+
minimatch.sep = sep;
|
|
1211
|
+
var GLOBSTAR = /* @__PURE__ */ Symbol("globstar **");
|
|
1212
|
+
minimatch.GLOBSTAR = GLOBSTAR;
|
|
1213
|
+
var qmark2 = "[^/]";
|
|
1214
|
+
var star2 = qmark2 + "*?";
|
|
1215
|
+
var twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
|
|
1216
|
+
var twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?";
|
|
1217
|
+
var filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options);
|
|
1218
|
+
minimatch.filter = filter;
|
|
1219
|
+
var ext = (a, b = {}) => Object.assign({}, a, b);
|
|
1220
|
+
var defaults = (def) => {
|
|
1221
|
+
if (!def || typeof def !== "object" || !Object.keys(def).length) {
|
|
1222
|
+
return minimatch;
|
|
1223
|
+
}
|
|
1224
|
+
const orig = minimatch;
|
|
1225
|
+
const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
|
|
1226
|
+
return Object.assign(m, {
|
|
1227
|
+
Minimatch: class Minimatch extends orig.Minimatch {
|
|
1228
|
+
constructor(pattern, options = {}) {
|
|
1229
|
+
super(pattern, ext(def, options));
|
|
1230
|
+
}
|
|
1231
|
+
static defaults(options) {
|
|
1232
|
+
return orig.defaults(ext(def, options)).Minimatch;
|
|
1233
|
+
}
|
|
1234
|
+
},
|
|
1235
|
+
AST: class AST extends orig.AST {
|
|
1236
|
+
/* c8 ignore start */
|
|
1237
|
+
constructor(type, parent, options = {}) {
|
|
1238
|
+
super(type, parent, ext(def, options));
|
|
1239
|
+
}
|
|
1240
|
+
/* c8 ignore stop */
|
|
1241
|
+
static fromGlob(pattern, options = {}) {
|
|
1242
|
+
return orig.AST.fromGlob(pattern, ext(def, options));
|
|
1243
|
+
}
|
|
1244
|
+
},
|
|
1245
|
+
unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
|
|
1246
|
+
escape: (s, options = {}) => orig.escape(s, ext(def, options)),
|
|
1247
|
+
filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
|
|
1248
|
+
defaults: (options) => orig.defaults(ext(def, options)),
|
|
1249
|
+
makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)),
|
|
1250
|
+
braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
|
|
1251
|
+
match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
|
|
1252
|
+
sep: orig.sep,
|
|
1253
|
+
GLOBSTAR
|
|
1254
|
+
});
|
|
1255
|
+
};
|
|
1256
|
+
minimatch.defaults = defaults;
|
|
1257
|
+
var braceExpand = (pattern, options = {}) => {
|
|
1258
|
+
assertValidPattern(pattern);
|
|
1259
|
+
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
|
|
1260
|
+
return [pattern];
|
|
1261
|
+
}
|
|
1262
|
+
return expand(pattern, { max: options.braceExpandMax });
|
|
1263
|
+
};
|
|
1264
|
+
minimatch.braceExpand = braceExpand;
|
|
1265
|
+
var makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe();
|
|
1266
|
+
minimatch.makeRe = makeRe;
|
|
1267
|
+
var match = (list, pattern, options = {}) => {
|
|
1268
|
+
const mm = new Minimatch(pattern, options);
|
|
1269
|
+
list = list.filter((f) => mm.match(f));
|
|
1270
|
+
if (mm.options.nonull && !list.length) {
|
|
1271
|
+
list.push(pattern);
|
|
1272
|
+
}
|
|
1273
|
+
return list;
|
|
1274
|
+
};
|
|
1275
|
+
minimatch.match = match;
|
|
1276
|
+
var globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
|
|
1277
|
+
var regExpEscape2 = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
1278
|
+
var Minimatch = class {
|
|
1279
|
+
options;
|
|
1280
|
+
set;
|
|
1281
|
+
pattern;
|
|
1282
|
+
windowsPathsNoEscape;
|
|
1283
|
+
nonegate;
|
|
1284
|
+
negate;
|
|
1285
|
+
comment;
|
|
1286
|
+
empty;
|
|
1287
|
+
preserveMultipleSlashes;
|
|
1288
|
+
partial;
|
|
1289
|
+
globSet;
|
|
1290
|
+
globParts;
|
|
1291
|
+
nocase;
|
|
1292
|
+
isWindows;
|
|
1293
|
+
platform;
|
|
1294
|
+
windowsNoMagicRoot;
|
|
1295
|
+
maxGlobstarRecursion;
|
|
1296
|
+
regexp;
|
|
1297
|
+
constructor(pattern, options = {}) {
|
|
1298
|
+
assertValidPattern(pattern);
|
|
1299
|
+
options = options || {};
|
|
1300
|
+
this.options = options;
|
|
1301
|
+
this.maxGlobstarRecursion = options.maxGlobstarRecursion ?? 200;
|
|
1302
|
+
this.pattern = pattern;
|
|
1303
|
+
this.platform = options.platform || defaultPlatform;
|
|
1304
|
+
this.isWindows = this.platform === "win32";
|
|
1305
|
+
const awe = "allowWindowsEscape";
|
|
1306
|
+
this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options[awe] === false;
|
|
1307
|
+
if (this.windowsPathsNoEscape) {
|
|
1308
|
+
this.pattern = this.pattern.replace(/\\/g, "/");
|
|
1309
|
+
}
|
|
1310
|
+
this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
|
|
1311
|
+
this.regexp = null;
|
|
1312
|
+
this.negate = false;
|
|
1313
|
+
this.nonegate = !!options.nonegate;
|
|
1314
|
+
this.comment = false;
|
|
1315
|
+
this.empty = false;
|
|
1316
|
+
this.partial = !!options.partial;
|
|
1317
|
+
this.nocase = !!this.options.nocase;
|
|
1318
|
+
this.windowsNoMagicRoot = options.windowsNoMagicRoot !== void 0 ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
|
|
1319
|
+
this.globSet = [];
|
|
1320
|
+
this.globParts = [];
|
|
1321
|
+
this.set = [];
|
|
1322
|
+
this.make();
|
|
1323
|
+
}
|
|
1324
|
+
hasMagic() {
|
|
1325
|
+
if (this.options.magicalBraces && this.set.length > 1) {
|
|
1326
|
+
return true;
|
|
1327
|
+
}
|
|
1328
|
+
for (const pattern of this.set) {
|
|
1329
|
+
for (const part of pattern) {
|
|
1330
|
+
if (typeof part !== "string")
|
|
1331
|
+
return true;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
return false;
|
|
1335
|
+
}
|
|
1336
|
+
debug(..._) {
|
|
1337
|
+
}
|
|
1338
|
+
make() {
|
|
1339
|
+
const pattern = this.pattern;
|
|
1340
|
+
const options = this.options;
|
|
1341
|
+
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
1342
|
+
this.comment = true;
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
if (!pattern) {
|
|
1346
|
+
this.empty = true;
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
this.parseNegate();
|
|
1350
|
+
this.globSet = [...new Set(this.braceExpand())];
|
|
1351
|
+
if (options.debug) {
|
|
1352
|
+
this.debug = (...args) => console.error(...args);
|
|
1353
|
+
}
|
|
1354
|
+
this.debug(this.pattern, this.globSet);
|
|
1355
|
+
const rawGlobParts = this.globSet.map((s) => this.slashSplit(s));
|
|
1356
|
+
this.globParts = this.preprocess(rawGlobParts);
|
|
1357
|
+
this.debug(this.pattern, this.globParts);
|
|
1358
|
+
let set = this.globParts.map((s, _, __) => {
|
|
1359
|
+
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
1360
|
+
const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]);
|
|
1361
|
+
const isDrive = /^[a-z]:/i.test(s[0]);
|
|
1362
|
+
if (isUNC) {
|
|
1363
|
+
return [
|
|
1364
|
+
...s.slice(0, 4),
|
|
1365
|
+
...s.slice(4).map((ss) => this.parse(ss))
|
|
1366
|
+
];
|
|
1367
|
+
} else if (isDrive) {
|
|
1368
|
+
return [s[0], ...s.slice(1).map((ss) => this.parse(ss))];
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return s.map((ss) => this.parse(ss));
|
|
1372
|
+
});
|
|
1373
|
+
this.debug(this.pattern, set);
|
|
1374
|
+
this.set = set.filter((s) => s.indexOf(false) === -1);
|
|
1375
|
+
if (this.isWindows) {
|
|
1376
|
+
for (let i = 0; i < this.set.length; i++) {
|
|
1377
|
+
const p = this.set[i];
|
|
1378
|
+
if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && typeof p[3] === "string" && /^[a-z]:$/i.test(p[3])) {
|
|
1379
|
+
p[2] = "?";
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
this.debug(this.pattern, this.set);
|
|
1384
|
+
}
|
|
1385
|
+
// various transforms to equivalent pattern sets that are
|
|
1386
|
+
// faster to process in a filesystem walk. The goal is to
|
|
1387
|
+
// eliminate what we can, and push all ** patterns as far
|
|
1388
|
+
// to the right as possible, even if it increases the number
|
|
1389
|
+
// of patterns that we have to process.
|
|
1390
|
+
preprocess(globParts) {
|
|
1391
|
+
if (this.options.noglobstar) {
|
|
1392
|
+
for (const partset of globParts) {
|
|
1393
|
+
for (let j = 0; j < partset.length; j++) {
|
|
1394
|
+
if (partset[j] === "**") {
|
|
1395
|
+
partset[j] = "*";
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
const { optimizationLevel = 1 } = this.options;
|
|
1401
|
+
if (optimizationLevel >= 2) {
|
|
1402
|
+
globParts = this.firstPhasePreProcess(globParts);
|
|
1403
|
+
globParts = this.secondPhasePreProcess(globParts);
|
|
1404
|
+
} else if (optimizationLevel >= 1) {
|
|
1405
|
+
globParts = this.levelOneOptimize(globParts);
|
|
1406
|
+
} else {
|
|
1407
|
+
globParts = this.adjascentGlobstarOptimize(globParts);
|
|
1408
|
+
}
|
|
1409
|
+
return globParts;
|
|
1410
|
+
}
|
|
1411
|
+
// just get rid of adjascent ** portions
|
|
1412
|
+
adjascentGlobstarOptimize(globParts) {
|
|
1413
|
+
return globParts.map((parts) => {
|
|
1414
|
+
let gs = -1;
|
|
1415
|
+
while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
|
|
1416
|
+
let i = gs;
|
|
1417
|
+
while (parts[i + 1] === "**") {
|
|
1418
|
+
i++;
|
|
1419
|
+
}
|
|
1420
|
+
if (i !== gs) {
|
|
1421
|
+
parts.splice(gs, i - gs);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
return parts;
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
// get rid of adjascent ** and resolve .. portions
|
|
1428
|
+
levelOneOptimize(globParts) {
|
|
1429
|
+
return globParts.map((parts) => {
|
|
1430
|
+
parts = parts.reduce((set, part) => {
|
|
1431
|
+
const prev = set[set.length - 1];
|
|
1432
|
+
if (part === "**" && prev === "**") {
|
|
1433
|
+
return set;
|
|
1434
|
+
}
|
|
1435
|
+
if (part === "..") {
|
|
1436
|
+
if (prev && prev !== ".." && prev !== "." && prev !== "**") {
|
|
1437
|
+
set.pop();
|
|
1438
|
+
return set;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
set.push(part);
|
|
1442
|
+
return set;
|
|
1443
|
+
}, []);
|
|
1444
|
+
return parts.length === 0 ? [""] : parts;
|
|
1445
|
+
});
|
|
1446
|
+
}
|
|
1447
|
+
levelTwoFileOptimize(parts) {
|
|
1448
|
+
if (!Array.isArray(parts)) {
|
|
1449
|
+
parts = this.slashSplit(parts);
|
|
1450
|
+
}
|
|
1451
|
+
let didSomething = false;
|
|
1452
|
+
do {
|
|
1453
|
+
didSomething = false;
|
|
1454
|
+
if (!this.preserveMultipleSlashes) {
|
|
1455
|
+
for (let i = 1; i < parts.length - 1; i++) {
|
|
1456
|
+
const p = parts[i];
|
|
1457
|
+
if (i === 1 && p === "" && parts[0] === "")
|
|
1458
|
+
continue;
|
|
1459
|
+
if (p === "." || p === "") {
|
|
1460
|
+
didSomething = true;
|
|
1461
|
+
parts.splice(i, 1);
|
|
1462
|
+
i--;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
1466
|
+
didSomething = true;
|
|
1467
|
+
parts.pop();
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
let dd = 0;
|
|
1471
|
+
while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
|
|
1472
|
+
const p = parts[dd - 1];
|
|
1473
|
+
if (p && p !== "." && p !== ".." && p !== "**" && !(this.isWindows && /^[a-z]:$/i.test(p))) {
|
|
1474
|
+
didSomething = true;
|
|
1475
|
+
parts.splice(dd - 1, 2);
|
|
1476
|
+
dd -= 2;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
} while (didSomething);
|
|
1480
|
+
return parts.length === 0 ? [""] : parts;
|
|
1481
|
+
}
|
|
1482
|
+
// First phase: single-pattern processing
|
|
1483
|
+
// <pre> is 1 or more portions
|
|
1484
|
+
// <rest> is 1 or more portions
|
|
1485
|
+
// <p> is any portion other than ., .., '', or **
|
|
1486
|
+
// <e> is . or ''
|
|
1487
|
+
//
|
|
1488
|
+
// **/.. is *brutal* for filesystem walking performance, because
|
|
1489
|
+
// it effectively resets the recursive walk each time it occurs,
|
|
1490
|
+
// and ** cannot be reduced out by a .. pattern part like a regexp
|
|
1491
|
+
// or most strings (other than .., ., and '') can be.
|
|
1492
|
+
//
|
|
1493
|
+
// <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
|
|
1494
|
+
// <pre>/<e>/<rest> -> <pre>/<rest>
|
|
1495
|
+
// <pre>/<p>/../<rest> -> <pre>/<rest>
|
|
1496
|
+
// **/**/<rest> -> **/<rest>
|
|
1497
|
+
//
|
|
1498
|
+
// **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
|
|
1499
|
+
// this WOULD be allowed if ** did follow symlinks, or * didn't
|
|
1500
|
+
firstPhasePreProcess(globParts) {
|
|
1501
|
+
let didSomething = false;
|
|
1502
|
+
do {
|
|
1503
|
+
didSomething = false;
|
|
1504
|
+
for (let parts of globParts) {
|
|
1505
|
+
let gs = -1;
|
|
1506
|
+
while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
|
|
1507
|
+
let gss = gs;
|
|
1508
|
+
while (parts[gss + 1] === "**") {
|
|
1509
|
+
gss++;
|
|
1510
|
+
}
|
|
1511
|
+
if (gss > gs) {
|
|
1512
|
+
parts.splice(gs + 1, gss - gs);
|
|
1513
|
+
}
|
|
1514
|
+
let next = parts[gs + 1];
|
|
1515
|
+
const p = parts[gs + 2];
|
|
1516
|
+
const p2 = parts[gs + 3];
|
|
1517
|
+
if (next !== "..")
|
|
1518
|
+
continue;
|
|
1519
|
+
if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") {
|
|
1520
|
+
continue;
|
|
1521
|
+
}
|
|
1522
|
+
didSomething = true;
|
|
1523
|
+
parts.splice(gs, 1);
|
|
1524
|
+
const other = parts.slice(0);
|
|
1525
|
+
other[gs] = "**";
|
|
1526
|
+
globParts.push(other);
|
|
1527
|
+
gs--;
|
|
1528
|
+
}
|
|
1529
|
+
if (!this.preserveMultipleSlashes) {
|
|
1530
|
+
for (let i = 1; i < parts.length - 1; i++) {
|
|
1531
|
+
const p = parts[i];
|
|
1532
|
+
if (i === 1 && p === "" && parts[0] === "")
|
|
1533
|
+
continue;
|
|
1534
|
+
if (p === "." || p === "") {
|
|
1535
|
+
didSomething = true;
|
|
1536
|
+
parts.splice(i, 1);
|
|
1537
|
+
i--;
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
1541
|
+
didSomething = true;
|
|
1542
|
+
parts.pop();
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
let dd = 0;
|
|
1546
|
+
while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
|
|
1547
|
+
const p = parts[dd - 1];
|
|
1548
|
+
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
1549
|
+
didSomething = true;
|
|
1550
|
+
const needDot = dd === 1 && parts[dd + 1] === "**";
|
|
1551
|
+
const splin = needDot ? ["."] : [];
|
|
1552
|
+
parts.splice(dd - 1, 2, ...splin);
|
|
1553
|
+
if (parts.length === 0)
|
|
1554
|
+
parts.push("");
|
|
1555
|
+
dd -= 2;
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
} while (didSomething);
|
|
1560
|
+
return globParts;
|
|
1561
|
+
}
|
|
1562
|
+
// second phase: multi-pattern dedupes
|
|
1563
|
+
// {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
|
|
1564
|
+
// {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
|
|
1565
|
+
// {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
|
|
1566
|
+
//
|
|
1567
|
+
// {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
|
|
1568
|
+
// ^-- not valid because ** doens't follow symlinks
|
|
1569
|
+
secondPhasePreProcess(globParts) {
|
|
1570
|
+
for (let i = 0; i < globParts.length - 1; i++) {
|
|
1571
|
+
for (let j = i + 1; j < globParts.length; j++) {
|
|
1572
|
+
const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);
|
|
1573
|
+
if (matched) {
|
|
1574
|
+
globParts[i] = [];
|
|
1575
|
+
globParts[j] = matched;
|
|
1576
|
+
break;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
return globParts.filter((gs) => gs.length);
|
|
1581
|
+
}
|
|
1582
|
+
partsMatch(a, b, emptyGSMatch = false) {
|
|
1583
|
+
let ai = 0;
|
|
1584
|
+
let bi = 0;
|
|
1585
|
+
let result = [];
|
|
1586
|
+
let which = "";
|
|
1587
|
+
while (ai < a.length && bi < b.length) {
|
|
1588
|
+
if (a[ai] === b[bi]) {
|
|
1589
|
+
result.push(which === "b" ? b[bi] : a[ai]);
|
|
1590
|
+
ai++;
|
|
1591
|
+
bi++;
|
|
1592
|
+
} else if (emptyGSMatch && a[ai] === "**" && b[bi] === a[ai + 1]) {
|
|
1593
|
+
result.push(a[ai]);
|
|
1594
|
+
ai++;
|
|
1595
|
+
} else if (emptyGSMatch && b[bi] === "**" && a[ai] === b[bi + 1]) {
|
|
1596
|
+
result.push(b[bi]);
|
|
1597
|
+
bi++;
|
|
1598
|
+
} else if (a[ai] === "*" && b[bi] && (this.options.dot || !b[bi].startsWith(".")) && b[bi] !== "**") {
|
|
1599
|
+
if (which === "b")
|
|
1600
|
+
return false;
|
|
1601
|
+
which = "a";
|
|
1602
|
+
result.push(a[ai]);
|
|
1603
|
+
ai++;
|
|
1604
|
+
bi++;
|
|
1605
|
+
} else if (b[bi] === "*" && a[ai] && (this.options.dot || !a[ai].startsWith(".")) && a[ai] !== "**") {
|
|
1606
|
+
if (which === "a")
|
|
1607
|
+
return false;
|
|
1608
|
+
which = "b";
|
|
1609
|
+
result.push(b[bi]);
|
|
1610
|
+
ai++;
|
|
1611
|
+
bi++;
|
|
1612
|
+
} else {
|
|
1613
|
+
return false;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
return a.length === b.length && result;
|
|
1617
|
+
}
|
|
1618
|
+
parseNegate() {
|
|
1619
|
+
if (this.nonegate)
|
|
1620
|
+
return;
|
|
1621
|
+
const pattern = this.pattern;
|
|
1622
|
+
let negate = false;
|
|
1623
|
+
let negateOffset = 0;
|
|
1624
|
+
for (let i = 0; i < pattern.length && pattern.charAt(i) === "!"; i++) {
|
|
1625
|
+
negate = !negate;
|
|
1626
|
+
negateOffset++;
|
|
1627
|
+
}
|
|
1628
|
+
if (negateOffset)
|
|
1629
|
+
this.pattern = pattern.slice(negateOffset);
|
|
1630
|
+
this.negate = negate;
|
|
1631
|
+
}
|
|
1632
|
+
// set partial to true to test if, for example,
|
|
1633
|
+
// "/a/b" matches the start of "/*/b/*/d"
|
|
1634
|
+
// Partial means, if you run out of file before you run
|
|
1635
|
+
// out of pattern, then that's fine, as long as all
|
|
1636
|
+
// the parts match.
|
|
1637
|
+
matchOne(file, pattern, partial = false) {
|
|
1638
|
+
let fileStartIndex = 0;
|
|
1639
|
+
let patternStartIndex = 0;
|
|
1640
|
+
if (this.isWindows) {
|
|
1641
|
+
const fileDrive = typeof file[0] === "string" && /^[a-z]:$/i.test(file[0]);
|
|
1642
|
+
const fileUNC = !fileDrive && file[0] === "" && file[1] === "" && file[2] === "?" && /^[a-z]:$/i.test(file[3]);
|
|
1643
|
+
const patternDrive = typeof pattern[0] === "string" && /^[a-z]:$/i.test(pattern[0]);
|
|
1644
|
+
const patternUNC = !patternDrive && pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
|
|
1645
|
+
const fdi = fileUNC ? 3 : fileDrive ? 0 : void 0;
|
|
1646
|
+
const pdi = patternUNC ? 3 : patternDrive ? 0 : void 0;
|
|
1647
|
+
if (typeof fdi === "number" && typeof pdi === "number") {
|
|
1648
|
+
const [fd, pd] = [
|
|
1649
|
+
file[fdi],
|
|
1650
|
+
pattern[pdi]
|
|
1651
|
+
];
|
|
1652
|
+
if (fd.toLowerCase() === pd.toLowerCase()) {
|
|
1653
|
+
pattern[pdi] = fd;
|
|
1654
|
+
patternStartIndex = pdi;
|
|
1655
|
+
fileStartIndex = fdi;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
const { optimizationLevel = 1 } = this.options;
|
|
1660
|
+
if (optimizationLevel >= 2) {
|
|
1661
|
+
file = this.levelTwoFileOptimize(file);
|
|
1662
|
+
}
|
|
1663
|
+
if (pattern.includes(GLOBSTAR)) {
|
|
1664
|
+
return this.#matchGlobstar(file, pattern, partial, fileStartIndex, patternStartIndex);
|
|
1665
|
+
}
|
|
1666
|
+
return this.#matchOne(file, pattern, partial, fileStartIndex, patternStartIndex);
|
|
1667
|
+
}
|
|
1668
|
+
#matchGlobstar(file, pattern, partial, fileIndex, patternIndex) {
|
|
1669
|
+
const firstgs = pattern.indexOf(GLOBSTAR, patternIndex);
|
|
1670
|
+
const lastgs = pattern.lastIndexOf(GLOBSTAR);
|
|
1671
|
+
const [head, body, tail] = partial ? [
|
|
1672
|
+
pattern.slice(patternIndex, firstgs),
|
|
1673
|
+
pattern.slice(firstgs + 1),
|
|
1674
|
+
[]
|
|
1675
|
+
] : [
|
|
1676
|
+
pattern.slice(patternIndex, firstgs),
|
|
1677
|
+
pattern.slice(firstgs + 1, lastgs),
|
|
1678
|
+
pattern.slice(lastgs + 1)
|
|
1679
|
+
];
|
|
1680
|
+
if (head.length) {
|
|
1681
|
+
const fileHead = file.slice(fileIndex, fileIndex + head.length);
|
|
1682
|
+
if (!this.#matchOne(fileHead, head, partial, 0, 0)) {
|
|
1683
|
+
return false;
|
|
1684
|
+
}
|
|
1685
|
+
fileIndex += head.length;
|
|
1686
|
+
patternIndex += head.length;
|
|
1687
|
+
}
|
|
1688
|
+
let fileTailMatch = 0;
|
|
1689
|
+
if (tail.length) {
|
|
1690
|
+
if (tail.length + fileIndex > file.length)
|
|
1691
|
+
return false;
|
|
1692
|
+
let tailStart = file.length - tail.length;
|
|
1693
|
+
if (this.#matchOne(file, tail, partial, tailStart, 0)) {
|
|
1694
|
+
fileTailMatch = tail.length;
|
|
1695
|
+
} else {
|
|
1696
|
+
if (file[file.length - 1] !== "" || fileIndex + tail.length === file.length) {
|
|
1697
|
+
return false;
|
|
1698
|
+
}
|
|
1699
|
+
tailStart--;
|
|
1700
|
+
if (!this.#matchOne(file, tail, partial, tailStart, 0)) {
|
|
1701
|
+
return false;
|
|
1702
|
+
}
|
|
1703
|
+
fileTailMatch = tail.length + 1;
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
if (!body.length) {
|
|
1707
|
+
let sawSome = !!fileTailMatch;
|
|
1708
|
+
for (let i2 = fileIndex; i2 < file.length - fileTailMatch; i2++) {
|
|
1709
|
+
const f = String(file[i2]);
|
|
1710
|
+
sawSome = true;
|
|
1711
|
+
if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) {
|
|
1712
|
+
return false;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
return partial || sawSome;
|
|
1716
|
+
}
|
|
1717
|
+
const bodySegments = [[[], 0]];
|
|
1718
|
+
let currentBody = bodySegments[0];
|
|
1719
|
+
let nonGsParts = 0;
|
|
1720
|
+
const nonGsPartsSums = [0];
|
|
1721
|
+
for (const b of body) {
|
|
1722
|
+
if (b === GLOBSTAR) {
|
|
1723
|
+
nonGsPartsSums.push(nonGsParts);
|
|
1724
|
+
currentBody = [[], 0];
|
|
1725
|
+
bodySegments.push(currentBody);
|
|
1726
|
+
} else {
|
|
1727
|
+
currentBody[0].push(b);
|
|
1728
|
+
nonGsParts++;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
let i = bodySegments.length - 1;
|
|
1732
|
+
const fileLength = file.length - fileTailMatch;
|
|
1733
|
+
for (const b of bodySegments) {
|
|
1734
|
+
b[1] = fileLength - (nonGsPartsSums[i--] + b[0].length);
|
|
1735
|
+
}
|
|
1736
|
+
return !!this.#matchGlobStarBodySections(file, bodySegments, fileIndex, 0, partial, 0, !!fileTailMatch);
|
|
1737
|
+
}
|
|
1738
|
+
// return false for "nope, not matching"
|
|
1739
|
+
// return null for "not matching, cannot keep trying"
|
|
1740
|
+
#matchGlobStarBodySections(file, bodySegments, fileIndex, bodyIndex, partial, globStarDepth, sawTail) {
|
|
1741
|
+
const bs = bodySegments[bodyIndex];
|
|
1742
|
+
if (!bs) {
|
|
1743
|
+
for (let i = fileIndex; i < file.length; i++) {
|
|
1744
|
+
sawTail = true;
|
|
1745
|
+
const f = file[i];
|
|
1746
|
+
if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) {
|
|
1747
|
+
return false;
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
return sawTail;
|
|
1751
|
+
}
|
|
1752
|
+
const [body, after] = bs;
|
|
1753
|
+
while (fileIndex <= after) {
|
|
1754
|
+
const m = this.#matchOne(file.slice(0, fileIndex + body.length), body, partial, fileIndex, 0);
|
|
1755
|
+
if (m && globStarDepth < this.maxGlobstarRecursion) {
|
|
1756
|
+
const sub = this.#matchGlobStarBodySections(file, bodySegments, fileIndex + body.length, bodyIndex + 1, partial, globStarDepth + 1, sawTail);
|
|
1757
|
+
if (sub !== false) {
|
|
1758
|
+
return sub;
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
const f = file[fileIndex];
|
|
1762
|
+
if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) {
|
|
1763
|
+
return false;
|
|
1764
|
+
}
|
|
1765
|
+
fileIndex++;
|
|
1766
|
+
}
|
|
1767
|
+
return partial || null;
|
|
1768
|
+
}
|
|
1769
|
+
#matchOne(file, pattern, partial, fileIndex, patternIndex) {
|
|
1770
|
+
let fi;
|
|
1771
|
+
let pi;
|
|
1772
|
+
let pl;
|
|
1773
|
+
let fl;
|
|
1774
|
+
for (fi = fileIndex, pi = patternIndex, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
|
|
1775
|
+
this.debug("matchOne loop");
|
|
1776
|
+
let p = pattern[pi];
|
|
1777
|
+
let f = file[fi];
|
|
1778
|
+
this.debug(pattern, p, f);
|
|
1779
|
+
if (p === false || p === GLOBSTAR) {
|
|
1780
|
+
return false;
|
|
1781
|
+
}
|
|
1782
|
+
let hit;
|
|
1783
|
+
if (typeof p === "string") {
|
|
1784
|
+
hit = f === p;
|
|
1785
|
+
this.debug("string match", p, f, hit);
|
|
1786
|
+
} else {
|
|
1787
|
+
hit = p.test(f);
|
|
1788
|
+
this.debug("pattern match", p, f, hit);
|
|
1789
|
+
}
|
|
1790
|
+
if (!hit)
|
|
1791
|
+
return false;
|
|
1792
|
+
}
|
|
1793
|
+
if (fi === fl && pi === pl) {
|
|
1794
|
+
return true;
|
|
1795
|
+
} else if (fi === fl) {
|
|
1796
|
+
return partial;
|
|
1797
|
+
} else if (pi === pl) {
|
|
1798
|
+
return fi === fl - 1 && file[fi] === "";
|
|
1799
|
+
} else {
|
|
1800
|
+
throw new Error("wtf?");
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
braceExpand() {
|
|
1804
|
+
return braceExpand(this.pattern, this.options);
|
|
1805
|
+
}
|
|
1806
|
+
parse(pattern) {
|
|
1807
|
+
assertValidPattern(pattern);
|
|
1808
|
+
const options = this.options;
|
|
1809
|
+
if (pattern === "**")
|
|
1810
|
+
return GLOBSTAR;
|
|
1811
|
+
if (pattern === "")
|
|
1812
|
+
return "";
|
|
1813
|
+
let m;
|
|
1814
|
+
let fastTest = null;
|
|
1815
|
+
if (m = pattern.match(starRE)) {
|
|
1816
|
+
fastTest = options.dot ? starTestDot : starTest;
|
|
1817
|
+
} else if (m = pattern.match(starDotExtRE)) {
|
|
1818
|
+
fastTest = (options.nocase ? options.dot ? starDotExtTestNocaseDot : starDotExtTestNocase : options.dot ? starDotExtTestDot : starDotExtTest)(m[1]);
|
|
1819
|
+
} else if (m = pattern.match(qmarksRE)) {
|
|
1820
|
+
fastTest = (options.nocase ? options.dot ? qmarksTestNocaseDot : qmarksTestNocase : options.dot ? qmarksTestDot : qmarksTest)(m);
|
|
1821
|
+
} else if (m = pattern.match(starDotStarRE)) {
|
|
1822
|
+
fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
|
|
1823
|
+
} else if (m = pattern.match(dotStarRE)) {
|
|
1824
|
+
fastTest = dotStarTest;
|
|
1825
|
+
}
|
|
1826
|
+
const re = AST.fromGlob(pattern, this.options).toMMPattern();
|
|
1827
|
+
if (fastTest && typeof re === "object") {
|
|
1828
|
+
Reflect.defineProperty(re, "test", { value: fastTest });
|
|
1829
|
+
}
|
|
1830
|
+
return re;
|
|
1831
|
+
}
|
|
1832
|
+
makeRe() {
|
|
1833
|
+
if (this.regexp || this.regexp === false)
|
|
1834
|
+
return this.regexp;
|
|
1835
|
+
const set = this.set;
|
|
1836
|
+
if (!set.length) {
|
|
1837
|
+
this.regexp = false;
|
|
1838
|
+
return this.regexp;
|
|
1839
|
+
}
|
|
1840
|
+
const options = this.options;
|
|
1841
|
+
const twoStar = options.noglobstar ? star2 : options.dot ? twoStarDot : twoStarNoDot;
|
|
1842
|
+
const flags = new Set(options.nocase ? ["i"] : []);
|
|
1843
|
+
let re = set.map((pattern) => {
|
|
1844
|
+
const pp = pattern.map((p) => {
|
|
1845
|
+
if (p instanceof RegExp) {
|
|
1846
|
+
for (const f of p.flags.split(""))
|
|
1847
|
+
flags.add(f);
|
|
1848
|
+
}
|
|
1849
|
+
return typeof p === "string" ? regExpEscape2(p) : p === GLOBSTAR ? GLOBSTAR : p._src;
|
|
1850
|
+
});
|
|
1851
|
+
pp.forEach((p, i) => {
|
|
1852
|
+
const next = pp[i + 1];
|
|
1853
|
+
const prev = pp[i - 1];
|
|
1854
|
+
if (p !== GLOBSTAR || prev === GLOBSTAR) {
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
if (prev === void 0) {
|
|
1858
|
+
if (next !== void 0 && next !== GLOBSTAR) {
|
|
1859
|
+
pp[i + 1] = "(?:\\/|" + twoStar + "\\/)?" + next;
|
|
1860
|
+
} else {
|
|
1861
|
+
pp[i] = twoStar;
|
|
1862
|
+
}
|
|
1863
|
+
} else if (next === void 0) {
|
|
1864
|
+
pp[i - 1] = prev + "(?:\\/|\\/" + twoStar + ")?";
|
|
1865
|
+
} else if (next !== GLOBSTAR) {
|
|
1866
|
+
pp[i - 1] = prev + "(?:\\/|\\/" + twoStar + "\\/)" + next;
|
|
1867
|
+
pp[i + 1] = GLOBSTAR;
|
|
1868
|
+
}
|
|
1869
|
+
});
|
|
1870
|
+
const filtered = pp.filter((p) => p !== GLOBSTAR);
|
|
1871
|
+
if (this.partial && filtered.length >= 1) {
|
|
1872
|
+
const prefixes = [];
|
|
1873
|
+
for (let i = 1; i <= filtered.length; i++) {
|
|
1874
|
+
prefixes.push(filtered.slice(0, i).join("/"));
|
|
1875
|
+
}
|
|
1876
|
+
return "(?:" + prefixes.join("|") + ")";
|
|
1877
|
+
}
|
|
1878
|
+
return filtered.join("/");
|
|
1879
|
+
}).join("|");
|
|
1880
|
+
const [open, close] = set.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
1881
|
+
re = "^" + open + re + close + "$";
|
|
1882
|
+
if (this.partial) {
|
|
1883
|
+
re = "^(?:\\/|" + open + re.slice(1, -1) + close + ")$";
|
|
1884
|
+
}
|
|
1885
|
+
if (this.negate)
|
|
1886
|
+
re = "^(?!" + re + ").+$";
|
|
1887
|
+
try {
|
|
1888
|
+
this.regexp = new RegExp(re, [...flags].join(""));
|
|
1889
|
+
} catch {
|
|
1890
|
+
this.regexp = false;
|
|
1891
|
+
}
|
|
1892
|
+
return this.regexp;
|
|
1893
|
+
}
|
|
1894
|
+
slashSplit(p) {
|
|
1895
|
+
if (this.preserveMultipleSlashes) {
|
|
1896
|
+
return p.split("/");
|
|
1897
|
+
} else if (this.isWindows && /^\/\/[^/]+/.test(p)) {
|
|
1898
|
+
return ["", ...p.split(/\/+/)];
|
|
1899
|
+
} else {
|
|
1900
|
+
return p.split(/\/+/);
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
match(f, partial = this.partial) {
|
|
1904
|
+
this.debug("match", f, this.pattern);
|
|
1905
|
+
if (this.comment) {
|
|
1906
|
+
return false;
|
|
1907
|
+
}
|
|
1908
|
+
if (this.empty) {
|
|
1909
|
+
return f === "";
|
|
1910
|
+
}
|
|
1911
|
+
if (f === "/" && partial) {
|
|
1912
|
+
return true;
|
|
1913
|
+
}
|
|
1914
|
+
const options = this.options;
|
|
1915
|
+
if (this.isWindows) {
|
|
1916
|
+
f = f.split("\\").join("/");
|
|
1917
|
+
}
|
|
1918
|
+
const ff = this.slashSplit(f);
|
|
1919
|
+
this.debug(this.pattern, "split", ff);
|
|
1920
|
+
const set = this.set;
|
|
1921
|
+
this.debug(this.pattern, "set", set);
|
|
1922
|
+
let filename = ff[ff.length - 1];
|
|
1923
|
+
if (!filename) {
|
|
1924
|
+
for (let i = ff.length - 2; !filename && i >= 0; i--) {
|
|
1925
|
+
filename = ff[i];
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
for (const pattern of set) {
|
|
1929
|
+
let file = ff;
|
|
1930
|
+
if (options.matchBase && pattern.length === 1) {
|
|
1931
|
+
file = [filename];
|
|
1932
|
+
}
|
|
1933
|
+
const hit = this.matchOne(file, pattern, partial);
|
|
1934
|
+
if (hit) {
|
|
1935
|
+
if (options.flipNegate) {
|
|
1936
|
+
return true;
|
|
1937
|
+
}
|
|
1938
|
+
return !this.negate;
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
if (options.flipNegate) {
|
|
1942
|
+
return false;
|
|
1943
|
+
}
|
|
1944
|
+
return this.negate;
|
|
1945
|
+
}
|
|
1946
|
+
static defaults(def) {
|
|
1947
|
+
return minimatch.defaults(def).Minimatch;
|
|
1948
|
+
}
|
|
1949
|
+
};
|
|
1950
|
+
minimatch.AST = AST;
|
|
1951
|
+
minimatch.Minimatch = Minimatch;
|
|
1952
|
+
minimatch.escape = escape;
|
|
1953
|
+
minimatch.unescape = unescape;
|
|
1954
|
+
|
|
1955
|
+
// src/work-proofs-tests.ts
|
|
1956
|
+
var ID_CHARACTER = "A-Za-z0-9_-";
|
|
1957
|
+
function escapeRegExp(text) {
|
|
1958
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1959
|
+
}
|
|
1960
|
+
function containsId(text, id) {
|
|
1961
|
+
return new RegExp(`(?<![${ID_CHARACTER}])${escapeRegExp(id)}(?![${ID_CHARACTER}])`).test(text);
|
|
1962
|
+
}
|
|
1963
|
+
function runnerFor(path2, runners) {
|
|
1964
|
+
const index = runners.findIndex((runner) => minimatch(path2, runner.files, { dot: true }));
|
|
1965
|
+
return index === -1 ? void 0 : index;
|
|
1966
|
+
}
|
|
1967
|
+
function planRuns(files, runners) {
|
|
1968
|
+
const plan = /* @__PURE__ */ new Map();
|
|
1969
|
+
for (const file of [...files].sort()) {
|
|
1970
|
+
const index = runnerFor(file, runners);
|
|
1971
|
+
if (index === void 0) continue;
|
|
1972
|
+
plan.set(index, [...plan.get(index) ?? [], file]);
|
|
1973
|
+
}
|
|
1974
|
+
return new Map([...plan].sort(([a], [b]) => a - b));
|
|
1975
|
+
}
|
|
1976
|
+
function shellQuote(text) {
|
|
1977
|
+
const path2 = text.startsWith("-") ? `./${text}` : text;
|
|
1978
|
+
if (/^[A-Za-z0-9_@%+=:,./-]+$/.test(path2)) return path2;
|
|
1979
|
+
return `'${path2.replace(/'/g, `'\\''`)}'`;
|
|
1980
|
+
}
|
|
1981
|
+
function fillFiles(command, files) {
|
|
1982
|
+
const quoted = files.map(shellQuote).join(" ");
|
|
1983
|
+
return command.split("{files}").join(quoted);
|
|
1984
|
+
}
|
|
1985
|
+
function proofFileCriterion(name, declared) {
|
|
1986
|
+
const dot = name.lastIndexOf(".");
|
|
1987
|
+
if (dot <= 0) return void 0;
|
|
1988
|
+
const stem = name.slice(0, dot);
|
|
1989
|
+
return declared.has(stem) ? stem : void 0;
|
|
1990
|
+
}
|
|
1991
|
+
function git(root, args, accepted = [0]) {
|
|
1992
|
+
const result = spawnSync("git", args, { cwd: root, encoding: "utf8", maxBuffer: 268435456 });
|
|
1993
|
+
if (result.error !== void 0 || !accepted.includes(result.status)) {
|
|
1994
|
+
throw new WorkCommandError(`git ${args[0]} failed (${result.error?.message ?? `exit status ${result.status}`}), so the tests that name a proof cannot be found.`);
|
|
1995
|
+
}
|
|
1996
|
+
return result.stdout;
|
|
1997
|
+
}
|
|
1998
|
+
function discoverTestFiles(root, ids, runners) {
|
|
1999
|
+
const found = /* @__PURE__ */ new Map();
|
|
2000
|
+
if (ids.length === 0 || runners.length === 0) return found;
|
|
2001
|
+
const grep = git(root, ["grep", "-z", "-l", "-I", "-F", ...ids.flatMap((id) => ["-e", id]), "HEAD", "--"], [0, 1]);
|
|
2002
|
+
const paths = grep.split("\0").filter((entry) => entry !== "").map((entry) => entry.slice("HEAD:".length)).filter((path2) => runnerFor(path2, runners) !== void 0).sort();
|
|
2003
|
+
for (const path2 of paths) {
|
|
2004
|
+
const shown = git(root, ["show", `HEAD:${path2}`]);
|
|
2005
|
+
for (const id of ids) {
|
|
2006
|
+
if (containsId(shown, id)) found.set(id, [...found.get(id) ?? [], path2]);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
return found;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
// src/work-proofs-record.ts
|
|
2013
|
+
var CONFIG_FILE = ".outerlayer-proofs.yaml";
|
|
2014
|
+
var DEFAULT_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
2015
|
+
var DEMO_PROOFS = /* @__PURE__ */ new Set(["screenshot", "video"]);
|
|
2016
|
+
var NO_TEST = "no test at HEAD names this criterion";
|
|
2017
|
+
function changedTrackedFiles(root) {
|
|
2018
|
+
const status = spawnSync("git", ["status", "--porcelain=v1", "-z", "--untracked-files=no"], { cwd: root, encoding: "utf8", maxBuffer: 16 * 1024 * 1024 });
|
|
2019
|
+
if (status.error !== void 0 || status.status !== 0) {
|
|
2020
|
+
throw new WorkCommandError(`git cannot say whether the working copy matches HEAD (${status.error?.message ?? `exit status ${status.status}`}), so nothing was recorded.`);
|
|
2021
|
+
}
|
|
2022
|
+
const fields = status.stdout.split("\0").filter((field) => field !== "");
|
|
2023
|
+
const paths = [];
|
|
2024
|
+
for (let i = 0; i < fields.length; i += 1) {
|
|
2025
|
+
const field = fields[i];
|
|
2026
|
+
paths.push(field.slice(3));
|
|
2027
|
+
if (/[RC]/.test(field.slice(0, 2))) i += 1;
|
|
2028
|
+
}
|
|
2029
|
+
return paths;
|
|
2030
|
+
}
|
|
2031
|
+
function topLevelFiles(folder) {
|
|
2032
|
+
try {
|
|
2033
|
+
return readdirSync(folder, { withFileTypes: true }).filter((entry) => entry.isFile()).map((entry) => entry.name).sort();
|
|
2034
|
+
} catch {
|
|
2035
|
+
return [];
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
function chapterCriteria(manifestPath) {
|
|
2039
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2040
|
+
try {
|
|
2041
|
+
const parsed = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
2042
|
+
for (const chapter of parsed.chapters ?? []) {
|
|
2043
|
+
if (typeof chapter?.criterionId === "string") ids.add(chapter.criterionId);
|
|
2044
|
+
}
|
|
2045
|
+
} catch {
|
|
2046
|
+
}
|
|
2047
|
+
return ids;
|
|
2048
|
+
}
|
|
2049
|
+
function showAtHead(root, path2) {
|
|
2050
|
+
const shown = spawnSync("git", ["show", `HEAD:${path2}`], { cwd: root, encoding: "utf8", maxBuffer: 16 * 1024 * 1024 });
|
|
2051
|
+
return shown.status === 0 ? shown.stdout : void 0;
|
|
2052
|
+
}
|
|
2053
|
+
function findManifests(folder) {
|
|
2054
|
+
const found = [];
|
|
2055
|
+
let entries = [];
|
|
2056
|
+
try {
|
|
2057
|
+
entries = readdirSync(folder, { withFileTypes: true });
|
|
2058
|
+
} catch {
|
|
2059
|
+
}
|
|
2060
|
+
for (const entry of entries) {
|
|
2061
|
+
const path2 = join(folder, entry.name);
|
|
2062
|
+
if (entry.isDirectory()) found.push(...findManifests(path2));
|
|
2063
|
+
else if (entry.name === "manifest.json" && folder.split("/").pop() === "demo") found.push(path2);
|
|
2064
|
+
}
|
|
2065
|
+
return found;
|
|
2066
|
+
}
|
|
2067
|
+
function unstoredUploads(result, spooled) {
|
|
2068
|
+
if (typeof result !== "object" || result === null) return [];
|
|
2069
|
+
const { artifactsDropped, artifactsHeld, rejected, uploadedArtifacts } = result;
|
|
2070
|
+
if (Array.isArray(uploadedArtifacts)) {
|
|
2071
|
+
const stored = new Set(uploadedArtifacts.map((a) => a?.artifactId));
|
|
2072
|
+
return spooled.filter((id) => !stored.has(id));
|
|
2073
|
+
}
|
|
2074
|
+
const lost = typeof artifactsDropped === "number" && artifactsDropped > 0 || typeof artifactsHeld === "number" && artifactsHeld > 0 || Array.isArray(rejected) && rejected.length > 0;
|
|
2075
|
+
return lost ? "all" : [];
|
|
2076
|
+
}
|
|
2077
|
+
function shortSha(sha) {
|
|
2078
|
+
return sha.slice(0, 7);
|
|
2079
|
+
}
|
|
2080
|
+
function oneLine(text) {
|
|
2081
|
+
return text.replace(/\s+/g, " ").trim();
|
|
2082
|
+
}
|
|
2083
|
+
async function runWorkProofsRecord(opts) {
|
|
2084
|
+
const env = opts.env ?? process.env;
|
|
2085
|
+
const item = resolveProofsItem({ item: opts.item, env });
|
|
2086
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
2087
|
+
const identity = resolveRepoIdentity(cwd);
|
|
2088
|
+
if (identity.repoRoot === void 0 || identity.commitSha === void 0) {
|
|
2089
|
+
throw new WorkCommandError("this is not a git checkout with a commit. Run this inside the repository, after the tests are committed.");
|
|
2090
|
+
}
|
|
2091
|
+
const { repoRoot: root, commitSha: head } = identity;
|
|
2092
|
+
const changed = changedTrackedFiles(root);
|
|
2093
|
+
if (changed.length > 0) {
|
|
2094
|
+
throw new WorkCommandError(
|
|
2095
|
+
`the working copy differs from HEAD in ${changed.join(", ")}. Only the committed files run, so nothing was recorded. Commit or discard the change, then record again.`
|
|
2096
|
+
);
|
|
2097
|
+
}
|
|
2098
|
+
const fetchImpl = opts.fetchImpl ?? defaultFetch;
|
|
2099
|
+
const creds = resolveCredentials({ ...opts, env });
|
|
2100
|
+
const home = opts.home;
|
|
2101
|
+
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
2102
|
+
const lines = [];
|
|
2103
|
+
const say = (line) => void lines.push(line);
|
|
2104
|
+
const { data } = await getJson(creds.url, `/v1/work-items/${item}`, creds.apiKey, creds.appId, fetchImpl);
|
|
2105
|
+
const body = data;
|
|
2106
|
+
const own = ownPullRequest(body.pullRequests ?? [], opts.pr, identity.gitRepo);
|
|
2107
|
+
if ("ambiguous" in own) {
|
|
2108
|
+
throw new WorkCommandError(`the item links several open pull requests (${own.ambiguous.map((n) => `#${n}`).join(", ")}). Pass --pr <number> to name this checkout's.`);
|
|
2109
|
+
}
|
|
2110
|
+
const ownPr = own.pr;
|
|
2111
|
+
const postGeneral = async (text, clientCommentId) => {
|
|
2112
|
+
try {
|
|
2113
|
+
await runWorkComment({ ...creds, item, body: text, clientCommentId, cwd, home, env, fetchImpl, quiet: true });
|
|
2114
|
+
} catch (err) {
|
|
2115
|
+
if (!(err instanceof WorkCommandError && err.code === "comment_conflict")) {
|
|
2116
|
+
say(`The comment on the item's thread was not posted: ${oneLine(String(err instanceof Error ? err.message : err))}`);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
};
|
|
2120
|
+
const configText = showAtHead(root, CONFIG_FILE);
|
|
2121
|
+
const parsed = configText === void 0 ? void 0 : parseProofsConfig(configText);
|
|
2122
|
+
if (parsed === void 0 || !parsed.ok) {
|
|
2123
|
+
const problem = parsed === void 0 ? `${CONFIG_FILE} is missing at HEAD. Commit it at the repository root, with the setup, teardown and runners that run the tests.` : `${CONFIG_FILE} cannot be read: ${parsed.problems.join("; ")}`;
|
|
2124
|
+
if (opts.comment) {
|
|
2125
|
+
const text = `No proof was recorded at ${shortSha(head)}. ${problem}`.slice(0, 2e3);
|
|
2126
|
+
await postGeneral(text, proofsCommentId(item, head, [{ id: CONFIG_FILE, proof: "setup file", reason: problem }]));
|
|
2127
|
+
}
|
|
2128
|
+
throw new WorkCommandError(problem);
|
|
2129
|
+
}
|
|
2130
|
+
const config = parsed.value;
|
|
2131
|
+
const heads = /* @__PURE__ */ new Set([head.toLowerCase(), ...otherPullRequestHeads(body.pullRequests ?? [], ownPr, identity.gitRepo)]);
|
|
2132
|
+
const states = classifyProofsAt(body, heads);
|
|
2133
|
+
const todo = states.filter((state) => state.state !== "current").map((state) => state.id);
|
|
2134
|
+
const declared = new Map((body.criteria?.items ?? []).map((criterion) => [criterion.id, criterion]));
|
|
2135
|
+
const proofOf = (id) => declared.get(id).proof;
|
|
2136
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
2137
|
+
const emitted = /* @__PURE__ */ new Map();
|
|
2138
|
+
const found = discoverTestFiles(root, todo, config.runners);
|
|
2139
|
+
for (const id of todo) {
|
|
2140
|
+
if (!found.has(id)) reasons.set(id, NO_TEST);
|
|
2141
|
+
}
|
|
2142
|
+
const plan = planRuns([...new Set([...found.values()].flat())], config.runners);
|
|
2143
|
+
const logDir = mkdtempSync(join(tmpdir(), "outerlayer-proofs-"));
|
|
2144
|
+
const proofOuts = [];
|
|
2145
|
+
const groups = [];
|
|
2146
|
+
const runCommand = opts.runCommand ?? runShell;
|
|
2147
|
+
const baseEnv = { ...process.env, ...env };
|
|
2148
|
+
delete baseEnv.OUTERLAYER_PROOF_OUT;
|
|
2149
|
+
let spooledCount = 0;
|
|
2150
|
+
const spooledCriteria = /* @__PURE__ */ new Set();
|
|
2151
|
+
const emitArtifact = async (emitOpts) => {
|
|
2152
|
+
const result = await (opts.emitArtifact ?? runEmitArtifact)(emitOpts);
|
|
2153
|
+
if (result.spooled) spooledCount += 1;
|
|
2154
|
+
return result;
|
|
2155
|
+
};
|
|
2156
|
+
const common = { url: creds.url, apiKey: creds.apiKey, appId: creds.appId, cwd: root, home, env, fetchImpl, quiet: true };
|
|
2157
|
+
const stopGroups = () => {
|
|
2158
|
+
for (const pid of groups) {
|
|
2159
|
+
try {
|
|
2160
|
+
process.kill(-pid, "SIGTERM");
|
|
2161
|
+
} catch {
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
};
|
|
2165
|
+
const cleanUp = () => {
|
|
2166
|
+
rmSync(logDir, { recursive: true, force: true });
|
|
2167
|
+
for (const folder of proofOuts) rmSync(folder, { recursive: true, force: true });
|
|
2168
|
+
};
|
|
2169
|
+
const onSignal = (signal) => {
|
|
2170
|
+
stopGroups();
|
|
2171
|
+
cleanUp();
|
|
2172
|
+
process.exit(signal === "SIGINT" ? 130 : 143);
|
|
2173
|
+
};
|
|
2174
|
+
const onInterrupt = () => onSignal("SIGINT");
|
|
2175
|
+
const onTerminate = () => onSignal("SIGTERM");
|
|
2176
|
+
process.once("SIGINT", onInterrupt);
|
|
2177
|
+
process.once("SIGTERM", onTerminate);
|
|
2178
|
+
const runs = [];
|
|
2179
|
+
try {
|
|
2180
|
+
let setupStarted = false;
|
|
2181
|
+
try {
|
|
2182
|
+
let setupFailed;
|
|
2183
|
+
if (plan.size > 0) {
|
|
2184
|
+
setupStarted = true;
|
|
2185
|
+
for (const command of config.setup) {
|
|
2186
|
+
const result = await runCommand(command, { cwd: root, env: baseEnv, timeoutMs, logDir, groups });
|
|
2187
|
+
if (result.status !== 0) {
|
|
2188
|
+
setupFailed = `setup failed: "${oneLine(command)}" ${result.timedOut ? `timed out after ${Math.round(timeoutMs / 1e3)} s` : `exited with status ${result.status}`}`;
|
|
2189
|
+
say(setupFailed);
|
|
2190
|
+
if (result.tail !== "") say(result.tail);
|
|
2191
|
+
break;
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
for (const [index, files] of plan) {
|
|
2196
|
+
const runner = config.runners[index];
|
|
2197
|
+
const criteria = todo.filter((id) => found.get(id)?.some((file) => files.includes(file)));
|
|
2198
|
+
if (setupFailed !== void 0) {
|
|
2199
|
+
for (const id of criteria) reasons.set(id, setupFailed);
|
|
2200
|
+
continue;
|
|
2201
|
+
}
|
|
2202
|
+
const proofOut = mkdtempSync(join(tmpdir(), "outerlayer-proof-out-"));
|
|
2203
|
+
proofOuts.push(proofOut);
|
|
2204
|
+
const result = await runCommand(fillFiles(runner.command, files), { cwd: root, env: { ...baseEnv, OUTERLAYER_PROOF_OUT: proofOut }, timeoutMs, logDir, groups });
|
|
2205
|
+
const failure = result.timedOut ? `the runner for ${runner.files} timed out after ${Math.round(timeoutMs / 1e3)} s` : result.status === 0 ? void 0 : `the runner for ${runner.files} exited with status ${result.status}`;
|
|
2206
|
+
if (failure !== void 0) {
|
|
2207
|
+
say(failure);
|
|
2208
|
+
if (result.tail !== "") say(result.tail);
|
|
2209
|
+
}
|
|
2210
|
+
runs.push({ glob: runner.files, proofOut, criteria, failure, tail: result.tail });
|
|
2211
|
+
}
|
|
2212
|
+
} finally {
|
|
2213
|
+
if (setupStarted) {
|
|
2214
|
+
for (const command of config.teardown) {
|
|
2215
|
+
const result = await runCommand(command, { cwd: root, env: baseEnv, timeoutMs, logDir, groups });
|
|
2216
|
+
if (result.status !== 0) say(`teardown failed: "${oneLine(command)}" ${result.timedOut ? "timed out" : `exited with status ${result.status}`}`);
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
process.off("SIGINT", onInterrupt);
|
|
2220
|
+
process.off("SIGTERM", onTerminate);
|
|
2221
|
+
stopGroups();
|
|
2222
|
+
}
|
|
2223
|
+
if (plan.size > 0) {
|
|
2224
|
+
let left = [];
|
|
2225
|
+
try {
|
|
2226
|
+
left = changedTrackedFiles(root);
|
|
2227
|
+
} catch {
|
|
2228
|
+
}
|
|
2229
|
+
if (left.length > 0) {
|
|
2230
|
+
say(`The run changed tracked files: ${left.join(", ")}. The next --record records nothing until they match HEAD. Make setup, the tests and teardown leave them unchanged.`);
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
await emitProofs();
|
|
2234
|
+
} finally {
|
|
2235
|
+
cleanUp();
|
|
2236
|
+
}
|
|
2237
|
+
async function emitProofs() {
|
|
2238
|
+
const notCurrent2 = new Set(todo);
|
|
2239
|
+
const manifests = runs.flatMap((run) => findManifests(run.proofOut));
|
|
2240
|
+
const chapters = /* @__PURE__ */ new Set();
|
|
2241
|
+
if (manifests.length > 1) {
|
|
2242
|
+
say(`Not recorded, the demo: the runners left ${manifests.length} demo manifests, so it is unclear which to store`);
|
|
2243
|
+
} else if (manifests.length === 1) {
|
|
2244
|
+
for (const id of chapterCriteria(manifests[0])) chapters.add(id);
|
|
2245
|
+
await recordDemo(manifests[0], chapters);
|
|
2246
|
+
}
|
|
2247
|
+
for (const run of runs) {
|
|
2248
|
+
const names = topLevelFiles(run.proofOut);
|
|
2249
|
+
for (const name of names) {
|
|
2250
|
+
const id = proofFileCriterion(name, new Set(declared.keys()));
|
|
2251
|
+
if (id === void 0) {
|
|
2252
|
+
say(`Ignored ${name}: its name is not the id of a declared criterion.`);
|
|
2253
|
+
continue;
|
|
2254
|
+
}
|
|
2255
|
+
if (!notCurrent2.has(id)) {
|
|
2256
|
+
say(`Ignored ${name}: the proof for ${id} is current, or no proof is declared for it.`);
|
|
2257
|
+
continue;
|
|
2258
|
+
}
|
|
2259
|
+
if (DEMO_PROOFS.has(proofOf(id)) && chapters.has(id)) {
|
|
2260
|
+
say(`Ignored ${name}: a demo chapter proves ${id}.`);
|
|
2261
|
+
continue;
|
|
2262
|
+
}
|
|
2263
|
+
if (emitted.has(id)) continue;
|
|
2264
|
+
const fail = (reason) => {
|
|
2265
|
+
reasons.set(id, reason);
|
|
2266
|
+
say(`Not recorded, ${id}: ${reason}`);
|
|
2267
|
+
};
|
|
2268
|
+
if (run.failure !== void 0) {
|
|
2269
|
+
fail(`${run.failure}, so its files are not recorded`);
|
|
2270
|
+
continue;
|
|
2271
|
+
}
|
|
2272
|
+
const problem = kindProblem(proofOf(id), name);
|
|
2273
|
+
if (problem !== void 0) {
|
|
2274
|
+
fail(problem);
|
|
2275
|
+
continue;
|
|
2276
|
+
}
|
|
2277
|
+
try {
|
|
2278
|
+
const caption = (declared.get(id).text ?? `Proof for ${id}`).slice(0, ARTIFACT_MAX_CAPTION_LENGTH);
|
|
2279
|
+
const before = spooledCount;
|
|
2280
|
+
const result = await emitArtifact({ ...common, file: join(run.proofOut, name), caption, criterionId: id, ...ownPr === void 0 ? {} : { pr: ownPr } });
|
|
2281
|
+
const artifactId = result.record?.artifactId ?? result.data?.clientArtifactId;
|
|
2282
|
+
if (artifactId === void 0) {
|
|
2283
|
+
fail("the upload returned no artifact id");
|
|
2284
|
+
continue;
|
|
2285
|
+
}
|
|
2286
|
+
emitted.set(id, artifactId);
|
|
2287
|
+
if (spooledCount > before) spooledCriteria.add(id);
|
|
2288
|
+
} catch (err) {
|
|
2289
|
+
fail(`the upload failed: ${oneLine(String(err instanceof Error ? err.message : err))}`);
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
for (const run of runs) {
|
|
2294
|
+
for (const id of run.criteria) {
|
|
2295
|
+
if (emitted.has(id) || reasons.has(id)) continue;
|
|
2296
|
+
reasons.set(id, run.failure ?? `the tests ran and wrote no ${id}.<ext> file under OUTERLAYER_PROOF_OUT`);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
async function recordDemo(manifest, chapters) {
|
|
2301
|
+
const demoCriteria = todo.filter((id) => DEMO_PROOFS.has(proofOf(id)));
|
|
2302
|
+
let replaces;
|
|
2303
|
+
try {
|
|
2304
|
+
replaces = (await readNewestDemo({ url: creds.url, apiKey: creds.apiKey, appId: creds.appId, item, fetchImpl }))?.artifactId;
|
|
2305
|
+
} catch (err) {
|
|
2306
|
+
replaces = void 0;
|
|
2307
|
+
say(`The previous demo could not be read, so the new demo does not replace it: ${oneLine(String(err instanceof Error ? err.message : err))}`);
|
|
2308
|
+
}
|
|
2309
|
+
const before = spooledCount;
|
|
2310
|
+
let result;
|
|
2311
|
+
try {
|
|
2312
|
+
result = await (opts.emitDemo ?? runEmitDemo)({
|
|
2313
|
+
...common,
|
|
2314
|
+
manifest,
|
|
2315
|
+
item,
|
|
2316
|
+
...ownPr === void 0 ? {} : { pr: ownPr },
|
|
2317
|
+
...replaces === void 0 ? {} : { replaces },
|
|
2318
|
+
emitArtifact
|
|
2319
|
+
});
|
|
2320
|
+
} catch (err) {
|
|
2321
|
+
const reason = `the demo was not stored: ${oneLine(String(err instanceof Error ? err.message : err))}`;
|
|
2322
|
+
for (const id of demoCriteria) reasons.set(id, reason);
|
|
2323
|
+
say(`Not recorded, the demo: ${reason}`);
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
for (const id of demoCriteria) {
|
|
2327
|
+
const artifactId = proofOf(id) === "screenshot" ? result.screenshots.find((shot) => shot.criterionId === id && shot.artifactId !== void 0)?.artifactId : result.clips.find((clip) => clip.criterionId === id && clip.bound)?.clipArtifactId;
|
|
2328
|
+
if (artifactId !== void 0) {
|
|
2329
|
+
emitted.set(id, artifactId);
|
|
2330
|
+
if (spooledCount > before) spooledCriteria.add(id);
|
|
2331
|
+
} else if (chapters.has(id)) {
|
|
2332
|
+
reasons.set(id, result.failures.length > 0 ? `the demo failed a check: ${oneLine(result.failures[0])}` : "the demo has no passing chapter for it");
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
for (const failure of result.failures) say(`Demo check failed: ${oneLine(failure)}`);
|
|
2336
|
+
}
|
|
2337
|
+
if (spooledCount > 0) {
|
|
2338
|
+
try {
|
|
2339
|
+
const synced = await (opts.sync ?? (() => runSync({ ...common })))();
|
|
2340
|
+
const unstored = unstoredUploads(
|
|
2341
|
+
synced,
|
|
2342
|
+
[...spooledCriteria].map((id) => emitted.get(id))
|
|
2343
|
+
);
|
|
2344
|
+
const lostIds = unstored === "all" ? [...spooledCriteria] : [...spooledCriteria].filter((id) => unstored.includes(emitted.get(id)));
|
|
2345
|
+
for (const id of lostIds) {
|
|
2346
|
+
emitted.delete(id);
|
|
2347
|
+
reasons.set(id, "the sync did not store the upload, so the proof is stored only in the session record");
|
|
2348
|
+
}
|
|
2349
|
+
if (lostIds.length > 0) say("The sync did not store an upload. The proofs that went through the session record are not stored.");
|
|
2350
|
+
} catch (err) {
|
|
2351
|
+
for (const id of spooledCriteria) {
|
|
2352
|
+
emitted.delete(id);
|
|
2353
|
+
reasons.set(id, "the sync failed, so the proof is stored only in the session record");
|
|
2354
|
+
}
|
|
2355
|
+
say(`The sync failed, so the new proofs are stored only in the session record: ${oneLine(String(err instanceof Error ? err.message : err))}`);
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
for (const [criterion, artifactId] of emitted) say(`Recorded ${criterion}: ${artifactId}`);
|
|
2359
|
+
let finalStates = states;
|
|
2360
|
+
try {
|
|
2361
|
+
const { data: fresh } = await getJson(creds.url, `/v1/work-items/${item}`, creds.apiKey, creds.appId, fetchImpl);
|
|
2362
|
+
finalStates = classifyProofsAt(fresh, heads);
|
|
2363
|
+
} catch (err) {
|
|
2364
|
+
say(`The item could not be read again, so the list below may be out of date: ${oneLine(String(err instanceof Error ? err.message : err))}`);
|
|
2365
|
+
}
|
|
2366
|
+
const notCurrent = finalStates.filter((state) => state.state !== "current" && !emitted.has(state.id)).map((state) => ({ id: state.id, proof: state.proof, reason: reasons.get(state.id) ?? "it was not recorded in this run" }));
|
|
2367
|
+
if (opts.comment && notCurrent.length > 0) {
|
|
2368
|
+
await postGeneral(proofsCommentBody(head, notCurrent), proofsCommentId(item, head, notCurrent));
|
|
2369
|
+
}
|
|
2370
|
+
for (const proof of notCurrent) say(`Not current, ${proof.id} (${proof.proof}): ${proof.reason}`);
|
|
2371
|
+
const closing = await runWorkProofs({ ...opts, item, env, quiet: true, checkoutHead: head, fetchImpl });
|
|
2372
|
+
const output = [...lines, closing.output].join("\n");
|
|
2373
|
+
if (!opts.quiet) process.stdout.write(output + "\n");
|
|
2374
|
+
return {
|
|
2375
|
+
exitCode: closing.exitCode,
|
|
2376
|
+
output,
|
|
2377
|
+
emitted: [...emitted].map(([criterion, artifactId]) => ({ criterion, artifactId })),
|
|
2378
|
+
notCurrent
|
|
2379
|
+
};
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
export { runWorkProofsRecord };
|