dsh-coding-subscription-oauth 0.6.0 → 0.6.3
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 +236 -206
- package/CONTRIBUTING.md +129 -120
- package/INSTALL.md +221 -220
- package/LICENSE +19 -19
- package/NOTICE +11 -11
- package/README.de.md +292 -293
- package/README.es.md +293 -294
- package/README.fr.md +293 -294
- package/README.ja.md +293 -294
- package/README.ko.md +293 -294
- package/README.md +307 -308
- package/README.pt-BR.md +293 -294
- package/README.ru.md +293 -294
- package/README.zh-CN.md +305 -306
- package/compatibility/dsh-bom.json +17 -30
- package/cordis.patch.yml +13 -13
- package/docs/00-project-rules.md +212 -195
- package/docs/02-architecture.md +130 -130
- package/docs/02-architecture.zh-CN.md +130 -130
- package/lib/adapter.d.ts.map +1 -1
- package/lib/alias-adapter.d.ts +3 -1
- package/lib/alias-adapter.d.ts.map +1 -1
- package/lib/bin.js +3 -3
- package/lib/bin.js.map +2 -2
- package/lib/capability-settings.d.ts +8 -2
- package/lib/capability-settings.d.ts.map +1 -1
- package/lib/capability-tools.d.ts +7 -2
- package/lib/capability-tools.d.ts.map +1 -1
- package/lib/client.js +3 -3
- package/lib/client.js.map +4 -4
- package/lib/codex-images.d.ts +8 -0
- package/lib/codex-images.d.ts.map +1 -1
- package/lib/compatibility.d.ts +14 -14
- package/lib/dsh-host-adapter.d.ts.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +141 -86
- package/lib/index.js.map +3 -3
- package/lib/invariant.js.map +1 -1
- package/media/en/settings_gateway.png +0 -0
- package/media/zh-CN/settings_gateway.png +0 -0
- package/package.json +185 -185
- package/patches/dsh-agy@0.1.2.patch +25 -25
- package/scripts/release.mjs +186 -186
- package/scripts/smoke-deployed-routes.mjs +146 -146
- package/scripts/verify-deployed-catalog.mjs +87 -87
- package/src/adapter.ts +348 -287
- package/src/alias-adapter.ts +147 -153
- package/src/auth-routes.ts +921 -921
- package/src/auth.ts +67 -67
- package/src/bin.ts +350 -350
- package/src/capability-routes.ts +279 -279
- package/src/capability-runtime.ts +314 -313
- package/src/capability-settings.ts +671 -658
- package/src/capability-tools.ts +685 -666
- package/src/catalog.ts +271 -271
- package/src/client/GrokBuildSettings.tsx +771 -770
- package/src/client/api.ts +88 -88
- package/src/client/components/AboutTab.tsx +30 -30
- package/src/client/components/AccountsTab.tsx +241 -241
- package/src/client/components/Badge.tsx +33 -33
- package/src/client/components/CapabilitiesTab.tsx +265 -265
- package/src/client/components/CliPullPreview.tsx +116 -116
- package/src/client/components/CopyButton.tsx +57 -57
- package/src/client/components/GatewayTab.tsx +469 -469
- package/src/client/components/NoticeBanner.tsx +46 -46
- package/src/client/components/ProgressBar.tsx +53 -53
- package/src/client/components/ProviderCard.tsx +606 -606
- package/src/client/components/SettingsTabs.tsx +75 -75
- package/src/client/components/ToggleSwitch.tsx +71 -71
- package/src/client/constants.ts +230 -224
- package/src/client/display.ts +61 -61
- package/src/client/dshClientAdapter.ts +127 -109
- package/src/client/gatewaySnippets.ts +37 -37
- package/src/client/index.tsx +156 -156
- package/src/client/locales.ts +540 -535
- package/src/client/microStyles.ts +52 -52
- package/src/client/parsers.ts +398 -396
- package/src/client/styles.ts +325 -325
- package/src/client/types.ts +199 -197
- package/src/codex-http.ts +447 -447
- package/src/codex-images.ts +503 -485
- package/src/codex-model-capabilities.ts +320 -320
- package/src/codex-search.ts +245 -245
- package/src/codex-usage.ts +263 -263
- package/src/compatibility.ts +55 -55
- package/src/dsh-host-adapter.ts +173 -171
- package/src/gateway-anthropic-messages.ts +84 -84
- package/src/gateway-auth.ts +102 -102
- package/src/gateway-backend.ts +274 -274
- package/src/gateway-body.ts +49 -49
- package/src/gateway-config.ts +76 -76
- package/src/gateway-http.ts +104 -104
- package/src/gateway-openai-chat.ts +124 -124
- package/src/gateway-openai-responses.ts +53 -53
- package/src/gateway-parse.ts +224 -224
- package/src/gateway-protocol.ts +52 -52
- package/src/gateway-routes.ts +158 -158
- package/src/gateway.ts +258 -258
- package/src/grok-errors.ts +24 -24
- package/src/grok-imagine.ts +1627 -1627
- package/src/grok-import.ts +151 -151
- package/src/http-json.ts +82 -82
- package/src/ids.ts +59 -59
- package/src/imagine-routes.ts +463 -463
- package/src/index.ts +735 -748
- package/src/invariant.ts +17 -17
- package/src/kimi-errors.ts +26 -26
- package/src/media-store.ts +927 -927
- package/src/oauth-import-routes.ts +324 -324
- package/src/oauth-providers.ts +152 -152
- package/src/oauth-session.ts +183 -183
- package/src/oauth-sources.ts +1104 -1104
- package/src/oauth.ts +620 -620
- package/src/provider.ts +128 -128
- package/src/proxy.ts +11 -11
- package/src/redact.ts +72 -72
- package/src/session.ts +218 -218
- package/src/store.ts +217 -217
- package/src/web-origin.ts +296 -296
- package/src/web-routes.ts +38 -38
package/scripts/release.mjs
CHANGED
|
@@ -1,186 +1,186 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Local release verifier/packer.
|
|
4
|
-
*
|
|
5
|
-
* This helper never bumps versions, commits, tags, pushes, or publishes. Those
|
|
6
|
-
* operations require an explicit human decision outside this script.
|
|
7
|
-
*/
|
|
8
|
-
import { spawnSync } from "node:child_process";
|
|
9
|
-
import { access, mkdir, readFile, rename, rm } from "node:fs/promises";
|
|
10
|
-
import { dirname, join, resolve } from "node:path";
|
|
11
|
-
import { fileURLToPath } from "node:url";
|
|
12
|
-
|
|
13
|
-
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
14
|
-
const output = join(root, "output");
|
|
15
|
-
const knownFlags = new Set(["--dry-run", "--pack", "--help"]);
|
|
16
|
-
const args = new Set(process.argv.slice(2));
|
|
17
|
-
for (const argument of args) {
|
|
18
|
-
if (!knownFlags.has(argument)) {
|
|
19
|
-
console.error(`Unknown option: ${argument}`);
|
|
20
|
-
process.exit(2);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (args.has("--dry-run") && args.has("--pack")) {
|
|
24
|
-
console.error("Choose either --dry-run or --pack, not both.");
|
|
25
|
-
process.exit(2);
|
|
26
|
-
}
|
|
27
|
-
if (args.has("--help")) {
|
|
28
|
-
console.log(`dsh-coding-subscription-oauth release helper
|
|
29
|
-
|
|
30
|
-
Usage:
|
|
31
|
-
node scripts/release.mjs --dry-run Verify current release artifacts and packed file list
|
|
32
|
-
node scripts/release.mjs --pack Rebuild, verify, and write a local tarball under output/
|
|
33
|
-
|
|
34
|
-
This command never changes versions, commits, tags, pushes, or publishes.`);
|
|
35
|
-
process.exit(0);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const mode = args.has("--pack") ? "pack" : "dry-run";
|
|
39
|
-
const manifest = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
|
|
40
|
-
const changelog = await readFile(join(root, "CHANGELOG.md"), "utf8");
|
|
41
|
-
const readme = await readFile(join(root, "README.md"), "utf8");
|
|
42
|
-
const expectedName = "dsh-coding-subscription-oauth";
|
|
43
|
-
const semver = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/u;
|
|
44
|
-
|
|
45
|
-
function fail(message) {
|
|
46
|
-
throw new Error(message);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function run(command, commandArgs, options = {}) {
|
|
50
|
-
let executable = command;
|
|
51
|
-
let args = commandArgs;
|
|
52
|
-
if (process.platform === "win32" && command === "pnpm") {
|
|
53
|
-
const pnpmCli =
|
|
54
|
-
process.env.npm_execpath ??
|
|
55
|
-
(process.env.APPDATA === undefined
|
|
56
|
-
? undefined
|
|
57
|
-
: resolve(process.env.APPDATA, "npm/node_modules/pnpm/bin/pnpm.cjs"));
|
|
58
|
-
if (pnpmCli === undefined) fail("pnpm CLI path is unavailable on Windows");
|
|
59
|
-
executable = process.execPath;
|
|
60
|
-
args = [pnpmCli, ...commandArgs];
|
|
61
|
-
} else if (process.platform === "win32" && command === "npm") {
|
|
62
|
-
executable = process.execPath;
|
|
63
|
-
args = [resolve(dirname(process.execPath), "node_modules/npm/bin/npm-cli.js"), ...commandArgs];
|
|
64
|
-
}
|
|
65
|
-
const result = spawnSync(executable, args, {
|
|
66
|
-
cwd: root,
|
|
67
|
-
encoding: "utf8",
|
|
68
|
-
stdio: options.capture === true ? ["ignore", "pipe", "pipe"] : "inherit",
|
|
69
|
-
});
|
|
70
|
-
if (result.error !== undefined) throw result.error;
|
|
71
|
-
if (result.status !== 0) {
|
|
72
|
-
const details = options.capture === true ? `${result.stderr ?? ""}${result.stdout ?? ""}`.trim() : "";
|
|
73
|
-
fail(`${command} ${commandArgs.join(" ")} failed${details === "" ? "" : `:\n${details}`}`);
|
|
74
|
-
}
|
|
75
|
-
return result.stdout ?? "";
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (manifest.name !== expectedName) fail(`package name must be ${expectedName}; found ${String(manifest.name)}`);
|
|
79
|
-
if (typeof manifest.version !== "string" || !semver.test(manifest.version)) {
|
|
80
|
-
fail(`package version is not valid semver: ${String(manifest.version)}`);
|
|
81
|
-
}
|
|
82
|
-
if (manifest.private === true) fail("release package must not be private");
|
|
83
|
-
|
|
84
|
-
const releaseVersions = [
|
|
85
|
-
...changelog.matchAll(/^##\s+v?(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)(?:\s+-\s+\d{4}-\d{2}-\d{2})?\s*$/gmu),
|
|
86
|
-
].map((match) => match[1]);
|
|
87
|
-
if (releaseVersions[0] !== manifest.version) {
|
|
88
|
-
fail(`top CHANGELOG release (${releaseVersions[0] ?? "missing"}) does not match package version ${manifest.version}`);
|
|
89
|
-
}
|
|
90
|
-
if (!readme.includes(manifest.version)) fail(`README.md does not mention ${manifest.version}`);
|
|
91
|
-
const installDoc = await readFile(join(root, "INSTALL.md"), "utf8");
|
|
92
|
-
if (!installDoc.includes(manifest.version)) fail(`INSTALL.md does not mention ${manifest.version}`);
|
|
93
|
-
const readmeZh = await readFile(join(root, "README.zh-CN.md"), "utf8");
|
|
94
|
-
if (!readmeZh.includes(manifest.version)) fail(`README.zh-CN.md does not mention ${manifest.version}`);
|
|
95
|
-
|
|
96
|
-
if (mode === "pack") run("pnpm", ["run", "release:build"]);
|
|
97
|
-
else run("pnpm", ["run", "release:verify"]);
|
|
98
|
-
|
|
99
|
-
const packOutput = run("npm", ["pack", "--dry-run", "--json", "--ignore-scripts"], { capture: true });
|
|
100
|
-
let packReport;
|
|
101
|
-
try {
|
|
102
|
-
packReport = JSON.parse(packOutput);
|
|
103
|
-
} catch (error) {
|
|
104
|
-
throw new Error("npm pack --dry-run returned invalid JSON", { cause: error });
|
|
105
|
-
}
|
|
106
|
-
const report = Array.isArray(packReport) ? packReport[0] : undefined;
|
|
107
|
-
if (report === undefined || !Array.isArray(report.files)) fail("npm pack did not return a file manifest");
|
|
108
|
-
const packedFiles = report.files.map((entry) => entry.path).sort();
|
|
109
|
-
const packed = new Set(packedFiles);
|
|
110
|
-
const missingModes = report.files.filter((entry) => typeof entry.mode !== "number").map((entry) => entry.path);
|
|
111
|
-
if (missingModes.length > 0) fail(`npm pack omitted file modes:\n${missingModes.sort().join("\n")}`);
|
|
112
|
-
const privateModes = report.files
|
|
113
|
-
.filter((entry) => typeof entry.mode === "number" && (entry.mode & 0o044) !== 0o044)
|
|
114
|
-
.map((entry) => `${entry.path} (${entry.mode.toString(8)})`)
|
|
115
|
-
.sort();
|
|
116
|
-
if (privateModes.length > 0)
|
|
117
|
-
fail(`packed release contains files unreadable outside their owner:\n${privateModes.join("\n")}`);
|
|
118
|
-
const writableModes = report.files
|
|
119
|
-
.filter((entry) => typeof entry.mode === "number" && (entry.mode & 0o022) !== 0)
|
|
120
|
-
.map((entry) => `${entry.path} (${entry.mode.toString(8)})`)
|
|
121
|
-
.sort();
|
|
122
|
-
if (writableModes.length > 0) fail(`packed release contains group/world-writable files:\n${writableModes.join("\n")}`);
|
|
123
|
-
for (const required of [
|
|
124
|
-
"package.json",
|
|
125
|
-
"README.md",
|
|
126
|
-
"LICENSE",
|
|
127
|
-
"cordis.patch.yml",
|
|
128
|
-
"lib/index.js",
|
|
129
|
-
"lib/index.d.ts",
|
|
130
|
-
"lib/client.js",
|
|
131
|
-
"lib/bin.js",
|
|
132
|
-
"lib/invariant.js",
|
|
133
|
-
"compatibility/dsh-bom.json",
|
|
134
|
-
]) {
|
|
135
|
-
if (!packed.has(required)) fail(`packed release is missing ${required}`);
|
|
136
|
-
}
|
|
137
|
-
const packedBin = report.files.find((entry) => entry.path === "lib/bin.js");
|
|
138
|
-
if (process.platform !== "win32" && typeof packedBin?.mode === "number" && (packedBin.mode & 0o111) === 0) {
|
|
139
|
-
fail(`packed CLI is not executable: lib/bin.js (${packedBin.mode.toString(8)})`);
|
|
140
|
-
}
|
|
141
|
-
const forbiddenFragments = [
|
|
142
|
-
"docs/local",
|
|
143
|
-
"reference/",
|
|
144
|
-
".env",
|
|
145
|
-
".secrets",
|
|
146
|
-
"package-lock.json",
|
|
147
|
-
"tsdown.config",
|
|
148
|
-
"lib/client.cjs",
|
|
149
|
-
"docs/MIGRATION.md",
|
|
150
|
-
];
|
|
151
|
-
const leaked = packedFiles.filter((path) => forbiddenFragments.some((fragment) => path.includes(fragment)));
|
|
152
|
-
if (leaked.length > 0) fail(`packed release contains forbidden files:\n${leaked.join("\n")}`);
|
|
153
|
-
|
|
154
|
-
console.log(`Verified ${manifest.name}@${manifest.version}`);
|
|
155
|
-
console.log(`Packed files: ${packedFiles.length}`);
|
|
156
|
-
|
|
157
|
-
if (mode === "dry-run") {
|
|
158
|
-
console.log("Dry-run complete. No version, Git, registry, or tarball changes were made.");
|
|
159
|
-
process.exit(0);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const staging = join(output, `.pack-${process.pid}`);
|
|
163
|
-
await rm(staging, { recursive: true, force: true });
|
|
164
|
-
await mkdir(staging, { recursive: true });
|
|
165
|
-
try {
|
|
166
|
-
const actualOutput = run("npm", ["pack", "--json", "--ignore-scripts", "--pack-destination", staging], {
|
|
167
|
-
capture: true,
|
|
168
|
-
});
|
|
169
|
-
let actualReport;
|
|
170
|
-
try {
|
|
171
|
-
actualReport = JSON.parse(actualOutput);
|
|
172
|
-
} catch (error) {
|
|
173
|
-
throw new Error("npm pack returned invalid JSON", { cause: error });
|
|
174
|
-
}
|
|
175
|
-
const filename = Array.isArray(actualReport) ? actualReport[0]?.filename : undefined;
|
|
176
|
-
if (typeof filename !== "string" || filename.length === 0) fail("npm pack did not report a tarball filename");
|
|
177
|
-
const source = join(staging, filename);
|
|
178
|
-
await access(source);
|
|
179
|
-
await mkdir(output, { recursive: true });
|
|
180
|
-
const target = join(output, `${manifest.name}-${manifest.version}.tgz`);
|
|
181
|
-
await rm(target, { force: true });
|
|
182
|
-
await rename(source, target);
|
|
183
|
-
console.log(`Wrote ${target}`);
|
|
184
|
-
} finally {
|
|
185
|
-
await rm(staging, { recursive: true, force: true });
|
|
186
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Local release verifier/packer.
|
|
4
|
+
*
|
|
5
|
+
* This helper never bumps versions, commits, tags, pushes, or publishes. Those
|
|
6
|
+
* operations require an explicit human decision outside this script.
|
|
7
|
+
*/
|
|
8
|
+
import { spawnSync } from "node:child_process";
|
|
9
|
+
import { access, mkdir, readFile, rename, rm } from "node:fs/promises";
|
|
10
|
+
import { dirname, join, resolve } from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
|
|
13
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
14
|
+
const output = join(root, "output");
|
|
15
|
+
const knownFlags = new Set(["--dry-run", "--pack", "--help"]);
|
|
16
|
+
const args = new Set(process.argv.slice(2));
|
|
17
|
+
for (const argument of args) {
|
|
18
|
+
if (!knownFlags.has(argument)) {
|
|
19
|
+
console.error(`Unknown option: ${argument}`);
|
|
20
|
+
process.exit(2);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (args.has("--dry-run") && args.has("--pack")) {
|
|
24
|
+
console.error("Choose either --dry-run or --pack, not both.");
|
|
25
|
+
process.exit(2);
|
|
26
|
+
}
|
|
27
|
+
if (args.has("--help")) {
|
|
28
|
+
console.log(`dsh-coding-subscription-oauth release helper
|
|
29
|
+
|
|
30
|
+
Usage:
|
|
31
|
+
node scripts/release.mjs --dry-run Verify current release artifacts and packed file list
|
|
32
|
+
node scripts/release.mjs --pack Rebuild, verify, and write a local tarball under output/
|
|
33
|
+
|
|
34
|
+
This command never changes versions, commits, tags, pushes, or publishes.`);
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const mode = args.has("--pack") ? "pack" : "dry-run";
|
|
39
|
+
const manifest = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
|
|
40
|
+
const changelog = await readFile(join(root, "CHANGELOG.md"), "utf8");
|
|
41
|
+
const readme = await readFile(join(root, "README.md"), "utf8");
|
|
42
|
+
const expectedName = "dsh-coding-subscription-oauth";
|
|
43
|
+
const semver = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/u;
|
|
44
|
+
|
|
45
|
+
function fail(message) {
|
|
46
|
+
throw new Error(message);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function run(command, commandArgs, options = {}) {
|
|
50
|
+
let executable = command;
|
|
51
|
+
let args = commandArgs;
|
|
52
|
+
if (process.platform === "win32" && command === "pnpm") {
|
|
53
|
+
const pnpmCli =
|
|
54
|
+
process.env.npm_execpath ??
|
|
55
|
+
(process.env.APPDATA === undefined
|
|
56
|
+
? undefined
|
|
57
|
+
: resolve(process.env.APPDATA, "npm/node_modules/pnpm/bin/pnpm.cjs"));
|
|
58
|
+
if (pnpmCli === undefined) fail("pnpm CLI path is unavailable on Windows");
|
|
59
|
+
executable = process.execPath;
|
|
60
|
+
args = [pnpmCli, ...commandArgs];
|
|
61
|
+
} else if (process.platform === "win32" && command === "npm") {
|
|
62
|
+
executable = process.execPath;
|
|
63
|
+
args = [resolve(dirname(process.execPath), "node_modules/npm/bin/npm-cli.js"), ...commandArgs];
|
|
64
|
+
}
|
|
65
|
+
const result = spawnSync(executable, args, {
|
|
66
|
+
cwd: root,
|
|
67
|
+
encoding: "utf8",
|
|
68
|
+
stdio: options.capture === true ? ["ignore", "pipe", "pipe"] : "inherit",
|
|
69
|
+
});
|
|
70
|
+
if (result.error !== undefined) throw result.error;
|
|
71
|
+
if (result.status !== 0) {
|
|
72
|
+
const details = options.capture === true ? `${result.stderr ?? ""}${result.stdout ?? ""}`.trim() : "";
|
|
73
|
+
fail(`${command} ${commandArgs.join(" ")} failed${details === "" ? "" : `:\n${details}`}`);
|
|
74
|
+
}
|
|
75
|
+
return result.stdout ?? "";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (manifest.name !== expectedName) fail(`package name must be ${expectedName}; found ${String(manifest.name)}`);
|
|
79
|
+
if (typeof manifest.version !== "string" || !semver.test(manifest.version)) {
|
|
80
|
+
fail(`package version is not valid semver: ${String(manifest.version)}`);
|
|
81
|
+
}
|
|
82
|
+
if (manifest.private === true) fail("release package must not be private");
|
|
83
|
+
|
|
84
|
+
const releaseVersions = [
|
|
85
|
+
...changelog.matchAll(/^##\s+v?(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)(?:\s+-\s+\d{4}-\d{2}-\d{2})?\s*$/gmu),
|
|
86
|
+
].map((match) => match[1]);
|
|
87
|
+
if (releaseVersions[0] !== manifest.version) {
|
|
88
|
+
fail(`top CHANGELOG release (${releaseVersions[0] ?? "missing"}) does not match package version ${manifest.version}`);
|
|
89
|
+
}
|
|
90
|
+
if (!readme.includes(manifest.version)) fail(`README.md does not mention ${manifest.version}`);
|
|
91
|
+
const installDoc = await readFile(join(root, "INSTALL.md"), "utf8");
|
|
92
|
+
if (!installDoc.includes(manifest.version)) fail(`INSTALL.md does not mention ${manifest.version}`);
|
|
93
|
+
const readmeZh = await readFile(join(root, "README.zh-CN.md"), "utf8");
|
|
94
|
+
if (!readmeZh.includes(manifest.version)) fail(`README.zh-CN.md does not mention ${manifest.version}`);
|
|
95
|
+
|
|
96
|
+
if (mode === "pack") run("pnpm", ["run", "release:build"]);
|
|
97
|
+
else run("pnpm", ["run", "release:verify"]);
|
|
98
|
+
|
|
99
|
+
const packOutput = run("npm", ["pack", "--dry-run", "--json", "--ignore-scripts"], { capture: true });
|
|
100
|
+
let packReport;
|
|
101
|
+
try {
|
|
102
|
+
packReport = JSON.parse(packOutput);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw new Error("npm pack --dry-run returned invalid JSON", { cause: error });
|
|
105
|
+
}
|
|
106
|
+
const report = Array.isArray(packReport) ? packReport[0] : undefined;
|
|
107
|
+
if (report === undefined || !Array.isArray(report.files)) fail("npm pack did not return a file manifest");
|
|
108
|
+
const packedFiles = report.files.map((entry) => entry.path).sort();
|
|
109
|
+
const packed = new Set(packedFiles);
|
|
110
|
+
const missingModes = report.files.filter((entry) => typeof entry.mode !== "number").map((entry) => entry.path);
|
|
111
|
+
if (missingModes.length > 0) fail(`npm pack omitted file modes:\n${missingModes.sort().join("\n")}`);
|
|
112
|
+
const privateModes = report.files
|
|
113
|
+
.filter((entry) => typeof entry.mode === "number" && (entry.mode & 0o044) !== 0o044)
|
|
114
|
+
.map((entry) => `${entry.path} (${entry.mode.toString(8)})`)
|
|
115
|
+
.sort();
|
|
116
|
+
if (privateModes.length > 0)
|
|
117
|
+
fail(`packed release contains files unreadable outside their owner:\n${privateModes.join("\n")}`);
|
|
118
|
+
const writableModes = report.files
|
|
119
|
+
.filter((entry) => typeof entry.mode === "number" && (entry.mode & 0o022) !== 0)
|
|
120
|
+
.map((entry) => `${entry.path} (${entry.mode.toString(8)})`)
|
|
121
|
+
.sort();
|
|
122
|
+
if (writableModes.length > 0) fail(`packed release contains group/world-writable files:\n${writableModes.join("\n")}`);
|
|
123
|
+
for (const required of [
|
|
124
|
+
"package.json",
|
|
125
|
+
"README.md",
|
|
126
|
+
"LICENSE",
|
|
127
|
+
"cordis.patch.yml",
|
|
128
|
+
"lib/index.js",
|
|
129
|
+
"lib/index.d.ts",
|
|
130
|
+
"lib/client.js",
|
|
131
|
+
"lib/bin.js",
|
|
132
|
+
"lib/invariant.js",
|
|
133
|
+
"compatibility/dsh-bom.json",
|
|
134
|
+
]) {
|
|
135
|
+
if (!packed.has(required)) fail(`packed release is missing ${required}`);
|
|
136
|
+
}
|
|
137
|
+
const packedBin = report.files.find((entry) => entry.path === "lib/bin.js");
|
|
138
|
+
if (process.platform !== "win32" && typeof packedBin?.mode === "number" && (packedBin.mode & 0o111) === 0) {
|
|
139
|
+
fail(`packed CLI is not executable: lib/bin.js (${packedBin.mode.toString(8)})`);
|
|
140
|
+
}
|
|
141
|
+
const forbiddenFragments = [
|
|
142
|
+
"docs/local",
|
|
143
|
+
"reference/",
|
|
144
|
+
".env",
|
|
145
|
+
".secrets",
|
|
146
|
+
"package-lock.json",
|
|
147
|
+
"tsdown.config",
|
|
148
|
+
"lib/client.cjs",
|
|
149
|
+
"docs/MIGRATION.md",
|
|
150
|
+
];
|
|
151
|
+
const leaked = packedFiles.filter((path) => forbiddenFragments.some((fragment) => path.includes(fragment)));
|
|
152
|
+
if (leaked.length > 0) fail(`packed release contains forbidden files:\n${leaked.join("\n")}`);
|
|
153
|
+
|
|
154
|
+
console.log(`Verified ${manifest.name}@${manifest.version}`);
|
|
155
|
+
console.log(`Packed files: ${packedFiles.length}`);
|
|
156
|
+
|
|
157
|
+
if (mode === "dry-run") {
|
|
158
|
+
console.log("Dry-run complete. No version, Git, registry, or tarball changes were made.");
|
|
159
|
+
process.exit(0);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const staging = join(output, `.pack-${process.pid}`);
|
|
163
|
+
await rm(staging, { recursive: true, force: true });
|
|
164
|
+
await mkdir(staging, { recursive: true });
|
|
165
|
+
try {
|
|
166
|
+
const actualOutput = run("npm", ["pack", "--json", "--ignore-scripts", "--pack-destination", staging], {
|
|
167
|
+
capture: true,
|
|
168
|
+
});
|
|
169
|
+
let actualReport;
|
|
170
|
+
try {
|
|
171
|
+
actualReport = JSON.parse(actualOutput);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
throw new Error("npm pack returned invalid JSON", { cause: error });
|
|
174
|
+
}
|
|
175
|
+
const filename = Array.isArray(actualReport) ? actualReport[0]?.filename : undefined;
|
|
176
|
+
if (typeof filename !== "string" || filename.length === 0) fail("npm pack did not report a tarball filename");
|
|
177
|
+
const source = join(staging, filename);
|
|
178
|
+
await access(source);
|
|
179
|
+
await mkdir(output, { recursive: true });
|
|
180
|
+
const target = join(output, `${manifest.name}-${manifest.version}.tgz`);
|
|
181
|
+
await rm(target, { force: true });
|
|
182
|
+
await rename(source, target);
|
|
183
|
+
console.log(`Wrote ${target}`);
|
|
184
|
+
} finally {
|
|
185
|
+
await rm(staging, { recursive: true, force: true });
|
|
186
|
+
}
|