@wasm-fmt/oxc_fmt 0.0.0 → 0.2.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 +71 -0
- package/layout_config.d.ts +16 -0
- package/options.d.ts +114 -0
- package/oxc_fmt.d.ts +16 -53
- package/oxc_fmt.js +7 -512
- package/oxc_fmt_bg.js +419 -0
- package/oxc_fmt_bg.wasm +0 -0
- package/oxc_fmt_esm.js +27 -0
- package/oxc_fmt_node.js +17 -6
- package/oxc_fmt_vite.js +35 -5
- package/oxc_fmt_web.d.ts +44 -0
- package/oxc_fmt_web.js +93 -0
- package/package.json +28 -5
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
[](https://github.com/wasm-fmt/web_fmt/actions/workflows/test.yml)
|
|
2
|
+
|
|
3
|
+
# Install
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@wasm-fmt/oxc_fmt)
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @wasm-fmt/oxc_fmt
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
[](https://jsr.io/@fmt/oxc-fmt)
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npx jsr add @fmt/oxc-fmt
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
# Usage
|
|
18
|
+
|
|
19
|
+
## Node.js / Deno / Bun / Bundler
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import { format } from "@wasm-fmt/oxc_fmt";
|
|
23
|
+
|
|
24
|
+
const input = `const foo = "bar"`;
|
|
25
|
+
|
|
26
|
+
const formatted = format(input, "index.js");
|
|
27
|
+
console.log(formatted);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Web
|
|
31
|
+
|
|
32
|
+
For web environments, you need to initialize WASM module manually:
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
import init, { format } from "@wasm-fmt/oxc_fmt/web";
|
|
36
|
+
|
|
37
|
+
await init();
|
|
38
|
+
|
|
39
|
+
const input = `const foo = "bar"`;
|
|
40
|
+
|
|
41
|
+
const formatted = format(input, "index.js");
|
|
42
|
+
console.log(formatted);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Vite
|
|
46
|
+
|
|
47
|
+
```JavaScript
|
|
48
|
+
import init, { format } from "@wasm-fmt/oxc_fmt/vite";
|
|
49
|
+
|
|
50
|
+
await init();
|
|
51
|
+
// ...
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Entry Points
|
|
55
|
+
|
|
56
|
+
- `.` - Auto-detects environment (Node.js uses node, Webpack uses bundler, default is ESM)
|
|
57
|
+
- `./node` - Node.js environment (no init required)
|
|
58
|
+
- `./esm` - ESM environments like Deno (no init required)
|
|
59
|
+
- `./bundler` - Bundlers like Webpack (no init required)
|
|
60
|
+
- `./web` - Web browsers (requires manual init)
|
|
61
|
+
- `./vite` - Vite bundler (requires manual init)
|
|
62
|
+
|
|
63
|
+
# Configuration
|
|
64
|
+
|
|
65
|
+
See [oxc formatter configuration docs](https://oxc.rs/docs/guide/usage/formatter/config.html) and [prettier options](https://prettier.io/docs/options) for all available options.
|
|
66
|
+
|
|
67
|
+
# Credits
|
|
68
|
+
|
|
69
|
+
Thanks to:
|
|
70
|
+
|
|
71
|
+
- The [oxc](https://github.com/oxc-project/oxc) project
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layout configuration options shared across all formatters.
|
|
3
|
+
*/
|
|
4
|
+
export interface LayoutConfig {
|
|
5
|
+
/** Indentation style. Defaults to "space". */
|
|
6
|
+
indentStyle?: "tab" | "space";
|
|
7
|
+
|
|
8
|
+
/** Number of spaces per indentation level. Defaults to 2. */
|
|
9
|
+
indentWidth?: number;
|
|
10
|
+
|
|
11
|
+
/** Maximum line width before wrapping. Defaults to 80. */
|
|
12
|
+
lineWidth?: number;
|
|
13
|
+
|
|
14
|
+
/** Line ending style. Defaults to "lf". */
|
|
15
|
+
lineEnding?: "lf" | "crlf";
|
|
16
|
+
}
|
package/options.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { LayoutConfig } from "./layout_config.d.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for OXC formatter.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://oxc.rs/docs/guide/usage/formatter/config.html}
|
|
7
|
+
* @see {@link https://prettier.io/docs/options}
|
|
8
|
+
*/
|
|
9
|
+
export interface Config extends LayoutConfig {
|
|
10
|
+
/** The style for quotes. Defaults to "double". */
|
|
11
|
+
singleQuote?: boolean;
|
|
12
|
+
|
|
13
|
+
/** The style for JSX quotes. Defaults to "double". */
|
|
14
|
+
jsxSingleQuote?: boolean;
|
|
15
|
+
|
|
16
|
+
/** When properties in objects are quoted. Defaults to "as-needed". */
|
|
17
|
+
quoteProps?: "as-needed" | "consistent" | "preserve";
|
|
18
|
+
|
|
19
|
+
/** Print trailing commas wherever possible in multi-line comma-separated syntactic structures. Defaults to "all". */
|
|
20
|
+
trailingComma?: "all" | "es5" | "none";
|
|
21
|
+
|
|
22
|
+
/** Whether the formatter prints semicolons for all statements. Defaults to true. */
|
|
23
|
+
semi?: boolean;
|
|
24
|
+
|
|
25
|
+
/** Whether to add non-necessary parentheses to arrow functions. Defaults to "always". */
|
|
26
|
+
arrowParens?: "always" | "avoid";
|
|
27
|
+
|
|
28
|
+
/** Whether to insert spaces around brackets in object literals. Defaults to true. */
|
|
29
|
+
bracketSpacing?: boolean;
|
|
30
|
+
|
|
31
|
+
/** Whether to hug the closing bracket of multiline HTML/JSX tags to the end of the last line. Defaults to false. */
|
|
32
|
+
bracketSameLine?: boolean;
|
|
33
|
+
|
|
34
|
+
/** Attribute position style. Defaults to false. */
|
|
35
|
+
singleAttributePerLine?: boolean;
|
|
36
|
+
|
|
37
|
+
/** Whether to expand object and array literals to multiple lines. Defaults to "auto". */
|
|
38
|
+
objectWrap?: "preserve" | "collapse";
|
|
39
|
+
|
|
40
|
+
/** Controls the position of operators in binary expressions. Defaults to "end". */
|
|
41
|
+
experimentalOperatorPosition?: "start" | "end";
|
|
42
|
+
|
|
43
|
+
/** Try prettier's new ternary formatting before it becomes the default behavior. Defaults to false. */
|
|
44
|
+
experimentalTernaries?: boolean;
|
|
45
|
+
|
|
46
|
+
/** Enable formatting for embedded languages (e.g., CSS, SQL, GraphQL) within template literals. Defaults to "auto". */
|
|
47
|
+
embeddedLanguageFormatting?: "auto" | "off";
|
|
48
|
+
|
|
49
|
+
/** Sort import statements. By default disabled. */
|
|
50
|
+
experimentalSortImports?: SortImportsOptions;
|
|
51
|
+
|
|
52
|
+
/** Enable Tailwind CSS class sorting in JSX class/className attributes. Defaults to None (disabled). */
|
|
53
|
+
experimentalTailwindcss?: TailwindcssOptions;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Options for sorting import statements. */
|
|
57
|
+
export interface SortImportsOptions {
|
|
58
|
+
/** Partition imports by newlines. Default is `false`. */
|
|
59
|
+
partitionByNewline?: boolean;
|
|
60
|
+
|
|
61
|
+
/** Partition imports by comments. Default is `false`. */
|
|
62
|
+
partitionByComment?: boolean;
|
|
63
|
+
|
|
64
|
+
/** Sort side effects imports. Default is `false`. */
|
|
65
|
+
sortSideEffects?: boolean;
|
|
66
|
+
|
|
67
|
+
/** Sort order (asc or desc). Default is ascending ("asc"). */
|
|
68
|
+
order?: "asc" | "desc";
|
|
69
|
+
|
|
70
|
+
/** Ignore case when sorting. Default is `true`. */
|
|
71
|
+
ignoreCase?: boolean;
|
|
72
|
+
|
|
73
|
+
/** Whether to insert blank lines between different import groups. Default is `true`. */
|
|
74
|
+
newlinesBetween?: boolean;
|
|
75
|
+
|
|
76
|
+
/** Prefixes for internal imports. Defaults to `["~/", "@/"]`. */
|
|
77
|
+
internalPattern?: string[];
|
|
78
|
+
|
|
79
|
+
/** Groups configuration for organizing imports. */
|
|
80
|
+
groups?: string[][];
|
|
81
|
+
|
|
82
|
+
/** Define your own groups for matching very specific imports. */
|
|
83
|
+
customGroups?: CustomGroupDefinition[];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Custom group definition for sort imports. */
|
|
87
|
+
export interface CustomGroupDefinition {
|
|
88
|
+
/** The name of the custom group. */
|
|
89
|
+
groupName: string;
|
|
90
|
+
|
|
91
|
+
/** Patterns to match import source names against. */
|
|
92
|
+
elementNamePattern: string[];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Options for Tailwind CSS class sorting. */
|
|
96
|
+
export interface TailwindcssOptions {
|
|
97
|
+
/** Path to your Tailwind CSS configuration file (v3). Default: `"./tailwind.config.js"` */
|
|
98
|
+
config?: string;
|
|
99
|
+
|
|
100
|
+
/** Path to your Tailwind CSS stylesheet (v4). Example: `"./src/app.css"` */
|
|
101
|
+
stylesheet?: string;
|
|
102
|
+
|
|
103
|
+
/** List of custom function names that contain Tailwind CSS classes. Example: `["clsx", "cn", "cva", "tw"]` */
|
|
104
|
+
functions?: string[];
|
|
105
|
+
|
|
106
|
+
/** List of additional attributes to sort (beyond `class` and `className`). Example: `["myClassProp", ":class"]` */
|
|
107
|
+
attributes?: string[];
|
|
108
|
+
|
|
109
|
+
/** Preserve whitespace around classes. Default: `false` */
|
|
110
|
+
preserveWhitespace?: boolean;
|
|
111
|
+
|
|
112
|
+
/** Preserve duplicate classes. Default: `false` */
|
|
113
|
+
preserveDuplicates?: boolean;
|
|
114
|
+
}
|
package/oxc_fmt.d.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM formatter for JavaScript/TypeScript using OXC (experimental).
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { format } from "@wasm-fmt/oxc_fmt";
|
|
7
|
+
*
|
|
8
|
+
* const input = "const x=1";
|
|
9
|
+
* const output = format(input, "index.js");
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { Config } from "./options.d.ts";
|
|
16
|
+
|
|
1
17
|
/* tslint:disable */
|
|
2
18
|
/* eslint-disable */
|
|
3
19
|
|
|
4
|
-
export interface Config extends LayoutConfig {
|
|
5
|
-
/**
|
|
6
|
-
* See {@link https://oxc.rs/docs/guide/usage/formatter/config.html}
|
|
7
|
-
* See {@link https://prettier.io/docs/options}
|
|
8
|
-
*/
|
|
9
|
-
[other: string]: any;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
20
|
type Mod = "" | "m" | "c";
|
|
14
21
|
type Lang = "j" | "t";
|
|
15
22
|
type X = "" | "x";
|
|
@@ -17,47 +24,3 @@ type X = "" | "x";
|
|
|
17
24
|
export type Filename = `index.${Mod}${Lang}s${X}` | `index.d.${Mod}ts${X}` | (string & {});
|
|
18
25
|
|
|
19
26
|
export function format(code: string, filename: Filename, config?: Config): string;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
interface LayoutConfig {
|
|
24
|
-
indentStyle?: "tab" | "space";
|
|
25
|
-
indentWidth?: number;
|
|
26
|
-
lineWidth?: number;
|
|
27
|
-
lineEnding?: "lf" | "crlf";
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
32
|
-
|
|
33
|
-
export interface InitOutput {
|
|
34
|
-
readonly memory: WebAssembly.Memory;
|
|
35
|
-
readonly format: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
36
|
-
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
37
|
-
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
38
|
-
readonly __wbindgen_export3: (a: number) => void;
|
|
39
|
-
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
40
|
-
readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Instantiates the given `module`, which can either be bytes or
|
|
47
|
-
* a precompiled `WebAssembly.Module`.
|
|
48
|
-
*
|
|
49
|
-
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
50
|
-
*
|
|
51
|
-
* @returns {InitOutput}
|
|
52
|
-
*/
|
|
53
|
-
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
57
|
-
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
58
|
-
*
|
|
59
|
-
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
60
|
-
*
|
|
61
|
-
* @returns {Promise<InitOutput>}
|
|
62
|
-
*/
|
|
63
|
-
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|