@kirill.konshin/lint 0.8.8 → 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 +28 -6
- package/dist/config.d.ts +13 -0
- package/dist/config.js +7 -1
- 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 +96 -0
- package/dist/graphify.js +255 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +8 -9
- package/dist/lib.d.ts +37 -21
- package/dist/lib.js +105 -71
- package/dist/lintPrepare.d.ts +13 -10
- package/dist/lintPrepare.js +52 -39
- 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 +35 -68
- package/package.json +4 -1
- package/skills/spec-tools/scripts/cli.js +700 -627
package/dist/gates.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export declare function nextGate(option: boolean | NextOptions | undefined, stri
|
|
|
14
14
|
files: string[];
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
* Storybook: a `.storybook/main.*` marks a Storybook repo
|
|
18
|
-
*
|
|
17
|
+
* Storybook: a `.storybook/main.*` marks a Storybook repo; `eslint-plugin-storybook` statically imports `storybook`,
|
|
18
|
+
* so it must be resolvable from the workspace root.
|
|
19
19
|
*/
|
|
20
20
|
export declare function storybookGate(option: boolean | ToggleOptions | undefined, strict: boolean): {
|
|
21
21
|
enabled: boolean;
|
|
@@ -29,11 +29,11 @@ export declare function turboGate(option: boolean | ToggleOptions | undefined):
|
|
|
29
29
|
files: string[];
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
32
|
-
* Nx: `nx.json` at the workspace root (strict: at cwd). `packageName`: the package the integration needs
|
|
33
|
-
* the Vite+ config runs `@nx/eslint-plugin` as a JS plugin, which needs `eslint`.
|
|
32
|
+
* Nx: in use when `nx.json` is at the workspace root (strict: at cwd). `packageName`: the package the integration needs
|
|
33
|
+
* resolvable, checked on its own - the Vite+ config runs `@nx/eslint-plugin` as a JS plugin, which needs `eslint`.
|
|
34
34
|
*/
|
|
35
35
|
export declare function nxGate(option: boolean | ToggleOptions | undefined, strict: boolean, { packageName }?: {
|
|
36
|
-
packageName?: string
|
|
36
|
+
packageName?: string;
|
|
37
37
|
}): {
|
|
38
38
|
enabled: boolean;
|
|
39
39
|
options: {};
|
package/dist/gates.js
CHANGED
|
@@ -10,7 +10,7 @@ import { globSync } from "glob";
|
|
|
10
10
|
function nextGate(option, strict, { requirePackage = true } = {}) {
|
|
11
11
|
return toolGate(option, strict, {
|
|
12
12
|
tool: "next",
|
|
13
|
-
has: hasNext,
|
|
13
|
+
has: hasNext(),
|
|
14
14
|
packageName: "next",
|
|
15
15
|
requirePackage,
|
|
16
16
|
absolutizeOptions: ({ rootDir }) => (Array.isArray(rootDir) ? rootDir : [rootDir]).filter((dir) => Boolean(dir)).flatMap((dir) => {
|
|
@@ -22,52 +22,64 @@ function nextGate(option, strict, { requirePackage = true } = {}) {
|
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
* `
|
|
25
|
+
* A tool marked by a config file: the file anywhere in the workspace marks the repo even when the tool's package
|
|
26
|
+
* (`tool`) sits in a leaf package.
|
|
27
27
|
*/
|
|
28
|
-
function
|
|
28
|
+
function configFileGate(option, strict, spec) {
|
|
29
|
+
const { tool, has, file, dot, requirePackage } = spec;
|
|
29
30
|
return toolGate(option, strict, {
|
|
31
|
+
tool,
|
|
32
|
+
has,
|
|
33
|
+
packageName: tool,
|
|
34
|
+
requirePackage,
|
|
35
|
+
scan: () => scanWorkspace(file, GLOBAL_IGNORES, { dot })
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Storybook: a `.storybook/main.*` marks a Storybook repo; `eslint-plugin-storybook` statically imports `storybook`,
|
|
40
|
+
* so it must be resolvable from the workspace root.
|
|
41
|
+
*/
|
|
42
|
+
function storybookGate(option, strict) {
|
|
43
|
+
return configFileGate(option, strict, {
|
|
30
44
|
tool: "storybook",
|
|
31
|
-
has: hasStorybook,
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
has: hasStorybook(),
|
|
46
|
+
file: ".storybook/main.*",
|
|
47
|
+
dot: true
|
|
34
48
|
});
|
|
35
49
|
}
|
|
36
50
|
/** Turborepo: probe only, never strict - no evidence scan. */
|
|
37
51
|
function turboGate(option) {
|
|
38
52
|
return toolGate(option, false, {
|
|
39
53
|
tool: "turbo",
|
|
40
|
-
has: hasTurbo
|
|
54
|
+
has: hasTurbo()
|
|
41
55
|
});
|
|
42
56
|
}
|
|
43
57
|
/**
|
|
44
|
-
* Nx: `nx.json` at the workspace root (strict: at cwd). `packageName`: the package the integration needs
|
|
45
|
-
* the Vite+ config runs `@nx/eslint-plugin` as a JS plugin, which needs `eslint`.
|
|
58
|
+
* Nx: in use when `nx.json` is at the workspace root (strict: at cwd). `packageName`: the package the integration needs
|
|
59
|
+
* resolvable, checked on its own - the Vite+ config runs `@nx/eslint-plugin` as a JS plugin, which needs `eslint`.
|
|
46
60
|
*/
|
|
47
|
-
function nxGate(option, strict, { packageName
|
|
61
|
+
function nxGate(option, strict, { packageName } = {}) {
|
|
48
62
|
return toolGate(option, strict, {
|
|
49
63
|
tool: "nx",
|
|
50
|
-
has: hasNx,
|
|
64
|
+
has: hasNx(),
|
|
51
65
|
strictHas: strict && existsSync(resolve(process.cwd(), "nx.json")),
|
|
52
|
-
|
|
66
|
+
packageName
|
|
53
67
|
});
|
|
54
68
|
}
|
|
55
69
|
function jestGate(option, strict) {
|
|
56
|
-
return
|
|
70
|
+
return configFileGate(option, strict, {
|
|
57
71
|
tool: "jest",
|
|
58
|
-
has: hasJest,
|
|
59
|
-
|
|
60
|
-
requirePackage: false
|
|
61
|
-
scan: () => scanWorkspace("jest.config.*", GLOBAL_IGNORES)
|
|
72
|
+
has: hasJest(),
|
|
73
|
+
file: "jest.config.*",
|
|
74
|
+
requirePackage: false
|
|
62
75
|
});
|
|
63
76
|
}
|
|
64
77
|
function vitestGate(option, strict) {
|
|
65
|
-
return
|
|
78
|
+
return configFileGate(option, strict, {
|
|
66
79
|
tool: "vitest",
|
|
67
|
-
has: hasVitest,
|
|
68
|
-
|
|
69
|
-
requirePackage: false
|
|
70
|
-
scan: () => scanWorkspace("{vitest,vite}.config.*", GLOBAL_IGNORES)
|
|
80
|
+
has: hasVitest(),
|
|
81
|
+
file: "{vitest,vite}.config.*",
|
|
82
|
+
requirePackage: false
|
|
71
83
|
});
|
|
72
84
|
}
|
|
73
85
|
/**
|
|
@@ -106,7 +118,7 @@ function findTailwindEntry(ignores) {
|
|
|
106
118
|
function tailwindGate(option, strict = false) {
|
|
107
119
|
const { enabled, options, files } = toolGate(option, strict, {
|
|
108
120
|
tool: "tailwind",
|
|
109
|
-
has: hasTailwind,
|
|
121
|
+
has: hasTailwind(),
|
|
110
122
|
packageName: "tailwindcss",
|
|
111
123
|
needs: {
|
|
112
124
|
what: "entry CSS",
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { GraphifyOptions } from "./config.js";
|
|
2
|
+
import { RunCommand } from "./runCommand.js";
|
|
3
|
+
//#region src/graphify.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* graphify (https://graphify.com, PyPI `graphifyy`) for `lint-prepare`, by the `graphify` option of `lint.config.ts`:
|
|
6
|
+
*
|
|
7
|
+
* - left out (`detect`): a `graphify` on `PATH` gets its skills and a graph build
|
|
8
|
+
* - `true` or options (`venv`): installed into the project `.venv` with `uv`, plus its AGENTS.md section and Claude
|
|
9
|
+
* Code hooks, which are committed: every clone gets the same `.venv`
|
|
10
|
+
* - `false` (`off`): nothing, and what earlier runs installed is removed
|
|
11
|
+
*
|
|
12
|
+
* graphify writes its own files: its skills into `.agents/skills` (the generic flavor) and `.claude/skills` (the Claude
|
|
13
|
+
* Code flavor), its section into AGENTS.md between the anchors lint-prepare generates, its hooks into
|
|
14
|
+
* `.claude/settings.json`. lint-prepare only points the hooks at `.venv` and keeps the section on the next generation.
|
|
15
|
+
*/
|
|
16
|
+
export type GraphifyMode = 'off' | 'detect' | 'venv';
|
|
17
|
+
/** What setUpGraphify() leaves for the rest of `lint-prepare`. */
|
|
18
|
+
export type GraphifySetup = {
|
|
19
|
+
mode: GraphifyMode;
|
|
20
|
+
/** The executable, when graphify can run. */
|
|
21
|
+
exe?: string;
|
|
22
|
+
};
|
|
23
|
+
/** The skill name graphify installs. */
|
|
24
|
+
export declare const GRAPHIFY_SKILL = "graphify";
|
|
25
|
+
/** The mode the `graphify` option asks for, and the version `venv` installs. */
|
|
26
|
+
export declare function graphifyMode(option: boolean | GraphifyOptions | undefined): {
|
|
27
|
+
mode: GraphifyMode;
|
|
28
|
+
version: string;
|
|
29
|
+
};
|
|
30
|
+
/** The absolute path of `command` on `PATH`, undefined when there is none. */
|
|
31
|
+
export declare function findOnPath(command: string, env?: NodeJS.ProcessEnv): string | undefined;
|
|
32
|
+
/** The graphify executable of the project `.venv`. */
|
|
33
|
+
export declare const venvExe: (cwd: string) => string;
|
|
34
|
+
/** A skill folder graphify installed: it holds graphify's version stamp. */
|
|
35
|
+
export declare const isGraphifySkill: (dir: string) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Create the project `.venv` with `uv` (kept when it exists) and install `graphifyy==version` into it. Throws when `uv`
|
|
38
|
+
* is missing: `graphify: true` asks for it.
|
|
39
|
+
*/
|
|
40
|
+
export declare function installGraphifyVenv(cwd: string, version: string, run: RunCommand): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Let graphify install its skills where skills live: the generic flavor into `.agents/skills/graphify` (Codex and the
|
|
43
|
+
* rest), the Claude Code flavor into `.claude/skills/graphify` (it also registers the skill in `.claude/CLAUDE.md`).
|
|
44
|
+
*/
|
|
45
|
+
export declare function installGraphifySkills(cwd: string, exe: string, run: RunCommand): boolean;
|
|
46
|
+
/** Remove what graphify installed: its skill folders (only the ones with its stamp) and its skill registration. */
|
|
47
|
+
export declare function removeGraphifySkills(cwd: string): void;
|
|
48
|
+
/** `content` without the section that starts at the exact line `heading` and ends before the next `boundary` line. */
|
|
49
|
+
export declare function removeSection(content: string, heading: string, boundary: string): string;
|
|
50
|
+
/**
|
|
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
|
+
*/
|
|
55
|
+
export declare const GRAPHIFY_SECTION: {
|
|
56
|
+
tool: string;
|
|
57
|
+
start: string;
|
|
58
|
+
end: string;
|
|
59
|
+
tail: string;
|
|
60
|
+
};
|
|
61
|
+
/** A graphify hook command, any executable path, run from `.venv`. */
|
|
62
|
+
export declare const toVenvCommand: (command: string) => string;
|
|
63
|
+
/**
|
|
64
|
+
* `settings` with graphify's hooks run from `.venv` (`venv`), or without them (an emptied group, event or `hooks`
|
|
65
|
+
* goes too).
|
|
66
|
+
*/
|
|
67
|
+
export declare function updateGraphifyHooks(settings: Record<string, unknown>, venv: boolean): Record<string, unknown>;
|
|
68
|
+
/**
|
|
69
|
+
* Run updateGraphifyHooks() over `.claude/settings.json`, writing it only when it changes; a file that does not parse
|
|
70
|
+
* is left alone.
|
|
71
|
+
*/
|
|
72
|
+
export declare function updateClaudeSettings(cwd: string, venv: boolean): void;
|
|
73
|
+
/**
|
|
74
|
+
* `graphify claude install`: its section into AGENTS.md (through the `CLAUDE.md` link, between the anchors) and its
|
|
75
|
+
* hooks into `.claude/settings.json`, then the hooks pointed at `.venv`. Not `--project`: that installs the skill
|
|
76
|
+
* again.
|
|
77
|
+
*/
|
|
78
|
+
export declare function installGraphifyInstructions(cwd: string, exe: string, run: RunCommand): void;
|
|
79
|
+
/**
|
|
80
|
+
* The root `.gitignore` with lint-prepare's graphify block listing `entries`, or without it when there are none. The
|
|
81
|
+
* block depends on `lint.config.ts` only, never on what a machine has, so every clone writes the same.
|
|
82
|
+
*/
|
|
83
|
+
export declare function updateGitignoreBlock(content: string, entries: string[]): string;
|
|
84
|
+
/** Write updateGitignoreBlock() into `cwd/.gitignore` when it changes. */
|
|
85
|
+
export declare function writeGitignoreBlock(cwd: string, mode: GraphifyMode): void;
|
|
86
|
+
/**
|
|
87
|
+
* Set graphify up for `mode` before the agent dirs are synced: the executable (`.venv` installed for `venv`, `PATH`
|
|
88
|
+
* for `detect`) and its skills; `off` removes them. Nothing on CI. Throws when `venv` has no `uv`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function setUpGraphify(cwd: string, option: boolean | GraphifyOptions | undefined, run: RunCommand): GraphifySetup;
|
|
91
|
+
/**
|
|
92
|
+
* After AGENTS.md is generated: `venv` gets graphify's section and hooks, the other modes lose the hooks. Then the code
|
|
93
|
+
* graph in `graphify-out` is built or refreshed (`graphify update .`: code only, no LLM, no API key). Nothing on CI.
|
|
94
|
+
*/
|
|
95
|
+
export declare function finishGraphify(cwd: string, { mode, exe }: GraphifySetup, run: RunCommand): void;
|
|
96
|
+
//#endregion
|
package/dist/graphify.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { asOptions } from "./lib.js";
|
|
2
|
+
import { GRAPHIFY_VERSION } from "./config.js";
|
|
3
|
+
import { runOrWarn } from "./runCommand.js";
|
|
4
|
+
import { findBlock } from "./textBlocks.js";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
//#region src/graphify.ts
|
|
8
|
+
/** The skill name graphify installs. */
|
|
9
|
+
const GRAPHIFY_SKILL = "graphify";
|
|
10
|
+
const SECTION_HEADING = "## graphify";
|
|
11
|
+
const VENV_HEADING = "## graphify virtualenv";
|
|
12
|
+
const GITIGNORE_BEGIN = "# @kirill.konshin/lint: graphify";
|
|
13
|
+
const GITIGNORE_END = "# @kirill.konshin/lint: graphify end";
|
|
14
|
+
const VENV = ".venv";
|
|
15
|
+
const VENV_HOOK_EXE = `"$CLAUDE_PROJECT_DIR"/${VENV}/bin/graphify`;
|
|
16
|
+
const VERSION_STAMP = ".graphify_version";
|
|
17
|
+
const REGISTRATION_HEADING = "# graphify";
|
|
18
|
+
const QUIET = { stdio: [
|
|
19
|
+
"ignore",
|
|
20
|
+
"ignore",
|
|
21
|
+
"inherit"
|
|
22
|
+
] };
|
|
23
|
+
const isWindows = process.platform === "win32";
|
|
24
|
+
/** The mode the `graphify` option asks for, and the version `venv` installs. */
|
|
25
|
+
function graphifyMode(option) {
|
|
26
|
+
const { enabled, version = GRAPHIFY_VERSION } = asOptions(option);
|
|
27
|
+
return {
|
|
28
|
+
mode: enabled === void 0 ? "detect" : enabled ? "venv" : "off",
|
|
29
|
+
version
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** The absolute path of `command` on `PATH`, undefined when there is none. */
|
|
33
|
+
function findOnPath(command, env = process.env) {
|
|
34
|
+
const exts = isWindows ? (env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";") : [""];
|
|
35
|
+
for (const dir of (env.PATH ?? "").split(path.delimiter).filter(Boolean)) for (const ext of exts) {
|
|
36
|
+
const file = path.join(dir, command + ext);
|
|
37
|
+
try {
|
|
38
|
+
fs.accessSync(file, fs.constants.X_OK);
|
|
39
|
+
if (fs.statSync(file).isFile()) return file;
|
|
40
|
+
} catch {}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** The graphify executable of the project `.venv`. */
|
|
44
|
+
const venvExe = (cwd) => isWindows ? path.join(cwd, VENV, "Scripts", "graphify.exe") : path.join(cwd, VENV, "bin", "graphify");
|
|
45
|
+
/** A skill folder graphify installed: it holds graphify's version stamp. */
|
|
46
|
+
const isGraphifySkill = (dir) => fs.existsSync(path.join(dir, VERSION_STAMP));
|
|
47
|
+
const runQuiet = (run, command, args, cwd) => runOrWarn(run, {
|
|
48
|
+
command,
|
|
49
|
+
args,
|
|
50
|
+
options: {
|
|
51
|
+
cwd,
|
|
52
|
+
...QUIET
|
|
53
|
+
},
|
|
54
|
+
label: `${path.basename(command)} ${args.join(" ")}`,
|
|
55
|
+
what: "graphify"
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Create the project `.venv` with `uv` (kept when it exists) and install `graphifyy==version` into it. Throws when `uv`
|
|
59
|
+
* is missing: `graphify: true` asks for it.
|
|
60
|
+
*/
|
|
61
|
+
function installGraphifyVenv(cwd, version, run) {
|
|
62
|
+
const uv = findOnPath("uv");
|
|
63
|
+
if (!uv) throw new Error("[lint-prepare] graphify: true in lint.config.ts needs uv, install it: https://docs.astral.sh/uv/getting-started/installation/");
|
|
64
|
+
return runQuiet(run, uv, [
|
|
65
|
+
"venv",
|
|
66
|
+
"--allow-existing",
|
|
67
|
+
VENV
|
|
68
|
+
], cwd) && runQuiet(run, uv, [
|
|
69
|
+
"pip",
|
|
70
|
+
"install",
|
|
71
|
+
"--python",
|
|
72
|
+
VENV,
|
|
73
|
+
`graphifyy==${version}`
|
|
74
|
+
], cwd);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Let graphify install its skills where skills live: the generic flavor into `.agents/skills/graphify` (Codex and the
|
|
78
|
+
* rest), the Claude Code flavor into `.claude/skills/graphify` (it also registers the skill in `.claude/CLAUDE.md`).
|
|
79
|
+
*/
|
|
80
|
+
function installGraphifySkills(cwd, exe, run) {
|
|
81
|
+
return ["agents", "claude"].every((platform) => runQuiet(run, exe, [
|
|
82
|
+
"install",
|
|
83
|
+
"--project",
|
|
84
|
+
"--platform",
|
|
85
|
+
platform
|
|
86
|
+
], cwd));
|
|
87
|
+
}
|
|
88
|
+
/** Remove what graphify installed: its skill folders (only the ones with its stamp) and its skill registration. */
|
|
89
|
+
function removeGraphifySkills(cwd) {
|
|
90
|
+
for (const dir of [".agents", ".claude"]) {
|
|
91
|
+
const skill = path.join(cwd, dir, "skills", GRAPHIFY_SKILL);
|
|
92
|
+
if (isGraphifySkill(skill)) fs.rmSync(skill, {
|
|
93
|
+
recursive: true,
|
|
94
|
+
force: true
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const claudeMd = path.join(cwd, ".claude", "CLAUDE.md");
|
|
98
|
+
if (!fs.existsSync(claudeMd)) return;
|
|
99
|
+
const content = fs.readFileSync(claudeMd, "utf-8");
|
|
100
|
+
const updated = removeSection(content, REGISTRATION_HEADING, "# ");
|
|
101
|
+
if (updated === content) return;
|
|
102
|
+
if (updated.trim()) fs.writeFileSync(claudeMd, updated);
|
|
103
|
+
else fs.unlinkSync(claudeMd);
|
|
104
|
+
}
|
|
105
|
+
/** `content` without the section that starts at the exact line `heading` and ends before the next `boundary` line. */
|
|
106
|
+
function removeSection(content, heading, boundary) {
|
|
107
|
+
const lines = content.split("\n");
|
|
108
|
+
const start = lines.findIndex((line) => line.trim() === heading);
|
|
109
|
+
if (start === -1) return content;
|
|
110
|
+
const length = lines.slice(start + 1).findIndex((line) => line.startsWith(boundary));
|
|
111
|
+
return `${[...lines.slice(0, start), ...length === -1 ? [] : lines.slice(start + 1 + length)].join("\n").replace(/\n{3,}/g, "\n\n").trim()}\n`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
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`.
|
|
117
|
+
*/
|
|
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
|
+
};
|
|
124
|
+
const isGraphifyCommand = (command = "") => command.includes("graphify") && /\bhook-(guard|check)\b/.test(command);
|
|
125
|
+
/** A graphify hook command, any executable path, run from `.venv`. */
|
|
126
|
+
const toVenvCommand = (command) => command.replace(/^(?:"[^"]*"|\S+)(?=\s+hook-(?:guard|check)\b)/, VENV_HOOK_EXE);
|
|
127
|
+
/**
|
|
128
|
+
* `settings` with graphify's hooks run from `.venv` (`venv`), or without them (an emptied group, event or `hooks`
|
|
129
|
+
* goes too).
|
|
130
|
+
*/
|
|
131
|
+
function updateGraphifyHooks(settings, venv) {
|
|
132
|
+
const hooks = {};
|
|
133
|
+
for (const [event, groups] of Object.entries(settings.hooks ?? {})) {
|
|
134
|
+
const kept = groups.flatMap((group) => {
|
|
135
|
+
if (!group.hooks?.some((hook) => isGraphifyCommand(hook.command))) return [group];
|
|
136
|
+
const own = venv ? group.hooks.map((hook) => isGraphifyCommand(hook.command) ? {
|
|
137
|
+
...hook,
|
|
138
|
+
command: toVenvCommand(hook.command)
|
|
139
|
+
} : hook) : group.hooks.filter((hook) => !isGraphifyCommand(hook.command));
|
|
140
|
+
return own.length ? [{
|
|
141
|
+
...group,
|
|
142
|
+
hooks: own
|
|
143
|
+
}] : [];
|
|
144
|
+
});
|
|
145
|
+
if (kept.length) hooks[event] = kept;
|
|
146
|
+
}
|
|
147
|
+
const rest = { ...settings };
|
|
148
|
+
delete rest.hooks;
|
|
149
|
+
return Object.keys(hooks).length ? {
|
|
150
|
+
...rest,
|
|
151
|
+
hooks
|
|
152
|
+
} : rest;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Run updateGraphifyHooks() over `.claude/settings.json`, writing it only when it changes; a file that does not parse
|
|
156
|
+
* is left alone.
|
|
157
|
+
*/
|
|
158
|
+
function updateClaudeSettings(cwd, venv) {
|
|
159
|
+
const file = path.join(cwd, ".claude", "settings.json");
|
|
160
|
+
if (!fs.existsSync(file)) return;
|
|
161
|
+
let settings;
|
|
162
|
+
try {
|
|
163
|
+
settings = JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.warn(`[lint-prepare] ${file} does not parse, graphify hooks not updated`, { error });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const updated = updateGraphifyHooks(settings, venv);
|
|
169
|
+
if (JSON.stringify(updated) !== JSON.stringify(settings)) fs.writeFileSync(file, `${JSON.stringify(updated, null, 2)}\n`);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* `graphify claude install`: its section into AGENTS.md (through the `CLAUDE.md` link, between the anchors) and its
|
|
173
|
+
* hooks into `.claude/settings.json`, then the hooks pointed at `.venv`. Not `--project`: that installs the skill
|
|
174
|
+
* again.
|
|
175
|
+
*/
|
|
176
|
+
function installGraphifyInstructions(cwd, exe, run) {
|
|
177
|
+
if (runQuiet(run, exe, ["claude", "install"], cwd)) updateClaudeSettings(cwd, true);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The root `.gitignore` with lint-prepare's graphify block listing `entries`, or without it when there are none. The
|
|
181
|
+
* block depends on `lint.config.ts` only, never on what a machine has, so every clone writes the same.
|
|
182
|
+
*/
|
|
183
|
+
function updateGitignoreBlock(content, entries) {
|
|
184
|
+
const lines = content.split("\n");
|
|
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();
|
|
187
|
+
const block = entries.length ? [
|
|
188
|
+
GITIGNORE_BEGIN,
|
|
189
|
+
...entries,
|
|
190
|
+
GITIGNORE_END
|
|
191
|
+
].join("\n") : "";
|
|
192
|
+
return [text, block].filter(Boolean).join("\n\n") + (text || block ? "\n" : "");
|
|
193
|
+
}
|
|
194
|
+
/** Write updateGitignoreBlock() into `cwd/.gitignore` when it changes. */
|
|
195
|
+
function writeGitignoreBlock(cwd, mode) {
|
|
196
|
+
const file = path.join(cwd, ".gitignore");
|
|
197
|
+
const entries = {
|
|
198
|
+
off: [],
|
|
199
|
+
detect: ["/graphify-out"],
|
|
200
|
+
venv: ["/graphify-out", `/${VENV}`]
|
|
201
|
+
}[mode];
|
|
202
|
+
const content = fs.existsSync(file) ? fs.readFileSync(file, "utf-8") : "";
|
|
203
|
+
const updated = updateGitignoreBlock(content, entries);
|
|
204
|
+
if (updated !== content) fs.writeFileSync(file, updated);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Set graphify up for `mode` before the agent dirs are synced: the executable (`.venv` installed for `venv`, `PATH`
|
|
208
|
+
* for `detect`) and its skills; `off` removes them. Nothing on CI. Throws when `venv` has no `uv`.
|
|
209
|
+
*/
|
|
210
|
+
function setUpGraphify(cwd, option, run) {
|
|
211
|
+
const { mode, version } = graphifyMode(option);
|
|
212
|
+
const setup = { mode };
|
|
213
|
+
if (process.env.CI) return setup;
|
|
214
|
+
if (mode === "off") {
|
|
215
|
+
removeGraphifySkills(cwd);
|
|
216
|
+
return setup;
|
|
217
|
+
}
|
|
218
|
+
if (mode === "detect") {
|
|
219
|
+
const exe = findOnPath("graphify");
|
|
220
|
+
if (!exe) {
|
|
221
|
+
console.log("graphify is not on PATH, skipped (graphify: false in lint.config.ts silences this)");
|
|
222
|
+
return setup;
|
|
223
|
+
}
|
|
224
|
+
setup.exe = exe;
|
|
225
|
+
} else {
|
|
226
|
+
if (!installGraphifyVenv(cwd, version, run)) return setup;
|
|
227
|
+
setup.exe = venvExe(cwd);
|
|
228
|
+
}
|
|
229
|
+
if (!installGraphifySkills(cwd, setup.exe, run)) return { mode };
|
|
230
|
+
console.log(`Set up graphify (${mode === "venv" ? `${VENV}, graphifyy ${version}` : setup.exe})`);
|
|
231
|
+
return setup;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* After AGENTS.md is generated: `venv` gets graphify's section and hooks, the other modes lose the hooks. Then the code
|
|
235
|
+
* graph in `graphify-out` is built or refreshed (`graphify update .`: code only, no LLM, no API key). Nothing on CI.
|
|
236
|
+
*/
|
|
237
|
+
function finishGraphify(cwd, { mode, exe }, run) {
|
|
238
|
+
if (process.env.CI) return;
|
|
239
|
+
if (mode !== "venv") updateClaudeSettings(cwd, false);
|
|
240
|
+
else if (exe) installGraphifyInstructions(cwd, exe, run);
|
|
241
|
+
if (!exe) return;
|
|
242
|
+
console.log("Building the graphify code graph (graphify update .)");
|
|
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"
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
//#endregion
|
|
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";
|
|
3
|
-
import { DEFAULT_LINT_CONFIG, DefaultIgnoreOptions, DetectionOptions, EslintOptions, LINT_CONFIG_FILE, LintConfig, NextOptions, SkillSourceOptions, SkillsConfig, TailwindOptions, ToggleOptions, TypeAwareOptions, VitePlusOptions, defineLintConfig, loadLintConfig, mergeLintConfig, resolveLintConfig } from "./config.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
|
+
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, 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";
|
|
3
|
-
import { DEFAULT_LINT_CONFIG, LINT_CONFIG_FILE, defineLintConfig, loadLintConfig, mergeLintConfig, resolveLintConfig } from "./config.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
|
+
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, 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 };
|