load-oxfmt-config 0.7.2 → 0.8.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 +29 -99
- package/dist/index.d.mts +7 -36
- package/dist/index.mjs +81 -38
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -38,19 +38,19 @@ pnpm add load-oxfmt-config
|
|
|
38
38
|
Load config from current directory or parent directories:
|
|
39
39
|
|
|
40
40
|
```ts
|
|
41
|
-
import {
|
|
41
|
+
import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
42
42
|
|
|
43
43
|
// Automatically searches for oxfmt config files and the nearest .editorconfig
|
|
44
|
-
const result = await
|
|
44
|
+
const result = await loadOxfmtConfig()
|
|
45
45
|
console.log(result.config) // { printWidth: 80, ... }
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
### Merge With `.editorconfig`
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
|
-
import {
|
|
51
|
+
import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
52
52
|
|
|
53
|
-
const result = await
|
|
53
|
+
const result = await loadOxfmtConfig({ cwd: '/path/to/project' })
|
|
54
54
|
|
|
55
55
|
// Returns one merged static config object
|
|
56
56
|
console.log(result.config)
|
|
@@ -66,9 +66,9 @@ console.log(result.config)
|
|
|
66
66
|
### Specify Working Directory
|
|
67
67
|
|
|
68
68
|
```ts
|
|
69
|
-
import {
|
|
69
|
+
import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
70
70
|
|
|
71
|
-
const result = await
|
|
71
|
+
const result = await loadOxfmtConfig({
|
|
72
72
|
cwd: '/path/to/project',
|
|
73
73
|
})
|
|
74
74
|
```
|
|
@@ -76,9 +76,9 @@ const result = await loadOxfmtConfigResult({
|
|
|
76
76
|
### Get Config Metadata
|
|
77
77
|
|
|
78
78
|
```ts
|
|
79
|
-
import {
|
|
79
|
+
import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
80
80
|
|
|
81
|
-
const result = await
|
|
81
|
+
const result = await loadOxfmtConfig({ cwd: '/path/to/project' })
|
|
82
82
|
|
|
83
83
|
console.log(result.config) // merged oxfmt options
|
|
84
84
|
console.log(result.filepath) // /path/to/project/.oxfmtrc.json (or undefined)
|
|
@@ -102,16 +102,16 @@ console.log(result)
|
|
|
102
102
|
### Explicit Config Path
|
|
103
103
|
|
|
104
104
|
```ts
|
|
105
|
-
import {
|
|
105
|
+
import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
106
106
|
|
|
107
107
|
// Relative path (resolved relative to cwd)
|
|
108
|
-
const result = await
|
|
108
|
+
const result = await loadOxfmtConfig({
|
|
109
109
|
configPath: 'configs/.oxfmtrc.json',
|
|
110
110
|
cwd: '/path/to/project',
|
|
111
111
|
})
|
|
112
112
|
|
|
113
113
|
// Absolute path
|
|
114
|
-
const absoluteResult = await
|
|
114
|
+
const absoluteResult = await loadOxfmtConfig({
|
|
115
115
|
configPath: '/absolute/path/to/.oxfmtrc.json',
|
|
116
116
|
})
|
|
117
117
|
```
|
|
@@ -119,10 +119,10 @@ const absoluteResult = await loadOxfmtConfigResult({
|
|
|
119
119
|
### Disable `.editorconfig`
|
|
120
120
|
|
|
121
121
|
```ts
|
|
122
|
-
import {
|
|
122
|
+
import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
123
123
|
|
|
124
124
|
// Skip .editorconfig reading entirely
|
|
125
|
-
const result = await
|
|
125
|
+
const result = await loadOxfmtConfig({
|
|
126
126
|
editorconfig: false,
|
|
127
127
|
})
|
|
128
128
|
```
|
|
@@ -130,10 +130,10 @@ const result = await loadOxfmtConfigResult({
|
|
|
130
130
|
### Limit `.editorconfig` to `cwd`
|
|
131
131
|
|
|
132
132
|
```ts
|
|
133
|
-
import {
|
|
133
|
+
import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
134
134
|
|
|
135
135
|
// Only look in the cwd directory itself, no upward traversal
|
|
136
|
-
const result = await
|
|
136
|
+
const result = await loadOxfmtConfig({
|
|
137
137
|
editorconfig: { onlyCwd: true },
|
|
138
138
|
})
|
|
139
139
|
```
|
|
@@ -141,10 +141,10 @@ const result = await loadOxfmtConfigResult({
|
|
|
141
141
|
### Override `.editorconfig` Search Directory
|
|
142
142
|
|
|
143
143
|
```ts
|
|
144
|
-
import {
|
|
144
|
+
import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
145
145
|
|
|
146
146
|
// Search .editorconfig from a custom directory instead of the config file's directory
|
|
147
|
-
const result = await
|
|
147
|
+
const result = await loadOxfmtConfig({
|
|
148
148
|
editorconfig: {
|
|
149
149
|
cwd: '/path/to/editorconfig-dir',
|
|
150
150
|
},
|
|
@@ -154,23 +154,14 @@ const result = await loadOxfmtConfigResult({
|
|
|
154
154
|
### Disable Caching
|
|
155
155
|
|
|
156
156
|
```ts
|
|
157
|
-
import {
|
|
157
|
+
import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
158
158
|
|
|
159
159
|
// Force reload from disk, bypassing cache
|
|
160
|
-
const result = await
|
|
160
|
+
const result = await loadOxfmtConfig({
|
|
161
161
|
useCache: false,
|
|
162
162
|
})
|
|
163
163
|
```
|
|
164
164
|
|
|
165
|
-
### Legacy API (Deprecated)
|
|
166
|
-
|
|
167
|
-
```ts
|
|
168
|
-
import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
169
|
-
|
|
170
|
-
// Deprecated: prefer loadOxfmtConfigResult
|
|
171
|
-
const config = await loadOxfmtConfig({ cwd: '/path/to/project' })
|
|
172
|
-
```
|
|
173
|
-
|
|
174
165
|
### Path Resolution Only
|
|
175
166
|
|
|
176
167
|
```ts
|
|
@@ -185,67 +176,6 @@ console.log(configPath) // '/path/to/.oxfmtrc.json' or undefined
|
|
|
185
176
|
|
|
186
177
|
### `loadOxfmtConfig(options?)`
|
|
187
178
|
|
|
188
|
-
> Deprecated. Prefer `loadOxfmtConfigResult(options?)`.
|
|
189
|
-
|
|
190
|
-
Load and parse oxfmt configuration files, then merge supported `.editorconfig` fields into the returned result.
|
|
191
|
-
|
|
192
|
-
**Parameters:**
|
|
193
|
-
|
|
194
|
-
- `options` - Optional configuration object (`LoadOxfmtConfigOptions`)
|
|
195
|
-
|
|
196
|
-
Option fields:
|
|
197
|
-
|
|
198
|
-
#### `cwd`
|
|
199
|
-
|
|
200
|
-
- **Type:** `string`
|
|
201
|
-
- **Default:** `process.cwd()`
|
|
202
|
-
|
|
203
|
-
Current working directory to start searching for config files. The loader will walk up from this directory to find a config file.
|
|
204
|
-
|
|
205
|
-
#### `configPath`
|
|
206
|
-
|
|
207
|
-
- **Type:** `string`
|
|
208
|
-
- **Default:** `undefined`
|
|
209
|
-
|
|
210
|
-
Explicit path to the config file:
|
|
211
|
-
|
|
212
|
-
- **Relative path:** Resolved relative to `cwd`
|
|
213
|
-
- **Absolute path:** Used as-is
|
|
214
|
-
- **When provided:** Skips auto-discovery and uses this path directly
|
|
215
|
-
|
|
216
|
-
#### `useCache`
|
|
217
|
-
|
|
218
|
-
- **Type:** `boolean`
|
|
219
|
-
- **Default:** `true`
|
|
220
|
-
|
|
221
|
-
Enable in-memory caching for both path resolution and parsed config contents. When enabled:
|
|
222
|
-
|
|
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
|
|
226
|
-
|
|
227
|
-
Set to `false` to force reload from disk on every call.
|
|
228
|
-
|
|
229
|
-
#### `editorconfig`
|
|
230
|
-
|
|
231
|
-
- **Type:** `boolean | EditorconfigOption`
|
|
232
|
-
- **Default:** `true`
|
|
233
|
-
|
|
234
|
-
Control how `.editorconfig` files are read and merged:
|
|
235
|
-
|
|
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:
|
|
239
|
-
|
|
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`. |
|
|
244
|
-
|
|
245
|
-
**Returns:** `Promise<OxfmtOptions>` - Parsed and merged oxfmt configuration object. Returns empty object `{}` if no supported config file is found.
|
|
246
|
-
|
|
247
|
-
### `loadOxfmtConfigResult(options?)`
|
|
248
|
-
|
|
249
179
|
Load and parse oxfmt configuration files, merge supported `.editorconfig` fields, and return metadata for the resolved config file.
|
|
250
180
|
|
|
251
181
|
**Parameters:**
|
|
@@ -336,7 +266,7 @@ Option fields:
|
|
|
336
266
|
- **Default:** `process.cwd()`
|
|
337
267
|
|
|
338
268
|
Current working directory.
|
|
339
|
-
Also the base directory for default `.
|
|
269
|
+
Also the base directory for default `.prettierignore` lookup.
|
|
340
270
|
|
|
341
271
|
#### `filepath`
|
|
342
272
|
|
|
@@ -358,7 +288,7 @@ When provided, nested config lookup is disabled (same as oxfmt CLI `-c`).
|
|
|
358
288
|
- **Type:** `string | string[]`
|
|
359
289
|
- **Default:** `undefined`
|
|
360
290
|
|
|
361
|
-
Ignore files to use instead of cwd `.
|
|
291
|
+
Ignore files to use instead of default `.gitignore` hierarchy + cwd `.prettierignore`.
|
|
362
292
|
Can be passed multiple times in CLI style.
|
|
363
293
|
|
|
364
294
|
#### `withNodeModules`
|
|
@@ -404,6 +334,7 @@ When `false`, `isOxfmtIgnored()` only applies global ignore and skips config loa
|
|
|
404
334
|
- `default-dir`
|
|
405
335
|
- `lockfile`
|
|
406
336
|
- `gitignore`
|
|
337
|
+
- `git-info-exclude`
|
|
407
338
|
- `prettierignore`
|
|
408
339
|
- `ignore-path`
|
|
409
340
|
- `config-ignore-patterns`
|
|
@@ -495,16 +426,15 @@ Global ignore includes:
|
|
|
495
426
|
- Default lockfiles: `package-lock.json`, `npm-shrinkwrap.json`, `pnpm-lock.yaml`, `yarn.lock`, `bun.lock`, `bun.lockb`
|
|
496
427
|
- Ignore files:
|
|
497
428
|
- If `ignorePath` is provided: use those files only (multiple supported)
|
|
498
|
-
- If `ignorePath` is not provided:
|
|
429
|
+
- If `ignorePath` is not provided:
|
|
430
|
+
- Read `.gitignore` from the file's directory upward until the git repo boundary
|
|
431
|
+
- Read `<repo>/.git/info/exclude` when inside a git repo
|
|
432
|
+
- Read `.prettierignore` from `cwd`
|
|
499
433
|
|
|
500
434
|
Notes:
|
|
501
435
|
|
|
502
436
|
- `node_modules` can be included by passing `withNodeModules: true`.
|
|
503
437
|
|
|
504
|
-
Type compatibility note:
|
|
505
|
-
|
|
506
|
-
- `Options` is still exported as a deprecated alias of `LoadOxfmtConfigOptions`.
|
|
507
|
-
- This package does not read parent `.gitignore` files or global gitignore settings.
|
|
508
438
|
- 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.
|
|
509
439
|
- `ignorePatterns` are always interpreted relative to the resolved oxfmt config directory.
|
|
510
440
|
- `includeConfigIgnorePatterns` defaults to `true` to preserve current behavior.
|
|
@@ -527,15 +457,15 @@ This means explicit oxfmt config values always win over `.editorconfig` fallback
|
|
|
527
457
|
|
|
528
458
|
## Limitations
|
|
529
459
|
|
|
530
|
-
`
|
|
460
|
+
`loadOxfmtConfig()` returns a static merged `OxfmtOptions` shape. That means `.editorconfig` support is represented as merged root + overrides config data, not as per-file runtime evaluation. In practice this works well for common root settings and section-based overrides, but it is not a full replacement for oxfmt's own file-by-file config resolution.
|
|
531
461
|
|
|
532
462
|
## Error Handling
|
|
533
463
|
|
|
534
464
|
```ts
|
|
535
|
-
import {
|
|
465
|
+
import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
536
466
|
|
|
537
467
|
try {
|
|
538
|
-
const result = await
|
|
468
|
+
const result = await loadOxfmtConfig()
|
|
539
469
|
console.log(result.config)
|
|
540
470
|
} catch (error) {
|
|
541
471
|
// Thrown when config file exists but contains invalid JSON/JSONC
|
package/dist/index.d.mts
CHANGED
|
@@ -100,7 +100,7 @@ interface LoadOxfmtConfigResult {
|
|
|
100
100
|
interface IsOxfmtIgnoredOptions {
|
|
101
101
|
/**
|
|
102
102
|
* Current working directory.
|
|
103
|
-
* Also the base directory for default
|
|
103
|
+
* Also the base directory for default `.prettierignore` lookup.
|
|
104
104
|
*/
|
|
105
105
|
cwd?: string;
|
|
106
106
|
/**
|
|
@@ -113,7 +113,7 @@ interface IsOxfmtIgnoredOptions {
|
|
|
113
113
|
*/
|
|
114
114
|
configPath?: string;
|
|
115
115
|
/**
|
|
116
|
-
* Ignore files to use instead of cwd
|
|
116
|
+
* Ignore files to use instead of default `.gitignore` hierarchy + cwd `.prettierignore`.
|
|
117
117
|
* Can be passed multiple times in CLI style.
|
|
118
118
|
*/
|
|
119
119
|
ignorePath?: string | string[];
|
|
@@ -155,16 +155,8 @@ interface IsOxfmtIgnoredResult {
|
|
|
155
155
|
/**
|
|
156
156
|
* Matched ignore source.
|
|
157
157
|
*/
|
|
158
|
-
reason?: 'default-dir' | 'lockfile' | 'gitignore' | 'prettierignore' | 'ignore-path' | 'config-ignore-patterns';
|
|
158
|
+
reason?: 'default-dir' | 'lockfile' | 'gitignore' | 'git-info-exclude' | 'prettierignore' | 'ignore-path' | 'config-ignore-patterns';
|
|
159
159
|
}
|
|
160
|
-
/**
|
|
161
|
-
* @deprecated Use `OxfmtConfigOverride` instead
|
|
162
|
-
*/
|
|
163
|
-
type FormatOptionOverride = OxfmtConfigOverride;
|
|
164
|
-
/**
|
|
165
|
-
* @deprecated Use `LoadOxfmtConfigOptions` instead.
|
|
166
|
-
*/
|
|
167
|
-
type Options = LoadOxfmtConfigOptions;
|
|
168
160
|
//#endregion
|
|
169
161
|
//#region src/config-file.d.ts
|
|
170
162
|
/**
|
|
@@ -196,13 +188,13 @@ declare function resolveOxfmtrcPath(cwd: string, configPath?: string): Promise<s
|
|
|
196
188
|
*
|
|
197
189
|
* @example
|
|
198
190
|
* ```ts
|
|
199
|
-
* import {
|
|
191
|
+
* import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
200
192
|
*
|
|
201
|
-
* const result = await
|
|
193
|
+
* const result = await loadOxfmtConfig({ cwd: process.cwd() })
|
|
202
194
|
* console.log(result.config)
|
|
203
195
|
* ```
|
|
204
196
|
*/
|
|
205
|
-
declare function
|
|
197
|
+
declare function loadOxfmtConfig(options?: LoadOxfmtConfigOptions): Promise<LoadOxfmtConfigResult>;
|
|
206
198
|
//#endregion
|
|
207
199
|
//#region src/ignore.d.ts
|
|
208
200
|
/**
|
|
@@ -223,25 +215,4 @@ declare function loadOxfmtConfigResult(options?: LoadOxfmtConfigOptions): Promis
|
|
|
223
215
|
*/
|
|
224
216
|
declare function isOxfmtIgnored(options: IsOxfmtIgnoredOptions): Promise<IsOxfmtIgnoredResult>;
|
|
225
217
|
//#endregion
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Legacy API that returns only the merged config object.
|
|
229
|
-
*
|
|
230
|
-
* Prefer using `loadOxfmtConfigResult` when you also need resolved config metadata.
|
|
231
|
-
*
|
|
232
|
-
* @deprecated Prefer `loadOxfmtConfigResult`.
|
|
233
|
-
*
|
|
234
|
-
* @param options - Loader options.
|
|
235
|
-
* @returns Parsed and merged oxfmt options.
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* ```ts
|
|
239
|
-
* import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
240
|
-
*
|
|
241
|
-
* // Deprecated: prefer loadOxfmtConfigResult.
|
|
242
|
-
* const config = await loadOxfmtConfig({ cwd: process.cwd() })
|
|
243
|
-
* ```
|
|
244
|
-
*/
|
|
245
|
-
declare function loadOxfmtConfig(options?: LoadOxfmtConfigOptions): Promise<OxfmtOptions>;
|
|
246
|
-
//#endregion
|
|
247
|
-
export { EditorconfigOption, FormatOptionOverride, IsOxfmtIgnoredOptions, IsOxfmtIgnoredResult, LoadOxfmtConfigOptions, LoadOxfmtConfigResult, Options, OxfmtConfigOverride, OxfmtOptions, isOxfmtIgnored, loadOxfmtConfig, loadOxfmtConfigResult, resolveOxfmtrcPath };
|
|
218
|
+
export { EditorconfigOption, IsOxfmtIgnoredOptions, IsOxfmtIgnoredResult, LoadOxfmtConfigOptions, LoadOxfmtConfigResult, OxfmtConfigOverride, OxfmtOptions, isOxfmtIgnored, loadOxfmtConfig, resolveOxfmtrcPath };
|
package/dist/index.mjs
CHANGED
|
@@ -53,10 +53,6 @@ const DEFAULT_IGNORED_LOCKFILES = [
|
|
|
53
53
|
"bun.lockb"
|
|
54
54
|
];
|
|
55
55
|
/**
|
|
56
|
-
* Default ignore files loaded from cwd when --ignore-path is not provided.
|
|
57
|
-
*/
|
|
58
|
-
const DEFAULT_IGNORE_FILES = [".gitignore", ".prettierignore"];
|
|
59
|
-
/**
|
|
60
56
|
* Supported EditorConfig filename.
|
|
61
57
|
*/
|
|
62
58
|
const EDITORCONFIG_FILE = ".editorconfig";
|
|
@@ -394,13 +390,13 @@ const configCache = /* @__PURE__ */ new Map();
|
|
|
394
390
|
*
|
|
395
391
|
* @example
|
|
396
392
|
* ```ts
|
|
397
|
-
* import {
|
|
393
|
+
* import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
398
394
|
*
|
|
399
|
-
* const result = await
|
|
395
|
+
* const result = await loadOxfmtConfig({ cwd: process.cwd() })
|
|
400
396
|
* console.log(result.config)
|
|
401
397
|
* ```
|
|
402
398
|
*/
|
|
403
|
-
async function
|
|
399
|
+
async function loadOxfmtConfig(options = {}) {
|
|
404
400
|
const useCache = options.useCache !== false;
|
|
405
401
|
const cwd = resolve(options.cwd || process.cwd());
|
|
406
402
|
const editorconfig = options.editorconfig ?? true;
|
|
@@ -500,12 +496,13 @@ function relativeSafe(from, to) {
|
|
|
500
496
|
* @param filepath - Absolute file path.
|
|
501
497
|
* @param ignoreFilePath - Ignore file path.
|
|
502
498
|
* @param useCache - Whether to use matcher cache.
|
|
499
|
+
* @param baseDir - Base directory for relative path calculation, defaults to ignore file directory.
|
|
503
500
|
* @returns True when ignored by this file.
|
|
504
501
|
*/
|
|
505
|
-
async function matchIgnoreFile(filepath, ignoreFilePath, useCache) {
|
|
502
|
+
async function matchIgnoreFile(filepath, ignoreFilePath, useCache, baseDir) {
|
|
506
503
|
const matcher = await loadIgnoreMatcher(ignoreFilePath, useCache);
|
|
507
504
|
if (!matcher) return false;
|
|
508
|
-
const relativeToIgnore = relativeSafe(dirname(ignoreFilePath), filepath);
|
|
505
|
+
const relativeToIgnore = relativeSafe(baseDir ?? dirname(ignoreFilePath), filepath);
|
|
509
506
|
if (relativeToIgnore === ".." || relativeToIgnore.startsWith("../")) return false;
|
|
510
507
|
return matcher.ignores(relativeToIgnore);
|
|
511
508
|
}
|
|
@@ -520,6 +517,62 @@ function resolveIgnoreFilePath(path, cwd) {
|
|
|
520
517
|
return isAbsolute(path) ? path : resolve(cwd, path);
|
|
521
518
|
}
|
|
522
519
|
/**
|
|
520
|
+
* Check whether a directory looks like a git repo root.
|
|
521
|
+
*
|
|
522
|
+
* A `.git` entry can be either a directory (regular repo) or a file (worktree/submodule).
|
|
523
|
+
*
|
|
524
|
+
* @param dir - Directory to inspect.
|
|
525
|
+
* @returns True when `.git` exists under the directory.
|
|
526
|
+
*/
|
|
527
|
+
async function hasGitEntry(dir) {
|
|
528
|
+
try {
|
|
529
|
+
await stat(join(dir, ".git"));
|
|
530
|
+
return true;
|
|
531
|
+
} catch (error) {
|
|
532
|
+
const code = error.code;
|
|
533
|
+
if (code === "ENOENT" || code === "ENOTDIR") return false;
|
|
534
|
+
throw error;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Find the nearest git repo root by walking up from a start directory.
|
|
539
|
+
*
|
|
540
|
+
* @param fromDir - Directory to start from.
|
|
541
|
+
* @returns Repo root directory, or undefined when no git boundary is found.
|
|
542
|
+
*/
|
|
543
|
+
async function findGitRepoRoot(fromDir) {
|
|
544
|
+
let current = fromDir;
|
|
545
|
+
while (true) {
|
|
546
|
+
if (await hasGitEntry(current)) return current;
|
|
547
|
+
const parent = dirname(current);
|
|
548
|
+
if (parent === current) return;
|
|
549
|
+
current = parent;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Collect `.gitignore` files from file directory up to git repo boundary.
|
|
554
|
+
*
|
|
555
|
+
* @param filepath - Absolute file path to test.
|
|
556
|
+
* @returns Collected ignore files and repo root when found.
|
|
557
|
+
*/
|
|
558
|
+
async function collectGitignorePaths(filepath) {
|
|
559
|
+
const fileDir = dirname(filepath);
|
|
560
|
+
const repoRoot = await findGitRepoRoot(fileDir);
|
|
561
|
+
const paths = [];
|
|
562
|
+
let current = fileDir;
|
|
563
|
+
while (true) {
|
|
564
|
+
paths.push(join(current, ".gitignore"));
|
|
565
|
+
if (repoRoot && current === repoRoot) break;
|
|
566
|
+
const parent = dirname(current);
|
|
567
|
+
if (parent === current) break;
|
|
568
|
+
current = parent;
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
paths,
|
|
572
|
+
repoRoot
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
523
576
|
* Match `ignorePatterns` from config with support for negated patterns.
|
|
524
577
|
*
|
|
525
578
|
* @param filepath - Absolute file path.
|
|
@@ -575,12 +628,25 @@ async function isOxfmtIgnored(options) {
|
|
|
575
628
|
ignored: true,
|
|
576
629
|
reason: "ignore-path"
|
|
577
630
|
};
|
|
578
|
-
} else
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
631
|
+
} else {
|
|
632
|
+
const { paths: gitignorePaths, repoRoot } = await collectGitignorePaths(filepath);
|
|
633
|
+
for (const ignorePath of gitignorePaths) if (await matchIgnoreFile(filepath, ignorePath, useCache)) return {
|
|
634
|
+
ignored: true,
|
|
635
|
+
reason: "gitignore"
|
|
636
|
+
};
|
|
637
|
+
if (repoRoot) {
|
|
638
|
+
if (await matchIgnoreFile(filepath, join(repoRoot, ".git", "info", "exclude"), useCache, repoRoot)) return {
|
|
639
|
+
ignored: true,
|
|
640
|
+
reason: "git-info-exclude"
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
if (await matchIgnoreFile(filepath, resolve(cwd, ".prettierignore"), useCache)) return {
|
|
644
|
+
ignored: true,
|
|
645
|
+
reason: "prettierignore"
|
|
646
|
+
};
|
|
647
|
+
}
|
|
582
648
|
if (!loadConfigForIgnorePatterns) return { ignored: false };
|
|
583
|
-
const configResult = await
|
|
649
|
+
const configResult = await loadOxfmtConfig({
|
|
584
650
|
cwd: options.configPath || options.disableNestedConfig ? cwd : dirname(filepath),
|
|
585
651
|
...options.configPath ? { configPath: options.configPath } : {},
|
|
586
652
|
editorconfig: false,
|
|
@@ -593,27 +659,4 @@ async function isOxfmtIgnored(options) {
|
|
|
593
659
|
return { ignored: false };
|
|
594
660
|
}
|
|
595
661
|
//#endregion
|
|
596
|
-
|
|
597
|
-
/**
|
|
598
|
-
* Legacy API that returns only the merged config object.
|
|
599
|
-
*
|
|
600
|
-
* Prefer using `loadOxfmtConfigResult` when you also need resolved config metadata.
|
|
601
|
-
*
|
|
602
|
-
* @deprecated Prefer `loadOxfmtConfigResult`.
|
|
603
|
-
*
|
|
604
|
-
* @param options - Loader options.
|
|
605
|
-
* @returns Parsed and merged oxfmt options.
|
|
606
|
-
*
|
|
607
|
-
* @example
|
|
608
|
-
* ```ts
|
|
609
|
-
* import { loadOxfmtConfig } from 'load-oxfmt-config'
|
|
610
|
-
*
|
|
611
|
-
* // Deprecated: prefer loadOxfmtConfigResult.
|
|
612
|
-
* const config = await loadOxfmtConfig({ cwd: process.cwd() })
|
|
613
|
-
* ```
|
|
614
|
-
*/
|
|
615
|
-
async function loadOxfmtConfig(options = {}) {
|
|
616
|
-
return (await loadOxfmtConfigResult(options)).config;
|
|
617
|
-
}
|
|
618
|
-
//#endregion
|
|
619
|
-
export { isOxfmtIgnored, loadOxfmtConfig, loadOxfmtConfigResult, resolveOxfmtrcPath };
|
|
662
|
+
export { isOxfmtIgnored, loadOxfmtConfig, resolveOxfmtrcPath };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "load-oxfmt-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Load oxfmt config files and merge supported .editorconfig options.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"editorconfig",
|
|
@@ -48,20 +48,20 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@ntnyq/tsconfig": "^3.1.0",
|
|
51
|
-
"@types/node": "^25.
|
|
51
|
+
"@types/node": "^25.7.0",
|
|
52
52
|
"@types/picomatch": "^4.0.3",
|
|
53
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
53
|
+
"@typescript/native-preview": "^7.0.0-dev.20260511.1",
|
|
54
54
|
"bumpp": "^11.1.0",
|
|
55
55
|
"husky": "^9.1.7",
|
|
56
56
|
"nano-staged": "^1.0.2",
|
|
57
57
|
"npm-run-all2": "^8.0.4",
|
|
58
|
-
"oxfmt": "^0.
|
|
59
|
-
"oxlint": "^1.
|
|
58
|
+
"oxfmt": "^0.49.0",
|
|
59
|
+
"oxlint": "^1.64.0",
|
|
60
60
|
"tsdown": "^0.22.0",
|
|
61
|
-
"vitest": "^4.1.
|
|
61
|
+
"vitest": "^4.1.6"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"oxfmt": ">=0.
|
|
64
|
+
"oxfmt": ">=0.49.0"
|
|
65
65
|
},
|
|
66
66
|
"nano-staged": {
|
|
67
67
|
"*.{js,ts,mjs,tsx}": "oxlint --fix",
|