diff --git a/packages/rollup/lib/index.js b/packages/rollup/lib/index.js index ddbf4a0eb..78a00c03e 100644 --- a/packages/rollup/lib/index.js +++ b/packages/rollup/lib/index.js @@ -32,8 +32,8 @@ * Callback called by Rollup and Vite to transform. * @param {string} value * File contents. - * @param {string} path - * File path. + * @param {string} id + * Module ID. * @returns {Promise} * Result. * @@ -80,7 +80,7 @@ export function rollup(options) { ...rest }) }, - async transform(value, path) { + async transform(value, id) { if (!formatAwareProcessors) { formatAwareProcessors = createFormatAwareProcessors({ SourceMapGenerator, @@ -88,6 +88,7 @@ export function rollup(options) { }) } + const [path] = id.split('?') const file = new VFile({path, value}) if ( diff --git a/packages/rollup/test/index.js b/packages/rollup/test/index.js index e8e308ced..4d826ca2d 100644 --- a/packages/rollup/test/index.js +++ b/packages/rollup/test/index.js @@ -101,4 +101,27 @@ test('@mdx-js/rollup', async function (t) { assert.doesNotMatch(code, /jsxs?\(/) assert.match(code, /jsxDEV\(/) }) + + await t.test('should handle query parameters in vite', async () => { + const result = /** @type {Array} */ ( + await build({ + build: { + lib: { + entry: + fileURLToPath(new URL('vite-entry.mdx', import.meta.url)) + + '?query=param', + name: 'query' + }, + write: false + }, + logLevel: 'silent', + plugins: [rollupMdx()] + }) + ) + + const code = result[0].output[0].code + + assert.match(code, /Hello Vite/) + assert.match(code, /jsxs?\(/) + }) })