@ossido-labs/ossido-mdx 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/vite.js +4 -1
- package/dist/esm/vite.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/vite.js
CHANGED
|
@@ -62,7 +62,10 @@ function ossidoMdx(options = {}) {
|
|
|
62
62
|
load(id) {
|
|
63
63
|
if (id !== RESOLVED_VIRTUAL_ID) return void 0;
|
|
64
64
|
const file = findComponentsFile(viteRoot);
|
|
65
|
-
if (file)
|
|
65
|
+
if (file) {
|
|
66
|
+
const specifier = file.replaceAll("\\", "/");
|
|
67
|
+
return `export { useMDXComponents } from ${JSON.stringify(specifier)}`;
|
|
68
|
+
}
|
|
66
69
|
return `export function useMDXComponents(components) {\n return components ?? {}\n}`;
|
|
67
70
|
}
|
|
68
71
|
}, {
|
package/dist/esm/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../../src/vite.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport mdx from '@mdx-js/rollup';\nimport type { Plugin } from 'vite';\n\n/**\n * The module the MDX compiler imports `useMDXComponents` from (via\n * `providerImportSource`). It is virtual: the `ossido-mdx:components` plugin\n * resolves it to the project's `src/mdx-components` file, or a passthrough\n * default when that file doesn't exist yet.\n */\nconst VIRTUAL_ID = 'virtual:ossido-mdx/components';\nconst RESOLVED_VIRTUAL_ID = '\\0' + VIRTUAL_ID;\n\nconst COMPONENTS_BASENAME = 'mdx-components';\nconst EXTENSIONS = ['tsx', 'jsx', 'ts', 'js'] as const;\n\n/**\n * Locate the project's `src/mdx-components.{tsx,jsx,ts,js}`.\n *\n * ossido runs vite with `root: '.ossido'`, so the project lives one directory\n * up; we look there first (the real location) and fall back to the vite root so\n * this also works for a non-ossido vite project.\n */\nfunction findComponentsFile(viteRoot: string): string | undefined {\n const projectRoots = [path.dirname(viteRoot), viteRoot];\n for (const base of projectRoots) {\n for (const ext of EXTENSIONS) {\n const candidate = path.join(base, 'src', `${COMPONENTS_BASENAME}.${ext}`);\n if (fs.existsSync(candidate)) return candidate;\n }\n }\n return undefined;\n}\n\nexport interface OssidoMdxOptions {\n /**\n * Extra options forwarded to `@mdx-js/rollup` (remark/rehype plugins, etc.).\n * `providerImportSource` is managed by this plugin and can't be overridden.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n mdxOptions?: Record<string, any>;\n}\n\n/**\n * MDX support for ossido with a Next.js-style global components convention.\n *\n * Add it to your ossido config's `vite.plugins`:\n *\n * ```ts\n * // ossido.config.ts\n * import { ossidoMdx } from '@ossido-labs/ossido-mdx/vite'\n *\n * export default { vite: { plugins: [ossidoMdx()] } }\n * ```\n *\n * Then style Markdown globally by exporting `useMDXComponents` from\n * `src/mdx-components.tsx` — every `.mdx` file picks it up, no `<MDXProvider>`\n * needed. Until that file exists, MDX renders with plain HTML elements.\n */\nexport function ossidoMdx(options: OssidoMdxOptions = {}): Array<Plugin> {\n let viteRoot = process.cwd();\n\n const componentsPlugin: Plugin = {\n name: 'ossido-mdx:components',\n enforce: 'pre',\n configResolved(config): void {\n viteRoot = config.root;\n },\n resolveId(id): string | undefined {\n if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID;\n return undefined;\n },\n load(id): string | undefined {\n if (id !== RESOLVED_VIRTUAL_ID) return undefined;\n\n const file = findComponentsFile(viteRoot);\n if (file) {\n // Re-export the user's hook; the dependency on `file` also gives HMR.\n return `export { useMDXComponents } from ${JSON.stringify(
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../../src/vite.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport mdx from '@mdx-js/rollup';\nimport type { Plugin } from 'vite';\n\n/**\n * The module the MDX compiler imports `useMDXComponents` from (via\n * `providerImportSource`). It is virtual: the `ossido-mdx:components` plugin\n * resolves it to the project's `src/mdx-components` file, or a passthrough\n * default when that file doesn't exist yet.\n */\nconst VIRTUAL_ID = 'virtual:ossido-mdx/components';\nconst RESOLVED_VIRTUAL_ID = '\\0' + VIRTUAL_ID;\n\nconst COMPONENTS_BASENAME = 'mdx-components';\nconst EXTENSIONS = ['tsx', 'jsx', 'ts', 'js'] as const;\n\n/**\n * Locate the project's `src/mdx-components.{tsx,jsx,ts,js}`.\n *\n * ossido runs vite with `root: '.ossido'`, so the project lives one directory\n * up; we look there first (the real location) and fall back to the vite root so\n * this also works for a non-ossido vite project.\n */\nfunction findComponentsFile(viteRoot: string): string | undefined {\n const projectRoots = [path.dirname(viteRoot), viteRoot];\n for (const base of projectRoots) {\n for (const ext of EXTENSIONS) {\n const candidate = path.join(base, 'src', `${COMPONENTS_BASENAME}.${ext}`);\n if (fs.existsSync(candidate)) return candidate;\n }\n }\n return undefined;\n}\n\nexport interface OssidoMdxOptions {\n /**\n * Extra options forwarded to `@mdx-js/rollup` (remark/rehype plugins, etc.).\n * `providerImportSource` is managed by this plugin and can't be overridden.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n mdxOptions?: Record<string, any>;\n}\n\n/**\n * MDX support for ossido with a Next.js-style global components convention.\n *\n * Add it to your ossido config's `vite.plugins`:\n *\n * ```ts\n * // ossido.config.ts\n * import { ossidoMdx } from '@ossido-labs/ossido-mdx/vite'\n *\n * export default { vite: { plugins: [ossidoMdx()] } }\n * ```\n *\n * Then style Markdown globally by exporting `useMDXComponents` from\n * `src/mdx-components.tsx` — every `.mdx` file picks it up, no `<MDXProvider>`\n * needed. Until that file exists, MDX renders with plain HTML elements.\n */\nexport function ossidoMdx(options: OssidoMdxOptions = {}): Array<Plugin> {\n let viteRoot = process.cwd();\n\n const componentsPlugin: Plugin = {\n name: 'ossido-mdx:components',\n enforce: 'pre',\n configResolved(config): void {\n viteRoot = config.root;\n },\n resolveId(id): string | undefined {\n if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID;\n return undefined;\n },\n load(id): string | undefined {\n if (id !== RESOLVED_VIRTUAL_ID) return undefined;\n\n const file = findComponentsFile(viteRoot);\n if (file) {\n // Emit a POSIX-style specifier: module import paths use forward slashes\n // on every platform. Windows backslashes are invalid escapes in a JS\n // string and are not valid Vite/Rollup module ids.\n const specifier = file.replaceAll('\\\\', '/');\n // Re-export the user's hook; the dependency on `file` also gives HMR.\n return `export { useMDXComponents } from ${JSON.stringify(specifier)}`;\n }\n // Passthrough default: MDX works before a mdx-components file is created.\n return `export function useMDXComponents(components) {\\n return components ?? {}\\n}`;\n },\n };\n\n const mdxPlugin: Plugin = {\n enforce: 'pre',\n ...(mdx({\n ...options.mdxOptions,\n providerImportSource: VIRTUAL_ID,\n }) as Plugin),\n };\n\n return [componentsPlugin, mdxPlugin];\n}\n"],"mappings":";;;;;;;;;;;AAYA,MAAM,aAAa;AACnB,MAAM,sBAAsB;AAE5B,MAAM,sBAAsB;AAC5B,MAAM,aAAa;CAAC;CAAO;CAAO;CAAM;AAAI;;;;;;;;AAS5C,SAAS,mBAAmB,UAAsC;CAChE,MAAM,eAAe,CAAC,KAAK,QAAQ,QAAQ,GAAG,QAAQ;CACtD,KAAK,MAAM,QAAQ,cACjB,KAAK,MAAM,OAAO,YAAY;EAC5B,MAAM,YAAY,KAAK,KAAK,MAAM,OAAO,GAAG,oBAAoB,GAAG,KAAK;EACxE,IAAI,GAAG,WAAW,SAAS,GAAG,OAAO;CACvC;AAGJ;;;;;;;;;;;;;;;;;AA2BA,SAAgB,UAAU,UAA4B,CAAC,GAAkB;CACvE,IAAI,WAAW,QAAQ,IAAI;CAqC3B,OAAO,CAAC;EAlCN,MAAM;EACN,SAAS;EACT,eAAe,QAAc;GAC3B,WAAW,OAAO;EACpB;EACA,UAAU,IAAwB;GAChC,IAAI,OAAO,YAAY,OAAO;EAEhC;EACA,KAAK,IAAwB;GAC3B,IAAI,OAAO,qBAAqB,OAAO;GAEvC,MAAM,OAAO,mBAAmB,QAAQ;GACxC,IAAI,MAAM;IAIR,MAAM,YAAY,KAAK,WAAW,MAAM,GAAG;IAE3C,OAAO,oCAAoC,KAAK,UAAU,SAAS;GACrE;GAEA,OAAO;EACT;CAWqB,GAAG;EAPxB,SAAS;EACT,GAAI,IAAI;GACN,GAAG,QAAQ;GACX,sBAAsB;EACxB,CAAC;CAG+B,CAAC;AACrC"}
|