66
77const identifierUtils = require ( "./util/identifier" ) ;
88
9- const portableIdCache = new WeakMap ( ) ;
10-
119class RecordIdsPlugin {
10+ constructor ( options ) {
11+ this . options = options || { } ;
12+ }
1213
1314 apply ( compiler ) {
15+ const portableIds = this . options . portableIds ;
1416 compiler . plugin ( "compilation" , compilation => {
1517 compilation . plugin ( "record-modules" , ( modules , records ) => {
1618 if ( ! records . modules ) records . modules = { } ;
1719 if ( ! records . modules . byIdentifier ) records . modules . byIdentifier = { } ;
1820 if ( ! records . modules . usedIds ) records . modules . usedIds = { } ;
1921 modules . forEach ( module => {
20- let identifier = portableIdCache . get ( module ) ;
21- if ( ! identifier ) portableIdCache . set ( module , identifier = identifierUtils . makePathsRelative ( compiler . context , module . identifier ( ) ) ) ;
22+ const identifier = portableIds ? identifierUtils . makePathsRelative ( compiler . context , module . identifier ( ) , compilation . cache ) : module . identifier ( ) ;
2223 records . modules . byIdentifier [ identifier ] = module . id ;
2324 records . modules . usedIds [ module . id ] = module . id ;
2425 } ) ;
@@ -29,8 +30,7 @@ class RecordIdsPlugin {
2930 const usedIds = { } ;
3031 modules . forEach ( module => {
3132 if ( module . id !== null ) return ;
32- let identifier = portableIdCache . get ( module ) ;
33- if ( ! identifier ) portableIdCache . set ( module , identifier = identifierUtils . makePathsRelative ( compiler . context , module . identifier ( ) ) ) ;
33+ const identifier = portableIds ? identifierUtils . makePathsRelative ( compiler . context , module . identifier ( ) , compilation . cache ) : module . identifier ( ) ;
3434 const id = records . modules . byIdentifier [ identifier ] ;
3535 if ( id === undefined ) return ;
3636 if ( usedIds [ id ] ) return ;
@@ -53,7 +53,8 @@ class RecordIdsPlugin {
5353 block = block . parent ;
5454 }
5555 if ( ! block . identifier ) return null ;
56- ident . push ( identifierUtils . makePathsRelative ( compiler . context , block . identifier ( ) ) ) ;
56+ const identifier = portableIds ? identifierUtils . makePathsRelative ( compiler . context , block . identifier ( ) , compilation . cache ) : block . identifier ( ) ;
57+ ident . push ( identifier ) ;
5758 return ident . reverse ( ) . join ( ":" ) ;
5859 } ;
5960
0 commit comments