@@ -57,6 +57,10 @@ function doesChildVersionMatch (child, requested, requestor) {
5757 if ( fromSw . toString ( ) === requested . toString ( ) ) return true
5858 }
5959
60+ if ( requested . type === 'alias' ) {
61+ return doesChildVersionMatch ( child , requested . subSpec , requestor )
62+ }
63+
6064 if ( ! registryTypes [ requested . type ] ) {
6165 var childReq = child . package . _requested
6266 if ( childReq ) {
@@ -72,7 +76,7 @@ function doesChildVersionMatch (child, requested, requestor) {
7276 // You'll see this scenario happen with at least tags and git dependencies.
7377 // Some buggy clients will write spaces into the module name part of a _from.
7478 if ( child . package . _from ) {
75- var fromReq = npa . resolve ( moduleName ( child ) , child . package . _from . replace ( new RegExp ( '^\\s*' + moduleName ( child ) + '\\s*@' ) , '' ) )
79+ var fromReq = npa ( child . package . _from )
7680 if ( fromReq . rawSpec === requested . rawSpec ) return true
7781 if ( fromReq . type === requested . type && fromReq . saveSpec && fromReq . saveSpec === requested . saveSpec ) return true
7882 }
@@ -289,13 +293,15 @@ function computeVersionSpec (tree, child) {
289293 var requested
290294 var childReq = child . package . _requested
291295 if ( child . isLink ) {
292- requested = npa . resolve ( child . package . name , 'file:' + child . realpath , getTop ( tree ) . path )
296+ requested = npa . resolve ( moduleName ( child ) , 'file:' + child . realpath , getTop ( tree ) . path )
293297 } else if ( childReq && ( isNotEmpty ( childReq . saveSpec ) || ( isNotEmpty ( childReq . rawSpec ) && isNotEmpty ( childReq . fetchSpec ) ) ) ) {
294298 requested = child . package . _requested
295299 } else if ( child . package . _from ) {
296300 requested = npa ( child . package . _from , tree . path )
301+ } else if ( child . name && child . name !== child . package . name ) {
302+ requested = npa . resolve ( child . name , `npm:${ child . package . name } @${ child . package . version } )` )
297303 } else {
298- requested = npa . resolve ( child . package . name , child . package . version )
304+ npa . resolve ( child . package . name , child . package . version )
299305 }
300306 if ( isRegistry ( requested ) ) {
301307 var version = child . package . version
@@ -305,6 +311,9 @@ function computeVersionSpec (tree, child) {
305311 ! npm . config . get ( 'save-exact' ) ) {
306312 rangeDescriptor = npm . config . get ( 'save-prefix' )
307313 }
314+ if ( requested . type === 'alias' ) {
315+ rangeDescriptor = `npm:${ requested . subSpec . name } @${ rangeDescriptor } `
316+ }
308317 return rangeDescriptor + version
309318 } else if ( requested . type === 'directory' || requested . type === 'file' ) {
310319 return 'file:' + unixFormatPath ( path . relative ( getTop ( tree ) . path , requested . fetchSpec ) )
@@ -324,7 +333,7 @@ exports.removeDeps = function (args, tree, saveToDependencies, next) {
324333 for ( let pkg of args ) {
325334 var pkgName = moduleName ( pkg )
326335 var toRemove = tree . children . filter ( moduleNameMatches ( pkgName ) )
327- var pkgToRemove = toRemove [ 0 ] || createChild ( { package : { name : pkgName } } )
336+ var pkgToRemove = toRemove [ 0 ] || createChild ( { name : pkgName } )
328337 var saveType = getSaveType ( tree , pkg ) || 'dependencies'
329338 if ( tree . isTop && saveToDependencies ) {
330339 pkgToRemove . save = saveType
@@ -652,11 +661,13 @@ function resolveWithNewModule (pkg, tree, log, next) {
652661 addBundled ( pkg , ( bundleErr ) => {
653662 var parent = earliestInstallable ( tree , tree , pkg , log , null ) || tree
654663 var isLink = pkg . _requested . type === 'directory'
664+ var name = pkg . _requested . name || pkg . name
655665 var child = createChild ( {
666+ name,
656667 package : pkg ,
657668 parent : parent ,
658- path : path . join ( parent . isLink ? parent . realpath : parent . path , 'node_modules' , pkg . name ) ,
659- realpath : isLink ? pkg . _requested . fetchSpec : path . join ( parent . realpath , 'node_modules' , pkg . name ) ,
669+ path : path . join ( parent . isLink ? parent . realpath : parent . path , 'node_modules' , name ) ,
670+ realpath : isLink ? pkg . _requested . fetchSpec : path . join ( parent . realpath , 'node_modules' , name ) ,
660671 children : pkg . _bundled || [ ] ,
661672 isLink : isLink ,
662673 isInLink : parent . isLink ,
0 commit comments