oxlint-tailwindcss 1.3.1 → 1.3.2

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 CHANGED
@@ -125,7 +125,9 @@ order:
125
125
  ```
126
126
 
127
127
  **Pattern B — one `.oxlintrc.json` per package**, each with its own string `entryPoint`. oxlint
128
- resolves the closest config to the file being linted.
128
+ resolves the closest config to the file being linted, and a relative `entryPoint` is anchored to
129
+ that config's directory (falling back to the working directory), so it resolves to the same CSS
130
+ whether oxlint runs from the package (CLI) or the workspace root (editor).
129
131
 
130
132
  See the full [monorepo guide](https://oxlint-tailwindcss.pages.dev/monorepo) for examples of both.
131
133
 
package/dist/index.cjs CHANGED
@@ -1991,6 +1991,19 @@ function safeFilename(context) {
1991
1991
  }
1992
1992
  }
1993
1993
  /**
1994
+ * Safely read `context.cwd`, falling back to `process.cwd()`. Same try/catch
1995
+ * pattern as the other accessors (the getter throws in `createOnce` on older
1996
+ * oxlint). The fallback keeps relative-path resolution working even when the
1997
+ * linter never populates `cwd`.
1998
+ */
1999
+ function safeCwd(context) {
2000
+ try {
2001
+ return context.cwd ?? process.cwd();
2002
+ } catch {
2003
+ return process.cwd();
2004
+ }
2005
+ }
2006
+ /**
1994
2007
  * Lazily memoize a compiled options object across visitor calls.
1995
2008
  *
1996
2009
  * Every rule with options reinvents:
@@ -2106,6 +2119,76 @@ function resolveByGlobMapping(mappings, filePath, baseDir) {
2106
2119
  return null;
2107
2120
  }
2108
2121
  /**
2122
+ * oxlint discovers nested configuration by walking up from each linted file
2123
+ * looking for files with these names. We mirror that walk to find the config
2124
+ * directory a relative `entryPoint` should be anchored to.
2125
+ */
2126
+ const OXLINT_CONFIG_NAMES = [".oxlintrc.json"];
2127
+ /** Memoizes the nearest-config walk per starting directory (cleared in tests). */
2128
+ const nearestConfigDirCache = /* @__PURE__ */ new Map();
2129
+ /**
2130
+ * Find the directory of the **nearest** enclosing oxlint config, walking up
2131
+ * from `filePath` toward the filesystem root. Returns `undefined` if none is
2132
+ * found. This is the config oxlint applies to the file under its default
2133
+ * nested-config discovery, so a relative `entryPoint` declared in it is meant
2134
+ * to resolve relative to that directory — not the process CWD, which differs
2135
+ * between the CLI (`cd package && oxlint`) and an editor (CWD = workspace
2136
+ * root). See issue #39.
2137
+ *
2138
+ * Stops at the first match (early exit), so in the common case it touches only
2139
+ * the file's package, not the whole path to root.
2140
+ */
2141
+ function nearestConfigDir(filePath) {
2142
+ const start = (0, node_path.dirname)((0, node_path.resolve)(filePath));
2143
+ const cached = nearestConfigDirCache.get(start);
2144
+ if (cached !== void 0) return cached ?? void 0;
2145
+ let dir = start;
2146
+ for (;;) {
2147
+ if (OXLINT_CONFIG_NAMES.some((name) => (0, node_fs.existsSync)((0, node_path.resolve)(dir, name)))) {
2148
+ nearestConfigDirCache.set(start, dir);
2149
+ return dir;
2150
+ }
2151
+ const parent = (0, node_path.dirname)(dir);
2152
+ if (parent === dir) break;
2153
+ dir = parent;
2154
+ }
2155
+ nearestConfigDirCache.set(start, null);
2156
+ }
2157
+ /**
2158
+ * Resolve a string `entryPoint` (from `settings` or a rule option) to an
2159
+ * absolute path.
2160
+ *
2161
+ * Absolute paths are returned normalized and untouched. A **relative** path is
2162
+ * anchored to the directory of the nearest enclosing `.oxlintrc.json` (the
2163
+ * config oxlint applies to the file), with the CWD as a single fallback:
2164
+ *
2165
+ * 1. nearest config dir — if its candidate file exists, use it;
2166
+ * 2. CWD — if its candidate file exists, use it;
2167
+ * 3. otherwise resolve against the nearest config dir (else CWD) so the
2168
+ * downstream "could not stat" diagnostic names the package-local path the
2169
+ * user most likely intended — i.e. fail loud rather than silently reach
2170
+ * past the nearest config into an unrelated ancestor.
2171
+ *
2172
+ * Deliberately a two-step [config dir → CWD] resolution, NOT a walk through
2173
+ * every ancestor config: the v1 charter is deterministic + fail-loud, and a
2174
+ * multi-ancestor existence probe would let a coincidentally same-named CSS in
2175
+ * an unrelated parent silently shadow a genuine misconfiguration.
2176
+ *
2177
+ * This makes resolution independent of where oxlint is launched from: the
2178
+ * editor (CWD = workspace root) and the CLI (CWD = package dir) now agree on
2179
+ * the same CSS file in a Pattern-B monorepo (issue #39).
2180
+ */
2181
+ function resolveStringEntryPoint(entry, filePath, cwd) {
2182
+ if ((0, node_path.isAbsolute)(entry)) return (0, node_path.resolve)(entry);
2183
+ const configDir = filePath ? nearestConfigDir(filePath) : void 0;
2184
+ const bases = configDir && configDir !== cwd ? [configDir, cwd] : [cwd];
2185
+ for (const base of bases) {
2186
+ const candidate = (0, node_path.resolve)(base, entry);
2187
+ if ((0, node_fs.existsSync)(candidate)) return candidate;
2188
+ }
2189
+ return (0, node_path.resolve)(bases[0], entry);
2190
+ }
2191
+ /**
2109
2192
  * Extract `rootFontSize` from `settings.tailwindcss` (default: 16).
2110
2193
  */
2111
2194
  function rootFontSizeFromSettings(settings) {
@@ -2139,7 +2222,7 @@ function getLoadedDesignSystem(cssPath, settings) {
2139
2222
  try {
2140
2223
  mtime = (0, node_fs.statSync)(resolvedPath).mtimeMs;
2141
2224
  } catch (cause) {
2142
- throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable. The path is resolved relative to the oxlint working directory.", { cause: cause instanceof Error ? cause : void 0 });
2225
+ throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable. A relative `entryPoint` is resolved against the nearest `.oxlintrc.json` directory, falling back to the oxlint working directory.", { cause: cause instanceof Error ? cause : void 0 });
2143
2226
  }
2144
2227
  const cached = dsCache.get(resolvedPath);
2145
2228
  if (cached && cached.mtime === mtime) return {
@@ -2178,6 +2261,10 @@ function getLoadedDesignSystem(cssPath, settings) {
2178
2261
  * 3. `settings.tailwindcss.entryPoint` as an `EntryPointMapping[]` —
2179
2262
  * first matching glob (relative to CWD) wins.
2180
2263
  *
2264
+ * A relative string entry (1 or 2) is anchored to the nearest enclosing
2265
+ * `.oxlintrc.json` directory rather than the CWD, so editor and CLI runs agree
2266
+ * in Pattern-B monorepos (issue #39); see `resolveStringEntryPoint`.
2267
+ *
2181
2268
  * If none of those produce an entry point for the current file, throws
2182
2269
  * `MissingEntryPointError`. If the resolved CSS fails to load, throws
2183
2270
  * `DesignSystemLoadError`. Both extend `OxlintTailwindError` and are
@@ -2208,7 +2295,7 @@ function createLazyLoader(context) {
2208
2295
  lastResult = void 0;
2209
2296
  lastError = void 0;
2210
2297
  try {
2211
- lastResult = getLoadedDesignSystem(resolveEntryPointForFile(ruleOptionEntry, entryPointFromSettings(settings), filePath), settings);
2298
+ lastResult = getLoadedDesignSystem(resolveEntryPointForFile(ruleOptionEntry, entryPointFromSettings(settings), filePath, safeCwd(context)), settings);
2212
2299
  } catch (err) {
2213
2300
  if (isFatalError(err) && err instanceof Error) lastError = err;
2214
2301
  throw err;
@@ -2218,18 +2305,21 @@ function createLazyLoader(context) {
2218
2305
  };
2219
2306
  }
2220
2307
  /**
2221
- * Pure resolution from (rule option, settings entry, file path) to a CSS
2222
- * entry-point path. Exported for testability.
2308
+ * Pure resolution from (rule option, settings entry, file path, cwd) to an
2309
+ * absolute CSS entry-point path. Exported for testability.
2310
+ *
2311
+ * Relative string entries are anchored via `resolveStringEntryPoint` (nearest
2312
+ * `.oxlintrc.json` dir, then `cwd`); mapping arrays match relative to `cwd`.
2223
2313
  *
2224
2314
  * Throws `MissingEntryPointError` if nothing resolves. The error message
2225
2315
  * names the file so the user knows which one tripped the configuration.
2226
2316
  */
2227
- function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath) {
2228
- if (ruleOptionEntry) return ruleOptionEntry;
2229
- if (typeof settingsEntry === "string") return settingsEntry;
2317
+ function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath, cwd = process.cwd()) {
2318
+ if (ruleOptionEntry) return resolveStringEntryPoint(ruleOptionEntry, filePath, cwd);
2319
+ if (typeof settingsEntry === "string") return resolveStringEntryPoint(settingsEntry, filePath, cwd);
2230
2320
  if (Array.isArray(settingsEntry)) {
2231
2321
  if (!filePath) throw new MissingEntryPointError("`settings.tailwindcss.entryPoint` is a mapping array but no file path is available to match against.", "This usually means the rule ran outside the linter context. Open an issue if you see this in a real lint run.");
2232
- const matched = resolveByGlobMapping(settingsEntry, filePath, process.cwd());
2322
+ const matched = resolveByGlobMapping(settingsEntry, filePath, cwd);
2233
2323
  if (matched) return matched;
2234
2324
  throw new MissingEntryPointError(`No \`entryPoint\` mapping matched \`${filePath}\`.`, "Add a mapping covering this file to `settings.tailwindcss.entryPoint`, or use a `\"**\"` fallback entry.");
