44*/
55"use strict" ;
66
7- function makeRelative ( compiler , identifier ) {
8- const context = compiler . context ;
9- return identifier . split ( "|" ) . map ( str => str . split ( "!" ) . map ( str => path . relative ( context , str ) ) . join ( "!" ) ) . join ( "|" ) ;
10- }
11-
127const path = require ( "path" ) ;
138
149class RecordIdsPlugin {
10+
11+ static looksLikeAbsolutePath ( maybeAbsolutePath ) {
12+ return / ^ (?: [ a - z ] : \\ | \/ ) / i. test ( maybeAbsolutePath ) ;
13+ }
14+
15+ static makeRelative ( context , identifier ) {
16+ return identifier
17+ . split ( / ( [ | ! ] ) / )
18+ . map ( str => RecordIdsPlugin . looksLikeAbsolutePath ( str ) ? path . relative ( context , str ) : str )
19+ . join ( "" ) ;
20+ }
21+
1522 apply ( compiler ) {
1623 compiler . plugin ( "compilation" , compilation => {
1724 compilation . plugin ( "record-modules" , ( modules , records ) => {
1825 if ( ! records . modules ) records . modules = { } ;
1926 if ( ! records . modules . byIdentifier ) records . modules . byIdentifier = { } ;
2027 if ( ! records . modules . usedIds ) records . modules . usedIds = { } ;
2128 modules . forEach ( function ( module ) {
22- if ( ! module . portableId ) module . portableId = makeRelative ( compiler , module . identifier ( ) ) ;
29+ if ( ! module . portableId ) module . portableId = RecordIdsPlugin . makeRelative ( compiler . context , module . identifier ( ) ) ;
2330 const identifier = module . portableId ;
2431 records . modules . byIdentifier [ identifier ] = module . id ;
2532 records . modules . usedIds [ module . id ] = module . id ;
@@ -31,7 +38,7 @@ class RecordIdsPlugin {
3138 const usedIds = { } ;
3239 modules . forEach ( function ( module ) {
3340 if ( module . id !== null ) return ;
34- if ( ! module . portableId ) module . portableId = makeRelative ( compiler , module . identifier ( ) ) ;
41+ if ( ! module . portableId ) module . portableId = RecordIdsPlugin . makeRelative ( compiler . context , module . identifier ( ) ) ;
3542 const identifier = module . portableId ;
3643 const id = records . modules . byIdentifier [ identifier ] ;
3744 if ( id === undefined ) return ;
@@ -55,7 +62,7 @@ class RecordIdsPlugin {
5562 block = block . parent ;
5663 }
5764 if ( ! block . identifier ) return null ;
58- ident . unshift ( makeRelative ( compiler , block . identifier ( ) ) ) ;
65+ ident . unshift ( RecordIdsPlugin . makeRelative ( compiler . context , block . identifier ( ) ) ) ;
5966 return ident . join ( ":" ) ;
6067 }
6168 compilation . plugin ( "record-chunks" , ( chunks , records ) => {
0 commit comments