Skip to content

Commit

Permalink
Merge pull request #130 from nksaraf/directives-fix
Browse files Browse the repository at this point in the history
Add onModuleFound callback to shimExportsPlugin
  • Loading branch information
nksaraf authored Jan 15, 2024
2 parents 738640c + fae6e44 commit 6de7b6c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/thin-windows-glow.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion packages/vinxi-directives/plugins/shim-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export function shimExportsPlugin({
],
),
);
onModuleFound?.(id);
this.traverse(path);
}
return false;
Expand All @@ -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,
};
}
Expand Down
5 changes: 4 additions & 1 deletion packages/vinxi-directives/transform.test.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 6de7b6c

Please sign in to comment.