@@ -2,7 +2,7 @@ import path from 'node:path'
22import MagicString from 'magic-string'
33import type { ImportSpecifier } from 'es-module-lexer'
44import { init , parse as parseImports } from 'es-module-lexer'
5- import type { OutputAsset , SourceMap } from 'rolldown'
5+ import type { SourceMap } from 'rolldown'
66import { viteBuildImportAnalysisPlugin as nativeBuildImportAnalysisPlugin } from 'rolldown/experimental'
77import type { RawSourceMap } from '@jridgewell/remapping'
88import convertSourceMap from 'convert-source-map'
@@ -13,7 +13,7 @@ import { toOutputFilePathInJS } from '../build'
1313import { genSourceMapUrl } from '../server/sourcemap'
1414import type { PartialEnvironment } from '../baseEnvironment'
1515import { removedPureCssFilesCache } from './css'
16- import { getImportMapFilename } from './html'
16+ import { getImportMap , getImportMapFilename } from './html'
1717
1818type FileDep = {
1919 url : string
@@ -351,20 +351,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin[] {
351351 let importMapMapping : Record < string , string > | undefined
352352 let importMapReverseMapping : Record < string , string > | undefined
353353 if ( config . build . chunkImportMap ) {
354- const decoder = new TextDecoder ( )
355- const importMap = bundle [ getImportMapFilename ( config ) ] ! as OutputAsset
356- const importMapContent : { imports : Record < string , string > } =
357- JSON . parse (
358- typeof importMap . source === 'string'
359- ? importMap . source
360- : decoder . decode ( importMap . source ) ,
361- )
362- importMapMapping = Object . fromEntries (
363- Object . entries ( importMapContent . imports ) . map ( ( [ k , v ] ) => [
364- k . slice ( config . base . length ) ,
365- v . slice ( config . base . length ) ,
366- ] ) ,
367- )
354+ const importMap = getImportMap ( bundle , config ) !
355+ importMapMapping = importMap . mapping
368356 importMapReverseMapping = Object . fromEntries (
369357 Object . entries ( importMapMapping ) . map ( ( [ k , v ] ) => [ v , k ] ) ,
370358 )
@@ -373,7 +361,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin[] {
373361 this . emitFile ( {
374362 type : 'asset' ,
375363 fileName : 'importmap.legacy.json' ,
376- source : importMap . source ,
364+ source : importMap . asset . source ,
377365 } )
378366 delete bundle [ getImportMapFilename ( config ) ]
379367 }
0 commit comments