tslaws 0.10.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 +7 -2
- package/bin/tslaws.js +8 -2
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +25 -5
- 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 +211 -27
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +175 -34
- package/dist/compile.d.ts +15 -5
- package/dist/compile.js +198 -69
- package/dist/coverage.d.ts +38 -1
- package/dist/coverage.js +94 -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 +43 -1
- package/dist/projects.js +283 -11
- package/dist/promote.d.ts +56 -2
- package/dist/promote.js +429 -13
- package/dist/property.js +5 -1
- package/dist/propertyWorker.js +7 -0
- package/dist/proposals.d.ts +52 -4
- package/dist/proposals.js +484 -21
- package/dist/reporters.js +5 -1
- package/dist/runtimeEnv.d.ts +13 -5
- package/dist/runtimeEnv.js +48 -10
- 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/hooks/claude-hook.mjs +2 -0
- package/package.json +18 -6
package/dist/cli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createInterface } from 'node:readline/promises';
|
|
2
|
-
import { readFileSync, watch } from 'node:fs';
|
|
2
|
+
import { existsSync, readFileSync, watch } from 'node:fs';
|
|
3
3
|
import { join, relative, resolve, sep } from 'node:path';
|
|
4
4
|
import { resolveEngine } from "./browser.js";
|
|
5
5
|
import { bundledCompiler, checkoutCompiler } from "./bundled.js";
|
|
6
|
-
import { check, exemptionsOf } from "./check.js";
|
|
6
|
+
import { certificatesToAccept, check, exemptionsOf } from "./check.js";
|
|
7
7
|
import { readManifest } from "./compile.js";
|
|
8
8
|
import { hintFor } from "./hints.js";
|
|
9
9
|
import { discoverLaws, discoverProposals, ignoredDirs } from "./lawFiles.js";
|
|
@@ -11,38 +11,45 @@ import { isProposedLawFile } from "./lawNames.js";
|
|
|
11
11
|
import { init, nextStep } from "./init.js";
|
|
12
12
|
import { listLawFiles, renderList } from "./list.js";
|
|
13
13
|
import { serveMcp } from "./mcp.js";
|
|
14
|
-
import { discoverProjects, isMonorepoRoot } from "./projects.js";
|
|
14
|
+
import { affectedProjects, changedSince, discoverProjects, isMonorepoRoot } from "./projects.js";
|
|
15
15
|
import { promoteFiles, promoteProposal } from "./promote.js";
|
|
16
16
|
import { addProposal, ProposalError } from "./proposals.js";
|
|
17
17
|
import { clearCorpus, listCorpus } from "./regressions.js";
|
|
18
18
|
import { proposalText, reporterNames, reportAs } from "./reporters.js";
|
|
19
19
|
import { readConfig } from "./coverage.js";
|
|
20
|
+
import { parseGithubConfig } from "./github.js";
|
|
20
21
|
import { migrateCommand, migrateUsage } from "./migrate/index.js";
|
|
21
22
|
import { mutate, renderMutation } from "./mutate.js";
|
|
22
23
|
import { mutateDefaults, resolveSettings } from "./settings.js";
|
|
23
24
|
import { serveUi } from "./ui.js";
|
|
24
25
|
import { acceptGate, defaultDuration, describeGrants, fileHash, grantFor, logDelegatedAccept, parseDuration, personOnly, revokeFor, } from "./delegation.js";
|
|
25
|
-
import {
|
|
26
|
+
import { certificateLabel } from "./certificates.js";
|
|
27
|
+
import { fileOfKey, lockFormat, lockOf, mergeScoped, readLock, scopeOf, writeLockValue } from "./lock.js";
|
|
26
28
|
import { lockLevels } from "./lawKinds.js";
|
|
29
|
+
import { securityUsage } from "./security/cli.js";
|
|
30
|
+
import { plural } from "./plural.js";
|
|
31
|
+
import { configureJobs } from "./pool.js";
|
|
27
32
|
const usage = `tslaws init [--force] scaffold tslaws.json, .gitignore, AGENTS.md, Claude Code hooks and a starter law (never writes the lock)
|
|
28
|
-
tslaws check [files...] [--reporter text|json|junit|github|ndjson] [--law NAME[,NAME]] [--json] [--summary] [--watch] [--runs N] [--seed N] [--no-prove] [--no-regressions] [--bound N] [--proof-timeout MS] [--property-timeout MS] [--proposed] [--compiler PATH] [--browser chromium|firefox|webkit]
|
|
33
|
+
tslaws check [files...] [--reporter text|json|junit|github|ndjson] [--law NAME[,NAME]] [--json] [--summary] [--watch] [--runs N] [--seed N] [--no-prove] [--certify] [--require-certify] [--no-regressions] [--no-sandbox] [--allow-e2e] [--bound N] [--proof-timeout MS] [--property-timeout MS] [--jobs N] [--proposed] [--compiler PATH] [--browser chromium|firefox|webkit]
|
|
29
34
|
tslaws ui [files...] [--port N] [--no-open] [--tab] open a dashboard of the laws in its own desktop window (--tab: a browser tab): tree, filters, search, source, live reruns on save
|
|
30
|
-
tslaws mutate [files...] [--max N] [--seed N] [--runs N] [--bound N] [--proof-timeout MS] [--property-timeout MS] [--browser ENGINE] [--json] mutation-test the laws: mutate covered code, report mutants no law kills
|
|
35
|
+
tslaws mutate [files...] [--max N] [--seed N] [--runs N] [--bound N] [--proof-timeout MS] [--property-timeout MS] [--jobs N] [--browser ENGINE] [--no-sandbox] [--allow-e2e] [--json] mutation-test the laws: mutate covered code, report mutants no law kills
|
|
31
36
|
tslaws regressions [list|clear] show or delete the stored counterexamples (.tslaws/regressions); check replays them first, --no-regressions skips them
|
|
32
37
|
tslaws accept [files...] record the current laws in tsc-laws.lock (people only: needs a terminal, or a live delegation; never under CI)
|
|
33
38
|
tslaws delegate grant [--for 1h|8h|1d|7d] [--root DIR] lend accept to an agent for a limited time (people only; default 8h, max 7d)
|
|
34
39
|
tslaws delegate revoke [--root DIR] withdraw the delegation for a project (people only)
|
|
35
40
|
tslaws delegate status list delegations and when they end
|
|
36
41
|
tslaws propose <file.ts> [--from PATH] write a proposal into .tslaws/proposals/ from PATH or stdin (outside the tree, git-ignored; never touches the lock or any other file)
|
|
37
|
-
tslaws promote <proposal> [--to PATH] move a proposal from .tslaws/proposals/ into the tree at a path you confirm (people only: needs a terminal; run accept afterwards). In-tree *.proposed.laws.ts files (the usual proposals) promote with --all or by name
|
|
42
|
+
tslaws promote <proposal> [--to PATH] [--yes] move a proposal from .tslaws/proposals/ into the tree at a path you confirm (people only: needs a terminal; run accept afterwards). It prints the imports and helper code it would add and asks first, and refuses an import of a file outside the project, under .tslaws/, node_modules or .git, or git-ignored; --yes adds it without asking (it is still printed; it never lets promote run without a terminal). In-tree *.proposed.laws.ts files (the usual proposals) promote with --all or by name
|
|
38
43
|
tslaws list [--json] the laws files and proposals of the project: the level each runs at (from its name, or its imports with levels: imports) and whether it is accepted, unaccepted or proposed (reads files and the lock; runs nothing)
|
|
39
|
-
tslaws github report|command|merge|verify accept laws on GitHub: flag and run each proposal on a pull request, record /tslaws accept comments, and write tsc-laws.lock on merge (CI only; see "github" in tslaws.json)
|
|
44
|
+
tslaws github report|command|merge|verify accept laws on GitHub: flag and run each proposal on a pull request, record /tslaws accept comments, and write tsc-laws.lock on merge or on demand (workflow_dispatch) (CI only; see "github" in tslaws.json)
|
|
40
45
|
tslaws mcp [--compiler PATH] serve check, check_proposed, explain and propose as Model Context Protocol tools on stdio (cannot accept, promote or touch the lock)
|
|
41
46
|
${migrateUsage}
|
|
47
|
+
${securityUsage}
|
|
42
48
|
|
|
43
|
-
In a monorepo (a root tslaws.json with "projects", or package.json/pnpm workspaces whose packages have a tslaws.json), run from the root: check, accept, list, mutate and
|
|
49
|
+
In a monorepo (a root tslaws.json with "projects", or package.json/pnpm workspaces whose packages have a tslaws.json), run from the root: check, accept, list, mutate, regressions and security deps run in every project, one after another, each with its own config and lock, and end with one summary line. --json and --reporter json print one object keyed by project path; --reporter ndjson tags each line with "project". init, ui, mcp, github, propose, promote, delegate, migrate and --watch run in one project: pick it with --project when the root has several.
|
|
44
50
|
--project run only in this project directory (repeat it, or comma-separate: --project packages/a,packages/b)
|
|
45
51
|
--filter run only in projects whose path matches this glob (repeatable; a leading ! excludes), for example --filter 'packages/*'
|
|
52
|
+
--changed run only the projects affected since the merge-base of this ref and HEAD (committed, staged and untracked changes): the projects holding a changed file and everything that depends on them; a root config change runs all. Combines with --project and --filter. In one project: runs only if something there changed. For example --changed origin/main
|
|
46
53
|
|
|
47
54
|
Without files, every *.laws.ts under the current directory (and every file the "laws" globs of tslaws.json pick that declares a law) is checked; with --proposed, the in-tree *.proposed.laws.ts files are (and any proposals in .tslaws/proposals/), with no lock and no coverage gate.
|
|
48
55
|
A laws file's level comes from its name by default: *.browser.laws.ts is a browser law, *.e2e.laws.ts an end-to-end law, anything else runs in Node. With "levels": "imports" in tslaws.json it comes from the import graph instead (tslaws/browser, tslaws/adapters/* or tslaws/e2e, directly or through the file's own modules), and the names are hints.
|
|
@@ -70,6 +77,7 @@ function parse(args) {
|
|
|
70
77
|
'bound',
|
|
71
78
|
'proof-timeout',
|
|
72
79
|
'property-timeout',
|
|
80
|
+
'jobs',
|
|
73
81
|
'browser',
|
|
74
82
|
'port',
|
|
75
83
|
'reporter',
|
|
@@ -82,10 +90,14 @@ function parse(args) {
|
|
|
82
90
|
'out',
|
|
83
91
|
'pr',
|
|
84
92
|
'config-from',
|
|
93
|
+
'results',
|
|
94
|
+
'results-out',
|
|
85
95
|
'head-sha',
|
|
86
96
|
'rerun-workflow',
|
|
87
97
|
'protect',
|
|
88
98
|
'project-path',
|
|
99
|
+
'fail-on',
|
|
100
|
+
'changed',
|
|
89
101
|
]);
|
|
90
102
|
for (let i = 0; i < args.length; i += 1) {
|
|
91
103
|
const arg = args[i];
|
|
@@ -120,7 +132,8 @@ function parse(args) {
|
|
|
120
132
|
arg === 'list' ||
|
|
121
133
|
arg === 'migrate' ||
|
|
122
134
|
arg === 'delegate' ||
|
|
123
|
-
arg === 'github'
|
|
135
|
+
arg === 'github' ||
|
|
136
|
+
arg === 'security'))
|
|
124
137
|
command = arg;
|
|
125
138
|
else
|
|
126
139
|
files.push(arg);
|
|
@@ -135,6 +148,8 @@ function describe(result) {
|
|
|
135
148
|
lines.push(` ${result.message}`);
|
|
136
149
|
if (result.assumptions !== undefined && result.assumptions.length > 0)
|
|
137
150
|
lines.push(` assuming: ${result.assumptions.join('; ')}`);
|
|
151
|
+
if (result.certificate !== undefined)
|
|
152
|
+
lines.push(` certificate: ${certificateLabel(result.certificate)}`);
|
|
138
153
|
const proposed = proposalText(result);
|
|
139
154
|
if (proposed !== undefined)
|
|
140
155
|
lines.push(` ${proposed}`);
|
|
@@ -158,9 +173,9 @@ function summarise(result) {
|
|
|
158
173
|
.replace(/\s+/g, ' ');
|
|
159
174
|
return `${result.status.toUpperCase()} ${result.name} (${result.file}:${result.line})${detail === '' ? '' : ` ${detail}`}`;
|
|
160
175
|
}
|
|
161
|
-
function totals(report) {
|
|
176
|
+
export function totals(report) {
|
|
162
177
|
const count = (status) => report.results.filter((r) => r.status === status).length;
|
|
163
|
-
return `${report.results.length}
|
|
178
|
+
return `${plural(report.results.length, 'law')}: ${count('proved')} proved, ${count('bounded')} bounded, ${count('tested')} tested, ${count('open')} open, ${count('failed')} failed, ${count('tampered')} tampered, ${plural(count('error'), 'error')}`;
|
|
164
179
|
}
|
|
165
180
|
function render(report, flags, project) {
|
|
166
181
|
const reporter = String(flags.get('reporter') ?? (flags.has('json') ? 'json' : 'text'));
|
|
@@ -204,7 +219,17 @@ function options(cwd, flags, chosen) {
|
|
|
204
219
|
compiler: String(flags.get('compiler') ?? process.env.TSC_LAWS_BIN ?? bundledCompiler() ?? checkoutCompiler(cwd) ?? 'tsc-laws'),
|
|
205
220
|
lockFile: join(cwd, 'tsc-laws.lock'),
|
|
206
221
|
noProve: flags.has('no-prove'),
|
|
222
|
+
// `--certify` turns certificates on (and keeps a "require" from tslaws.json); `--require-certify` makes them required.
|
|
223
|
+
certify: flags.has('require-certify')
|
|
224
|
+
? 'require'
|
|
225
|
+
: flags.has('certify')
|
|
226
|
+
? readConfig(cwd).certify === 'require'
|
|
227
|
+
? 'require'
|
|
228
|
+
: true
|
|
229
|
+
: undefined,
|
|
207
230
|
noRegressions: flags.has('no-regressions'),
|
|
231
|
+
sandbox: !flags.has('no-sandbox'),
|
|
232
|
+
allowE2e: flags.has('allow-e2e'),
|
|
208
233
|
only: typeof flags.get('law') === 'string' ? String(flags.get('law')).split(',').filter(Boolean) : undefined,
|
|
209
234
|
bound: settings.bound,
|
|
210
235
|
proofTimeoutMs: settings.proofTimeoutMs,
|
|
@@ -240,7 +265,7 @@ async function runCheck(cwd, flags, files, run = direct) {
|
|
|
240
265
|
run.out(`${JSON.stringify(run.tag === undefined ? event : { project: run.tag, ...event })}\n`);
|
|
241
266
|
}
|
|
242
267
|
: undefined;
|
|
243
|
-
const report = await check({ ...options(cwd, flags, chosen), onEvent }, !flags.has('proposed'));
|
|
268
|
+
const report = await check({ ...options(cwd, flags, chosen), partial: files.length > 0, onEvent }, !flags.has('proposed'));
|
|
244
269
|
run.out(render(report, flags, run.tag));
|
|
245
270
|
return report.ok ? 0 : 1;
|
|
246
271
|
}
|
|
@@ -307,8 +332,10 @@ export async function acceptCommand(cwd, flags, files, ctx) {
|
|
|
307
332
|
err('no laws files found (looking for *.laws.ts)\n');
|
|
308
333
|
return 1;
|
|
309
334
|
}
|
|
310
|
-
|
|
311
|
-
|
|
335
|
+
// A project that accepts laws on GitHub still lets a person accept by hand, unless it sets "github.local" to false.
|
|
336
|
+
const github = readConfig(cwd).github;
|
|
337
|
+
if (github !== undefined && !parseGithubConfig(github).local) {
|
|
338
|
+
err('this project accepts laws on GitHub only: tsc-laws.lock is written by the tslaws workflow, on merge or on demand (see "github" in tslaws.json, where "local" is false); propose the laws in a pull request instead\n');
|
|
312
339
|
return 1;
|
|
313
340
|
}
|
|
314
341
|
const gate = acceptGate({ isTTY: ctx.isTTY, env: ctx.env, root: cwd, now: ctx.now, home: ctx.home });
|
|
@@ -318,7 +345,7 @@ export async function acceptCommand(cwd, flags, files, ctx) {
|
|
|
318
345
|
}
|
|
319
346
|
const opts = options(cwd, flags, chosen);
|
|
320
347
|
const laws = readManifest(opts.compiler, opts.files, cwd);
|
|
321
|
-
out(`${laws.length}
|
|
348
|
+
out(`${plural(laws.length, 'law')} in ${plural(chosen.length, 'file')}:\n${laws.map((l) => ` ${l.file}:${l.line} ${l.name}`).join('\n')}\n`);
|
|
322
349
|
if (!gate.delegated) {
|
|
323
350
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
324
351
|
const answer = await rl.question('Write tsc-laws.lock? Type accept, yes or y to confirm: ');
|
|
@@ -336,7 +363,22 @@ export async function acceptCommand(cwd, flags, files, ctx) {
|
|
|
336
363
|
// tslaws/browser reads as tampered until a person accepts again. By name (the default) the lock is unchanged.
|
|
337
364
|
const mode = readConfig(cwd).levels ?? 'names';
|
|
338
365
|
const levels = lockLevels(cwd, laws, mode);
|
|
339
|
-
|
|
366
|
+
// Certificates enter the lock only for the proofs and problems of this run; see certificatesToAccept.
|
|
367
|
+
// Naming files accepts only those: the lock keeps every entry it has for the other files.
|
|
368
|
+
const held = readLock(opts.lockFile);
|
|
369
|
+
// The entries a partial accept keeps for the other files were hashed in the old format; keeping them under the new
|
|
370
|
+
// version would make every one of them read as changed. Only a full accept can write the whole lock again.
|
|
371
|
+
if (files.length > 0 && held !== undefined && (held.version ?? lockFormat) < lockFormat) {
|
|
372
|
+
out('Nothing written: lock format upgraded. The lock holds laws hashed in the old format for files you did not name; run `tslaws accept` without files to record them all.\n');
|
|
373
|
+
return 1;
|
|
374
|
+
}
|
|
375
|
+
const scope = scopeOf(chosen);
|
|
376
|
+
const heldHere = files.length === 0
|
|
377
|
+
? held?.certificates
|
|
378
|
+
: Object.fromEntries(Object.entries(held?.certificates ?? {}).filter(([key]) => scope.has(fileOfKey(key))));
|
|
379
|
+
const certificates = await certificatesToAccept(opts, laws, heldHere, out);
|
|
380
|
+
const next = lockOf(laws, exempt, levels, certificates);
|
|
381
|
+
writeLockValue(opts.lockFile, files.length === 0 ? next : mergeScoped(held, scope, next));
|
|
340
382
|
out('tsc-laws.lock written\n');
|
|
341
383
|
if (gate.delegated) {
|
|
342
384
|
logDelegatedAccept(cwd, gate.grant, before, fileHash(opts.lockFile), ctx.now ?? new Date());
|
|
@@ -458,6 +500,7 @@ export async function promoteCommand(cwd, flags, files, ctx) {
|
|
|
458
500
|
err('--to takes one path, for one proposal\n');
|
|
459
501
|
return 1;
|
|
460
502
|
}
|
|
503
|
+
const yes = flags.get('yes') === true;
|
|
461
504
|
const rl = ctx.ask === undefined ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
|
|
462
505
|
const ask = ctx.ask ?? ((question) => rl.question(question));
|
|
463
506
|
const checkFile = ctx.checkFile ??
|
|
@@ -470,11 +513,11 @@ export async function promoteCommand(cwd, flags, files, ctx) {
|
|
|
470
513
|
for (const file of chosen) {
|
|
471
514
|
const rel = relative(cwd, resolve(cwd, file)).replaceAll('\\', '/');
|
|
472
515
|
if (isProposedLawFile(rel) && !file.startsWith('.tslaws')) {
|
|
473
|
-
await promoteFiles({ cwd, ask, out, checkFile }, [rel]);
|
|
516
|
+
await promoteFiles({ cwd, ask, out, checkFile, yes }, [rel]);
|
|
474
517
|
continue;
|
|
475
518
|
}
|
|
476
519
|
try {
|
|
477
|
-
await promoteProposal({ cwd, ask, out, checkFile }, file, to);
|
|
520
|
+
await promoteProposal({ cwd, ask, out, checkFile, yes }, file, to);
|
|
478
521
|
}
|
|
479
522
|
catch (error) {
|
|
480
523
|
if (!(error instanceof ProposalError))
|
|
@@ -491,20 +534,41 @@ export async function promoteCommand(cwd, flags, files, ctx) {
|
|
|
491
534
|
}
|
|
492
535
|
const list = (projects) => projects.map((p) => (p.path === '' ? '.' : p.path)).join(', ');
|
|
493
536
|
/** `undefined` for an ordinary single-project run: no project flags, and the directory is not a monorepo root. */
|
|
494
|
-
function selectProjects(cwd, only, filter) {
|
|
537
|
+
function selectProjects(cwd, only, filter, changed) {
|
|
495
538
|
const asked = only.length > 0 || filter.length > 0;
|
|
496
539
|
const monorepo = isMonorepoRoot(cwd);
|
|
497
|
-
if (!asked && !monorepo)
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
540
|
+
if (!asked && !monorepo) {
|
|
541
|
+
if (changed === undefined)
|
|
542
|
+
return undefined;
|
|
543
|
+
const { files } = changedSince(cwd, changed);
|
|
544
|
+
if (files.length > 0)
|
|
545
|
+
return undefined;
|
|
546
|
+
return {
|
|
547
|
+
chosen: [],
|
|
548
|
+
all: [],
|
|
549
|
+
fanOut: false,
|
|
550
|
+
notes: [`--changed ${changed}: nothing changed in this project, nothing to run`],
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
// A standalone project ("standalone": true) is in `all`, but a run covers it only when --project names it.
|
|
554
|
+
const all = discoverProjects(cwd, { standalone: true });
|
|
555
|
+
let chosen = asked ? discoverProjects(cwd, { only, filter }) : all.filter((p) => !p.standalone);
|
|
501
556
|
if (chosen.length === 0) {
|
|
502
557
|
const named = [...only.map((p) => `--project ${p}`), ...filter.map((g) => `--filter ${g}`)].join(' ');
|
|
503
558
|
throw new Error(all.length === 0
|
|
504
559
|
? 'no tslaws project found here (a project is a directory with a tslaws.json; see "projects" in tslaws.json)'
|
|
505
|
-
:
|
|
506
|
-
|
|
507
|
-
|
|
560
|
+
: asked
|
|
561
|
+
? `no project matches ${named}; projects: ${list(all)}`
|
|
562
|
+
: `every project here is standalone ("standalone": true), so a root run covers none of them: pick one with --project <dir> (${list(all)})`);
|
|
563
|
+
}
|
|
564
|
+
const notes = [];
|
|
565
|
+
if (changed !== undefined) {
|
|
566
|
+
const { base, files } = changedSince(cwd, changed);
|
|
567
|
+
const reasons = new Map(affectedProjects(cwd, files).map((a) => [a.project.path, a.reason]));
|
|
568
|
+
chosen = chosen.filter((p) => reasons.has(p.path));
|
|
569
|
+
notes.push(`--changed ${changed} (merge-base ${base.slice(0, 8)}, ${files.length} changed file${files.length === 1 ? '' : 's'}): ${chosen.length} of ${all.length} project${all.length === 1 ? '' : 's'} selected`, ...chosen.map((p) => ` ${p.path === '' ? '.' : p.path}: ${reasons.get(p.path)}`));
|
|
570
|
+
}
|
|
571
|
+
return { chosen, all, fanOut: monorepo || chosen.some((p) => p.path !== ''), notes };
|
|
508
572
|
}
|
|
509
573
|
/** The projects nested below `project`, relative to it. */
|
|
510
574
|
function nestedIn(project, all) {
|
|
@@ -514,7 +578,7 @@ function nestedIn(project, all) {
|
|
|
514
578
|
.map((other) => other.path.slice(prefix.length));
|
|
515
579
|
}
|
|
516
580
|
/** Commands that run once for every project of a monorepo; the rest run in one project. */
|
|
517
|
-
const fansOut = new Set(['check', 'accept', 'list', 'mutate', 'regressions']);
|
|
581
|
+
const fansOut = new Set(['check', 'accept', 'list', 'mutate', 'regressions', 'security']);
|
|
518
582
|
/** How a root run lays out machine output: one JSON object keyed by project, or ndjson lines tagged with `project`. */
|
|
519
583
|
function machineOf(command, flags) {
|
|
520
584
|
if (command === 'check') {
|
|
@@ -523,7 +587,7 @@ function machineOf(command, flags) {
|
|
|
523
587
|
throw new Error('--reporter junit writes one XML document per project: pick one project with --project <dir>');
|
|
524
588
|
return reporter === 'json' || reporter === 'ndjson' ? reporter : 'text';
|
|
525
589
|
}
|
|
526
|
-
return (command === 'list' || command === 'mutate') && flags.has('json') ? 'json' : 'text';
|
|
590
|
+
return (command === 'list' || command === 'mutate' || command === 'security') && flags.has('json') ? 'json' : 'text';
|
|
527
591
|
}
|
|
528
592
|
/** One project at a time, each under a `── path ──` header, then one summary line. Nonzero if any project failed. */
|
|
529
593
|
async function runProjects(selection, machine, run) {
|
|
@@ -577,11 +641,21 @@ export async function main(args) {
|
|
|
577
641
|
}
|
|
578
642
|
const { command, flags, files, projects, filters } = parse(args);
|
|
579
643
|
const cwd = process.cwd();
|
|
644
|
+
if (flags.has('jobs')) {
|
|
645
|
+
const given = Number(flags.get('jobs'));
|
|
646
|
+
if (!Number.isInteger(given) || given < 1) {
|
|
647
|
+
stderrWrite(`--jobs must be an integer of at least 1, got ${JSON.stringify(flags.get('jobs'))}
|
|
648
|
+
`);
|
|
649
|
+
return 1;
|
|
650
|
+
}
|
|
651
|
+
configureJobs({ flag: given });
|
|
652
|
+
}
|
|
653
|
+
const changed = flags.has('changed') ? String(flags.get('changed')) : undefined;
|
|
580
654
|
// `init --project .` scaffolds right here, in a root that has projects or not.
|
|
581
655
|
const here = command === 'init' && projects.some((p) => p === '.' || p === './');
|
|
582
656
|
let selection;
|
|
583
657
|
try {
|
|
584
|
-
selection = here ? undefined : selectProjects(cwd, projects, filters);
|
|
658
|
+
selection = here ? undefined : selectProjects(cwd, projects, filters, changed);
|
|
585
659
|
}
|
|
586
660
|
catch (error) {
|
|
587
661
|
stderrWrite(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
@@ -589,10 +663,22 @@ export async function main(args) {
|
|
|
589
663
|
}
|
|
590
664
|
if (selection === undefined)
|
|
591
665
|
return runOne(command, flags, files, cwd, direct);
|
|
666
|
+
// The decision goes to stderr so that machine output on stdout stays whole.
|
|
667
|
+
for (const note of selection.notes)
|
|
668
|
+
stderrWrite(`${note}\n`);
|
|
669
|
+
if (selection.chosen.length === 0) {
|
|
670
|
+
if (flags.has('json') || flags.get('reporter') === 'json')
|
|
671
|
+
stdoutWrite('{}\n');
|
|
672
|
+
return 0;
|
|
673
|
+
}
|
|
674
|
+
// From the root with no --project: every project in one process (one comment, one commit for all the locks).
|
|
675
|
+
if (command === 'github' && projects.length === 0 && isMonorepoRoot(cwd))
|
|
676
|
+
return githubRoot(flags, files, cwd, selection);
|
|
592
677
|
// One project and a reporter that writes one document (junit) runs plainly: there is nothing to join.
|
|
593
678
|
const oneDocument = command === 'check' && flags.get('reporter') === 'junit' && selection.chosen.length === 1 && !flags.has('watch');
|
|
594
679
|
if (selection.fanOut && fansOut.has(command) && !flags.has('watch') && !oneDocument) {
|
|
595
|
-
|
|
680
|
+
// `security deps` names a subcommand, not a file.
|
|
681
|
+
if (files.length > 0 && command !== 'regressions' && command !== 'security') {
|
|
596
682
|
stderrWrite(`name files only inside one project: run \`tslaws ${command} ${files[0]}\` there, or pick it with --project <dir>\n`);
|
|
597
683
|
return 1;
|
|
598
684
|
}
|
|
@@ -613,6 +699,49 @@ export async function main(args) {
|
|
|
613
699
|
const [only] = selection.chosen;
|
|
614
700
|
return runOne(command, flags, files, only.dir, { ...direct, skip: nestedIn(only, selection.all) });
|
|
615
701
|
}
|
|
702
|
+
/**
|
|
703
|
+
* `tslaws github <mode>` from a monorepo root: every selected project in one run. Each project keeps its own options
|
|
704
|
+
* and its own `github` settings (read in githubCli.ts); the projects nested in another are left out of that one's laws.
|
|
705
|
+
*/
|
|
706
|
+
async function githubRoot(flags, files, cwd, selection) {
|
|
707
|
+
const { githubCommand, projectPathOf, joinRepo } = await import("./githubCli.js");
|
|
708
|
+
// The token stays with tslaws, as in a single project (see runOne): laws run in a child that never gets it.
|
|
709
|
+
const env = { ...process.env };
|
|
710
|
+
delete process.env.GITHUB_TOKEN;
|
|
711
|
+
delete process.env.GH_TOKEN;
|
|
712
|
+
const trusted = flags.get('config-from');
|
|
713
|
+
const prefix = projectPathOf(cwd, flags.get('project-path'));
|
|
714
|
+
const optionsOf = (project) => {
|
|
715
|
+
const skip = nestedIn(project, selection.all);
|
|
716
|
+
const chosen = options(project.dir, flags, outside(discover(project.dir, false), skip));
|
|
717
|
+
// With --config-from the projects are a pull request's files, read as data: never run a compiler from among them.
|
|
718
|
+
if (typeof trusted === 'string' && chosen.compiler === checkoutCompiler(project.dir))
|
|
719
|
+
chosen.compiler = checkoutCompiler(resolve(cwd, trusted, project.path)) ?? 'tsc-laws';
|
|
720
|
+
return chosen;
|
|
721
|
+
};
|
|
722
|
+
return githubCommand(files[0], {
|
|
723
|
+
cwd,
|
|
724
|
+
projectPath: prefix,
|
|
725
|
+
options: optionsOf(selection.chosen[0]),
|
|
726
|
+
projects: selection.chosen.map((project) => ({
|
|
727
|
+
cwd: project.dir,
|
|
728
|
+
rel: project.path,
|
|
729
|
+
path: joinRepo(prefix, project.path),
|
|
730
|
+
options: optionsOf(project),
|
|
731
|
+
})),
|
|
732
|
+
discovered: selection.all.map((project) => project.path),
|
|
733
|
+
optionsFor: (rel) => {
|
|
734
|
+
// A directory the files here no longer discover still has the laws it had: merge checks it if the base had it.
|
|
735
|
+
const project = selection.all.find((candidate) => candidate.path === rel) ??
|
|
736
|
+
(existsSync(join(cwd, rel, 'tslaws.json')) ? { dir: join(cwd, rel), path: rel, standalone: false } : undefined);
|
|
737
|
+
return project === undefined ? undefined : optionsOf(project);
|
|
738
|
+
},
|
|
739
|
+
env,
|
|
740
|
+
flags,
|
|
741
|
+
out: (text) => void process.stdout.write(text),
|
|
742
|
+
err: (text) => void process.stderr.write(text),
|
|
743
|
+
});
|
|
744
|
+
}
|
|
616
745
|
/** One command in one project directory. */
|
|
617
746
|
async function runOne(command, flags, files, cwd, run) {
|
|
618
747
|
if (command === 'init') {
|
|
@@ -621,8 +750,8 @@ async function runOne(command, flags, files, cwd, run) {
|
|
|
621
750
|
}
|
|
622
751
|
if (command === 'github') {
|
|
623
752
|
const { githubCommand, projectPathOf } = await import("./githubCli.js");
|
|
624
|
-
// The token stays with tslaws: laws run in
|
|
625
|
-
//
|
|
753
|
+
// The token stays with tslaws: the laws run in a child process whose environment is an allowlist (see isolate.ts), so
|
|
754
|
+
// a law under test cannot read it from process.env or /proc/self/environ and act as the bot.
|
|
626
755
|
const env = { ...process.env };
|
|
627
756
|
delete process.env.GITHUB_TOKEN;
|
|
628
757
|
delete process.env.GH_TOKEN;
|
|
@@ -647,6 +776,10 @@ async function runOne(command, flags, files, cwd, run) {
|
|
|
647
776
|
return delegateCommand(cwd, files[0], flags, { isTTY: process.stdin.isTTY === true, env: process.env });
|
|
648
777
|
if (command === 'migrate')
|
|
649
778
|
return migrateCommand(cwd, files[0], files.slice(1), flags, (text) => process.stdout.write(text));
|
|
779
|
+
if (command === 'security') {
|
|
780
|
+
const { securityCommand } = await import("./security/cli.js");
|
|
781
|
+
return securityCommand(cwd, files, flags, run.out, undefined, run.skip);
|
|
782
|
+
}
|
|
650
783
|
if (command === 'mcp')
|
|
651
784
|
return serveMcp({ cwd, compiler: options(cwd, flags, []).compiler });
|
|
652
785
|
if (command === 'promote')
|
|
@@ -679,6 +812,8 @@ async function runOne(command, flags, files, cwd, run) {
|
|
|
679
812
|
compiler: options(cwd, flags, chosen).compiler,
|
|
680
813
|
max: Number(flags.get('max') ?? 50),
|
|
681
814
|
seed: flags.has('seed') ? Number(flags.get('seed')) : undefined,
|
|
815
|
+
sandbox: !flags.has('no-sandbox'),
|
|
816
|
+
allowE2e: flags.has('allow-e2e'),
|
|
682
817
|
onProgress: flags.has('json') ? undefined : (line) => process.stderr.write(`${line}\n`),
|
|
683
818
|
});
|
|
684
819
|
run.out(flags.has('json') ? `${JSON.stringify(report, null, 2)}\n` : renderMutation(report));
|
|
@@ -712,7 +847,13 @@ async function runOne(command, flags, files, cwd, run) {
|
|
|
712
847
|
open: !flags.has('no-open'),
|
|
713
848
|
appWindow: !flags.has('tab'),
|
|
714
849
|
// A watcher sees a browser page only if it stays as the law left it for a moment.
|
|
715
|
-
run: (only, onEvent, laws) => check({
|
|
850
|
+
run: (only, onEvent, laws) => check({
|
|
851
|
+
...options(cwd, flags, only ?? chosen),
|
|
852
|
+
partial: only !== undefined || files.length > 0,
|
|
853
|
+
only: laws,
|
|
854
|
+
onEvent,
|
|
855
|
+
browserPauseMs: 120,
|
|
856
|
+
}, !flags.has('proposed')),
|
|
716
857
|
log: (line) => process.stdout.write(`${line}\n`),
|
|
717
858
|
});
|
|
718
859
|
}
|
package/dist/compile.d.ts
CHANGED
|
@@ -23,11 +23,21 @@ export declare function readManifest(compiler: string, files: string[], cwd: str
|
|
|
23
23
|
* error rather than an arbitrary flag handed to the compiler. `strict` is the one default these can override.
|
|
24
24
|
*/
|
|
25
25
|
export declare function compilerFlags(options: Record<string, unknown> | undefined): string[];
|
|
26
|
-
/** Lowers every `.js` file the native compiler emitted into `dir` as ES modules, which is how `import.meta` is allowed. */
|
|
27
|
-
export declare function lowerEmittedModules(dir: string): void;
|
|
28
26
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
27
|
+
* Lowers what the native compiler emitted into `dir` as ES modules, which is how `import.meta` is allowed: `.js` becomes
|
|
28
|
+
* CommonJS and the `import.meta` of a `.mjs` (from a `.mts`, kept as an ES module Node can load) is rewritten in place.
|
|
29
|
+
* `outDir` and `root` say where `dir` sits and what it mirrors, so `import.meta` can name the source. Returns one line
|
|
30
|
+
* per module that cannot be lowered.
|
|
31
|
+
*/
|
|
32
|
+
export declare function lowerEmittedModules(dir: string, where?: {
|
|
33
|
+
outDir?: string;
|
|
34
|
+
root?: string;
|
|
35
|
+
}): string[];
|
|
36
|
+
/**
|
|
37
|
+
* Compiles `files` to CommonJS plus declarations in `.tslaws/out` under `cwd`, so `node_modules` still resolves.
|
|
38
|
+
* Module resolution follows the project's tsconfig (see tsconfigResolve.ts), for the compiler and, through the runtime
|
|
39
|
+
* hooks, for Node when it loads the output. The built-in compiler always reads the project as ES modules and lowers the
|
|
40
|
+
* output. The native compiler does so only for a project that uses `import.meta` (it reports TS1343 as CommonJS), so
|
|
41
|
+
* every other project builds exactly as before.
|
|
32
42
|
*/
|
|
33
43
|
export declare function build(compiler: string, files: string[], cwd: string): BuildResult;
|