load-oxfmt-config 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,6 +1,23 @@
1
1
  import { FormatOptions } from "oxfmt";
2
2
 
3
3
  //#region src/types.d.ts
4
+ /**
5
+ * Format option override for a single matching rule
6
+ */
7
+ interface FormatOptionOverride {
8
+ /**
9
+ * Glob patterns to match files
10
+ */
11
+ files: string[];
12
+ /**
13
+ * Glob patterns to exclude files
14
+ */
15
+ excludeFiles?: string[];
16
+ /**
17
+ * Format options to apply
18
+ */
19
+ options?: FormatOptions;
20
+ }
4
21
  interface Options {
5
22
  /**
6
23
  * Path to the configuration file
@@ -15,14 +32,38 @@ interface Options {
15
32
  */
16
33
  useCache?: boolean;
17
34
  }
35
+ /**
36
+ * Final oxfmt options (including overrides)
37
+ */
38
+ interface OxfmtOptions extends FormatOptions {
39
+ /**
40
+ * Ignore files matching these glob patterns
41
+ * Patterns are based on the location of the Oxfmt configuration file
42
+ */
43
+ ignorePatterns?: string[];
44
+ /**
45
+ * Array of format option overrides
46
+ */
47
+ overrides?: FormatOptionOverride[];
48
+ }
18
49
  //#endregion
19
50
  //#region src/core.d.ts
51
+ /**
52
+ * Resolve the oxfmt config file path.
53
+ * - If `configPath` is provided, absolute paths are returned as-is; relative paths are joined to cwd.
54
+ * - Otherwise, walk upward from cwd to find known filenames.
55
+ *
56
+ * @param cwd - Starting directory for resolution.
57
+ * @param configPath - Optional explicit path (absolute or relative to cwd).
58
+ * @returns Absolute path to the config file, or undefined when not found.
59
+ */
60
+ declare function resolveOxfmtrcPath(cwd: string, configPath?: string): Promise<string | undefined>;
20
61
  /**
21
62
  * Load oxfmt configuration: resolve the file path, then read and parse it.
22
63
  * Caching is enabled by default; pass `useCache: false` to force a re-read.
23
64
  *
24
65
  * @param options - Optional loader settings (cwd, configPath, useCache).
25
- * @returns Parsed oxfmt FormatOptions or an empty object when missing.
66
+ * @returns Parsed oxfmt OxfmtOptions or an empty object when missing.
26
67
  * @throws {Error} when the config file exists but cannot be parsed.
27
68
  *
28
69
  * @example
@@ -30,16 +71,6 @@ interface Options {
30
71
  * const config = await loadOxfmtConfig({ cwd: '/project' })
31
72
  * ```
32
73
  */
33
- declare function loadOxfmtConfig(options?: Options): Promise<FormatOptions>;
34
- /**
35
- * Resolve the oxfmt config file path.
36
- * - If `configPath` is provided, absolute paths are returned as-is; relative paths are joined to cwd.
37
- * - Otherwise, walk upward from cwd to find known filenames.
38
- *
39
- * @param cwd - Starting directory for resolution.
40
- * @param configPath - Optional explicit path (absolute or relative to cwd).
41
- * @returns Absolute path to the config file, or undefined when not found.
42
- */
43
- declare function resolveOxfmtrcPath(cwd: string, configPath?: string): Promise<string | undefined>;
74
+ declare function loadOxfmtConfig(options?: Options): Promise<OxfmtOptions>;
44
75
  //#endregion
45
- export { Options, loadOxfmtConfig, resolveOxfmtrcPath };
76
+ export { FormatOptionOverride, Options, OxfmtOptions, loadOxfmtConfig, resolveOxfmtrcPath };
package/dist/index.mjs CHANGED
@@ -2,45 +2,43 @@ import { readFile, stat } from "node:fs/promises";
2
2
  import { isAbsolute, join } from "node:path";
3
3
  import process from "node:process";
4
4
  import { parse } from "jsonc-parser";
5
-
6
5
  //#region src/constants.ts
7
6
  /**
8
7
  * Supported configuration files for oxfmt.
9
8
  * @see https://oxc.rs/docs/guide/usage/formatter/config.html#oxfmtrc-json-c
10
9
  */
11
10
  const OXFMT_CONFIG_FILES = [".oxfmtrc.json", ".oxfmtrc.jsonc"];
12
-
13
11
  //#endregion
14
12
  //#region src/core.ts
15
13
  const resolveCache = /* @__PURE__ */ new Map();
16
14
  const configCache = /* @__PURE__ */ new Map();
