@@ -3145,6 +3145,60 @@ describe('html', function () {
3145
3145
assert . equal ( value , 7 ) ;
3146
3146
} ) ;
3147
3147
3148
+ it ( 'should generate an import map with relative public url' , async function ( ) {
3149
+ await fsFixture ( overlayFS , dir ) `
3150
+ index.html:
3151
+ <body>
3152
+ <script src="./main.js" type="module"></script>
3153
+ </body>
3154
+ main.js:
3155
+ globalThis.output = async () => (await import('./main-async')).bar();
3156
+ main-async.js:
3157
+ import './main-async.css';
3158
+ export const bar = async () => (await import('./nested-async')).bar + 3;
3159
+ main-async.css:
3160
+ .foo { color: red }
3161
+ nested-async.js:
3162
+ import './nested-async.css';
3163
+ export const bar = 4;
3164
+ nested-async.css:
3165
+ .bar { color: green }
3166
+ ` ;
3167
+
3168
+ let b = await bundle ( path . join ( dir , '/index.html' ) , {
3169
+ inputFS : overlayFS ,
3170
+ mode : 'production' ,
3171
+ defaultTargetOptions : {
3172
+ publicUrl : '.' ,
3173
+ } ,
3174
+ } ) ;
3175
+
3176
+ let html = await overlayFS . readFile ( b . getBundles ( ) [ 0 ] . filePath , 'utf8' ) ;
3177
+ let importMap = JSON . parse (
3178
+ html . match ( / < s c r i p t t y p e = " i m p o r t m a p " > ( .* ?) < \/ s c r i p t > / ) [ 1 ] ,
3179
+ ) ;
3180
+ assert . deepEqual ( importMap , {
3181
+ imports : {
3182
+ [ b . getBundles ( ) [ 2 ] . publicId ] :
3183
+ './' + path . basename ( b . getBundles ( ) [ 2 ] . filePath ) ,
3184
+ [ b . getBundles ( ) [ 3 ] . publicId ] :
3185
+ './' + path . basename ( b . getBundles ( ) [ 3 ] . filePath ) ,
3186
+ [ b . getBundles ( ) [ 4 ] . publicId ] :
3187
+ './' + path . basename ( b . getBundles ( ) [ 4 ] . filePath ) ,
3188
+ [ b . getBundles ( ) [ 5 ] . publicId ] :
3189
+ './' + path . basename ( b . getBundles ( ) [ 5 ] . filePath ) ,
3190
+ } ,
3191
+ } ) ;
3192
+
3193
+ assert (
3194
+ html . indexOf ( '<script type="importmap">' ) < html . indexOf ( '<script src' ) ,
3195
+ ) ;
3196
+
3197
+ let res = await run ( b , null , { require : false } ) ;
3198
+ let value = await res . output ( ) ;
3199
+ assert . equal ( value , 7 ) ;
3200
+ } ) ;
3201
+
3148
3202
it ( 'should merge with an existing import map' , async function ( ) {
3149
3203
await fsFixture ( overlayFS , dir ) `
3150
3204
index.html:
0 commit comments