|
22 | 22 | StringPrototypeSlice, |
23 | 23 | StringPrototypeSplit, |
24 | 24 | StringPrototypeStartsWith, |
25 | | - StringPrototypeSubstr, |
26 | 25 | }=primordials; |
27 | 26 | constinternalFS=require('internal/fs/utils'); |
28 | 27 | const{ NativeModule }=require('internal/bootstrap/loaders'); |
@@ -582,38 +581,49 @@ function packageImportsResolve(name, base, conditions){ |
582 | 581 | packageJSONUrl=pathToFileURL(packageConfig.pjsonPath); |
583 | 582 | constimports=packageConfig.imports; |
584 | 583 | if(imports){ |
585 | | -if(ObjectPrototypeHasOwnProperty(imports,name)){ |
| 584 | +if(ObjectPrototypeHasOwnProperty(imports,name)&& |
| 585 | +!StringPrototypeIncludes(name,'*')&& |
| 586 | +!StringPrototypeEndsWith(name,'/')){ |
586 | 587 | constresolved=resolvePackageTarget( |
587 | 588 | packageJSONUrl,imports[name],'',name,base,false,true,conditions |
588 | 589 | ); |
589 | 590 | if(resolved!==null) |
590 | 591 | return{ resolved,exact: true}; |
591 | 592 | }else{ |
592 | 593 | letbestMatch=''; |
| 594 | +letbestMatchSubpath; |
593 | 595 | constkeys=ObjectGetOwnPropertyNames(imports); |
594 | 596 | for(leti=0;i<keys.length;i++){ |
595 | 597 | constkey=keys[i]; |
596 | | -if(key[key.length-1]==='*'&& |
| 598 | +constpatternIndex=StringPrototypeIndexOf(key,'*'); |
| 599 | +if(patternIndex!==-1&& |
597 | 600 | StringPrototypeStartsWith(name, |
598 | | -StringPrototypeSlice(key,0,-1))&& |
599 | | -name.length>=key.length&& |
600 | | -key.length>bestMatch.length){ |
601 | | -bestMatch=key; |
| 601 | +StringPrototypeSlice(key,0, |
| 602 | +patternIndex))){ |
| 603 | +constpatternTrailer=StringPrototypeSlice(key,patternIndex+1); |
| 604 | +if(name.length>=key.length&& |
| 605 | +StringPrototypeEndsWith(name,patternTrailer)&& |
| 606 | +patternKeyCompare(bestMatch,key)===1&& |
| 607 | +StringPrototypeLastIndexOf(key,'*')===patternIndex){ |
| 608 | +bestMatch=key; |
| 609 | +bestMatchSubpath=StringPrototypeSlice( |
| 610 | +name,patternIndex,name.length-patternTrailer.length); |
| 611 | +} |
602 | 612 | }elseif(key[key.length-1]==='/'&& |
603 | 613 | StringPrototypeStartsWith(name,key)&& |
604 | | -key.length>bestMatch.length){ |
| 614 | +patternKeyCompare(bestMatch,key)===1){ |
605 | 615 | bestMatch=key; |
| 616 | +bestMatchSubpath=StringPrototypeSlice(name,key.length); |
606 | 617 | } |
607 | 618 | } |
608 | 619 |
|
609 | 620 | if(bestMatch){ |
610 | 621 | consttarget=imports[bestMatch]; |
611 | | -constpattern=bestMatch[bestMatch.length-1]==='*'; |
612 | | -constsubpath=StringPrototypeSubstr(name,bestMatch.length- |
613 | | -(pattern ? 1 : 0)); |
614 | | -constresolved=resolvePackageTarget( |
615 | | -packageJSONUrl,target,subpath,bestMatch,base,pattern,true, |
616 | | -conditions); |
| 622 | +constpattern=StringPrototypeIncludes(bestMatch,'*'); |
| 623 | +constresolved=resolvePackageTarget(packageJSONUrl,target, |
| 624 | +bestMatchSubpath,bestMatch, |
| 625 | +base,pattern,true, |
| 626 | +conditions); |
617 | 627 | if(resolved!==null) |
618 | 628 | return{ resolved,exact: pattern}; |
619 | 629 | } |
|
0 commit comments