diff --git a/packages/rollup-plugin-import-meta-assets/test/integration.test.js b/packages/rollup-plugin-import-meta-assets/test/integration.test.js index d5eedc4c8..66a6df9ef 100644 --- a/packages/rollup-plugin-import-meta-assets/test/integration.test.js +++ b/packages/rollup-plugin-import-meta-assets/test/integration.test.js @@ -294,6 +294,43 @@ describe('rollup-plugin-import-meta-assets', () => { expectAsset(output, 'snapshots/two.svg', 'two.svg', 'assets/two--yckvrYd.svg'), expectAsset(output, 'snapshots/three.svg', 'three.svg', 'assets/three-CDdgprDC.svg'), expectAsset(output, 'snapshots/four.svg', 'four.svg', 'assets/four-lJVunLww.svg'), + + it('respects the rollup resolution', async () => { + const config = { + input: { 'simple-bundle-switched': require.resolve('./fixtures/simple-entrypoint.js') }, + plugins: [ + importMetaAssets(), + { + resolveId(source, importer) { + if (source == './one.svg') { + return path.resolve(path.dirname(importer), 'two.svg'); + } + if (source == './two.svg') { + return path.resolve(path.dirname(importer), 'one.svg'); + } + if (source === './three.svg') { + return { + id: source, + external: true, + }; + } + return undefined; + }, + }, + ], + }; + + const bundle = await rollup.rollup(config); + const { output } = await bundle.generate(outputConfig); + + expect(output.length).to.equal(5); + expectChunk(output, 'snapshots/simple-bundle-switched.js', 'simple-bundle-switched.js', [ + expectAsset(output, 'snapshots/two.svg', 'two.svg', 'assets/two--yckvrYd.svg'), + expectAsset(output, 'snapshots/one.svg', 'one.svg', 'assets/one-ZInu4dBJ.svg'), + expectAsset(output, 'snapshots/four.svg', 'four.svg', 'assets/four-lJVunLww.svg'), + expectAsset(output, 'snapshots/five', 'five', 'assets/five-Z74_0e9C'), + ]); + }), ]); }); }); diff --git a/packages/rollup-plugin-import-meta-assets/test/snapshots/simple-bundle-switched.js b/packages/rollup-plugin-import-meta-assets/test/snapshots/simple-bundle-switched.js new file mode 100644 index 000000000..dc2a623e9 --- /dev/null +++ b/packages/rollup-plugin-import-meta-assets/test/snapshots/simple-bundle-switched.js @@ -0,0 +1,13 @@ +const justUrlObject = new URL(new URL('assets/two--yckvrYd.svg', import.meta.url).href, import.meta.url); +const href = new URL(new URL('assets/one-ZInu4dBJ.svg', import.meta.url).href, import.meta.url).href; +const pathname = new URL('./three.svg', import.meta.url).pathname; +const searchParams = new URL(new URL('assets/four-lJVunLww.svg', import.meta.url).href, import.meta.url).searchParams; +const noExtension = new URL(new URL('assets/five-Z74_0e9C', import.meta.url).href, import.meta.url); + +console.log({ + justUrlObject, + href, + pathname, + searchParams, + noExtension, +});