File tree Expand file tree Collapse file tree 2 files changed +7
-16
lines changed Expand file tree Collapse file tree 2 files changed +7
-16
lines changed Original file line number Diff line number Diff line change @@ -272,17 +272,16 @@ class Hooks {
272
272
273
273
// Avoid expensive URL instantiation for known-good URLs
274
274
if ( ! this . #validatedUrls. has ( url ) ) {
275
- try {
276
- new URL ( url ) ;
277
- this . #validatedUrls. add ( url ) ;
278
- } catch {
275
+ if ( ! URL . canParse ( url ) ) {
279
276
throw new ERR_INVALID_RETURN_PROPERTY_VALUE (
280
277
'a URL string' ,
281
278
hookErrIdentifier ,
282
279
'url' ,
283
280
url ,
284
281
) ;
285
282
}
283
+
284
+ this . #validatedUrls. add ( url ) ;
286
285
}
287
286
288
287
if (
@@ -352,16 +351,15 @@ class Hooks {
352
351
353
352
// Avoid expensive URL instantiation for known-good URLs
354
353
if ( ! this . #validatedUrls. has ( nextUrl ) ) {
355
- try {
356
- new URL ( nextUrl ) ;
357
- this . #validatedUrls. add ( nextUrl ) ;
358
- } catch {
354
+ if ( ! URL . canParse ( nextUrl ) ) {
359
355
throw new ERR_INVALID_ARG_VALUE (
360
356
`${ hookErrIdentifier } url` ,
361
357
nextUrl ,
362
358
'should be a URL string' ,
363
359
) ;
364
360
}
361
+
362
+ this . #validatedUrls. add ( nextUrl ) ;
365
363
}
366
364
367
365
if ( ctx ) { validateObject ( ctx , `${ hookErrIdentifier } context` ) ; }
Original file line number Diff line number Diff line change @@ -333,14 +333,7 @@ function resolvePackageTargetString(
333
333
if ( ! StringPrototypeStartsWith ( target , './' ) ) {
334
334
if ( internal && ! StringPrototypeStartsWith ( target , '../' ) &&
335
335
! StringPrototypeStartsWith ( target , '/' ) ) {
336
- let isURL = false ;
337
- try {
338
- new URL ( target ) ;
339
- isURL = true ;
340
- } catch {
341
- // Continue regardless of error.
342
- }
343
- if ( ! isURL ) {
336
+ if ( ! URL . canParse ( target ) ) {
344
337
const exportTarget = pattern ?
345
338
RegExpPrototypeSymbolReplace ( patternRegEx , target , ( ) => subpath ) :
346
339
target + subpath ;
You can’t perform that action at this time.
0 commit comments