@prestack/thread 0.0.3 → 0.1.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/CHANGELOG.md +98 -0
- package/dist/core/{asking.d.ts → answers.d.ts} +6 -14
- package/dist/core/{asking.js → answers.js} +13 -332
- package/dist/core/{asking.ts → answers.ts} +14 -357
- package/dist/core/attach.js +2 -2
- package/dist/core/attach.ts +2 -3
- package/dist/core/chain.js +4 -11
- package/dist/core/chain.ts +4 -3
- package/dist/core/client.d.ts +57 -0
- package/dist/core/client.js +186 -0
- package/dist/core/client.ts +227 -0
- package/dist/core/descend.d.ts +2 -0
- package/dist/core/descend.js +109 -16
- package/dist/core/descend.ts +120 -16
- package/dist/core/files.d.ts +45 -0
- package/dist/core/files.js +95 -0
- package/dist/core/files.ts +137 -0
- package/dist/core/init.d.ts +1 -0
- package/dist/core/init.js +10 -2
- package/dist/core/init.ts +8 -2
- package/dist/core/invoked.js +1 -1
- package/dist/core/invoked.ts +1 -1
- package/dist/core/rows.d.ts +2 -0
- package/dist/core/rows.js +65 -0
- package/dist/core/rows.ts +58 -0
- package/dist/core/tree.js +1 -1
- package/dist/core/tree.ts +1 -1
- package/dist/derivation/attach.js +0 -12
- package/dist/derivation/attach.ts +0 -12
- package/dist/derivation/generators/build.js +8 -7
- package/dist/derivation/generators/build.ts +8 -7
- package/dist/derivation/generators/release.d.ts +1 -1
- package/dist/derivation/generators/release.js +15 -23
- package/dist/derivation/generators/release.ts +15 -15
- package/dist/integrations/attach.js +1 -19
- package/dist/integrations/attach.ts +1 -19
- package/dist/integrations/generators/read.js +2 -2
- package/dist/integrations/generators/read.ts +4 -4
- package/dist/integrations/generators/vault.js +4 -12
- package/dist/integrations/generators/vault.ts +4 -4
- package/dist/integrations/module.js +5 -3
- package/dist/integrations/module.ts +5 -3
- package/dist/integrations/vault.js +5 -5
- package/dist/integrations/vault.ts +5 -5
- package/dist/integrity/attach.js +0 -12
- package/dist/integrity/attach.ts +0 -12
- package/dist/integrity/check-threads.js +1 -1
- package/dist/integrity/check-threads.ts +1 -1
- package/dist/integrity/constraint.d.ts +11 -2
- package/dist/integrity/constraint.js +163 -20
- package/dist/integrity/constraint.ts +174 -22
- package/dist/integrity/generators/compiler.js +1 -1
- package/dist/integrity/generators/compiler.ts +1 -1
- package/dist/integrity/generators/gate.js +8 -16
- package/dist/integrity/generators/gate.ts +8 -7
- package/dist/integrity/generators/publish.js +14 -26
- package/dist/integrity/generators/publish.ts +14 -17
- package/dist/integrity/generators/trial.d.ts +2 -2
- package/dist/integrity/generators/trial.js +108 -50
- package/dist/integrity/generators/trial.ts +107 -48
- package/dist/integrity/lint.js +3 -3
- package/dist/integrity/lint.ts +3 -3
- package/dist/integrity/lsp/diagnostics.js +1 -1
- package/dist/integrity/lsp/diagnostics.ts +1 -1
- package/dist/integrity/lsp/lint.js +1 -1
- package/dist/integrity/lsp/lint.ts +1 -1
- package/dist/integrity/slopnator.d.ts +1 -14
- package/dist/integrity/slopnator.js +8 -40
- package/dist/integrity/slopnator.ts +9 -51
- package/dist/integrity/slopnators/sl_broken_lineage.js +4 -2
- package/dist/integrity/slopnators/sl_broken_lineage.ts +4 -2
- package/dist/integrity/slopnators/sl_declared_elsewhere.js +24 -3
- package/dist/integrity/slopnators/sl_declared_elsewhere.ts +24 -3
- package/dist/integrity/slopnators/sl_derived_drift.js +10 -4
- package/dist/integrity/slopnators/sl_derived_drift.ts +10 -4
- package/dist/integrity/slopnators/sl_inert_island.js +7 -13
- package/dist/integrity/slopnators/sl_inert_island.ts +7 -16
- package/dist/integrity/slopnators/sl_inert_slopnator.js +8 -8
- package/dist/integrity/slopnators/sl_inert_slopnator.ts +8 -8
- package/dist/integrity/slopnators/sl_missing_row.js +14 -9
- package/dist/integrity/slopnators/sl_missing_row.ts +14 -10
- package/dist/integrity/slopnators/sl_no_child_process.js +8 -8
- package/dist/integrity/slopnators/sl_no_child_process.ts +8 -8
- package/dist/integrity/slopnators/sl_no_import_cycle.js +1 -1
- package/dist/integrity/slopnators/sl_no_import_cycle.ts +1 -1
- package/dist/integrity/slopnators/sl_no_such_command.js +20 -5
- package/dist/integrity/slopnators/sl_no_such_command.ts +22 -5
- package/dist/integrity/slopnators/sl_only_takes_a_literal.js +8 -8
- package/dist/integrity/slopnators/sl_only_takes_a_literal.ts +8 -8
- package/dist/integrity/slopnators/sl_stale_path.js +91 -18
- package/dist/integrity/slopnators/sl_stale_path.ts +97 -18
- package/dist/integrity/slopnators/sl_twice_meant.js +25 -2
- package/dist/integrity/slopnators/sl_twice_meant.ts +28 -2
- package/dist/integrity/slopnators/sl_twice_parented.js +26 -5
- package/dist/integrity/slopnators/sl_twice_parented.ts +26 -5
- package/dist/integrity/slopnators/sl_undeclared_node.js +18 -2
- package/dist/integrity/slopnators/sl_undeclared_node.ts +18 -2
- package/dist/integrity/slopnators/sl_undeclared_operation.js +3 -1
- package/dist/integrity/slopnators/sl_undeclared_operation.ts +3 -1
- package/dist/integrity/slopnators/sl_undeclared_variant.js +6 -2
- package/dist/integrity/slopnators/sl_undeclared_variant.ts +6 -2
- package/dist/integrity/slopnators/sl_ungoverned_island.js +3 -4
- package/dist/integrity/slopnators/sl_ungoverned_island.ts +3 -4
- package/dist/integrity/slopnators/sl_unkept_rows.js +1 -1
- package/dist/integrity/slopnators/sl_unkept_rows.ts +1 -1
- package/dist/integrity/slopnators/sl_unpaired_member.js +13 -8
- package/dist/integrity/slopnators/sl_unpaired_member.ts +16 -8
- package/dist/integrity/slopnators/sl_unpaired_slopnator.js +16 -3
- package/dist/integrity/slopnators/sl_unpaired_slopnator.ts +16 -3
- package/dist/integrity/slopnators/sl_unthreaded.d.ts +1 -0
- package/dist/integrity/slopnators/sl_unthreaded.js +18 -10
- package/dist/integrity/slopnators/sl_unthreaded.ts +19 -11
- package/dist/integrity/slopnators/sl_untranslated_key.js +1 -1
- package/dist/integrity/slopnators/sl_untranslated_key.ts +1 -1
- package/dist/integrity/slopnators/sl_unversioned.js +16 -2
- package/dist/integrity/slopnators/sl_unversioned.ts +16 -2
- package/dist/integrity/sweep.js +17 -3
- package/dist/integrity/sweep.ts +20 -3
- package/dist/knowledge/attach.js +0 -6
- package/dist/knowledge/attach.ts +0 -6
- package/dist/knowledge/generators/docsgen.js +12 -3
- package/dist/knowledge/generators/docsgen.ts +12 -2
- package/dist/knowledge/generators/glossary.js +1 -1
- package/dist/knowledge/generators/glossary.ts +1 -1
- package/dist/operations/attach.js +2 -26
- package/dist/operations/attach.ts +2 -27
- package/dist/operations/dispatch.js +2 -3
- package/dist/operations/dispatch.ts +2 -3
- package/dist/operations/generators/capability.js +4 -7
- package/dist/operations/generators/capability.ts +3 -6
- package/dist/operations/generators/compile.js +8 -13
- package/dist/operations/generators/compile.ts +8 -4
- package/dist/operations/generators/permits.js +4 -13
- package/dist/operations/generators/permits.ts +3 -3
- package/dist/operations/generators/seed.js +5 -2
- package/dist/operations/generators/seed.ts +6 -2
- package/dist/operations/generators/trial.js +10 -10
- package/dist/operations/generators/trial.ts +10 -10
- package/dist/operations/http.js +4 -1
- package/dist/operations/http.ts +6 -1
- package/package.json +2 -2
- package/dist/core/cli.d.ts +0 -2
- package/dist/core/cli.js +0 -1761
- package/dist/core/cli.ts +0 -2004
- package/dist/core/generators/meta.d.ts +0 -2
- package/dist/core/generators/meta.js +0 -829
- package/dist/core/generators/meta.ts +0 -1006
- package/dist/derivation/generators/derivation.d.ts +0 -3
- package/dist/derivation/generators/derivation.js +0 -273
- package/dist/derivation/generators/derivation.ts +0 -347
- package/dist/derivation/makers/release.d.ts +0 -1
- package/dist/derivation/makers/release.js +0 -107
- package/dist/derivation/makers/release.ts +0 -135
- package/dist/integrations/generators/secret.d.ts +0 -1
- package/dist/integrations/generators/secret.js +0 -233
- package/dist/integrations/generators/secret.ts +0 -289
- package/dist/integrations/generators/target.d.ts +0 -1
- package/dist/integrations/generators/target.js +0 -775
- package/dist/integrations/generators/target.ts +0 -944
- package/dist/integrity/generators/rule.d.ts +0 -2
- package/dist/integrity/generators/rule.js +0 -213
- package/dist/integrity/generators/rule.ts +0 -271
- package/dist/integrity/generators/seal.d.ts +0 -4
- package/dist/integrity/generators/seal.js +0 -101
- package/dist/integrity/generators/seal.ts +0 -117
- package/dist/integrity/sealed.d.ts +0 -1
- package/dist/integrity/sealed.js +0 -56
- package/dist/integrity/sealed.ts +0 -56
- package/dist/knowledge/generators/skills.d.ts +0 -1
- package/dist/knowledge/generators/skills.js +0 -222
- package/dist/knowledge/generators/skills.ts +0 -263
- package/dist/operations/generators/grant.d.ts +0 -1
- package/dist/operations/generators/grant.js +0 -267
- package/dist/operations/generators/grant.ts +0 -336
- package/dist/operations/generators/operation.d.ts +0 -1
- package/dist/operations/generators/operation.js +0 -811
- package/dist/operations/generators/operation.ts +0 -972
- package/dist/operations/makers/capability.d.ts +0 -1
- package/dist/operations/makers/capability.js +0 -117
- package/dist/operations/makers/capability.ts +0 -166
- package/dist/operations/makers/trial.d.ts +0 -1
- package/dist/operations/makers/trial.js +0 -413
- package/dist/operations/makers/trial.ts +0 -520
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { argv, stdout } from 'node:process';
|
|
4
|
-
import { exit } from "../../core/invoked.js";
|
|
5
|
-
import { ELSEWHERE, RECEIPT, answer, answering, asking, asksOf, bodied, given as pipedIn, guidance, issue, marked, named as answerNames, needed, only, ownAnswers, refuse, rowLines, seeding, spend, stating, within, wordsIn } from "../../core/asking.js";
|
|
6
|
-
import { holdsRow, listBounds, withRow } from "../../core/rows.js";
|
|
7
|
-
import { named } from "../../core/scope.js";
|
|
8
|
-
import { findTree, inTree } from "../../core/tree.js";
|
|
9
|
-
import { ROOT, SEEDED, declareSeeded, rules, scaffold, slopnatorName, write } from "../slopnator.js";
|
|
10
|
-
const TREE = findTree();
|
|
11
|
-
const FILE = 'rules.ts';
|
|
12
|
-
const LIST = 'RULES';
|
|
13
|
-
const at = within(TREE.at, inTree(TREE, FILE));
|
|
14
|
-
const kebab = (one) => one.trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
15
|
-
const KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
16
|
-
export const ASKS = asksOf('rule', 'Constraint', {
|
|
17
|
-
name: { guide: 'kebab-case, e.g. no-fetch-in-a-screen', asks: 'name: ' },
|
|
18
|
-
describes: {
|
|
19
|
-
guide: 'one sentence a reader who has not seen the code could act on',
|
|
20
|
-
asks: 'describes — one sentence a reader who has not seen the code could act on: ',
|
|
21
|
-
},
|
|
22
|
-
where: {
|
|
23
|
-
guide: 'comma separated path fragments this governs, e.g. app/, src/nodes/',
|
|
24
|
-
asks: 'where (comma separated path fragments this governs, e.g. app/, src/nodes/): ',
|
|
25
|
-
},
|
|
26
|
-
except: {
|
|
27
|
-
guide: 'optional — comma separated path fragments to leave out',
|
|
28
|
-
asks: 'except (comma separated, blank for none): ',
|
|
29
|
-
},
|
|
30
|
-
bans: { guide: 'the exact form this refuses, in one line', asks: 'bans — the exact form this refuses, in one line: ' },
|
|
31
|
-
because: { guide: 'a fact somebody measured — why this is refused', asks: 'because — a fact somebody measured: ' },
|
|
32
|
-
instead: { guide: 'what to do instead', asks: 'instead — what to do instead: ' },
|
|
33
|
-
wrong: {
|
|
34
|
-
guide: 'one line of the form this refuses — its trial',
|
|
35
|
-
asks: 'wrong — one line of the form this refuses, its trial: ',
|
|
36
|
-
},
|
|
37
|
-
right: {
|
|
38
|
-
guide: 'one line of the form this allows — its trial',
|
|
39
|
-
asks: 'right — one line of the form this allows, its trial: ',
|
|
40
|
-
},
|
|
41
|
-
severity: {
|
|
42
|
-
guide: 'optional — forbidden (default, leave blank) or warning',
|
|
43
|
-
asks: 'severity — forbidden or warning (blank for forbidden): ',
|
|
44
|
-
},
|
|
45
|
-
finds: {
|
|
46
|
-
guide: 'one sentence saying what the check looks for, read by whoever opens it next',
|
|
47
|
-
asks: 'finds — one sentence saying what the check looks for: ',
|
|
48
|
-
},
|
|
49
|
-
body: {
|
|
50
|
-
guide: 'the check itself, written where it is asked for. Leave it blank and the rule is declared with nothing behind it, which `npx thread trials` reports unproven',
|
|
51
|
-
asks: 'body: ',
|
|
52
|
-
optional: true,
|
|
53
|
-
},
|
|
54
|
-
}, ['id', 'at', 'version']);
|
|
55
|
-
const said = (one) => ASKS.find((each) => each.at === one)?.asks ?? `${one}: `;
|
|
56
|
-
import { quoted } from "../../core/rows.js";
|
|
57
|
-
const held = await rules();
|
|
58
|
-
if (held === undefined) {
|
|
59
|
-
refuse(`there is no ${at} declaring \`${LIST}\` here, so a rule has nowhere to go. ` +
|
|
60
|
-
`Run \`npx thread attach ${named('integrity')}\` — the sheet is the package's to write, not yours.`);
|
|
61
|
-
}
|
|
62
|
-
const existing = held;
|
|
63
|
-
const mark = (one) => marked([one.id, one.describes, one.bans, one.because, one.instead, one.wrong, one.right, JSON.stringify(one.where), one.severity ?? '']);
|
|
64
|
-
const listing = [
|
|
65
|
-
existing.length === 0
|
|
66
|
-
? 'no rules of its own yet — this app enforces only what the packages it attached ship.'
|
|
67
|
-
: `${String(existing.length)} rule(s) this app adds of its own:`,
|
|
68
|
-
...existing.map((one) => ` [${mark(one)}] ${one.id} — ${one.bans}${one.severity === 'warning' ? ' (warning)' : ''}`),
|
|
69
|
-
].join('\n');
|
|
70
|
-
const words = wordsIn(['new']);
|
|
71
|
-
stdout.write(`${listing}\n`);
|
|
72
|
-
const flagged = argv.indexOf(RECEIPT);
|
|
73
|
-
if (flagged === -1) {
|
|
74
|
-
const nonce = issue(TREE.at, listing);
|
|
75
|
-
stdout.write([
|
|
76
|
-
'',
|
|
77
|
-
...answering('rule'),
|
|
78
|
-
'',
|
|
79
|
-
...guidance(ASKS),
|
|
80
|
-
'',
|
|
81
|
-
` npx thread create rule new <name> ${RECEIPT} ${nonce}`,
|
|
82
|
-
'',
|
|
83
|
-
...ELSEWHERE,
|
|
84
|
-
'',
|
|
85
|
-
`${RECEIPT} is spent by one run, and is refused if ${at} changed after it was issued.`,
|
|
86
|
-
'',
|
|
87
|
-
'this writes three things, not one. The row goes in the sheet, the check goes in the file it ' +
|
|
88
|
-
'seeds from the `body` you give, and the trial comes from `wrong` and `right`.',
|
|
89
|
-
'',
|
|
90
|
-
'then it runs every generator this tree declares, that trial among them, so before this command ' +
|
|
91
|
-
'returns you see whether the rule fires at the form it refuses and stays silent at the fix it ' +
|
|
92
|
-
'names. Leave `body` blank and the row is declared with nothing behind it, and `npx thread ' +
|
|
93
|
-
'trials` reports it unproven until somebody writes the check.',
|
|
94
|
-
'',
|
|
95
|
-
].join('\n'));
|
|
96
|
-
stdout.write(`create: receipt ${nonce} — spent on use, and stale the moment ${at} changes.\n`);
|
|
97
|
-
exit(0);
|
|
98
|
-
}
|
|
99
|
-
spend(TREE.at, listing, argv[flagged + 1], at);
|
|
100
|
-
const all = pipedIn();
|
|
101
|
-
const { piped, ask, line, shut } = asking(all);
|
|
102
|
-
const own = ownAnswers(all);
|
|
103
|
-
if (piped)
|
|
104
|
-
only(own, answerNames(ASKS), '`new`');
|
|
105
|
-
const name = kebab(words[1] ?? (piped ? needed(own, 'name', '`new`') : await ask('name', said('name'))));
|
|
106
|
-
if (!KEBAB.test(name)) {
|
|
107
|
-
shut();
|
|
108
|
-
refuse(`\`${name}\` cannot be the id of a rule — it is kebab-case, e.g. no-fetch-in-a-screen.`);
|
|
109
|
-
}
|
|
110
|
-
if (existing.some((one) => one.id === name)) {
|
|
111
|
-
shut();
|
|
112
|
-
refuse(`\`${name}\` is already declared in ${at}. One id, one rule — two would silently keep whichever ran second.`);
|
|
113
|
-
}
|
|
114
|
-
const describes = piped
|
|
115
|
-
? needed(own, 'describes', '`new`')
|
|
116
|
-
: await ask('describes', said('describes'));
|
|
117
|
-
if (describes === '') {
|
|
118
|
-
shut();
|
|
119
|
-
refuse(`\`${name}\` was given no meaning, and a row without one is a name nobody can read.`);
|
|
120
|
-
}
|
|
121
|
-
const whereSaid = piped ? needed(own, 'where', '`new`') : await ask('where', said('where'));
|
|
122
|
-
const paths = whereSaid.split(',').map((one) => one.trim()).filter((one) => one !== '');
|
|
123
|
-
if (paths.length === 0) {
|
|
124
|
-
shut();
|
|
125
|
-
refuse(`\`${name}\` names no path, so it would govern nothing — a rule that cannot fire is indistinguishable from a rule being obeyed.`);
|
|
126
|
-
}
|
|
127
|
-
const exceptSaid = piped ? (answer(own, 'except') ?? '') : await ask('except', said('except'));
|
|
128
|
-
const except = exceptSaid.split(',').map((one) => one.trim()).filter((one) => one !== '');
|
|
129
|
-
const bans = piped ? needed(own, 'bans', '`new`') : await ask('bans', said('bans'));
|
|
130
|
-
if (bans === '') {
|
|
131
|
-
shut();
|
|
132
|
-
refuse(`\`${name}\` names no \`bans\`, and a rule that does not say what form it refuses cannot be told from one refusing nothing.`);
|
|
133
|
-
}
|
|
134
|
-
const because = piped ? needed(own, 'because', '`new`') : await ask('because', said('because'));
|
|
135
|
-
if (because === '') {
|
|
136
|
-
shut();
|
|
137
|
-
refuse(`\`${name}\` names no \`because\`, and a refusal with no reason is an order rather than a rule.`);
|
|
138
|
-
}
|
|
139
|
-
const instead = piped ? needed(own, 'instead', '`new`') : await ask('instead', said('instead'));
|
|
140
|
-
if (instead === '') {
|
|
141
|
-
shut();
|
|
142
|
-
refuse(`\`${name}\` names no \`instead\`, so whoever it refuses is told only what they did wrong.`);
|
|
143
|
-
}
|
|
144
|
-
const wrong = piped ? needed(own, 'wrong', '`new`') : await ask('wrong', said('wrong'));
|
|
145
|
-
if (wrong === '') {
|
|
146
|
-
shut();
|
|
147
|
-
refuse(`\`${name}\` names no \`wrong\`, and a rule with nothing it refuses is a predicate with no trial to prove it fires.`);
|
|
148
|
-
}
|
|
149
|
-
const right = piped ? needed(own, 'right', '`new`') : await ask('right', said('right'));
|
|
150
|
-
if (right === '') {
|
|
151
|
-
shut();
|
|
152
|
-
refuse(`\`${name}\` names no \`right\`, and a rule that only shows what it refuses cannot prove it stays silent on the fix it recommends.`);
|
|
153
|
-
}
|
|
154
|
-
const severity = piped ? (answer(own, 'severity') ?? '') : await ask('severity', said('severity'));
|
|
155
|
-
if (severity !== '' && severity !== 'forbidden' && severity !== 'warning') {
|
|
156
|
-
shut();
|
|
157
|
-
refuse(`\`${severity}\` is not a severity — a rule is \`forbidden\` (the default, leave blank to use it) or \`warning\`.`);
|
|
158
|
-
}
|
|
159
|
-
const finds = piped ? needed(own, 'finds', '`new`') : await ask('finds', said('finds'));
|
|
160
|
-
if (finds === '') {
|
|
161
|
-
shut();
|
|
162
|
-
refuse(`\`${name}\` says nothing about what its check looks for, and that sentence is the only thing between the ` +
|
|
163
|
-
'next person and opening the file. Say what THIS one looks for, not what a check is.');
|
|
164
|
-
}
|
|
165
|
-
const body = await bodied(`the check for \`${name}\``, scaffold(), piped, all, line);
|
|
166
|
-
const { stated, kids } = await stating(ASKS, all, piped, ask, line, ['name', 'id', 'at', 'describes', 'version', 'where', 'except', 'bans', 'because', 'instead', 'wrong', 'right', 'severity', 'finds', 'body']);
|
|
167
|
-
shut();
|
|
168
|
-
const row = [
|
|
169
|
-
' {',
|
|
170
|
-
` id: ${quoted(name)},`,
|
|
171
|
-
` at: ${quoted(at)},`,
|
|
172
|
-
` describes: ${quoted(describes)},`,
|
|
173
|
-
' version: 1,',
|
|
174
|
-
` where: { paths: [${paths.map(quoted).join(', ')}]${except.length === 0 ? '' : `, except: [${except.map(quoted).join(', ')}]`} },`,
|
|
175
|
-
` bans: ${quoted(bans)},`,
|
|
176
|
-
` because: ${quoted(because)},`,
|
|
177
|
-
` instead: ${quoted(instead)},`,
|
|
178
|
-
` wrong: ${quoted(wrong)},`,
|
|
179
|
-
` right: ${quoted(right)},`,
|
|
180
|
-
...(severity === '' || severity === 'forbidden' ? [] : [` severity: ${quoted(severity)},`]),
|
|
181
|
-
...rowLines(' ', stated, kids),
|
|
182
|
-
' },',
|
|
183
|
-
].join('\n');
|
|
184
|
-
const path = inTree(TREE, FILE);
|
|
185
|
-
const text = readFileSync(path, 'utf8');
|
|
186
|
-
const where = listBounds(text, LIST);
|
|
187
|
-
if (where === undefined)
|
|
188
|
-
refuse(`${at} states no \`${LIST}\` list to declare a rule in.`);
|
|
189
|
-
if (holdsRow(text, where, name))
|
|
190
|
-
refuse(`\`${name}\` is already declared in ${at}.`);
|
|
191
|
-
writeFileSync(path, withRow(text, where, row), 'utf8');
|
|
192
|
-
stdout.write(`create: declared ${name} in ${at}.\n`);
|
|
193
|
-
const slopAt = `${SEEDED}/${slopnatorName(name)}.ts`;
|
|
194
|
-
if (existsSync(join(ROOT, slopAt))) {
|
|
195
|
-
stdout.write(`create: ${slopAt} is already on disk — left untouched, and declared below.\n`);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
write(ROOT, { path: slopAt, content: body ?? scaffold() });
|
|
199
|
-
stdout.write(body === undefined
|
|
200
|
-
? `create: seeded ${slopAt} with nothing behind it — its \`holds\` answers NOT_WRITTEN.\n`
|
|
201
|
-
: `create: seeded ${slopAt} with the check you wrote.\n`);
|
|
202
|
-
}
|
|
203
|
-
for (const told of seeding(kids, ROOT))
|
|
204
|
-
stdout.write(`create: ${told}\n`);
|
|
205
|
-
const declared = await declareSeeded(ROOT, [name], finds);
|
|
206
|
-
if (declared.length > 0)
|
|
207
|
-
stdout.write(`create: declared the check for "${name}" in its own row.\n`);
|
|
208
|
-
stdout.write(body === undefined
|
|
209
|
-
? `create: ${name} refuses nothing yet — write ${slopAt}, matching the shape any file already under ` +
|
|
210
|
-
'slopnators/ uses. `npx thread trials` reports it unproven until you do.\n'
|
|
211
|
-
: `create: ${name} is declared and its check is written. The trial derived from \`wrong\` and \`right\` ` +
|
|
212
|
-
'runs below — it proves the rule fires at the form it refuses and stays silent at the fix it names.\n');
|
|
213
|
-
exit(0);
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
2
|
-
import { join } from 'node:path'
|
|
3
|
-
import { argv, stdout } from 'node:process'
|
|
4
|
-
|
|
5
|
-
import { exit } from '../../core/invoked.ts'
|
|
6
|
-
import { ELSEWHERE, RECEIPT, answer, answering, asking, asksOf, bodied, given as pipedIn, guidance, issue, marked, named as answerNames, needed, only, ownAnswers, refuse, rowLines, seeding, spend, stating, within, wordsIn, type Asked } from '../../core/asking.ts'
|
|
7
|
-
import { holdsRow, listBounds, withRow } from '../../core/rows.ts'
|
|
8
|
-
import { named } from '../../core/scope.ts'
|
|
9
|
-
import { findTree, inTree } from '../../core/tree.ts'
|
|
10
|
-
|
|
11
|
-
import type { Constraint } from '../constraint.ts'
|
|
12
|
-
import { ROOT, SEEDED, declareSeeded, rules, scaffold, slopnatorName, write } from '../slopnator.ts'
|
|
13
|
-
|
|
14
|
-
const TREE = findTree()
|
|
15
|
-
|
|
16
|
-
const FILE = 'rules.ts'
|
|
17
|
-
|
|
18
|
-
const LIST = 'RULES'
|
|
19
|
-
|
|
20
|
-
const at = within(TREE.at, inTree(TREE, FILE))
|
|
21
|
-
|
|
22
|
-
const kebab = (one: string): string => one.trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '')
|
|
23
|
-
|
|
24
|
-
const KEBAB = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/
|
|
25
|
-
|
|
26
|
-
export const ASKS: readonly Asked[] = asksOf(
|
|
27
|
-
'rule',
|
|
28
|
-
'Constraint',
|
|
29
|
-
{
|
|
30
|
-
name: { guide: 'kebab-case, e.g. no-fetch-in-a-screen', asks: 'name: ' },
|
|
31
|
-
describes: {
|
|
32
|
-
guide: 'one sentence a reader who has not seen the code could act on',
|
|
33
|
-
asks: 'describes — one sentence a reader who has not seen the code could act on: ',
|
|
34
|
-
},
|
|
35
|
-
where: {
|
|
36
|
-
guide: 'comma separated path fragments this governs, e.g. app/, src/nodes/',
|
|
37
|
-
asks: 'where (comma separated path fragments this governs, e.g. app/, src/nodes/): ',
|
|
38
|
-
},
|
|
39
|
-
except: {
|
|
40
|
-
guide: 'optional — comma separated path fragments to leave out',
|
|
41
|
-
asks: 'except (comma separated, blank for none): ',
|
|
42
|
-
},
|
|
43
|
-
bans: { guide: 'the exact form this refuses, in one line', asks: 'bans — the exact form this refuses, in one line: ' },
|
|
44
|
-
because: { guide: 'a fact somebody measured — why this is refused', asks: 'because — a fact somebody measured: ' },
|
|
45
|
-
instead: { guide: 'what to do instead', asks: 'instead — what to do instead: ' },
|
|
46
|
-
wrong: {
|
|
47
|
-
guide: 'one line of the form this refuses — its trial',
|
|
48
|
-
asks: 'wrong — one line of the form this refuses, its trial: ',
|
|
49
|
-
},
|
|
50
|
-
right: {
|
|
51
|
-
guide: 'one line of the form this allows — its trial',
|
|
52
|
-
asks: 'right — one line of the form this allows, its trial: ',
|
|
53
|
-
},
|
|
54
|
-
severity: {
|
|
55
|
-
guide: 'optional — forbidden (default, leave blank) or warning',
|
|
56
|
-
asks: 'severity — forbidden or warning (blank for forbidden): ',
|
|
57
|
-
},
|
|
58
|
-
finds: {
|
|
59
|
-
guide: 'one sentence saying what the check looks for, read by whoever opens it next',
|
|
60
|
-
asks: 'finds — one sentence saying what the check looks for: ',
|
|
61
|
-
},
|
|
62
|
-
body: {
|
|
63
|
-
guide:
|
|
64
|
-
'the check itself, written where it is asked for. Leave it blank and the rule is declared with nothing behind it, which `npx thread trials` reports unproven',
|
|
65
|
-
asks: 'body: ',
|
|
66
|
-
optional: true,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
['id', 'at', 'version'],
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
const said = (one: string): string => ASKS.find((each) => each.at === one)?.asks ?? `${one}: `
|
|
73
|
-
|
|
74
|
-
import { quoted } from '../../core/rows.ts'
|
|
75
|
-
|
|
76
|
-
const held = await rules()
|
|
77
|
-
if (held === undefined) {
|
|
78
|
-
refuse(
|
|
79
|
-
`there is no ${at} declaring \`${LIST}\` here, so a rule has nowhere to go. ` +
|
|
80
|
-
`Run \`npx thread attach ${named('integrity')}\` — the sheet is the package's to write, not yours.`,
|
|
81
|
-
)
|
|
82
|
-
}
|
|
83
|
-
const existing: readonly Constraint[] = held
|
|
84
|
-
|
|
85
|
-
const mark = (one: Constraint): string =>
|
|
86
|
-
marked([one.id, one.describes, one.bans, one.because, one.instead, one.wrong, one.right, JSON.stringify(one.where), one.severity ?? ''])
|
|
87
|
-
|
|
88
|
-
const listing = [
|
|
89
|
-
existing.length === 0
|
|
90
|
-
? 'no rules of its own yet — this app enforces only what the packages it attached ship.'
|
|
91
|
-
: `${String(existing.length)} rule(s) this app adds of its own:`,
|
|
92
|
-
...existing.map((one) => ` [${mark(one)}] ${one.id} — ${one.bans}${one.severity === 'warning' ? ' (warning)' : ''}`),
|
|
93
|
-
].join('\n')
|
|
94
|
-
|
|
95
|
-
const words = wordsIn(['new'])
|
|
96
|
-
|
|
97
|
-
stdout.write(`${listing}\n`)
|
|
98
|
-
|
|
99
|
-
const flagged = argv.indexOf(RECEIPT)
|
|
100
|
-
|
|
101
|
-
if (flagged === -1) {
|
|
102
|
-
const nonce = issue(TREE.at, listing)
|
|
103
|
-
stdout.write(
|
|
104
|
-
[
|
|
105
|
-
'',
|
|
106
|
-
...answering('rule'),
|
|
107
|
-
'',
|
|
108
|
-
...guidance(ASKS),
|
|
109
|
-
'',
|
|
110
|
-
` npx thread create rule new <name> ${RECEIPT} ${nonce}`,
|
|
111
|
-
'',
|
|
112
|
-
...ELSEWHERE,
|
|
113
|
-
'',
|
|
114
|
-
`${RECEIPT} is spent by one run, and is refused if ${at} changed after it was issued.`,
|
|
115
|
-
'',
|
|
116
|
-
'this writes three things, not one. The row goes in the sheet, the check goes in the file it ' +
|
|
117
|
-
'seeds from the `body` you give, and the trial comes from `wrong` and `right`.',
|
|
118
|
-
'',
|
|
119
|
-
'then it runs every generator this tree declares, that trial among them, so before this command ' +
|
|
120
|
-
'returns you see whether the rule fires at the form it refuses and stays silent at the fix it ' +
|
|
121
|
-
'names. Leave `body` blank and the row is declared with nothing behind it, and `npx thread ' +
|
|
122
|
-
'trials` reports it unproven until somebody writes the check.',
|
|
123
|
-
'',
|
|
124
|
-
].join('\n'),
|
|
125
|
-
)
|
|
126
|
-
stdout.write(`create: receipt ${nonce} — spent on use, and stale the moment ${at} changes.\n`)
|
|
127
|
-
exit(0)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
spend(TREE.at, listing, argv[flagged + 1], at)
|
|
131
|
-
|
|
132
|
-
const all = pipedIn()
|
|
133
|
-
const { piped, ask, line, shut } = asking(all)
|
|
134
|
-
|
|
135
|
-
const own = ownAnswers(all)
|
|
136
|
-
|
|
137
|
-
if (piped) only(own, answerNames(ASKS), '`new`')
|
|
138
|
-
|
|
139
|
-
const name = kebab(words[1] ?? (piped ? needed(own, 'name', '`new`') : await ask('name', said('name'))))
|
|
140
|
-
if (!KEBAB.test(name)) {
|
|
141
|
-
shut()
|
|
142
|
-
refuse(`\`${name}\` cannot be the id of a rule — it is kebab-case, e.g. no-fetch-in-a-screen.`)
|
|
143
|
-
}
|
|
144
|
-
if (existing.some((one) => one.id === name)) {
|
|
145
|
-
shut()
|
|
146
|
-
refuse(`\`${name}\` is already declared in ${at}. One id, one rule — two would silently keep whichever ran second.`)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const describes = piped
|
|
150
|
-
? needed(own, 'describes', '`new`')
|
|
151
|
-
: await ask('describes', said('describes'))
|
|
152
|
-
if (describes === '') {
|
|
153
|
-
shut()
|
|
154
|
-
refuse(`\`${name}\` was given no meaning, and a row without one is a name nobody can read.`)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const whereSaid = piped ? needed(own, 'where', '`new`') : await ask('where', said('where'))
|
|
158
|
-
const paths = whereSaid.split(',').map((one) => one.trim()).filter((one) => one !== '')
|
|
159
|
-
if (paths.length === 0) {
|
|
160
|
-
shut()
|
|
161
|
-
refuse(`\`${name}\` names no path, so it would govern nothing — a rule that cannot fire is indistinguishable from a rule being obeyed.`)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const exceptSaid = piped ? (answer(own, 'except') ?? '') : await ask('except', said('except'))
|
|
165
|
-
const except = exceptSaid.split(',').map((one) => one.trim()).filter((one) => one !== '')
|
|
166
|
-
|
|
167
|
-
const bans = piped ? needed(own, 'bans', '`new`') : await ask('bans', said('bans'))
|
|
168
|
-
if (bans === '') {
|
|
169
|
-
shut()
|
|
170
|
-
refuse(`\`${name}\` names no \`bans\`, and a rule that does not say what form it refuses cannot be told from one refusing nothing.`)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const because = piped ? needed(own, 'because', '`new`') : await ask('because', said('because'))
|
|
174
|
-
if (because === '') {
|
|
175
|
-
shut()
|
|
176
|
-
refuse(`\`${name}\` names no \`because\`, and a refusal with no reason is an order rather than a rule.`)
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const instead = piped ? needed(own, 'instead', '`new`') : await ask('instead', said('instead'))
|
|
180
|
-
if (instead === '') {
|
|
181
|
-
shut()
|
|
182
|
-
refuse(`\`${name}\` names no \`instead\`, so whoever it refuses is told only what they did wrong.`)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const wrong = piped ? needed(own, 'wrong', '`new`') : await ask('wrong', said('wrong'))
|
|
186
|
-
if (wrong === '') {
|
|
187
|
-
shut()
|
|
188
|
-
refuse(`\`${name}\` names no \`wrong\`, and a rule with nothing it refuses is a predicate with no trial to prove it fires.`)
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const right = piped ? needed(own, 'right', '`new`') : await ask('right', said('right'))
|
|
192
|
-
if (right === '') {
|
|
193
|
-
shut()
|
|
194
|
-
refuse(
|
|
195
|
-
`\`${name}\` names no \`right\`, and a rule that only shows what it refuses cannot prove it stays silent on the fix it recommends.`,
|
|
196
|
-
)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const severity = piped ? (answer(own, 'severity') ?? '') : await ask('severity', said('severity'))
|
|
200
|
-
if (severity !== '' && severity !== 'forbidden' && severity !== 'warning') {
|
|
201
|
-
shut()
|
|
202
|
-
refuse(`\`${severity}\` is not a severity — a rule is \`forbidden\` (the default, leave blank to use it) or \`warning\`.`)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const finds = piped ? needed(own, 'finds', '`new`') : await ask('finds', said('finds'))
|
|
206
|
-
if (finds === '') {
|
|
207
|
-
shut()
|
|
208
|
-
refuse(
|
|
209
|
-
`\`${name}\` says nothing about what its check looks for, and that sentence is the only thing between the ` +
|
|
210
|
-
'next person and opening the file. Say what THIS one looks for, not what a check is.',
|
|
211
|
-
)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const body = await bodied(`the check for \`${name}\``, scaffold(), piped, all, line)
|
|
215
|
-
|
|
216
|
-
const { stated, kids } = await stating(ASKS, all, piped, ask, line, ['name', 'id', 'at', 'describes', 'version', 'where', 'except', 'bans', 'because', 'instead', 'wrong', 'right', 'severity', 'finds', 'body'])
|
|
217
|
-
|
|
218
|
-
shut()
|
|
219
|
-
|
|
220
|
-
const row = [
|
|
221
|
-
' {',
|
|
222
|
-
` id: ${quoted(name)},`,
|
|
223
|
-
` at: ${quoted(at)},`,
|
|
224
|
-
` describes: ${quoted(describes)},`,
|
|
225
|
-
' version: 1,',
|
|
226
|
-
` where: { paths: [${paths.map(quoted).join(', ')}]${except.length === 0 ? '' : `, except: [${except.map(quoted).join(', ')}]`} },`,
|
|
227
|
-
` bans: ${quoted(bans)},`,
|
|
228
|
-
` because: ${quoted(because)},`,
|
|
229
|
-
` instead: ${quoted(instead)},`,
|
|
230
|
-
` wrong: ${quoted(wrong)},`,
|
|
231
|
-
` right: ${quoted(right)},`,
|
|
232
|
-
...(severity === '' || severity === 'forbidden' ? [] : [` severity: ${quoted(severity)},`]),
|
|
233
|
-
...rowLines(' ', stated, kids),
|
|
234
|
-
' },',
|
|
235
|
-
].join('\n')
|
|
236
|
-
|
|
237
|
-
const path = inTree(TREE, FILE)
|
|
238
|
-
const text = readFileSync(path, 'utf8')
|
|
239
|
-
const where = listBounds(text, LIST)
|
|
240
|
-
if (where === undefined) refuse(`${at} states no \`${LIST}\` list to declare a rule in.`)
|
|
241
|
-
if (holdsRow(text, where, name)) refuse(`\`${name}\` is already declared in ${at}.`)
|
|
242
|
-
|
|
243
|
-
writeFileSync(path, withRow(text, where, row), 'utf8')
|
|
244
|
-
stdout.write(`create: declared ${name} in ${at}.\n`)
|
|
245
|
-
|
|
246
|
-
const slopAt = `${SEEDED}/${slopnatorName(name)}.ts`
|
|
247
|
-
if (existsSync(join(ROOT, slopAt))) {
|
|
248
|
-
stdout.write(`create: ${slopAt} is already on disk — left untouched, and declared below.\n`)
|
|
249
|
-
} else {
|
|
250
|
-
write(ROOT, { path: slopAt, content: body ?? scaffold() })
|
|
251
|
-
stdout.write(
|
|
252
|
-
body === undefined
|
|
253
|
-
? `create: seeded ${slopAt} with nothing behind it — its \`holds\` answers NOT_WRITTEN.\n`
|
|
254
|
-
: `create: seeded ${slopAt} with the check you wrote.\n`,
|
|
255
|
-
)
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
for (const told of seeding(kids, ROOT)) stdout.write(`create: ${told}\n`)
|
|
259
|
-
|
|
260
|
-
const declared = await declareSeeded(ROOT, [name], finds)
|
|
261
|
-
if (declared.length > 0) stdout.write(`create: declared the check for "${name}" in its own row.\n`)
|
|
262
|
-
|
|
263
|
-
stdout.write(
|
|
264
|
-
body === undefined
|
|
265
|
-
? `create: ${name} refuses nothing yet — write ${slopAt}, matching the shape any file already under ` +
|
|
266
|
-
'slopnators/ uses. `npx thread trials` reports it unproven until you do.\n'
|
|
267
|
-
: `create: ${name} is declared and its check is written. The trial derived from \`wrong\` and \`right\` ` +
|
|
268
|
-
'runs below — it proves the rule fires at the form it refuses and stays silent at the fix it names.\n',
|
|
269
|
-
)
|
|
270
|
-
|
|
271
|
-
exit(0)
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const SEALED_AT = "sealed.ts";
|
|
2
|
-
export declare function sealable(home?: string): readonly string[];
|
|
3
|
-
export declare function sealOf(home?: string): Readonly<Record<string, string>>;
|
|
4
|
-
export declare function content(seal: Readonly<Record<string, string>>): string;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
-
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
-
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
-
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
return path;
|
|
8
|
-
};
|
|
9
|
-
import { createHash } from 'node:crypto';
|
|
10
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs';
|
|
11
|
-
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
12
|
-
import { argv, stderr, stdout } from 'node:process';
|
|
13
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
14
|
-
import { runChecker } from "../../core/finding.js";
|
|
15
|
-
import { exit, invoked } from "../../core/invoked.js";
|
|
16
|
-
import { findTree, inTree } from "../../core/tree.js";
|
|
17
|
-
import { SEALED } from "../sealed.js";
|
|
18
|
-
export const SEALED_AT = 'sealed.ts';
|
|
19
|
-
const HERE = fileURLToPath(import.meta.url);
|
|
20
|
-
const FROM_SOURCE = HERE.endsWith('.ts');
|
|
21
|
-
const ROOT = FROM_SOURCE ? findTree().at : resolve(HERE, '../..');
|
|
22
|
-
const DOMAIN = basename(resolve(HERE, '../..'));
|
|
23
|
-
const WRITTEN = join(dirname(HERE), '..', SEALED_AT);
|
|
24
|
-
const BUILT = SEALED_AT.replace(/\.ts$/, '.js');
|
|
25
|
-
const CODE = /\.js$/;
|
|
26
|
-
const SHEET = 'packaging.ts';
|
|
27
|
-
async function declared() {
|
|
28
|
-
const sheet = inTree(findTree(), SHEET);
|
|
29
|
-
if (!existsSync(sheet))
|
|
30
|
-
return [];
|
|
31
|
-
const loaded = (await import(__rewriteRelativeImportExtension(pathToFileURL(sheet).href)));
|
|
32
|
-
return loaded.PACKAGES ?? [];
|
|
33
|
-
}
|
|
34
|
-
const PACKAGES = FROM_SOURCE ? await declared() : [];
|
|
35
|
-
function built() {
|
|
36
|
-
if (!FROM_SOURCE)
|
|
37
|
-
return ROOT;
|
|
38
|
-
const folders = PACKAGES.map((one) => one.folder ?? '').filter((one) => one !== '');
|
|
39
|
-
const holder = folders.find((folder) => existsSync(join(ROOT, folder, 'dist', DOMAIN)));
|
|
40
|
-
if (holder === undefined) {
|
|
41
|
-
stderr.write(`seal: no package built here holds \`${DOMAIN}\` — ${folders.length === 0 ? '_threads/packaging.ts declares no package' : `none of ${folders.join(', ')} has a dist/${DOMAIN}`}. ` +
|
|
42
|
-
`Run \`thread packaged --build\` first, and if no package row carries the ${DOMAIN} words, put them on one in _threads/packaging.ts.\n`);
|
|
43
|
-
exit(1);
|
|
44
|
-
}
|
|
45
|
-
return join(ROOT, holder, 'dist', DOMAIN);
|
|
46
|
-
}
|
|
47
|
-
export function sealable(home = built()) {
|
|
48
|
-
const found = [];
|
|
49
|
-
const step = (at) => {
|
|
50
|
-
for (const entry of readdirSync(at).sort()) {
|
|
51
|
-
const here = join(at, entry);
|
|
52
|
-
if (statSync(here).isDirectory())
|
|
53
|
-
step(here);
|
|
54
|
-
else if (CODE.test(entry) && relative(home, here) !== BUILT)
|
|
55
|
-
found.push(here);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
step(home);
|
|
59
|
-
return found.sort();
|
|
60
|
-
}
|
|
61
|
-
export function sealOf(home = built()) {
|
|
62
|
-
const held = {};
|
|
63
|
-
for (const file of sealable(home)) {
|
|
64
|
-
held[relative(home, file)] = createHash('sha256').update(readFileSync(file)).digest('hex');
|
|
65
|
-
}
|
|
66
|
-
return held;
|
|
67
|
-
}
|
|
68
|
-
export function content(seal) {
|
|
69
|
-
const rows = Object.entries(seal).map(([at, hash]) => ` '${at}': '${hash}',`);
|
|
70
|
-
return [
|
|
71
|
-
'export const SEALED: Readonly<Record<string, string>> = {',
|
|
72
|
-
...rows,
|
|
73
|
-
'}',
|
|
74
|
-
'',
|
|
75
|
-
].join('\n');
|
|
76
|
-
}
|
|
77
|
-
if (invoked(import.meta.url)) {
|
|
78
|
-
const seal = sealOf();
|
|
79
|
-
const emitted = content(seal);
|
|
80
|
-
if (argv.includes('--check')) {
|
|
81
|
-
const sealed = Object.keys(seal).length;
|
|
82
|
-
const findings = content(SEALED) === emitted
|
|
83
|
-
? []
|
|
84
|
-
: [
|
|
85
|
-
{
|
|
86
|
-
detail: `${SEALED_AT} is not the bytes this package is made of`,
|
|
87
|
-
instead: 'run `thread seal` and commit what it writes — the seal is what proves an installed copy is the one that shipped',
|
|
88
|
-
file: relative(ROOT, WRITTEN),
|
|
89
|
-
},
|
|
90
|
-
];
|
|
91
|
-
runChecker('seal', findings, `${String(sealed)} file(s) sealed`);
|
|
92
|
-
exit(findings.length === 0 ? 0 : 1);
|
|
93
|
-
}
|
|
94
|
-
if (!FROM_SOURCE) {
|
|
95
|
-
stderr.write('seal: this copy is installed, and a seal is written where the package is made. Nothing was rewritten — `thread seal --check` says whether this copy is the one that shipped.\n');
|
|
96
|
-
exit(1);
|
|
97
|
-
}
|
|
98
|
-
mkdirSync(dirname(WRITTEN), { recursive: true });
|
|
99
|
-
writeFileSync(WRITTEN, emitted);
|
|
100
|
-
stdout.write(`seal: wrote ${SEALED_AT} — ${String(Object.keys(seal).length)} file(s).\n`);
|
|
101
|
-
}
|