passport-bridge 0.26.0 → 0.28.0
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 +4 -4
- package/dist/blindKind.d.ts +15 -0
- package/dist/blindKind.js +5 -0
- package/dist/cliChanges.d.ts +12 -4
- package/dist/cliChanges.js +26 -15
- package/dist/cliGuardState.js +2 -2
- package/dist/cliHook.js +2 -2
- package/dist/cliHookBlind.d.ts +15 -0
- package/dist/cliHookBlind.js +65 -0
- package/dist/cliHookDecide.d.ts +8 -1
- package/dist/cliHookDecide.js +52 -4
- package/dist/cliHookLocal.d.ts +7 -16
- package/dist/cliHookLocal.js +75 -97
- package/dist/cliHookLocalCode.js +7 -1
- package/dist/cliHookLocalFs.d.ts +15 -0
- package/dist/cliHookLocalFs.js +77 -0
- package/dist/cliHookScripts.d.ts +2 -1
- package/dist/cliHookSessionEnd.d.ts +48 -0
- package/dist/cliHookSessionEnd.js +162 -0
- package/dist/cliOutput.js +2 -2
- package/dist/cliProjectSummary.d.ts +1 -1
- package/dist/cliProjectSummary.js +19 -8
- package/dist/cliScriptRead.d.ts +5 -4
- package/dist/cliScriptRead.js +3 -2
- package/dist/cliSeen.d.ts +24 -15
- package/dist/cliSeen.js +34 -16
- package/dist/cliSessions.js +20 -6
- package/dist/cliSessionsJson.d.ts +48 -0
- package/dist/cliSessionsJson.js +40 -10
- package/dist/cliSessionsRender.d.ts +4 -0
- package/dist/cliSessionsRender.js +42 -8
- package/dist/inlineCode.d.ts +35 -0
- package/dist/inlineCode.js +201 -0
- package/dist/inlineScan.d.ts +23 -0
- package/dist/inlineScan.js +389 -0
- package/dist/localCommands.d.ts +10 -3
- package/dist/localCommands.js +59 -37
- package/dist/localFiles.d.ts +38 -2
- package/dist/localFiles.js +453 -33
- package/dist/localGit.js +53 -17
- package/dist/localShared.d.ts +3 -0
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/localFiles.js
CHANGED
|
@@ -135,56 +135,476 @@ export function fd(words, ctx) {
|
|
|
135
135
|
]);
|
|
136
136
|
return readOf("fd", "find", named.slice(1), ctx);
|
|
137
137
|
}
|
|
138
|
-
|
|
138
|
+
const SED_FLAGS = new Set(["n", "E", "r", "s", "u", "z"]);
|
|
139
|
+
const SED_LONG = /^--(posix|debug|regexp-extended|quiet|silent|separate|unbuffered|null-data|sandbox|follow-symlinks|line-length=\d+)$/;
|
|
140
|
+
/** sed: a read of the named files (or stdin), or a change to them in place.
|
|
141
|
+
* A script that writes or runs something, or comes from a file, is no decision. */
|
|
139
142
|
export function sed(words, ctx) {
|
|
140
|
-
|
|
143
|
+
let inPlace = false;
|
|
141
144
|
const scripts = [];
|
|
142
|
-
const
|
|
143
|
-
let
|
|
145
|
+
const operands = [];
|
|
146
|
+
let ended = false;
|
|
144
147
|
for (let index = 0; index < words.length; index++) {
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
index++;
|
|
148
|
+
const text = words[index].text;
|
|
149
|
+
if (ended || !text.startsWith("-") || text === "-") {
|
|
150
|
+
operands.push(words[index]);
|
|
151
|
+
continue;
|
|
150
152
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
+
if (text === "--")
|
|
154
|
+
ended = true;
|
|
155
|
+
else if (text === "--expression" || text.startsWith("--expression=")) {
|
|
156
|
+
scripts.push(text === "--expression" ? (words[++index]?.text ?? "") : text.slice(13));
|
|
153
157
|
}
|
|
154
|
-
else if (
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
else if (text === "-f" || text.startsWith("--file"))
|
|
159
|
+
return unknown("sed script from a file");
|
|
160
|
+
else if (text === "--in-place" || text.startsWith("--in-place="))
|
|
161
|
+
inPlace = true;
|
|
162
|
+
else if (text === "-i" && bsdSuffix(words[index + 1])) {
|
|
163
|
+
inPlace = true;
|
|
164
|
+
index++;
|
|
157
165
|
}
|
|
158
|
-
else if (
|
|
159
|
-
|
|
160
|
-
|
|
166
|
+
else if (SED_LONG.test(text))
|
|
167
|
+
continue;
|
|
168
|
+
else if (text.startsWith("--"))
|
|
169
|
+
return unknown("sed option not recognized");
|
|
170
|
+
else {
|
|
171
|
+
// A bundle: flags, then -i[SUFFIX], -e SCRIPT, or -l N, which take the rest.
|
|
172
|
+
for (let at = 1; at < text.length; at++) {
|
|
173
|
+
const flag = text[at];
|
|
174
|
+
if (SED_FLAGS.has(flag))
|
|
175
|
+
continue;
|
|
176
|
+
if (flag === "i")
|
|
177
|
+
inPlace = true;
|
|
178
|
+
else if (flag === "e")
|
|
179
|
+
scripts.push(at + 1 < text.length ? text.slice(at + 1) : (words[++index]?.text ?? ""));
|
|
180
|
+
else if (flag === "l") {
|
|
181
|
+
if (at + 1 === text.length)
|
|
182
|
+
index++;
|
|
183
|
+
}
|
|
184
|
+
else if (flag === "f")
|
|
185
|
+
return unknown("sed script from a file");
|
|
186
|
+
else
|
|
187
|
+
return unknown("sed option not recognized");
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
161
190
|
}
|
|
162
|
-
else
|
|
163
|
-
files.push(word);
|
|
164
191
|
}
|
|
165
|
-
if (!scripts.
|
|
192
|
+
if (!scripts.length) {
|
|
193
|
+
const script = operands.shift();
|
|
194
|
+
if (!script)
|
|
195
|
+
return unknown("sed with no script");
|
|
196
|
+
scripts.push(script.text);
|
|
197
|
+
}
|
|
198
|
+
if (scripts.some((script) => sedScriptProblem(script) !== null))
|
|
166
199
|
return unknown("sed script writes or runs something");
|
|
167
200
|
if (inPlace)
|
|
168
|
-
return writeOf("sed", "change",
|
|
169
|
-
return readOf("sed", "read",
|
|
201
|
+
return writeOf("sed", "change", operands, ctx);
|
|
202
|
+
return readOf("sed", "read", operands, ctx);
|
|
170
203
|
}
|
|
171
204
|
/** BSD sed takes `-i ''` (an empty backup suffix) as its own word. */
|
|
172
205
|
export function bsdSuffix(word) {
|
|
173
206
|
return word !== undefined && (word.text === "" || /^\.[A-Za-z0-9~_-]{0,12}$/.test(word.text));
|
|
174
207
|
}
|
|
175
|
-
/**
|
|
208
|
+
/** True when a sed script only prints, deletes, substitutes, or edits its own buffers. */
|
|
176
209
|
export function safeSedScript(script) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
210
|
+
return sedScriptProblem(script) === null;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* A small scanner over a sed script (GNU and BSD), returning why it isn't
|
|
214
|
+
* safe or null. Grammar, separated by `;` or newline outside brackets,
|
|
215
|
+
* regexes, and text:
|
|
216
|
+
*
|
|
217
|
+
* command := address? `!`* verb
|
|
218
|
+
* address := one (`,` (one | `+N` | `~N`))? one := N | N~M | `$` | /re/ | \%re% (flags I M)
|
|
219
|
+
* verb := p d D q Q n N P h H g G x z = l F { } : b t T (labels)
|
|
220
|
+
* | s<d>re<d>text<d>flags flags: g p i I m M digits (e and w are unknown)
|
|
221
|
+
* | y<d>from<d>to<d>
|
|
222
|
+
* | a i c text (output only, runs to the end of the line)
|
|
223
|
+
* unknown := r R w W e v and anything else
|
|
224
|
+
*/
|
|
225
|
+
export function sedScriptProblem(script) {
|
|
226
|
+
const scan = new SedScan(script);
|
|
227
|
+
const depth = [];
|
|
228
|
+
let commands = 0;
|
|
229
|
+
while (scan.skip()) {
|
|
230
|
+
const problem = scan.address();
|
|
231
|
+
if (problem)
|
|
232
|
+
return problem;
|
|
233
|
+
const verb = scan.text[scan.at++];
|
|
234
|
+
commands++;
|
|
235
|
+
if (verb === "{")
|
|
236
|
+
depth.push(commands);
|
|
237
|
+
else if (verb === "}" && !depth.pop())
|
|
238
|
+
return "unbalanced braces";
|
|
239
|
+
else if (verb !== "}") {
|
|
240
|
+
const bad = scan.verb(verb);
|
|
241
|
+
if (bad)
|
|
242
|
+
return bad;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (depth.length)
|
|
246
|
+
return "unbalanced braces";
|
|
247
|
+
return commands ? null : "empty script";
|
|
248
|
+
}
|
|
249
|
+
/** The sed scanner's position and its small readers (`sedScriptProblem`). */
|
|
250
|
+
class SedScan {
|
|
251
|
+
text;
|
|
252
|
+
at = 0;
|
|
253
|
+
constructor(text) {
|
|
254
|
+
this.text = text;
|
|
255
|
+
}
|
|
256
|
+
/** Past separators and comments; false at the end. */
|
|
257
|
+
skip() {
|
|
258
|
+
for (;;) {
|
|
259
|
+
while (this.at < this.text.length && /[\s;]/.test(this.text[this.at]))
|
|
260
|
+
this.at++;
|
|
261
|
+
if (this.text[this.at] !== "#")
|
|
262
|
+
return this.at < this.text.length;
|
|
263
|
+
while (this.at < this.text.length && this.text[this.at] !== "\n")
|
|
264
|
+
this.at++;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
space() {
|
|
268
|
+
while (this.text[this.at] === " " || this.text[this.at] === "\t")
|
|
269
|
+
this.at++;
|
|
270
|
+
}
|
|
271
|
+
number() {
|
|
272
|
+
const start = this.at;
|
|
273
|
+
while (/[0-9]/.test(this.text[this.at] ?? ""))
|
|
274
|
+
this.at++;
|
|
275
|
+
return this.at > start;
|
|
276
|
+
}
|
|
277
|
+
/** A delimited part, from just after its opening delimiter; brackets are literal in regexes. */
|
|
278
|
+
part(delimiter, regex) {
|
|
279
|
+
const { text } = this;
|
|
280
|
+
while (this.at < text.length) {
|
|
281
|
+
const char = text[this.at];
|
|
282
|
+
if (char === delimiter) {
|
|
283
|
+
this.at++;
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
if (char === "\n" && regex)
|
|
287
|
+
return false;
|
|
288
|
+
if (char === "\\")
|
|
289
|
+
this.at += 2;
|
|
290
|
+
else
|
|
291
|
+
this.at = regex && char === "[" ? bracketEnd(text, this.at) : this.at + 1;
|
|
292
|
+
}
|
|
182
293
|
return false;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
294
|
+
}
|
|
295
|
+
/** One address: `N`, `N~M`, `$`, `/re/`, `\%re%` (flags I M). */
|
|
296
|
+
one() {
|
|
297
|
+
const { text } = this;
|
|
298
|
+
if (text[this.at] === "$") {
|
|
299
|
+
this.at++;
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
if (this.number()) {
|
|
303
|
+
if (text[this.at] === "~" && ++this.at)
|
|
304
|
+
this.number();
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
if (text[this.at] !== "/" && text[this.at] !== "\\")
|
|
308
|
+
return false;
|
|
309
|
+
const delimiter = text[this.at] === "\\" ? text[++this.at] : "/";
|
|
310
|
+
this.at++;
|
|
311
|
+
if (!delimiter || !this.part(delimiter, true))
|
|
312
|
+
return false;
|
|
313
|
+
while (text[this.at] === "I" || text[this.at] === "M")
|
|
314
|
+
this.at++;
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
/** An optional address or range, then any `!`. */
|
|
318
|
+
address() {
|
|
319
|
+
if (this.one()) {
|
|
320
|
+
this.space();
|
|
321
|
+
if (this.text[this.at] === ",") {
|
|
322
|
+
this.at++;
|
|
323
|
+
this.space();
|
|
324
|
+
const step = this.text[this.at] === "+" || this.text[this.at] === "~";
|
|
325
|
+
if (step)
|
|
326
|
+
this.at++;
|
|
327
|
+
if (!(step ? this.number() : this.one()))
|
|
328
|
+
return "bad address";
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
this.space();
|
|
332
|
+
while (this.text[this.at] === "!") {
|
|
333
|
+
this.at++;
|
|
334
|
+
this.space();
|
|
335
|
+
}
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
/** The command after an address, up to its separator. */
|
|
339
|
+
verb(verb) {
|
|
340
|
+
const { text } = this;
|
|
341
|
+
if (verb === "s" || verb === "y") {
|
|
342
|
+
const delimiter = text[this.at++];
|
|
343
|
+
if (!delimiter || delimiter === "\\" || delimiter === "\n")
|
|
344
|
+
return "bad delimiter";
|
|
345
|
+
if (!this.part(delimiter, verb === "s") || !this.part(delimiter, false))
|
|
346
|
+
return "unterminated command";
|
|
347
|
+
while (verb === "s" && /[gpiImM0-9]/.test(text[this.at] ?? ""))
|
|
348
|
+
this.at++;
|
|
349
|
+
if (verb === "s" && (text[this.at] === "e" || text[this.at] === "w"))
|
|
350
|
+
return "sed script writes or runs something";
|
|
351
|
+
}
|
|
352
|
+
else if (verb === "a" || verb === "i" || verb === "c") {
|
|
353
|
+
// Text to the end of the line; a trailing backslash continues it.
|
|
354
|
+
while (this.at < text.length && text[this.at] !== "\n")
|
|
355
|
+
this.at += text[this.at] === "\\" ? 2 : 1;
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
else if (verb === ":" || verb === "b" || verb === "t" || verb === "T") {
|
|
359
|
+
while (this.at < text.length && !/[\n;}]/.test(text[this.at]))
|
|
360
|
+
this.at++;
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
else if (verb === "q" || verb === "Q" || verb === "l") {
|
|
364
|
+
this.space();
|
|
365
|
+
this.number();
|
|
366
|
+
}
|
|
367
|
+
else if (!verb || !"pdDnNPhHgGxz=F".includes(verb))
|
|
368
|
+
return "sed script writes or runs something";
|
|
369
|
+
this.space();
|
|
370
|
+
return this.at < text.length && !/[;\n}#]/.test(text[this.at]) ? "unexpected text" : null;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/** Where a bracket expression starting at `start` ends (just past its `]`). */
|
|
374
|
+
function bracketEnd(text, start) {
|
|
375
|
+
let at = start + 1;
|
|
376
|
+
if (text[at] === "^")
|
|
377
|
+
at++;
|
|
378
|
+
if (text[at] === "]")
|
|
379
|
+
at++;
|
|
380
|
+
while (at < text.length && text[at] !== "]") {
|
|
381
|
+
if (text[at] === "[" && /[:.=]/.test(text[at + 1] ?? "")) {
|
|
382
|
+
const close = text.indexOf(`${text[at + 1]}]`, at + 2);
|
|
383
|
+
at = close === -1 ? text.length : close + 2;
|
|
384
|
+
}
|
|
385
|
+
else
|
|
386
|
+
at++;
|
|
387
|
+
}
|
|
388
|
+
return at + 1;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* awk, gawk, mawk, nawk: a read of the named files (or stdin), or with gawk's
|
|
392
|
+
* `-i inplace` / `--in-place` a change to them. Options: `-F sep`, `-v
|
|
393
|
+
* name=value`, `--`; `-f file` is unknown. The first operand is the program,
|
|
394
|
+
* scanned with strings and regexes set aside (`awkProblem`).
|
|
395
|
+
*/
|
|
396
|
+
export function awk(program, words, ctx) {
|
|
397
|
+
let inPlace = false;
|
|
398
|
+
const operands = [];
|
|
399
|
+
for (let index = 0; index < words.length; index++) {
|
|
400
|
+
const text = words[index].text;
|
|
401
|
+
if (operands.length || !text.startsWith("-") || text === "-")
|
|
402
|
+
operands.push(words[index]);
|
|
403
|
+
else if (text === "--") {
|
|
404
|
+
operands.push(...words.slice(index + 1));
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
else if (text === "-F" || text === "-v")
|
|
408
|
+
index++;
|
|
409
|
+
else if (/^-[Fv]./.test(text) || /^--(field-separator|assign)=/.test(text))
|
|
410
|
+
continue;
|
|
411
|
+
else if (text === "-f" || /^-f.|^--file/.test(text))
|
|
412
|
+
return unknown("awk program from a file");
|
|
413
|
+
else if ((text === "-i" && words[index + 1]?.text === "inplace") || text === "--in-place") {
|
|
414
|
+
inPlace = true;
|
|
415
|
+
if (text === "-i")
|
|
416
|
+
index++;
|
|
417
|
+
}
|
|
418
|
+
else
|
|
419
|
+
return unknown(`${program} option not recognized`);
|
|
420
|
+
}
|
|
421
|
+
const source = operands.shift();
|
|
422
|
+
if (!source || source.expands)
|
|
423
|
+
return unknown(`${program} program Passport can't see`);
|
|
424
|
+
const problem = awkProblem(source.text);
|
|
425
|
+
if (problem)
|
|
426
|
+
return unknown(problem);
|
|
427
|
+
// `name=value` operands set variables between files.
|
|
428
|
+
const files = operands.filter((word) => !/^[A-Za-z_][A-Za-z0-9_]*=/.test(word.text));
|
|
429
|
+
return inPlace ? writeOf(program, "change", files, ctx) : readOf(program, "read", files, ctx);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Why an awk program isn't read-only, or null. With string and regex
|
|
433
|
+
* contents set aside: `system(`, a pipe (`print … | "cmd"`, `"cmd" | getline`,
|
|
434
|
+
* `|&`), `getline <` from a file, and `>`/`>>` at the top level of a `print`
|
|
435
|
+
* or `printf` statement (a redirection; inside parentheses it compares).
|
|
436
|
+
*/
|
|
437
|
+
export function awkProblem(program) {
|
|
438
|
+
let code = "";
|
|
439
|
+
let previous = "";
|
|
440
|
+
for (let at = 0; at < program.length; at++) {
|
|
441
|
+
const char = program[at];
|
|
442
|
+
if (char === '"') {
|
|
443
|
+
const end = quoted(program, at, '"');
|
|
444
|
+
if (end === -1)
|
|
445
|
+
return "awk program Passport can't read";
|
|
446
|
+
code += '""';
|
|
447
|
+
at = end;
|
|
448
|
+
}
|
|
449
|
+
else if (char === "/" && (previous === "" || /[(,{};!~&|=\n?:]/.test(previous))) {
|
|
450
|
+
const end = quoted(program, at, "/");
|
|
451
|
+
if (end === -1)
|
|
452
|
+
return "awk program Passport can't read";
|
|
453
|
+
code += "//";
|
|
454
|
+
at = end;
|
|
455
|
+
}
|
|
456
|
+
else if (char === "#") {
|
|
457
|
+
while (at < program.length && program[at] !== "\n")
|
|
458
|
+
at++;
|
|
459
|
+
code += "\n";
|
|
460
|
+
}
|
|
461
|
+
else
|
|
462
|
+
code += char;
|
|
463
|
+
if (code.length && !/\s/.test(char))
|
|
464
|
+
previous = code[code.length - 1];
|
|
465
|
+
}
|
|
466
|
+
if (/\bsystem\s*\(/.test(code))
|
|
467
|
+
return "awk program runs a command";
|
|
468
|
+
if (/\|/.test(code.replace(/\|\|/g, "")))
|
|
469
|
+
return "awk program runs a command";
|
|
470
|
+
if (/\bgetline\b[^;\n}]*</.test(code))
|
|
471
|
+
return "awk program reads another file";
|
|
472
|
+
if (code.includes("@"))
|
|
473
|
+
return "awk program loads code";
|
|
474
|
+
for (const statement of code.split(/[;{}\n]/)) {
|
|
475
|
+
const print = /\bprintf?\b/.exec(statement);
|
|
476
|
+
if (!print)
|
|
477
|
+
continue;
|
|
478
|
+
let depth = 0;
|
|
479
|
+
for (const char of statement.slice(print.index + print[0].length)) {
|
|
480
|
+
if (char === "(")
|
|
481
|
+
depth++;
|
|
482
|
+
else if (char === ")")
|
|
483
|
+
depth--;
|
|
484
|
+
else if (char === ">" && depth <= 0)
|
|
485
|
+
return "awk program writes a file";
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
/** The index of the closing `quote` for one opened at `start`, or -1. */
|
|
491
|
+
function quoted(text, start, quote) {
|
|
492
|
+
for (let at = start + 1; at < text.length; at++) {
|
|
493
|
+
if (text[at] === "\\")
|
|
494
|
+
at++;
|
|
495
|
+
else if (text[at] === quote)
|
|
496
|
+
return at;
|
|
497
|
+
else if (quote === "/" && text[at] === "[")
|
|
498
|
+
at = bracketEnd(text, at) - 1;
|
|
499
|
+
else if (text[at] === "\n")
|
|
500
|
+
return -1;
|
|
501
|
+
}
|
|
502
|
+
return -1;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* `perl -pi -e 's/a/b/g' files`: with flags among -p -n -i[SUFFIX] -e -E -l
|
|
506
|
+
* -0 -a -F -w -s -C and every script only `s///`, `tr///`, or `y///`, a change
|
|
507
|
+
* to the named files with -i, else a read of them. Null: any other perl, left
|
|
508
|
+
* to the interpreter rules and the inline-code scan.
|
|
509
|
+
*/
|
|
510
|
+
export function perlSubstitution(words, ctx) {
|
|
511
|
+
const scripts = [];
|
|
512
|
+
let inPlace = false;
|
|
513
|
+
let index = 0;
|
|
514
|
+
for (; index < words.length; index++) {
|
|
515
|
+
const text = words[index].text;
|
|
516
|
+
if (text === "--") {
|
|
517
|
+
index++;
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
if (!text.startsWith("-") || text === "-")
|
|
521
|
+
break;
|
|
522
|
+
for (let at = 1; at < text.length; at++) {
|
|
523
|
+
const flag = text[at];
|
|
524
|
+
if ("pnaws".includes(flag))
|
|
525
|
+
continue;
|
|
526
|
+
if (flag === "l" || flag === "0" || flag === "C") {
|
|
527
|
+
// -l[octal], -0[octal] or -0xHEX, -C[number or IOESioDALa].
|
|
528
|
+
const value = flag === "C" ? /^[0-9IOESioDALa]*/ : text[at + 1] === "x" ? /^x[0-9a-fA-F]*/ : /^[0-7]*/;
|
|
529
|
+
at += value.exec(text.slice(at + 1))[0].length;
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
if (flag === "i")
|
|
533
|
+
inPlace = true;
|
|
534
|
+
else if (flag === "e" || flag === "E") {
|
|
535
|
+
const rest = text.slice(at + 1);
|
|
536
|
+
const word = rest ? { text: rest } : words[++index];
|
|
537
|
+
if (!word || word.expands)
|
|
538
|
+
return null;
|
|
539
|
+
scripts.push(word.text);
|
|
540
|
+
}
|
|
541
|
+
else if (flag !== "F")
|
|
542
|
+
return null;
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (!scripts.length || !scripts.every(substitutionsOnly))
|
|
547
|
+
return null;
|
|
548
|
+
const files = words.slice(index);
|
|
549
|
+
return inPlace ? writeOf("perl", "change", files, ctx) : readOf("perl", "read", files, ctx);
|
|
550
|
+
}
|
|
551
|
+
const PAIRS = { "{": "}", "[": "]", "(": ")", "<": ">" };
|
|
552
|
+
/** Only `s///` and `tr///`/`y///`, any delimiter, joined by `;` or whitespace;
|
|
553
|
+
* flags among g i m s x r (tr: c d s r). No code in the pattern or replacement. */
|
|
554
|
+
function substitutionsOnly(script) {
|
|
555
|
+
let at = 0;
|
|
556
|
+
let count = 0;
|
|
557
|
+
/** One delimited part from `at` (on its opening delimiter); its text, or null. */
|
|
558
|
+
const part = () => {
|
|
559
|
+
const open = script[at];
|
|
560
|
+
if (!open || /[\s\w]/.test(open))
|
|
561
|
+
return null;
|
|
562
|
+
const close = PAIRS[open] ?? open;
|
|
563
|
+
let depth = 0;
|
|
564
|
+
for (let end = at + 1; end < script.length; end++) {
|
|
565
|
+
if (script[end] === "\\")
|
|
566
|
+
end++;
|
|
567
|
+
else if (script[end] === open && close !== open)
|
|
568
|
+
depth++;
|
|
569
|
+
else if (script[end] === close && depth-- === 0) {
|
|
570
|
+
const text = script.slice(at + 1, end);
|
|
571
|
+
at = close === open ? end : end + 1;
|
|
572
|
+
return text;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return null;
|
|
576
|
+
};
|
|
577
|
+
while (at < script.length) {
|
|
578
|
+
while (/[\s;]/.test(script[at] ?? ""))
|
|
579
|
+
at++;
|
|
580
|
+
if (at >= script.length)
|
|
581
|
+
break;
|
|
582
|
+
const operator = /^(s|tr|y)(?=[^\w\s])/.exec(script.slice(at))?.[1];
|
|
583
|
+
if (!operator)
|
|
584
|
+
return false;
|
|
585
|
+
at += operator.length;
|
|
586
|
+
const paired = Object.hasOwn(PAIRS, script[at]);
|
|
587
|
+
const from = part();
|
|
588
|
+
if (from === null)
|
|
589
|
+
return false;
|
|
590
|
+
if (paired)
|
|
591
|
+
while (/\s/.test(script[at] ?? ""))
|
|
592
|
+
at++;
|
|
593
|
+
const to = part();
|
|
594
|
+
if (to === null)
|
|
595
|
+
return false;
|
|
596
|
+
if (!paired)
|
|
597
|
+
at++;
|
|
598
|
+
const flags = /^[a-z]*/.exec(script.slice(at))[0];
|
|
599
|
+
at += flags.length;
|
|
600
|
+
if (!(operator === "s" ? /^[gimsxr]*$/ : /^[cdsr]*$/).test(flags))
|
|
601
|
+
return false;
|
|
602
|
+
// Code inside a regex or an interpolated replacement: (?{ }), @{[ ]}, ${\ }.
|
|
603
|
+
if (/\(\?\??\{|[@$]\{|@\$|\$\(/.test(from + to.replace(/\$\{\w+\}/g, "")))
|
|
604
|
+
return false;
|
|
605
|
+
count++;
|
|
606
|
+
}
|
|
607
|
+
return count > 0;
|
|
188
608
|
}
|
|
189
609
|
export function tar(words, ctx) {
|
|
190
610
|
const bundled = words[0] && !words[0].text.startsWith("-") ? words[0].text : "";
|
package/dist/localGit.js
CHANGED
|
@@ -6,41 +6,53 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { C, D, R, hasFlag, hasShortFlag } from "./localTools.js";
|
|
8
8
|
import { local, named, unknown, writeOf } from "./localShared.js";
|
|
9
|
+
/** `-c` settings that only change how git prints or who it says you are. */
|
|
10
|
+
const HARMLESS_CONFIG = /^(core\.pager=cat|color\.ui=(false|never)|advice\.[a-z]+=[a-z]*|core\.quotepath=false|user\.(name|email)=.*)$/i;
|
|
9
11
|
/** git: local work is Development; a push lands on a branch; the vendor map keeps push itself. */
|
|
10
12
|
export function git(words, ctx) {
|
|
11
13
|
let index = 0;
|
|
12
14
|
let here = ctx.here;
|
|
15
|
+
let folder = null;
|
|
13
16
|
while (index < words.length && words[index].text.startsWith("-")) {
|
|
14
17
|
const flag = words[index].text;
|
|
15
|
-
if (flag === "-c"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
if (flag === "-c") {
|
|
19
|
+
const setting = words[index + 1];
|
|
20
|
+
if (!setting || setting.expands || !HARMLESS_CONFIG.test(setting.text))
|
|
21
|
+
return unknown("git options that change what runs");
|
|
22
|
+
index += 2;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (/^--(exec-path|git-dir|work-tree|namespace|config-env)/.test(flag)) {
|
|
20
26
|
return unknown("git options that change what runs");
|
|
21
27
|
}
|
|
22
28
|
if (flag === "-C") {
|
|
23
|
-
|
|
24
|
-
if (!
|
|
29
|
+
folder = words[index + 1] ?? null;
|
|
30
|
+
if (!folder)
|
|
25
31
|
return unknown("git -C with nothing named");
|
|
26
|
-
here = ctx.place(
|
|
32
|
+
here = ctx.place(folder);
|
|
27
33
|
index += 2;
|
|
28
34
|
continue;
|
|
29
35
|
}
|
|
30
36
|
index++;
|
|
31
37
|
}
|
|
32
|
-
// Running git elsewhere runs that folder's hooks and config
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
// Running git elsewhere runs that folder's hooks and config; another
|
|
39
|
+
// worktree of this project's repository shares them.
|
|
40
|
+
if (here !== "project" && here !== "project-root") {
|
|
41
|
+
if (here === "sensitive" || here === "unknown" || !ctx.sameRepository?.(folder))
|
|
42
|
+
return unknown("git outside this project");
|
|
43
|
+
}
|
|
35
44
|
const sub = words[index]?.text;
|
|
36
45
|
const rest = words.slice(index + 1);
|
|
37
46
|
const args = rest.map((word) => word.text);
|
|
38
47
|
if (!sub)
|
|
39
48
|
return local(gitAction("help", "read"));
|
|
49
|
+
const verdict = gitVerdict(sub, args);
|
|
50
|
+
// A pattern the shell expands could become an option: only reads that stay reads take one.
|
|
40
51
|
if (rest.some((word) => word.glob) && !/^(add|status|diff|log|show|ls-files|grep|blame)$/.test(sub)) {
|
|
41
|
-
|
|
52
|
+
const reads = typeof verdict === "object" && verdict?.kind === "read" && !/^(fetch|ls-remote)$/.test(sub);
|
|
53
|
+
if (!reads)
|
|
54
|
+
return unknown("an unquoted pattern could become a git option");
|
|
42
55
|
}
|
|
43
|
-
const verdict = gitVerdict(sub, args);
|
|
44
56
|
if (verdict === "push")
|
|
45
57
|
return { kind: "vendor", push: pushPlace(args, ctx) };
|
|
46
58
|
if (verdict === "vendor")
|
|
@@ -132,7 +144,27 @@ const BRANCH_EDITS = [
|
|
|
132
144
|
"-f",
|
|
133
145
|
"--force"
|
|
134
146
|
];
|
|
135
|
-
const CONFIG_READS = [
|
|
147
|
+
const CONFIG_READS = [
|
|
148
|
+
"--get",
|
|
149
|
+
"--get-all",
|
|
150
|
+
"--get-regexp",
|
|
151
|
+
"--get-urlmatch",
|
|
152
|
+
"--get-color",
|
|
153
|
+
"--get-colorbool",
|
|
154
|
+
"--list",
|
|
155
|
+
"-l",
|
|
156
|
+
"--show-origin"
|
|
157
|
+
];
|
|
158
|
+
const CONFIG_EDITS = [
|
|
159
|
+
"--unset",
|
|
160
|
+
"--unset-all",
|
|
161
|
+
"--add",
|
|
162
|
+
"--replace-all",
|
|
163
|
+
"--rename-section",
|
|
164
|
+
"--remove-section",
|
|
165
|
+
"-e",
|
|
166
|
+
"--edit"
|
|
167
|
+
];
|
|
136
168
|
function stash({ positional }) {
|
|
137
169
|
const action = positional[0] ?? "push";
|
|
138
170
|
if (action === "list" || action === "show")
|
|
@@ -150,9 +182,11 @@ function remote({ flags, positional }) {
|
|
|
150
182
|
: null;
|
|
151
183
|
}
|
|
152
184
|
function config({ flags, positional }) {
|
|
153
|
-
const reads = hasFlag(flags, ...CONFIG_READS);
|
|
185
|
+
const reads = hasFlag(flags, ...CONFIG_READS) && !hasFlag(flags, ...CONFIG_EDITS);
|
|
154
186
|
if (hasFlag(flags, "--global", "--system") && !reads)
|
|
155
187
|
return C("config --global", "machine");
|
|
188
|
+
if (hasFlag(flags, ...CONFIG_EDITS))
|
|
189
|
+
return C("config");
|
|
156
190
|
if (reads || positional[0] === "get" || positional[0] === "list" || positional.length === 1)
|
|
157
191
|
return R("config");
|
|
158
192
|
return C("config");
|
|
@@ -188,7 +222,9 @@ const GIT_FORMS = {
|
|
|
188
222
|
const action = positional[0];
|
|
189
223
|
if (action === "list")
|
|
190
224
|
return R("worktree list");
|
|
191
|
-
|
|
225
|
+
if (action === "prune")
|
|
226
|
+
return C("worktree prune");
|
|
227
|
+
return action === "remove" ? D("worktree remove") : C("worktree");
|
|
192
228
|
},
|
|
193
229
|
submodule: ({ positional }) => !positional.length || positional[0] === "status" || positional[0] === "summary" ? R("submodule") : C("submodule"),
|
|
194
230
|
reflog: ({ positional }) => positional[0] === "expire" || positional[0] === "delete" ? D("reflog expire") : R("reflog"),
|
|
@@ -207,7 +243,7 @@ const GIT_FORMS = {
|
|
|
207
243
|
/** What one git subcommand does. "push" and "vendor" defer to the vendor map. */
|
|
208
244
|
export function gitVerdict(sub, args) {
|
|
209
245
|
if (sub === "push")
|
|
210
|
-
return "push";
|
|
246
|
+
return hasFlag(args, "--dry-run") || hasShortFlag(args, "n") ? R("push --dry-run") : "push";
|
|
211
247
|
if ((sub === "diff" || sub === "log") && hasFlag(args, "--output"))
|
|
212
248
|
return C(`${sub} --output`);
|
|
213
249
|
if (GIT_READS.has(sub))
|
package/dist/localShared.d.ts
CHANGED
|
@@ -69,6 +69,9 @@ export type CommandContext = {
|
|
|
69
69
|
currentBranch?: string | null;
|
|
70
70
|
/** The repository's default branch, if known. */
|
|
71
71
|
defaultBranch?: string | null;
|
|
72
|
+
/** A folder in another checkout of this project's repository (a worktree
|
|
73
|
+
* sharing its git folder). `null`: the folder the command runs in. */
|
|
74
|
+
sameRepository?(word: ShellWord | null): boolean;
|
|
72
75
|
};
|
|
73
76
|
export declare const PLACE_TOUCHES: Record<Place, Touches>;
|
|
74
77
|
export declare const PLACE_VERB: Record<Place, string>;
|
package/dist/pluginPin.d.ts
CHANGED
package/dist/pluginPin.js
CHANGED
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.28.0";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Keep in lockstep with bridge/package.json.
|
|
2
|
-
export const VERSION = "0.
|
|
2
|
+
export const VERSION = "0.28.0";
|