Skip to content

Commit 2b3381a

Browse files
rollup: fix support for query parameters in Vite
Closes GH-2629. Reviewed-by: Remco Haszing <[email protected]> Reviewed-by: Titus Wormer <[email protected]>
1 parent def2cba commit 2b3381a

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

packages/rollup/lib/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
* Callback called by Rollup and Vite to transform.
3333
* @param {string} value
3434
* File contents.
35-
* @param {string} path
36-
* File path.
35+
* @param {string} id
36+
* Module ID.
3737
* @returns {Promise<SourceDescription | undefined>}
3838
* Result.
3939
*
@@ -80,14 +80,15 @@ export function rollup(options) {
8080
...rest
8181
})
8282
},
83-
async transform(value, path) {
83+
async transform(value, id) {
8484
if (!formatAwareProcessors) {
8585
formatAwareProcessors = createFormatAwareProcessors({
8686
SourceMapGenerator,
8787
...rest
8888
})
8989
}
9090

91+
const [path] = id.split('?')
9192
const file = new VFile({path, value})
9293

9394
if (

packages/rollup/test/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,27 @@ test('@mdx-js/rollup', async function (t) {
101101
assert.doesNotMatch(code, /jsxs?\(/)
102102
assert.match(code, /jsxDEV\(/)
103103
})
104+
105+
await t.test('should handle query parameters in vite', async () => {
106+
const result = /** @type {Array<RollupOutput>} */ (
107+
await build({
108+
build: {
109+
lib: {
110+
entry:
111+
fileURLToPath(new URL('vite-entry.mdx', import.meta.url)) +
112+
'?query=param',
113+
name: 'query'
114+
},
115+
write: false
116+
},
117+
logLevel: 'silent',
118+
plugins: [rollupMdx()]
119+
})
120+
)
121+
122+
const code = result[0].output[0].code
123+
124+
assert.match(code, /Hello Vite/)
125+
assert.match(code, /jsxs?\(/)
126+
})
104127
})

0 commit comments

Comments
 (0)