(scriptContent: string)
| 128 | * @returns The file path to link to in the code tab |
| 129 | */ |
| 130 | export function getInstallScriptFilePath(scriptContent: string): string { |
| 131 | const match = NODE_SCRIPT_PATTERN.exec(scriptContent) |
| 132 | |
| 133 | if (match?.[1]) { |
| 134 | // Script is `node <file-path>`, link to that file |
| 135 | // Normalize path: strip leading ./ |
| 136 | const filePath = match[1].replace(/^\.\//, '') |
| 137 | |
| 138 | // Fall back to package.json if path contains navigational elements (the client-side routing can't handle these well) |
| 139 | if (filePath.includes('../') || filePath.includes('./')) { |
| 140 | return 'package.json' |
| 141 | } |
| 142 | |
| 143 | return filePath |
| 144 | } |
| 145 | |
| 146 | // Default: link to package.json |
| 147 | return 'package.json' |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Parse an install script into a prefix and a linkable file path. |
no outgoing calls
no test coverage detected