@wasm-fmt/dart_fmt 0.3.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 +27 -4
- 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 -77
- package/wasm-fmt-dart_fmt-0.3.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;
|
package/dart_fmt.mjs
CHANGED
|
@@ -53,7 +53,7 @@ class CompiledApp {
|
|
|
53
53
|
// should be the bytes for the wasm module in a format supported by
|
|
54
54
|
// `WebAssembly.compile` or `WebAssembly.compileStreaming`. The second
|
|
55
55
|
// should be the result of using the JS 'import' API on the js file path.
|
|
56
|
-
|
|
56
|
+
instantiate(additionalImports, {loadDeferredWasm, loadDynamicModule} = {}) {
|
|
57
57
|
let dartInstance;
|
|
58
58
|
|
|
59
59
|
// Prints to the console
|
|
@@ -189,7 +189,7 @@ class CompiledApp {
|
|
|
189
189
|
_182: (x0,x1) => { x0.success = x1 },
|
|
190
190
|
_183: (x0,x1) => { x0.code = x1 },
|
|
191
191
|
_184: (x0,x1) => { x0.error = x1 },
|
|
192
|
-
_185: x0 => { format = x0 },
|
|
192
|
+
_185: x0 => { this.format = x0 },
|
|
193
193
|
_186: f => finalizeWrapper(f, function(x0,x1,x2) { return dartInstance.exports._186(f,arguments.length,x0,x1,x2) }),
|
|
194
194
|
_203: (c) =>
|
|
195
195
|
queueMicrotask(() => dartInstance.exports.$invokeCallback(c)),
|
|
@@ -339,7 +339,7 @@ class CompiledApp {
|
|
|
339
339
|
|
|
340
340
|
|
|
341
341
|
|
|
342
|
-
dartInstance =
|
|
342
|
+
dartInstance = new WebAssembly.Instance(this.module, {
|
|
343
343
|
...baseImports,
|
|
344
344
|
...additionalImports,
|
|
345
345
|
|
|
@@ -361,5 +361,28 @@ class InstantiatedApp {
|
|
|
361
361
|
this.instantiatedModule.exports.$invokeMain(args);
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
365
|
+
export function initSync(module, compileOptions = { builtins: ["js-string"] }) {
|
|
366
|
+
const app = new CompiledApp(module, compileOptions).instantiate();
|
|
367
|
+
app.invokeMain();
|
|
368
|
+
return app;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export function formatWrapper(app, source, filename = "stdin.dart", config = {}) {
|
|
372
|
+
const options = { lineEnding: "\n" };
|
|
373
|
+
if (config.line_width) {
|
|
374
|
+
options.pageWidth = config.line_width;
|
|
375
|
+
}
|
|
376
|
+
if (config.line_ending === "crlf") {
|
|
377
|
+
options.lineEnding = "\r\n";
|
|
378
|
+
}
|
|
379
|
+
if (config.language_version) {
|
|
380
|
+
options.languageVersion = config.language_version;
|
|
381
|
+
}
|
|
364
382
|
|
|
365
|
-
|
|
383
|
+
const result = app.compiledApp.format(source, filename, JSON.stringify(options));
|
|
384
|
+
if (result.success) {
|
|
385
|
+
return result.code;
|
|
386
|
+
}
|
|
387
|
+
throw new Error(result.error);
|
|
388
|
+
}
|
package/dart_fmt.unopt.wasm
CHANGED
|
Binary file
|