Skip to content

Commit 5f6147a

Browse files
Fix some errors
1 parent 6ec16ab commit 5f6147a

2 files changed

Lines changed: 49 additions & 37 deletions

File tree

lib/installer.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ const performInstallation = async (args, isUpdate = false) => {
108108
capabilities,
109109
log,
110110
);
111+
112+
// Handle script installation case
113+
if (result && result.method === "script") {
114+
log.log(`Successfully installed via script: ${source.repo}`);
115+
return;
116+
}
117+
111118
selected = result.selected;
112119
releaseInfo = result.releaseInfo;
113120
break;
@@ -152,8 +159,7 @@ const performInstallation = async (args, isUpdate = false) => {
152159
}
153160

154161
log.log(
155-
`Successfully ${
156-
isUpdate ? "updated" : "installed"
162+
`Successfully ${isUpdate ? "updated" : "installed"
157163
}: ${installationResult.binaries.join(", ")}`,
158164
);
159165
} finally {
@@ -238,8 +244,7 @@ const handleSmartUrlSource = async (
238244
log.debug("Assets found:");
239245
result.assets.forEach((asset, index) => {
240246
log.debug(
241-
` ${index + 1}. ${asset.name} (ext: ${
242-
asset.extension || "none"
247+
` ${index + 1}. ${asset.name} (ext: ${asset.extension || "none"
243248
}, url: ${asset.browser_download_url})`,
244249
);
245250
});
@@ -253,15 +258,14 @@ const handleSmartUrlSource = async (
253258
log.log("No compatible assets found. Available downloads:");
254259
result.assets.forEach((asset, index) => {
255260
log.log(
256-
` ${index + 1}. ${asset.name} (${
257-
asset.extension || "no extension"
261+
` ${index + 1}. ${asset.name} (${asset.extension || "no extension"
258262
}) - ${asset.browser_download_url}`,
259263
);
260264
});
261265

262266
throw new Error(
263267
`Couldn't find a compatible download for ${platformInfo.platform}/${platformInfo.arch}. ` +
264-
`Check manually: ${source.url}`,
268+
`Check manually: ${source.url}`,
265269
);
266270
}
267271

@@ -287,8 +291,7 @@ const handleWebsiteSource = async (source, platformInfo, capabilities, log) => {
287291
log.debug("Assets found:");
288292
assets.forEach((asset, index) => {
289293
log.debug(
290-
` ${index + 1}. ${asset.name} (ext: ${
291-
asset.extension || "none"
294+
` ${index + 1}. ${asset.name} (ext: ${asset.extension || "none"
292295
}, url: ${asset.browser_download_url})`,
293296
);
294297
});
@@ -302,15 +305,14 @@ const handleWebsiteSource = async (source, platformInfo, capabilities, log) => {
302305
log.log("No compatible assets found. Available downloads:");
303306
assets.forEach((asset, index) => {
304307
log.log(
305-
` ${index + 1}. ${asset.name} (${
306-
asset.extension || "no extension"
308+
` ${index + 1}. ${asset.name} (${asset.extension || "no extension"
307309
}) - ${asset.browser_download_url}`,
308310
);
309311
});
310312

311313
throw new Error(
312314
`Couldn't find a compatible download for ${platformInfo.platform}/${platformInfo.arch}. ` +
313-
`Check manually: ${source.url}`,
315+
`Check manually: ${source.url}`,
314316
);
315317
}
316318

@@ -326,10 +328,10 @@ const displayScriptPreview = (script, log) => {
326328
const { code, source, score } = script;
327329
log.log(
328330
`Found installer code in ${source} (score: ${score}):\n\n` +
329-
colors.fg.green +
330-
code +
331-
colors.reset +
332-
"\n",
331+
colors.fg.green +
332+
code +
333+
colors.reset +
334+
"\n",
333335
);
334336
};
335337

@@ -455,6 +457,8 @@ const handleGitHubSource = async (source, platformInfo, capabilities, log) => {
455457
body,
456458
);
457459

460+
log.debug(`Found ${installScripts.length} install scripts`);
461+
458462
// Check for installer.sh in assets
459463
const installerScript = assets.find((i) => i.name.includes("installer.sh"));
460464
if (installerScript) {
@@ -490,6 +494,8 @@ const handleGitHubSource = async (source, platformInfo, capabilities, log) => {
490494
const shouldUseInstallSnippets =
491495
!selected || hasHighPriorityInstallScript(installScripts);
492496

497+
log.debug(`Selected asset: ${!!selected}, use snippets: ${shouldUseInstallSnippets}, scripts: ${installScripts.length}`);
498+
493499
if (shouldUseInstallSnippets && installScripts.length > 0) {
494500
if (!selected) {
495501
log.debug(`No suitable asset found, using install scripts as fallback`);
@@ -519,7 +525,7 @@ const handleGitHubSource = async (source, platformInfo, capabilities, log) => {
519525
);
520526
addInstallation(installRecord);
521527

522-
return;
528+
return { success: true, method: "script" };
523529
}
524530
}
525531

@@ -533,7 +539,7 @@ const handleGitHubSource = async (source, platformInfo, capabilities, log) => {
533539
}
534540
throw new Error(
535541
`Couldn't find a compatible binary for ${platformInfo.platform}/${platformInfo.arch}. ` +
536-
`Check manually: https://github.com/${source.owner}/${source.repo}/releases`,
542+
`Check manually: https://github.com/${source.owner}/${source.repo}/releases`,
537543
);
538544
}
539545

lib/sources.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -533,26 +533,27 @@ const SCRIPT_DETECTION_CONFIG = {
533533
MIN_SCORE_THRESHOLD: 5,
534534
MAX_CODE_LINES: 10,
535535
REJECTION_KEYWORDS: [
536-
"installing",
537536
"](#",
538537
"](http",
539538
"- [",
540-
"ls",
541-
"cd",
542-
"pwd",
543-
"echo",
544-
"cat",
545-
"grep",
546539
"brew update",
547540
"brew upgrade",
548-
"sed",
549541
"copy and paste",
550542
"```",
551-
"sudo rm",
552-
"http://",
553543
"open powershell",
554544
"open terminal",
555545
],
546+
REJECTION_STARTSWITH: [
547+
"sudo rm",
548+
"http://",
549+
"grep ",
550+
"sed ",
551+
"ls ",
552+
"echo ",
553+
"cat ",
554+
"cd ",
555+
"pwd",
556+
],
556557
SCORE_WEIGHTS: {
557558
HIGH: 10,
558559
MEDIUM: 5,
@@ -579,12 +580,17 @@ const isInstallScript = (code) => {
579580
if (!code || typeof code !== "string") return false;
580581

581582
const lowerCode = code.toLowerCase().trim();
582-
const { REJECTION_KEYWORDS, MAX_CODE_LINES, MIN_SCORE_THRESHOLD } =
583-
SCRIPT_DETECTION_CONFIG;
584-
585-
// Reject obvious non-install scripts
583+
const {
584+
REJECTION_KEYWORDS,
585+
REJECTION_STARTSWITH,
586+
MAX_CODE_LINES,
587+
MIN_SCORE_THRESHOLD,
588+
} = SCRIPT_DETECTION_CONFIG;
589+
590+
// Reject obvious non-install scripts - only reject if script STARTS with these keywords
586591
if (
587592
REJECTION_KEYWORDS.some((keyword) => lowerCode.includes(keyword)) ||
593+
REJECTION_STARTSWITH.some((keyword) => lowerCode.startsWith(keyword)) ||
588594
lowerCode.split("\n").length > MAX_CODE_LINES
589595
) {
590596
return false;
@@ -657,21 +663,21 @@ const normalizeCode = (code) => code.replace(/\s+/g, " ").trim();
657663

658664
const removeCommentLines = (code) => {
659665
if (!code || typeof code !== 'string') return code;
660-
666+
661667
return code
662668
.split('\n')
663669
.filter(line => {
664670
const trimmedLine = line.trim();
665-
671+
666672
// Preserve shebang lines
667673
if (trimmedLine.startsWith('#!')) {
668674
return true;
669675
}
670-
676+
671677
// Remove lines that start with common comment patterns
672678
return !(
673-
trimmedLine.startsWith('#') ||
674-
trimmedLine.startsWith('//') ||
679+
trimmedLine.startsWith('#') ||
680+
trimmedLine.startsWith('//') ||
675681
trimmedLine.startsWith('/*') ||
676682
trimmedLine.startsWith('*') ||
677683
trimmedLine.startsWith('"""') ||

0 commit comments

Comments
 (0)