toolcrib 0.11.0 → 0.11.2
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/package.json +1 -1
- package/src/commands/exportPatches.js +31 -2
- package/src/index.js +0 -0
- package/src/lib/exportFormat.js +2 -0
- package/src/lib/exportPatches.js +74 -1
- package/src/lib/github.js +7 -6
- package/src/lib/managedDocs.js +2 -0
- package/src/lib/project.js +7 -1
- package/src/lib/version.js +26 -0
package/package.json
CHANGED
|
@@ -80,6 +80,23 @@ async function postExport(options) {
|
|
|
80
80
|
.filter((d) => d.isDirectory())
|
|
81
81
|
.map((d) => d.name)
|
|
82
82
|
.sort();
|
|
83
|
+
// The README was written at export time; the user may have deleted folders since.
|
|
84
|
+
const readmePath = path.join(outDir, 'README.md');
|
|
85
|
+
if (fs.existsSync(readmePath)) {
|
|
86
|
+
const listed = new Set();
|
|
87
|
+
for (const line of fs.readFileSync(readmePath, 'utf8').split(/\r?\n/)) {
|
|
88
|
+
const m = /^\|\s*(\d+-[^\s|]+)\s*\|/.exec(line);
|
|
89
|
+
if (m) listed.add(m[1]);
|
|
90
|
+
}
|
|
91
|
+
const missing = [...listed].filter((f) => !folders.includes(f)).sort();
|
|
92
|
+
const unlisted = folders.filter((f) => !listed.has(f));
|
|
93
|
+
if (missing.length) {
|
|
94
|
+
p.log.warn(`README.md lists contribution(s) whose folder is missing (not posted): ${missing.join(', ')}`);
|
|
95
|
+
}
|
|
96
|
+
if (unlisted.length) {
|
|
97
|
+
p.log.warn(`Folder(s) present but not listed in README.md: ${unlisted.join(', ')}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
83
100
|
const plans = [];
|
|
84
101
|
for (const folder of folders) {
|
|
85
102
|
const dir = path.join(outDir, folder);
|
|
@@ -105,7 +122,13 @@ async function postExport(options) {
|
|
|
105
122
|
const text = fs.readFileSync(path.join(dir, fileName), 'utf8');
|
|
106
123
|
return { fileName, upstreamPath: upstreamPathOf(text) ?? fileName, text };
|
|
107
124
|
});
|
|
108
|
-
plans.push({
|
|
125
|
+
plans.push({
|
|
126
|
+
folder,
|
|
127
|
+
dir,
|
|
128
|
+
summaryText,
|
|
129
|
+
files: patches.map((x) => x.upstreamPath),
|
|
130
|
+
plan: buildPostPlan({ summaryText, patches }),
|
|
131
|
+
});
|
|
109
132
|
}
|
|
110
133
|
|
|
111
134
|
if (plans.length === 0) {
|
|
@@ -132,9 +155,15 @@ async function postExport(options) {
|
|
|
132
155
|
|
|
133
156
|
p.log.info(
|
|
134
157
|
plans
|
|
135
|
-
.map(
|
|
158
|
+
.map(
|
|
159
|
+
(x) =>
|
|
160
|
+
`${x.plan.title}\n body ${x.plan.body.length} chars, ${x.plan.comments.length} comment(s)\n` +
|
|
161
|
+
` files whose full contents will be posted:\n` +
|
|
162
|
+
x.files.map((f) => ` ${f}`).join('\n')
|
|
163
|
+
)
|
|
136
164
|
.join('\n') + `\nPosting as @${login} to escape-llc/toolcrib → Consumer Patches`
|
|
137
165
|
);
|
|
166
|
+
p.log.warn("These posts go to a public GitHub repository's Discussions; anyone can read them.");
|
|
138
167
|
|
|
139
168
|
if (!options.yes) {
|
|
140
169
|
if (!isTTY) {
|
package/src/index.js
CHANGED
|
File without changes
|
package/src/lib/exportFormat.js
CHANGED
|
@@ -177,6 +177,8 @@ export function renderReadme({ baseVersion, entries, notExported, regeneratedUps
|
|
|
177
177
|
'',
|
|
178
178
|
"Fill in each contribution's `intent:` lines in its SUMMARY.md before posting.",
|
|
179
179
|
'',
|
|
180
|
+
'This README describes the export as generated. If you delete a contribution folder you do not want to send, this file is not updated; `--post` sends only the folders still present.',
|
|
181
|
+
'',
|
|
180
182
|
'## Contributions',
|
|
181
183
|
'',
|
|
182
184
|
];
|
package/src/lib/exportPatches.js
CHANGED
|
@@ -30,6 +30,38 @@ export const VALID_CATEGORIES = ['Layout Primitives', 'Containers', 'Overlays',
|
|
|
30
30
|
|
|
31
31
|
const INFRA_DIRS = ['theme', 'eventBus', 'observer'];
|
|
32
32
|
const CODE_FILE = /\.[cm]?[jt]sx?$/;
|
|
33
|
+
|
|
34
|
+
const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The binding names imported from `specifier` across every import/export
|
|
38
|
+
* statement naming it: default, named (by their exported name), `*`, and
|
|
39
|
+
* `side-effect` for a bare `import 'x'` or a dynamic import. Whitespace and
|
|
40
|
+
* order don't matter, so reformatting an import line changes nothing.
|
|
41
|
+
*/
|
|
42
|
+
function importedNames(source, specifier) {
|
|
43
|
+
const code = stripComments(source);
|
|
44
|
+
const q = `['"]${escapeRegExp(specifier)}['"]`;
|
|
45
|
+
const names = new Set();
|
|
46
|
+
const re = new RegExp(`\\b(?:import|export)\\s+(?:type\\s+)?([^'";]*?)\\s*from\\s*${q}`, 'g');
|
|
47
|
+
let m;
|
|
48
|
+
while ((m = re.exec(code))) {
|
|
49
|
+
const clause = m[1];
|
|
50
|
+
const braces = /\{([^}]*)\}/.exec(clause);
|
|
51
|
+
if (braces) {
|
|
52
|
+
for (const part of braces[1].split(',')) {
|
|
53
|
+
const name = part.trim().replace(/^type\s+/, '').split(/\s+as\s+/)[0].trim();
|
|
54
|
+
if (name) names.add(name);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const outside = clause.replace(/\{[^}]*\}/, '');
|
|
58
|
+
if (/\*/.test(outside)) names.add('*');
|
|
59
|
+
const def = outside.replace(/\*(\s*as\s+\w+)?/, '').replace(/,/g, ' ').trim();
|
|
60
|
+
if (def) names.add('default');
|
|
61
|
+
}
|
|
62
|
+
if (new RegExp(`\\bimport\\s*(?:\\(\\s*)?${q}`).test(code)) names.add('side-effect');
|
|
63
|
+
return names;
|
|
64
|
+
}
|
|
33
65
|
const MANIFEST_BLOCK_RE = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*export\s+(?:const|function)\s+(\w+)/g;
|
|
34
66
|
const EXPORT_DECL_RE = /\bexport\s+(?:declare\s+)?(?:abstract\s+)?(?:const|let|var|function|class|interface|type|enum)\s+(\w+)/g;
|
|
35
67
|
/** Raw React prop types that carry style/className, as an extends, intersection or alias. */
|
|
@@ -265,6 +297,31 @@ export function analyzeExport({ releaseFiles, localFiles }) {
|
|
|
265
297
|
const isInfraCandidate = (p) => changed.has(p) && INFRA_DIRS.includes(topSegment(p)) && !unitOf.has(p);
|
|
266
298
|
const reachedBy = new Map(); // candidate relPath -> Set(unit key)
|
|
267
299
|
const reachedPerUnit = new Map();
|
|
300
|
+
const dependencyPerUnit = new Map();
|
|
301
|
+
const relHas = (p) => rel.has(p);
|
|
302
|
+
// Resolved import target -> the names imported from it (see importedNames).
|
|
303
|
+
const resolvedImports = (content, relPath, exists) => {
|
|
304
|
+
const out = new Map();
|
|
305
|
+
if (content === undefined || !CODE_FILE.test(relPath)) return out;
|
|
306
|
+
for (const spec of extractImports(content)) {
|
|
307
|
+
const resolved = resolveRelativeImport(relPath, spec, exists);
|
|
308
|
+
if (!resolved) continue;
|
|
309
|
+
if (!out.has(resolved)) out.set(resolved, new Set());
|
|
310
|
+
for (const n of importedNames(content, spec)) out.get(resolved).add(n);
|
|
311
|
+
}
|
|
312
|
+
return out;
|
|
313
|
+
};
|
|
314
|
+
// Import targets the unit's own change introduced: a target the release
|
|
315
|
+
// version didn't import, or one it now imports a name from that it didn't
|
|
316
|
+
// before (a new export used through an import line that already existed).
|
|
317
|
+
// An added file counts all its imports; a deleted file contributes none.
|
|
318
|
+
const newImportTargets = (relPath) => {
|
|
319
|
+
const before = resolvedImports(rel.get(relPath), relPath, relHas);
|
|
320
|
+
const after = resolvedImports(loc.get(relPath), relPath, localHas);
|
|
321
|
+
return [...after]
|
|
322
|
+
.filter(([t, names]) => !before.has(t) || [...names].some((n) => !before.get(t).has(n)))
|
|
323
|
+
.map(([t]) => t);
|
|
324
|
+
};
|
|
268
325
|
for (const [key, unit] of units) {
|
|
269
326
|
const seen = new Set(unit.paths);
|
|
270
327
|
const stack = [...unit.paths];
|
|
@@ -286,6 +343,22 @@ export function analyzeExport({ releaseFiles, localFiles }) {
|
|
|
286
343
|
}
|
|
287
344
|
}
|
|
288
345
|
reachedPerUnit.set(key, reached);
|
|
346
|
+
// Dependency, as opposed to reachability: only what the unit's own change newly imports.
|
|
347
|
+
const dependencySeen = new Set(unit.paths);
|
|
348
|
+
const dependencyStack = [];
|
|
349
|
+
for (const f of unit.paths) dependencyStack.push(...newImportTargets(f));
|
|
350
|
+
const dependsOnFiles = new Set();
|
|
351
|
+
while (dependencyStack.length) {
|
|
352
|
+
const d = dependencyStack.pop();
|
|
353
|
+
if (dependencySeen.has(d)) continue;
|
|
354
|
+
dependencySeen.add(d);
|
|
355
|
+
if (SHARED_FILES.includes(d)) continue;
|
|
356
|
+
const owner = unitOf.get(d);
|
|
357
|
+
if (owner !== undefined && owner !== key) continue; // another unit's own files
|
|
358
|
+
if (isInfraCandidate(d)) dependsOnFiles.add(d);
|
|
359
|
+
for (const n of deps(d)) dependencyStack.push(n);
|
|
360
|
+
}
|
|
361
|
+
dependencyPerUnit.set(key, dependsOnFiles);
|
|
289
362
|
unit.missingDependencies = [...missing].sort();
|
|
290
363
|
for (const d of reached) {
|
|
291
364
|
if (!reachedBy.has(d)) reachedBy.set(d, new Set());
|
|
@@ -335,7 +408,7 @@ export function analyzeExport({ releaseFiles, localFiles }) {
|
|
|
335
408
|
infra.sort((a, b) => a.name.localeCompare(b.name));
|
|
336
409
|
for (const [key, unit] of units) {
|
|
337
410
|
const names = new Set();
|
|
338
|
-
for (const d of
|
|
411
|
+
for (const d of dependencyPerUnit.get(key)) {
|
|
339
412
|
if (infraOfFile.has(d)) names.add(infraOfFile.get(d).name);
|
|
340
413
|
}
|
|
341
414
|
unit.dependsOn = [...names].sort();
|
package/src/lib/github.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
|
+
import { assertValidVersion } from './version.js';
|
|
2
3
|
|
|
3
4
|
const REPO = 'escape-llc/toolcrib';
|
|
4
5
|
const ASSET_NAME = 'toolcrib.zip';
|
|
@@ -91,7 +92,7 @@ export async function fetchLatestVersion() {
|
|
|
91
92
|
if (!res.ok) throwGitHubApiError(res, 'the latest release');
|
|
92
93
|
|
|
93
94
|
const release = await res.json();
|
|
94
|
-
return release.tag_name.replace(/^v/, '');
|
|
95
|
+
return assertValidVersion(String(release.tag_name).replace(/^v/, ''), 'GitHub API latest release tag');
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
/**
|
|
@@ -124,10 +125,10 @@ export async function fetchSecurityAdvisories() {
|
|
|
124
125
|
return JSON.parse(await res.text());
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
function assetUrl(version, assetName) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
export function assetUrl(version, assetName) {
|
|
129
|
+
if (version === 'latest') return `${RELEASES_BASE}/latest/download/${assetName}`;
|
|
130
|
+
assertValidVersion(version, 'release download version');
|
|
131
|
+
return `${RELEASES_BASE}/download/v${version}/${assetName}`;
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
/**
|
|
@@ -137,7 +138,7 @@ function assetUrl(version, assetName) {
|
|
|
137
138
|
* `init latest` after a new release appears is never a silent surprise.
|
|
138
139
|
*/
|
|
139
140
|
export async function resolveVersion(version) {
|
|
140
|
-
if (version !== 'latest') return version;
|
|
141
|
+
if (version !== 'latest') return assertValidVersion(version, '--version argument');
|
|
141
142
|
return fetchLatestVersion();
|
|
142
143
|
}
|
|
143
144
|
|
package/src/lib/managedDocs.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* ./toolcrib/ already are.
|
|
7
7
|
*/
|
|
8
8
|
import { FENCE_STYLES, buildFence, extractFence, upsertFence } from './fences.js';
|
|
9
|
+
import { assertValidVersion } from './version.js';
|
|
9
10
|
|
|
10
11
|
// doc-id -> source filename under ai-docs/, in the order they should read
|
|
11
12
|
// when more than one is present in the same target file.
|
|
@@ -45,6 +46,7 @@ export function listManagedBlocks(fileContent) {
|
|
|
45
46
|
return Object.keys(MANAGED_DOCS)
|
|
46
47
|
.map((docId) => {
|
|
47
48
|
const block = extractManagedBlock(fileContent, docId);
|
|
49
|
+
if (block) assertValidVersion(block.version, `managed block "${docId}" version attribute`);
|
|
48
50
|
return block ? { docId, ...block } : null;
|
|
49
51
|
})
|
|
50
52
|
.filter(Boolean);
|
package/src/lib/project.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { FENCE_STYLES, upsertFence, extractFence } from './fences.js';
|
|
4
|
+
import { assertValidVersion } from './version.js';
|
|
4
5
|
|
|
5
6
|
// No leading "./" — git apply rejects paths with one as invalid, and
|
|
6
7
|
// every other relPath used in PendingChanges (component files, package.json)
|
|
@@ -64,7 +65,12 @@ export function fileExists(filePath) {
|
|
|
64
65
|
* drift, etc.) — see design notes.
|
|
65
66
|
*/
|
|
66
67
|
export function readLock(projectRoot) {
|
|
67
|
-
|
|
68
|
+
const lock = readJsonIfExists(path.join(projectRoot, LOCK_PATH));
|
|
69
|
+
if (lock) {
|
|
70
|
+
assertValidVersion(lock.version, LOCK_PATH);
|
|
71
|
+
if (lock.testsVersion !== undefined) assertValidVersion(lock.testsVersion, `${LOCK_PATH} testsVersion`);
|
|
72
|
+
}
|
|
73
|
+
return lock;
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
/**
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// A version string reaching a release download URL (`.../download/v${version}/...`)
|
|
2
|
+
// or a `v${version}` tag must be plain semver. Anything else (e.g. a lock file
|
|
3
|
+
// containing `1/../../x`) could redirect the download to another repository,
|
|
4
|
+
// whose zip and .sha256 would both be attacker-controlled and so pass the
|
|
5
|
+
// checksum. One helper, called at every boundary where a version enters the
|
|
6
|
+
// CLI (lock file, managed-block attribute, --version flag, GitHub API) and
|
|
7
|
+
// again inside the URL builder, so no URL is built from an unvalidated string.
|
|
8
|
+
const SEMVER_RE = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
|
|
9
|
+
|
|
10
|
+
export function isValidVersion(version) {
|
|
11
|
+
return typeof version === 'string' && SEMVER_RE.test(version);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns `version` unchanged if it is strict semver; otherwise throws an error
|
|
16
|
+
* that names where the bad value came from (`source`, e.g. "toolcrib/.toolcrib-lock.json").
|
|
17
|
+
*/
|
|
18
|
+
export function assertValidVersion(version, source) {
|
|
19
|
+
if (!isValidVersion(version)) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Invalid version ${JSON.stringify(version)} from ${source}: expected a semver version like 1.2.3 ` +
|
|
22
|
+
`(optionally with a -prerelease suffix). Refusing to build a release URL from it.`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return version;
|
|
26
|
+
}
|