oxfmt 0.18.0 → 0.19.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.
@@ -58,21 +58,31 @@
58
58
  ]
59
59
  },
60
60
  "ignoreCase": {
61
- "default": true,
62
- "type": "boolean"
61
+ "description": "Ignore case when sorting. (Default: `true`)",
62
+ "markdownDescription": "Ignore case when sorting. (Default: `true`)",
63
+ "type": [
64
+ "boolean",
65
+ "null"
66
+ ]
63
67
  },
64
68
  "internalPattern": {
69
+ "description": "Glob patterns to identify internal imports.",
65
70
  "items": {
66
71
  "type": "string"
67
72
  },
73
+ "markdownDescription": "Glob patterns to identify internal imports.",
68
74
  "type": [
69
75
  "array",
70
76
  "null"
71
77
  ]
72
78
  },
73
79
  "newlinesBetween": {
74
- "default": true,
75
- "type": "boolean"
80
+ "description": "Add newlines between import groups. (Default: `true`)",
81
+ "markdownDescription": "Add newlines between import groups. (Default: `true`)",
82
+ "type": [
83
+ "boolean",
84
+ "null"
85
+ ]
76
86
  },
77
87
  "order": {
78
88
  "anyOf": [
@@ -82,19 +92,33 @@
82
92
  {
83
93
  "type": "null"
84
94
  }
85
- ]
95
+ ],
96
+ "description": "Sort order. (Default: `\"asc\"`)",
97
+ "markdownDescription": "Sort order. (Default: `\"asc\"`)"
86
98
  },
87
99
  "partitionByComment": {
88
- "default": false,
89
- "type": "boolean"
100
+ "description": "Partition imports by comments. (Default: `false`)",
101
+ "markdownDescription": "Partition imports by comments. (Default: `false`)",
102
+ "type": [
103
+ "boolean",
104
+ "null"
105
+ ]
90
106
  },
91
107
  "partitionByNewline": {
92
- "default": false,
93
- "type": "boolean"
108
+ "description": "Partition imports by newlines. (Default: `false`)",
109
+ "markdownDescription": "Partition imports by newlines. (Default: `false`)",
110
+ "type": [
111
+ "boolean",
112
+ "null"
113
+ ]
94
114
  },
95
115
  "sortSideEffects": {
96
- "default": false,
97
- "type": "boolean"
116
+ "description": "Sort side-effect imports. (Default: `false`)",
117
+ "markdownDescription": "Sort side-effect imports. (Default: `false`)",
118
+ "type": [
119
+ "boolean",
120
+ "null"
121
+ ]
98
122
  }
99
123
  },
100
124
  "type": "object"
@@ -115,8 +139,8 @@
115
139
  "type": "string"
116
140
  }
117
141
  },
