@wasm-fmt/mago_fmt 0.3.1 → 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/README.md +31 -43
- package/jsr.jsonc +39 -31
- package/mago_fmt.d.ts +6 -34
- package/mago_fmt.js +5 -506
- package/mago_fmt_bg.js +442 -0
- package/mago_fmt_bg.wasm +0 -0
- package/mago_fmt_esm.js +27 -0
- package/mago_fmt_node.js +25 -8
- package/mago_fmt_vite.js +35 -5
- package/mago_fmt_web.d.ts +18 -0
- package/mago_fmt_web.js +76 -0
- package/package.json +61 -39
package/README.md
CHANGED
|
@@ -16,10 +16,10 @@ npx jsr add @fmt/mago-fmt
|
|
|
16
16
|
|
|
17
17
|
# Usage
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
import init, { format } from "@wasm-fmt/mago_fmt";
|
|
19
|
+
## Node.js / Deno / Bun / Bundler
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
```javascript
|
|
22
|
+
import { format } from "@wasm-fmt/mago_fmt";
|
|
23
23
|
|
|
24
24
|
const input = `<?php
|
|
25
25
|
function hello( \$name ) {
|
|
@@ -27,16 +27,18 @@ function hello( \$name ) {
|
|
|
27
27
|
}
|
|
28
28
|
?>`;
|
|
29
29
|
|
|
30
|
-
const formatted = format(input
|
|
30
|
+
const formatted = format(input, "main.php", {
|
|
31
|
+
"use-tabs": false,
|
|
32
|
+
"tab-width": 4,
|
|
33
|
+
"print-width": 120,
|
|
34
|
+
});
|
|
31
35
|
console.log(formatted);
|
|
32
36
|
```
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
With specific PHP version:
|
|
35
39
|
|
|
36
40
|
```javascript
|
|
37
|
-
import
|
|
38
|
-
|
|
39
|
-
await init();
|
|
41
|
+
import { format_with_version } from "@wasm-fmt/mago_fmt";
|
|
40
42
|
|
|
41
43
|
const input = `<?php
|
|
42
44
|
function hello( \$name ) {
|
|
@@ -44,18 +46,20 @@ function hello( \$name ) {
|
|
|
44
46
|
}
|
|
45
47
|
?>`;
|
|
46
48
|
|
|
47
|
-
const formatted =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
const formatted = format_with_version(input, "8.3", "main.php", {
|
|
50
|
+
"use-tabs": false,
|
|
51
|
+
"tab-width": 4,
|
|
52
|
+
"print-width": 120,
|
|
51
53
|
});
|
|
52
54
|
console.log(formatted);
|
|
53
55
|
```
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
## Web
|
|
58
|
+
|
|
59
|
+
For web environments, you need to initialize WASM module manually:
|
|
56
60
|
|
|
57
61
|
```javascript
|
|
58
|
-
import init, {
|
|
62
|
+
import init, { format } from "@wasm-fmt/mago_fmt/web";
|
|
59
63
|
|
|
60
64
|
await init();
|
|
61
65
|
|
|
@@ -65,47 +69,31 @@ function hello( \$name ) {
|
|
|
65
69
|
}
|
|
66
70
|
?>`;
|
|
67
71
|
|
|
68
|
-
const formatted =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
const formatted = format(input, "main.php", {
|
|
73
|
+
"use-tabs": false,
|
|
74
|
+
"tab-width": 4,
|
|
75
|
+
"print-width": 120,
|
|
72
76
|
});
|
|
73
77
|
console.log(formatted);
|
|
74
78
|
```
|
|
75
79
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
Add `"@wasm-fmt/mago_fmt"` to `optimizeDeps.exclude` in your vite config:
|
|
79
|
-
|
|
80
|
-
```JSON
|
|
81
|
-
{
|
|
82
|
-
"optimizeDeps": {
|
|
83
|
-
"exclude": ["@wasm-fmt/mago_fmt"]
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
<details>
|
|
89
|
-
<summary>
|
|
90
|
-
If you cannot change the vite config, you can use another import entry
|
|
91
|
-
|
|
92
|
-
</summary>
|
|
80
|
+
### Vite
|
|
93
81
|
|
|
94
82
|
```JavaScript
|
|
95
83
|
import init, { format } from "@wasm-fmt/mago_fmt/vite";
|
|
96
84
|
|
|
85
|
+
await init();
|
|
97
86
|
// ...
|
|
98
87
|
```
|
|
99
88
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
# How does it work?
|
|
103
|
-
|
|
104
|
-
[Mago] is an extremely fast PHP linter, formatter, and static analyzer, written in Rust.
|
|
105
|
-
|
|
106
|
-
This package is a WebAssembly build of the Mago formatter, with a JavaScript wrapper.
|
|
89
|
+
## Entry Points
|
|
107
90
|
|
|
108
|
-
|
|
91
|
+
- `.` - Auto-detects environment (Node.js uses node, Webpack uses bundler, default is ESM)
|
|
92
|
+
- `./node` - Node.js environment (no init required)
|
|
93
|
+
- `./esm` - ESM environments like Deno (no init required)
|
|
94
|
+
- `./bundler` - Bundlers like Webpack (no init required)
|
|
95
|
+
- `./web` - Web browsers (requires manual init)
|
|
96
|
+
- `./vite` - Vite bundler (requires manual init)
|
|
109
97
|
|
|
110
98
|
# Credits
|
|
111
99
|
|
package/jsr.jsonc
CHANGED
|
@@ -1,33 +1,41 @@
|
|
|
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
|
-
|
|
2
|
+
"name": "@fmt/mago-fmt",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"collaborators": [
|
|
5
|
+
"magic-akari <akari.ccino@gmail.com>"
|
|
6
|
+
],
|
|
7
|
+
"description": "A WASM based PHP Formatter",
|
|
8
|
+
"version": "0.4.0",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/wasm-fmt/mago_fmt"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/wasm-fmt/mago_fmt",
|
|
15
|
+
"types": "mago_fmt.d.ts",
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"./mago_fmt.js",
|
|
18
|
+
"./snippets/*"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"wasm",
|
|
22
|
+
"mago",
|
|
23
|
+
"PHP",
|
|
24
|
+
"formatter"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./mago_fmt_esm.js",
|
|
31
|
+
"./esm": "./mago_fmt_esm.js",
|
|
32
|
+
"./node": "./mago_fmt_node.js",
|
|
33
|
+
"./bundler": "./mago_fmt.js",
|
|
34
|
+
"./web": "./mago_fmt_web.js",
|
|
35
|
+
"./wasm": "./mago_fmt_bg.wasm"
|
|
36
|
+
},
|
|
37
|
+
"exclude": [
|
|
38
|
+
"!**",
|
|
39
|
+
"*.tgz"
|
|
40
|
+
]
|
|
33
41
|
}
|
package/mago_fmt.d.ts
CHANGED
|
@@ -1,40 +1,12 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
-
export function format(code: string, filename?: string | null, settings?: any | null): string;
|
|
5
|
-
|
|
6
|
-
export function format_with_version(code: string, php_version: string, filename?: string | null, settings?: any | null): string;
|
|
7
|
-
|
|
8
|
-
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
9
|
-
|
|
10
|
-
export interface InitOutput {
|
|
11
|
-
readonly memory: WebAssembly.Memory;
|
|
12
|
-
readonly format: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
13
|
-
readonly format_with_version: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
14
|
-
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
15
|
-
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
16
|
-
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
17
|
-
readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
21
|
-
|
|
22
4
|
/**
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
27
|
-
*
|
|
28
|
-
* @returns {InitOutput}
|
|
29
|
-
*/
|
|
30
|
-
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
5
|
+
* Format PHP code with optional filename and settings.
|
|
6
|
+
*/
|
|
7
|
+
export function format(code: string, filename?: string | null, settings?: any | null): string;
|
|
31
8
|
|
|
32
9
|
/**
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
37
|
-
*
|
|
38
|
-
* @returns {Promise<InitOutput>}
|
|
39
|
-
*/
|
|
40
|
-
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
10
|
+
* Format PHP code with specified PHP version, optional filename and settings.
|
|
11
|
+
*/
|
|
12
|
+
export function format_with_version(code: string, php_version: string, filename?: string | null, settings?: any | null): string;
|