2235
2325
  }
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { definePlugin, defineRule } from "@oxlint/plugins";
3
3
  import { Worker, threadId } from "node:worker_threads";
4
4
  import { createHash } from "node:crypto";
5
5
  import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync } from "node:fs";
6
- import { dirname, join, relative, resolve } from "node:path";
6
+ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
7
7
  import { tmpdir, userInfo } from "node:os";
8
8
  //#region \0rolldown/runtime.js
9
9
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
@@ -1995,6 +1995,19 @@ function safeFilename(context) {
1995
1995
  }
1996
1996
  }
1997
1997
  /**
1998
+ * Safely read `context.cwd`, falling back to `process.cwd()`. Same try/catch
1999
+ * pattern as the other accessors (the getter throws in `createOnce` on older
2000
+ * oxlint). The fallback keeps relative-path resolution working even when the
2001
+ * linter never populates `cwd`.
2002
+ */
2003
+ function safeCwd(context) {
2004
+ try {
2005
+ return context.cwd ?? process.cwd();
2006
+ } catch {
2007
+ return process.cwd();
2008
+ }
2009
+ }
2010
+ /**
1998
2011
  * Lazily memoize a compiled options object across visitor calls.
1999
2012
  *
2000
2013
  * Every rule with options reinvents:
@@ -2110,6 +2123,76 @@ function resolveByGlobMapping(mappings, filePath, baseDir) {
2110
2123
  return null;
2111
2124
  }
2112
2125
  /**
2126
+ * oxlint discovers nested configuration by walking up from each linted file
2127
+ * looking for files with these names. We mirror that walk to find the config
2128
+ * directory a relative `entryPoint` should be anchored to.
2129
+ */
2130
+ const OXLINT_CONFIG_NAMES = [".oxlintrc.json"];
2131
+ /** Memoizes the nearest-config walk per starting directory (cleared in tests). */
2132
+ const nearestConfigDirCache = /* @__PURE__ */ new Map();
2133
+ /**
2134
+ * Find the directory of the **nearest** enclosing oxlint config, walking up
2135
+ * from `filePath` toward the filesystem root. Returns `undefined` if none is
2136
+ * found. This is the config oxlint applies to the file under its default
2137
+ * nested-config discovery, so a relative `entryPoint` declared in it is meant
2138
+ * to resolve relative to that directory — not the process CWD, which differs
2139
+ * between the CLI (`cd package && oxlint`) and an editor (CWD = workspace
2140
+ * root). See issue #39.
2141
+ *
2142
+ * Stops at the first match (early exit), so in the common case it touches only
2143
+ * the file's package, not the whole path to root.
2144
+ */
2145
+ function nearestConfigDir(filePath) {
2146
+ const start = dirname(resolve(filePath));
2147
+ const cached = nearestConfigDirCache.get(start);
2148
+ if (cached !== void 0) return cached ?? void 0;
2149
+ let dir = start;
2150
+ for (;;) {
2151
+ if (OXLINT_CONFIG_NAMES.some((name) => existsSync(resolve(dir, name)))) {
2152
+ nearestConfigDirCache.set(start, dir);
2153
+ return dir;
2154
+ }
2155
+ const parent = dirname(dir);
2156
+ if (parent === dir) break;
2157
+ dir = parent;
2158
+ }
2159
+ nearestConfigDirCache.set(start, null);
2160
+ }
2161
+ /**
2162
+ * Resolve a string `entryPoint` (from `settings` or a rule option) to an
2163
+ * absolute path.
2164
+ *
2165
+ * Absolute paths are returned normalized and untouched. A **relative** path is
2166
+ * anchored to the directory of the nearest enclosing `.oxlintrc.json` (the
2167
+ * config oxlint applies to the file), with the CWD as a single fallback:
2168
+ *
2169
+ * 1. nearest config dir — if its candidate file exists, use it;
2170
+ * 2. CWD — if its candidate file exists, use it;
2171
+ * 3. otherwise resolve against the nearest config dir (else CWD) so the
2172
+ * downstream "could not stat" diagnostic names the package-local path the
2173
+ * user most likely intended — i.e. fail loud rather than silently reach
2174
+ * past the nearest config into an unrelated ancestor.
2175
+ *
2176
+ * Deliberately a two-step [config dir → CWD] resolution, NOT a walk through
2177
+ * every ancestor config: the v1 charter is deterministic + fail-loud, and a
2178
+ * multi-ancestor existence probe would let a coincidentally same-named CSS in
2179
+ * an unrelated parent silently shadow a genuine misconfiguration.
2180
+ *
2181
+ * This makes resolution independent of where oxlint is launched from: the
2182
+ * editor (CWD = workspace root) and the CLI (CWD = package dir) now agree on
2183
+ * the same CSS file in a Pattern-B monorepo (issue #39).
2184
+ */
2185
+ function resolveStringEntryPoint(entry, filePath, cwd) {
2186
+ if (isAbsolute(entry)) return resolve(entry);
2187
+ const configDir = filePath ? nearestConfigDir(filePath) : void 0;
2188
+ const bases = configDir && configDir !== cwd ? [configDir, cwd] : [cwd];
2189
+ for (const base of bases) {
2190
+ const candidate = resolve(base, entry);
2191
+ if (existsSync(candidate)) return candidate;
2192
+ }
2193
+ return resolve(bases[0], entry);
2194
+ }
2195
+ /**
2113
2196
  * Extract `rootFontSize` from `settings.tailwindcss` (default: 16).
2114
2197
  */
