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

Function parseNodeScript

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

Source from the content-addressed store, hash-verified

157 * @returns Parsed parts, or null if no node file path was extracted
158 */
159export function parseNodeScript(
160 scriptContent: string,
161): { prefix: string; filePath: string } | null {
162 const match = NODE_SCRIPT_PATTERN.exec(scriptContent)
163
164 if (match?.[1]) {
165 const filePath = match[1].replace(/^\.\//, '')
166
167 // Fall back if path contains navigational elements
168 if (filePath.includes('../') || filePath.includes('./')) {
169 return null
170 }
171
172 // Reconstruct the prefix (everything before the captured file path)
173 const prefix = scriptContent.slice(0, match.index + match[0].indexOf(match[1]))
174 return { prefix, filePath }
175 }
176
177 return null
178}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected