@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/dart_fmt_esm.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* @ts-self-types="./dart_fmt.d.ts" */
|
|
2
|
+
// prettier-ignore
|
|
3
|
+
import source wasmModule from "./dart_fmt.wasm";
|
|
4
|
+
import { formatWrapper, initSync } from "./dart_fmt.mjs";
|
|
5
|
+
|
|
6
|
+
const app = initSync(wasmModule);
|
|
7
|
+
|
|
8
|
+
export function format(source, filename, options) {
|
|
9
|
+
return formatWrapper(app, source, filename, options);
|
|
10
|
+
}
|
package/dart_fmt_node.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
/* @ts-self-types="./dart_fmt.d.ts" */
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { formatWrapper, initSync } from "./dart_fmt.mjs";
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
+
const wasmUrl = new URL("dart_fmt.wasm", import.meta.url);
|
|
6
|
+
const wasmBytes = readFileSync(wasmUrl);
|
|
7
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
return initAsync(init);
|
|
8
|
-
}
|
|
9
|
+
const app = initSync(wasmModule);
|
|
9
10
|
|
|
10
|
-
export
|
|
11
|
+
export function format(source, filename, options) {
|
|
12
|
+
return formatWrapper(app, source, filename, options);
|
|
13
|
+
}
|
package/dart_fmt_vite.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/* @ts-self-types="./dart_fmt_web.d.ts" */
|
|
2
|
+
|
|
2
3
|
import wasm from "./dart_fmt.wasm?url";
|
|
4
|
+
import initAsync from "./dart_fmt_web.js";
|
|
3
5
|
|
|
4
|
-
export default function
|
|
6
|
+
export default function (input = wasm) {
|
|
5
7
|
return initAsync(input);
|
|
6
8
|
}
|
|
7
9
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import this module and call init function before using.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import init, { format } from "@wasm-fmt/dart_fmt/web";
|
|
7
|
+
*
|
|
8
|
+
* await init();
|
|
9
|
+
*
|
|
10
|
+
* const input = "void main() { print('Hello, World!'); }";
|
|
11
|
+
* const output = format(input, "main.dart");
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Input types for asynchronous WASM initialization.
|
|
19
|
+
* Can be a URL/path to fetch, a Response object, raw bytes, or a pre-compiled WebAssembly.Module.
|
|
20
|
+
*/
|
|
21
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Input types for synchronous WASM initialization.
|
|
25
|
+
* Must be raw bytes (BufferSource) or a pre-compiled WebAssembly.Module.
|
|
26
|
+
*/
|
|
27
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Initializes the WASM module asynchronously.
|
|
31
|
+
* @param init_input - Optional URL/path to the WASM file, or any valid InitInput
|
|
32
|
+
*/
|
|
33
|
+
export default function initAsync(init_input?: InitInput | Promise<InitInput>): Promise<void>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Initializes the WASM module synchronously.
|
|
37
|
+
* @param module_or_buffer - The WASM module or buffer source
|
|
38
|
+
*/
|
|
39
|
+
export declare function initSync(module_or_buffer: SyncInitInput): void;
|
|
40
|
+
|
|
41
|
+
export * from "./dart_fmt.d.ts";
|
package/dart_fmt_web.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* @ts-self-types="./dart_fmt_web.d.ts" */
|
|
2
|
+
let app, wasmModule;
|
|
3
|
+
import { formatWrapper, initSync as finalize_init } from "./dart_fmt.mjs";
|
|
4
|
+
|
|
5
|
+
async function load(input) {
|
|
6
|
+
if (typeof Response === "function" && input instanceof Response) {
|
|
7
|
+
if (typeof WebAssembly.compileStreaming === "function") {
|
|
8
|
+
try {
|
|
9
|
+
return await WebAssembly.compileStreaming(input, compileOptions);
|
|
10
|
+
} catch (e) {
|
|
11
|
+
const validResponse = input.ok && expectedResponseType(input.type);
|
|
12
|
+
|
|
13
|
+
if (validResponse && input.headers.get("Content-Type") !== "application/wasm") {
|
|
14
|
+
console.warn(
|
|
15
|
+
"`WebAssembly.compileStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",
|
|
16
|
+
e,
|
|
17
|
+
);
|
|
18
|
+
} else {
|
|
19
|
+
throw e;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const bytes = await input.arrayBuffer();
|
|
25
|
+
return await WebAssembly.compile(bytes, compileOptions);
|
|
26
|
+
} else {
|
|
27
|
+
return await WebAssembly.compile(input, compileOptions);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function expectedResponseType(type) {
|
|
31
|
+
switch (type) {
|
|
32
|
+
case "basic":
|
|
33
|
+
case "cors":
|
|
34
|
+
case "default":
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function initSync(module_or_buffer) {
|
|
42
|
+
if (app !== void 0) return app;
|
|
43
|
+
|
|
44
|
+
if (!(module_or_buffer instanceof WebAssembly.Module)) {
|
|
45
|
+
module_or_buffer = new WebAssembly.Module(module_or_buffer, compileOptions);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (app = finalize_init(module_or_buffer, compileOptions));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default async function initAsync(init_input) {
|
|
52
|
+
if (app !== void 0) return app;
|
|
53
|
+
|
|
54
|
+
if (init_input === void 0) {
|
|
55
|
+
init_input = new URL("dart_fmt.wasm", import.meta.url);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (
|
|
59
|
+
typeof init_input === "string" ||
|
|
60
|
+
(typeof Request === "function" && init_input instanceof Request) ||
|
|
61
|
+
(typeof URL === "function" && init_input instanceof URL)
|
|
62
|
+
) {
|
|
63
|
+
init_input = fetch(init_input);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const module = await load(await init_input);
|
|
67
|
+
|
|
68
|
+
return (app = finalize_init(module, compileOptions));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function format(source, filename, options) {
|
|
72
|
+
return formatWrapper(app, source, filename, options);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const compileOptions = { builtins: ["js-string"] };
|
package/jsr.jsonc
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"type": "module",
|
|
21
|
-
"publishConfig": {
|
|
22
|
-
"access": "public"
|
|
23
|
-
},
|
|
24
|
-
"exports": "./dart_fmt.js",
|
|
25
|
-
"exclude": [
|
|
26
|
-
"!../build",
|
|
27
|
-
"*.tgz",
|
|
28
|
-
".npmignore"
|
|
29
|
-
]
|
|
30
|
-
}
|
|
2
|
+
"$schema": "https://jsr.io/schema/config-file.v1.json",
|
|
3
|
+
"name": "@fmt/dart-fmt",
|
|
4
|
+
"version": "0.4.0",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./node": "./dart_fmt_node.js",
|
|
7
|
+
"./web": "./dart_fmt_web.js"
|
|
8
|
+
},
|
|
9
|
+
"publish": {
|
|
10
|
+
"include": [
|
|
11
|
+
"dart_fmt_*",
|
|
12
|
+
"dart_fmt.*",
|
|
13
|
+
"*.md"
|
|
14
|
+
],
|
|
15
|
+
"exclude": [
|
|
16
|
+
"!*"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,37 +1,62 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
2
|
+
"name": "@wasm-fmt/dart_fmt",
|
|
3
|
+
"description": "Dart Formatter powered by WASM ported from dart_style",
|
|
4
|
+
"author": "magic-akari <akari.ccino@gmail.com>",
|
|
5
|
+
"version": "0.4.0",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/wasm-fmt/dart_fmt.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/wasm-fmt/dart_fmt",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"wasm",
|
|
14
|
+
"formatter",
|
|
15
|
+
"dart"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "scripts/build.sh",
|
|
20
|
+
"fmt:dart": "dart format .",
|
|
21
|
+
"fmt:dprint": "dprint fmt",
|
|
22
|
+
"test:node": "node --test test_node/*.mjs",
|
|
23
|
+
"test:deno": "deno test test_deno --allow-read",
|
|
24
|
+
"test:bun": "bun test test_bun",
|
|
25
|
+
"version": "node ./scripts/sync_version.js && git add ."
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"sideEffects": [
|
|
31
|
+
"./dart_fmt_node.js",
|
|
32
|
+
"./dart_fmt_esm.js"
|
|
33
|
+
],
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dart_fmt.d.ts",
|
|
37
|
+
"bun": "./dart_fmt_node.js",
|
|
38
|
+
"module-sync": "./dart_fmt_node.js",
|
|
39
|
+
"node": "./dart_fmt_node.js",
|
|
40
|
+
"default": "./dart_fmt_esm.js"
|
|
41
|
+
},
|
|
42
|
+
"./esm": {
|
|
43
|
+
"types": "./dart_fmt.d.ts",
|
|
44
|
+
"default": "./dart_fmt_esm.js"
|
|
45
|
+
},
|
|
46
|
+
"./node": {
|
|
47
|
+
"types": "./dart_fmt.d.ts",
|
|
48
|
+
"default": "./dart_fmt_node.js"
|
|
49
|
+
},
|
|
50
|
+
"./web": {
|
|
51
|
+
"types": "./dart_fmt_web.d.ts",
|
|
52
|
+
"default": "./dart_fmt_web.js"
|
|
53
|
+
},
|
|
54
|
+
"./vite": {
|
|
55
|
+
"types": "./dart_fmt_web.d.ts",
|
|
56
|
+
"default": "./dart_fmt_vite.js"
|
|
57
|
+
},
|
|
58
|
+
"./wasm": "./dart_fmt.wasm",
|
|
59
|
+
"./package.json": "./package.json",
|
|
60
|
+
"./*": "./*"
|
|
61
|
+
}
|
|
37
62
|
}
|
|
Binary file
|
package/dart_fmt.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/* @ts-self-types="./dart_fmt.d.ts" */
|
|
2
|
-
import { format as dart_fmt, instantiate, invoke } from "./dart_fmt.mjs";
|
|
3
|
-
|
|
4
|
-
let wasm;
|
|
5
|
-
|
|
6
|
-
function normalize(module) {
|
|
7
|
-
if (!(module instanceof WebAssembly.Module)) {
|
|
8
|
-
return new WebAssembly.Module(module);
|
|
9
|
-
}
|
|
10
|
-
return module;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default async function (input) {
|
|
14
|
-
if (wasm !== undefined) return wasm;
|
|
15
|
-
|
|
16
|
-
if (typeof input === "undefined") {
|
|
17
|
-
input = new URL("dart_fmt.wasm", import.meta.url);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
typeof input === "string" ||
|
|
22
|
-
(typeof Request === "function" && input instanceof Request) ||
|
|
23
|
-
(typeof URL === "function" && input instanceof URL)
|
|
24
|
-
) {
|
|
25
|
-
input = fetch(input);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
wasm = await load(await input)
|
|
29
|
-
.then(normalize)
|
|
30
|
-
.then(instantiate);
|
|
31
|
-
|
|
32
|
-
invoke(wasm);
|
|
33
|
-
|
|
34
|
-
return wasm;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function load(module) {
|
|
38
|
-
if (typeof Response === "function" && module instanceof Response) {
|
|
39
|
-
if ("compileStreaming" in WebAssembly) {
|
|
40
|
-
try {
|
|
41
|
-
return await WebAssembly.compileStreaming(module);
|
|
42
|
-
} catch (e) {
|
|
43
|
-
if (module.headers.get("Content-Type") != "application/wasm") {
|
|
44
|
-
console.warn(
|
|
45
|
-
"`WebAssembly.compileStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",
|
|
46
|
-
e,
|
|
47
|
-
);
|
|
48
|
-
} else {
|
|
49
|
-
throw e;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return module.arrayBuffer();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return module;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function format(source, filename = "stdin.dart", config = {}) {
|
|
61
|
-
const options = { lineEnding: "\n" };
|
|
62
|
-
if (config.line_width) {
|
|
63
|
-
options.pageWidth = config.line_width;
|
|
64
|
-
}
|
|
65
|
-
if (config.line_ending === "crlf") {
|
|
66
|
-
options.lineEnding = "\r\n";
|
|
67
|
-
}
|
|
68
|
-
if (config.language_version) {
|
|
69
|
-
options.languageVersion = config.language_version;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const result = dart_fmt(source, filename, JSON.stringify(options));
|
|
73
|
-
if (result.success) {
|
|
74
|
-
return result.code;
|
|
75
|
-
}
|
|
76
|
-
throw new Error(result.error);
|
|
77
|
-
}
|
|
Binary file
|