@@ -101,7 +101,7 @@ function shrinkwrapDeps (deps, top, tree, seen) {
101101 if ( ! seen ) seen = new Set ( )
102102 if ( seen . has ( tree ) ) return
103103 seen . add ( tree )
104- tree . children . sort ( function ( aa , bb ) { return moduleName ( aa ) . localeCompare ( moduleName ( bb ) ) } ) . forEach ( function ( child ) {
104+ sortModules ( tree . children ) . forEach ( function ( child ) {
105105 if ( child . fakeChild ) {
106106 deps [ moduleName ( child ) ] = child . fakeChild
107107 return
@@ -130,7 +130,7 @@ function shrinkwrapDeps (deps, top, tree, seen) {
130130 if ( isOnlyOptional ( child ) ) pkginfo . optional = true
131131 if ( child . requires . length ) {
132132 pkginfo . requires = { }
133- child . requires . sort ( ( a , b ) => moduleName ( a ) . localeCompare ( moduleName ( b ) ) ) . forEach ( ( required ) => {
133+ sortModules ( child . requires ) . forEach ( ( required ) => {
134134 var requested = required . package . _requested || getRequested ( required ) || { }
135135 pkginfo . requires [ moduleName ( required ) ] = childVersion ( top , required , requested )
136136 } )
@@ -142,6 +142,14 @@ function shrinkwrapDeps (deps, top, tree, seen) {
142142 } )
143143}
144144
145+ function sortModules ( modules ) {
146+ // sort modules with the locale-agnostic Unicode sort
147+ var sortedModuleNames = modules . map ( moduleName ) . sort ( )
148+ return modules . sort ( ( a , b ) => (
149+ sortedModuleNames . indexOf ( moduleName ( a ) ) - sortedModuleNames . indexOf ( moduleName ( b ) )
150+ ) )
151+ }
152+
145153function childVersion ( top , child , req ) {
146154 if ( req . type === 'directory' || req . type === 'file' ) {
147155 return 'file:' + unixFormatPath ( path . relative ( top . path , child . package . _resolved || req . fetchSpec ) )
0 commit comments