toolcrib 0.11.0 → 0.11.1
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 +14 -2
- 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
|
@@ -105,7 +105,13 @@ async function postExport(options) {
|
|
|
105
105
|
const text = fs.readFileSync(path.join(dir, fileName), 'utf8');
|
|
106
106
|
return { fileName, upstreamPath: upstreamPathOf(text) ?? fileName, text };
|
|
107
107
|
});
|
|
108
|
-
plans.push({
|
|
108
|
+
plans.push({
|
|
109
|
+
folder,
|
|
110
|
+
dir,
|
|
111
|
+
summaryText,
|
|
112
|
+
files: patches.map((x) => x.upstreamPath),
|
|
113
|
+
plan: buildPostPlan({ summaryText, patches }),
|
|
114
|
+
});
|
|
109
115
|
}
|
|
110
116
|
|
|
111
117
|
if (plans.length === 0) {
|
|
@@ -132,9 +138,15 @@ async function postExport(options) {
|
|
|
132
138
|
|
|
133
139
|
p.log.info(
|
|
134
140
|
plans
|
|
135
|
-
.map(
|
|
141
|
+
.map(
|
|
142
|
+
(x) =>
|
|
143
|
+
`${x.plan.title}\n body ${x.plan.body.length} chars, ${x.plan.comments.length} comment(s)\n` +
|
|
144
|
+
` files whose full contents will be posted:\n` +
|
|
145
|
+
x.files.map((f) => ` ${f}`).join('\n')
|
|
146
|
+
)
|
|
136
147
|
.join('\n') + `\nPosting as @${login} to escape-llc/toolcrib → Consumer Patches`
|
|
137
148
|
);
|
|
149
|
+
p.log.warn("These posts go to a public GitHub repository's Discussions; anyone can read them.");
|
|
138
150
|
|
|
139
151
|
if (!options.yes) {
|
|
140
152
|
if (!isTTY) {
|
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
|
+
}
|