@qnroa/qtype 0.0.4 → 0.0.5

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/CHANGELOG.md CHANGED
@@ -13,6 +13,24 @@ can land in any minor bump (`0.x.0`).
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.0.5] - 2026-08-22
17
+
18
+ ### Fixed
19
+
20
+ - **Mermaid pre-render no longer fails under `npx` / hosted CI.**
21
+ `mermaidPrerender.init()` now uses `createRequire(import.meta.url).resolve('mermaid/…')`
22
+ to locate the mermaid ESM, so Node's own module resolver walks the
23
+ actual `node_modules` chain regardless of where qtype was installed
24
+ — user repo, npx cache, Cloudflare Pages build root, monorepo hoist.
25
+ The previous two hard-coded lookup paths remain as fallbacks but
26
+ are no longer the primary strategy. This fixes the
27
+ `mermaid ESM not found in node_modules` error on Cloudflare Pages
28
+ when a deck actually contains ` ```mermaid ` code blocks.
29
+ - **`publish build` now copies `material/assets/**`** into
30
+ `dist/material/assets/` verbatim. Previously the CLI only walked
31
+ `.md` files, so any image the cards referenced via
32
+ `![](/material/assets/…)` returned 404 on the deployed site.
33
+
16
34
  ## [0.0.4] - 2026-08-22
17
35
 
18
36
  ### Added
package/CHANGELOG.zh.md CHANGED
@@ -12,6 +12,22 @@ English: [CHANGELOG.md](https://www.npmjs.com/package/@qnroa/qtype?activeTab=cod
12
12
 
13
13
  ## [Unreleased]
14
14
 
15
+ ## [0.0.5] - 2026-08-22
16
+
17
+ ### 修复
18
+
19
+ - **Mermaid 预渲染在 `npx` / 托管 CI 环境不再失败**。
20
+ `mermaidPrerender.init()` 改用
21
+ `createRequire(import.meta.url).resolve('mermaid/…')`,让 Node
22
+ 自己顺着 `node_modules` 链找 mermaid,不管 qtype 是装到用户仓库、
23
+ npx 缓存、Cloudflare Pages build root 还是 monorepo hoist 都能
24
+ 找到。之前的两条硬编码查找路径保留作为兜底,但不再是主要策略。
25
+ 修复了 deck 里真的有 ` ```mermaid ` 代码块时,Cloudflare Pages 上
26
+ `mermaid ESM not found in node_modules` 报错。
27
+ - **`publish build` 现在会把 `material/assets/**`** 原样拷进
28
+ `dist/material/assets/`。之前 CLI 只遍历 `.md` 文件,导致卡片
29
+ 引用的 `![](/material/assets/…)` 图片在部署后 404。
30
+
15
31
  ## [0.0.4] - 2026-08-22
16
32
 
17
33
  ### 新增
@@ -38,15 +38,37 @@ export class MermaidRenderer {
38
38
  pageDark = null;
39
39
  pageLight = null;
40
40
  async init() {
41
- const candidates = [
42
- path.resolve(__dirname, '..', '..', '..', '..', '..', 'node_modules', 'mermaid', 'dist', 'mermaid.esm.min.mjs'),
43
- path.resolve(process.cwd(), 'node_modules', 'mermaid', 'dist', 'mermaid.esm.min.mjs'),
44
- ];
41
+ // Ask Node's own module resolver where mermaid actually lives. It
42
+ // walks the `node_modules` chain from this file up, so it works
43
+ // regardless of where the caller installed qtype:
44
+ //
45
+ // * user repo with `npm install @qnroa/qtype` → resolves in
46
+ // `<user>/node_modules/mermaid`
47
+ // * `npx @qnroa/qtype` on any host (Cloudflare, → resolves in
48
+ // Vercel, GitHub Pages) that hoists deps into the npx cache
49
+ // an npx cache
50
+ // * monorepo with hoisted deps → resolves in
51
+ // the hoisted root
52
+ //
53
+ // The two hard-coded fallbacks below only fire if Node's resolver
54
+ // fails entirely (older Node, exotic packaging), which shouldn't
55
+ // happen in any supported deployment.
45
56
  let mermaidEsm = null;
46
- for (const c of candidates) {
47
- if (fs.existsSync(c)) {
48
- mermaidEsm = c;
49
- break;
57
+ try {
58
+ const { createRequire } = await import('node:module');
59
+ const req = createRequire(import.meta.url);
60
+ mermaidEsm = req.resolve('mermaid/dist/mermaid.esm.min.mjs');
61
+ }
62
+ catch {
63
+ const candidates = [
64
+ path.resolve(__dirname, '..', '..', '..', '..', '..', 'node_modules', 'mermaid', 'dist', 'mermaid.esm.min.mjs'),
65
+ path.resolve(process.cwd(), 'node_modules', 'mermaid', 'dist', 'mermaid.esm.min.mjs'),
66
+ ];
67
+ for (const c of candidates) {
68
+ if (fs.existsSync(c)) {
69
+ mermaidEsm = c;
70
+ break;
71
+ }
50
72
  }
51
73
  }
52
74
  if (!mermaidEsm) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qnroa/qtype",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Turn Markdown notes into typing practice — CLI + review + static-site publisher",
5
5
  "keywords": [
6
6
  "typing",