@cplieger/deadset-ts 8.0.0-dev.18 → 8.0.0-dev.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/analysis.js +4 -1
- package/dist/src/commands/held.js +499 -0
- package/dist/src/commands/read.js +16 -10
- package/dist/src/commands/shell.js +109 -15
- package/dist/src/commands/tools.js +1540 -149
- package/dist/src/conformance-record.js +1 -1
- package/dist/src/contract/contract.generated.js +7 -0
- package/dist/src/entries/conventions.js +7 -6
- package/dist/src/entries/test-runners.js +6 -40
- package/dist/src/entries/workflow-steps.js +202 -28
- package/dist/src/findings/non-code-artifacts.js +11 -5
- package/dist/src/roots/manifest.js +47 -4
- package/dist/src/roots/root-set.js +14 -16
- package/dist/src/text/named-files.js +257 -34
- package/dist/src/verbs/analyze.js +16 -1
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/analysis.ts +13 -1
- package/src/commands/held.ts +632 -0
- package/src/commands/read.ts +26 -12
- package/src/commands/shell.ts +117 -15
- package/src/commands/tools.ts +1972 -202
- package/src/conformance-record.ts +1 -1
- package/src/contract/contract.generated.ts +7 -0
- package/src/dependencies.ts +1 -1
- package/src/entries/conventions.ts +8 -12
- package/src/entries/test-runners.ts +12 -45
- package/src/entries/workflow-steps.ts +227 -38
- package/src/file-facts.ts +5 -0
- package/src/findings/non-code-artifacts.ts +16 -5
- package/src/roots/manifest.ts +53 -8
- package/src/roots/root-set.ts +18 -16
- package/src/text/named-files.ts +333 -36
- package/src/verbs/analyze.ts +16 -1
package/src/commands/read.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The one reader of every command string the analysis reads. Layer 3, the holding rule
|
|
3
|
-
* `roots/root-set.ts` applies through `text/named-files.ts`, reads
|
|
4
|
-
* whatever the other two layers make of it; layer 1 parses the string and
|
|
5
|
-
* simple command a tool's reader understands, and they only add the files
|
|
3
|
+
* `roots/root-set.ts` applies through `commands/held.ts` and `text/named-files.ts`, reads every
|
|
4
|
+
* word of the string whatever the other two layers make of it; layer 1 parses the string and
|
|
5
|
+
* layer 2 reads each simple command a tool's reader understands, and they only add the files
|
|
6
|
+
* and modules it runs.
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
9
|
import { joinPath, resolvePath } from "../paths.ts";
|
|
@@ -11,10 +12,11 @@ import {
|
|
|
11
12
|
configurationsOf,
|
|
12
13
|
preloadTarget,
|
|
13
14
|
readBuiltin,
|
|
14
|
-
|
|
15
|
+
handedOn,
|
|
16
|
+
testRun,
|
|
15
17
|
type Outcome,
|
|
16
18
|
type Preload,
|
|
17
|
-
type
|
|
19
|
+
type TestRun,
|
|
18
20
|
} from "./tools.ts";
|
|
19
21
|
import { APPENDED_EXTENSIONS } from "../extensions.ts";
|
|
20
22
|
|
|
@@ -41,6 +43,11 @@ interface NamedConfiguration {
|
|
|
41
43
|
readonly written: string;
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
/** One test run a command string writes, with the directory it runs in. */
|
|
47
|
+
export interface CommandTests extends TestRun {
|
|
48
|
+
readonly dir: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
44
51
|
/** What one command string runs. */
|
|
45
52
|
export interface CommandReading {
|
|
46
53
|
readonly runs: readonly Run[];
|
|
@@ -50,7 +57,9 @@ export interface CommandReading {
|
|
|
50
57
|
*/
|
|
51
58
|
readonly commands: readonly CommandWords[];
|
|
52
59
|
readonly configurations: readonly NamedConfiguration[];
|
|
53
|
-
/**
|
|
60
|
+
/** Each test run of {@link commands}, as `testRun` reads the command a launcher hands on. */
|
|
61
|
+
readonly tests: readonly CommandTests[];
|
|
62
|
+
/** The string's whole text, which the dependency rule reads. */
|
|
54
63
|
readonly held: string;
|
|
55
64
|
}
|
|
56
65
|
|
|
@@ -90,14 +99,17 @@ export function readCommands(text: string, dir: string | undefined): CommandRead
|
|
|
90
99
|
const runs: Run[] = [];
|
|
91
100
|
const commands: CommandWords[] = [];
|
|
92
101
|
const configurations: NamedConfiguration[] = [];
|
|
102
|
+
const tests: CommandTests[] = [];
|
|
103
|
+
const readTests = (words: readonly Word[], at: string): void => {
|
|
104
|
+
const run = testRun(words);
|
|
105
|
+
if (run !== undefined) {
|
|
106
|
+
tests.push({ dir: at, ...run });
|
|
107
|
+
}
|
|
108
|
+
};
|
|
93
109
|
const readCommand = (words: readonly Word[], at: string): void => {
|
|
94
110
|
commands.push({ dir: at, words: words.map((word) => word.value) });
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
while (reading?.kind === "command") {
|
|
98
|
-
handed = reading.words;
|
|
99
|
-
reading = readTool(handed);
|
|
100
|
-
}
|
|
111
|
+
const [handed, reading] = handedOn(words);
|
|
112
|
+
readTests(handed, at);
|
|
101
113
|
if (reading?.kind === "line") {
|
|
102
114
|
readLine(reading.text, at);
|
|
103
115
|
return;
|
|
@@ -147,6 +159,7 @@ export function readCommands(text: string, dir: string | undefined): CommandRead
|
|
|
147
159
|
)) {
|
|
148
160
|
commands.push({ dir, words: words.map((word) => word.value) });
|
|
149
161
|
configurations.push(...configurationsOf(words).map((written) => ({ dir, written })));
|
|
162
|
+
readTests(handedOn(words)[0], dir);
|
|
150
163
|
}
|
|
151
164
|
}
|
|
152
165
|
const unique = <T>(all: readonly T[]): T[] => [
|
|
@@ -156,6 +169,7 @@ export function readCommands(text: string, dir: string | undefined): CommandRead
|
|
|
156
169
|
runs,
|
|
157
170
|
commands: unique(commands),
|
|
158
171
|
configurations: unique(configurations),
|
|
172
|
+
tests: unique(tests),
|
|
159
173
|
held: text,
|
|
160
174
|
};
|
|
161
175
|
}
|
package/src/commands/shell.ts
CHANGED
|
@@ -1,22 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Layer 1 of the command reader: one command line, parsed by the vendored shell parser, as
|
|
3
|
-
* its and-or lists, their pipelines and the words of each simple command
|
|
4
|
-
*
|
|
3
|
+
* its and-or lists, their pipelines and the words of each simple command, and the one place
|
|
4
|
+
* that decides which parts of a word the shell computes and which words a brace expansion
|
|
5
|
+
* stands for, for layer 3 too.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
8
|
import {
|
|
8
9
|
parse,
|
|
9
10
|
type CommandNode,
|
|
11
|
+
type ParsedScript,
|
|
10
12
|
type PipelineNode,
|
|
11
13
|
type Word as ShellWord,
|
|
12
14
|
type WordPart,
|
|
13
15
|
} from "../vendor/unbash/parser.ts";
|
|
14
16
|
|
|
17
|
+
/**
|
|
18
|
+
* The character that stands, in a word's text as layer 3 reads it, for a part only the run
|
|
19
|
+
* knows. It is a private-use character, so no path holds it, and the parser reads it as
|
|
20
|
+
* literal text.
|
|
21
|
+
*/
|
|
22
|
+
export const PART = "\uE000";
|
|
23
|
+
|
|
24
|
+
/** A GitHub Actions expression, which the runner substitutes before any shell reads the line. */
|
|
25
|
+
const EXPRESSION = /\$\{\{[\s\S]*?\}\}/gu;
|
|
26
|
+
|
|
27
|
+
/** `text` with each `${{ }}` expression in it read as a part only the run knows. */
|
|
28
|
+
export function expressionsAsParts(text: string): string {
|
|
29
|
+
return text.replace(EXPRESSION, PART);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** One command line parsed, each `${{ }}` expression in it read as a part only the run knows. */
|
|
33
|
+
export function parseLine(source: string): ParsedScript {
|
|
34
|
+
return parse(expressionsAsParts(source));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The words a word's brace expansions stand for, at most this many. */
|
|
38
|
+
const ALTERNATIVES = 64;
|
|
39
|
+
|
|
15
40
|
/** One word of a simple command: its value, or `undefined` where the shell computes it. */
|
|
16
41
|
export interface Word {
|
|
17
42
|
readonly value: string | undefined;
|
|
18
43
|
/** The word as the line writes it. */
|
|
19
44
|
readonly text: string;
|
|
45
|
+
/** Where the shell expands it to one text, that text with each part it computes as {@link PART}. */
|
|
46
|
+
readonly written?: string;
|
|
20
47
|
}
|
|
21
48
|
|
|
22
49
|
/** One pipeline of an and-or list. */
|
|
@@ -45,29 +72,104 @@ interface List {
|
|
|
45
72
|
readonly pipelines: readonly Pipeline[];
|
|
46
73
|
}
|
|
47
74
|
|
|
48
|
-
/**
|
|
49
|
-
|
|
75
|
+
/**
|
|
76
|
+
* The text one part of a word stands for: a literal's, a quoted text's or an escape's value,
|
|
77
|
+
* and {@link PART} for every part the shell computes, a glob among them.
|
|
78
|
+
*/
|
|
79
|
+
function partText(part: WordPart): string {
|
|
50
80
|
switch (part.type) {
|
|
51
81
|
case "Literal":
|
|
52
82
|
case "SingleQuoted":
|
|
53
83
|
case "AnsiCQuoted":
|
|
54
|
-
return
|
|
84
|
+
return part.value;
|
|
55
85
|
case "DoubleQuoted":
|
|
56
|
-
return part.parts.
|
|
86
|
+
return part.parts.map((child) => (child.type === "Literal" ? child.value : PART)).join("");
|
|
57
87
|
default:
|
|
58
|
-
return
|
|
88
|
+
return PART;
|
|
59
89
|
}
|
|
60
90
|
}
|
|
61
91
|
|
|
92
|
+
/** The texts the word `piece` of a brace expansion stands for, or a part where it is no one word. */
|
|
93
|
+
function alternativeTexts(piece: string): readonly string[] {
|
|
94
|
+
if (piece === "") {
|
|
95
|
+
return [""];
|
|
96
|
+
}
|
|
97
|
+
const script = parse(piece);
|
|
98
|
+
const [statement, ...more] = script.commands;
|
|
99
|
+
const command = statement?.command;
|
|
100
|
+
return (script.errors ?? []).length === 0 &&
|
|
101
|
+
more.length === 0 &&
|
|
102
|
+
command?.type === "Command" &&
|
|
103
|
+
command.name !== undefined &&
|
|
104
|
+
command.prefix.length === 0 &&
|
|
105
|
+
command.suffix.length === 0
|
|
106
|
+
? heldTextsOf(command.name)
|
|
107
|
+
: [PART];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The texts a brace expansion stands for, its comma-separated alternatives, or a part where it
|
|
112
|
+
* has none, a sequence such as `{1..3}` among them.
|
|
113
|
+
*/
|
|
114
|
+
function braceTexts(text: string): readonly string[] {
|
|
115
|
+
const inner = text.slice(1, -1);
|
|
116
|
+
const pieces: string[] = [];
|
|
117
|
+
let depth = 0;
|
|
118
|
+
let from = 0;
|
|
119
|
+
let quote = "";
|
|
120
|
+
for (let at = 0; at < inner.length; at += 1) {
|
|
121
|
+
const char = inner.charAt(at);
|
|
122
|
+
if (char === "\\") {
|
|
123
|
+
at += 1;
|
|
124
|
+
} else if (quote !== "") {
|
|
125
|
+
quote = char === quote ? "" : quote;
|
|
126
|
+
} else if (char === "'" || char === '"') {
|
|
127
|
+
quote = char;
|
|
128
|
+
} else if (char === "{" || char === "}") {
|
|
129
|
+
depth += char === "{" ? 1 : -1;
|
|
130
|
+
} else if (char === "," && depth === 0) {
|
|
131
|
+
pieces.push(inner.slice(from, at));
|
|
132
|
+
from = at + 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (pieces.length === 0) {
|
|
136
|
+
return [PART];
|
|
137
|
+
}
|
|
138
|
+
pieces.push(inner.slice(from));
|
|
139
|
+
return pieces.flatMap(alternativeTexts);
|
|
140
|
+
}
|
|
141
|
+
|
|
62
142
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
143
|
+
* Each word the shell may expand `word` to, as layer 3 reads it: its quotes removed, each brace
|
|
144
|
+
* expansion read as its alternatives, past {@link ALTERNATIVES} words as a part, and each part
|
|
145
|
+
* it computes, a tilde that starts it unquoted among them, as {@link PART}.
|
|
65
146
|
*/
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
147
|
+
export function heldTextsOf(word: ShellWord): readonly string[] {
|
|
148
|
+
const { parts } = word;
|
|
149
|
+
const [first] = parts ?? [];
|
|
150
|
+
const tilde =
|
|
151
|
+
parts === undefined
|
|
152
|
+
? word.text.startsWith("~")
|
|
153
|
+
: first?.type === "Literal" && first.text.startsWith("~");
|
|
154
|
+
let texts: readonly string[] = [parts === undefined ? word.value : ""];
|
|
155
|
+
for (const part of parts ?? []) {
|
|
156
|
+
const options = part.type === "BraceExpansion" ? braceTexts(part.text) : [partText(part)];
|
|
157
|
+
const next = texts.flatMap((text) => options.map((option) => `${text}${option}`));
|
|
158
|
+
texts = next.length > ALTERNATIVES ? texts.map((text) => `${text}${PART}`) : next;
|
|
159
|
+
}
|
|
160
|
+
return tilde ? texts.map((text) => `${PART}${text.slice(1)}`) : texts;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** One word as layer 1 reads it: static only where the shell expands it to one text with no part. */
|
|
164
|
+
export function wordOf(word: ShellWord): Word {
|
|
165
|
+
const [only, ...more] = heldTextsOf(word);
|
|
166
|
+
const one = more.length === 0 ? only : undefined;
|
|
167
|
+
const known = one !== undefined && !one.includes(PART);
|
|
168
|
+
return {
|
|
169
|
+
value: known ? word.value : undefined,
|
|
170
|
+
text: word.text,
|
|
171
|
+
...(one === undefined ? {} : { written: one }),
|
|
172
|
+
};
|
|
71
173
|
}
|
|
72
174
|
|
|
73
175
|
/**
|
|
@@ -109,7 +211,7 @@ function pipelineOf(node: PipelineNode, operator: Pipeline["operator"]): Pipelin
|
|
|
109
211
|
* gives no words, and marks its pipeline where it may change the line's directory.
|
|
110
212
|
*/
|
|
111
213
|
export function shellLine(source: string): readonly List[] {
|
|
112
|
-
const script =
|
|
214
|
+
const script = parseLine(source);
|
|
113
215
|
if ((script.errors ?? []).length > 0) {
|
|
114
216
|
return [];
|
|
115
217
|
}
|