@wasm-fmt/mago_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/README.md CHANGED
@@ -16,10 +16,10 @@ npx jsr add @fmt/mago-fmt
16
16
 
17
17
  # Usage
18
18
 
19
- ```javascript
20
- import init, { format } from "@wasm-fmt/mago_fmt";
19
+ ## Node.js / Deno / Bun / Bundler
21
20
 
22
- await init();
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
- with custom options:
38
+ With specific PHP version:
35
39
 
36
40
  ```javascript
37
- import init, { format } from "@wasm-fmt/mago_fmt";
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 = format(input, "main.php", {
48
- "use-tabs": false,
49
- "tab-width": 4,
50
- "print-width": 120,
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
- with specific PHP version:
57
+ ## Web
58
+
59
+ For web environments, you need to initialize WASM module manually:
56
60
 
57
61
  ```javascript
58
- import init, { format_with_version } from "@wasm-fmt/mago_fmt";
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 = format_with_version(input, "8.3", "main.php", {
69
- "use-tabs": false,
70
- "tab-width": 4,
71
- "print-width": 120,
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
- For Vite users:
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
- </details>
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
- [Mago]: https://github.com/carthage-software/mago
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
- "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.3.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
- "./snippets/*"
18
- ],
19
- "keywords": [
20
- "wasm",
21
- "mago",
22
- "PHP",
23
- "formatter"
24
- ],
25
- "publishConfig": {
26
- "access": "public"
27
- },
28
- "exports": "./mago_fmt.js",
29
- "exclude": [
30
- "!**",
31
- "*.tgz"
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
- * Instantiates the given `module`, which can either be bytes or
24
- * a precompiled `WebAssembly.Module`.
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
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
34
- * for everything else, calls `WebAssembly.instantiate` directly.
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;