@takazudo/mdx-formatter 1.0.2 → 1.0.4

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/index.d.ts CHANGED
@@ -9,6 +9,12 @@ export { detectMdx };
9
9
  * Format markdown/MDX content using the Rust formatter.
10
10
  */
11
11
  export declare function format(content: string, options?: FormatOptions): Promise<string>;
12
+ /**
13
+ * Synchronous format with default settings.
14
+ * API-compatible with @takazudo/mdx-formatter-wasm's format_with_defaults().
15
+ * Useful for mocking the WASM module in Node.js test environments.
16
+ */
17
+ export declare function formatSync(content: string): string;
12
18
  /**
13
19
  * Format a file and write it back if changed
14
20
  */
@@ -19,6 +25,7 @@ export declare function formatFile(filePath: string, options?: FormatOptions): P
19
25
  export declare function checkFile(filePath: string, options?: FormatOptions): Promise<boolean>;
20
26
  declare const _default: {
21
27
  format: typeof format;
28
+ formatSync: typeof formatSync;
22
29
  formatFile: typeof formatFile;
23
30
  checkFile: typeof checkFile;
24
31
  detectMdx: typeof detectMdx;
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ import { promises as fs } from 'fs';
6
6
  import { loadConfig } from './load-config.js';
7
7
  import { detectMdx } from './detect-mdx.js';
8
8
  import { nativeFormat } from './rust-formatter.js';
9
+ import { formatterSettings } from './settings.js';
9
10
  export { detectMdx };
10
11
  /**
11
12
  * Format markdown/MDX content using the Rust formatter.
@@ -15,6 +16,14 @@ export async function format(content, options = {}) {
15
16
  const settingsJson = JSON.stringify(settings);
16
17
  return nativeFormat(content, settingsJson);
17
18
  }
19
+ /**
20
+ * Synchronous format with default settings.
21
+ * API-compatible with @takazudo/mdx-formatter-wasm's format_with_defaults().
22
+ * Useful for mocking the WASM module in Node.js test environments.
23
+ */
24
+ export function formatSync(content) {
25
+ return nativeFormat(content, JSON.stringify(formatterSettings));
26
+ }
18
27
  /**
19
28
  * Format a file and write it back if changed
20
29
  */
@@ -37,6 +46,7 @@ export async function checkFile(filePath, options = {}) {
37
46
  }
38
47
  export default {
39
48
  format,
49
+ formatSync,
40
50
  formatFile,
41
51
  checkFile,
42
52
  detectMdx,
@@ -24,7 +24,15 @@ function getPackageName() {
24
24
  return platformMap[platformName]?.[archName] ?? '';
25
25
  }
26
26
  function loadNativeModule() {
27
- // Try platform-specific npm package first
27
+ // In the repo, prefer a freshly built local native module so tests exercise
28
+ // the code from the current checkout instead of the last published binary.
29
+ try {
30
+ const native = require('../crates/mdx-formatter-napi/mdx-formatter-napi.node');
31
+ return native.format;
32
+ }
33
+ catch {
34
+ // Local build not present, fall back to platform-specific npm package.
35
+ }
28
36
  const packageName = getPackageName();
29
37
  if (packageName) {
30
38
  try {
@@ -32,17 +40,10 @@ function loadNativeModule() {
32
40
  return native.format;
33
41
  }
34
42
  catch {
35
- // Platform package not installed, try local build
43
+ // Platform package not installed, surface a build hint below.
36
44
  }
37
45
  }
38
- // Try local build
39
- try {
40
- const native = require('../crates/mdx-formatter-napi/mdx-formatter-napi.node');
41
- return native.format;
42
- }
43
- catch {
44
- throw new Error('Rust native module not available. Build it with: pnpm build:rust');
45
- }
46
+ throw new Error('Rust native module not available. Build it with: pnpm build:rust');
46
47
  }
47
48
  /**
48
49
  * The native format function. Loaded once at module init.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takazudo/mdx-formatter",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "AST-based markdown and MDX formatter with Japanese text support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -44,7 +44,7 @@
44
44
  "benchmark": "npx tsx benchmark/run.ts",
45
45
  "build:wasm": ". \"$HOME/.cargo/env\" && wasm-pack build crates/mdx-formatter-wasm --target web --out-dir ../../wasm/pkg",
46
46
  "build:wasm:bundler": ". \"$HOME/.cargo/env\" && wasm-pack build crates/mdx-formatter-wasm --target bundler --out-dir ../../wasm/pkg-bundler",
47
- "build:wasm:doc": ". \"$HOME/.cargo/env\" && wasm-pack build crates/mdx-formatter-wasm --target web --out-dir ../../doc/src/wasm-pkg && mkdir -p doc/public/wasm && cp doc/src/wasm-pkg/mdx_formatter_wasm_bg.wasm doc/public/wasm/",
47
+ "build:wasm:doc": ". \"$HOME/.cargo/env\" && wasm-pack build crates/mdx-formatter-wasm --target web --out-dir ../../doc/src/wasm-pkg && mkdir -p doc/public/wasm && cp doc/src/wasm-pkg/mdx_formatter_wasm_bg.wasm doc/public/wasm/ && cp doc/src/wasm-pkg/mdx_formatter_wasm.js doc/public/wasm/",
48
48
  "b4push": "./scripts/run-b4push.sh",
49
49
  "doc:start": "pnpm --dir doc start",
50
50
  "prepublishOnly": "tsc && vitest run"