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

Function extractNpxDependencies

app/utils/install-scripts.ts:27–63  ·  view source on GitHub ↗
(
  scripts: Record<string, string> | undefined,
)

Source from the content-addressed store, hash-verified

25 * @returns Record of package name to version (or "latest" if none specified)
26 */
27export function extractNpxDependencies(
28 scripts: Record<string, string> | undefined,
29): Record<string, string> {
30 if (!scripts) return {}
31
32 const npxPackages: Record<string, string> = {}
33
34 for (const [scriptName, script] of Object.entries(scripts)) {
35 // Only check scripts that run during installation
36 if (!INSTALL_SCRIPTS.has(scriptName)) continue
37 // Reset regex state
38 NPX_PATTERN.lastIndex = 0
39
40 let match: RegExpExecArray | null
41 while ((match = NPX_PATTERN.exec(script)) !== null) {
42 const captured = match[1]
43 if (!captured) continue
44
45 // Extract package name and version
46 const parsed = PACKAGE_VERSION_PATTERN.exec(captured)
47 if (parsed && parsed[1]) {
48 const packageName = parsed[1]
49 const version = parsed[2] || 'latest'
50
51 // Skip common built-in commands that aren't packages
52 if (isBuiltinCommand(packageName)) continue
53
54 // Only add if not already present (first occurrence wins)
55 if (!(packageName in npxPackages)) {
56 npxPackages[packageName] = version
57 }
58 }
59 }
60 }
61
62 return npxPackages
63}
64
65/**
66 * Check if a command is a built-in/common command that isn't an npm package

Callers 1

Calls 1

isBuiltinCommandFunction · 0.85

Tested by

no test coverage detected