Skip to content

Commit 8587cc3

Browse files
sunnylqmclaude
andcommitted
fix: propagate zip entry errors, correct exit codes, versionId null unbind, Windows cresc brand detection
- enumZipEntries now rejects on callback errors instead of silently skipping entries, preventing incomplete diff patches reported as success - exit with code 1 on 401 auth failure and command errors (was 0 / 255) - install: validate package args, check spawnSync result, support Windows (.cmd shims need shell), report failures instead of silent success - update --versionId null now sends real null to unbind instead of "null" - interactive version chooser: normalize id comparison (number vs string) - rolloutConfigSet message: fill missing {{version}} placeholder - cresc brand detection: dedicated bin entry setting RNU_BRAND, no longer relies on argv[1] basename (always bin.js under Windows npm shims) - cli.json: remove unimplemented build/release commands - engines: >= 18.17.0 to match read@4 requirement Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 215d0a4 commit 8587cc3

14 files changed

Lines changed: 84 additions & 17 deletions

File tree

bun.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@
221221
}
222222
}
223223
},
224-
"build": {
225-
"description": "Bundle javascript and copy assets."
226-
},
227224
"bundle": {
228225
"description": "Bundle javascript code only and optionally publish.",
229226
"options": {
@@ -316,9 +313,6 @@
316313
}
317314
}
318315
},
319-
"release": {
320-
"description": "Push builded file to server."
321-
},
322316
"hdiff": {
323317
"description": "Create hdiff patch",
324318
"options": {

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "lib/exports.d.ts",
77
"bin": {
88
"pushy": "lib/bin.js",
9-
"cresc": "lib/bin.js"
9+
"cresc": "lib/bin-cresc.js"
1010
},
1111
"exports": {
1212
".": {
@@ -32,7 +32,7 @@
3232
"cli.json"
3333
],
3434
"scripts": {
35-
"build": "rm -rf lib && swc src -d lib --strip-leading-paths && bun run typecheck:build && chmod +x lib/bin.js",
35+
"build": "rm -rf lib && swc src -d lib --strip-leading-paths && bun run typecheck:build && chmod +x lib/bin.js lib/bin-cresc.js",
3636
"prepublishOnly": "bun run build",
3737
"typecheck": "tsc --noEmit",
3838
"typecheck:build": "tsc -p tsconfig.build.json",
@@ -87,7 +87,7 @@
8787
"@xmldom/xmldom": "0.8.13"
8888
},
8989
"engines": {
90-
"node": ">= 16.6.0"
90+
"node": ">= 18.17.0"
9191
},
9292
"devDependencies": {
9393
"@biomejs/biome": "^2.4.12",

src/bin-cresc.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env node
2+
3+
// Dedicated entry for the `cresc` bin so brand detection does not depend on
4+
// process.argv[1], which on Windows npm shims always points to the js file
5+
// instead of the invoked command name.
6+
process.env.RNU_BRAND = 'cresc';
7+
8+
require('./bin');

src/bin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ async function run() {
8383
} catch (err: any) {
8484
if (err.status === 401) {
8585
console.log(t('loginFirst'));
86-
return;
86+
process.exit(1);
8787
}
8888
console.error(err.stack);
89-
process.exit(-1);
89+
process.exit(1);
9090
}
9191
}
9292

src/diff.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ async function diffFromPPK(
182182
entry.fileName,
183183
zipOptionsForPayloadEntry(entry.fileName, entryPrefix),
184184
);
185+
readStream.on('error', reject);
185186
readStream.on('end', () => {
186187
//console.log('add finished');
187188
resolve(void 0);
@@ -318,6 +319,7 @@ async function diffFromPackage(
318319
entry.fileName,
319320
zipOptionsForPayloadEntry(entry.fileName, entryPrefix),
320321
);
322+
readStream.on('error', reject);
321323
readStream.on('end', () => {
322324
//console.log('add finished');
323325
resolve(void 0);

src/install.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
11
import { spawnSync } from 'child_process';
22
import path from 'path';
33
import type { CommandContext } from './types';
4+
import { scriptName } from './utils/constants';
5+
import { t } from './utils/i18n';
46
import { getInstallCommand } from './utils/runtime';
57

8+
// package names / version specs only — rejects shell metacharacters since
9+
// Windows needs shell: true to run package manager .cmd shims
10+
const SAFE_PACKAGE_ARG = /^[@a-z0-9^~._/-]+$/i;
11+
612
export const installCommands = {
713
install: async ({ args }: CommandContext) => {
814
if (args.length === 0) {
9-
return;
15+
throw new Error(t('installPackageRequired', { scriptName }));
16+
}
17+
for (const arg of args) {
18+
if (!SAFE_PACKAGE_ARG.test(arg)) {
19+
throw new Error(t('installPackageRequired', { scriptName }));
20+
}
1021
}
1122

1223
const cliDir = path.resolve(__dirname, '..');
1324
const installCommand = getInstallCommand(args, cliDir);
1425

15-
spawnSync(installCommand.command, installCommand.args, {
26+
const result = spawnSync(installCommand.command, installCommand.args, {
1627
cwd: cliDir,
1728
stdio: 'inherit',
29+
// package manager executables are .cmd shims on Windows
30+
shell: process.platform === 'win32',
1831
});
32+
33+
if (result.error) {
34+
throw new Error(
35+
t('installFailed', {
36+
packages: args.join(' '),
37+
error: result.error.message,
38+
}),
39+
);
40+
}
41+
if (result.status !== 0) {
42+
throw new Error(
43+
t('installFailed', {
44+
packages: args.join(' '),
45+
error: `${installCommand.command} exited with code ${result.status}`,
46+
}),
47+
);
48+
}
1949
},
2050
};

src/locales/en.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
182182
nodeHdiffpatchRequired:
183183
'This function needs "node-hdiffpatch". Please run "{{scriptName}} install node-hdiffpatch" to install',
184184
apkExtracted: 'APK extracted to {{output}}',
185+
installPackageRequired:
186+
'Please specify the package to install, e.g. "{{scriptName}} install node-hdiffpatch"',
187+
installFailed: 'Failed to install {{packages}}: {{error}}',
185188
proxyNetworkError:
186189
'Network error — likely caused by a proxy/VPN. Please try disabling your proxy and retry.',
187190
proxyNetworkErrorTips:

src/locales/zh.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ export default {
168168
nodeHdiffpatchRequired:
169169
'此功能需要 "node-hdiffpatch"。请运行 "{{scriptName}} install node-hdiffpatch" 来安装',
170170
apkExtracted: 'APK 已提取到 {{output}}',
171+
installPackageRequired:
172+
'请指定要安装的包,例如 "{{scriptName}} install node-hdiffpatch"',
173+
installFailed: '安装 {{packages}} 失败: {{error}}',
171174
proxyNetworkError:
172175
'网络连接异常,可能是代理/VPN 导致。请尝试关闭代理后重试。',
173176
proxyNetworkErrorTips:

src/utils/constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import path from 'path';
22

3-
export const scriptName = path.basename(process.argv[1]) as 'cresc' | 'pushy';
3+
export const scriptName =
4+
process.env.RNU_BRAND === 'cresc' ||
5+
path.basename(process.argv[1] ?? '') === 'cresc'
6+
? 'cresc'
7+
: 'pushy';
48
export const IS_CRESC = scriptName === 'cresc';
59

610
export const ppkBundleFileNames = ['index.bundlejs', 'bundle.harmony.js'];

0 commit comments

Comments
 (0)