dommief 0.1.2 → 0.1.3

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/cli.js CHANGED
@@ -1013,6 +1013,7 @@ import { cac } from "cac";
1013
1013
  import { createServer } from "vite";
1014
1014
 
1015
1015
  // src/vite/plugin.ts
1016
+ import { transformWithOxc } from "vite";
1016
1017
  import fs10 from "fs";
1017
1018
  import path10 from "path";
1018
1019
 
@@ -2180,10 +2181,16 @@ function dommiefPlugin(opts) {
2180
2181
  if (!loaded) throw new Error("dommief: config ch\u01B0a \u0111\u01B0\u1EE3c n\u1EA1p");
2181
2182
  return loaded;
2182
2183
  });
2184
+ let isServe = false;
2185
+ const jsx2 = async (code, name) => {
2186
+ const r = await transformWithOxc(code, name + ".jsx", { lang: "jsx", jsx: { runtime: "automatic", development: isServe } });
2187
+ return { code: r.code, map: r.map ?? null, moduleType: "js" };
2188
+ };
2183
2189
  const markdownPlugin = {
2184
2190
  name: "dommief:markdown",
2185
2191
  enforce: "pre",
2186
- async config() {
2192
+ async config(_, env) {
2193
+ isServe = env.command === "serve";
2187
2194
  if (!loaded) {
2188
2195
  const config = await loadConfig(opts.root);
2189
2196
  loaded = { config, host: createPluginHost(config.plugins ?? []) };
@@ -2193,7 +2200,10 @@ function dommiefPlugin(opts) {
2193
2200
  return {
2194
2201
  base: loaded.config.base,
2195
2202
  resolve: { dedupe: ["react", "react-dom", "react-router"], alias: aliases },
2196
- ssr: { noExternal: ["dommief"] }
2203
+ ssr: { noExternal: ["dommief"] },
2204
+ // Client dommief nằm trong node_modules nên Vite không quét dep → React CJS bị serve thô
2205
+ // ("does not provide an export named 'jsxDEV'").
2206
+ optimizeDeps: { include: ["react", "react-dom", "react-dom/client", "react/jsx-runtime", "react/jsx-dev-runtime", "react-router"] }
2197
2207
  };
2198
2208
  },
2199
2209
  resolveId(id, importer) {
@@ -2218,7 +2228,7 @@ function dommiefPlugin(opts) {
2218
2228
  if (id.startsWith("\0virtual:dommief-demo/")) {
2219
2229
  const demoId2 = id.slice("\0virtual:dommief-demo/".length);
2220
2230
  const source = demoRegistry.get(demoId2) ?? "export default function Demo(){ return null; }";
2221
- return { code: source, map: null, moduleType: "jsx" };
2231
+ return jsx2(source, "demo-" + demoId2);
2222
2232
  }
2223
2233
  if (id === "\0virtual:dommief/entry") {
2224
2234
  return { code: `import ${JSON.stringify(resolveClientFile("entry-client.tsx"))};`, map: null, moduleType: "js" };
@@ -2270,7 +2280,7 @@ function dommiefPlugin(opts) {
2270
2280
  if (isMeta) {
2271
2281
  return { code: `export default ${JSON.stringify({ frontmatter: meta.frontmatter, toc: meta.toc })};`, map: null, moduleType: "js" };
2272
2282
  }
2273
- return { code: out, map: null, moduleType: "jsx" };
2283
+ return jsx2(out, file);
2274
2284
  }
2275
2285
  return null;
2276
2286
  },
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"dommief","version":"0.1.2","type":"module","main":"dist/index.js","types":"dist/index.d.ts","bin":{"dommief":"dist/cli.js"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./theme-api":{"types":"./dist/theme-api.d.ts","default":"./dist/theme-api.js"},"./client":{"types":"./src/client/index.tsx","default":"./src/client/index.tsx"}},"files":["dist","src"],"scripts":{"build":"tsup","dev":"tsup --watch"},"dependencies":{"cac":"^7.1.0","chokidar":"^6.0.0","estree-util-to-js":"^2.0.0","github-slugger":"^2.0.0","hast-util-to-estree":"^3.1.3","minisearch":"^7.2.0","picocolors":"^1.1.1","react-docgen-typescript":"^2.4.0","rehype-raw":"^7.0.0","remark-directive":"^4.0.0","remark-frontmatter":"^5.0.0","remark-gfm":"^4.0.1","remark-parse":"^11.0.0","remark-rehype":"^11.1.2","shiki":"^4.5.0","unified":"^11.0.5","unist-util-visit":"^5.0.0","yaml":"^2.9.1","zod":"^4.6.7"},"peerDependencies":{"react":"^19.0.0","react-dom":"^19.0.0","react-router":"^8.0.0","typescript":"^5.0.0","vite":"^8.0.0"},"devDependencies":{"react":"^19.3.1","react-dom":"^19.3.1","react-router":"^8.5.0","tsup":"^9.0.0","typescript":"^5.9.3","vite":"^8.3.5"}}
1
+ {"name":"dommief","version":"0.1.3","type":"module","main":"dist/index.js","types":"dist/index.d.ts","bin":{"dommief":"dist/cli.js"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./theme-api":{"types":"./dist/theme-api.d.ts","default":"./dist/theme-api.js"},"./client":{"types":"./src/client/index.tsx","default":"./src/client/index.tsx"}},"files":["dist","src"],"scripts":{"build":"tsup","dev":"tsup --watch"},"dependencies":{"cac":"^7.1.0","chokidar":"^6.0.0","estree-util-to-js":"^2.0.0","github-slugger":"^2.0.0","hast-util-to-estree":"^3.1.3","minisearch":"^7.2.0","picocolors":"^1.1.1","react-docgen-typescript":"^2.4.0","rehype-raw":"^7.0.0","remark-directive":"^4.0.0","remark-frontmatter":"^5.0.0","remark-gfm":"^4.0.1","remark-parse":"^11.0.0","remark-rehype":"^11.1.2","shiki":"^4.5.0","unified":"^11.0.5","unist-util-visit":"^5.0.0","yaml":"^2.9.1","zod":"^4.6.7"},"peerDependencies":{"react":"^19.0.0","react-dom":"^19.0.0","react-router":"^8.0.0","typescript":"^5.0.0","vite":"^8.0.0"},"devDependencies":{"react":"^19.3.1","react-dom":"^19.3.1","react-router":"^8.5.0","tsup":"^9.0.0","typescript":"^5.9.3","vite":"^8.3.5"}}
@@ -1,4 +1,4 @@
1
- import type { Plugin } from 'vite';
1
+ import { transformWithOxc, type Plugin } from 'vite';
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { loadConfig, type ResolvedConfig } from '../config.js';
@@ -50,10 +50,18 @@ export function dommiefPlugin(opts: DommiefPluginOptions) {
50
50
  return loaded;
51
51
  });
52
52
 
53
+ let isServe = false;
54
+ // Vite 8 dev bỏ qua `moduleType: 'jsx'` từ load → JSX thô tới import-analysis. Tự biên dịch.
55
+ const jsx = async (code: string, name: string) => {
56
+ const r = await transformWithOxc(code, name + '.jsx', { lang: 'jsx', jsx: { runtime: 'automatic', development: isServe } });
57
+ return { code: r.code, map: r.map ?? null, moduleType: 'js' as const };
58
+ };
59
+
53
60
  const markdownPlugin: Plugin = {
54
61
  name: 'dommief:markdown',
55
62
  enforce: 'pre',
56
- async config() {
63
+ async config(_, env) {
64
+ isServe = env.command === 'serve';
57
65
  if (!loaded) {
58
66
  const config = await loadConfig(opts.root);
59
67
  loaded = { config, host: createPluginHost(config.plugins ?? []) };
@@ -68,6 +76,9 @@ export function dommiefPlugin(opts: DommiefPluginOptions) {
68
76
  base: loaded.config.base,
69
77
  resolve: { dedupe: ['react', 'react-dom', 'react-router'], alias: aliases },
70
78
  ssr: { noExternal: ['dommief'] },
79
+ // Client dommief nằm trong node_modules nên Vite không quét dep → React CJS bị serve thô
80
+ // ("does not provide an export named 'jsxDEV'").
81
+ optimizeDeps: { include: ['react', 'react-dom', 'react-dom/client', 'react/jsx-runtime', 'react/jsx-dev-runtime', 'react-router'] },
71
82
  };
72
83
  },
73
84
  resolveId(id, importer) {
@@ -94,7 +105,7 @@ export function dommiefPlugin(opts: DommiefPluginOptions) {
94
105
  if (id.startsWith('\0virtual:dommief-demo/')) {
95
106
  const demoId = id.slice('\0virtual:dommief-demo/'.length);
96
107
  const source = demoRegistry.get(demoId) ?? 'export default function Demo(){ return null; }';
97
- return { code: source, map: null, moduleType: 'jsx' };
108
+ return jsx(source, 'demo-' + demoId);
98
109
  }
99
110
  if (id === '\0virtual:dommief/entry') {
100
111
  return { code: `import ${JSON.stringify(resolveClientFile('entry-client.tsx'))};`, map: null, moduleType: 'js' };
@@ -137,7 +148,7 @@ export function dommiefPlugin(opts: DommiefPluginOptions) {
137
148
  // Trả frontmatter + toc (nhỏ) — không texts (nặng, chỉ để tìm kiếm).
138
149
  return { code: `export default ${JSON.stringify({ frontmatter: meta.frontmatter, toc: meta.toc })};`, map: null, moduleType: 'js' };
139
150
  }
140
- return { code: out, map: null, moduleType: 'jsx' };
151
+ return jsx(out, file);
141
152
  }
142
153
  return null;
143
154
  },