Skip to content

Commit

Permalink
Merge pull request #134 from jer3m01/fix/rehype
Browse files Browse the repository at this point in the history
fix(vinxi-mdx): provide file path to rehype transform
  • Loading branch information
nksaraf authored Jan 26, 2024
2 parents 7b326ea + 35cd983 commit 4edb432
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilly-papayas-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@vinxi/plugin-mdx": patch
"vinxi": patch
---

fix(vinxi-mdx): provide file path to rehype transform
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"scripts": {
"dev": "pnpm -r --parallel --filter \"./packages/*\" run dev",
"build": "pnpm -r --filter \"./packages/*\" run build",
"types": "pnpm -r --filter \"./packages/*\" run types",
"clean:test": "rimraf ../.fixtures",
"clean": "rm -rf **/*/.{nitro,output}",
"test": "pnpm --filter vinxi-tests clean && pnpm --filter vinxi-tests test -- && pnpm run test:directives",
"test:directives": "pnpm --filter @vinxi/plugin-directives test --",
"ci": "pnpm -r --stream run ci",
"release": "pnpm run build && pnpm --filter vinxi run types && changeset publish",
"release": "pnpm run build && pnpm run types && changeset publish",
"test:packages": "pnpm -r --stream run test",
"test:prettier": "prettier --check --ignore-path .gitignore --ignore-unknown . '!pnpm-lock.yaml'",
"format": "prettier --ignore-path .gitignore --ignore-unknown . '!pnpm-lock.yaml' --write",
Expand Down
3 changes: 2 additions & 1 deletion packages/vinxi-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"@alloc/quick-lru": "^5.2.0",
"esbuild": "0.18.7",
"resolve": "^1.22.4",
"unified": "^9.2.2"
"unified": "^9.2.2",
"vfile": "^5.0.0"
},
"devDependencies": {
"@mdx-js/mdx": "2.3.0",
Expand Down
9 changes: 5 additions & 4 deletions packages/vinxi-mdx/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NamedImports } from "./imports";
import { createTransformer } from "./transform";
import { MdxOptions, MdxPlugin } from "./types";
import { viteMdxTransclusion } from "./viteMdxTransclusion";
import { VFile, VFileCompatible } from "vfile";

export { MdxOptions, MdxPlugin };

Expand Down Expand Up @@ -37,7 +38,7 @@ function createPlugin(
let reactRefresh: Plugin | undefined;
let transformMdx:
| ((
code_mdx: string,
code_mdx: VFileCompatible,
mdxOptions?: MdxOptions | undefined,
) => Promise<string>)
| undefined;
Expand Down Expand Up @@ -74,10 +75,10 @@ function createPlugin(
globalMdxOptions,
getMdxOptions?.(path),
);
// @ts-ignore
// mdxOptions.filepath = path;

code = await transformMdx(code, { ...mdxOptions });
const input = new VFile({ value: code, path })

code = await transformMdx(input, { ...mdxOptions });
// @ts-ignore
const refreshResult = await reactRefresh?.transform!.call(
this,
Expand Down
6 changes: 3 additions & 3 deletions packages/vinxi-mdx/src/transform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { transform } from "esbuild";

import { assertImportExists, inferNamedImports, requireMdx } from "./imports";
import { VFileCompatible } from "vfile";
import { assertImportExists, inferNamedImports } from "./imports";
import { MdxOptions } from "./types";

export function createTransformer(
Expand All @@ -16,7 +16,7 @@ export function createTransformer(
},
);

return async function transform(code_mdx: string, mdxOptions?: MdxOptions) {
return async function transform(code_mdx: VFileCompatible, mdxOptions?: MdxOptions) {
const mdx = await import("@mdx-js/mdx");
let code_jsx = await mdx.compile(code_mdx, mdxOptions as any);
let code = !mdxOptions.jsx
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4edb432

Please sign in to comment.