* Parse a package name from a specifier. * @param {string} specifier - The import specifier. * @param {string | URL | undefined} base - The parent URL. * @returns {object}
(specifier, base)
| 231 | * @returns {object} |
| 232 | */ |
| 233 | function parsePackageName(specifier, base) { |
| 234 | let separatorIndex = StringPrototypeIndexOf(specifier, '/'); |
| 235 | let validPackageName = true; |
| 236 | let isScoped = false; |
| 237 | if (specifier[0] === '@') { |
| 238 | isScoped = true; |
| 239 | if (separatorIndex === -1 || specifier.length === 0) { |
| 240 | validPackageName = false; |
| 241 | } else { |
| 242 | separatorIndex = StringPrototypeIndexOf( |
| 243 | specifier, '/', separatorIndex + 1); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | const packageName = separatorIndex === -1 ? |
| 248 | specifier : StringPrototypeSlice(specifier, 0, separatorIndex); |
| 249 | |
| 250 | // Package name cannot have leading . and cannot have percent-encoding or |
| 251 | // \\ separators. |
| 252 | if (RegExpPrototypeExec(invalidPackageNameRegEx, packageName) !== null) { |
| 253 | validPackageName = false; |
| 254 | } |
| 255 | |
| 256 | if (!validPackageName) { |
| 257 | throw new ERR_INVALID_MODULE_SPECIFIER( |
| 258 | specifier, 'is not a valid package name', fileURLToPath(base)); |
| 259 | } |
| 260 | |
| 261 | const packageSubpath = '.' + (separatorIndex === -1 ? '' : |
| 262 | StringPrototypeSlice(specifier, separatorIndex)); |
| 263 | |
| 264 | return { packageName, packageSubpath, isScoped }; |
| 265 | } |
| 266 | |
| 267 | function getPackageJSONURL(specifier, base) { |
| 268 | const { packageName, packageSubpath, isScoped } = parsePackageName(specifier, base); |
no test coverage detected
searching dependent graphs…