118
- "description": "Configuration options for the Oxfmt.\nMost options are the same as Prettier's options.\nSee also <https://prettier.io/docs/options>\nBut some options are our own extensions.",
119
- "markdownDescription": "Configuration options for the Oxfmt.\nMost options are the same as Prettier's options.\nSee also <https://prettier.io/docs/options>\nBut some options are our own extensions.",
142
+ "description": "Configuration options for the Oxfmt.\n\nMost options are the same as Prettier's options.\nSee also <https://prettier.io/docs/options>\n\nIn addition, some options are our own extensions.",
143
+ "markdownDescription": "Configuration options for the Oxfmt.\n\nMost options are the same as Prettier's options.\nSee also <https://prettier.io/docs/options>\n\nIn addition, some options are our own extensions.",
120
144
  "properties": {
121
145
  "arrowParens": {
122
146
  "anyOf": [
@@ -1,5 +1,4 @@
1
1
  import { createRequire } from "node:module";
2
- import Tinypool from "tinypool";
3
2
 
4
3
  //#region src-js/bindings.js
5
4
  const require = createRequire(import.meta.url);
@@ -59,7 +58,7 @@ function requireNative() {
59
58
  try {
60
59
  const binding = require("@oxfmt/android-arm64");
61
60
  const bindingPackageVersion = require("@oxfmt/android-arm64/package.json").version;
62
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
61
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
63
62
  return binding;
64
63
  } catch (e) {
65
64
  loadErrors.push(e);
@@ -73,7 +72,7 @@ function requireNative() {
73
72
  try {
74
73
  const binding = require("@oxfmt/android-arm-eabi");
75
74
  const bindingPackageVersion = require("@oxfmt/android-arm-eabi/package.json").version;
76
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
75
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
77
76
  return binding;
78
77
  } catch (e) {
79
78
  loadErrors.push(e);
@@ -88,7 +87,7 @@ function requireNative() {
88
87
  try {
89
88
  const binding = require("@oxfmt/win32-x64-gnu");
90
89
  const bindingPackageVersion = require("@oxfmt/win32-x64-gnu/package.json").version;
91
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
90
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
92
91
  return binding;
93
92
  } catch (e) {
94
93
  loadErrors.push(e);
@@ -102,7 +101,7 @@ function requireNative() {
102
101
  try {
103
102
  const binding = require("@oxfmt/win32-x64");
104
103
  const bindingPackageVersion = require("@oxfmt/win32-x64/package.json").version;
105
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
104
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
106
105
  return binding;
107
106
  } catch (e) {
108
107
  loadErrors.push(e);
@@ -117,7 +116,7 @@ function requireNative() {
117
116
  try {
118
117
  const binding = require("@oxfmt/win32-ia32");
119
118
  const bindingPackageVersion = require("@oxfmt/win32-ia32/package.json").version;
120
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
119
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
121
120
  return binding;
122
121
  } catch (e) {
123
122
  loadErrors.push(e);
@@ -131,7 +130,7 @@ function requireNative() {
131
130
  try {
132
131
  const binding = require("@oxfmt/win32-arm64");
133
132
  const bindingPackageVersion = require("@oxfmt/win32-arm64/package.json").version;
134
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
133
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
135
134
  return binding;
136
135
  } catch (e) {
137
136
  loadErrors.push(e);
@@ -146,7 +145,7 @@ function requireNative() {
146
145
  try {
147
146
  const binding = require("@oxfmt/darwin-universal");
148
147
  const bindingPackageVersion = require("@oxfmt/darwin-universal/package.json").version;
149
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
148
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
150
149
  return binding;
151
150
  } catch (e) {
152
151
  loadErrors.push(e);
@@ -160,7 +159,7 @@ function requireNative() {
160
159
  try {
161
160
  const binding = require("@oxfmt/darwin-x64");
162
161
  const bindingPackageVersion = require("@oxfmt/darwin-x64/package.json").version;
163
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
162
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
164
163
  return binding;
165
164
  } catch (e) {
166
165
  loadErrors.push(e);
@@ -174,7 +173,7 @@ function requireNative() {
174
173
  try {
175
174
  const binding = require("@oxfmt/darwin-arm64");
176
175
  const bindingPackageVersion = require("@oxfmt/darwin-arm64/package.json").version;
177
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
176
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
178
177
  return binding;
179
178
  } catch (e) {
180
179
  loadErrors.push(e);
@@ -189,7 +188,7 @@ function requireNative() {
189
188
  try {
190
189
  const binding = require("@oxfmt/freebsd-x64");
191
190
  const bindingPackageVersion = require("@oxfmt/freebsd-x64/package.json").version;
192
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
191
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
193
192
  return binding;
194
193
  } catch (e) {
195
194
  loadErrors.push(e);
@@ -203,7 +202,7 @@ function requireNative() {
203
202
  try {
204
203
  const binding = require("@oxfmt/freebsd-arm64");
205
204
  const bindingPackageVersion = require("@oxfmt/freebsd-arm64/package.json").version;
206
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
205
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
207
206
  return binding;
208
207
  } catch (e) {
209
208
  loadErrors.push(e);
@@ -218,7 +217,7 @@ function requireNative() {
218
217
  try {
219
218
  const binding = require("@oxfmt/linux-x64-musl");
220
219
  const bindingPackageVersion = require("@oxfmt/linux-x64-musl/package.json").version;
221
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
220
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
222
221
  return binding;
223
222
  } catch (e) {
224
223
  loadErrors.push(e);
@@ -232,7 +231,7 @@ function requireNative() {
232
231
  try {
233
232
  const binding = require("@oxfmt/linux-x64-gnu");
234
233
  const bindingPackageVersion = require("@oxfmt/linux-x64-gnu/package.json").version;
235
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
234
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
236
235
  return binding;
237
236
  } catch (e) {
238
237
  loadErrors.push(e);
@@ -247,7 +246,7 @@ function requireNative() {
247
246
  try {
248
247
  const binding = require("@oxfmt/linux-arm64-musl");
249
248
  const bindingPackageVersion = require("@oxfmt/linux-arm64-musl/package.json").version;
250
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
249
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
251
250
  return binding;
252
251
  } catch (e) {
253
252
  loadErrors.push(e);
@@ -261,7 +260,7 @@ function requireNative() {
261
260
  try {
262
261
  const binding = require("@oxfmt/linux-arm64-gnu");
263
262
  const bindingPackageVersion = require("@oxfmt/linux-arm64-gnu/package.json").version;
264
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
263
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
265
264
  return binding;
266
265
  } catch (e) {
267
266
  loadErrors.push(e);
@@ -276,7 +275,7 @@ function requireNative() {
276
275
  try {
277
276
  const binding = require("@oxfmt/linux-arm-musleabihf");
278
277
  const bindingPackageVersion = require("@oxfmt/linux-arm-musleabihf/package.json").version;
279
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
278
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
280
279
  return binding;
281
280
  } catch (e) {
282
281
  loadErrors.push(e);
@@ -290,7 +289,7 @@ function requireNative() {
290
289
  try {
291
290
  const binding = require("@oxfmt/linux-arm-gnueabihf");
292
291
  const bindingPackageVersion = require("@oxfmt/linux-arm-gnueabihf/package.json").version;
293
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
292
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
294
293
  return binding;
295
294
  } catch (e) {
296
295
  loadErrors.push(e);
@@ -305,7 +304,7 @@ function requireNative() {
305
304
  try {
306
305
  const binding = require("@oxfmt/linux-loong64-musl");
307
306
  const bindingPackageVersion = require("@oxfmt/linux-loong64-musl/package.json").version;
308
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
307
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
309
308
  return binding;
310
309
  } catch (e) {
311
310
  loadErrors.push(e);
@@ -319,7 +318,7 @@ function requireNative() {
319
318
  try {
320
319
  const binding = require("@oxfmt/linux-loong64-gnu");
321
320
  const bindingPackageVersion = require("@oxfmt/linux-loong64-gnu/package.json").version;
322
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
321
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
323
322
  return binding;
324
323
  } catch (e) {
325
324
  loadErrors.push(e);
@@ -334,7 +333,7 @@ function requireNative() {
334
333
  try {
335
334
  const binding = require("@oxfmt/linux-riscv64-musl");
336
335
  const bindingPackageVersion = require("@oxfmt/linux-riscv64-musl/package.json").version;
337
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
336
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
338
337
  return binding;
339
338
  } catch (e) {
340
339
  loadErrors.push(e);
@@ -348,7 +347,7 @@ function requireNative() {
348
347
  try {
349
348
  const binding = require("@oxfmt/linux-riscv64-gnu");
350
349
  const bindingPackageVersion = require("@oxfmt/linux-riscv64-gnu/package.json").version;
351
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
350
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
352
351
  return binding;
353
352
  } catch (e) {
354
353
  loadErrors.push(e);
@@ -363,7 +362,7 @@ function requireNative() {
363
362
  try {
364
363
  const binding = require("@oxfmt/linux-ppc64-gnu");
365
364
  const bindingPackageVersion = require("@oxfmt/linux-ppc64-gnu/package.json").version;
366
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
365
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
367
366
  return binding;
368
367
  } catch (e) {
369
368
  loadErrors.push(e);
@@ -377,7 +376,7 @@ function requireNative() {
377
376
  try {
378
377
  const binding = require("@oxfmt/linux-s390x-gnu");
379
378
  const bindingPackageVersion = require("@oxfmt/linux-s390x-gnu/package.json").version;
380
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
379
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
381
380
  return binding;
382
381
  } catch (e) {
383
382
  loadErrors.push(e);
@@ -392,7 +391,7 @@ function requireNative() {
392
391
  try {
393
392
  const binding = require("@oxfmt/openharmony-arm64");
394
393
  const bindingPackageVersion = require("@oxfmt/openharmony-arm64/package.json").version;
395
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
394
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
396
395
  return binding;
397
396
  } catch (e) {
398
397
  loadErrors.push(e);
@@ -406,7 +405,7 @@ function requireNative() {
406
405
  try {
407
406
  const binding = require("@oxfmt/openharmony-x64");
408
407
  const bindingPackageVersion = require("@oxfmt/openharmony-x64/package.json").version;
409
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
408
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
410
409
  return binding;
411
410
  } catch (e) {
412
411
  loadErrors.push(e);
@@ -420,7 +419,7 @@ function requireNative() {
420
419
  try {
421
420
  const binding = require("@oxfmt/openharmony-arm");
422
421
  const bindingPackageVersion = require("@oxfmt/openharmony-arm/package.json").version;
423
- if (bindingPackageVersion !== "0.18.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.18.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
422
+ if (bindingPackageVersion !== "0.19.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") throw new Error(`Native binding package version mismatch, expected 0.19.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
424
423
  return binding;
425
424
  } catch (e) {
426
425
  loadErrors.push(e);
@@ -460,68 +459,7 @@ if (!nativeBinding) {
460
459
  }) });
461
460
  throw new Error(`Failed to load native binding`);
462
461
  }
463
- const { runCli } = nativeBinding;
462
+ const { Severity, format, runCli } = nativeBinding;
464
463
 
465
464
  //#endregion
466
- //#region src-js/prettier-proxy.ts
467
- let pool = null;
468
- /**
469
- * Setup Prettier configuration.
470
- * NOTE: Called from Rust via NAPI ThreadsafeFunction with FnArgs
471
- * @param configJSON - Prettier configuration as JSON string
472
- * @param numThreads - Number of worker threads to use (same as Rayon thread count)
473
- * @returns Array of loaded plugin's `languages` info
474
- * */
475
- async function setupConfig(configJSON, numThreads) {
476
- const workerData = { prettierConfig: JSON.parse(configJSON) };
477
- if (pool) throw new Error("`setupConfig()` has already been called");
478
- pool = new Tinypool({
479
- filename: new URL("./prettier-worker.js", import.meta.url).href,
480
- minThreads: numThreads,
481
- maxThreads: numThreads,
482
- workerData
483
- });
484
- return [];
485
- }
486
- const TAG_TO_PARSER = {
487
- css: "css",
488
- styled: "css",
489
- gql: "graphql",
490
- graphql: "graphql",
491
- html: "html",
492
- md: "markdown",
493
- markdown: "markdown"
494
- };
495
- /**
496
- * Format embedded code using Prettier.
497
- * NOTE: Called from Rust via NAPI ThreadsafeFunction with FnArgs
498
- * @param tagName - The template tag name (e.g., "css", "gql", "html")
499
- * @param code - The code to format
500
- * @returns Formatted code
501
- */
502
- async function formatEmbeddedCode(tagName, code) {
503
- const parser = TAG_TO_PARSER[tagName];
504
- if (!parser) return code;
505
- return pool.run({
506
- parser,
507
- code
508
- }, { name: "formatEmbeddedCode" });
509
- }
510
- /**
511
- * Format whole file content using Prettier.
512
- * NOTE: Called from Rust via NAPI ThreadsafeFunction with FnArgs
513
- * @param parserName - The parser name
514
- * @param fileName - The file name (e.g., "package.json")
515
- * @param code - The code to format
516
- * @returns Formatted code
517
- */
518
- async function formatFile(parserName, fileName, code) {
519
- return pool.run({
520
- parserName,
521
- fileName,
522
- code
523
- }, { name: "formatFile" });
524
- }
525
-
526
- //#endregion
527
- export { runCli as i, formatFile as n, setupConfig as r, formatEmbeddedCode as t };
465
+ export { runCli as n, format as t };
@@ -0,0 +1,38 @@
1
+ import { Options } from "prettier";
2
+
3
+ //#region src-js/libs/prettier.d.ts
4
+
5
+ /**
6
+ * Format xxx-in-js code snippets
7
+ *
8
+ * @returns Formatted code snippet
9
+ * TODO: In the future, this should return `Doc` instead of string,
10
+ * otherwise, we cannot calculate `printWidth` correctly.
11
+ */
12
+ declare function formatEmbeddedCode({
13
+ code,
14
+ tagName,
15
+ options
16
+ }: {
17
+ code: string;
18
+ tagName: string;
19
+ options: Options;
20
+ }): Promise<string>;
21
+ /**
22
+ * Format non-js file
23
+ *
24
+ * @returns Formatted code
25
+ */
26
+ declare function formatFile({
27
+ code,
28
+ parserName,
29
+ fileName,
30
+ options
31
+ }: {
32
+ code: string;
33
+ parserName: string;
34
+ fileName: string;
35
+ options: Options;
36
+ }): Promise<string>;
37
+ //#endregion
38
+ export { formatEmbeddedCode, formatFile };
@@ -0,0 +1,3 @@
1
+ import { n as formatFile, t as formatEmbeddedCode } from "./prettier-DrLdIo7u.js";
2
+
3
+ export { formatEmbeddedCode, formatFile };
package/dist/cli.js CHANGED
@@ -1,152 +1,46 @@
1
- import { i as runCli, n as formatFile, r as setupConfig, t as formatEmbeddedCode } from "./prettier-proxy-DtsR3p_O.js";
2
- import { join } from "node:path";
3
- import { readFile, stat, writeFile } from "node:fs/promises";
1
+ import { n as runCli } from "./bindings-BLpuw3L7.js";
2
+ import { r as resolvePlugins } from "./prettier-DrLdIo7u.js";
3
+ import Tinypool from "tinypool";
4
4
 
5
- //#region src-js/migration/shared.ts
6
- async function hasOxfmtrcFile(cwd) {
7
- return await isFile(join(cwd, ".oxfmtrc.json")) || await isFile(join(cwd, ".oxfmtrc.jsonc"));
8
- }
9
- const SCHEMA_RELATIVE_PATH = "./node_modules/oxfmt/configuration_schema.json";
10
- async function hasSchemaFile(cwd) {
11
- return await isFile(join(cwd, "node_modules/oxfmt/configuration_schema.json")) ? SCHEMA_RELATIVE_PATH : null;
12
- }
13
- async function createBlankOxfmtrcFile(cwd) {
14
- const config = {
15
- $schema: await hasSchemaFile(cwd),
16
- ignorePatterns: []
17
- };
18
- if (config.$schema === null) delete config.$schema;
19
- return config;
20
- }
21
- async function saveOxfmtrcFile(cwd, jsonStr) {
22
- await writeFile(join(cwd, ".oxfmtrc.json"), jsonStr + "\n", "utf8");
23
- }
24
- function exitWithError(message) {
25
- console.error(message);
26
- process.exitCode = 1;
27
- }
28
- async function isFile(path) {
29
- try {
30
- return (await stat(path)).isFile();
31
- } catch {
32
- return false;
33
- }
34
- }
35
-
36
- //#endregion
37
- //#region src-js/migration/init.ts
38
- /**
39
- * Run the `--init` command to scaffold a default `.oxfmtrc.json` file.
40
- */
41
- async function runInit() {
42
- const cwd = process.cwd();
43
- if (await hasOxfmtrcFile(cwd)) return exitWithError("Oxfmt configuration file already exists.");
44
- const oxfmtrc = await createBlankOxfmtrcFile(cwd);
45
- const jsonStr = JSON.stringify(oxfmtrc, null, 2);
46
- try {
47
- await saveOxfmtrcFile(cwd, jsonStr);
48
- console.log("Created `.oxfmtrc.json`.");
49
- } catch {
50
- return exitWithError("Failed to create `.oxfmtrc.json`.");
51
- }
52
- }
53
-
54
- //#endregion
55
- //#region src-js/migration/migrate-prettier.ts
56
- /**
57
- * Run the `--migrate prettier` command to migrate various Prettier's config to `.oxfmtrc.json` file.
58
- * https://prettier.io/docs/configuration
59
- */
60
- async function runMigratePrettier() {
61
- const cwd = process.cwd();
62
- if (await hasOxfmtrcFile(cwd)) return exitWithError("Oxfmt configuration file already exists.");
63
- const { resolveConfigFile, resolveConfig } = await import("./prettier-BAX-9y1Y.js");
64
- const prettierConfigPath = await resolveConfigFile(join(cwd, "dummy.js"));
65
- if (!prettierConfigPath) {
66
- console.log("No Prettier configuration file found.");
67
- const oxfmtrc$1 = await createBlankOxfmtrcFile(cwd);
68
- const jsonStr$1 = JSON.stringify(oxfmtrc$1, null, 2);
69
- try {
70
- await saveOxfmtrcFile(cwd, jsonStr$1);
71
- console.log("Created `.oxfmtrc.json` instead.");
72
- } catch {
73
- exitWithError("Failed to create `.oxfmtrc.json`.");
74
- }
75
- return;
76
- }
77
- let prettierConfig;
78
- try {
79
- prettierConfig = await resolveConfig(prettierConfigPath, { editorconfig: false });
80
- console.log("Found Prettier configuration at:", prettierConfigPath);
81
- } catch {
82
- return exitWithError(`Failed to parse: ${prettierConfigPath}`);
83
- }
84
- const oxfmtrc = await createBlankOxfmtrcFile(cwd);
85
- for (const [key, value] of Object.entries(prettierConfig ?? {})) {
86
- if (key === "overrides") {
87
- console.error(` - "overrides" is not supported, skipping...`);
88
- continue;
89
- }
90
- if (key === "plugins") {
91
- console.error(` - "plugins" is not supported yet, skipping...`);
92
- continue;
93
- }
94
- if (key === "endOfLine" && value === "auto") {
95
- console.error(` - "endOfLine: auto" is not supported, skipping...`);
96
- continue;
97
- }
98
- if (key === "experimentalTernaries" || key === "experimentalOperatorPosition") {
99
- console.error(` - "${key}" is not supported in JS/TS files yet`);
100
- continue;
101
- }
102
- oxfmtrc[key] = value;
103
- }
104
- if (typeof oxfmtrc.printWidth !== "number") {
105
- console.error(` - "printWidth" is not set in Prettier config, defaulting to 80 (Oxfmt default: 100)`);
106
- oxfmtrc.printWidth = 80;
107
- }
108
- if (oxfmtrc.embeddedLanguageFormatting !== "off") console.error(` - "embeddedLanguageFormatting" in JS/TS files is not fully supported yet`);
109
- const ignores = await resolvePrettierIgnore(cwd);
110
- if (0 < ignores.length) {
111
- oxfmtrc.ignorePatterns = ignores;
112
- console.log("Migrated ignore patterns from `.prettierignore`");
113
- }
114
- const jsonStr = JSON.stringify(oxfmtrc, null, 2);
115
- try {
116
- await saveOxfmtrcFile(cwd, jsonStr);
117
- console.log("Created `.oxfmtrc.json`.");
118
- } catch {
119
- return exitWithError("Failed to create `.oxfmtrc.json`.");
120
- }
121
- }
122
- async function resolvePrettierIgnore(cwd) {
123
- const ignores = [];
124
- try {
125
- const lines = (await readFile(join(cwd, ".prettierignore"), "utf8")).split("\n");
126
- for (let line of lines) {
127
- line = line.trim();
128
- if (line === "" || line.startsWith("#")) continue;
129
- ignores.push(line);
130
- }
131
- } catch {}
132
- return ignores;
5
+ //#region src-js/cli/worker-proxy.ts
6
+ let pool = null;
7
+ async function initExternalFormatter(numThreads) {
8
+ pool = new Tinypool({
9
+ filename: new URL("./cli-worker.js", import.meta.url).href,
10
+ minThreads: numThreads,
11
+ maxThreads: numThreads
12
+ });
13
+ return resolvePlugins();
14
+ }
15
+ async function formatEmbeddedCode(options, tagName, code) {
16
+ return pool.run({
17
+ options,
18
+ code,
19
+ tagName
20
+ }, { name: "formatEmbeddedCode" });
21
+ }
22
+ async function formatFile(options, parserName, fileName, code) {
23
+ return pool.run({
24
+ options,
25
+ code,
26
+ fileName,
27
+ parserName
28
+ }, { name: "formatFile" });
133
29
  }
134
30
 
135
31
  //#endregion
136
32
  //#region src-js/cli.ts
137
33
  (async () => {
138
- const [mode, exitCode] = await runCli(process.argv.slice(2), setupConfig, formatEmbeddedCode, formatFile);
139
- switch (mode) {
140
- case "init":
141
- await runInit();
142
- break;
143
- case "migrate:prettier":
144
- await runMigratePrettier();
145
- break;
146
- default:
147
- if (exitCode) process.exitCode = exitCode;
148
- break;
34
+ const [mode, exitCode] = await runCli(process.argv.slice(2), initExternalFormatter, formatEmbeddedCode, formatFile);
35
+ if (mode === "init") {
36
+ await import("./init-CJps11re.js").then((m) => m.runInit());
37
+ return;
38
+ }
39
+ if (mode === "migrate:prettier") {
40
+ await import("./migrate-prettier-WznNXMZY.js").then((m) => m.runMigratePrettier());
41
+ return;
149
42
  }
43
+ process.exitCode = exitCode;
150
44
  })();
151
45
 
152
46
  //#endregion
package/dist/index.d.ts CHANGED
@@ -1,46 +1,108 @@
1
1
  //#region src-js/bindings.d.ts
2
- /* auto-generated by NAPI-RS */
3
- /* eslint-disable */
4
- /**
5
- * NAPI entry point.
6
- *
7
- * JS side passes in:
8
- * 1. `args`: Command line arguments (process.argv.slice(2))
9
- * 2. `setup_config_cb`: Callback to setup Prettier config
10
- * 3. `format_embedded_cb`: Callback to format embedded code in templates
11
- * 4. `format_file_cb`: Callback to format files
12
- *
13
- * Returns a tuple of `[mode, exitCode]`:
14
- * - `mode`: If main logic will run in JS side, use this to indicate which mode
15
- * - `exitCode`: If main logic already ran in Rust side, return the exit code
16
- */
17
- declare function runCli(args: Array<string>, setupConfigCb: (configJSON: string, numThreads: number) => Promise<string[]>, formatEmbeddedCb: (tagName: string, code: string) => Promise<string>, formatFileCb: (parserName: string, fileName: string, code: string) => Promise<string>): Promise<[string, number | undefined | null]>;
2
+
3
+ interface ErrorLabel {
4
+ message: string | null;
5
+ start: number;
6
+ end: number;
7
+ }
8
+ interface OxcError {
9
+ severity: Severity;
10
+ message: string;
11
+ labels: Array<ErrorLabel>;
12
+ helpMessage: string | null;
13
+ codeframe: string | null;
14
+ }
15
+ declare const enum Severity {
16
+ Error = 'Error',
17
+ Warning = 'Warning',
18
+ Advice = 'Advice',
19
+ }
20
+ interface FormatResult {
21
+ /** The formatted code. */
22
+ code: string;
23
+ /** Parse and format errors. */
24
+ errors: Array<OxcError>;
25
+ }
18
26
  //#endregion
19
- //#region src-js/prettier-proxy.d.ts
27
+ //#region src-js/index.d.ts
20
28
  /**
21
- * Setup Prettier configuration.
22
- * NOTE: Called from Rust via NAPI ThreadsafeFunction with FnArgs
23
- * @param configJSON - Prettier configuration as JSON string
24
- * @param numThreads - Number of worker threads to use (same as Rayon thread count)
25
- * @returns Array of loaded plugin's `languages` info
26
- * */
27
- declare function setupConfig(configJSON: string, numThreads: number): Promise<string[]>;
29
+ * Format the given source text according to the specified options.
30
+ */
31
+ declare function format(fileName: string, sourceText: string, options?: FormatOptions): Promise<FormatResult>;
28
32
  /**
29
- * Format embedded code using Prettier.
30
- * NOTE: Called from Rust via NAPI ThreadsafeFunction with FnArgs
31
- * @param tagName - The template tag name (e.g., "css", "gql", "html")
32
- * @param code - The code to format
33
- * @returns Formatted code
33
+ * Configuration options for the Oxfmt.
34
+ *
35
+ * Most options are the same as Prettier's options.
36
+ * See also <https://prettier.io/docs/options>
37
+ *
38
+ * In addition, some options are our own extensions.
34
39
  */
35
- declare function formatEmbeddedCode(tagName: string, code: string): Promise<string>;
40
+ type FormatOptions = {
41
+ /** Use tabs for indentation or spaces. (Default: `false`) */
42
+ useTabs?: boolean;
43
+ /** Number of spaces per indentation level. (Default: `2`) */
44
+ tabWidth?: number;
45
+ /** Which end of line characters to apply. (Default: `"lf"`) */
46
+ endOfLine?: "lf" | "crlf" | "cr";
47
+ /** The line length that the printer will wrap on. (Default: `100`) */
48
+ printWidth?: number;
49
+ /** Use single quotes instead of double quotes. (Default: `false`) */
50
+ singleQuote?: boolean;
51
+ /** Use single quotes instead of double quotes in JSX. (Default: `false`) */
52
+ jsxSingleQuote?: boolean;
53
+ /** Change when properties in objects are quoted. (Default: `"as-needed"`) */
54
+ quoteProps?: "as-needed" | "consistent" | "preserve";
55
+ /** Print trailing commas wherever possible. (Default: `"all"`) */
56
+ trailingComma?: "all" | "es5" | "none";
57
+ /** Print semicolons at the ends of statements. (Default: `true`) */
58
+ semi?: boolean;
59
+ /** Include parentheses around a sole arrow function parameter. (Default: `"always"`) */
60
+ arrowParens?: "always" | "avoid";
61
+ /** Print spaces between brackets in object literals. (Default: `true`) */
62
+ bracketSpacing?: boolean;
63
+ /**
64
+ * Put the `>` of a multi-line JSX element at the end of the last line
65
+ * instead of being alone on the next line. (Default: `false`)
66
+ */
67
+ bracketSameLine?: boolean;
68
+ /**
69
+ * How to wrap object literals when they could fit on one line or span multiple lines. (Default: `"preserve"`)
70
+ * NOTE: In addition to Prettier's `"preserve"` and `"collapse"`, we also support `"always"`.
71
+ */
72
+ objectWrap?: "preserve" | "collapse" | "always";
73
+ /** Put each attribute on a new line in JSX. (Default: `false`) */
74
+ singleAttributePerLine?: boolean;
75
+ /** Control whether formats quoted code embedded in the file. (Default: `"auto"`) */
76
+ embeddedLanguageFormatting?: "auto" | "off";
77
+ /** Experimental: Sort import statements. Disabled by default. */
78
+ experimentalSortImports?: SortImportsOptions;
79
+ /** Experimental: Sort `package.json` keys. (Default: `true`) */
80
+ experimentalSortPackageJson?: boolean;
81
+ } & Record<string, unknown>;
36
82
  /**
37
- * Format whole file content using Prettier.
38
- * NOTE: Called from Rust via NAPI ThreadsafeFunction with FnArgs
39
- * @param parserName - The parser name
40
- * @param fileName - The file name (e.g., "package.json")
41
- * @param code - The code to format
42
- * @returns Formatted code
83
+ * Configuration options for sort imports.
43
84
  */
44
- declare function formatFile(parserName: string, fileName: string, code: string): Promise<string>;
85
+ type SortImportsOptions = {
86
+ /** Partition imports by newlines. (Default: `false`) */
87
+ partitionByNewline?: boolean;
88
+ /** Partition imports by comments. (Default: `false`) */
89
+ partitionByComment?: boolean;
90
+ /** Sort side-effect imports. (Default: `false`) */
91
+ sortSideEffects?: boolean;
92
+ /** Sort order. (Default: `"asc"`) */
93
+ order?: "asc" | "desc";
94
+ /** Ignore case when sorting. (Default: `true`) */
95
+ ignoreCase?: boolean;
96
+ /** Add newlines between import groups. (Default: `true`) */
97
+ newlinesBetween?: boolean;
98
+ /** Glob patterns to identify internal imports. */
99
+ internalPattern?: string[];
100
+ /**
101
+ * Custom groups configuration for organizing imports.
102
+ * Each array element represents a group, and multiple group names in the same array are treated as one.
103
+ * Accepts both `string` and `string[]` as group elements.
104
+ */
105
+ groups?: (string | string[])[];
106
+ };
45
107
  //#endregion
46
- export { formatEmbeddedCode, formatFile, runCli, setupConfig };
108
+ export { FormatOptions, SortImportsOptions, format };
package/dist/index.js CHANGED
@@ -1,3 +1,24 @@
1
- import { i as runCli, n as formatFile, r as setupConfig, t as formatEmbeddedCode } from "./prettier-proxy-DtsR3p_O.js";
1
+ import { t as format$1 } from "./bindings-BLpuw3L7.js";
2
+ import { n as formatFile, r as resolvePlugins, t as formatEmbeddedCode } from "./prettier-DrLdIo7u.js";
2
3
 
3
- export { formatEmbeddedCode, formatFile, runCli, setupConfig };
4
+ //#region src-js/index.ts
5
+ /**
6
+ * Format the given source text according to the specified options.
7
+ */
8
+ async function format(fileName, sourceText, options) {
9
+ if (typeof fileName !== "string") throw new TypeError("`fileName` must be a string");
10
+ if (typeof sourceText !== "string") throw new TypeError("`sourceText` must be a string");
11
+ return format$1(fileName, sourceText, options ?? {}, resolvePlugins, (options$1, tagName, code) => formatEmbeddedCode({
12
+ options: options$1,
13
+ tagName,
14
+ code
15
+ }), (options$1, parserName, fileName$1, code) => formatFile({
16
+ options: options$1,
17
+ parserName,
18
+ fileName: fileName$1,
19
+ code
20
+ }));
21
+ }
22
+
23
+ //#endregion
24
+ export { format };
@@ -0,0 +1,21 @@
1
+ import { i as saveOxfmtrcFile, n as exitWithError, r as hasOxfmtrcFile, t as createBlankOxfmtrcFile } from "./shared-WqBdMVAn.js";
2
+
3
+ //#region src-js/cli/migration/init.ts
4
+ /**
5
+ * Run the `--init` command to scaffold a default `.oxfmtrc.json` file.
6
+ */
7
+ async function runInit() {
8
+ const cwd = process.cwd();
9
+ if (await hasOxfmtrcFile(cwd)) return exitWithError("Oxfmt configuration file already exists.");
10
+ const oxfmtrc = await createBlankOxfmtrcFile(cwd);
11
+ const jsonStr = JSON.stringify(oxfmtrc, null, 2);
12
+ try {
13
+ await saveOxfmtrcFile(cwd, jsonStr);
14
+ console.log("Created `.oxfmtrc.json`.");
15
+ } catch {
16
+ return exitWithError("Failed to create `.oxfmtrc.json`.");
17
+ }
18
+ }
19
+
20
+ //#endregion
21
+ export { runInit };
@@ -0,0 +1,85 @@
1
+ import { i as saveOxfmtrcFile, n as exitWithError, r as hasOxfmtrcFile, t as createBlankOxfmtrcFile } from "./shared-WqBdMVAn.js";
2
+ import { join } from "node:path";
3
+ import { readFile } from "node:fs/promises";
4
+
5
+ //#region src-js/cli/migration/migrate-prettier.ts
6
+ /**
7
+ * Run the `--migrate prettier` command to migrate various Prettier's config to `.oxfmtrc.json` file.
8
+ * https://prettier.io/docs/configuration
9
+ */
10
+ async function runMigratePrettier() {
11
+ const cwd = process.cwd();
12
+ if (await hasOxfmtrcFile(cwd)) return exitWithError("Oxfmt configuration file already exists.");
13
+ const { resolveConfigFile, resolveConfig } = await import("./prettier-BnljmOi5.js");
14
+ const prettierConfigPath = await resolveConfigFile(join(cwd, "dummy.js"));
15
+ if (!prettierConfigPath) {
16
+ console.log("No Prettier configuration file found.");
17
+ const oxfmtrc$1 = await createBlankOxfmtrcFile(cwd);
18
+ const jsonStr$1 = JSON.stringify(oxfmtrc$1, null, 2);
19
+ try {
20
+ await saveOxfmtrcFile(cwd, jsonStr$1);
21
+ console.log("Created `.oxfmtrc.json` instead.");
22
+ } catch {
23
+ exitWithError("Failed to create `.oxfmtrc.json`.");
24
+ }
25
+ return;
26
+ }
27
+ let prettierConfig;
28
+ try {
29
+ prettierConfig = await resolveConfig(prettierConfigPath, { editorconfig: false });
30
+ console.log("Found Prettier configuration at:", prettierConfigPath);
31
+ } catch {
32
+ return exitWithError(`Failed to parse: ${prettierConfigPath}`);
33
+ }
34
+ const oxfmtrc = await createBlankOxfmtrcFile(cwd);
35
+ for (const [key, value] of Object.entries(prettierConfig ?? {})) {
36
+ if (key === "overrides") {
37
+ console.error(` - "overrides" is not supported, skipping...`);
38
+ continue;
39
+ }
40
+ if (key === "plugins") {
41
+ console.error(` - "plugins" is not supported yet, skipping...`);
42
+ continue;
43
+ }
44
+ if (key === "endOfLine" && value === "auto") {
45
+ console.error(` - "endOfLine: auto" is not supported, skipping...`);
46
+ continue;
47
+ }
48
+ if (key === "experimentalTernaries" || key === "experimentalOperatorPosition") {
49
+ console.error(` - "${key}" is not supported in JS/TS files yet`);
50
+ continue;
51
+ }
52
+ oxfmtrc[key] = value;
53
+ }
54
+ if (typeof oxfmtrc.printWidth !== "number") {
55
+ console.error(` - "printWidth" is not set in Prettier config, defaulting to 80 (Oxfmt default: 100)`);
56
+ oxfmtrc.printWidth = 80;
57
+ }
58
+ if (oxfmtrc.embeddedLanguageFormatting !== "off") console.error(` - "embeddedLanguageFormatting" in JS/TS files is not fully supported yet`);
59
+ const ignores = await resolvePrettierIgnore(cwd);
60
+ if (ignores.length > 0) console.log("Migrated ignore patterns from `.prettierignore`");
61
+ delete oxfmtrc.ignorePatterns;
62
+ oxfmtrc.ignorePatterns = ignores;
63
+ const jsonStr = JSON.stringify(oxfmtrc, null, 2);
64
+ try {
65
+ await saveOxfmtrcFile(cwd, jsonStr);
66
+ console.log("Created `.oxfmtrc.json`.");
67
+ } catch {
68
+ return exitWithError("Failed to create `.oxfmtrc.json`.");
69
+ }
70
+ }
71
+ async function resolvePrettierIgnore(cwd) {
72
+ const ignores = [];
73
+ try {
74
+ const lines = (await readFile(join(cwd, ".prettierignore"), "utf8")).split("\n");
75
+ for (let line of lines) {
76
+ line = line.trim();
77
+ if (line === "" || line.startsWith("#")) continue;
78
+ ignores.push(line);
79
+ }
80
+ } catch {}
81
+ return ignores;
82
+ }
83
+
84
+ //#endregion
85
+ export { runMigratePrettier };
@@ -11359,7 +11359,7 @@ async function loadConfigFromPackageYaml(file) {
11359
11359
  var parseYaml;
11360
11360
  async function loadYaml(file) {
11361
11361
  const content = await read_file_default(file);
11362
- if (!parseYaml) ({__parsePrettierYamlConfig: parseYaml} = await import("./yaml-dJK89GQF.js"));
11362
+ if (!parseYaml) ({__parsePrettierYamlConfig: parseYaml} = await import("./yaml-D-v2gjzo.js"));
11363
11363
  try {
11364
11364
  return parseYaml(content);
11365
11365
  } catch (error) {
@@ -15175,7 +15175,7 @@ function createParsersAndPrinters(modules) {
15175
15175
  };
15176
15176
  }
15177
15177
  var estreePlugin = createParsersAndPrinters([{
15178
- importPlugin: () => import("./estree--Z9-_PI0.js"),
15178
+ importPlugin: () => import("./estree-CVa_AA8B.js"),
15179
15179
  printers: ["estree", "estree-json"]
15180
15180
  }]);
15181
15181
  var options7 = {
@@ -15198,11 +15198,11 @@ var languages = [
15198
15198
  ];
15199
15199
  var { parsers, printers } = createParsersAndPrinters([
15200
15200
  {
15201
- importPlugin: () => import("./acorn-Dyod6zSw.js"),
15201
+ importPlugin: () => import("./acorn--TByBHhx.js"),
15202
15202
  parsers: ["acorn", "espree"]
15203
15203
  },
15204
15204
  {
15205
- importPlugin: () => import("./angular-Dk40sjqQ.js"),
15205
+ importPlugin: () => import("./angular-BLzr5qhs.js"),
15206
15206
  parsers: [
15207
15207
  "__ng_action",
15208
15208
  "__ng_binding",
@@ -15211,7 +15211,7 @@ var { parsers, printers } = createParsersAndPrinters([
15211
15211
  ]
15212
15212
  },
15213
15213
  {
15214
- importPlugin: () => import("./babel-BoFWbjUo.js"),
15214
+ importPlugin: () => import("./babel-DhJC4fWe.js"),
15215
15215
  parsers: [
15216
15216
  "babel",
15217
15217
  "babel-flow",
@@ -15230,21 +15230,21 @@ var { parsers, printers } = createParsersAndPrinters([
15230
15230
  ]
15231
15231
  },
15232
15232
  {
15233
- importPlugin: () => import("./flow-wgnoyyH6.js"),
15233
+ importPlugin: () => import("./flow-CI6YHpLC.js"),
15234
15234
  parsers: ["flow"]
15235
15235
  },
15236
15236
  {
15237
- importPlugin: () => import("./glimmer-BbVO9Afp.js"),
15237
+ importPlugin: () => import("./glimmer-JkMh_-MX.js"),
15238
15238
  parsers: ["glimmer"],
15239
15239
  printers: ["glimmer"]
15240
15240
  },
15241
15241
  {
15242
- importPlugin: () => import("./graphql-DpMdcZw2.js"),
15242
+ importPlugin: () => import("./graphql-C9_i3-Cc.js"),
15243
15243
  parsers: ["graphql"],
15244
15244
  printers: ["graphql"]
15245
15245
  },
15246
15246
  {
15247
- importPlugin: () => import("./html-yrDkeEeX.js"),
15247
+ importPlugin: () => import("./html-JgYha5FV.js"),
15248
15248
  parsers: [
15249
15249
  "html",
15250
15250
  "angular",
@@ -15255,7 +15255,7 @@ var { parsers, printers } = createParsersAndPrinters([
15255
15255
  printers: ["html"]
15256
15256
  },
15257
15257
  {
15258
- importPlugin: () => import("./markdown-gTBUizsY.js"),
15258
+ importPlugin: () => import("./markdown-BuwM4NAn.js"),
15259
15259
  parsers: [
15260
15260
  "markdown",
15261
15261
  "mdx",
@@ -15264,11 +15264,11 @@ var { parsers, printers } = createParsersAndPrinters([
15264
15264
  printers: ["mdast"]
15265
15265
  },
15266
15266
  {
15267
- importPlugin: () => import("./meriyah-zg0rZPcG.js"),
15267
+ importPlugin: () => import("./meriyah-BRoj9SnS.js"),
15268
15268
  parsers: ["meriyah"]
15269
15269
  },
15270
15270
  {
15271
- importPlugin: () => import("./postcss-DeeCU2-7.js"),
15271
+ importPlugin: () => import("./postcss-DoFjbuyt.js"),
15272
15272
  parsers: [
15273
15273
  "css",
15274
15274
  "less",
@@ -15277,11 +15277,11 @@ var { parsers, printers } = createParsersAndPrinters([
15277
15277
  printers: ["postcss"]
15278
15278
  },
15279
15279
  {
15280
- importPlugin: () => import("./typescript-DcSkdikT.js"),
15280
+ importPlugin: () => import("./typescript-CeGed7GO.js"),
15281
15281
  parsers: ["typescript"]
15282
15282
  },
15283
15283
  {
15284
- importPlugin: () => import("./yaml-dJK89GQF.js"),
15284
+ importPlugin: () => import("./yaml-D-v2gjzo.js"),
15285
15285
  parsers: ["yaml"],
15286
15286
  printers: ["yaml"]
15287
15287
  }
@@ -0,0 +1,50 @@
1
+ //#region src-js/libs/prettier.ts
2
+ let prettierCache;
3
+ /**
4
+ * TODO: Plugins support
5
+ * - Read `plugins` field
6
+ * - Load plugins dynamically and parse `languages` field
7
+ * - Map file extensions and filenames to Prettier parsers
8
+ *
9
+ * @returns Array of loaded plugin's `languages` info
10
+ */
11
+ async function resolvePlugins() {
12
+ return [];
13
+ }
14
+ const TAG_TO_PARSER = {
15
+ css: "css",
16
+ styled: "css",
17
+ gql: "graphql",
18
+ graphql: "graphql",
19
+ html: "html",
20
+ md: "markdown",
21
+ markdown: "markdown"
22
+ };
23
+ /**
24
+ * Format xxx-in-js code snippets
25
+ *
26
+ * @returns Formatted code snippet
27
+ * TODO: In the future, this should return `Doc` instead of string,
28
+ * otherwise, we cannot calculate `printWidth` correctly.
29
+ */
30
+ async function formatEmbeddedCode({ code, tagName, options }) {
31
+ const parserName = TAG_TO_PARSER[tagName];
32
+ if (!parserName) return code;
33
+ if (!prettierCache) prettierCache = await import("./prettier-BnljmOi5.js");
34
+ options.parser = parserName;
35
+ return prettierCache.format(code, options).then((formatted) => formatted.trimEnd()).catch(() => code);
36
+ }
37
+ /**
38
+ * Format non-js file
39
+ *
40
+ * @returns Formatted code
41
+ */
42
+ async function formatFile({ code, parserName, fileName, options }) {
43
+ if (!prettierCache) prettierCache = await import("./prettier-BnljmOi5.js");
44
+ options.parser = parserName;
45
+ options.filepath = fileName;
46
+ return prettierCache.format(code, options);
47
+ }
48
+
49
+ //#endregion
50
+ export { formatFile as n, resolvePlugins as r, formatEmbeddedCode as t };
@@ -0,0 +1,36 @@
1
+ import { join } from "node:path";
2
+ import { stat, writeFile } from "node:fs/promises";
3
+
4
+ //#region src-js/cli/migration/shared.ts
5
+ async function hasOxfmtrcFile(cwd) {
6
+ return await isFile(join(cwd, ".oxfmtrc.json")) || await isFile(join(cwd, ".oxfmtrc.jsonc"));
7
+ }
8
+ const SCHEMA_RELATIVE_PATH = "./node_modules/oxfmt/configuration_schema.json";
9
+ async function hasSchemaFile(cwd) {
10
+ return await isFile(join(cwd, "node_modules/oxfmt/configuration_schema.json")) ? SCHEMA_RELATIVE_PATH : null;
11
+ }
12
+ async function createBlankOxfmtrcFile(cwd) {
13
+ const config = {
14
+ $schema: await hasSchemaFile(cwd),
15
+ ignorePatterns: []
16
+ };
17
+ if (config.$schema === null) delete config.$schema;
18
+ return config;
19
+ }
20
+ async function saveOxfmtrcFile(cwd, jsonStr) {
21
+ await writeFile(join(cwd, ".oxfmtrc.json"), jsonStr + "\n", "utf8");
22
+ }
23
+ function exitWithError(message) {
24
+ console.error(message);
25
+ process.exitCode = 1;
26
+ }
27
+ async function isFile(path) {
28
+ try {
29
+ return (await stat(path)).isFile();
30
+ } catch {
31
+ return false;
32
+ }
33
+ }
34
+
35
+ //#endregion
36
+ export { saveOxfmtrcFile as i, exitWithError as n, hasOxfmtrcFile as r, createBlankOxfmtrcFile as t };
package/package.json CHANGED
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "name": "oxfmt",
3
- "version": "0.18.0",
4
- "type": "module",
3
+ "version": "0.19.0",
5
4
  "description": "Formatter for the JavaScript Oxidation Compiler",
6
5
  "keywords": [],
7
- "author": "Boshen and oxc contributors",
8
- "license": "MIT",
9
6
  "homepage": "https://oxc.rs",
10
7
  "bugs": "https://github.com/oxc-project/oxc/issues",
11
8
  "repository": {
@@ -13,34 +10,37 @@
13
10
  "url": "git+https://github.com/oxc-project/oxc",
14
11
  "directory": "npm/oxfmt"
15
12
  },
13
+ "author": "Boshen and oxc contributors",
14
+ "funding": {
15
+ "url": "https://github.com/sponsors/Boshen"
16
+ },
17
+ "license": "MIT",
18
+ "type": "module",
16
19
  "main": "dist/index.js",
20
+ "types": "dist/index.d.ts",
17
21
  "bin": {
18
22
  "oxfmt": "bin/oxfmt"
19
23
  },
20
- "types": "dist/index.d.ts",
21
- "funding": {
22
- "url": "https://github.com/sponsors/Boshen"
23
- },
24
+ "files": [
25
+ "README.md",
26
+ "bin/oxfmt",
27
+ "configuration_schema.json",
28
+ "dist"
29
+ ],
24
30
  "dependencies": {
25
31
  "tinypool": "2.0.0"
26
32
  },
27
33
  "engines": {
28
34
  "node": "^20.19.0 || >=22.12.0"
29
35
  },
30
- "files": [
31
- "bin/oxfmt",
32
- "configuration_schema.json",
33
- "dist",
34
- "README.md"
35
- ],
36
36
  "optionalDependencies": {
37
- "@oxfmt/win32-x64": "0.18.0",
38
- "@oxfmt/win32-arm64": "0.18.0",
39
- "@oxfmt/linux-x64-gnu": "0.18.0",
40
- "@oxfmt/linux-arm64-gnu": "0.18.0",
41
- "@oxfmt/linux-x64-musl": "0.18.0",
42
- "@oxfmt/linux-arm64-musl": "0.18.0",
43
- "@oxfmt/darwin-x64": "0.18.0",
44
- "@oxfmt/darwin-arm64": "0.18.0"
37
+ "@oxfmt/win32-x64": "0.19.0",
38
+ "@oxfmt/win32-arm64": "0.19.0",
39
+ "@oxfmt/linux-x64-gnu": "0.19.0",
40
+ "@oxfmt/linux-arm64-gnu": "0.19.0",
41
+ "@oxfmt/linux-x64-musl": "0.19.0",
42
+ "@oxfmt/linux-arm64-musl": "0.19.0",
43
+ "@oxfmt/darwin-x64": "0.19.0",
44
+ "@oxfmt/darwin-arm64": "0.19.0"
45
45
  }
46
46
  }
@@ -1,26 +0,0 @@
1
- import { Options } from "prettier";
2
-
3
- //#region src-js/prettier-worker.d.ts
4
- type WorkerData = {
5
- prettierConfig: Options;
6
- };
7
- type FormatEmbeddedCodeArgs = {
8
- parser: string;
9
- code: string;
10
- };
11
- declare function formatEmbeddedCode({
12
- parser,
13
- code
14
- }: FormatEmbeddedCodeArgs): Promise<string>;
15
- type FormatFileArgs = {
16
- parserName: string;
17
- fileName: string;
18
- code: string;
19
- };
20
- declare function formatFile({
21
- parserName,
22
- fileName,
23
- code
24
- }: FormatFileArgs): Promise<string>;
25
- //#endregion
26
- export { FormatEmbeddedCodeArgs, FormatFileArgs, WorkerData, formatEmbeddedCode, formatFile };
@@ -1,23 +0,0 @@
1
- import { workerData } from "node:worker_threads";
2
-
3
- //#region src-js/prettier-worker.ts
4
- let prettierCache;
5
- const [, { prettierConfig }] = workerData;
6
- async function formatEmbeddedCode({ parser, code }) {
7
- if (!prettierCache) prettierCache = await import("./prettier-BAX-9y1Y.js");
8
- return prettierCache.format(code, {
9
- ...prettierConfig,
10
- parser
11
- }).then((formatted) => formatted.trimEnd()).catch(() => code);
12
- }
13
- async function formatFile({ parserName, fileName, code }) {
14
- if (!prettierCache) prettierCache = await import("./prettier-BAX-9y1Y.js");
15
- return prettierCache.format(code, {
16
- ...prettierConfig,
17
- parser: parserName,
18
- filepath: fileName
19
- });
20
- }
21
-
22
- //#endregion
23
- export { formatEmbeddedCode, formatFile };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes