toolcrib 0.4.0 → 0.6.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 +13 -1
- package/package.json +6 -3
- package/src/commands/doctor.js +78 -33
- package/src/index.js +17 -1
- package/src/lib/github.js +104 -38
- package/src/lib/project.js +19 -7
- package/src/lib/rootProvider.js +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,18 @@ toolcrib <command>
|
|
|
29
29
|
Run every command from your project's root — the same directory as your
|
|
30
30
|
`package.json`.
|
|
31
31
|
|
|
32
|
+
**Two version numbers, completely unrelated — never try to align them.**
|
|
33
|
+
`npx toolcrib` (or `npm install -g toolcrib`) always resolves to the CLI's
|
|
34
|
+
own latest npm release; there's no reason to ever pin it (`npx
|
|
35
|
+
toolcrib@1.2.3`), and doing so has nothing to do with which toolkit content
|
|
36
|
+
you get. The toolkit itself — the components, `ai-docs/`, everything
|
|
37
|
+
`init`/`merge` actually download — is versioned completely separately, as
|
|
38
|
+
GitHub Releases. That's what `init`/`merge`'s own `--version` flag targets
|
|
39
|
+
(see [Commands](#commands) below), and it already defaults to `latest` on
|
|
40
|
+
its own. These two numbers will essentially never match each other, by
|
|
41
|
+
design — don't infer one from the other, and don't specify either unless
|
|
42
|
+
you have a specific reason to pin a particular release.
|
|
43
|
+
|
|
32
44
|
## The lifecycle, at a glance
|
|
33
45
|
|
|
34
46
|
```
|
|
@@ -131,7 +143,7 @@ anything. It reports:
|
|
|
131
143
|
- **Stale instruction-file blocks** — if the `<!-- toolcrib:managed:... -->`
|
|
132
144
|
block in your `AGENTS.md`/`CLAUDE.md` was hand-edited instead of
|
|
133
145
|
regenerated, or is out of date with your installed version.
|
|
134
|
-
- **Whether a newer release is available
|
|
146
|
+
- **Whether a newer release is available** — and, when a known, fixed vulnerability affects your installed version specifically, its severity and a link to the fix (generated from real, fixed toolcrib CodeQL findings — see the project's own `AGENTS.md` for how).
|
|
135
147
|
- **A `tsconfig.json` compatibility check** — if `moduleResolution` isn't
|
|
136
148
|
set to `"bundler"`, `"node16"`, or `"nodenext"`, `import { ... } from
|
|
137
149
|
'#toolcrib'` will run fine but your editor/`tsc` may falsely report
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toolcrib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Bootstrap the toolcrib UI toolkit into your project",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"test": "vitest run",
|
|
23
|
-
"test:watch": "vitest"
|
|
23
|
+
"test:watch": "vitest",
|
|
24
|
+
"coverage:unit": "vitest run --coverage"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"@clack/prompts": "^1.7.0",
|
|
@@ -29,6 +30,8 @@
|
|
|
29
30
|
"semver": "^7.6.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"vitest": "^
|
|
33
|
+
"@vitest/coverage-v8": "^5.0.0",
|
|
34
|
+
"cross-spawn": "^7.0.6",
|
|
35
|
+
"vitest": "^5.0.0"
|
|
33
36
|
}
|
|
34
37
|
}
|
package/src/commands/doctor.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import semver from 'semver';
|
|
2
3
|
import * as p from '@clack/prompts';
|
|
3
4
|
import { fetchRelease } from '../lib/release.js';
|
|
4
5
|
import { normalize } from '../lib/patches.js';
|
|
5
6
|
import { readJsonIfExists, readLock, readTextIfExists, fileExists } from '../lib/project.js';
|
|
6
|
-
import {
|
|
7
|
+
import { fetchLatestVersion, fetchSecurityAdvisories } from '../lib/github.js';
|
|
7
8
|
import { MANAGED_DOCS, KNOWN_TARGET_FILES, listManagedBlocks } from '../lib/managedDocs.js';
|
|
8
9
|
import { detectBundler } from '../lib/bundler.js';
|
|
9
10
|
import { checkRootProviderWired } from '../lib/rootProvider.js';
|
|
@@ -186,50 +187,94 @@ export async function doctorCommand(options = {}) {
|
|
|
186
187
|
|
|
187
188
|
const spinner = p.spinner();
|
|
188
189
|
spinner.start(`Checking against installed version v${lock.version}`);
|
|
189
|
-
|
|
190
|
+
// Network-dependent section 1 of 2: drift check against the installed
|
|
191
|
+
// release. A failure here (rate limit, network down, bad release asset)
|
|
192
|
+
// should only skip *this* check, not abort bundler detection/root-provider
|
|
193
|
+
// check/etc. below — those are 100% local and would otherwise succeed.
|
|
194
|
+
let release = null;
|
|
195
|
+
let releaseFetchError = null;
|
|
190
196
|
try {
|
|
191
197
|
release = await fetchRelease(lock.version);
|
|
192
198
|
} catch (err) {
|
|
193
|
-
|
|
194
|
-
throw err;
|
|
199
|
+
releaseFetchError = err;
|
|
195
200
|
}
|
|
196
201
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
if (release) {
|
|
203
|
+
const drifted = [];
|
|
204
|
+
for (const relPath of release.allFiles()) {
|
|
205
|
+
const targetPath = path.join(projectRoot, TOOLKIT_DIR, relPath);
|
|
206
|
+
const local = readTextIfExists(targetPath);
|
|
207
|
+
const shipped = release.readFile(relPath);
|
|
208
|
+
if (normalize(local) !== normalize(shipped)) {
|
|
209
|
+
drifted.push(relPath);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const managedBlockMessages = await checkManagedBlocks(projectRoot, release);
|
|
213
|
+
await release.cleanup();
|
|
214
|
+
spinner.stop('Drift check complete');
|
|
215
|
+
|
|
216
|
+
if (drifted.length === 0) {
|
|
217
|
+
p.log.success(`No local drift detected from v${lock.version}.`);
|
|
218
|
+
} else {
|
|
219
|
+
p.log.warn(
|
|
220
|
+
`${drifted.length} file(s) differ from the shipped v${lock.version}:\n` +
|
|
221
|
+
drifted.map((f) => ` ${f}`).join('\n')
|
|
222
|
+
);
|
|
204
223
|
}
|
|
205
|
-
}
|
|
206
|
-
const managedBlockMessages = await checkManagedBlocks(projectRoot, release);
|
|
207
|
-
await release.cleanup();
|
|
208
|
-
spinner.stop('Drift check complete');
|
|
209
224
|
|
|
210
|
-
|
|
211
|
-
|
|
225
|
+
if (managedBlockMessages.length === 0) {
|
|
226
|
+
p.log.success('No managed AGENTS.md/CLAUDE.md blocks found, or none have drifted.');
|
|
227
|
+
} else {
|
|
228
|
+
for (const message of managedBlockMessages) {
|
|
229
|
+
p.log[message.level](message.text);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
212
232
|
} else {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
drifted.map((f) => ` ${f}`).join('\n')
|
|
216
|
-
);
|
|
233
|
+
spinner.stop('Drift check skipped');
|
|
234
|
+
p.log.warn(`Could not fetch v${lock.version} to check for drift: ${releaseFetchError.message}`);
|
|
217
235
|
}
|
|
218
236
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
237
|
+
// Network-dependent section 2 of 2: "is a newer version available."
|
|
238
|
+
// Independent failure point from the drift check above (different
|
|
239
|
+
// GitHub endpoint, same rate limit) — same rule applies: a failure here
|
|
240
|
+
// shouldn't take out the local-only checks that follow.
|
|
241
|
+
// fetchLatestVersion (GitHub's dedicated /releases/latest endpoint), not
|
|
242
|
+
// listVersions — doctor only ever needs the single newest release to
|
|
243
|
+
// compare against what's installed, not every release's full metadata.
|
|
244
|
+
try {
|
|
245
|
+
const newestVersion = await fetchLatestVersion();
|
|
246
|
+
if (newestVersion !== lock.version) {
|
|
247
|
+
p.log.info(`A newer version is available: v${newestVersion} (installed: v${lock.version}). Run 'toolcrib merge'.`);
|
|
248
|
+
} else {
|
|
249
|
+
p.log.info('You are on the latest release.');
|
|
224
250
|
}
|
|
251
|
+
} catch (err) {
|
|
252
|
+
p.log.warn(`Could not check for a newer release: ${err.message}`);
|
|
225
253
|
}
|
|
226
254
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
255
|
+
// Network-dependent section 3 of 3: security advisories, generated from
|
|
256
|
+
// real CodeQL findings (see scripts/generate-security-advisories.js).
|
|
257
|
+
// Independent failure point from the version check above -- this file
|
|
258
|
+
// always lives on the toolcrib repo's own main branch, never in a
|
|
259
|
+
// consumer's vendored copy (a frozen snapshot that structurally can't
|
|
260
|
+
// know about anything published after it), so it's fetched fresh on
|
|
261
|
+
// every run for the same reason fetchLatestVersion is. Enriches the
|
|
262
|
+
// version check above rather than replacing it: same underlying
|
|
263
|
+
// question ("is there a newer version worth getting"), this just says
|
|
264
|
+
// *why* when the answer is yes for a real, fixed vulnerability.
|
|
265
|
+
try {
|
|
266
|
+
const advisories = await fetchSecurityAdvisories();
|
|
267
|
+
const relevant = advisories
|
|
268
|
+
.filter((a) => semver.gt(a.fixedIn, lock.version))
|
|
269
|
+
.sort((a, b) => semver.compare(b.fixedIn, a.fixedIn));
|
|
270
|
+
for (const a of relevant) {
|
|
271
|
+
p.log.warn(
|
|
272
|
+
`Security: v${a.fixedIn} fixes a ${a.severity.toUpperCase()}-severity issue (installed: v${lock.version}) -- ` +
|
|
273
|
+
`${a.summary}\n ${a.url}\n Run 'toolcrib merge' to update.`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
} catch (err) {
|
|
277
|
+
p.log.warn(`Could not check for security advisories: ${err.message}`);
|
|
233
278
|
}
|
|
234
279
|
|
|
235
280
|
if (!checkTypeScriptAdopted(projectRoot)) {
|
|
@@ -270,7 +315,7 @@ export async function doctorCommand(options = {}) {
|
|
|
270
315
|
p.log.warn(
|
|
271
316
|
"Root providers: couldn't find <ToolcribProvider> or a manual <ThemeProvider>/<ToastProvider>/<ToastContainer> " +
|
|
272
317
|
'composition anywhere under src/. Every toolcrib component throws or silently no-ops without one of these ' +
|
|
273
|
-
"wrapping your app root — see CORE.md
|
|
318
|
+
"wrapping your app root — see CORE.md's Root Setup section. (Heuristic text scan — a false warning is possible if your root " +
|
|
274
319
|
'setup uses an unusual file layout or a re-exported alias; verify directly if you believe it\'s already wired.)'
|
|
275
320
|
);
|
|
276
321
|
}
|
package/src/index.js
CHANGED
|
@@ -29,7 +29,23 @@ program.enablePositionalOptions();
|
|
|
29
29
|
program
|
|
30
30
|
.name('toolcrib')
|
|
31
31
|
.description('Bootstrap and maintain the toolcrib UI toolkit in your project')
|
|
32
|
-
|
|
32
|
+
// Commander auto-adds -V/--version at the top level; without a custom
|
|
33
|
+
// description it just says "output the version number" with no
|
|
34
|
+
// indication of WHICH version. This is a real, confirmed source of
|
|
35
|
+
// confusion: an agent runs `toolcrib --version`, gets this CLI package's
|
|
36
|
+
// own npm version (e.g. "0.4.0"), and has no reason to suspect that
|
|
37
|
+
// number is unrelated to the toolkit content release `init`/`merge`'s
|
|
38
|
+
// own --version flag targets (a completely separate, independently-
|
|
39
|
+
// versioned GitHub Release) -- then reuses the wrong number there. The
|
|
40
|
+
// *parsing* collision between these two same-named flags was already
|
|
41
|
+
// fixed via enablePositionalOptions() above; this is the remaining
|
|
42
|
+
// *semantic* one -- disambiguated right in the text an agent actually
|
|
43
|
+
// reads when it checks.
|
|
44
|
+
.version(
|
|
45
|
+
packageJson.version,
|
|
46
|
+
'-V, --version',
|
|
47
|
+
"output this CLI tool's own npm package version -- unrelated to the toolkit content version (see `toolcrib init --version`/`toolcrib versions`)"
|
|
48
|
+
);
|
|
33
49
|
|
|
34
50
|
program
|
|
35
51
|
.command('init')
|
package/src/lib/github.js
CHANGED
|
@@ -11,40 +11,48 @@ const CHECKSUM_ASSET_NAME = 'toolcrib.zip.sha256';
|
|
|
11
11
|
const API_BASE = process.env.TOOLCRIB_API_BASE || 'https://api.github.com';
|
|
12
12
|
const RELEASES_BASE = process.env.TOOLCRIB_RELEASES_BASE || `https://github.com/${REPO}/releases`;
|
|
13
13
|
|
|
14
|
+
// GitHub's unauthenticated rate limit (60/hr, shared across every caller on
|
|
15
|
+
// the same IP — e.g. a shared CI runner or sandbox) surfaces as a plain 403,
|
|
16
|
+
// indistinguishable from a real auth/network failure unless the response
|
|
17
|
+
// headers are inspected. Left as a generic error, this sends whoever/
|
|
18
|
+
// whatever hits it down a diagnostic path (checking headers, retrying with
|
|
19
|
+
// curl, poking at User-Agent) to rediscover a fix (`toolcrib init --version
|
|
20
|
+
// <x.y.z>`) that already exists and is documented — see CLI README. Checked
|
|
21
|
+
// here so the message states the real cause and the real fix directly,
|
|
22
|
+
// instead of a bare status code. Shared by every GitHub API call in this
|
|
23
|
+
// file (not just listVersions' original one) since the failure mode and fix
|
|
24
|
+
// are identical regardless of which endpoint hit it.
|
|
25
|
+
function throwGitHubApiError(res, context) {
|
|
26
|
+
const remaining = res.status === 403 ? res.headers?.get?.('x-ratelimit-remaining') : null;
|
|
27
|
+
if (res.status === 403 && remaining === '0') {
|
|
28
|
+
const resetHeader = res.headers?.get?.('x-ratelimit-reset');
|
|
29
|
+
const resetAt = resetHeader ? new Date(Number(resetHeader) * 1000).toLocaleTimeString() : 'unknown';
|
|
30
|
+
throw new Error(
|
|
31
|
+
`GitHub's unauthenticated API rate limit (60 requests/hour, shared by IP) is exhausted — ` +
|
|
32
|
+
`resets around ${resetAt}. This only affects version *discovery* ("latest" resolution); it ` +
|
|
33
|
+
`does not affect release downloads themselves. Fix: run \`toolcrib init --version <x.y.z>\` ` +
|
|
34
|
+
`(or \`apply\`/\`merge\` with an explicit version) with a version you already know, which skips ` +
|
|
35
|
+
`this call entirely.`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`Failed to fetch ${context}: ${res.status} ${res.statusText}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
14
41
|
/**
|
|
15
42
|
* List published (non-draft) releases from the GitHub API, newest first.
|
|
16
43
|
* No auth needed for public repos; subject to the standard 60/hr
|
|
17
44
|
* unauthenticated rate limit, which is fine for occasional CLI use.
|
|
45
|
+
*
|
|
46
|
+
* Only `versionsCommand` (`toolcrib versions`, which prints every release)
|
|
47
|
+
* actually needs this full list — resolving "latest" doesn't, see
|
|
48
|
+
* fetchLatestVersion below.
|
|
18
49
|
*/
|
|
19
50
|
export async function listVersions() {
|
|
20
51
|
const res = await fetch(`${API_BASE}/repos/${REPO}/releases`, {
|
|
21
52
|
headers: { Accept: 'application/vnd.github+json' },
|
|
22
53
|
});
|
|
23
54
|
|
|
24
|
-
if (!res.ok)
|
|
25
|
-
// GitHub's unauthenticated rate limit (60/hr, shared across every caller
|
|
26
|
-
// on the same IP — e.g. a shared CI runner or sandbox) surfaces as a
|
|
27
|
-
// plain 403, indistinguishable from a real auth/network failure unless
|
|
28
|
-
// the response headers are inspected. Left as a generic error, this
|
|
29
|
-
// sends whoever/whatever hits it down a diagnostic path (checking
|
|
30
|
-
// headers, retrying with curl, poking at User-Agent) to rediscover a
|
|
31
|
-
// fix (`toolcrib init --version <x.y.z>`) that already exists and is
|
|
32
|
-
// documented — see CLI README. Checked here so the message states the
|
|
33
|
-
// real cause and the real fix directly, instead of a bare status code.
|
|
34
|
-
const remaining = res.status === 403 ? res.headers?.get?.('x-ratelimit-remaining') : null;
|
|
35
|
-
if (res.status === 403 && remaining === '0') {
|
|
36
|
-
const resetHeader = res.headers?.get?.('x-ratelimit-reset');
|
|
37
|
-
const resetAt = resetHeader ? new Date(Number(resetHeader) * 1000).toLocaleTimeString() : 'unknown';
|
|
38
|
-
throw new Error(
|
|
39
|
-
`GitHub's unauthenticated API rate limit (60 requests/hour, shared by IP) is exhausted — ` +
|
|
40
|
-
`resets around ${resetAt}. This only affects version *discovery* ("latest" resolution); it ` +
|
|
41
|
-
`does not affect release downloads themselves. Fix: run \`toolcrib init --version <x.y.z>\` ` +
|
|
42
|
-
`(or \`apply\`/\`merge\` with an explicit version) with a version you already know, which skips ` +
|
|
43
|
-
`this call entirely.`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
throw new Error(`Failed to fetch release list: ${res.status} ${res.statusText}`);
|
|
47
|
-
}
|
|
55
|
+
if (!res.ok) throwGitHubApiError(res, 'release list');
|
|
48
56
|
|
|
49
57
|
const releases = await res.json();
|
|
50
58
|
|
|
@@ -57,6 +65,59 @@ export async function listVersions() {
|
|
|
57
65
|
}));
|
|
58
66
|
}
|
|
59
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Resolve "latest" to a concrete version string via GitHub's own dedicated
|
|
70
|
+
* `/releases/latest` endpoint — "the most recent non-prerelease, non-draft
|
|
71
|
+
* release" by GitHub's own definition, matching exactly what resolveVersion
|
|
72
|
+
* used to compute client-side (`listVersions().find(v => !v.prerelease)`)
|
|
73
|
+
* after fetching *every* release's full metadata just to find the first
|
|
74
|
+
* one. Same 60/hr quota cost either way (one request either way), but a
|
|
75
|
+
* much smaller response and the semantically-correct endpoint for this
|
|
76
|
+
* exact question. 404 means no qualifying release exists yet, per GitHub's
|
|
77
|
+
* own documented behavior for this endpoint.
|
|
78
|
+
*/
|
|
79
|
+
export async function fetchLatestVersion() {
|
|
80
|
+
const res = await fetch(`${API_BASE}/repos/${REPO}/releases/latest`, {
|
|
81
|
+
headers: { Accept: 'application/vnd.github+json' },
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (res.status === 404) throw new Error('No published releases found.');
|
|
85
|
+
if (!res.ok) throwGitHubApiError(res, 'the latest release');
|
|
86
|
+
|
|
87
|
+
const release = await res.json();
|
|
88
|
+
return release.tag_name.replace(/^v/, '');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Fetch security-advisories.json fresh from the toolcrib repo's own
|
|
93
|
+
* `main` branch -- never from a consumer's vendored copy, which is a
|
|
94
|
+
* frozen snapshot from whatever version they installed and structurally
|
|
95
|
+
* can't know about anything published after that (see
|
|
96
|
+
* scripts/generate-security-advisories.js for how the file itself is
|
|
97
|
+
* generated, from real CodeQL alert state, never hand-authored).
|
|
98
|
+
*
|
|
99
|
+
* Uses the Contents API's raw media type to get the file's bytes
|
|
100
|
+
* directly rather than base64-decoding the default JSON-wrapped
|
|
101
|
+
* response. A missing file (a fresh main with nothing published yet, or
|
|
102
|
+
* before this file's first commit) is treated as "no advisories," not an
|
|
103
|
+
* error -- unlike every other call in this file, absence here is the
|
|
104
|
+
* normal, expected starting state, not a failure.
|
|
105
|
+
*
|
|
106
|
+
* Public, unauthenticated read (unlike the generator script, which needs
|
|
107
|
+
* a token to read the code-scanning alerts API this file is derived
|
|
108
|
+
* from) -- a consumer's `doctor` run never needs credentials for this.
|
|
109
|
+
*/
|
|
110
|
+
export async function fetchSecurityAdvisories() {
|
|
111
|
+
const res = await fetch(`${API_BASE}/repos/${REPO}/contents/security-advisories.json?ref=main`, {
|
|
112
|
+
headers: { Accept: 'application/vnd.github.raw+json' },
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
if (res.status === 404) return [];
|
|
116
|
+
if (!res.ok) throwGitHubApiError(res, 'security-advisories.json');
|
|
117
|
+
|
|
118
|
+
return JSON.parse(await res.text());
|
|
119
|
+
}
|
|
120
|
+
|
|
60
121
|
function assetUrl(version, assetName) {
|
|
61
122
|
return version === 'latest'
|
|
62
123
|
? `${RELEASES_BASE}/latest/download/${assetName}`
|
|
@@ -71,10 +132,7 @@ function assetUrl(version, assetName) {
|
|
|
71
132
|
*/
|
|
72
133
|
export async function resolveVersion(version) {
|
|
73
134
|
if (version !== 'latest') return version;
|
|
74
|
-
|
|
75
|
-
const newest = versions.find((v) => !v.prerelease);
|
|
76
|
-
if (!newest) throw new Error('No published releases found.');
|
|
77
|
-
return newest.version;
|
|
135
|
+
return fetchLatestVersion();
|
|
78
136
|
}
|
|
79
137
|
|
|
80
138
|
async function fetchText(url) {
|
|
@@ -98,6 +156,11 @@ function sha256(buffer) {
|
|
|
98
156
|
* and return the raw buffer. Throws on mismatch (corrupted/truncated
|
|
99
157
|
* download, or a tampered file at rest — see design notes on what a
|
|
100
158
|
* checksum does and doesn't guarantee against a compromised source).
|
|
159
|
+
*
|
|
160
|
+
* Every published release has shipped a .sha256 sibling since this
|
|
161
|
+
* mechanism was introduced — a failed fetch of it (missing, network
|
|
162
|
+
* error, or an on-path actor blocking just that request) is treated
|
|
163
|
+
* as an integrity failure, not tolerated as an older-release gap.
|
|
101
164
|
*/
|
|
102
165
|
export async function downloadReleaseZip(version) {
|
|
103
166
|
const zipUrl = assetUrl(version, ASSET_NAME);
|
|
@@ -105,18 +168,21 @@ export async function downloadReleaseZip(version) {
|
|
|
105
168
|
|
|
106
169
|
const [zipBuffer, checksumText] = await Promise.all([
|
|
107
170
|
fetchBuffer(zipUrl),
|
|
108
|
-
fetchText(checksumUrl).catch(() =>
|
|
109
|
-
]);
|
|
110
|
-
|
|
111
|
-
if (checksumText) {
|
|
112
|
-
const expected = checksumText.trim().split(/\s+/)[0];
|
|
113
|
-
const actual = sha256(zipBuffer);
|
|
114
|
-
if (actual !== expected) {
|
|
171
|
+
fetchText(checksumUrl).catch((err) => {
|
|
115
172
|
throw new Error(
|
|
116
|
-
`
|
|
117
|
-
`
|
|
173
|
+
`Failed to fetch checksum for ${ASSET_NAME} (${err.message}). ` +
|
|
174
|
+
`Refusing to install an unverified download.`
|
|
118
175
|
);
|
|
119
|
-
}
|
|
176
|
+
}),
|
|
177
|
+
]);
|
|
178
|
+
|
|
179
|
+
const expected = checksumText.trim().split(/\s+/)[0];
|
|
180
|
+
const actual = sha256(zipBuffer);
|
|
181
|
+
if (actual !== expected) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`Checksum mismatch for ${ASSET_NAME} (expected ${expected}, got ${actual}). ` +
|
|
184
|
+
`The download may be corrupted or incomplete — try again.`
|
|
185
|
+
);
|
|
120
186
|
}
|
|
121
187
|
|
|
122
188
|
return zipBuffer;
|
package/src/lib/project.js
CHANGED
|
@@ -13,12 +13,9 @@ const GITIGNORE_FENCE_ID = 'gitignore';
|
|
|
13
13
|
// literal at the start of the string. Left in place, it breaks
|
|
14
14
|
// JSON.parse() outright ("Unexpected token" — a real, well-known Node
|
|
15
15
|
// gotcha, not hypothetical: package.json/tsconfig.json saved by some
|
|
16
|
-
// Windows editors carry one)
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
// corrupting any byte-for-byte comparison against BOM-less content. Strip
|
|
20
|
-
// it at the read chokepoint, once, rather than defending against it at
|
|
21
|
-
// every call site.
|
|
16
|
+
// Windows editors carry one). readJsonIfExists strips it for exactly that
|
|
17
|
+
// reason, at the read chokepoint, once, rather than defending against it
|
|
18
|
+
// at every JSON.parse call site.
|
|
22
19
|
function stripBOM(text) {
|
|
23
20
|
return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
24
21
|
}
|
|
@@ -28,8 +25,23 @@ export function readJsonIfExists(filePath) {
|
|
|
28
25
|
return JSON.parse(stripBOM(fs.readFileSync(filePath, 'utf-8')));
|
|
29
26
|
}
|
|
30
27
|
|
|
28
|
+
// Deliberately does NOT strip a BOM, unlike readJsonIfExists above --
|
|
29
|
+
// confirmed as a real, previously-shipped bug (found via
|
|
30
|
+
// cli/integration-test/run-windows-integration.mjs, not assumed): every
|
|
31
|
+
// call site of this function feeds `changes.propose()`'s "current"
|
|
32
|
+
// argument, which becomes the literal "before" context in a real diff/
|
|
33
|
+
// patch that `git apply` later matches byte-for-byte against the real
|
|
34
|
+
// file on disk. Stripping the BOM here made that comparison start from
|
|
35
|
+
// content that no longer matches what's actually in the file -- so a
|
|
36
|
+
// project with a BOM'd package.json (PowerShell's `Out-File`/`>`
|
|
37
|
+
// redirection adds one by default) got `error: patch does not apply` on
|
|
38
|
+
// the very first line, and the patch was silently discarded, every time.
|
|
39
|
+
// The BOM in the file itself is still handled correctly elsewhere: the
|
|
40
|
+
// *new* content computed from readJsonIfExists (which does strip it) is
|
|
41
|
+
// always BOM-free, so applying the resulting patch also naturally cleans
|
|
42
|
+
// up a pre-existing BOM going forward.
|
|
31
43
|
export function readTextIfExists(filePath) {
|
|
32
|
-
return fs.existsSync(filePath) ?
|
|
44
|
+
return fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : '';
|
|
33
45
|
}
|
|
34
46
|
|
|
35
47
|
/**
|
package/src/lib/rootProvider.js
CHANGED
|
@@ -41,7 +41,7 @@ function listCandidateFiles(rootDir) {
|
|
|
41
41
|
* Read-only heuristic: does this project's own source wire up toolcrib's
|
|
42
42
|
* root providers, via `<ToolcribProvider>` or the equivalent manual
|
|
43
43
|
* `<ThemeProvider>` + `<ToastProvider>` + `<ToastContainer>` composition?
|
|
44
|
-
* Both are legitimate per `CORE.md`
|
|
44
|
+
* Both are legitimate per `CORE.md`'s Root Setup section -- this doesn't prefer one, it just
|
|
45
45
|
* confirms *something* is wired, since every toolcrib component throws or
|
|
46
46
|
* silently no-ops without it, and that failure mode gives no clue back to
|
|
47
47
|
* "you forgot the root setup."
|