diff --git a/.changeset/thin-windows-glow.md b/.changeset/thin-windows-glow.md new file mode 100644 index 00000000..4a6dc2ed --- /dev/null +++ b/.changeset/thin-windows-glow.md @@ -0,0 +1,6 @@ +--- +"@vinxi/plugin-directives": patch +"vinxi": patch +--- + +fix: @vinxi/plugin-directives: Add onModuleFound callback to shimExportsPlugin, fixes #129, solidjs/solid-start#1261 diff --git a/packages/vinxi-directives/plugins/shim-exports.js b/packages/vinxi-directives/plugins/shim-exports.js index 4943de08..efe4aa52 100644 --- a/packages/vinxi-directives/plugins/shim-exports.js +++ b/packages/vinxi-directives/plugins/shim-exports.js @@ -297,6 +297,7 @@ export function shimExportsPlugin({ ], ), ); + onModuleFound?.(id); this.traverse(path); } return false; @@ -312,7 +313,9 @@ export function shimExportsPlugin({ }); return { - code: `import { ${runtime.function} } from '${runtime.module}';\n` + result.code, + code: + `import { ${runtime.function} } from '${runtime.module}';\n` + + result.code, map: result.map, }; } diff --git a/packages/vinxi-directives/transform.test.js b/packages/vinxi-directives/transform.test.js index 459b836e..4e17c514 100644 --- a/packages/vinxi-directives/transform.test.js +++ b/packages/vinxi-directives/transform.test.js @@ -1,5 +1,5 @@ import { prettyPrint } from "recast"; -import { describe, expect, it } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { parseAdvanced } from "./parse.js"; import { @@ -36,12 +36,15 @@ async function transformSSR( pragma: "use runtime", }, ) { + const onModuleFound = vi.fn(); const instance = plugin({ ...args, + onModuleFound, }); let result = await instance.transform(code, args.id, args.options); const data = js(result); + expect(onModuleFound.mock.calls.length).toBeGreaterThan(0); return data; } async function transformClient(