MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / getInstallScriptFilePath

Function getInstallScriptFilePath

app/utils/install-scripts.ts:130–148  ·  view source on GitHub ↗
(scriptContent: string)

Source from the content-addressed store, hash-verified

128 * @returns The file path to link to in the code tab
129 */
130export 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.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected