@kirill.konshin/lint 0.8.9 → 0.8.10
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 +5 -5
- package/dist/configs/base.js +2 -4
- package/dist/configs/nx.d.ts +3 -1
- package/dist/configs/nx.js +4 -4
- package/dist/configs/promise.js +2 -6
- package/dist/configs/react.d.ts +4 -2
- package/dist/configs/react.js +12 -31
- package/dist/configs/testing.js +32 -18
- package/dist/configs/turbo.d.ts +4 -3
- package/dist/configs/turbo.js +5 -7
- package/dist/configs/unicorn.js +2 -2
- package/dist/conventions.d.ts +26 -1
- package/dist/conventions.js +66 -1
- package/dist/exts.d.ts +3 -0
- package/dist/exts.js +4 -1
- package/dist/gates.d.ts +5 -5
- package/dist/gates.js +36 -24
- package/dist/graphify.d.ts +10 -5
- package/dist/graphify.js +35 -40
- package/dist/index.d.ts +6 -6
- package/dist/index.js +7 -8
- package/dist/lib.d.ts +37 -21
- package/dist/lib.js +104 -71
- package/dist/lintPrepare.d.ts +11 -8
- package/dist/lintPrepare.js +39 -37
- package/dist/runCommand.d.ts +24 -0
- package/dist/runCommand.js +12 -0
- package/dist/textBlocks.d.ts +7 -0
- package/dist/textBlocks.js +12 -0
- package/dist/vitePlus.js +34 -68
- package/package.json +1 -1
- package/skills/spec-tools/scripts/cli.js +700 -627
package/dist/graphify.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphifyOptions } from "./config.js";
|
|
2
|
-
import { RunCommand } from "./
|
|
2
|
+
import { RunCommand } from "./runCommand.js";
|
|
3
3
|
//#region src/graphify.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* graphify (https://graphify.com, PyPI `graphifyy`) for `lint-prepare`, by the `graphify` option of `lint.config.ts`:
|
|
@@ -48,11 +48,16 @@ export declare function removeGraphifySkills(cwd: string): void;
|
|
|
48
48
|
/** `content` without the section that starts at the exact line `heading` and ends before the next `boundary` line. */
|
|
49
49
|
export declare function removeSection(content: string, heading: string, boundary: string): string;
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* to reach `.venv`.
|
|
51
|
+
* graphify's AGENTS.md section for `venv`, kept by `lint-prepare` from one generation to the next: `## graphify`, which
|
|
52
|
+
* `graphify claude install` fills (it replaces up to the next `## ` line), then the `## graphify virtualenv` heading,
|
|
53
|
+
* which ends it, with how to reach `.venv`.
|
|
54
54
|
*/
|
|
55
|
-
export declare
|
|
55
|
+
export declare const GRAPHIFY_SECTION: {
|
|
56
|
+
tool: string;
|
|
57
|
+
start: string;
|
|
58
|
+
end: string;
|
|
59
|
+
tail: string;
|
|
60
|
+
};
|
|
56
61
|
/** A graphify hook command, any executable path, run from `.venv`. */
|
|
57
62
|
export declare const toVenvCommand: (command: string) => string;
|
|
58
63
|
/**
|
package/dist/graphify.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { asOptions } from "./lib.js";
|
|
1
2
|
import { GRAPHIFY_VERSION } from "./config.js";
|
|
3
|
+
import { runOrWarn } from "./runCommand.js";
|
|
4
|
+
import { findBlock } from "./textBlocks.js";
|
|
2
5
|
import fs from "node:fs";
|
|
3
6
|
import path from "node:path";
|
|
4
7
|
//#region src/graphify.ts
|
|
@@ -20,17 +23,10 @@ const QUIET = { stdio: [
|
|
|
20
23
|
const isWindows = process.platform === "win32";
|
|
21
24
|
/** The mode the `graphify` option asks for, and the version `venv` installs. */
|
|
22
25
|
function graphifyMode(option) {
|
|
23
|
-
|
|
24
|
-
mode: "detect",
|
|
25
|
-
version: GRAPHIFY_VERSION
|
|
26
|
-
};
|
|
27
|
-
if (typeof option === "boolean") return {
|
|
28
|
-
mode: option ? "venv" : "off",
|
|
29
|
-
version: GRAPHIFY_VERSION
|
|
30
|
-
};
|
|
26
|
+
const { enabled, version = GRAPHIFY_VERSION } = asOptions(option);
|
|
31
27
|
return {
|
|
32
|
-
mode:
|
|
33
|
-
version
|
|
28
|
+
mode: enabled === void 0 ? "detect" : enabled ? "venv" : "off",
|
|
29
|
+
version
|
|
34
30
|
};
|
|
35
31
|
}
|
|
36
32
|
/** The absolute path of `command` on `PATH`, undefined when there is none. */
|
|
@@ -48,15 +44,16 @@ function findOnPath(command, env = process.env) {
|
|
|
48
44
|
const venvExe = (cwd) => isWindows ? path.join(cwd, VENV, "Scripts", "graphify.exe") : path.join(cwd, VENV, "bin", "graphify");
|
|
49
45
|
/** A skill folder graphify installed: it holds graphify's version stamp. */
|
|
50
46
|
const isGraphifySkill = (dir) => fs.existsSync(path.join(dir, VERSION_STAMP));
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
const runQuiet = (run, command, args, cwd) => runOrWarn(run, {
|
|
48
|
+
command,
|
|
49
|
+
args,
|
|
50
|
+
options: {
|
|
53
51
|
cwd,
|
|
54
52
|
...QUIET
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
53
|
+
},
|
|
54
|
+
label: `${path.basename(command)} ${args.join(" ")}`,
|
|
55
|
+
what: "graphify"
|
|
56
|
+
});
|
|
60
57
|
/**
|
|
61
58
|
* Create the project `.venv` with `uv` (kept when it exists) and install `graphifyy==version` into it. Throws when `uv`
|
|
62
59
|
* is missing: `graphify: true` asks for it.
|
|
@@ -114,22 +111,16 @@ function removeSection(content, heading, boundary) {
|
|
|
114
111
|
return `${[...lines.slice(0, start), ...length === -1 ? [] : lines.slice(start + 1 + length)].join("\n").replace(/\n{3,}/g, "\n\n").trim()}\n`;
|
|
115
112
|
}
|
|
116
113
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* to reach `.venv`.
|
|
114
|
+
* graphify's AGENTS.md section for `venv`, kept by `lint-prepare` from one generation to the next: `## graphify`, which
|
|
115
|
+
* `graphify claude install` fills (it replaces up to the next `## ` line), then the `## graphify virtualenv` heading,
|
|
116
|
+
* which ends it, with how to reach `.venv`.
|
|
120
117
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
"",
|
|
128
|
-
VENV_HEADING,
|
|
129
|
-
"",
|
|
130
|
-
`graphify is installed in the project \`${VENV}\`, not on \`PATH\`: run every \`graphify\` and \`python3\` command of the graphify skill as \`source ${VENV}/bin/activate && <command>\`, from the repository root.`
|
|
131
|
-
].join("\n");
|
|
132
|
-
}
|
|
118
|
+
const GRAPHIFY_SECTION = {
|
|
119
|
+
tool: "graphify",
|
|
120
|
+
start: SECTION_HEADING,
|
|
121
|
+
end: VENV_HEADING,
|
|
122
|
+
tail: `graphify is installed in the project \`${VENV}\`, not on \`PATH\`: run every \`graphify\` and \`python3\` command of the graphify skill as \`source ${VENV}/bin/activate && <command>\`, from the repository root.`
|
|
123
|
+
};
|
|
133
124
|
const isGraphifyCommand = (command = "") => command.includes("graphify") && /\bhook-(guard|check)\b/.test(command);
|
|
134
125
|
/** A graphify hook command, any executable path, run from `.venv`. */
|
|
135
126
|
const toVenvCommand = (command) => command.replace(/^(?:"[^"]*"|\S+)(?=\s+hook-(?:guard|check)\b)/, VENV_HOOK_EXE);
|
|
@@ -191,9 +182,8 @@ function installGraphifyInstructions(cwd, exe, run) {
|
|
|
191
182
|
*/
|
|
192
183
|
function updateGitignoreBlock(content, entries) {
|
|
193
184
|
const lines = content.split("\n");
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
const text = (to === -1 ? lines : [...lines.slice(0, from), ...lines.slice(to + 1)]).join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
185
|
+
const found = findBlock(lines, GITIGNORE_BEGIN, GITIGNORE_END);
|
|
186
|
+
const text = (found ? [...lines.slice(0, found[0]), ...lines.slice(found[1] + 1)] : lines).join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
197
187
|
const block = entries.length ? [
|
|
198
188
|
GITIGNORE_BEGIN,
|
|
199
189
|
...entries,
|
|
@@ -250,11 +240,16 @@ function finishGraphify(cwd, { mode, exe }, run) {
|
|
|
250
240
|
else if (exe) installGraphifyInstructions(cwd, exe, run);
|
|
251
241
|
if (!exe) return;
|
|
252
242
|
console.log("Building the graphify code graph (graphify update .)");
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
243
|
+
runOrWarn(run, {
|
|
244
|
+
command: exe,
|
|
245
|
+
args: ["update", "."],
|
|
246
|
+
options: {
|
|
247
|
+
cwd,
|
|
248
|
+
stdio: "inherit"
|
|
249
|
+
},
|
|
250
|
+
label: "graphify update .",
|
|
251
|
+
what: "the code graph"
|
|
256
252
|
});
|
|
257
|
-
if (result.status !== 0) console.warn(`[lint-prepare] graphify update failed (${result.error?.message ?? `exit code ${result.status}`}): run "graphify update ." to retry`);
|
|
258
253
|
}
|
|
259
254
|
//#endregion
|
|
260
|
-
export { GRAPHIFY_SKILL, findOnPath, finishGraphify,
|
|
255
|
+
export { GRAPHIFY_SECTION, GRAPHIFY_SKILL, findOnPath, finishGraphify, graphifyMode, installGraphifyInstructions, installGraphifySkills, installGraphifyVenv, isGraphifySkill, removeGraphifySkills, removeSection, setUpGraphify, toVenvCommand, updateClaudeSettings, updateGitignoreBlock, updateGraphifyHooks, venvExe, writeGitignoreBlock };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { eslintExts, eslintExtsRaw, markupExtsRaw, prettierExts, prettierExtsRaw, tsExts, tsExtsRaw } from "./exts.js";
|
|
2
|
-
import { GLOBAL_IGNORES, asOptions, findNextRoots, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, isPackageResolvable, packageDirOf, scanWorkspace, toolGate, workspaceDependsOn } from "./lib.js";
|
|
1
|
+
import { eslintExts, eslintExtsRaw, markupExtsRaw, prettierExts, prettierExtsRaw, testFiles, tsExts, tsExtsRaw, tsFiles } from "./exts.js";
|
|
2
|
+
import { GLOBAL_IGNORES, asOptions, detectionOf, findNextRoots, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, isPackageResolvable, packageDirOf, scanWorkspace, toolGate, workspaceDependsOn } from "./lib.js";
|
|
3
3
|
import { DEFAULT_LINT_CONFIG, DefaultIgnoreOptions, DetectionOptions, EslintOptions, GRAPHIFY_VERSION, GraphifyOptions, LINT_CONFIG_FILE, LintConfig, NextOptions, SkillSourceOptions, SkillsConfig, TailwindOptions, ToggleOptions, TypeAwareOptions, VitePlusOptions, defineLintConfig, loadLintConfig, mergeLintConfig, resolveLintConfig } from "./config.js";
|
|
4
4
|
import { baseConfig, defaultIgnoreConfig, includeIgnoreFile } from "./configs/base.js";
|
|
5
5
|
import { importSortConfig, importXConfig, unusedImportsConfig } from "./configs/imports.js";
|
|
6
|
-
import {
|
|
6
|
+
import { loadNxPlugin, nxConfig } from "./configs/nx.js";
|
|
7
7
|
import { prettierConfig } from "./configs/prettier.js";
|
|
8
8
|
import { promiseConfig } from "./configs/promise.js";
|
|
9
|
-
import { nextBaseConfig, nextConfig, nextOverridesConfig,
|
|
9
|
+
import { loadNextPlugin, nextBaseConfig, nextConfig, nextOverridesConfig, reactBaseConfig, reactConfig, reactSettingsConfig, typescriptOverridesConfig } from "./configs/react.js";
|
|
10
10
|
import { storybookConfig } from "./configs/storybook.js";
|
|
11
11
|
import { findTailwindEntry, jestGate, nextGate, nxGate, storybookGate, tailwindGate, turboGate, vitestGate } from "./gates.js";
|
|
12
12
|
import { tailwindConfig } from "./configs/tailwind.js";
|
|
13
13
|
import { jestConfig, jestPlugin, testConfig, vitestConfig, vitestPlugin } from "./configs/testing.js";
|
|
14
|
-
import {
|
|
14
|
+
import { loadTurboPlugin, turboConfig } from "./configs/turbo.js";
|
|
15
15
|
import { typeAwareConfig } from "./configs/typescriptTypeAware.js";
|
|
16
16
|
import { unicornConfig } from "./configs/unicorn.js";
|
|
17
17
|
import { Restriction, restrictions } from "./restrictions.js";
|
|
@@ -31,4 +31,4 @@ import { Linter } from "eslint";
|
|
|
31
31
|
*/
|
|
32
32
|
export declare function eslintConfig(overrides?: LintConfig): Promise<Linter.Config[]>;
|
|
33
33
|
//#endregion
|
|
34
|
-
export { DEFAULT_LINT_CONFIG, DefaultIgnoreOptions, DetectionOptions, EslintOptions, GLOBAL_IGNORES, GRAPHIFY_VERSION, GraphifyOptions, LINT_CONFIG_FILE, LintConfig, NextOptions, Restriction, SkillSourceOptions, SkillsConfig, TailwindOptions, ToggleOptions, TypeAwareOptions, VitePlusOptions, asOptions, baseConfig, defaultIgnoreConfig, defineLintConfig, eslintExts, eslintExtsRaw, findNextRoots, findTailwindEntry, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, importSortConfig, importXConfig, includeIgnoreFile, isPackageResolvable, jestConfig, jestGate, jestPlugin, listStaged, loadLintConfig, markupExtsRaw, mergeLintConfig, nextBaseConfig, nextConfig, nextGate, nextOverridesConfig,
|
|
34
|
+
export { DEFAULT_LINT_CONFIG, DefaultIgnoreOptions, DetectionOptions, EslintOptions, GLOBAL_IGNORES, GRAPHIFY_VERSION, GraphifyOptions, LINT_CONFIG_FILE, LintConfig, NextOptions, Restriction, SkillSourceOptions, SkillsConfig, TailwindOptions, ToggleOptions, TypeAwareOptions, VitePlusOptions, asOptions, baseConfig, defaultIgnoreConfig, defineLintConfig, detectionOf, eslintExts, eslintExtsRaw, findNextRoots, findTailwindEntry, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, importSortConfig, importXConfig, includeIgnoreFile, isPackageResolvable, jestConfig, jestGate, jestPlugin, listStaged, loadLintConfig, loadNextPlugin, loadNxPlugin, loadTurboPlugin, markupExtsRaw, mergeLintConfig, nextBaseConfig, nextConfig, nextGate, nextOverridesConfig, nxConfig, nxGate, packageDirOf, prettier, prettierConfig, prettierExts, prettierExtsRaw, promiseConfig, reactBaseConfig, reactConfig, reactSettingsConfig, resolveLintConfig, restrictions, scanWorkspace, storybookConfig, storybookGate, tailwindConfig, tailwindGate, testConfig, testFiles, toolGate, tsExts, tsExtsRaw, tsFiles, turboConfig, turboGate, typeAwareConfig, typescriptOverridesConfig, unicornConfig, unusedImportsConfig, vitestConfig, vitestGate, vitestPlugin, workspaceDependsOn };
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { GLOBAL_IGNORES, asOptions, findNextRoots, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, isPackageResolvable, packageDirOf, scanWorkspace, toolGate, workspaceDependsOn } from "./lib.js";
|
|
2
|
-
import { eslintExts, eslintExtsRaw, markupExtsRaw, prettierExts, prettierExtsRaw, tsExts, tsExtsRaw } from "./exts.js";
|
|
1
|
+
import { GLOBAL_IGNORES, asOptions, detectionOf, findNextRoots, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, isPackageResolvable, packageDirOf, scanWorkspace, toolGate, workspaceDependsOn } from "./lib.js";
|
|
2
|
+
import { eslintExts, eslintExtsRaw, markupExtsRaw, prettierExts, prettierExtsRaw, testFiles, tsExts, tsExtsRaw, tsFiles } from "./exts.js";
|
|
3
3
|
import { DEFAULT_LINT_CONFIG, GRAPHIFY_VERSION, LINT_CONFIG_FILE, defineLintConfig, loadLintConfig, mergeLintConfig, resolveLintConfig } from "./config.js";
|
|
4
4
|
import { findTailwindEntry, jestGate, nextGate, nxGate, storybookGate, tailwindGate, turboGate, vitestGate } from "./gates.js";
|
|
5
5
|
import { baseConfig, defaultIgnoreConfig, includeIgnoreFile } from "./configs/base.js";
|
|
6
6
|
import { importSortConfig, importXConfig, unusedImportsConfig } from "./configs/imports.js";
|
|
7
|
-
import {
|
|
7
|
+
import { loadNxPlugin, nxConfig } from "./configs/nx.js";
|
|
8
8
|
import { prettierConfig } from "./configs/prettier.js";
|
|
9
9
|
import { promiseConfig } from "./configs/promise.js";
|
|
10
|
-
import { nextBaseConfig, nextConfig, nextOverridesConfig,
|
|
10
|
+
import { loadNextPlugin, nextBaseConfig, nextConfig, nextOverridesConfig, reactBaseConfig, reactConfig, reactSettingsConfig, typescriptOverridesConfig } from "./configs/react.js";
|
|
11
11
|
import { storybookConfig } from "./configs/storybook.js";
|
|
12
12
|
import { tailwindConfig } from "./configs/tailwind.js";
|
|
13
13
|
import { jestConfig, jestPlugin, testConfig, vitestConfig, vitestPlugin } from "./configs/testing.js";
|
|
14
|
-
import {
|
|
14
|
+
import { loadTurboPlugin, turboConfig } from "./configs/turbo.js";
|
|
15
15
|
import { typeAwareConfig } from "./configs/typescriptTypeAware.js";
|
|
16
16
|
import { unicornConfig } from "./configs/unicorn.js";
|
|
17
17
|
import { restrictions } from "./restrictions.js";
|
|
@@ -31,8 +31,7 @@ import { prettier } from "./prettier.js";
|
|
|
31
31
|
async function eslintConfig(overrides = {}) {
|
|
32
32
|
const options = await resolveLintConfig(overrides);
|
|
33
33
|
const { typeAware, defaultIgnore } = options.eslint ?? {};
|
|
34
|
-
const {
|
|
35
|
-
const flag = (option) => option === void 0 && !defaultOn ? false : option;
|
|
34
|
+
const { strict, flag } = detectionOf(options);
|
|
36
35
|
return [
|
|
37
36
|
...baseConfig(),
|
|
38
37
|
...defaultIgnoreConfig(defaultIgnore),
|
|
@@ -54,4 +53,4 @@ async function eslintConfig(overrides = {}) {
|
|
|
54
53
|
];
|
|
55
54
|
}
|
|
56
55
|
//#endregion
|
|
57
|
-
export { DEFAULT_LINT_CONFIG, GLOBAL_IGNORES, GRAPHIFY_VERSION, LINT_CONFIG_FILE, asOptions, baseConfig, defaultIgnoreConfig, defineLintConfig, eslintConfig, eslintExts, eslintExtsRaw, findNextRoots, findTailwindEntry, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, importSortConfig, importXConfig, includeIgnoreFile, isPackageResolvable, jestConfig, jestGate, jestPlugin, listStaged, loadLintConfig, markupExtsRaw, mergeLintConfig, nextBaseConfig, nextConfig, nextGate, nextOverridesConfig,
|
|
56
|
+
export { DEFAULT_LINT_CONFIG, GLOBAL_IGNORES, GRAPHIFY_VERSION, LINT_CONFIG_FILE, asOptions, baseConfig, defaultIgnoreConfig, defineLintConfig, detectionOf, eslintConfig, eslintExts, eslintExtsRaw, findNextRoots, findTailwindEntry, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, importSortConfig, importXConfig, includeIgnoreFile, isPackageResolvable, jestConfig, jestGate, jestPlugin, listStaged, loadLintConfig, loadNextPlugin, loadNxPlugin, loadTurboPlugin, markupExtsRaw, mergeLintConfig, nextBaseConfig, nextConfig, nextGate, nextOverridesConfig, nxConfig, nxGate, packageDirOf, prettier, prettierConfig, prettierExts, prettierExtsRaw, promiseConfig, reactBaseConfig, reactConfig, reactSettingsConfig, resolveLintConfig, restrictions, scanWorkspace, storybookConfig, storybookGate, tailwindConfig, tailwindGate, testConfig, testFiles, toolGate, tsExts, tsExtsRaw, tsFiles, turboConfig, turboGate, typeAwareConfig, typescriptOverridesConfig, unicornConfig, unusedImportsConfig, vitestConfig, vitestGate, vitestPlugin, workspaceDependsOn };
|
package/dist/lib.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { ToggleOptions } from "./config.js";
|
|
1
|
+
import { LintConfig, ToggleOptions } from "./config.js";
|
|
2
2
|
//#region src/lib.d.ts
|
|
3
3
|
type NormalizedOptions<T extends ToggleOptions> = Omit<T, 'enabled'>;
|
|
4
4
|
type ToolGateSpec<T extends ToggleOptions> = {
|
|
5
5
|
tool: string;
|
|
6
|
+
/** Is the tool in use (the workspace-root probe)? Usually `packageName` resolvable, `nx.json` for Nx. */
|
|
6
7
|
has: boolean;
|
|
8
|
+
/** The strict probe from cwd, when it is not `packageName` resolvable from cwd. */
|
|
7
9
|
strictHas?: boolean;
|
|
10
|
+
/** The package the integration needs at lint time - checked on its own, whatever `has` probes. */
|
|
8
11
|
packageName?: string;
|
|
9
12
|
requirePackage?: boolean;
|
|
10
13
|
absolutizeOptions?: (options: NormalizedOptions<T>) => string[];
|
|
@@ -23,10 +26,10 @@ type ToolGateResult<T extends ToggleOptions> = {
|
|
|
23
26
|
};
|
|
24
27
|
export declare const GLOBAL_IGNORES: string[];
|
|
25
28
|
/**
|
|
26
|
-
* Capability gate: is a package resolvable from the workspace root
|
|
27
|
-
* themselves resolve from at lint time
|
|
29
|
+
* Capability gate: is a package resolvable from `scope` - by default the workspace root, the scope the ESLint plugins
|
|
30
|
+
* themselves resolve from at lint time; strict detection probes from cwd (see {@link toolGate}).
|
|
28
31
|
*/
|
|
29
|
-
export declare function isPackageResolvable(packageName: string): boolean;
|
|
32
|
+
export declare function isPackageResolvable(packageName: string, scope?: string): boolean;
|
|
30
33
|
/**
|
|
31
34
|
* Workspace root of the consumer project - the anchor for every config-file scan (Tailwind entry,
|
|
32
35
|
* `next.config.*`) and root-file detection (`nx.json`): `process.cwd()` alone is unreliable
|
|
@@ -53,7 +56,7 @@ export declare function findWorkspaceRoot(cwd?: string): string;
|
|
|
53
56
|
export declare function workspaceDependsOn(packageName: string, root?: string): boolean;
|
|
54
57
|
/**
|
|
55
58
|
* The workspace package owning `file` (e.g. the Tailwind entry CSS) - matched against the real
|
|
56
|
-
* workspace package dirs (see {@link
|
|
59
|
+
* workspace package dirs (see {@link workspaceOf}), NOT by walking to the nearest
|
|
57
60
|
* package.json: a directory that is not a declared workspace member belongs to the root. Returns
|
|
58
61
|
* the workspace root when no package contains `file`.
|
|
59
62
|
*
|
|
@@ -61,7 +64,7 @@ export declare function workspaceDependsOn(packageName: string, root?: string):
|
|
|
61
64
|
export declare function packageDirOf(file: string): string;
|
|
62
65
|
/**
|
|
63
66
|
* Glob for config-file candidates across the workspace: the root directory plus every workspace
|
|
64
|
-
* package (the real `workspaces` globs via {@link
|
|
67
|
+
* package (the real `workspaces` globs via {@link workspaceOf}, not a depth heuristic),
|
|
65
68
|
* skipping dot dirs, build outputs, the given ignore patterns and everything in the root
|
|
66
69
|
* `.gitignore`. Anchored to {@link findWorkspaceRoot}, NOT cwd.
|
|
67
70
|
*
|
|
@@ -88,14 +91,14 @@ export declare function scanWorkspace(fileGlob: string, ignores?: string[], { do
|
|
|
88
91
|
* block, so the Vite+ config detects Next.js without loading `eslint-config-next`.
|
|
89
92
|
*/
|
|
90
93
|
export declare function findNextRoots(ignores: string[]): string[];
|
|
91
|
-
export declare const hasNext: boolean;
|
|
92
|
-
export declare const hasStorybook: boolean;
|
|
93
|
-
export declare const hasVite: boolean;
|
|
94
|
-
export declare const hasJest: boolean;
|
|
95
|
-
export declare const hasVitest: boolean;
|
|
96
|
-
export declare const hasTurbo: boolean;
|
|
97
|
-
export declare const hasNx: boolean;
|
|
98
|
-
export declare const hasTailwind: boolean;
|
|
94
|
+
export declare const hasNext: () => boolean;
|
|
95
|
+
export declare const hasStorybook: () => boolean;
|
|
96
|
+
export declare const hasVite: () => boolean;
|
|
97
|
+
export declare const hasJest: () => boolean;
|
|
98
|
+
export declare const hasVitest: () => boolean;
|
|
99
|
+
export declare const hasTurbo: () => boolean;
|
|
100
|
+
export declare const hasNx: () => boolean;
|
|
101
|
+
export declare const hasTailwind: () => boolean;
|
|
99
102
|
/**
|
|
100
103
|
* Normalize a defineLintConfig flag into its options object with a canonical `enabled`:
|
|
101
104
|
* - `true` / `false` → `{ enabled: true | false }`
|
|
@@ -108,6 +111,19 @@ export declare const hasTailwind: boolean;
|
|
|
108
111
|
export declare function asOptions<T extends ToggleOptions>(option: boolean | T | null | undefined): NormalizedOptions<T> & {
|
|
109
112
|
enabled?: boolean;
|
|
110
113
|
};
|
|
114
|
+
/** A tool option with the `detection` setting applied: see {@link detectionOf}. */
|
|
115
|
+
type DetectionFlag = <T>(option: T | undefined) => T | false | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* The `detection` setting of `lint.config.ts`, read the same way by the ESLint config, the Vite+ config and
|
|
118
|
+
* `lint-prepare` (same toggle notation as the tools): `detect` - tools are ON unless said otherwise (default true);
|
|
119
|
+
* `strict` - same-scope probes from cwd only, no workspace evidence scans (default false; for per-package monorepo
|
|
120
|
+
* configs); `flag` - with detection off, a tool not mentioned explicitly is OFF instead of auto-detected.
|
|
121
|
+
*/
|
|
122
|
+
export declare function detectionOf(config: LintConfig): {
|
|
123
|
+
detect: boolean;
|
|
124
|
+
strict: boolean;
|
|
125
|
+
flag: DetectionFlag;
|
|
126
|
+
};
|
|
111
127
|
/**
|
|
112
128
|
* Shared activation gate of the tool-scoped config blocks (next, storybook, turbo, nx, jest,
|
|
113
129
|
* vitest, tailwind) - the one decision every block repeats: is the tool ON, and can its plugin
|
|
@@ -116,16 +132,16 @@ export declare function asOptions<T extends ToggleOptions>(option: boolean | T |
|
|
|
116
132
|
*
|
|
117
133
|
* Decision flow:
|
|
118
134
|
* - `enabled: false` → off, always.
|
|
119
|
-
* - strict (defineLintConfig `detection.strict`):
|
|
120
|
-
*
|
|
121
|
-
* that is ON while its package is unresolvable
|
|
122
|
-
* missing (`needs`) throws instead of producing a config that
|
|
135
|
+
* - strict (defineLintConfig `detection.strict`): every probe runs from cwd - `packageName` resolvable from
|
|
136
|
+
* cwd, or the tool's own `strictHas` (e.g. `nx.json` at cwd), else `has`; `scan` never runs, but
|
|
137
|
+
* `absolutizeOptions` evidence still counts. A tool that is ON while its package is unresolvable from cwd
|
|
138
|
+
* (`requirePackage`) or its mandatory evidence is missing (`needs`) throws instead of producing a config that
|
|
139
|
+
* crashes at lint time.
|
|
123
140
|
* - non-strict: evidence-based detection - `absolutizeOptions(options)` wins over the `scan()`
|
|
124
141
|
* auto-discovery; the tool is detected when the package probe hits or evidence exists (`needs`
|
|
125
142
|
* makes evidence mandatory even when the probe hits). A tool that is ON while `packageName` is
|
|
126
|
-
* unresolvable from the workspace root throws an actionable HOISTING error (no silent skip
|
|
127
|
-
*
|
|
128
|
-
* them; the user or their AI agent picks it up from the error).
|
|
143
|
+
* unresolvable from the workspace root throws an actionable HOISTING error (no silent skip - the
|
|
144
|
+
* plugins resolve from the root scope, so only hoisting fixes them).
|
|
129
145
|
*
|
|
130
146
|
*/
|
|
131
147
|
export declare function toolGate<T extends ToggleOptions>(option: boolean | T | undefined, strict: boolean, spec: ToolGateSpec<T>): ToolGateResult<T>;
|
package/dist/lib.js
CHANGED
|
@@ -28,20 +28,23 @@ function debug(message, ...args) {
|
|
|
28
28
|
console.log(`[@kirill.konshin/lint] ${message}`, ...args);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Capability gate: is a package resolvable from the workspace root
|
|
32
|
-
* themselves resolve from at lint time
|
|
31
|
+
* Capability gate: is a package resolvable from `scope` - by default the workspace root, the scope the ESLint plugins
|
|
32
|
+
* themselves resolve from at lint time; strict detection probes from cwd (see {@link toolGate}).
|
|
33
33
|
*/
|
|
34
|
-
function isPackageResolvable(packageName) {
|
|
35
|
-
return isPackageExists(packageName, { paths: [
|
|
34
|
+
function isPackageResolvable(packageName, scope = findWorkspaceRoot()) {
|
|
35
|
+
return isPackageExists(packageName, { paths: [scope] });
|
|
36
36
|
}
|
|
37
|
+
/** Is `path` `dir` itself or inside it? */
|
|
38
|
+
const isInside = (dir, path) => {
|
|
39
|
+
const rel = relative(dir, path);
|
|
40
|
+
return !rel.startsWith("..") && !isAbsolute(rel);
|
|
41
|
+
};
|
|
37
42
|
/**
|
|
38
43
|
* An env-supplied root candidate is only plausible when it is an absolute existing directory that
|
|
39
44
|
* contains (or is) `cwd` - guards against stale env leaking in from an unrelated checkout.
|
|
40
45
|
*/
|
|
41
46
|
function isRootOf(root, cwd) {
|
|
42
|
-
|
|
43
|
-
const rel = relative(root, cwd);
|
|
44
|
-
return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
|
|
47
|
+
return Boolean(root && isAbsolute(root) && existsSync(root) && isInside(root, cwd));
|
|
45
48
|
}
|
|
46
49
|
const workspaceRoots = /* @__PURE__ */ new Map();
|
|
47
50
|
/**
|
|
@@ -74,52 +77,50 @@ function findWorkspaceRoot(cwd = process.cwd()) {
|
|
|
74
77
|
workspaceRoots.set(cwd, root);
|
|
75
78
|
return root;
|
|
76
79
|
}
|
|
77
|
-
const
|
|
80
|
+
const workspaces = /* @__PURE__ */ new Map();
|
|
78
81
|
/**
|
|
79
|
-
*
|
|
80
|
-
* globs expanded by `@manypkg/get-packages`, NOT a scan heuristic
|
|
81
|
-
* root itself
|
|
82
|
+
* The workspace of `root`, read once per process: the absolute directories of its packages - the real `workspaces` /
|
|
83
|
+
* `pnpm-workspace.yaml` globs expanded by `@manypkg/get-packages`, NOT a scan heuristic; a single-package repo yields
|
|
84
|
+
* the root itself - and the manifests of the root and every package. No package.json at all yields nothing
|
|
85
|
+
* (degenerate sandboxes, tests).
|
|
82
86
|
*/
|
|
83
|
-
function
|
|
84
|
-
const
|
|
85
|
-
const cached = workspacePackageDirs.get(root);
|
|
87
|
+
function workspaceOf(root = findWorkspaceRoot()) {
|
|
88
|
+
const cached = workspaces.get(root);
|
|
86
89
|
if (cached) return cached;
|
|
87
|
-
let
|
|
90
|
+
let workspace = {
|
|
91
|
+
dirs: [],
|
|
92
|
+
manifests: []
|
|
93
|
+
};
|
|
88
94
|
try {
|
|
89
|
-
|
|
95
|
+
const { rootPackage, packages } = getPackagesSync(root);
|
|
96
|
+
workspace = {
|
|
97
|
+
dirs: packages.map((pkg) => pkg.dir),
|
|
98
|
+
manifests: [rootPackage, ...packages].flatMap((pkg) => pkg ? [pkg.packageJson] : [])
|
|
99
|
+
};
|
|
90
100
|
} catch {}
|
|
91
|
-
|
|
92
|
-
return
|
|
101
|
+
workspaces.set(root, workspace);
|
|
102
|
+
return workspace;
|
|
93
103
|
}
|
|
104
|
+
/** Does this manifest declare `packageName`? Peer/optional declarations mark libraries, not users - ignored. */
|
|
105
|
+
const declares = ({ dependencies, devDependencies }, packageName) => Boolean(dependencies?.[packageName] ?? devDependencies?.[packageName]);
|
|
94
106
|
/**
|
|
95
107
|
* Does the root or a workspace package of `root` declare `packageName` in `dependencies` or `devDependencies`?
|
|
96
108
|
* Peer/optional declarations are ignored, as in {@link dependsOnNext}. Reads the manifests the workspace globs name
|
|
97
109
|
* (`@manypkg/get-packages`), no scan; false without a `package.json`.
|
|
98
110
|
*/
|
|
99
111
|
function workspaceDependsOn(packageName, root = findWorkspaceRoot()) {
|
|
100
|
-
|
|
101
|
-
const { rootPackage, packages } = getPackagesSync(root);
|
|
102
|
-
return [rootPackage, ...packages].some((pkg) => {
|
|
103
|
-
const { dependencies, devDependencies } = pkg?.packageJson ?? {};
|
|
104
|
-
return Boolean(dependencies?.[packageName] ?? devDependencies?.[packageName]);
|
|
105
|
-
});
|
|
106
|
-
} catch {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
112
|
+
return workspaceOf(root).manifests.some((manifest) => declares(manifest, packageName));
|
|
109
113
|
}
|
|
110
114
|
/**
|
|
111
115
|
* The workspace package owning `file` (e.g. the Tailwind entry CSS) - matched against the real
|
|
112
|
-
* workspace package dirs (see {@link
|
|
116
|
+
* workspace package dirs (see {@link workspaceOf}), NOT by walking to the nearest
|
|
113
117
|
* package.json: a directory that is not a declared workspace member belongs to the root. Returns
|
|
114
118
|
* the workspace root when no package contains `file`.
|
|
115
119
|
*
|
|
116
120
|
*/
|
|
117
121
|
function packageDirOf(file) {
|
|
118
122
|
const root = findWorkspaceRoot();
|
|
119
|
-
return
|
|
120
|
-
const rel = relative(dir, file);
|
|
121
|
-
return !rel.startsWith("..") && !isAbsolute(rel);
|
|
122
|
-
}) ?? root;
|
|
123
|
+
return workspaceOf(root).dirs.filter((dir) => dir !== root).sort((a, b) => b.length - a.length).find((dir) => isInside(dir, file)) ?? root;
|
|
123
124
|
}
|
|
124
125
|
const SCAN_IGNORES = [
|
|
125
126
|
"**/node_modules",
|
|
@@ -133,6 +134,7 @@ const SCAN_IGNORES = [
|
|
|
133
134
|
"**/.git"
|
|
134
135
|
];
|
|
135
136
|
const scurries = /* @__PURE__ */ new Map();
|
|
137
|
+
const gitignores = /* @__PURE__ */ new Map();
|
|
136
138
|
/**
|
|
137
139
|
* Filesystem cache of a scanned directory, shared by every {@link scanWorkspace} call: the detection scans all walk
|
|
138
140
|
* the same trees, so each directory is read once instead of once per scan. Cached per process, like the workspace
|
|
@@ -146,8 +148,22 @@ function scurryOf(dir) {
|
|
|
146
148
|
return scurry;
|
|
147
149
|
}
|
|
148
150
|
/**
|
|
151
|
+
* The root `.gitignore` as glob ignore patterns, read once per root. Reuses ESLint's gitignore->minimatch conversion;
|
|
152
|
+
* glob's `ignore` speaks the same language. Negations dropped: glob's ignore cannot un-ignore.
|
|
153
|
+
*/
|
|
154
|
+
function gitignoredOf(root) {
|
|
155
|
+
const cached = gitignores.get(root);
|
|
156
|
+
if (cached) return cached;
|
|
157
|
+
let patterns = [];
|
|
158
|
+
try {
|
|
159
|
+
patterns = (includeIgnoreFile(resolve(root, ".gitignore")).ignores ?? []).filter((p) => !p.startsWith("!"));
|
|
160
|
+
} catch {}
|
|
161
|
+
gitignores.set(root, patterns);
|
|
162
|
+
return patterns;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
149
165
|
* Glob for config-file candidates across the workspace: the root directory plus every workspace
|
|
150
|
-
* package (the real `workspaces` globs via {@link
|
|
166
|
+
* package (the real `workspaces` globs via {@link workspaceOf}, not a depth heuristic),
|
|
151
167
|
* skipping dot dirs, build outputs, the given ignore patterns and everything in the root
|
|
152
168
|
* `.gitignore`. Anchored to {@link findWorkspaceRoot}, NOT cwd.
|
|
153
169
|
*
|
|
@@ -157,15 +173,11 @@ function scurryOf(dir) {
|
|
|
157
173
|
*/
|
|
158
174
|
function scanWorkspace(fileGlob, ignores = [], { dot = false } = {}) {
|
|
159
175
|
const root = findWorkspaceRoot();
|
|
160
|
-
const packages =
|
|
161
|
-
let gitignored = [];
|
|
162
|
-
try {
|
|
163
|
-
gitignored = (includeIgnoreFile(resolve(root, ".gitignore")).ignores ?? []).filter((pattern) => !pattern.startsWith("!"));
|
|
164
|
-
} catch {}
|
|
176
|
+
const packages = workspaceOf(root).dirs.filter((dir) => dir !== root);
|
|
165
177
|
const ignore = [
|
|
166
178
|
...ignores,
|
|
167
179
|
...SCAN_IGNORES,
|
|
168
|
-
...
|
|
180
|
+
...gitignoredOf(root)
|
|
169
181
|
].flatMap((pattern) => [pattern, pattern.endsWith("/") ? `${pattern}**` : `${pattern}/**`]);
|
|
170
182
|
const rootIgnore = [...ignore, ...packages.flatMap((dir) => {
|
|
171
183
|
const rel = relative(root, dir).replaceAll("\\", "/");
|
|
@@ -191,8 +203,7 @@ function scanWorkspace(fileGlob, ignores = [], { dot = false } = {}) {
|
|
|
191
203
|
*/
|
|
192
204
|
function dependsOnNext(file) {
|
|
193
205
|
try {
|
|
194
|
-
|
|
195
|
-
return Boolean(dependencies?.next ?? devDependencies?.next);
|
|
206
|
+
return declares(JSON.parse(readFileSync(file, "utf-8")), "next");
|
|
196
207
|
} catch {
|
|
197
208
|
return false;
|
|
198
209
|
}
|
|
@@ -219,24 +230,30 @@ function findNextRoots(ignores) {
|
|
|
219
230
|
...scanWorkspace("src/{app,pages}/", ignores).map((dir) => dirname(dirname(dir)))
|
|
220
231
|
])].sort();
|
|
221
232
|
}
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
const
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
233
|
+
const probes = /* @__PURE__ */ new Map();
|
|
234
|
+
/** `check` of the workspace root, run once per root and only when a gate asks for it - not when a module loads. */
|
|
235
|
+
function probe(name, check) {
|
|
236
|
+
const root = findWorkspaceRoot();
|
|
237
|
+
const key = `${root}\0${name}`;
|
|
238
|
+
const cached = probes.get(key);
|
|
239
|
+
if (cached !== void 0) return cached;
|
|
240
|
+
const found = check(root);
|
|
241
|
+
probes.set(key, found);
|
|
242
|
+
debug("capability probe", {
|
|
243
|
+
name,
|
|
244
|
+
root,
|
|
245
|
+
found
|
|
246
|
+
});
|
|
247
|
+
return found;
|
|
248
|
+
}
|
|
249
|
+
const hasNext = () => probe("next", (root) => isPackageResolvable("next", root));
|
|
250
|
+
const hasStorybook = () => probe("storybook", (root) => isPackageResolvable("storybook", root));
|
|
251
|
+
const hasVite = () => probe("vite", (root) => isPackageResolvable("vite", root));
|
|
252
|
+
const hasJest = () => probe("jest", (root) => isPackageResolvable("jest", root));
|
|
253
|
+
const hasVitest = () => probe("vitest", (root) => isPackageResolvable("vitest", root));
|
|
254
|
+
const hasTurbo = () => probe("turbo", (root) => isPackageResolvable("turbo", root));
|
|
255
|
+
const hasNx = () => probe("nx.json", (root) => existsSync(resolve(root, "nx.json")));
|
|
256
|
+
const hasTailwind = () => probe("tailwindcss", (root) => isPackageResolvable("tailwindcss", root));
|
|
240
257
|
/**
|
|
241
258
|
* Normalize a defineLintConfig flag into its options object with a canonical `enabled`:
|
|
242
259
|
* - `true` / `false` → `{ enabled: true | false }`
|
|
@@ -255,6 +272,21 @@ function asOptions(option) {
|
|
|
255
272
|
return {};
|
|
256
273
|
}
|
|
257
274
|
/**
|
|
275
|
+
* The `detection` setting of `lint.config.ts`, read the same way by the ESLint config, the Vite+ config and
|
|
276
|
+
* `lint-prepare` (same toggle notation as the tools): `detect` - tools are ON unless said otherwise (default true);
|
|
277
|
+
* `strict` - same-scope probes from cwd only, no workspace evidence scans (default false; for per-package monorepo
|
|
278
|
+
* configs); `flag` - with detection off, a tool not mentioned explicitly is OFF instead of auto-detected.
|
|
279
|
+
*/
|
|
280
|
+
function detectionOf(config) {
|
|
281
|
+
const { enabled: detect = true, strict = false } = asOptions(config.detection);
|
|
282
|
+
const flag = (option) => option === void 0 && !detect ? false : option;
|
|
283
|
+
return {
|
|
284
|
+
detect,
|
|
285
|
+
strict,
|
|
286
|
+
flag
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
258
290
|
* Shared activation gate of the tool-scoped config blocks (next, storybook, turbo, nx, jest,
|
|
259
291
|
* vitest, tailwind) - the one decision every block repeats: is the tool ON, and can its plugin
|
|
260
292
|
* actually run. The `configs/*.ts` functions keep only their tool-specific parts (which blocks to
|
|
@@ -262,16 +294,16 @@ function asOptions(option) {
|
|
|
262
294
|
*
|
|
263
295
|
* Decision flow:
|
|
264
296
|
* - `enabled: false` → off, always.
|
|
265
|
-
* - strict (defineLintConfig `detection.strict`):
|
|
266
|
-
*
|
|
267
|
-
* that is ON while its package is unresolvable
|
|
268
|
-
* missing (`needs`) throws instead of producing a config that
|
|
297
|
+
* - strict (defineLintConfig `detection.strict`): every probe runs from cwd - `packageName` resolvable from
|
|
298
|
+
* cwd, or the tool's own `strictHas` (e.g. `nx.json` at cwd), else `has`; `scan` never runs, but
|
|
299
|
+
* `absolutizeOptions` evidence still counts. A tool that is ON while its package is unresolvable from cwd
|
|
300
|
+
* (`requirePackage`) or its mandatory evidence is missing (`needs`) throws instead of producing a config that
|
|
301
|
+
* crashes at lint time.
|
|
269
302
|
* - non-strict: evidence-based detection - `absolutizeOptions(options)` wins over the `scan()`
|
|
270
303
|
* auto-discovery; the tool is detected when the package probe hits or evidence exists (`needs`
|
|
271
304
|
* makes evidence mandatory even when the probe hits). A tool that is ON while `packageName` is
|
|
272
|
-
* unresolvable from the workspace root throws an actionable HOISTING error (no silent skip
|
|
273
|
-
*
|
|
274
|
-
* them; the user or their AI agent picks it up from the error).
|
|
305
|
+
* unresolvable from the workspace root throws an actionable HOISTING error (no silent skip - the
|
|
306
|
+
* plugins resolve from the root scope, so only hoisting fixes them).
|
|
275
307
|
*
|
|
276
308
|
*/
|
|
277
309
|
function toolGate(option, strict, spec) {
|
|
@@ -298,7 +330,7 @@ function toolGate(option, strict, spec) {
|
|
|
298
330
|
files: []
|
|
299
331
|
};
|
|
300
332
|
if (enabled === false) return trace(off, "disabled explicitly");
|
|
301
|
-
const { tool, has, strictHas
|
|
333
|
+
const { tool, has, strictHas, packageName, requirePackage = Boolean(packageName), absolutizeOptions, scan, allowMultiple = true, needs } = spec;
|
|
302
334
|
const prefix = `[@kirill.konshin/lint] \`${tool}\``;
|
|
303
335
|
const usable = (candidates) => {
|
|
304
336
|
if (!allowMultiple && candidates.length > 1) {
|
|
@@ -308,8 +340,9 @@ function toolGate(option, strict, spec) {
|
|
|
308
340
|
return candidates;
|
|
309
341
|
};
|
|
310
342
|
if (strict) {
|
|
311
|
-
|
|
312
|
-
if (
|
|
343
|
+
const here = packageName ? isPackageResolvable(packageName, process.cwd()) : has;
|
|
344
|
+
if (!(enabled ?? strictHas ?? here)) return trace(off, "strict probe negative");
|
|
345
|
+
if (requirePackage && !here) throw new Error(`${prefix} is on under strict detection, but the \`${packageName}\` package is not resolvable at this scope - install it here or set \`${tool}: false\`.`);
|
|
313
346
|
absolutized = absolutizeOptions?.(options) ?? [];
|
|
314
347
|
const files = usable(absolutized);
|
|
315
348
|
if (needs && files.length === 0) throw new Error(`${prefix} is on under strict detection, which cannot scan for the ${needs.what} - pass ${needs.hint} or set \`${tool}: false\`.`);
|
|
@@ -327,7 +360,7 @@ function toolGate(option, strict, spec) {
|
|
|
327
360
|
return trace(off, `no ${needs.what} found`);
|
|
328
361
|
}
|
|
329
362
|
if (!(enabled ?? (has || files.length > 0))) return trace(off, "not detected");
|
|
330
|
-
if (requirePackage && packageName && !
|
|
363
|
+
if (requirePackage && packageName && !isPackageResolvable(packageName)) {
|
|
331
364
|
const leaf = files.map((file) => dirname(file)).find((dir) => isPackageExists(packageName, { paths: [dir] }));
|
|
332
365
|
throw new Error(`${prefix} is in use, but the \`${packageName}\` package is not resolvable from the workspace root` + (leaf ? ` (it is installed near \`${leaf}\`)` : "") + ` - hoist it: keep the package manager's default hoisting (no \`installConfig.hoistingLimits\` / \`nohoist\`), on pnpm add \`public-hoist-pattern[]=${packageName}\` to .npmrc, or add \`${packageName}\` to the root devDependencies. Set \`${tool}: false\` to turn the tool off. Run eslint with LINT_DEBUG=1 to trace detection.`);
|
|
333
366
|
}
|
|
@@ -338,4 +371,4 @@ function toolGate(option, strict, spec) {
|
|
|
338
371
|
}, enabled ? "forced on" : "detected");
|
|
339
372
|
}
|
|
340
373
|
//#endregion
|
|
341
|
-
export { GLOBAL_IGNORES, asOptions, findNextRoots, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, isPackageResolvable, packageDirOf, scanWorkspace, toolGate, workspaceDependsOn };
|
|
374
|
+
export { GLOBAL_IGNORES, asOptions, detectionOf, findNextRoots, findWorkspaceRoot, hasJest, hasNext, hasNx, hasStorybook, hasTailwind, hasTurbo, hasVite, hasVitest, isPackageResolvable, packageDirOf, scanWorkspace, toolGate, workspaceDependsOn };
|