@nekoyasuii/config 0.1.7 → 0.1.9

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.
@@ -1,37 +1,27 @@
1
1
  // tools/oxlint/config/js-plugins/index.ts
2
2
  import { existsSync } from "node:fs";
3
- import { fileURLToPath } from "node:url";
3
+ import path from "node:path";
4
4
  import { defineConfig } from "oxlint";
5
- var lazueePluginCandidates = [
6
- new URL("../rules/index.js", import.meta.url),
7
- new URL("tools/oxlint/rules/index.js", import.meta.url)
8
- ];
9
- var lazueePluginSpecifier = fileURLToPath(lazueePluginCandidates.find((candidate) => existsSync(candidate)) ?? lazueePluginCandidates[0]);
10
- var antiSlopPluginCandidates = [
11
- new URL("../config/vendors/anti-slop.js", import.meta.url),
12
- new URL("tools/oxlint/config/vendors/anti-slop.js", import.meta.url)
13
- ];
14
- var antiSlopPluginSpecifier = fileURLToPath(antiSlopPluginCandidates.find((candidate) => existsSync(candidate)) ?? antiSlopPluginCandidates[0]);
15
- var noCommentSlopPluginCandidates = [
16
- new URL("../config/vendors/no-comment-slop.js", import.meta.url),
17
- new URL("tools/oxlint/config/vendors/no-comment-slop.js", import.meta.url)
18
- ];
19
- var noCommentSlopPluginSpecifier = fileURLToPath(noCommentSlopPluginCandidates.find((candidate) => existsSync(candidate)) ?? noCommentSlopPluginCandidates[0]);
20
- var shadcnLintPluginCandidates = [
21
- new URL("../config/vendors/shadcn.js", import.meta.url),
22
- new URL("tools/oxlint/config/vendors/shadcn.js", import.meta.url)
23
- ];
24
- var shadcnLintPluginSpecifier = fileURLToPath(shadcnLintPluginCandidates.find((candidate) => existsSync(candidate)) ?? shadcnLintPluginCandidates[0]);
5
+ var packageRoot = (() => {
6
+ let dir = import.meta.dirname;
7
+ while (!existsSync(path.join(dir, "tools", "oxlint")) && dir !== path.dirname(dir))
8
+ dir = path.dirname(dir);
9
+ return dir;
10
+ })();
11
+ var localPlugin = (relative) => path.join(packageRoot, relative);
25
12
  var reactDoctorRules = await import("oxlint-plugin-react-doctor").then(({ ALL_REACT_DOCTOR_RULES }) => ALL_REACT_DOCTOR_RULES).catch(() => null);
26
13
  var jsPluginEntries = [
27
14
  { name: "github", specifier: "eslint-plugin-github" },
28
15
  { name: "sonarjs", specifier: "eslint-plugin-sonarjs" },
29
16
  { name: "react-doctor", specifier: "oxlint-plugin-react-doctor" },
30
17
  { name: "tailwindcss", specifier: "oxlint-tailwindcss" },
31
- { name: "anti-slop", specifier: antiSlopPluginSpecifier },
32
- { name: "no-comment-slop", specifier: noCommentSlopPluginSpecifier },
33
- { name: "shadcn", specifier: shadcnLintPluginSpecifier },
34
- { name: "lazuee", specifier: lazueePluginSpecifier }
18
+ { name: "anti-slop", specifier: localPlugin("tools/oxlint/config/vendors/anti-slop.js") },
19
+ {
20
+ name: "no-comment-slop",
21
+ specifier: localPlugin("tools/oxlint/config/vendors/no-comment-slop.js")
22
+ },
23
+ { name: "shadcn", specifier: localPlugin("tools/oxlint/config/vendors/shadcn.js") },
24
+ { name: "lazuee", specifier: localPlugin("tools/oxlint/rules/index.js") }
35
25
  ];
