32
32
* Callback called by Rollup and Vite to transform.
33
33
* @param {string } value
34
34
* File contents.
35
- * @param {string } path
36
- * File path .
35
+ * @param {string } id
36
+ * Module ID .
37
37
* @returns {Promise<SourceDescription | undefined> }
38
38
* Result.
39
39
*
53
53
*/
54
54
55
55
import { createFormatAwareProcessors } from '@mdx-js/mdx/internal-create-format-aware-processors'
56
- import { extnamesToRegex } from '@mdx-js/mdx/internal-extnames-to-regex'
57
56
import { createFilter } from '@rollup/pluginutils'
58
57
import { SourceMapGenerator } from 'source-map'
59
58
import { VFile } from 'vfile'
@@ -70,8 +69,6 @@ export function rollup(options) {
70
69
const { exclude, include, ...rest } = options || { }
71
70
/** @type {FormatAwareProcessors } */
72
71
let formatAwareProcessors
73
- /** @type {RegExp } */
74
- let extnameRegex
75
72
const filter = createFilter ( include , exclude )
76
73
77
74
return {
@@ -82,20 +79,23 @@ export function rollup(options) {
82
79
development : env . mode === 'development' ,
83
80
...rest
84
81
} )
85
- extnameRegex = extnamesToRegex ( formatAwareProcessors . extnames )
86
82
} ,
87
- async transform ( value , path ) {
83
+ async transform ( value , id ) {
88
84
if ( ! formatAwareProcessors ) {
89
85
formatAwareProcessors = createFormatAwareProcessors ( {
90
86
SourceMapGenerator,
91
87
...rest
92
88
} )
93
- extnameRegex = extnamesToRegex ( formatAwareProcessors . extnames )
94
89
}
95
90
91
+ const [ path ] = id . split ( '?' )
96
92
const file = new VFile ( { path, value} )
97
93
98
- if ( file . extname && filter ( file . path ) && extnameRegex . test ( file . path ) ) {
94
+ if (
95
+ file . extname &&
96
+ filter ( file . path ) &&
97
+ formatAwareProcessors . extnames . includes ( file . extname )
98
+ ) {
99
99
const compiled = await formatAwareProcessors . process ( file )
100
100
const code = String ( compiled . value )
101
101
/** @type {SourceDescription } */
0 commit comments