@jondeodat/claude-setup-cli 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -9
- package/dist/claude-setup-cli.js +24 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -44,6 +44,13 @@ It never fails, so that it cannot break an `npm install` or a session start: a f
|
|
|
44
44
|
unknown plugin…) is reported, and the run goes on. It does nothing without the `claude` CLI, in CI (`CI`
|
|
45
45
|
set), or with `CLAUDE_SETUP_SKIP` set.
|
|
46
46
|
|
|
47
|
+
The `claude` CLI it runs is the one `CLAUDE_CODE_EXECPATH` names, or else the `claude` on the `PATH`,
|
|
48
|
+
whichever first answers `--version` as Claude Code. Claude Code sets `CLAUDE_CODE_EXECPATH` in the
|
|
49
|
+
processes it starts, a hook among them: a Claude Code installed only as an IDE extension puts no `claude`
|
|
50
|
+
on the `PATH`, but names its own binary in the variable, so its hooks still find it. The variable is not
|
|
51
|
+
documented, and may name a binary an update removed since or one that is not the `claude` CLI, hence the
|
|
52
|
+
check and the fallback.
|
|
53
|
+
|
|
47
54
|
## Installation
|
|
48
55
|
|
|
49
56
|
```sh
|
|
@@ -65,15 +72,8 @@ claude-setup [--hook] [--max-age <hours>]
|
|
|
65
72
|
- `--max-age <hours>` refreshes the marketplaces only when the last refresh, recorded in
|
|
66
73
|
`node_modules/.cache/claude-setup/state.json`, is older. Without it, every run refreshes.
|
|
67
74
|
|
|
68
|
-
In a project, from
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
```json
|
|
72
|
-
"prepare": "claude-setup"
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
And from a `SessionStart` hook of `.claude/settings.json`, once a day. The guard skips it in a clone where
|
|
76
|
-
the dependencies are not installed yet:
|
|
75
|
+
In a project, from a `SessionStart` hook of `.claude/settings.json`, once a day. The guard skips it in a
|
|
76
|
+
clone where the dependencies are not installed yet:
|
|
77
77
|
|
|
78
78
|
```json
|
|
79
79
|
"hooks": {
|
|
@@ -91,6 +91,21 @@ the dependencies are not installed yet:
|
|
|
91
91
|
}
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
Optionally, also from the `prepare` script of its `package.json`, which runs on an `npm install` or
|
|
95
|
+
`npm ci` in the project itself but not where the project is installed as a dependency (unlike
|
|
96
|
+
`postinstall`):
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
"prepare": "claude-setup"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- npm does not run it when `ignore-scripts` is set, a common hardening: `ignore-scripts` turns off the
|
|
103
|
+
scripts of the project's own `package.json` too, and `allowScripts` cannot let it through, since it only
|
|
104
|
+
covers the install scripts of dependencies and `ignore-scripts` overrides it. `npm run prepare` still
|
|
105
|
+
runs it.
|
|
106
|
+
- Run by npm, it only has `CLAUDE_CODE_EXECPATH` when the `npm install` itself was started from Claude
|
|
107
|
+
Code, such as from its Bash tool: otherwise it needs `claude` on the `PATH`.
|
|
108
|
+
|
|
94
109
|
## Development
|
|
95
110
|
|
|
96
111
|
```sh
|
|
@@ -138,6 +153,10 @@ npm run push
|
|
|
138
153
|
- `npm run push` runs `npm publish`, whose `prepublishOnly` script first runs `npm run typecheck`,
|
|
139
154
|
`npm test`, `npm run format:check` and `npm run build`, and stops if one fails; then it publishes the
|
|
140
155
|
package, publicly, on registry.npmjs.org.
|
|
156
|
+
- With `ignore-scripts` set, `npm publish` skips `prepublishOnly` and ships whatever `dist/` holds, stale
|
|
157
|
+
or missing: `npm run push` passes `--ignore-scripts=false`, so publish with it rather than with
|
|
158
|
+
`npm publish`. A publish installs nothing, so this only lets the scripts of this `package.json` run, no
|
|
159
|
+
dependency's.
|
|
141
160
|
|
|
142
161
|
## License
|
|
143
162
|
|
package/dist/claude-setup-cli.js
CHANGED
|
@@ -13,12 +13,32 @@ than the min-release-age npm reads for the project (.npmrc).
|
|
|
13
13
|
|
|
14
14
|
The claude CLI rewrites .claude/settings.json in its own format: this tool puts the file back as it was.
|
|
15
15
|
It does nothing in CI (CI set), with CLAUDE_SETUP_SKIP set, or without the claude CLI, and never fails.
|
|
16
|
+
The claude CLI is the one CLAUDE_CODE_EXECPATH names, set by Claude Code in a hook, or else the one on
|
|
17
|
+
the PATH, whichever first answers --version as Claude Code.
|
|
16
18
|
|
|
17
19
|
Options:
|
|
18
20
|
--hook prints its report as the JSON output of a SessionStart hook, and nothing when there
|
|
19
21
|
is nothing to report
|
|
20
22
|
--max-age <hours> refreshes the marketplaces only when the last refresh is older (default: every run)
|
|
21
23
|
-h, --help prints this help`;
|
|
24
|
+
/**
|
|
25
|
+
* Finds the claude CLI to run: the one of the Claude Code session that started this tool, as a hook,
|
|
26
|
+
* which Claude Code names in CLAUDE_CODE_EXECPATH even when it is only installed as an IDE extension and
|
|
27
|
+
* puts no claude on the PATH; or else the claude on the PATH. CLAUDE_CODE_EXECPATH is not documented: it
|
|
28
|
+
* can name a binary removed by an update since, or one that is not the claude CLI, so each candidate must
|
|
29
|
+
* answer `--version` as Claude Code does
|
|
30
|
+
*/
|
|
31
|
+
function findClaude() {
|
|
32
|
+
const candidates = [process.env.CLAUDE_CODE_EXECPATH, 'claude'].filter((candidate) => !!candidate);
|
|
33
|
+
return candidates.find((candidate) => {
|
|
34
|
+
const probe = spawnSync(candidate, ['--version'], { encoding: 'utf8' });
|
|
35
|
+
return !probe.error && probe.status === 0 && probe.stdout.includes('Claude Code');
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The claude CLI to run, that main() finds before anything runs it
|
|
40
|
+
*/
|
|
41
|
+
let claude = 'claude';
|
|
22
42
|
/**
|
|
23
43
|
* A `claude plugin` command can clone a marketplace
|
|
24
44
|
*/
|
|
@@ -27,7 +47,7 @@ const CLAUDE_TIMEOUT_MS = 180_000;
|
|
|
27
47
|
* Runs `claude <args> --json` from the project root
|
|
28
48
|
*/
|
|
29
49
|
function runClaude(root, args) {
|
|
30
|
-
const child = spawnSync(
|
|
50
|
+
const child = spawnSync(claude, [...args, '--json'], { cwd: root, encoding: 'utf8', timeout: CLAUDE_TIMEOUT_MS });
|
|
31
51
|
if (child.error) {
|
|
32
52
|
return { error: `claude ${args.join(' ')}: ${child.error.message}` };
|
|
33
53
|
}
|
|
@@ -287,10 +307,11 @@ function main() {
|
|
|
287
307
|
const report = createReport();
|
|
288
308
|
const original = readFileSync(settingsPath, 'utf8');
|
|
289
309
|
try {
|
|
290
|
-
const
|
|
291
|
-
if (
|
|
310
|
+
const found = findClaude();
|
|
311
|
+
if (!found) {
|
|
292
312
|
return;
|
|
293
313
|
}
|
|
314
|
+
claude = found;
|
|
294
315
|
setUp(root, JSON.parse(original), maxAgeHours, report);
|
|
295
316
|
}
|
|
296
317
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jondeodat/claude-setup-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Registers the Claude Code marketplaces and installs the plugins that a project declares in .claude/settings.json, at project scope.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"format": "prettier --write .",
|
|
48
48
|
"format:check": "prettier --check .",
|
|
49
49
|
"prepublishOnly": "npm run typecheck && npm test && npm run format:check && npm run build",
|
|
50
|
-
"push": "npm publish"
|
|
50
|
+
"push": "npm publish --ignore-scripts=false"
|
|
51
51
|
},
|
|
52
52
|
"keywords": [
|
|
53
53
|
"claude",
|