@wasm-fmt/dart_fmt 0.2.0 → 0.4.0

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
@@ -1,3 +1,16 @@
1
- ## 0.0.0
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.4.0]
9
+
10
+ ### Breaking
11
+
12
+ - **Entry point change:** The default entry point has been restructured. If you are upgrading from a version below 0.4.0 and want the previous behavior, import from `@wasm-fmt/dart_fmt/web` instead of the default entry point.
13
+
14
+ ## [0.0.0]
2
15
 
3
16
  - Initial version.
package/README.md CHANGED
@@ -16,39 +16,68 @@ npx jsr add @fmt/dart-fmt
16
16
 
17
17
  # Usage
18
18
 
19
- ```javascript
20
- import init, { format } from "@wasm-fmt/dart_fmt";
19
+ ## Node.js / Deno / Bun
21
20
 
22
- await init();
21
+ ```javascript
22
+ import { format } from "@wasm-fmt/dart_fmt";
23
23
 
24
- const input = `void main() { print('Hello, World!'); }`;
24
+ const source = `void main() { print('Hello, World!'); }`;
25
25
 
26
- const formatted = format(input, "main.dart");
26
+ const formatted = format(source);
27
27
  console.log(formatted);
28
28
  ```
29
29
 
30
- For Vite users:
30
+ ## Bundler
31
31
 
32
- Add `"@wasm-fmt/dart_fmt"` to `optimizeDeps.exclude` in your vite config:
32
+ dart_fmt does not support ESM Integration entry yet.
33
+ Try use other entry points like `./esm` or `./web` instead.
33
34
 
34
- ```JSON
35
- {
36
- "optimizeDeps": {
37
- "exclude": ["@wasm-fmt/dart_fmt"]
38
- }
39
- }
40
- ```
35
+ ## Web
36
+
37
+ For web environments, you need to initialize WASM module manually:
41
38
 
42
- <details>
43
- <summary>
44
- If you cannot change the vite config, you can use another import entry
39
+ ```javascript
40
+ import init, { format } from "@wasm-fmt/dart_fmt/web";
41
+
42
+ await init();
43
+
44
+ const source = `void main() { print('Hello, World!'); }`;
45
+
46
+ const formatted = format(source);
47
+ console.log(formatted);
48
+ ```
45
49
 
46
- </summary>
50
+ ### Vite
47
51
 
48
52
  ```JavaScript
49
53
  import init, { format } from "@wasm-fmt/dart_fmt/vite";
50
54
 
55
+ await init();
51
56
  // ...
52
57
  ```
53
58
 
54
- </details>
59
+ ## Entry Points
60
+
61
+ - `.` - Auto-detects environment (Node.js uses node, default is ESM)
62
+ - `./node` - Node.js `module-sync` compatible, include CommonJS (no init required)
63
+ - `./esm` - ESM environments like modern Node.js/Deno (no init required)
64
+ - `./web` - Web browsers (requires manual init)
65
+ - `./vite` - Vite bundler (requires manual init)
66
+
67
+ # Build from source
68
+
69
+ ```bash
70
+ # 1. install Dart https://dart.dev/get-dart
71
+
72
+ # 2. clone this repo
73
+ git clone https://github.com/wasm-fmt/dart_fmt.git
74
+
75
+ # 3. install dependencies
76
+ dart pub get
77
+
78
+ # 4. build
79
+ npm run build
80
+
81
+ # 5. test
82
+ npm run test:node
83
+ ```
package/dart_fmt.d.ts CHANGED
@@ -1,32 +1,31 @@
1
- export function format(input: string, filename: string, config?: LayoutConfig): string;
1
+ /**
2
+ * WASM formatter for Dart.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { format } from "@wasm-fmt/dart_fmt";
7
+ *
8
+ * const input = "void main() { print('Hello, World!'); }";
9
+ * const output = format(input, "main.dart");
10
+ * ```
11
+ *
12
+ * @module
13
+ */
2
14
 
3
15
  interface LayoutConfig {
16
+ /** The preferred line width at which the formatter should wrap lines */
4
17
  line_width?: number;
18
+ /** The type of line ending to apply to the printed input */
5
19
  line_ending?: "lf" | "crlf";
6
- language_version?: string;
7
20
  }
8
21
 
9
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
10
-
11
- export type InitOutput = unknown;
12
-
13
- // export type SyncInitInput = BufferSource | WebAssembly.Module;
14
- // /**
15
- // * Instantiates the given `module`, which can either be bytes or
16
- // * a precompiled `WebAssembly.Module`.
17
- // *
18
- // * @param {SyncInitInput} module
19
- // *
20
- // * @returns {InitOutput}
21
- // */
22
- // export function initSync(module: SyncInitInput): InitOutput;
22
+ /** Configuration for the Dart formatter */
23
+ export interface Config extends LayoutConfig {
24
+ /** The Dart language version to use for formatting */
25
+ language_version?: string;
26
+ }
23
27
 
24
28
  /**
25
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
26
- * for everything else, calls `WebAssembly.instantiate` directly.
27
- *
28
- * @param {InitInput | Promise<InitInput>} module_or_path
29
- *
30
- * @returns {Promise<InitOutput>}
31
- */
32
- export default function init(module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
29
+ * Format the entire Dart source code string.
30
+ */
31
+ export function format(input: string, filename: string, config?: Config): string;