tslaws 0.9.0 → 1.0.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 +8 -2
- package/bin/tslaws.js +8 -2
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +36 -7
- package/dist/bundled.js +2 -2
- package/dist/bundlerPlugins.d.ts +2 -0
- package/dist/bundlerPlugins.js +7 -0
- package/dist/certificates.d.ts +139 -0
- package/dist/certificates.js +433 -0
- package/dist/chc.d.ts +85 -0
- package/dist/chc.js +298 -0
- package/dist/check.d.ts +13 -1
- package/dist/check.js +215 -28
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +324 -41
- package/dist/compile.d.ts +17 -1
- package/dist/compile.js +244 -25
- package/dist/coverage.d.ts +55 -3
- package/dist/coverage.js +231 -12
- package/dist/e2eApi.js +3 -1
- package/dist/generators.js +12 -2
- package/dist/github.d.ts +49 -5
- package/dist/github.js +107 -24
- package/dist/githubCli.d.ts +28 -0
- package/dist/githubCli.js +1039 -211
- package/dist/hints.js +2 -1
- package/dist/init.js +42 -0
- package/dist/isolate.d.ts +28 -0
- package/dist/isolate.js +262 -0
- package/dist/isolatedCheck.d.ts +1 -0
- package/dist/isolatedCheck.js +16 -0
- package/dist/lawHost.d.ts +50 -0
- package/dist/lawHost.js +199 -0
- package/dist/lawRuntime.d.ts +39 -0
- package/dist/lawRuntime.js +242 -0
- package/dist/lock.d.ts +49 -9
- package/dist/lock.js +132 -21
- package/dist/mcp.js +28 -7
- package/dist/mutate.d.ts +4 -0
- package/dist/mutate.js +7 -1
- package/dist/plan.d.ts +1 -0
- package/dist/plan.js +4 -0
- package/dist/pluginHooks.d.ts +16 -0
- package/dist/pluginHooks.js +48 -0
- package/dist/pluginHost.d.ts +5 -0
- package/dist/pluginHost.js +43 -0
- package/dist/pluginWorker.d.ts +1 -0
- package/dist/pluginWorker.js +40 -0
- package/dist/plural.d.ts +2 -0
- package/dist/plural.js +4 -0
- package/dist/pool.d.ts +80 -7
- package/dist/pool.js +222 -11
- package/dist/projects.d.ts +70 -0
- package/dist/projects.js +457 -0
- package/dist/promote.d.ts +56 -2
- package/dist/promote.js +429 -13
- package/dist/property.js +13 -2
- package/dist/propertyWorker.js +11 -1
- package/dist/proposals.d.ts +52 -4
- package/dist/proposals.js +484 -21
- package/dist/reporters.js +5 -1
- package/dist/runtimeEnv.d.ts +32 -0
- package/dist/runtimeEnv.js +146 -0
- package/dist/sandbox.d.ts +98 -0
- package/dist/sandbox.js +673 -0
- package/dist/sandboxGuard.d.ts +56 -0
- package/dist/sandboxGuard.js +249 -0
- package/dist/seal.d.ts +9 -0
- package/dist/seal.js +426 -0
- package/dist/security/cli.d.ts +6 -0
- package/dist/security/cli.js +39 -0
- package/dist/security/cwe.d.ts +14 -0
- package/dist/security/cwe.js +40 -0
- package/dist/security/deps/cache.d.ts +28 -0
- package/dist/security/deps/cache.js +107 -0
- package/dist/security/deps/config.d.ts +16 -0
- package/dist/security/deps/config.js +43 -0
- package/dist/security/deps/imports.d.ts +4 -0
- package/dist/security/deps/imports.js +33 -0
- package/dist/security/deps/lockfiles.d.ts +23 -0
- package/dist/security/deps/lockfiles.js +153 -0
- package/dist/security/deps/osv.d.ts +66 -0
- package/dist/security/deps/osv.js +137 -0
- package/dist/security/deps/run.d.ts +54 -0
- package/dist/security/deps/run.js +135 -0
- package/dist/security/deps/severity.d.ts +26 -0
- package/dist/security/deps/severity.js +78 -0
- package/dist/security/generators.d.ts +9 -0
- package/dist/security/generators.js +36 -0
- package/dist/security/index.d.ts +27 -0
- package/dist/security/index.js +18 -0
- package/dist/security/integers.d.ts +31 -0
- package/dist/security/integers.js +105 -0
- package/dist/security/law.d.ts +54 -0
- package/dist/security/law.js +54 -0
- package/dist/security/pathTraversal.d.ts +29 -0
- package/dist/security/pathTraversal.js +146 -0
- package/dist/security/prototypePollution.d.ts +30 -0
- package/dist/security/prototypePollution.js +142 -0
- package/dist/security/redirect.d.ts +21 -0
- package/dist/security/redirect.js +154 -0
- package/dist/security/redos.d.ts +21 -0
- package/dist/security/redos.js +93 -0
- package/dist/security/validation.d.ts +25 -0
- package/dist/security/validation.js +89 -0
- package/dist/security/xss.d.ts +21 -0
- package/dist/security/xss.js +90 -0
- package/dist/settings.d.ts +20 -0
- package/dist/settings.js +32 -0
- package/dist/smt.d.ts +29 -1
- package/dist/smt.js +239 -107
- package/dist/smtWorker.d.ts +1 -0
- package/dist/smtWorker.js +26 -0
- package/dist/solvers.d.ts +9 -0
- package/dist/solvers.js +11 -5
- package/dist/symbolic.d.ts +54 -1
- package/dist/symbolic.js +239 -13
- package/dist/tsconfigResolve.d.ts +28 -0
- package/dist/tsconfigResolve.js +141 -0
- package/dist/types.d.ts +28 -0
- package/env.d.ts +17 -0
- package/hooks/claude-hook.mjs +2 -0
- package/package.json +22 -6
package/dist/coverage.js
CHANGED
|
@@ -5,12 +5,15 @@
|
|
|
5
5
|
// (directly or through other project modules). A function carrying `@tslaws-exempt` in its doc comment is exempt,
|
|
6
6
|
// but only once the exemption is in tsc-laws.lock, so an agent cannot exempt its own code.
|
|
7
7
|
import { parseGithubConfig } from "./github.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { parseSecurityConfig } from "./security/deps/config.js";
|
|
9
|
+
import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
|
|
10
|
+
import { dirname, isAbsolute, join, posix, relative, resolve } from 'node:path';
|
|
10
11
|
import ts from 'typescript';
|
|
11
12
|
import { parseE2eConfig } from "./e2e.js";
|
|
12
13
|
import { globMatcher } from "./globs.js";
|
|
13
14
|
import { customLawFile } from "./lawFiles.js";
|
|
15
|
+
import { certifyProblem } from "./certificates.js";
|
|
16
|
+
import { importMetaEnvOf, parseEnvConfig } from "./runtimeEnv.js";
|
|
14
17
|
import { solversProblem } from "./solvers.js";
|
|
15
18
|
const settingKeys = ['runs', 'propertyTimeoutMs', 'proofTimeoutMs', 'bound'];
|
|
16
19
|
const configKeys = [
|
|
@@ -18,57 +21,273 @@ const configKeys = [
|
|
|
18
21
|
'laws',
|
|
19
22
|
'levels',
|
|
20
23
|
'solvers',
|
|
24
|
+
'certify',
|
|
21
25
|
'compilerOptions',
|
|
26
|
+
'tsconfig',
|
|
22
27
|
'e2e',
|
|
23
28
|
'bundlerPlugins',
|
|
29
|
+
'sandboxReads',
|
|
30
|
+
'env',
|
|
24
31
|
'github',
|
|
32
|
+
'security',
|
|
33
|
+
'jobs',
|
|
25
34
|
...settingKeys,
|
|
26
35
|
];
|
|
27
|
-
/**
|
|
28
|
-
|
|
36
|
+
/** Keys that steer inheritance and discovery rather than a run; `readConfig` acts on them and drops them. */
|
|
37
|
+
const structuralKeys = ['extends', 'projects', 'standalone'];
|
|
38
|
+
/** Why `value` is not a usable `projects` list (directory globs relative to the file), or undefined. */
|
|
39
|
+
export function projectsProblem(value) {
|
|
40
|
+
if (!Array.isArray(value) ||
|
|
41
|
+
value.some((entry) => typeof entry !== 'string' || entry.replace(/^!/, '') === '' || entry.startsWith('/')))
|
|
42
|
+
return `"projects" must be an array of directory globs relative to tslaws.json, got ${JSON.stringify(value)}`;
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
/** The top-level checks that hold for one file on its own; `source` names that file in every message. */
|
|
46
|
+
function checkFile(raw, source) {
|
|
29
47
|
const fail = (message) => {
|
|
30
|
-
throw new Error(
|
|
48
|
+
throw new Error(`${source}: ${message}`);
|
|
31
49
|
};
|
|
32
50
|
if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
|
|
33
51
|
return fail('must be a JSON object');
|
|
34
52
|
const object = raw;
|
|
35
53
|
for (const key of Object.keys(object)) {
|
|
36
|
-
if (key !== '$schema' && !configKeys.includes(key))
|
|
37
|
-
fail(`unknown option "${key}"; supported options are ${configKeys.join(', ')}`);
|
|
54
|
+
if (key !== '$schema' && !configKeys.includes(key) && !structuralKeys.includes(key))
|
|
55
|
+
fail(`unknown option "${key}"; supported options are ${[...configKeys, ...structuralKeys].join(', ')}`);
|
|
38
56
|
}
|
|
39
|
-
|
|
57
|
+
if (object.extends !== undefined && (typeof object.extends !== 'string' || object.extends === ''))
|
|
58
|
+
fail(`"extends" must be a path to another tslaws.json, got ${JSON.stringify(object.extends)}`);
|
|
59
|
+
const projects = object.projects === undefined ? undefined : projectsProblem(object.projects);
|
|
60
|
+
if (projects !== undefined)
|
|
61
|
+
fail(projects);
|
|
62
|
+
if (object.standalone !== undefined && typeof object.standalone !== 'boolean')
|
|
63
|
+
fail(`"standalone" must be true or false, got ${JSON.stringify(object.standalone)}`);
|
|
64
|
+
for (const key of [...settingKeys, 'jobs']) {
|
|
40
65
|
const value = object[key];
|
|
41
66
|
if (value !== undefined && (typeof value !== 'number' || !Number.isInteger(value) || value < 1))
|
|
42
67
|
fail(`"${key}" must be an integer of at least 1, got ${JSON.stringify(value)}`);
|
|
43
68
|
}
|
|
69
|
+
const tsconfig = object.tsconfig;
|
|
70
|
+
if (tsconfig !== undefined && tsconfig !== false && (typeof tsconfig !== 'string' || tsconfig === ''))
|
|
71
|
+
fail(`"tsconfig" must be a path to a tsconfig file or false, got ${JSON.stringify(tsconfig)}`);
|
|
44
72
|
const plugins = object.bundlerPlugins;
|
|
45
73
|
if (plugins !== undefined &&
|
|
46
74
|
(!Array.isArray(plugins) || plugins.some((entry) => typeof entry !== 'string' || entry === '')))
|
|
47
75
|
fail(`"bundlerPlugins" must be an array of module paths, got ${JSON.stringify(plugins)}`);
|
|
76
|
+
const reads = object.sandboxReads;
|
|
77
|
+
if (reads !== undefined &&
|
|
78
|
+
(!Array.isArray(reads) || reads.some((entry) => typeof entry !== 'string' || entry === '')))
|
|
79
|
+
fail(`"sandboxReads" must be an array of directory paths, got ${JSON.stringify(reads)}`);
|
|
80
|
+
if (object.env !== undefined)
|
|
81
|
+
parseEnvConfig(object.env);
|
|
48
82
|
const levels = object.levels;
|
|
49
83
|
if (levels !== undefined && levels !== 'names' && levels !== 'imports')
|
|
50
84
|
fail(`"levels" must be "names" or "imports", got ${JSON.stringify(levels)}`);
|
|
51
85
|
const problem = object.solvers === undefined ? undefined : solversProblem(object.solvers);
|
|
52
86
|
if (problem !== undefined)
|
|
53
87
|
fail(problem);
|
|
88
|
+
const certifyIssue = object.certify === undefined ? undefined : certifyProblem(object.certify);
|
|
89
|
+
if (certifyIssue !== undefined)
|
|
90
|
+
fail(certifyIssue);
|
|
54
91
|
const laws = object.laws;
|
|
55
92
|
if (laws !== undefined &&
|
|
56
93
|
(!Array.isArray(laws) ||
|
|
57
94
|
laws.some((entry) => typeof entry !== 'string' || entry.replace(/^!/, '') === '' || entry.startsWith('/'))))
|
|
58
95
|
fail(`"laws" must be an array of project-relative globs, got ${JSON.stringify(laws)}`);
|
|
96
|
+
if (object.security !== undefined)
|
|
97
|
+
parseSecurityConfig(object.security);
|
|
98
|
+
return object;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Validates the top level of tslaws.json: known keys only, and the run settings are integers of at least 1. `extends`
|
|
102
|
+
* and `projects` are accepted (a string, and a list of globs) but are not part of the result: `readConfig` has
|
|
103
|
+
* already acted on `extends`, and discovery reads `projects` from the file itself.
|
|
104
|
+
*/
|
|
105
|
+
export function parseConfig(raw, source = 'tslaws.json') {
|
|
106
|
+
const object = checkFile(raw, source);
|
|
59
107
|
if (object.github !== undefined)
|
|
60
108
|
parseGithubConfig(object.github);
|
|
61
|
-
|
|
109
|
+
const config = { ...object };
|
|
110
|
+
for (const key of structuralKeys)
|
|
111
|
+
delete config[key];
|
|
112
|
+
return config;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The settings that name a file or directory by path, rebased when inherited through `extends`: a value is written
|
|
116
|
+
* relative to the file that declares it (as in tsconfig), so it is rebased to the extending file. `bundlerPlugins` are
|
|
117
|
+
* module paths and `e2e.server.cwd` is the directory the dev server runs in. A trailing `[]` means every element of an
|
|
118
|
+
* array. `cover` and `laws` are not here on purpose: they are globs relative to the project that uses the config, so a
|
|
119
|
+
* shared base saying `"cover": ["src/**"]` means each package's own src/. `compilerOptions`, `github` and `security` hold no
|
|
120
|
+
* paths. Add a new file-reference option here when it is added to `configKeys`.
|
|
121
|
+
*/
|
|
122
|
+
const pathFields = ['bundlerPlugins[]', 'sandboxReads[]', 'e2e.server.cwd', 'tsconfig'];
|
|
123
|
+
/** `entry`, written relative to the directory `from`, as a path relative to `to`. A leading `!` and absolute paths stay. */
|
|
124
|
+
function rebase(entry, from, to) {
|
|
125
|
+
const negated = entry.startsWith('!');
|
|
126
|
+
const body = negated ? entry.slice(1) : entry;
|
|
127
|
+
const prefix = relative(to, from).replaceAll('\\', '/');
|
|
128
|
+
if (prefix === '' || isAbsolute(body))
|
|
129
|
+
return entry;
|
|
130
|
+
return `${negated ? '!' : ''}${posix.join(prefix, body)}`;
|
|
131
|
+
}
|
|
132
|
+
function rebaseFields(config, from, to) {
|
|
133
|
+
const out = { ...config };
|
|
134
|
+
for (const field of pathFields) {
|
|
135
|
+
const parts = field.split('.');
|
|
136
|
+
let node = out;
|
|
137
|
+
for (const [index, part] of parts.entries()) {
|
|
138
|
+
const list = part.endsWith('[]');
|
|
139
|
+
const key = list ? part.slice(0, -2) : part;
|
|
140
|
+
const value = node[key];
|
|
141
|
+
if (index === parts.length - 1) {
|
|
142
|
+
if (list && Array.isArray(value))
|
|
143
|
+
node[key] = value.map((entry) => (typeof entry === 'string' ? rebase(entry, from, to) : entry));
|
|
144
|
+
else if (!list && typeof value === 'string')
|
|
145
|
+
node[key] = rebase(value, from, to);
|
|
146
|
+
}
|
|
147
|
+
else if (isPlain(value)) {
|
|
148
|
+
node[key] = { ...value };
|
|
149
|
+
node = node[key];
|
|
150
|
+
}
|
|
151
|
+
else
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
function isPlain(value) {
|
|
158
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
159
|
+
}
|
|
160
|
+
/** Objects merge key by key; anything else, arrays included, is replaced. The child wins. */
|
|
161
|
+
function deepMerge(base, child) {
|
|
162
|
+
const out = { ...base };
|
|
163
|
+
for (const [key, value] of Object.entries(child)) {
|
|
164
|
+
if (key === '__proto__')
|
|
165
|
+
continue;
|
|
166
|
+
const inherited = out[key];
|
|
167
|
+
out[key] = isPlain(value) && isPlain(inherited) ? deepMerge(inherited, value) : value;
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The text of an `extends` value if it is one this tool will follow: a non-empty relative path with forward slashes only.
|
|
173
|
+
* An absolute path, a drive or UNC path, a backslash, or a NUL is refused, so the on-disk loader and the GitHub checks
|
|
174
|
+
* that read the same files through the API resolve one target and never two.
|
|
175
|
+
*/
|
|
176
|
+
export function checkExtendsValue(value) {
|
|
177
|
+
if (typeof value !== 'string' || value === '')
|
|
178
|
+
throw new Error(`"extends" must be a path to another tslaws.json, got ${JSON.stringify(value)}`);
|
|
179
|
+
// Letters, digits and . _ - / @ only: no `?`, `#`, `&` or `%` (which change an API URL's query), no backslash, NUL,
|
|
180
|
+
// space or drive colon.
|
|
181
|
+
if (!/^[A-Za-z0-9._\-/@]+$/.test(value) || value.startsWith('/'))
|
|
182
|
+
throw new Error(`"extends" must be a relative path of letters, digits and . _ - / @ with forward slashes, got ${JSON.stringify(value)}`);
|
|
183
|
+
return value;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Where `extends` points, as a repository path: `fromFile` is the repository path of the file that names it. Refuses
|
|
187
|
+
* what `checkExtendsValue` does, and a target that leaves the repository.
|
|
188
|
+
*/
|
|
189
|
+
export function extendsTarget(fromFile, value) {
|
|
190
|
+
const target = posix.normalize(posix.join(posix.dirname(fromFile), checkExtendsValue(value)));
|
|
191
|
+
if (target === '..' || target.startsWith('../') || posix.isAbsolute(target))
|
|
192
|
+
throw new Error(`"extends" ${JSON.stringify(value)} in ${fromFile} leaves the repository`);
|
|
193
|
+
return target;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The directory no `extends` may leave: the nearest enclosing directory with a `.git`, else the highest enclosing one
|
|
197
|
+
* that carries a workspace file (`tslaws.json`, `package.json` or `pnpm-workspace.yaml`), else `cwd` itself.
|
|
198
|
+
*/
|
|
199
|
+
export function extendsRoot(cwd) {
|
|
200
|
+
let top = resolve(cwd);
|
|
201
|
+
let dir = top;
|
|
202
|
+
for (;;) {
|
|
203
|
+
if (existsSync(join(dir, '.git')))
|
|
204
|
+
return dir;
|
|
205
|
+
if (['tslaws.json', 'package.json', 'pnpm-workspace.yaml'].some((f) => existsSync(join(dir, f))))
|
|
206
|
+
top = dir;
|
|
207
|
+
const parent = dirname(dir);
|
|
208
|
+
if (parent === dir)
|
|
209
|
+
return top;
|
|
210
|
+
dir = parent;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** Whether `inner` is `outer` or inside it, by path alone. */
|
|
214
|
+
const within = (outer, inner) => {
|
|
215
|
+
const rel = relative(outer, inner);
|
|
216
|
+
return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Loads `file` and the files it `extends`, merged, with paths relative to the directory of `file`. `chain` holds the
|
|
220
|
+
* files being loaded, outermost first, so a cycle or a missing file is reported with the way it was reached; every
|
|
221
|
+
* file read is added to `loaded`.
|
|
222
|
+
*/
|
|
223
|
+
function loadMerged(file, cwd, root, chain, loaded) {
|
|
224
|
+
const shown = (path) => relative(cwd, path).replaceAll('\\', '/') || path;
|
|
225
|
+
const trail = [...chain, file];
|
|
226
|
+
let text;
|
|
227
|
+
try {
|
|
228
|
+
text = readFileSync(file, 'utf8');
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
throw new Error(`${shown(file)}: no such file (reached by extends: ${trail.map(shown).join(' -> ')})`);
|
|
232
|
+
}
|
|
233
|
+
// A symlink is not followed: the GitHub checks read a repository file as a blob and refuse a link, so a link here
|
|
234
|
+
// would be a file only one side reads.
|
|
235
|
+
if (lstatSync(file).isSymbolicLink())
|
|
236
|
+
throw new Error(`${shown(file)}: a symlink, which tslaws does not follow (reached by extends: ${trail.map(shown).join(' -> ')})`);
|
|
237
|
+
loaded.push(file);
|
|
238
|
+
let json;
|
|
239
|
+
try {
|
|
240
|
+
json = JSON.parse(text);
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
// The parser's message quotes the file's text, which is not ours to echo into a log.
|
|
244
|
+
throw new Error(`${shown(file)}: not valid JSON`);
|
|
245
|
+
}
|
|
246
|
+
const { extends: parent, ...own } = checkFile(json, shown(file));
|
|
247
|
+
if (parent === undefined)
|
|
248
|
+
return own;
|
|
249
|
+
const baseFile = resolve(dirname(file), checkExtendsValue(parent));
|
|
250
|
+
// The same containment as the GitHub checks (`extendsTarget`): by path, and by where a link or a linked directory
|
|
251
|
+
// really leads.
|
|
252
|
+
const outside = () => new Error(`${shown(file)}: "extends" ${JSON.stringify(parent)} leaves the repository (${shown(root)})`);
|
|
253
|
+
if (!within(root, baseFile))
|
|
254
|
+
throw outside();
|
|
255
|
+
if (existsSync(baseFile) && !within(realpathSync(root), realpathSync(baseFile)))
|
|
256
|
+
throw outside();
|
|
257
|
+
if (trail.includes(baseFile))
|
|
258
|
+
throw new Error(`${shown(file)}: "extends" forms a cycle (${[...trail, baseFile].map(shown).join(' -> ')})`);
|
|
259
|
+
const base = rebaseFields(loadMerged(baseFile, cwd, root, trail, loaded), dirname(baseFile), dirname(file));
|
|
260
|
+
// `projects` lists directories under the file that wrote it, so it is never inherited; nor is `standalone`, which is
|
|
261
|
+
// about the one project whose file says it.
|
|
262
|
+
delete base.projects;
|
|
263
|
+
delete base.standalone;
|
|
264
|
+
return deepMerge(base, own);
|
|
62
265
|
}
|
|
266
|
+
/** The settings of tslaws.json in `cwd`, with every `extends` followed; `{}` when there is no file. */
|
|
63
267
|
export function readConfig(cwd) {
|
|
64
268
|
const path = join(cwd, 'tslaws.json');
|
|
65
269
|
if (!existsSync(path))
|
|
66
270
|
return {};
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
271
|
+
const loaded = [];
|
|
272
|
+
const merged = loadMerged(path, cwd, extendsRoot(cwd), [], loaded);
|
|
273
|
+
let config;
|
|
274
|
+
try {
|
|
275
|
+
config = parseConfig(merged);
|
|
276
|
+
if (config.e2e !== undefined)
|
|
277
|
+
config.e2e = parseE2eConfig(config.e2e);
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
if (loaded.length === 1)
|
|
281
|
+
throw error;
|
|
282
|
+
const files = loaded.map((file) => relative(cwd, file).replaceAll('\\', '/')).join(', ');
|
|
283
|
+
throw new Error(`${error.message} (merged from ${files})`);
|
|
284
|
+
}
|
|
70
285
|
return config;
|
|
71
286
|
}
|
|
287
|
+
/** The `import.meta.env` of the project's laws: `process.env`, the defaults and the `env` of tslaws.json. */
|
|
288
|
+
export function lawEnv(cwd, surface) {
|
|
289
|
+
return importMetaEnvOf(readConfig(cwd).env, surface);
|
|
290
|
+
}
|
|
72
291
|
/** Source files matching the `cover` globs (a leading `!` excludes), minus laws files and declarations. */
|
|
73
292
|
export function coverFiles(cwd, globs) {
|
|
74
293
|
// Plain JavaScript sources are covered only when the project compiles them (`allowJs`).
|
package/dist/e2eApi.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
5
|
import { createRequire } from 'node:module';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
|
-
// The runner and the law may load this module through different paths (an ESM import and
|
|
7
|
+
// The runner and the law may load this module through different paths (an ESM import and the CommonJS `require` of a
|
|
8
|
+
// compiled law), so
|
|
8
9
|
// the storage lives on the global object and both see the same one.
|
|
9
10
|
const key = Symbol.for('tslaws.e2e.state');
|
|
10
11
|
function storage() {
|
|
@@ -63,6 +64,7 @@ export async function a11y(target, options = {}) {
|
|
|
63
64
|
const used = target ?? state.page;
|
|
64
65
|
let axePath;
|
|
65
66
|
try {
|
|
67
|
+
// Resolution only, from the project's directory (`import.meta.resolve` starts from this file); no CommonJS is loaded.
|
|
66
68
|
axePath = createRequire(join(state.cwd, 'package.json')).resolve('axe-core/axe.min.js');
|
|
67
69
|
}
|
|
68
70
|
catch {
|
package/dist/generators.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { arbitraryRegistry } from "./api.js";
|
|
3
|
+
import { registerSecurityGenerators, securityTypeNames } from "./security/generators.js";
|
|
3
4
|
import { arbitraryOf, UnsupportedType } from "./plan.js";
|
|
4
5
|
export { toWire, UnsupportedType, wireKey } from "./plan.js";
|
|
6
|
+
/** Whether a type is declared in tslaws' own security module, not by a project that reuses the name. */
|
|
7
|
+
function declaredBySecurity(symbol) {
|
|
8
|
+
return (symbol.declarations ?? []).some((d) => /\/tslaws\/(dist|src)\/security\//.test(d.getSourceFile().fileName));
|
|
9
|
+
}
|
|
5
10
|
export class GeneratorFactory {
|
|
6
11
|
checker;
|
|
7
12
|
active = new Set();
|
|
@@ -71,18 +76,23 @@ export class GeneratorFactory {
|
|
|
71
76
|
if (symbol === undefined)
|
|
72
77
|
return undefined;
|
|
73
78
|
const name = symbol.getName();
|
|
79
|
+
// The payload types of tslaws/security have their generators even when the law has not been loaded yet.
|
|
80
|
+
const security = securityTypeNames.has(name) && declaredBySecurity(symbol);
|
|
81
|
+
if (security && !arbitraryRegistry().has(name))
|
|
82
|
+
registerSecurityGenerators();
|
|
74
83
|
if (!arbitraryRegistry().has(name))
|
|
75
84
|
return undefined;
|
|
76
85
|
if (name === 'int')
|
|
77
86
|
return { k: 'named', name };
|
|
87
|
+
const tag = security ? { security: true } : {};
|
|
78
88
|
// What to generate if the registration is not there where the plan is used (a worker has only the built-in ones).
|
|
79
89
|
// `int` and the like are intersections that have no useful structure, so a type that cannot be planned has none.
|
|
80
90
|
try {
|
|
81
|
-
return { k: 'named', name, fallback: this.structural(type, depth) };
|
|
91
|
+
return { k: 'named', name, fallback: this.structural(type, depth), ...tag };
|
|
82
92
|
}
|
|
83
93
|
catch (error) {
|
|
84
94
|
if (error instanceof UnsupportedType)
|
|
85
|
-
return { k: 'named', name };
|
|
95
|
+
return { k: 'named', name, ...tag };
|
|
86
96
|
throw error;
|
|
87
97
|
}
|
|
88
98
|
}
|
package/dist/github.d.ts
CHANGED
|
@@ -23,6 +23,18 @@ export interface GithubConfig {
|
|
|
23
23
|
approvePullRequest: boolean;
|
|
24
24
|
/** A proposal that fails (or is open) is never accepted, whatever was said. Default true. */
|
|
25
25
|
requirePassing: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* `shared` (default): the repository-wide flow that runs from the monorepo root covers this project. `own`: the
|
|
28
|
+
* project keeps these settings but runs its own workflow (`tslaws github <mode> --project <dir>`); the root's
|
|
29
|
+
* report, merge and command leave it out. The root's verify still watches its lock.
|
|
30
|
+
*/
|
|
31
|
+
flow: 'shared' | 'own';
|
|
32
|
+
/**
|
|
33
|
+
* Whether a person may also change tsc-laws.lock directly: `tslaws accept` on their machine, or a pull request from
|
|
34
|
+
* someone with `admin` or `maintain` access. The workflow stays the way to accept on merge or on demand. Set false
|
|
35
|
+
* to make the workflow the only writer. Default true.
|
|
36
|
+
*/
|
|
37
|
+
local: boolean;
|
|
26
38
|
}
|
|
27
39
|
export declare const githubDefaults: GithubConfig;
|
|
28
40
|
/** Whether the bot is an account any workflow can act as, rather than a dedicated GitHub App. */
|
|
@@ -37,23 +49,35 @@ export interface Proposal {
|
|
|
37
49
|
kind: LockChange['kind'];
|
|
38
50
|
reason: LockChange['reason'];
|
|
39
51
|
fingerprint: string;
|
|
52
|
+
/** The project's path in the repository ('' for the root). Absent means the root. */
|
|
53
|
+
project?: string;
|
|
40
54
|
/** What the law did when it ran; undefined when the check did not report it (it did not run). */
|
|
41
55
|
outcome?: ProposalOutcome;
|
|
42
56
|
passes: boolean;
|
|
43
57
|
}
|
|
44
58
|
/** Joins the lock changes with what the check reported for each. */
|
|
45
|
-
export declare function proposalsOf(changes: LockChange[], report: CheckReport | undefined): Proposal[];
|
|
59
|
+
export declare function proposalsOf(changes: LockChange[], report: CheckReport | undefined, project?: string): Proposal[];
|
|
46
60
|
export type Command = {
|
|
47
61
|
verb: 'accept' | 'reject';
|
|
48
62
|
all: boolean;
|
|
49
63
|
names: string[];
|
|
64
|
+
/** `--project <dir>` (repeatable): the command covers only proposals of these projects. */
|
|
65
|
+
projects?: string[];
|
|
66
|
+
/** Why the line cannot be followed (a `--project` with no directory). Nothing is recorded for a comment with one. */
|
|
67
|
+
error?: string;
|
|
50
68
|
};
|
|
51
69
|
/**
|
|
52
70
|
* The `/tslaws accept ...` and `/tslaws reject ...` lines of a comment. Names are law names or `file::name` keys,
|
|
53
71
|
* separated by spaces or commas; a name with spaces is written in backticks or quotes.
|
|
54
72
|
*/
|
|
55
73
|
export declare function parseCommands(body: string): Command[];
|
|
56
|
-
/**
|
|
74
|
+
/** A proposal's key from the repository root: the project's path, then the project-relative `file::name`. */
|
|
75
|
+
export declare function repoKey(p: Proposal): string;
|
|
76
|
+
/**
|
|
77
|
+
* The proposals a command names. A name is a key from the repository root (`packages/a/src/x.laws.ts::name`), a
|
|
78
|
+
* project-relative `file::name` key, or a law name; the first form that matches decides, and a name that still matches
|
|
79
|
+
* more than one proposal (in several files or several projects) is ambiguous. `--project` limits the proposals first.
|
|
80
|
+
*/
|
|
57
81
|
export declare function resolveNames(proposals: Proposal[], command: Command): {
|
|
58
82
|
matched: Proposal[];
|
|
59
83
|
unknown: string[];
|
|
@@ -64,6 +88,11 @@ export interface ApprovalRecord {
|
|
|
64
88
|
by: string;
|
|
65
89
|
/** The head commit the person saw. */
|
|
66
90
|
sha: string;
|
|
91
|
+
/**
|
|
92
|
+
* The project the record is about, as its path in the repository ('' for the root). A record counts only for that
|
|
93
|
+
* project. Absent (a record written before projects were told apart) means the root.
|
|
94
|
+
*/
|
|
95
|
+
project?: string;
|
|
67
96
|
/** key and fingerprint of each proposal the record covers. */
|
|
68
97
|
items: {
|
|
69
98
|
key: string;
|
|
@@ -93,10 +122,12 @@ export interface IssueComment {
|
|
|
93
122
|
*/
|
|
94
123
|
export declare function readApprovals(comments: IssueComment[], bot: string): ApprovalRecord[];
|
|
95
124
|
/**
|
|
96
|
-
* The fingerprints accepted by the records, latest word wins: a later reject withdraws an earlier
|
|
97
|
-
* fingerprint. A fingerprint names one version of a law, so an edit after the accept leaves the new
|
|
125
|
+
* The fingerprints accepted by the records for one project, latest word wins: a later reject withdraws an earlier
|
|
126
|
+
* accept of the same fingerprint. A fingerprint names one version of a law, so an edit after the accept leaves the new
|
|
127
|
+
* version unaccepted. Only records of `project` count (default the root, which also takes records with no project), so
|
|
128
|
+
* an accept of a law in one project never accepts the same-named or same-fingerprint law of another.
|
|
98
129
|
*/
|
|
99
|
-
export declare function acceptedFingerprints(records: ApprovalRecord[]): Map<string, string>;
|
|
130
|
+
export declare function acceptedFingerprints(records: ApprovalRecord[], project?: string): Map<string, string>;
|
|
100
131
|
export interface Decision {
|
|
101
132
|
/** Fingerprints to write to the lock. */
|
|
102
133
|
accept: Set<string>;
|
|
@@ -121,3 +152,16 @@ export declare const stickyMarker = "<!-- tslaws-proposals -->";
|
|
|
121
152
|
export declare function stickyMarkerFor(project?: string): string;
|
|
122
153
|
/** The sticky pull request comment: every proposal, what it did, and whether it will be accepted on merge. */
|
|
123
154
|
export declare function renderSticky(proposals: Proposal[], config: GithubConfig, approvals: Map<string, string>, link: (p: Proposal) => string, project?: string): string;
|
|
155
|
+
export interface StickySection {
|
|
156
|
+
/** The project's path in the repository ('' for the root). */
|
|
157
|
+
project: string;
|
|
158
|
+
proposals: Proposal[];
|
|
159
|
+
config: GithubConfig;
|
|
160
|
+
approvals: Map<string, string>;
|
|
161
|
+
link: (p: Proposal) => string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* One sticky comment for a monorepo root run: a section per project that has proposals, and one line naming the rest.
|
|
165
|
+
* `marker` is the comment's own marker (the root's), so the per-project comments of single-project runs stay separate.
|
|
166
|
+
*/
|
|
167
|
+
export declare function renderStickyAll(sections: StickySection[], marker: string): string;
|