17
15
  /**
18
- * Load oxfmt configuration: resolve the file path, then read and parse it.
19
- * Caching is enabled by default; pass `useCache: false` to force a re-read.
20
- *
21
- * @param options - Optional loader settings (cwd, configPath, useCache).
22
- * @returns Parsed oxfmt FormatOptions or an empty object when missing.
23
- * @throws {Error} when the config file exists but cannot be parsed.
16
+ * Return a cached promise by key, creating and storing it on miss; failures clear the entry.
24
17
  *
25
- * @example
26
- * ```ts
27
- * const config = await loadOxfmtConfig({ cwd: '/project' })
28
- * ```
18
+ * @param cache - Map used to store inflight/resolved promises.
19
+ * @param key - Cache key.
20
+ * @param factory - Factory to create the promise when missing.
21
+ * @returns Cached or newly created promise.
29
22
  */
30
- async function loadOxfmtConfig(options = {}) {
31
- const useCache = options.useCache !== false;
32
- const cwd = options.cwd || process.cwd();
33
- const resolveKey = getResolveCacheKey(cwd, options.configPath);
34
- const resolvedPath = useCache ? await cachePromise(resolveCache, resolveKey, () => resolveOxfmtrcPath(cwd, options.configPath)) : await resolveOxfmtrcPath(cwd, options.configPath);
35
- if (!resolvedPath) {
36
- if (!useCache) return {};
37
- return cachePromise(configCache, getConfigCacheKey(resolvedPath, resolveKey), () => Promise.resolve({}));
38
- }
39
- const loadTask = () => readConfigFromFile(resolvedPath).catch((err) => {
40
- throw new Error(`Failed to parse oxfmt configuration file at ${resolvedPath}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
23
+ function cachePromise(cache, key, factory) {
24
+ const cached = cache.get(key);
25
+ if (cached) return cached;
26
+ const task = factory().catch((error) => {
27
+ cache.delete(key);
28
+ throw error;
41
29
  });
42
- if (!useCache) return loadTask();
43
- return cachePromise(configCache, getConfigCacheKey(resolvedPath, resolveKey), loadTask);
30
+ cache.set(key, task);
31
+ return task;
32
+ }
33
+ /**
34
+ * Build a cache key for config content; prefixes missing entries with `missing:`.
35
+ *
36
+ * @param resolvedPath - Resolved config path or undefined when missing.
37
+ * @param resolveKey - Key used for path resolution caching.
38
+ * @returns Cache key for config content.
39
+ */
40
+ function getConfigCacheKey(resolvedPath, resolveKey) {
41
+ return resolvedPath || `missing:${resolveKey}`;
44
42
  }
45
43
  /**
46
44
  * Resolve the oxfmt config file path.
@@ -67,34 +65,6 @@ async function resolveOxfmtrcPath(cwd, configPath) {
67
65
  }
68
66
  }
69
67
  /**
70
- * Return a cached promise by key, creating and storing it on miss; failures clear the entry.
71
- *
72
- * @param cache - Map used to store inflight/resolved promises.
73
- * @param key - Cache key.
74
- * @param factory - Factory to create the promise when missing.
75
- * @returns Cached or newly created promise.
76
- */
77
- function cachePromise(cache, key, factory) {
78
- const cached = cache.get(key);
79
- if (cached) return cached;
80
- const task = factory().catch((err) => {
81
- cache.delete(key);
82
- throw err;
83
- });
84
- cache.set(key, task);
85
- return task;
86
- }
87
- /**
88
- * Build a cache key for config content; prefixes missing entries with `missing:`.
89
- *
90
- * @param resolvedPath - Resolved config path or undefined when missing.
91
- * @param resolveKey - Key used for path resolution caching.
92
- * @returns Cache key for config content.
93
- */
94
- function getConfigCacheKey(resolvedPath, resolveKey) {
95
- return resolvedPath || `missing:${resolveKey}`;
96
- }
97
- /**
98
68
  * Build a cache key for path resolution (cwd + configPath).
99
69
  *
100
70
  * @param cwd - Current working directory.
@@ -108,13 +78,40 @@ function getResolveCacheKey(cwd, configPath) {
108
78
  * Read and parse config file, supporting JSON and JSONC.
109
79
  *
110
80
  * @param resolvedPath - Absolute path to the config file.
111
- * @returns Parsed FormatOptions object.
81
+ * @returns Parsed OxfmtOptions object.
112
82
  */
113
83
  async function readConfigFromFile(resolvedPath) {
114
- const content = await readFile(resolvedPath, "utf-8");
84
+ const content = await readFile(resolvedPath, "utf8");
115
85
  if (resolvedPath.endsWith(".jsonc")) return parse(content);
116
86
  return JSON.parse(content);
117
87
  }
118
-
88
+ /**
89
+ * Load oxfmt configuration: resolve the file path, then read and parse it.
90
+ * Caching is enabled by default; pass `useCache: false` to force a re-read.
91
+ *
92
+ * @param options - Optional loader settings (cwd, configPath, useCache).
93
+ * @returns Parsed oxfmt OxfmtOptions or an empty object when missing.
94
+ * @throws {Error} when the config file exists but cannot be parsed.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * const config = await loadOxfmtConfig({ cwd: '/project' })
99
+ * ```
100
+ */
101
+ async function loadOxfmtConfig(options = {}) {
102
+ const useCache = options.useCache !== false;
103
+ const cwd = options.cwd || process.cwd();
104
+ const resolveKey = getResolveCacheKey(cwd, options.configPath);
105
+ const resolvedPath = useCache ? await cachePromise(resolveCache, resolveKey, () => resolveOxfmtrcPath(cwd, options.configPath)) : await resolveOxfmtrcPath(cwd, options.configPath);
106
+ if (!resolvedPath) {
107
+ if (!useCache) return {};
108
+ return cachePromise(configCache, getConfigCacheKey(resolvedPath, resolveKey), () => Promise.resolve({}));
109
+ }
110
+ const loadTask = () => readConfigFromFile(resolvedPath).catch((error) => {
111
+ throw new Error(`Failed to parse oxfmt configuration file at ${resolvedPath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
112
+ });
113
+ if (!useCache) return loadTask();
114
+ return cachePromise(configCache, getConfigCacheKey(resolvedPath, resolveKey), loadTask);
115
+ }
119
116
  //#endregion
120
- export { loadOxfmtConfig, resolveOxfmtrcPath };
117
+ export { loadOxfmtConfig, resolveOxfmtrcPath };
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "load-oxfmt-config",
3
- "type": "module",
4
- "version": "0.1.0",
3
+ "version": "0.2.0",
5
4
  "description": "Load .oxfmtrc.json(c) for oxfmt.",
6
5
  "keywords": [
7
6
  "jsonc-parser",
@@ -11,16 +10,23 @@
11
10
  "oxfmt",
12
11
  "oxfmtrc"
13
12
  ],
13
+ "homepage": "https://github.com/ntnyq/load-oxfmt-config#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/ntnyq/load-oxfmt-config/issues"
16
+ },
14
17
  "license": "MIT",
15
18
  "author": {
16
19
  "name": "ntnyq",
17
20
  "email": "ntnyq13@gmail.com"
18
21
  },
19
- "homepage": "https://github.com/ntnyq/load-oxfmt-config#readme",
20
22
  "repository": "ntnyq/load-oxfmt-config",
21
- "bugs": {
22
- "url": "https://github.com/ntnyq/load-oxfmt-config/issues"
23
- },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "main": "./dist/index.mjs",
29
+ "types": "./dist/index.d.mts",
24
30
  "exports": {
25
31
  "./package.json": "./package.json",
26
32
  ".": {
@@ -28,46 +34,38 @@
28
34
  "default": "./dist/index.mjs"
29
35
  }
30
36
  },
31
- "main": "./dist/index.mjs",
32
- "types": "./dist/index.d.mts",
33
- "files": [
34
- "dist"
35
- ],
36
37
  "publishConfig": {
37
38
  "access": "public"
38
39
  },
39
- "sideEffects": false,
40
- "peerDependencies": {
41
- "oxfmt": "0.x"
42
- },
43
40
  "dependencies": {
44
41
  "jsonc-parser": "^3.3.1"
45
42
  },
46
43
  "devDependencies": {
47
- "@ntnyq/eslint-config": "^6.0.0-beta.6",
48
44
  "@ntnyq/tsconfig": "^3.1.0",
49
- "@types/node": "^25.2.0",
50
- "@typescript/native-preview": "^7.0.0-dev.20260202.1",
51
- "bumpp": "^10.4.0",
52
- "eslint": "^9.39.2",
45
+ "@types/node": "^25.4.0",
46
+ "@typescript/native-preview": "^7.0.0-dev.20260312.1",
47
+ "bumpp": "^10.4.1",
53
48
  "husky": "^9.1.7",
54
49
  "nano-staged": "^0.9.0",
55
50
  "npm-run-all2": "^8.0.4",
56
- "oxfmt": "^0.28.0",
57
- "tsdown": "^0.20.1",
58
- "typescript": "^5.9.3",
51
+ "oxfmt": "^0.39.0",
52
+ "oxlint": "^1.54.0",
53
+ "tsdown": "^0.21.2",
59
54
  "vitest": "^4.0.18"
60
55
  },
56
+ "peerDependencies": {
57
+ "oxfmt": "0.x"
58
+ },
61
59
  "nano-staged": {
62
- "*.{js,ts,mjs,cjs,md,vue,yml,yaml,toml,json}": "eslint --fix",
60
+ "*.{js,ts,mjs,tsx}": "oxlint --fix",
63
61
  "*": "oxfmt --no-error-on-unmatched-pattern"
64
62
  },
65
63
  "scripts": {
66
64
  "build": "tsdown",
67
65
  "dev": "tsdown --watch",
68
- "lint": "eslint",
69
66
  "format": "oxfmt",
70
67
  "format:check": "oxfmt --check",
68
+ "lint": "oxlint",
71
69
  "release": "run-s release:check release:version",
72
70
  "release:check": "run-s format:check lint typecheck test",
73
71
  "release:version": "bumpp",