* Check if a module specifier is an npm package (not a relative/absolute path or Node built-in)
(specifier: string)
| 99 | * Check if a module specifier is an npm package (not a relative/absolute path or Node built-in) |
| 100 | */ |
| 101 | function isNpmPackage(specifier: string): boolean { |
| 102 | // Remove quotes |
| 103 | const pkg = specifier.replace(/^['"]|['"]$/g, '').trim() |
| 104 | // Relative or absolute paths |
| 105 | if (pkg.startsWith('.') || pkg.startsWith('/')) return false |
| 106 | // Node built-ins with node: prefix |
| 107 | if (pkg.startsWith('node:')) return false |
| 108 | // Node built-ins without prefix |
| 109 | if (isBuiltin(pkg)) return false |
| 110 | // Empty |
| 111 | if (!pkg) return false |
| 112 | return true |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Extract the package name from a module specifier (handles scoped packages and subpaths) |