36
26
  var jsPluginSettings2 = {
37
27
  "react-doctor": {
@@ -4,7 +4,7 @@ import {
4
4
  } from "../../../chunk-k5zpegn9.js";
5
5
  import {
6
6
  selectJsPlugins2
7
- } from "../../../chunk-5vqtdgjy.js";
7
+ } from "../../../chunk-5cy3qjw4.js";
8
8
  import {
9
9
  reactConfig2
10
10
  } from "../../../chunk-cpyyjvfv.js";
@@ -2,7 +2,7 @@ import {
2
2
  jsPluginSettings2,
3
3
  selectJsPlugins2,
4
4
  js_plugins_default
5
- } from "../../../../chunk-5vqtdgjy.js";
5
+ } from "../../../../chunk-5cy3qjw4.js";
6
6
  export {
7
7
  js_plugins_default as default,
8
8
  jsPluginSettings2 as jsPluginSettings,
@@ -0,0 +1,388 @@
1
+ // tools/oxlint/config/vendors/tailwind-worker.ts
2
+ import { workerData } from "node:worker_threads";
3
+ import * as fs from "node:fs";
4
+ import { createRequire } from "node:module";
5
+ import * as path from "node:path";
6
+ import { pathToFileURL } from "node:url";
7
+ function splitVariants(token) {
8
+ if (!token.includes(":"))
9
+ return { variants: [], base: token };
10
+ const segments = [];
11
+ let bracketDepth = 0;
12
+ let parenDepth = 0;
13
+ let current = "";
14
+ for (const char of token) {
15
+ if (char === "[") {
16
+ bracketDepth++;
17
+ } else if (char === "]") {
18
+ bracketDepth--;
19
+ } else if (bracketDepth === 0) {
20
+ if (char === "(") {
21
+ parenDepth++;
22
+ } else if (char === ")") {
23
+ parenDepth--;
24
+ }
25
+ }
26
+ if (char === ":" && bracketDepth === 0 && parenDepth === 0) {
27
+ segments.push(current);
28
+ current = "";
29
+ continue;
30
+ }
31
+ current += char;
32
+ }
33
+ segments.push(current);
34
+ return {
35
+ variants: segments.slice(0, -1),
36
+ base: segments[segments.length - 1]
37
+ };
38
+ }
39
+ var MARKERS = new Set(["group", "peer", "dark", "light"]);
40
+ var COLOR_PREFIX = /^(?:text-shadow|inset-shadow|inset-ring|drop-shadow|scrollbar-(?:thumb|track)|ring-offset|border(?:-[trblxyse]|-[bi][se])?|divide(?:-[xy])?|mask-(?:linear|radial|conic|[trblxy])-(?:from|to)|bg|text|ring|outline|fill|stroke|from|via|to|accent|caret|decoration|placeholder|shadow)-/;
41
+ var PALETTE = [
42
+ "slate",
43
+ "gray",
44
+ "zinc",
45
+ "neutral",
46
+ "stone",
47
+ "mauve",
48
+ "olive",
49
+ "mist",
50
+ "taupe",
51
+ "red",
52
+ "orange",
53
+ "amber",
54
+ "yellow",
55
+ "lime",
56
+ "green",
57
+ "emerald",
58
+ "teal",
59
+ "cyan",
60
+ "sky",
61
+ "blue",
62
+ "indigo",
63
+ "violet",
64
+ "purple",
65
+ "fuchsia",
66
+ "pink",
67
+ "rose"
68
+ ];
69
+ var OPACITY_MODIFIER = /\/(?:[\w.%]+|\[[^\]]*\]|\([^)]*\))$/;
70
+ var PALETTE_RE = new RegExp(`${COLOR_PREFIX.source}(?:${PALETTE.join("|")})-\\d{2,3}(?:${OPACITY_MODIFIER.source})?$`);
71
+ function editDistance(a, b) {
72
+ const rows = a.length + 1;
73
+ const cols = b.length + 1;
74
+ const d = Array.from({ length: rows }, (_, i) => {
75
+ const row = new Array(cols).fill(0);
76
+ row[0] = i;
77
+ return row;
78
+ });
79
+ for (let j = 0;j < cols; j++)
80
+ d[0][j] = j;
81
+ for (let i = 1;i < rows; i++) {
82
+ for (let j = 1;j < cols; j++) {
83
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
84
+ d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
85
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
86
+ d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
87
+ }
88
+ }
89
+ }
90
+ return d[rows - 1][cols - 1];
91
+ }
92
+ function didYouMean(value, candidates, budget = value.length < 6 ? 1 : 2) {
93
+ if (value.length < 3)
94
+ return null;
95
+ let best = null;
96
+ for (const name of candidates) {
97
+ if (name === value)
98
+ return null;
99
+ if (Math.abs(name.length - value.length) > budget)
100
+ continue;
101
+ const distance = editDistance(value, name);
102
+ if (distance > budget)
103
+ continue;
104
+ if (!best || distance < best.distance || distance === best.distance && name.localeCompare(best.name) < 0) {
105
+ best = { name, distance };
106
+ }
107
+ }
108
+ return best?.name ?? null;
109
+ }
110
+ var SIGNATURE_TTL = 1000;
111
+ var loaded = new Map;
112
+ var generations = 0;
113
+ function resolveFrom(base, id) {
114
+ return createRequire(path.join(base, "noop.js")).resolve(id);
115
+ }
116
+ async function loadTailwind(dir) {
117
+ for (const from of [dir, process.cwd()]) {
118
+ let resolved;
119
+ try {
120
+ resolved = resolveFrom(from, "tailwindcss");
121
+ } catch {
122
+ continue;
123
+ }
124
+ const mod = await import(pathToFileURL(resolved).href);
125
+ const api = typeof mod.__unstable__loadDesignSystem === "function" ? mod : typeof mod.default?.__unstable__loadDesignSystem === "function" ? mod.default : null;
126
+ if (api)
127
+ return api;
128
+ throw new Error(`${resolved} is not Tailwind v4 (no __unstable__loadDesignSystem)`);
129
+ }
130
+ return null;
131
+ }
132
+ function existingFile(candidate) {
133
+ try {
134
+ return fs.statSync(candidate).isFile() ? candidate : null;
135
+ } catch {
136
+ return null;
137
+ }
138
+ }
139
+ function stylesheetAt(dir, name) {
140
+ const base = path.join(dir, name);
141
+ return existingFile(base) ?? existingFile(`${base}.css`) ?? existingFile(path.join(base, "index.css"));
142
+ }
143
+ function styleTarget(entry) {
144
+ if (typeof entry === "string")
145
+ return entry;
146
+ if (!entry || typeof entry !== "object")
147
+ return null;
148
+ const record = entry;
149
+ for (const key of ["style", "default"]) {
150
+ const target = styleTarget(record[key]);
151
+ if (target)
152
+ return target;
153
+ }
154
+ return null;
155
+ }
156
+ function exportedStyle(exports, subpath) {
157
+ const exact = styleTarget(exports[`./${subpath}`]);
158
+ if (exact)
159
+ return exact;
160
+ const patterns = Object.keys(exports).filter((key) => key.startsWith("./") && key.includes("*")).sort((a, b) => b.length - a.length);
161
+ for (const key of patterns) {
162
+ const star = key.indexOf("*");
163
+ const prefix = key.slice(2, star);
164
+ const suffix = key.slice(star + 1);
165
+ if (subpath.length < prefix.length + suffix.length || !subpath.startsWith(prefix) || !subpath.endsWith(suffix))
166
+ continue;
167
+ const target = styleTarget(exports[key]);
168
+ if (!target)
169
+ continue;
170
+ return target.replace("*", subpath.slice(prefix.length, subpath.length - suffix.length));
171
+ }
172
+ return null;
173
+ }
174
+ function packageDirectory(base, name) {
175
+ let dir = base;
176
+ for (let depth = 0;depth < 32; depth++) {
177
+ const candidate = path.join(dir, "node_modules", name);
178
+ if (existingFile(path.join(candidate, "package.json")))
179
+ return candidate;
180
+ const parent = path.dirname(dir);
181
+ if (parent === dir)
182
+ break;
183
+ dir = parent;
184
+ }
185
+ return null;
186
+ }
187
+ function resolveStylesheet(base, id) {
188
+ if (id === "tailwindcss")
189
+ return resolveStylesheet(base, "tailwindcss/index.css");
190
+ if (id.startsWith(".") || path.isAbsolute(id)) {
191
+ return stylesheetAt(path.dirname(path.resolve(base, id)), path.basename(id));
192
+ }
193
+ const match = id.match(/^(@[^/]+\/[^/]+|[^/]+)(?:\/(.*))?$/);
194
+ if (!match)
195
+ return null;
196
+ const [, name, subpath] = match;
197
+ const pkgDir = packageDirectory(base, name);
198
+ if (!pkgDir)
199
+ return null;
200
+ let pkg = {};
201
+ try {
202
+ pkg = JSON.parse(fs.readFileSync(path.join(pkgDir, "package.json"), "utf-8"));
203
+ } catch {}
204
+ const exports = pkg.exports;
205
+ if (subpath) {
206
+ const target = exports && typeof exports === "object" ? exportedStyle(exports, subpath) : null;
207
+ if (target)
208
+ return existingFile(path.join(pkgDir, target));
209
+ return stylesheetAt(path.dirname(path.join(pkgDir, subpath)), path.basename(subpath));
210
+ }
211
+ const root = typeof exports === "string" ? exports : exports && typeof exports === "object" ? styleTarget(exports["."] ?? exports) : null;
212
+ for (const target of [root, pkg.style, pkg.main]) {
213
+ if (typeof target !== "string")
214
+ continue;
215
+ const file = existingFile(path.join(pkgDir, target));
216
+ if (file)
217
+ return file;
218
+ }
219
+ return stylesheetAt(pkgDir, "index");
220
+ }
221
+ function realpathOf(file) {
222
+ try {
223
+ return fs.realpathSync.native(file);
224
+ } catch {
225
+ return file;
226
+ }
227
+ }
228
+ function mtimeOf(file) {
229
+ try {
230
+ return fs.statSync(file).mtimeMs;
231
+ } catch {
232
+ return null;
233
+ }
234
+ }
235
+ function signatureOf(files) {
236
+ return files.map((file) => `${file}:${mtimeOf(file) ?? "missing"}`).join("|");
237
+ }
238
+ async function build(cssFile) {
239
+ const dir = path.dirname(cssFile);
240
+ const tailwind = await loadTailwind(dir);
241
+ if (!tailwind) {
242
+ throw new Error(`tailwindcss v4 could not be resolved from ${dir}`);
243
+ }
244
+ const files = [cssFile];
245
+ let modules = 0;
246
+ const css = fs.readFileSync(cssFile, "utf-8");
247
+ const ds = await tailwind.__unstable__loadDesignSystem(css, {
248
+ base: dir,
249
+ async loadStylesheet(id, base) {
250
+ if (/^(?:https?:|data:)/.test(id))
251
+ return { base, content: "" };
252
+ const resolved = resolveStylesheet(base, id);
253
+ if (!resolved) {
254
+ throw new Error(`@import "${id}" could not be resolved from ${base}`);
255
+ }
256
+ const file = realpathOf(resolved);
257
+ files.push(file);
258
+ return {
259
+ base: path.dirname(file),
260
+ content: fs.readFileSync(file, "utf-8")
261
+ };
262
+ },
263
+ async loadModule(id, base) {
264
+ const resolved = resolveFrom(base, id);
265
+ files.push(resolved);
266
+ modules++;
267
+ const url = pathToFileURL(resolved);
268
+ url.searchParams.set("mtime", String(mtimeOf(resolved)));
269
+ const mod = await import(url.href);
270
+ return { base: path.dirname(resolved), module: mod.default ?? mod };
271
+ }
272
+ });
273
+ const variants = ds.getVariants();
274
+ return {
275
+ ds,
276
+ files,
277
+ modules,
278
+ prefix: ds.theme?.prefix ?? null,
279
+ signature: signatureOf(files),
280
+ checkedAt: Date.now(),
281
+ generation: ++generations,
282
+ classNames: null,
283
+ staticVariants: variants.filter((v) => !v.isArbitrary && !v.values.length).map((v) => v.name),
284
+ functionalVariants: variants.filter((v) => v.isArbitrary || v.values.length).map((v) => v.name)
285
+ };
286
+ }
287
+ async function designSystemFor(cssFile) {
288
+ const cached = loaded.get(cssFile);
289
+ const now = Date.now();
290
+ if (cached) {
291
+ if (now - cached.checkedAt < SIGNATURE_TTL)
292
+ return cached;
293
+ if (signatureOf(cached.files) === cached.signature) {
294
+ cached.checkedAt = now;
295
+ return cached;
296
+ }
297
+ }
298
+ const fresh = await build(cssFile);
299
+ loaded.set(cssFile, fresh);
300
+ return fresh;
301
+ }
302
+ function classNamesOf(system) {
303
+ if (!system.classNames) {
304
+ system.classNames = system.ds.getClassList().map((entry) => Array.isArray(entry) ? entry[0] : entry);
305
+ }
306
+ return system.classNames;
307
+ }
308
+ function variantKnown(system, variant) {
309
+ const name = variant.replace(/\/.*$/, "");
310
+ if (name.startsWith("[") || name.startsWith("@"))
311
+ return true;
312
+ if (system.staticVariants.includes(name))
313
+ return true;
314
+ return system.functionalVariants.some((prefix) => name === prefix || name.startsWith(`${prefix}-`));
315
+ }
316
+ function suggestionFor(system, candidate) {
317
+ const { variants, base } = splitVariants(candidate);
318
+ const prefixed = system.prefix !== null && variants[0] === system.prefix;
319
+ const probe = prefixed ? `${system.prefix}:${base}` : base;
320
+ if (variants.length && system.ds.candidatesToCss([probe])[0] !== null) {
321
+ let changed = false;
322
+ const fixed = variants.map((variant, i) => {
323
+ if (prefixed && i === 0)
324
+ return variant;
325
+ if (variantKnown(system, variant))
326
+ return variant;
327
+ const meant = didYouMean(variant, system.staticVariants, 1);
328
+ if (!meant)
329
+ return variant;
330
+ changed = true;
331
+ return meant;
332
+ });
333
+ return changed ? [...fixed, base].join(":") : null;
334
+ }
335
+ const bare = base.replace(/^!/, "").replace(/!$/, "").replace(/^-/, "");
336
+ const meant = didYouMean(bare, classNamesOf(system));
337
+ if (!meant)
338
+ return null;
339
+ const rebuilt = base.replace(bare, meant);
340
+ return [...variants, rebuilt].join(":");
341
+ }
342
+ function baseKnownOf(system, candidate) {
343
+ const { variants, base } = splitVariants(candidate);
344
+ if (!variants.length)
345
+ return false;
346
+ const bare = system.prefix && variants[0] === system.prefix ? `${system.prefix}:${base}` : base;
347
+ if (variants.length === (bare === base ? 0 : 1))
348
+ return false;
349
+ return system.ds.candidatesToCss([bare])[0] !== null;
350
+ }
351
+ async function query(cssFile, candidates) {
352
+ let system;
353
+ try {
354
+ system = await designSystemFor(cssFile);
355
+ } catch (error) {
356
+ return { ok: false, reason: error.message };
357
+ }
358
+ const css = system.ds.candidatesToCss(candidates);
359
+ const unknown = [];
360
+ for (let i = 0;i < candidates.length; i++) {
361
+ if (css[i] !== null)
362
+ continue;
363
+ unknown.push({
364
+ token: candidates[i],
365
+ suggestion: suggestionFor(system, candidates[i]),
366
+ baseKnown: baseKnownOf(system, candidates[i])
367
+ });
368
+ }
369
+ return {
370
+ ok: true,
371
+ generation: system.generation,
372
+ hasModules: system.modules > 0,
373
+ unknown
374
+ };
375
+ }
376
+ var port = workerData.port;
377
+ port.on("message", async ({ id, cssFile, candidates, shared }) => {
378
+ let answer;
379
+ try {
380
+ answer = await query(cssFile, candidates);
381
+ } catch (error) {
382
+ answer = { ok: false, reason: error.message };
383
+ }
384
+ port.postMessage({ id, answer });
385
+ const flag = new Int32Array(shared);
386
+ Atomics.store(flag, 0, 1);
387
+ Atomics.notify(flag, 0);
388
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nekoyasuii/config",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Shared TypeScript, Oxlint, and Oxfmt configs for my projects.",
5
5
  "files": [
6
6
  "dist",