File tree Expand file tree Collapse file tree 4 files changed +43
-3
lines changed
test/cli/samples/get-chunk-name Expand file tree Collapse file tree 4 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -1069,9 +1069,15 @@ export default class Chunk {
1069
1069
? sanitizedId . slice ( 0 , - extensionName . length )
1070
1070
: sanitizedId ;
1071
1071
if ( isAbsolute ( idWithoutExtension ) ) {
1072
- return preserveModulesRoot && resolve ( idWithoutExtension ) . startsWith ( preserveModulesRoot )
1073
- ? idWithoutExtension . slice ( preserveModulesRoot . length ) . replace ( / ^ [ / \\ ] / , '' )
1074
- : relative ( this . inputBase , idWithoutExtension ) ;
1072
+ if ( preserveModulesRoot && resolve ( idWithoutExtension ) . startsWith ( preserveModulesRoot ) ) {
1073
+ return idWithoutExtension . slice ( preserveModulesRoot . length ) . replace ( / ^ [ / \\ ] / , '' ) ;
1074
+ } else {
1075
+ // handle edge case in Windows
1076
+ if ( this . inputBase === '/' && ! idWithoutExtension . startsWith ( '/' ) ) {
1077
+ return relative ( this . inputBase , idWithoutExtension . replace ( / ^ [ a - z A - Z ] : [ / \\ ] / , '/' ) ) ;
1078
+ }
1079
+ return relative ( this . inputBase , idWithoutExtension ) ;
1080
+ }
1075
1081
} else {
1076
1082
return (
1077
1083
this . outputOptions . virtualDirname . replace ( / \/ $ / , '' ) + '/' + basename ( idWithoutExtension )
Original file line number Diff line number Diff line change
1
+ const assert = require ( 'node:assert' ) ;
2
+ module . exports = defineTest ( {
3
+ description : 'get right chunk name for preserve modules' ,
4
+ command : 'rollup -c' ,
5
+ result ( code ) {
6
+ assert . ok (
7
+ code . includes ( `//→ ${ __dirname . replace ( / ^ ( \/ | [ a - z A - Z ] : \\ ) / , '' ) . replace ( / \\ / g, '/' ) } /main.js` )
8
+ ) ;
9
+ assert . ok ( code . includes ( `//→ sub.js` ) ) ;
10
+ }
11
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import sub from '/sub.js' ;
2
+ assert . ok ( sub ) ;
Original file line number Diff line number Diff line change
1
+ export default {
2
+ input : 'main.js' ,
3
+ output : {
4
+ format : 'es' ,
5
+ preserveModules : true
6
+ } ,
7
+ plugins : [
8
+ {
9
+ resolveId ( id ) {
10
+ if ( id . endsWith ( 'sub.js' ) ) {
11
+ return id ;
12
+ }
13
+ } ,
14
+ load ( id ) {
15
+ if ( id . endsWith ( 'sub.js' ) ) {
16
+ return 'export default "sub.js url"' ;
17
+ }
18
+ }
19
+ }
20
+ ]
21
+ } ;
You can’t perform that action at this time.
0 commit comments