2115
2198
  function rootFontSizeFromSettings(settings) {
@@ -2143,7 +2226,7 @@ function getLoadedDesignSystem(cssPath, settings) {
2143
2226
  try {
2144
2227
  mtime = statSync(resolvedPath).mtimeMs;
2145
2228
  } catch (cause) {
2146
- throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable. The path is resolved relative to the oxlint working directory.", { cause: cause instanceof Error ? cause : void 0 });
2229
+ throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable. A relative `entryPoint` is resolved against the nearest `.oxlintrc.json` directory, falling back to the oxlint working directory.", { cause: cause instanceof Error ? cause : void 0 });
2147
2230
  }
2148
2231
  const cached = dsCache.get(resolvedPath);
2149
2232
  if (cached && cached.mtime === mtime) return {
@@ -2182,6 +2265,10 @@ function getLoadedDesignSystem(cssPath, settings) {
2182
2265
  * 3. `settings.tailwindcss.entryPoint` as an `EntryPointMapping[]` —
2183
2266
  * first matching glob (relative to CWD) wins.
2184
2267
  *
2268
+ * A relative string entry (1 or 2) is anchored to the nearest enclosing
2269
+ * `.oxlintrc.json` directory rather than the CWD, so editor and CLI runs agree
2270
+ * in Pattern-B monorepos (issue #39); see `resolveStringEntryPoint`.
2271
+ *
2185
2272
  * If none of those produce an entry point for the current file, throws
2186
2273
  * `MissingEntryPointError`. If the resolved CSS fails to load, throws
2187
2274
  * `DesignSystemLoadError`. Both extend `OxlintTailwindError` and are
@@ -2212,7 +2299,7 @@ function createLazyLoader(context) {
2212
2299
  lastResult = void 0;
2213
2300
  lastError = void 0;
2214
2301
  try {
2215
- lastResult = getLoadedDesignSystem(resolveEntryPointForFile(ruleOptionEntry, entryPointFromSettings(settings), filePath), settings);
2302
+ lastResult = getLoadedDesignSystem(resolveEntryPointForFile(ruleOptionEntry, entryPointFromSettings(settings), filePath, safeCwd(context)), settings);
2216
2303
  } catch (err) {
2217
2304
  if (isFatalError(err) && err instanceof Error) lastError = err;
2218
2305
  throw err;
@@ -2222,18 +2309,21 @@ function createLazyLoader(context) {
2222
2309
  };
2223
2310
  }
2224
2311
  /**
2225
- * Pure resolution from (rule option, settings entry, file path) to a CSS
2226
- * entry-point path. Exported for testability.
2312
+ * Pure resolution from (rule option, settings entry, file path, cwd) to an
2313
+ * absolute CSS entry-point path. Exported for testability.
2314
+ *
2315
+ * Relative string entries are anchored via `resolveStringEntryPoint` (nearest
2316
+ * `.oxlintrc.json` dir, then `cwd`); mapping arrays match relative to `cwd`.
2227
2317
  *
2228
2318
  * Throws `MissingEntryPointError` if nothing resolves. The error message
2229
2319
  * names the file so the user knows which one tripped the configuration.
2230
2320
  */
2231
- function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath) {
2232
- if (ruleOptionEntry) return ruleOptionEntry;
2233
- if (typeof settingsEntry === "string") return settingsEntry;
2321
+ function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath, cwd = process.cwd()) {
2322
+ if (ruleOptionEntry) return resolveStringEntryPoint(ruleOptionEntry, filePath, cwd);
2323
+ if (typeof settingsEntry === "string") return resolveStringEntryPoint(settingsEntry, filePath, cwd);
2234
2324
  if (Array.isArray(settingsEntry)) {
2235
2325
  if (!filePath) throw new MissingEntryPointError("`settings.tailwindcss.entryPoint` is a mapping array but no file path is available to match against.", "This usually means the rule ran outside the linter context. Open an issue if you see this in a real lint run.");
2236
- const matched = resolveByGlobMapping(settingsEntry, filePath, process.cwd());
2326
+ const matched = resolveByGlobMapping(settingsEntry, filePath, cwd);
2237
2327
  if (matched) return matched;
2238
2328
  throw new MissingEntryPointError(`No \`entryPoint\` mapping matched \`${filePath}\`.`, "Add a mapping covering this file to `settings.tailwindcss.entryPoint`, or use a `\"**\"` fallback entry.");
2239
2329
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxlint-tailwindcss",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Tailwind CSS linting rules for oxlint",
5
5
  "keywords": [
6
6
  "css",