load-oxfmt-config 0.5.0 → 0.7.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 +158 -35
- package/dist/index.d.mts +14 -0
- package/dist/index.mjs +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -191,66 +191,77 @@ Load and parse oxfmt configuration files, then merge supported `.editorconfig` f
|
|
|
191
191
|
|
|
192
192
|
**Parameters:**
|
|
193
193
|
|
|
194
|
-
- `options` - Optional configuration object
|
|
194
|
+
- `options` - Optional configuration object (`Options`)
|
|
195
195
|
|
|
196
|
-
|
|
196
|
+
Option fields:
|
|
197
197
|
|
|
198
|
-
|
|
198
|
+
#### `cwd`
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
- **Type:** `string`
|
|
201
|
+
- **Default:** `process.cwd()`
|
|
201
202
|
|
|
202
|
-
|
|
203
|
+
Current working directory to start searching for config files. The loader will walk up from this directory to find a config file.
|
|
203
204
|
|
|
204
|
-
|
|
205
|
+
#### `configPath`
|
|
205
206
|
|
|
206
|
-
**
|
|
207
|
+
- **Type:** `string`
|
|
208
|
+
- **Default:** `undefined`
|
|
207
209
|
|
|
208
|
-
|
|
209
|
-
- `filepath` - Resolved config absolute path (undefined when not found)
|
|
210
|
-
- `dirname` - Config directory (undefined when not found)
|
|
210
|
+
Explicit path to the config file:
|
|
211
211
|
|
|
212
|
-
**
|
|
212
|
+
- **Relative path:** Resolved relative to `cwd`
|
|
213
|
+
- **Absolute path:** Used as-is
|
|
214
|
+
- **When provided:** Skips auto-discovery and uses this path directly
|
|
213
215
|
|
|
214
|
-
|
|
216
|
+
#### `useCache`
|
|
215
217
|
|
|
216
|
-
|
|
218
|
+
- **Type:** `boolean`
|
|
219
|
+
- **Default:** `true`
|
|
217
220
|
|
|
218
|
-
|
|
221
|
+
Enable in-memory caching for both path resolution and parsed config contents. When enabled:
|
|
219
222
|
|
|
220
|
-
-
|
|
221
|
-
-
|
|
223
|
+
- Config file paths are cached to avoid repeated filesystem lookups
|
|
224
|
+
- Parsed config objects are cached to avoid re-parsing
|
|
225
|
+
- Subsequent calls with the same parameters return cached results instantly
|
|
222
226
|
|
|
223
|
-
|
|
227
|
+
Set to `false` to force reload from disk on every call.
|
|
224
228
|
|
|
225
|
-
|
|
229
|
+
#### `editorconfig`
|
|
226
230
|
|
|
227
|
-
|
|
231
|
+
- **Type:** `boolean | EditorconfigOption`
|
|
232
|
+
- **Default:** `true`
|
|
228
233
|
|
|
229
|
-
|
|
234
|
+
Control how `.editorconfig` files are read and merged:
|
|
230
235
|
|
|
231
|
-
|
|
236
|
+
- **`true`** — Read and merge the nearest `.editorconfig`, walking up from the config file's directory (or `cwd` when no config path is given).
|
|
237
|
+
- **`false`** — Disable `.editorconfig` reading entirely.
|
|
238
|
+
- **`EditorconfigOption`** — Enable with additional settings:
|
|
232
239
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
- `gitignore`
|
|
238
|
-
- `prettierignore`
|
|
239
|
-
- `ignore-path`
|
|
240
|
-
- `config-ignore-patterns`
|
|
240
|
+
| Property | Type | Default | Description |
|
|
241
|
+
| --------- | --------- | ----------- | --------------------------------------------------------------------------------------------------------------------- |
|
|
242
|
+
| `onlyCwd` | `boolean` | `false` | When `true`, only look for `.editorconfig` in `cwd` itself — no upward traversal. |
|
|
243
|
+
| `cwd` | `string` | `undefined` | Override the directory from which `.editorconfig` resolution starts, instead of the config file's directory or `cwd`. |
|
|
241
244
|
|
|
242
|
-
|
|
245
|
+
**Returns:** `Promise<OxfmtOptions>` - Parsed and merged oxfmt configuration object. Returns empty object `{}` if no supported config file is found.
|
|
243
246
|
|
|
244
|
-
|
|
247
|
+
### `loadOxfmtConfigResult(options?)`
|
|
245
248
|
|
|
246
|
-
|
|
249
|
+
Load and parse oxfmt configuration files, merge supported `.editorconfig` fields, and return metadata for the resolved config file.
|
|
250
|
+
|
|
251
|
+
**Parameters:**
|
|
252
|
+
|
|
253
|
+
- `options` - Optional configuration object (`Options`)
|
|
254
|
+
|
|
255
|
+
Option fields:
|
|
256
|
+
|
|
257
|
+
#### `cwd`
|
|
247
258
|
|
|
248
259
|
- **Type:** `string`
|
|
249
260
|
- **Default:** `process.cwd()`
|
|
250
261
|
|
|
251
262
|
Current working directory to start searching for config files. The loader will walk up from this directory to find a config file.
|
|
252
263
|
|
|
253
|
-
|
|
264
|
+
#### `configPath`
|
|
254
265
|
|
|
255
266
|
- **Type:** `string`
|
|
256
267
|
- **Default:** `undefined`
|
|
@@ -261,7 +272,7 @@ Explicit path to the config file:
|
|
|
261
272
|
- **Absolute path:** Used as-is
|
|
262
273
|
- **When provided:** Skips auto-discovery and uses this path directly
|
|
263
274
|
|
|
264
|
-
|
|
275
|
+
#### `useCache`
|
|
265
276
|
|
|
266
277
|
- **Type:** `boolean`
|
|
267
278
|
- **Default:** `true`
|
|
@@ -274,7 +285,7 @@ Enable in-memory caching for both path resolution and parsed config contents. Wh
|
|
|
274
285
|
|
|
275
286
|
Set to `false` to force reload from disk on every call.
|
|
276
287
|
|
|
277
|
-
|
|
288
|
+
#### `editorconfig`
|
|
278
289
|
|
|
279
290
|
- **Type:** `boolean | EditorconfigOption`
|
|
280
291
|
- **Default:** `true`
|
|
@@ -290,6 +301,113 @@ Control how `.editorconfig` files are read and merged:
|
|
|
290
301
|
| `onlyCwd` | `boolean` | `false` | When `true`, only look for `.editorconfig` in `cwd` itself — no upward traversal. |
|
|
291
302
|
| `cwd` | `string` | `undefined` | Override the directory from which `.editorconfig` resolution starts, instead of the config file's directory or `cwd`. |
|
|
292
303
|
|
|
304
|
+
**Returns:** `Promise<LoadOxfmtConfigResult>`
|
|
305
|
+
|
|
306
|
+
- `config` - Parsed and merged oxfmt configuration object
|
|
307
|
+
- `filepath` - Resolved config absolute path (undefined when not found)
|
|
308
|
+
- `dirname` - Config directory (undefined when not found)
|
|
309
|
+
|
|
310
|
+
**Throws:** Error if config file exists but cannot be parsed.
|
|
311
|
+
|
|
312
|
+
### `resolveOxfmtrcPath(cwd, configPath?)`
|
|
313
|
+
|
|
314
|
+
Resolve the absolute path to oxfmt config file.
|
|
315
|
+
|
|
316
|
+
**Parameters:**
|
|
317
|
+
|
|
318
|
+
- `cwd` - Starting directory for resolution
|
|
319
|
+
- `configPath` - Optional explicit path (absolute or relative to cwd)
|
|
320
|
+
|
|
321
|
+
**Returns:** `Promise<string | undefined>` - Absolute path to config file, or `undefined` if not found.
|
|
322
|
+
|
|
323
|
+
### `isOxfmtIgnored(options)`
|
|
324
|
+
|
|
325
|
+
Resolve whether a file should be ignored with oxfmt CLI-like semantics.
|
|
326
|
+
|
|
327
|
+
**Parameters:**
|
|
328
|
+
|
|
329
|
+
- `options` - Required configuration object (`IsOxfmtIgnoredOptions`)
|
|
330
|
+
|
|
331
|
+
Option fields:
|
|
332
|
+
|
|
333
|
+
#### `cwd`
|
|
334
|
+
|
|
335
|
+
- **Type:** `string`
|
|
336
|
+
- **Default:** `process.cwd()`
|
|
337
|
+
|
|
338
|
+
Current working directory.
|
|
339
|
+
Also the base directory for default `.gitignore`/`.prettierignore` lookup.
|
|
340
|
+
|
|
341
|
+
#### `filepath`
|
|
342
|
+
|
|
343
|
+
- **Type:** `string`
|
|
344
|
+
- **Default:** required
|
|
345
|
+
|
|
346
|
+
File path to test.
|
|
347
|
+
|
|
348
|
+
#### `configPath`
|
|
349
|
+
|
|
350
|
+
- **Type:** `string`
|
|
351
|
+
- **Default:** `undefined`
|
|
352
|
+
|
|
353
|
+
Explicit oxfmt config path.
|
|
354
|
+
When provided, nested config lookup is disabled (same as oxfmt CLI `-c`).
|
|
355
|
+
|
|
356
|
+
#### `ignorePath`
|
|
357
|
+
|
|
358
|
+
- **Type:** `string | string[]`
|
|
359
|
+
- **Default:** `undefined`
|
|
360
|
+
|
|
361
|
+
Ignore files to use instead of cwd `.gitignore`/`.prettierignore`.
|
|
362
|
+
Can be passed multiple times in CLI style.
|
|
363
|
+
|
|
364
|
+
#### `withNodeModules`
|
|
365
|
+
|
|
366
|
+
- **Type:** `boolean`
|
|
367
|
+
- **Default:** `true`
|
|
368
|
+
|
|
369
|
+
Whether `node_modules` should be included.
|
|
370
|
+
|
|
371
|
+
#### `disableNestedConfig`
|
|
372
|
+
|
|
373
|
+
- **Type:** `boolean`
|
|
374
|
+
- **Default:** `false`
|
|
375
|
+
|
|
376
|
+
Disable nested config lookup.
|
|
377
|
+
|
|
378
|
+
#### `useCache`
|
|
379
|
+
|
|
380
|
+
- **Type:** `boolean`
|
|
381
|
+
- **Default:** `true`
|
|
382
|
+
|
|
383
|
+
Whether to use in-memory cache.
|
|
384
|
+
|
|
385
|
+
#### `includeConfigIgnorePatterns`
|
|
386
|
+
|
|
387
|
+
- **Type:** `boolean`
|
|
388
|
+
- **Default:** `true`
|
|
389
|
+
|
|
390
|
+
Whether to include ignore patterns defined in the resolved config file.
|
|
391
|
+
|
|
392
|
+
#### `loadConfigForIgnorePatterns`
|
|
393
|
+
|
|
394
|
+
- **Type:** `boolean`
|
|
395
|
+
- **Default:** `true`
|
|
396
|
+
|
|
397
|
+
Whether to load the resolved config file during ignore checks.
|
|
398
|
+
When `false`, `isOxfmtIgnored()` only applies global ignore and skips config loading.
|
|
399
|
+
|
|
400
|
+
**Returns:** `Promise<IsOxfmtIgnoredResult>`
|
|
401
|
+
|
|
402
|
+
- `ignored` - Whether the file is ignored
|
|
403
|
+
- `reason` - One of:
|
|
404
|
+
- `default-dir`
|
|
405
|
+
- `lockfile`
|
|
406
|
+
- `gitignore`
|
|
407
|
+
- `prettierignore`
|
|
408
|
+
- `ignore-path`
|
|
409
|
+
- `config-ignore-patterns`
|
|
410
|
+
|
|
293
411
|
## Config File Discovery
|
|
294
412
|
|
|
295
413
|
When `configPath` is not provided, the loader automatically searches for config files:
|
|
@@ -368,6 +486,9 @@ Only `[*]` is treated as a global section to match oxfmt. Other sections such as
|
|
|
368
486
|
1. Global ignore
|
|
369
487
|
2. Ignore patterns from the resolved oxfmt config (`ignorePatterns`)
|
|
370
488
|
|
|
489
|
+
Set `includeConfigIgnorePatterns: false` to skip config `ignorePatterns` matching.
|
|
490
|
+
Set `loadConfigForIgnorePatterns: false` to skip config loading entirely and keep only global ignore behavior.
|
|
491
|
+
|
|
371
492
|
Global ignore includes:
|
|
372
493
|
|
|
373
494
|
- Default ignored directories: `.git`, `.svn`, `.jj`, `node_modules`
|
|
@@ -382,6 +503,8 @@ Notes:
|
|
|
382
503
|
- This package does not read parent `.gitignore` files or global gitignore settings.
|
|
383
504
|
- The default lockfile list mirrors oxfmt documentation intent (`package-lock.json`, `pnpm-lock.yaml`, etc.) and common ecosystem lockfiles. It is not guaranteed to be a complete internal oxfmt list.
|
|
384
505
|
- `ignorePatterns` are always interpreted relative to the resolved oxfmt config directory.
|
|
506
|
+
- `includeConfigIgnorePatterns` defaults to `true` to preserve current behavior.
|
|
507
|
+
- `loadConfigForIgnorePatterns` defaults to `true` to preserve current behavior.
|
|
385
508
|
- Nested config behavior follows oxfmt semantics:
|
|
386
509
|
- default: nearest config from target file directory upward
|
|
387
510
|
- `disableNestedConfig: true`: resolve from `cwd` only
|
package/dist/index.d.mts
CHANGED
|
@@ -119,16 +119,30 @@ interface IsOxfmtIgnoredOptions {
|
|
|
119
119
|
ignorePath?: string | string[];
|
|
120
120
|
/**
|
|
121
121
|
* Whether node_modules should be included.
|
|
122
|
+
* @default true
|
|
122
123
|
*/
|
|
123
124
|
withNodeModules?: boolean;
|
|
124
125
|
/**
|
|
125
126
|
* Disable nested config lookup.
|
|
127
|
+
* @default false
|
|
126
128
|
*/
|
|
127
129
|
disableNestedConfig?: boolean;
|
|
128
130
|
/**
|
|
129
131
|
* Whether to use in-memory cache.
|
|
132
|
+
* @default true
|
|
130
133
|
*/
|
|
131
134
|
useCache?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Whether to include ignore patterns defined in the config file.
|
|
137
|
+
* @default true
|
|
138
|
+
*/
|
|
139
|
+
includeConfigIgnorePatterns?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Whether to load resolved oxfmt config when evaluating config ignore patterns.
|
|
142
|
+
* When false, only global ignore is applied and config loading is skipped.
|
|
143
|
+
* @default true
|
|
144
|
+
*/
|
|
145
|
+
loadConfigForIgnorePatterns?: boolean;
|
|
132
146
|
}
|
|
133
147
|
/**
|
|
134
148
|
* Ignore resolution result.
|
package/dist/index.mjs
CHANGED
|
@@ -554,6 +554,8 @@ function matchConfigIgnorePatterns(filepath, configDir, patterns) {
|
|
|
554
554
|
*/
|
|
555
555
|
async function isOxfmtIgnored(options) {
|
|
556
556
|
const useCache = options.useCache !== false;
|
|
557
|
+
const includeConfigIgnorePatterns = options.includeConfigIgnorePatterns !== false;
|
|
558
|
+
const loadConfigForIgnorePatterns = options.loadConfigForIgnorePatterns !== false;
|
|
557
559
|
const cwd = resolve(options.cwd ?? process.cwd());
|
|
558
560
|
const filepath = isAbsolute(options.filepath) ? resolve(options.filepath) : resolve(cwd, options.filepath);
|
|
559
561
|
if (isDefaultIgnoredDir(filepath, options.withNodeModules ? { withNodeModules: true } : {})) return {
|
|
@@ -574,13 +576,14 @@ async function isOxfmtIgnored(options) {
|
|
|
574
576
|
ignored: true,
|
|
575
577
|
reason: ignoreFile === ".gitignore" ? "gitignore" : "prettierignore"
|
|
576
578
|
};
|
|
579
|
+
if (!loadConfigForIgnorePatterns) return { ignored: false };
|
|
577
580
|
const configResult = await loadOxfmtConfigResult({
|
|
578
581
|
cwd: options.configPath || options.disableNestedConfig ? cwd : dirname(filepath),
|
|
579
582
|
...options.configPath ? { configPath: options.configPath } : {},
|
|
580
583
|
editorconfig: false,
|
|
581
584
|
useCache
|
|
582
585
|
});
|
|
583
|
-
if (configResult.dirname && configResult.config.ignorePatterns && configResult.config.ignorePatterns.length > 0 && matchConfigIgnorePatterns(filepath, configResult.dirname, configResult.config.ignorePatterns)) return {
|
|
586
|
+
if (includeConfigIgnorePatterns && configResult.dirname && configResult.config.ignorePatterns && configResult.config.ignorePatterns.length > 0 && matchConfigIgnorePatterns(filepath, configResult.dirname, configResult.config.ignorePatterns)) return {
|
|
584
587
|
ignored: true,
|
|
585
588
|
reason: "config-ignore-patterns"
|
|
586
589
|
};
|