@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 +14 -1
- package/README.md +48 -19
- package/dart_fmt.d.ts +23 -24
- package/dart_fmt.mjs +329 -291
- package/dart_fmt.support.js +1 -0
- package/dart_fmt.unopt.wasm +0 -0
- package/dart_fmt.unopt.wasm.map +3 -3
- package/dart_fmt.wasm +0 -0
- package/dart_fmt.wasm.map +1 -1
- package/dart_fmt_esm.js +10 -0
- package/dart_fmt_node.js +10 -7
- package/dart_fmt_vite.js +4 -2
- package/dart_fmt_web.d.ts +41 -0
- package/dart_fmt_web.js +75 -0
- package/jsr.jsonc +18 -29
- package/package.json +60 -35
- package/wasm-fmt-dart_fmt-0.4.0.tgz +0 -0
- package/dart_fmt.js +0 -84
- package/wasm-fmt-dart_fmt-0.2.0.tgz +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
20
|
-
import init, { format } from "@wasm-fmt/dart_fmt";
|
|
19
|
+
## Node.js / Deno / Bun
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
```javascript
|
|
22
|
+
import { format } from "@wasm-fmt/dart_fmt";
|
|
23
23
|
|
|
24
|
-
const
|
|
24
|
+
const source = `void main() { print('Hello, World!'); }`;
|
|
25
25
|
|
|
26
|
-
const formatted = format(
|
|
26
|
+
const formatted = format(source);
|
|
27
27
|
console.log(formatted);
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
## Bundler
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
dart_fmt does not support ESM Integration entry yet.
|
|
33
|
+
Try use other entry points like `./esm` or `./web` instead.
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
*
|
|
26
|
-
|
|
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;
|