worsier 2.0.0 → 2.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 +20 -5
- package/configuration_schema.json +14 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
# Worsier
|
|
2
2
|
|
|
3
|
-
A focused JavaScript, TypeScript, JSX, and TSX formatter powered by Rust. It formats static imports
|
|
4
|
-
and the boundaries around runtime variable declarations while preserving
|
|
5
|
-
|
|
3
|
+
A focused JavaScript, TypeScript, JSX, and TSX formatter powered by Rust. It formats static imports,
|
|
4
|
+
trailing commas, and the boundaries around runtime variable declarations while preserving source
|
|
5
|
+
text outside the enabled rules.
|
|
6
6
|
Node.js 24.0.0 or newer is required.
|
|
7
7
|
Prebuilt Windows x64 binaries are temporarily unavailable while
|
|
8
8
|
[npm package publication is restored](https://github.com/Perdolique/worsier/issues/11).
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
11
|
pnpm add -D worsier
|
|
12
|
-
pnpm exec worsier --init
|
|
13
12
|
pnpm exec worsier --check .
|
|
14
13
|
pnpm exec worsier --write .
|
|
15
14
|
```
|
|
16
15
|
|
|
16
|
+
The CLI uses its opinionated defaults without a configuration file. An optional `worsier.jsonc`
|
|
17
|
+
can override them; run `pnpm exec worsier --init` to create the complete typed configuration.
|
|
18
|
+
|
|
17
19
|
```js
|
|
18
20
|
import { format } from 'worsier'
|
|
19
21
|
|
|
20
|
-
const output = await format('example.ts', "import{answer,type Value}from'pkg'"
|
|
22
|
+
const output = await format('example.ts', "import{answer,type Value}from'pkg'")
|
|
21
23
|
```
|
|
24
|
+
|
|
25
|
+
Pass an optional third `FormatConfig` argument to override the programmatic defaults. The
|
|
26
|
+
programmatic API does not discover configuration files.
|
|
27
|
+
|
|
28
|
+
## Broader alternatives
|
|
29
|
+
|
|
30
|
+
[Prettier](https://prettier.io/docs/) is a mature opinionated formatter that prints the complete
|
|
31
|
+
source, while [Oxfmt](https://oxc.rs/docs/guide/usage/formatter.html) is a fast,
|
|
32
|
+
Prettier-compatible formatter with broader language and formatting coverage. Both provide selected
|
|
33
|
+
configuration options, including [Prettier](https://prettier.io/docs/options#trailing-commas) and
|
|
34
|
+
[Oxfmt](https://oxc.rs/docs/guide/usage/formatter/config-file-reference#trailingcomma)
|
|
35
|
+
trailing-comma modes. Worsier instead focuses on independently configurable source-rewrite rules
|
|
36
|
+
and preserves text outside the selected rules.
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"statementSpacing": {
|
|
30
30
|
"imports": "separate",
|
|
31
31
|
"variableDeclarations": "separate"
|
|
32
|
-
}
|
|
32
|
+
},
|
|
33
|
+
"trailingCommas": "never"
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
"verifyAst": {
|
|
@@ -52,6 +53,10 @@
|
|
|
52
53
|
"imports": "separate",
|
|
53
54
|
"variableDeclarations": "separate"
|
|
54
55
|
}
|
|
56
|
+
},
|
|
57
|
+
"trailingCommas": {
|
|
58
|
+
"$ref": "#/$defs/TrailingCommaMode",
|
|
59
|
+
"default": "never"
|
|
55
60
|
}
|
|
56
61
|
},
|
|
57
62
|
"additionalProperties": false
|
|
@@ -77,6 +82,14 @@
|
|
|
77
82
|
"compact",
|
|
78
83
|
"off"
|
|
79
84
|
]
|
|
85
|
+
},
|
|
86
|
+
"TrailingCommaMode": {
|
|
87
|
+
"type": "string",
|
|
88
|
+
"enum": [
|
|
89
|
+
"always",
|
|
90
|
+
"never",
|
|
91
|
+
"off"
|
|
92
|
+
]
|
|
80
93
|
}
|
|
81
94
|
}
|
|
82
95
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { FormatConfig } from './types.js';
|
|
2
2
|
export type { FormatConfig } from './types.js';
|
|
3
|
-
export declare function format(fileName: string, sourceText: string, config
|
|
3
|
+
export declare function format(fileName: string, sourceText: string, config?: FormatConfig): Promise<string>;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { loadBinding } from './binding.js';
|
|
2
|
-
export async function format(fileName, sourceText, config) {
|
|
2
|
+
export async function format(fileName, sourceText, config = {}) {
|
|
3
3
|
const configJson = JSON.stringify(config);
|
|
4
4
|
try {
|
|
5
5
|
return await loadBinding().format(fileName, sourceText, configJson);
|
package/dist/types.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface FormatConfig {
|
|
|
8
8
|
export interface RulesConfig {
|
|
9
9
|
importLayout?: boolean;
|
|
10
10
|
statementSpacing?: StatementSpacingConfig;
|
|
11
|
+
trailingCommas?: 'always' | 'never' | 'off';
|
|
11
12
|
}
|
|
12
13
|
export interface StatementSpacingConfig {
|
|
13
14
|
imports?: 'separate' | 'compact' | 'off';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "worsier",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "A focused JavaScript and TypeScript import and
|
|
3
|
+
"version": "2.2.0",
|
|
4
|
+
"description": "A focused JavaScript and TypeScript import, trailing-comma, and statement-boundary formatter powered by Rust",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -48,13 +48,13 @@
|
|
|
48
48
|
]
|
|
49
49
|
},
|
|
50
50
|
"optionalDependencies": {
|
|
51
|
-
"worsier-darwin-arm64": "2.
|
|
52
|
-
"worsier-win32-arm64-msvc": "2.
|
|
53
|
-
"worsier-linux-arm64-gnu": "2.
|
|
54
|
-
"worsier-linux-arm64-musl": "2.
|
|
55
|
-
"worsier-darwin-x64": "2.
|
|
56
|
-
"worsier-linux-x64-gnu": "2.
|
|
57
|
-
"worsier-linux-x64-musl": "2.
|
|
51
|
+
"worsier-darwin-arm64": "2.2.0",
|
|
52
|
+
"worsier-win32-arm64-msvc": "2.2.0",
|
|
53
|
+
"worsier-linux-arm64-gnu": "2.2.0",
|
|
54
|
+
"worsier-linux-arm64-musl": "2.2.0",
|
|
55
|
+
"worsier-darwin-x64": "2.2.0",
|
|
56
|
+
"worsier-linux-x64-gnu": "2.2.0",
|
|
57
|
+
"worsier-linux-x64-musl": "2.2.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/node": "26.2.0",
|