File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,6 +7,12 @@ const targets = [
77 / ^ j s o n c - p a r s e r $ / ,
88]
99
10+ const UMD_SEGMENT_PATTERN = / [ / \\ ] u m d [ / \\ ] /
11+
12+ export function toEsmPath ( resolvedModulePath : string ) {
13+ return resolvedModulePath . replace ( UMD_SEGMENT_PATTERN , ( matchedSegment ) => matchedSegment . replace ( 'umd' , 'esm' ) )
14+ }
15+
1016export function umdToEsm ( ) : Rolldown . RolldownPlugin {
1117 return {
1218 name : 'umd-to-esm' ,
@@ -15,10 +21,10 @@ export function umdToEsm(): Rolldown.RolldownPlugin {
1521 id : targets ,
1622 } ,
1723 handler ( source , importer ) {
18- const require = createRequire ( importer ! )
19- const pathUmdMay = require . resolve ( source )
20- const pathEsm = pathUmdMay . replace ( '/umd/' , '/esm/' )
21- return { id : pathEsm }
24+ const require = createRequire ( importer ?? import . meta . url )
25+ const resolvedModulePath = require . resolve ( source )
26+ const resolvedEsmPath = toEsmPath ( resolvedModulePath )
27+ return { id : resolvedEsmPath }
2228 } ,
2329 } ,
2430 }
You can’t perform that action at this time.
0 commit comments