* Extract the package name from a module specifier (handles scoped packages and subpaths)
(specifier: string)
| 116 | * Extract the package name from a module specifier (handles scoped packages and subpaths) |
| 117 | */ |
| 118 | function getPackageName(specifier: string): string { |
| 119 | const pkg = specifier.replace(/^['"]|['"]$/g, '').trim() |
| 120 | // Scoped package: @scope/name or @scope/name/subpath |
| 121 | if (pkg.startsWith('@')) { |
| 122 | const parts = pkg.split('/') |
| 123 | if (parts[0] && parts[1]) { |
| 124 | return `${parts[0]}/${parts[1]}` |
| 125 | } |
| 126 | } |
| 127 | // Regular package: name or name/subpath |
| 128 | const firstSlash = pkg.indexOf('/') |
| 129 | if (firstSlash > 0) { |
| 130 | return pkg.substring(0, firstSlash) |
| 131 | } |
| 132 | return pkg |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Resolved dependency info for linking imports to specific versions |