@seoagent-official/seoagent 1.12.0 → 1.13.0
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/package.json +3 -2
- package/postinstall-hint.cjs +18 -19
- package/postinstall-lib.cjs +117 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seoagent-official/seoagent",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Scaffolder for Claude Code's SEOAgent skill. Run once: `npx -y @seoagent-official/seoagent init`. Sets up .seoagent/ for persistent audits, keyword strategy, content planning, and optimized writing. Not a runtime dependency.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"index.js",
|
|
11
11
|
"skills",
|
|
12
12
|
"assets",
|
|
13
|
-
"postinstall-hint.cjs"
|
|
13
|
+
"postinstall-hint.cjs",
|
|
14
|
+
"postinstall-lib.cjs"
|
|
14
15
|
],
|
|
15
16
|
"dependencies": {
|
|
16
17
|
"@clack/prompts": "^0.9.0",
|
package/postinstall-hint.cjs
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
const fs = require('fs');
|
|
20
20
|
const path = require('path');
|
|
21
21
|
const { spawnSync } = require('child_process');
|
|
22
|
+
const { isDirectInstall } = require('./postinstall-lib.cjs');
|
|
22
23
|
|
|
23
24
|
// -----------------------------------------------------------------------------
|
|
24
25
|
// Guards — skip auto-init when it would be wrong or annoying.
|
|
@@ -53,8 +54,20 @@ if (!projectRoot || !fs.existsSync(projectRoot)) {
|
|
|
53
54
|
// Don't auto-init when the package is being installed inside another
|
|
54
55
|
// package's `node_modules` (a transitive dep). INIT_CWD would be the
|
|
55
56
|
// transitive consumer's project root, not ours — we'd scaffold their repo.
|
|
56
|
-
//
|
|
57
|
-
|
|
57
|
+
//
|
|
58
|
+
// Detecting "transitive" reliably is harder than it looks: when a user runs
|
|
59
|
+
// `npm install @seoagent-official/seoagent` in a fresh project, npm 7+ runs
|
|
60
|
+
// THIS postinstall BEFORE writing the new dep to INIT_CWD/package.json. So
|
|
61
|
+
// "is our package name in INIT_CWD/package.json" is false-negative-prone and
|
|
62
|
+
// silently kills the captive install moment on every fresh install — which
|
|
63
|
+
// is exactly the case we most need it to fire on.
|
|
64
|
+
//
|
|
65
|
+
// Instead: look at sibling node_modules entries. If ANY of them declares us
|
|
66
|
+
// as a dependency, we're being dragged in transitively → bail. Otherwise
|
|
67
|
+
// we're a direct install (or no one else needs us yet) → proceed.
|
|
68
|
+
// We still consult package.json as a positive signal (e.g. for repeat installs
|
|
69
|
+
// where the dep is already saved), since it strengthens the "direct" conclusion.
|
|
70
|
+
if (!isDirectInstall(projectRoot)) {
|
|
58
71
|
// Most likely transitive — bail silently.
|
|
59
72
|
process.exit(0);
|
|
60
73
|
}
|
|
@@ -94,25 +107,11 @@ if (result.status === 0) {
|
|
|
94
107
|
}
|
|
95
108
|
|
|
96
109
|
// -----------------------------------------------------------------------------
|
|
97
|
-
// Helpers
|
|
110
|
+
// Helpers — direct-install detection lives in ./postinstall-lib.cjs so it can
|
|
111
|
+
// be unit-tested without firing the side effects above. The print functions
|
|
112
|
+
// stay inline because they don't have meaningful behavior to test.
|
|
98
113
|
// -----------------------------------------------------------------------------
|
|
99
114
|
|
|
100
|
-
function projectDeclaresUs(root) {
|
|
101
|
-
try {
|
|
102
|
-
const pkgPath = path.join(root, 'package.json');
|
|
103
|
-
if (!fs.existsSync(pkgPath)) {
|
|
104
|
-
// No package.json — user ran `npm install <pkg>` in an empty dir or
|
|
105
|
-
// outside a project. That's unusual but valid for scaffolding.
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
109
|
-
const all = { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) };
|
|
110
|
-
return '@seoagent-official/seoagent' in all;
|
|
111
|
-
} catch {
|
|
112
|
-
return true; // On error, fail open — better to scaffold than not.
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
115
|
function printPreInitBanner() {
|
|
117
116
|
process.stdout.write(
|
|
118
117
|
'\n' +
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// postinstall-lib — pure helpers used by postinstall-hint.cjs
|
|
5
|
+
//
|
|
6
|
+
// Lives in its own file (instead of inline in postinstall-hint.cjs) for two
|
|
7
|
+
// reasons:
|
|
8
|
+
// 1. Unit-testable. The main script has top-level side effects
|
|
9
|
+
// (process.exit, spawnSync) that fire on require — splitting the pure
|
|
10
|
+
// logic out means vitest can require THIS file safely.
|
|
11
|
+
// 2. The regression we're guarding against is subtle: npm 7+ writes the
|
|
12
|
+
// newly-installed package to the parent's package.json AFTER running
|
|
13
|
+
// the package's postinstall script. So the old "is our name in
|
|
14
|
+
// INIT_CWD/package.json" check returned false on every fresh install,
|
|
15
|
+
// silently killing the captive moment we built the package around.
|
|
16
|
+
// Tests for THIS file pin the corrected behavior in place.
|
|
17
|
+
// =============================================================================
|
|
18
|
+
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
const path = require('path');
|
|
21
|
+
|
|
22
|
+
const PKG_NAME = '@seoagent-official/seoagent';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Decide whether this postinstall is firing for a DIRECT install (user/agent
|
|
26
|
+
* explicitly added us) vs a TRANSITIVE install (we're a dep of someone else's
|
|
27
|
+
* dep). Returns true ⇒ scaffold; false ⇒ silent bail.
|
|
28
|
+
*
|
|
29
|
+
* Strategy is two-step because both signals alone are unreliable:
|
|
30
|
+
* 1. POSITIVE — INIT_CWD/package.json already lists us. Confirms direct
|
|
31
|
+
* (but is FALSE on the most common case: first-time `npm install <us>`,
|
|
32
|
+
* because npm 7+ writes package.json AFTER lifecycle scripts).
|
|
33
|
+
* 2. NEGATIVE — Look at every sibling under INIT_CWD/node_modules and check
|
|
34
|
+
* if any of THEIR package.json lists us as a dep. If yes → transitive.
|
|
35
|
+
* If no → direct (or top-level install with no other consumer yet).
|
|
36
|
+
*
|
|
37
|
+
* If both are inconclusive (e.g. no package.json at all because the user ran
|
|
38
|
+
* `npm install <us>` in an empty dir), default to "direct" — scaffolding is
|
|
39
|
+
* the whole point of the package and the existing `.seoagent/project.md`
|
|
40
|
+
* idempotency guard prevents double-scaffolding on subsequent runs.
|
|
41
|
+
*/
|
|
42
|
+
function isDirectInstall(root) {
|
|
43
|
+
if (!root) return true; // No INIT_CWD: nothing else we can check; scaffold.
|
|
44
|
+
if (declaredInProjectJson(root)) return true;
|
|
45
|
+
if (anySiblingDependsOnUs(root)) return false;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function declaredInProjectJson(root) {
|
|
50
|
+
try {
|
|
51
|
+
const pkgPath = path.join(root, 'package.json');
|
|
52
|
+
if (!fs.existsSync(pkgPath)) return false;
|
|
53
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
54
|
+
const all = mergeAllDepKinds(pkg);
|
|
55
|
+
return PKG_NAME in all;
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function anySiblingDependsOnUs(root) {
|
|
62
|
+
try {
|
|
63
|
+
const nm = path.join(root, 'node_modules');
|
|
64
|
+
if (!fs.existsSync(nm)) return false;
|
|
65
|
+
for (const entry of fs.readdirSync(nm, { withFileTypes: true })) {
|
|
66
|
+
if (!entry.isDirectory() || entry.name.startsWith('.')) continue;
|
|
67
|
+
// Scoped packages: recurse one level.
|
|
68
|
+
if (entry.name.startsWith('@')) {
|
|
69
|
+
const scopeDir = path.join(nm, entry.name);
|
|
70
|
+
let scoped;
|
|
71
|
+
try {
|
|
72
|
+
scoped = fs.readdirSync(scopeDir, { withFileTypes: true });
|
|
73
|
+
} catch {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
for (const inner of scoped) {
|
|
77
|
+
if (!inner.isDirectory()) continue;
|
|
78
|
+
// Skip ourselves.
|
|
79
|
+
if (entry.name === '@seoagent-official' && inner.name === 'seoagent') continue;
|
|
80
|
+
if (pkgListsUs(path.join(scopeDir, inner.name, 'package.json'))) return true;
|
|
81
|
+
}
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (pkgListsUs(path.join(nm, entry.name, 'package.json'))) return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
} catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function pkgListsUs(pkgJsonPath) {
|
|
93
|
+
try {
|
|
94
|
+
if (!fs.existsSync(pkgJsonPath)) return false;
|
|
95
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
|
|
96
|
+
return PKG_NAME in mergeAllDepKinds(pkg);
|
|
97
|
+
} catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function mergeAllDepKinds(pkg) {
|
|
103
|
+
return {
|
|
104
|
+
...(pkg.dependencies || {}),
|
|
105
|
+
...(pkg.devDependencies || {}),
|
|
106
|
+
...(pkg.optionalDependencies || {}),
|
|
107
|
+
...(pkg.peerDependencies || {}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = {
|
|
112
|
+
PKG_NAME,
|
|
113
|
+
isDirectInstall,
|
|
114
|
+
declaredInProjectJson,
|
|
115
|
+
anySiblingDependsOnUs,
|
|
116
|
+
pkgListsUs,
|
|
117
|
+
};
|