@getripple/core 1.0.4 → 1.0.6
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/CHANGELOG.md +13 -0
- package/README.md +306 -23
- package/dist/audit.d.ts +4 -0
- package/dist/audit.js +5 -0
- package/dist/audit.js.map +1 -1
- package/dist/change-intent.d.ts +1 -0
- package/dist/change-intent.js +22 -6
- package/dist/change-intent.js.map +1 -1
- package/dist/git.d.ts +6 -0
- package/dist/git.js +57 -0
- package/dist/git.js.map +1 -0
- package/dist/graph.d.ts +22 -2
- package/dist/graph.js +119 -31
- package/dist/graph.js.map +1 -1
- package/dist/readiness.d.ts +10 -0
- package/dist/readiness.js +117 -19
- package/dist/readiness.js.map +1 -1
- package/dist/staged-check.js +160 -98
- package/dist/staged-check.js.map +1 -1
- package/package.json +2 -2
package/dist/readiness.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { RippleAdapterDetectionSummary } from "./adapters";
|
|
2
2
|
import { GraphEngine } from "./graph";
|
|
3
3
|
export declare const RIPPLE_CI_WORKFLOW_PATH = ".github/workflows/ripple.yml";
|
|
4
|
+
export declare const RIPPLE_GITIGNORE_PATH = ".gitignore";
|
|
5
|
+
export declare const RIPPLE_CACHE_GITIGNORE_ENTRY = ".ripple/.cache/";
|
|
4
6
|
export type RippleReadinessCheck = {
|
|
5
7
|
ok: boolean;
|
|
6
8
|
detail: string;
|
|
@@ -16,8 +18,15 @@ export type RippleEnforcementReadiness = {
|
|
|
16
18
|
explicitPolicy: RippleReadinessCheck;
|
|
17
19
|
gaps: string[];
|
|
18
20
|
};
|
|
21
|
+
export type RippleReadinessDecision = "continue" | "setup-required";
|
|
19
22
|
export type RippleReadinessSummary = {
|
|
20
23
|
status: "ready" | "needs_setup";
|
|
24
|
+
decision: RippleReadinessDecision;
|
|
25
|
+
canContinue: boolean;
|
|
26
|
+
mustStop: boolean;
|
|
27
|
+
nextRequiredAction: string;
|
|
28
|
+
why: string[];
|
|
29
|
+
fixNow: string[];
|
|
21
30
|
workspace: string;
|
|
22
31
|
sourceFiles: number;
|
|
23
32
|
symbols: number;
|
|
@@ -27,6 +36,7 @@ export type RippleReadinessSummary = {
|
|
|
27
36
|
checks: {
|
|
28
37
|
graph: RippleReadinessCheck;
|
|
29
38
|
git: RippleReadinessCheck;
|
|
39
|
+
gitIgnore: RippleReadinessCheck;
|
|
30
40
|
ciWorkflow: RippleReadinessCheck;
|
|
31
41
|
latestIntent: RippleReadinessCheck;
|
|
32
42
|
};
|
package/dist/readiness.js
CHANGED
|
@@ -23,13 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.buildRippleReadinessSummary = exports.RIPPLE_CI_WORKFLOW_PATH = void 0;
|
|
26
|
+
exports.buildRippleReadinessSummary = exports.RIPPLE_CACHE_GITIGNORE_ENTRY = exports.RIPPLE_GITIGNORE_PATH = exports.RIPPLE_CI_WORKFLOW_PATH = void 0;
|
|
27
27
|
const fs = __importStar(require("fs"));
|
|
28
28
|
const path = __importStar(require("path"));
|
|
29
|
-
const child_process_1 = require("child_process");
|
|
30
29
|
const adapters_1 = require("./adapters");
|
|
31
30
|
const change_intent_1 = require("./change-intent");
|
|
31
|
+
const git_1 = require("./git");
|
|
32
32
|
exports.RIPPLE_CI_WORKFLOW_PATH = ".github/workflows/ripple.yml";
|
|
33
|
+
exports.RIPPLE_GITIGNORE_PATH = ".gitignore";
|
|
34
|
+
exports.RIPPLE_CACHE_GITIGNORE_ENTRY = ".ripple/.cache/";
|
|
33
35
|
function buildRippleReadinessSummary(workspaceRoot, engine) {
|
|
34
36
|
const sourceFiles = engine.graph.files.size;
|
|
35
37
|
const symbols = engine.graph.symbols.size;
|
|
@@ -39,7 +41,9 @@ function buildRippleReadinessSummary(workspaceRoot, engine) {
|
|
|
39
41
|
const latestIntentPath = (0, change_intent_1.defaultChangeIntentPath)(workspaceRoot);
|
|
40
42
|
const policyPath = path.join(workspaceRoot, ".ripple", "policy.json");
|
|
41
43
|
const graphOk = sourceFiles > 0;
|
|
42
|
-
const
|
|
44
|
+
const gitCheck = gitWorktreeCheck(workspaceRoot);
|
|
45
|
+
const gitOk = gitCheck.ok;
|
|
46
|
+
const gitIgnoreCheck = rippleGitIgnoreCheck(workspaceRoot);
|
|
43
47
|
const ciWorkflowOk = fs.existsSync(workflowPath);
|
|
44
48
|
const latestIntentOk = fs.existsSync(latestIntentPath);
|
|
45
49
|
const explicitPolicyOk = fs.existsSync(policyPath);
|
|
@@ -51,11 +55,8 @@ function buildRippleReadinessSummary(workspaceRoot, engine) {
|
|
|
51
55
|
: "No supported source files were found",
|
|
52
56
|
fix: graphOk ? undefined : "Run Ripple from a JavaScript, TypeScript, or Python repo root.",
|
|
53
57
|
},
|
|
54
|
-
git:
|
|
55
|
-
|
|
56
|
-
detail: gitOk ? "Inside a git worktree" : "Not inside a git worktree",
|
|
57
|
-
fix: gitOk ? undefined : "Run Ripple inside a git repository.",
|
|
58
|
-
},
|
|
58
|
+
git: gitCheck,
|
|
59
|
+
gitIgnore: gitIgnoreCheck,
|
|
59
60
|
ciWorkflow: {
|
|
60
61
|
ok: ciWorkflowOk,
|
|
61
62
|
detail: ciWorkflowOk
|
|
@@ -76,6 +77,8 @@ function buildRippleReadinessSummary(workspaceRoot, engine) {
|
|
|
76
77
|
const enforcement = buildEnforcementReadiness({
|
|
77
78
|
graphOk,
|
|
78
79
|
gitOk,
|
|
80
|
+
gitDetail: gitCheck.detail,
|
|
81
|
+
gitIgnoreOk: gitIgnoreCheck.ok,
|
|
79
82
|
ciWorkflowOk,
|
|
80
83
|
latestIntentOk,
|
|
81
84
|
explicitPolicyOk,
|
|
@@ -86,8 +89,16 @@ function buildRippleReadinessSummary(workspaceRoot, engine) {
|
|
|
86
89
|
if (nextSteps.length === 0) {
|
|
87
90
|
nextSteps.push("Run ripple ci --base origin/main --intent latest --github-annotations.");
|
|
88
91
|
}
|
|
92
|
+
const status = Object.values(checks).every((check) => check.ok) ? "ready" : "needs_setup";
|
|
93
|
+
const contract = readinessContract(status, enforcement, nextSteps);
|
|
89
94
|
return {
|
|
90
|
-
status
|
|
95
|
+
status,
|
|
96
|
+
decision: contract.decision,
|
|
97
|
+
canContinue: contract.canContinue,
|
|
98
|
+
mustStop: contract.mustStop,
|
|
99
|
+
nextRequiredAction: contract.nextRequiredAction,
|
|
100
|
+
why: contract.why,
|
|
101
|
+
fixNow: contract.fixNow,
|
|
91
102
|
workspace: workspaceRoot,
|
|
92
103
|
sourceFiles,
|
|
93
104
|
symbols,
|
|
@@ -99,6 +110,26 @@ function buildRippleReadinessSummary(workspaceRoot, engine) {
|
|
|
99
110
|
};
|
|
100
111
|
}
|
|
101
112
|
exports.buildRippleReadinessSummary = buildRippleReadinessSummary;
|
|
113
|
+
function readinessContract(status, enforcement, nextSteps) {
|
|
114
|
+
if (status === "ready") {
|
|
115
|
+
return {
|
|
116
|
+
decision: "continue",
|
|
117
|
+
canContinue: true,
|
|
118
|
+
mustStop: false,
|
|
119
|
+
nextRequiredAction: "Continue with the saved-intent workflow and keep the Ripple CI gate enabled.",
|
|
120
|
+
why: [enforcement.summary],
|
|
121
|
+
fixNow: [],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
decision: "setup-required",
|
|
126
|
+
canContinue: false,
|
|
127
|
+
mustStop: true,
|
|
128
|
+
nextRequiredAction: "Stop autonomous agent work until Ripple readiness gaps are fixed.",
|
|
129
|
+
why: enforcement.gaps,
|
|
130
|
+
fixNow: nextSteps,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
102
133
|
function buildEnforcementReadiness(input) {
|
|
103
134
|
const canGuideAgents = input.graphOk;
|
|
104
135
|
const canDetectDrift = input.graphOk && input.gitOk && input.latestIntentOk;
|
|
@@ -157,7 +188,10 @@ function enforcementGaps(input) {
|
|
|
157
188
|
gaps.push("No supported source graph is available.");
|
|
158
189
|
}
|
|
159
190
|
if (!input.gitOk) {
|
|
160
|
-
gaps.push(
|
|
191
|
+
gaps.push(`${input.gitDetail} Git is required for changed-file and CI drift checks.`);
|
|
192
|
+
}
|
|
193
|
+
if (!input.gitIgnoreOk) {
|
|
194
|
+
gaps.push("Missing .gitignore hygiene for .ripple/.cache/; generated cache files may be committed accidentally.");
|
|
161
195
|
}
|
|
162
196
|
if (!input.latestIntentOk) {
|
|
163
197
|
gaps.push("No latest saved intent exists, so Ripple cannot compare agent work to a plan.");
|
|
@@ -177,18 +211,82 @@ function countCallEdges(engine) {
|
|
|
177
211
|
});
|
|
178
212
|
return count;
|
|
179
213
|
}
|
|
180
|
-
function
|
|
214
|
+
function gitWorktreeCheck(workspaceRoot) {
|
|
181
215
|
try {
|
|
182
|
-
const output = (0,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
216
|
+
const output = (0, git_1.execGit)(workspaceRoot, ["rev-parse", "--is-inside-work-tree"], ["ignore", "pipe", "ignore"]);
|
|
217
|
+
const insideWorktree = output.trim() === "true";
|
|
218
|
+
return {
|
|
219
|
+
ok: insideWorktree,
|
|
220
|
+
detail: insideWorktree
|
|
221
|
+
? "Inside a git worktree"
|
|
222
|
+
: "Git command ran, but this directory is not inside a git worktree",
|
|
223
|
+
fix: insideWorktree
|
|
224
|
+
? undefined
|
|
225
|
+
: "Run Ripple from the repository root or initialize git first.",
|
|
226
|
+
};
|
|
188
227
|
}
|
|
189
|
-
catch {
|
|
190
|
-
|
|
228
|
+
catch (err) {
|
|
229
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
230
|
+
return {
|
|
231
|
+
ok: false,
|
|
232
|
+
detail,
|
|
233
|
+
fix: gitFixFor(detail),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function gitFixFor(detail) {
|
|
238
|
+
if (/could not be started|EPERM|EACCES/i.test(detail)) {
|
|
239
|
+
return "Run Ripple from a normal terminal, or allow Node.js to execute git in this environment.";
|
|
191
240
|
}
|
|
241
|
+
if (/not found|ENOENT/i.test(detail)) {
|
|
242
|
+
return "Install Git and make sure git is available on PATH.";
|
|
243
|
+
}
|
|
244
|
+
return "Run Ripple from the repository root or initialize git first.";
|
|
245
|
+
}
|
|
246
|
+
function rippleGitIgnoreCheck(workspaceRoot) {
|
|
247
|
+
const gitignorePath = path.join(workspaceRoot, exports.RIPPLE_GITIGNORE_PATH);
|
|
248
|
+
if (!fs.existsSync(gitignorePath)) {
|
|
249
|
+
return {
|
|
250
|
+
ok: false,
|
|
251
|
+
detail: "Missing .gitignore entry for .ripple/.cache/",
|
|
252
|
+
fix: "Run ripple init or add .ripple/.cache/ to .gitignore.",
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const lines = fs
|
|
256
|
+
.readFileSync(gitignorePath, "utf8")
|
|
257
|
+
.split(/\r?\n/)
|
|
258
|
+
.map((line) => line.trim())
|
|
259
|
+
.filter((line) => line.length > 0 && !line.startsWith("#"));
|
|
260
|
+
const broadRippleIgnore = lines.some(isBroadRippleIgnore);
|
|
261
|
+
if (broadRippleIgnore) {
|
|
262
|
+
return {
|
|
263
|
+
ok: false,
|
|
264
|
+
detail: "Overbroad .ripple/ ignore may hide policy, history, intents, or approvals",
|
|
265
|
+
fix: "Ignore only .ripple/.cache/ so Ripple audit files can be committed intentionally.",
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const cacheIgnored = lines.some(isRippleCacheIgnore);
|
|
269
|
+
return {
|
|
270
|
+
ok: cacheIgnored,
|
|
271
|
+
detail: cacheIgnored
|
|
272
|
+
? ".ripple/.cache/ is ignored; Ripple audit files remain commit-able"
|
|
273
|
+
: "Missing .gitignore entry for .ripple/.cache/",
|
|
274
|
+
fix: cacheIgnored
|
|
275
|
+
? undefined
|
|
276
|
+
: "Run ripple init or add .ripple/.cache/ to .gitignore.",
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function isRippleCacheIgnore(line) {
|
|
280
|
+
const normalized = line.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
281
|
+
return (normalized === exports.RIPPLE_CACHE_GITIGNORE_ENTRY ||
|
|
282
|
+
normalized === ".ripple/.cache" ||
|
|
283
|
+
normalized === ".ripple/.cache/**");
|
|
284
|
+
}
|
|
285
|
+
function isBroadRippleIgnore(line) {
|
|
286
|
+
const normalized = line.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
287
|
+
return (normalized === ".ripple" ||
|
|
288
|
+
normalized === ".ripple/" ||
|
|
289
|
+
normalized === ".ripple/**");
|
|
192
290
|
}
|
|
193
291
|
function formatWorkspacePath(workspaceRoot, filePath) {
|
|
194
292
|
const relative = path.relative(workspaceRoot, filePath);
|
package/dist/readiness.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readiness.js","sourceRoot":"","sources":["../src/readiness.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"readiness.js","sourceRoot":"","sources":["../src/readiness.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,yCAAoF;AACpF,mDAA0D;AAC1D,+BAAgC;AAGnB,QAAA,uBAAuB,GAAG,8BAA8B,CAAC;AACzD,QAAA,qBAAqB,GAAG,YAAY,CAAC;AACrC,QAAA,4BAA4B,GAAG,iBAAiB,CAAC;AAkD9D,SAAgB,2BAA2B,CACzC,aAAqB,EACrB,MAAmB;IAEnB,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;IAC5C,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;IAC1C,MAAM,SAAS,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IACzC,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ACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/staged-check.js
CHANGED
|
@@ -24,10 +24,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.highestStagedRisk = exports.buildStagedCheckSummary = exports.listGitChangedDiff = exports.listGitChangedFiles = exports.listGitStagedDiff = exports.listGitStagedFiles = exports.isRippleSourceFile = void 0;
|
|
27
|
-
const child_process_1 = require("child_process");
|
|
28
27
|
const fs = __importStar(require("fs"));
|
|
29
28
|
const path = __importStar(require("path"));
|
|
30
29
|
const ts_morph_1 = require("ts-morph");
|
|
30
|
+
const git_1 = require("./git");
|
|
31
31
|
const SOURCE_FILE_RE = /\.(ts|tsx|js|jsx|py)$/i;
|
|
32
32
|
const DEFAULT_STAGED_CHECK_TASK = "Review staged change before commit";
|
|
33
33
|
const RISK_RANK = {
|
|
@@ -42,11 +42,12 @@ function isRippleSourceFile(filePath) {
|
|
|
42
42
|
exports.isRippleSourceFile = isRippleSourceFile;
|
|
43
43
|
function listGitStagedFiles(workspaceRoot) {
|
|
44
44
|
try {
|
|
45
|
-
const output = (0,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
const output = (0, git_1.execGit)(workspaceRoot, [
|
|
46
|
+
"diff",
|
|
47
|
+
"--name-only",
|
|
48
|
+
"--cached",
|
|
49
|
+
"--diff-filter=ACMR",
|
|
50
|
+
]);
|
|
50
51
|
return output
|
|
51
52
|
.split(/\r?\n/)
|
|
52
53
|
.map((line) => line.trim())
|
|
@@ -60,11 +61,12 @@ function listGitStagedFiles(workspaceRoot) {
|
|
|
60
61
|
exports.listGitStagedFiles = listGitStagedFiles;
|
|
61
62
|
function listGitStagedDiff(workspaceRoot) {
|
|
62
63
|
try {
|
|
63
|
-
return (0,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
return (0, git_1.execGit)(workspaceRoot, [
|
|
65
|
+
"diff",
|
|
66
|
+
"--cached",
|
|
67
|
+
"--unified=0",
|
|
68
|
+
"--no-ext-diff",
|
|
69
|
+
]);
|
|
68
70
|
}
|
|
69
71
|
catch (err) {
|
|
70
72
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -74,11 +76,13 @@ function listGitStagedDiff(workspaceRoot) {
|
|
|
74
76
|
exports.listGitStagedDiff = listGitStagedDiff;
|
|
75
77
|
function listGitChangedFiles(workspaceRoot, baseRef) {
|
|
76
78
|
try {
|
|
77
|
-
const output = (0,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
const output = (0, git_1.execGit)(workspaceRoot, [
|
|
80
|
+
"diff",
|
|
81
|
+
"--name-only",
|
|
82
|
+
"--diff-filter=ACMR",
|
|
83
|
+
baseRef,
|
|
84
|
+
"--",
|
|
85
|
+
]);
|
|
82
86
|
return output
|
|
83
87
|
.split(/\r?\n/)
|
|
84
88
|
.map((line) => line.trim())
|
|
@@ -94,11 +98,11 @@ function listGitChangedFiles(workspaceRoot, baseRef) {
|
|
|
94
98
|
exports.listGitChangedFiles = listGitChangedFiles;
|
|
95
99
|
function listGitUntrackedSourceFiles(workspaceRoot) {
|
|
96
100
|
try {
|
|
97
|
-
const output = (0,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
const output = (0, git_1.execGit)(workspaceRoot, [
|
|
102
|
+
"ls-files",
|
|
103
|
+
"--others",
|
|
104
|
+
"--exclude-standard",
|
|
105
|
+
]);
|
|
102
106
|
return output
|
|
103
107
|
.split(/\r?\n/)
|
|
104
108
|
.map((line) => line.trim())
|
|
@@ -113,11 +117,13 @@ function uniqueString(value, index, values) {
|
|
|
113
117
|
}
|
|
114
118
|
function listGitChangedDiff(workspaceRoot, baseRef) {
|
|
115
119
|
try {
|
|
116
|
-
return (0,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
return (0, git_1.execGit)(workspaceRoot, [
|
|
121
|
+
"diff",
|
|
122
|
+
"--unified=0",
|
|
123
|
+
"--no-ext-diff",
|
|
124
|
+
baseRef,
|
|
125
|
+
"--",
|
|
126
|
+
]);
|
|
121
127
|
}
|
|
122
128
|
catch (err) {
|
|
123
129
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -486,11 +492,7 @@ function readWorkingTreeFileContent(workspaceRoot, projectPath) {
|
|
|
486
492
|
}
|
|
487
493
|
function readStagedFileContent(workspaceRoot, projectPath) {
|
|
488
494
|
try {
|
|
489
|
-
return (0,
|
|
490
|
-
cwd: workspaceRoot,
|
|
491
|
-
encoding: "utf8",
|
|
492
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
493
|
-
});
|
|
495
|
+
return (0, git_1.execGit)(workspaceRoot, ["show", `:${projectPath}`]);
|
|
494
496
|
}
|
|
495
497
|
catch {
|
|
496
498
|
const absolutePath = path.resolve(workspaceRoot, projectPath);
|
|
@@ -504,11 +506,7 @@ function readStagedFileContent(workspaceRoot, projectPath) {
|
|
|
504
506
|
}
|
|
505
507
|
function readGitRefFileContent(workspaceRoot, ref, projectPath) {
|
|
506
508
|
try {
|
|
507
|
-
return (0,
|
|
508
|
-
cwd: workspaceRoot,
|
|
509
|
-
encoding: "utf8",
|
|
510
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
511
|
-
});
|
|
509
|
+
return (0, git_1.execGit)(workspaceRoot, ["show", `${ref}:${projectPath}`]);
|
|
512
510
|
}
|
|
513
511
|
catch {
|
|
514
512
|
return null;
|
|
@@ -521,20 +519,7 @@ function parseSymbolRanges(engine, workspaceRoot, projectPath, content) {
|
|
|
521
519
|
if (projectPath.toLowerCase().endsWith(".py")) {
|
|
522
520
|
return parsePythonSymbolRanges(engine, workspaceRoot, projectPath, content);
|
|
523
521
|
}
|
|
524
|
-
const
|
|
525
|
-
compilerOptions: {
|
|
526
|
-
allowJs: true,
|
|
527
|
-
jsx: 4,
|
|
528
|
-
allowSyntheticDefaultImports: true,
|
|
529
|
-
esModuleInterop: true,
|
|
530
|
-
moduleResolution: 2,
|
|
531
|
-
target: 99,
|
|
532
|
-
strict: false,
|
|
533
|
-
},
|
|
534
|
-
skipAddingFilesFromTsConfig: true,
|
|
535
|
-
skipFileDependencyResolution: true,
|
|
536
|
-
});
|
|
537
|
-
const sourceFile = project.createSourceFile(projectPath, content, { overwrite: true });
|
|
522
|
+
const sourceFile = ts_morph_1.ts.createSourceFile(projectPath, content, ts_morph_1.ts.ScriptTarget.Latest, true, scriptKindForPath(projectPath));
|
|
538
523
|
const exportedNames = exportedSymbolNames(sourceFile);
|
|
539
524
|
const graphSymbols = graphSymbolsByName(engine, workspaceRoot, projectPath);
|
|
540
525
|
const ranges = [];
|
|
@@ -543,13 +528,13 @@ function parseSymbolRanges(engine, workspaceRoot, projectPath, content) {
|
|
|
543
528
|
if (!name || name.includes("{") || name.includes("[")) {
|
|
544
529
|
return;
|
|
545
530
|
}
|
|
546
|
-
const key = `${name}:${kind}:${node.getStart()}`;
|
|
531
|
+
const key = `${name}:${kind}:${node.getStart(sourceFile)}`;
|
|
547
532
|
if (seen.has(key)) {
|
|
548
533
|
return;
|
|
549
534
|
}
|
|
550
535
|
seen.add(key);
|
|
551
536
|
const graphSymbol = graphSymbols.get(name);
|
|
552
|
-
const nodeRange = lineRangeForNode(node);
|
|
537
|
+
const nodeRange = lineRangeForNode(sourceFile, node);
|
|
553
538
|
ranges.push({
|
|
554
539
|
symbol: `${projectPath}::${name}`,
|
|
555
540
|
file: projectPath,
|
|
@@ -563,27 +548,33 @@ function parseSymbolRanges(engine, workspaceRoot, projectPath, content) {
|
|
|
563
548
|
endLine: nodeRange.end,
|
|
564
549
|
signatureStartLine: nodeRange.signatureStart,
|
|
565
550
|
signatureEndLine: nodeRange.signatureEnd,
|
|
566
|
-
signatureText: signatureTextForNode(node),
|
|
551
|
+
signatureText: signatureTextForNode(sourceFile, node),
|
|
567
552
|
});
|
|
568
553
|
};
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
554
|
+
const visit = (node) => {
|
|
555
|
+
if (ts_morph_1.ts.isFunctionDeclaration(node)) {
|
|
556
|
+
addRange(node.name?.text, "function", node);
|
|
557
|
+
}
|
|
558
|
+
else if (ts_morph_1.ts.isClassDeclaration(node)) {
|
|
559
|
+
addRange(node.name?.text, "class", node);
|
|
560
|
+
node.members.forEach((member) => {
|
|
561
|
+
if (ts_morph_1.ts.isMethodDeclaration(member)) {
|
|
562
|
+
addRange(propertyNameText(member.name, sourceFile), "method", member);
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
else if (ts_morph_1.ts.isVariableDeclaration(node) && isTopLevelVariableDeclaration(node)) {
|
|
568
|
+
const initializer = node.initializer;
|
|
569
|
+
const kind = initializer &&
|
|
570
|
+
(ts_morph_1.ts.isArrowFunction(initializer) || ts_morph_1.ts.isFunctionExpression(initializer))
|
|
571
|
+
? "function"
|
|
572
|
+
: "variable";
|
|
573
|
+
addRange(bindingNameText(node.name, sourceFile), kind, node);
|
|
574
|
+
}
|
|
575
|
+
ts_morph_1.ts.forEachChild(node, visit);
|
|
576
|
+
};
|
|
577
|
+
ts_morph_1.ts.forEachChild(sourceFile, visit);
|
|
587
578
|
return ranges;
|
|
588
579
|
}
|
|
589
580
|
function parsePythonSymbolRanges(engine, workspaceRoot, projectPath, content) {
|
|
@@ -654,16 +645,86 @@ function symbolsByName(symbols) {
|
|
|
654
645
|
});
|
|
655
646
|
return result;
|
|
656
647
|
}
|
|
648
|
+
function scriptKindForPath(projectPath) {
|
|
649
|
+
const ext = path.extname(projectPath).toLowerCase();
|
|
650
|
+
if (ext === ".tsx") {
|
|
651
|
+
return ts_morph_1.ts.ScriptKind.TSX;
|
|
652
|
+
}
|
|
653
|
+
if (ext === ".jsx") {
|
|
654
|
+
return ts_morph_1.ts.ScriptKind.JSX;
|
|
655
|
+
}
|
|
656
|
+
if (ext === ".js") {
|
|
657
|
+
return ts_morph_1.ts.ScriptKind.JS;
|
|
658
|
+
}
|
|
659
|
+
if (ext === ".json") {
|
|
660
|
+
return ts_morph_1.ts.ScriptKind.JSON;
|
|
661
|
+
}
|
|
662
|
+
return ts_morph_1.ts.ScriptKind.TS;
|
|
663
|
+
}
|
|
657
664
|
function exportedSymbolNames(sourceFile) {
|
|
658
665
|
const exported = new Set();
|
|
659
|
-
sourceFile.
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
666
|
+
sourceFile.statements.forEach((statement) => {
|
|
667
|
+
if (ts_morph_1.ts.isFunctionDeclaration(statement)) {
|
|
668
|
+
addExportedName(exported, statement.name?.text, statement);
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
if (ts_morph_1.ts.isClassDeclaration(statement)) {
|
|
672
|
+
addExportedName(exported, statement.name?.text, statement);
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
if (!ts_morph_1.ts.isVariableStatement(statement)) {
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
if (!isExportedNode(statement)) {
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
statement.declarationList.declarations.forEach((declaration) => {
|
|
682
|
+
const name = bindingNameText(declaration.name, sourceFile);
|
|
683
|
+
if (name) {
|
|
684
|
+
exported.add(name);
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
});
|
|
688
|
+
sourceFile.statements.forEach((statement) => {
|
|
689
|
+
if (!ts_morph_1.ts.isExportDeclaration(statement)) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
const exportClause = statement.exportClause;
|
|
693
|
+
if (!exportClause || !ts_morph_1.ts.isNamedExports(exportClause)) {
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
exportClause.elements.forEach((namedExport) => {
|
|
697
|
+
exported.add(namedExport.propertyName?.text ?? namedExport.name.text);
|
|
663
698
|
});
|
|
664
699
|
});
|
|
665
700
|
return exported;
|
|
666
701
|
}
|
|
702
|
+
function addExportedName(exported, name, node) {
|
|
703
|
+
if (name && isExportedNode(node)) {
|
|
704
|
+
exported.add(name);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
function isExportedNode(node) {
|
|
708
|
+
return ts_morph_1.ts.canHaveModifiers(node) &&
|
|
709
|
+
(ts_morph_1.ts.getModifiers(node) ?? []).some((modifier) => modifier.kind === ts_morph_1.ts.SyntaxKind.ExportKeyword);
|
|
710
|
+
}
|
|
711
|
+
function bindingNameText(name, sourceFile) {
|
|
712
|
+
if (ts_morph_1.ts.isIdentifier(name)) {
|
|
713
|
+
return name.text;
|
|
714
|
+
}
|
|
715
|
+
return name.getText(sourceFile);
|
|
716
|
+
}
|
|
717
|
+
function propertyNameText(name, sourceFile) {
|
|
718
|
+
if (ts_morph_1.ts.isIdentifier(name) || ts_morph_1.ts.isStringLiteral(name) || ts_morph_1.ts.isNumericLiteral(name)) {
|
|
719
|
+
return name.text;
|
|
720
|
+
}
|
|
721
|
+
return name.getText(sourceFile);
|
|
722
|
+
}
|
|
723
|
+
function isTopLevelVariableDeclaration(node) {
|
|
724
|
+
const declarationList = node.parent;
|
|
725
|
+
const statement = declarationList.parent;
|
|
726
|
+
return ts_morph_1.ts.isVariableStatement(statement) && ts_morph_1.ts.isSourceFile(statement.parent);
|
|
727
|
+
}
|
|
667
728
|
function graphSymbolsByName(engine, workspaceRoot, projectPath) {
|
|
668
729
|
const symbols = new Map();
|
|
669
730
|
engine.graph.symbols.forEach((symbol) => {
|
|
@@ -673,13 +734,12 @@ function graphSymbolsByName(engine, workspaceRoot, projectPath) {
|
|
|
673
734
|
});
|
|
674
735
|
return symbols;
|
|
675
736
|
}
|
|
676
|
-
function lineRangeForNode(node) {
|
|
677
|
-
const
|
|
678
|
-
const
|
|
679
|
-
const end = sourceFile.getLineAndColumnAtPos(node.getEnd()).line;
|
|
737
|
+
function lineRangeForNode(sourceFile, node) {
|
|
738
|
+
const start = lineForPosition(sourceFile, node.getStart(sourceFile));
|
|
739
|
+
const end = lineForPosition(sourceFile, node.getEnd());
|
|
680
740
|
const body = bodyNodeFor(node);
|
|
681
741
|
const bodyStart = body
|
|
682
|
-
? sourceFile
|
|
742
|
+
? lineForPosition(sourceFile, body.getStart(sourceFile))
|
|
683
743
|
: start;
|
|
684
744
|
return {
|
|
685
745
|
start,
|
|
@@ -688,38 +748,40 @@ function lineRangeForNode(node) {
|
|
|
688
748
|
signatureEnd: Math.max(start, Math.min(bodyStart, end)),
|
|
689
749
|
};
|
|
690
750
|
}
|
|
751
|
+
function lineForPosition(sourceFile, position) {
|
|
752
|
+
return sourceFile.getLineAndCharacterOfPosition(position).line + 1;
|
|
753
|
+
}
|
|
691
754
|
function bodyNodeFor(node) {
|
|
692
|
-
if (ts_morph_1.
|
|
693
|
-
ts_morph_1.
|
|
694
|
-
ts_morph_1.
|
|
695
|
-
ts_morph_1.
|
|
696
|
-
return node.
|
|
755
|
+
if (ts_morph_1.ts.isFunctionDeclaration(node) ||
|
|
756
|
+
ts_morph_1.ts.isMethodDeclaration(node) ||
|
|
757
|
+
ts_morph_1.ts.isFunctionExpression(node) ||
|
|
758
|
+
ts_morph_1.ts.isArrowFunction(node)) {
|
|
759
|
+
return node.body;
|
|
697
760
|
}
|
|
698
|
-
if (ts_morph_1.
|
|
761
|
+
if (ts_morph_1.ts.isClassDeclaration(node)) {
|
|
699
762
|
return node;
|
|
700
763
|
}
|
|
701
|
-
if (ts_morph_1.
|
|
702
|
-
const initializer = node.
|
|
764
|
+
if (ts_morph_1.ts.isVariableDeclaration(node)) {
|
|
765
|
+
const initializer = node.initializer;
|
|
703
766
|
if (initializer &&
|
|
704
|
-
(ts_morph_1.
|
|
705
|
-
return initializer.
|
|
767
|
+
(ts_morph_1.ts.isArrowFunction(initializer) || ts_morph_1.ts.isFunctionExpression(initializer))) {
|
|
768
|
+
return initializer.body;
|
|
706
769
|
}
|
|
707
770
|
}
|
|
708
771
|
return undefined;
|
|
709
772
|
}
|
|
710
|
-
function signatureTextForNode(node) {
|
|
711
|
-
const
|
|
712
|
-
const fullText = sourceFile.getFullText();
|
|
773
|
+
function signatureTextForNode(sourceFile, node) {
|
|
774
|
+
const fullText = sourceFile.text;
|
|
713
775
|
const body = bodyNodeFor(node);
|
|
714
|
-
if (body && !ts_morph_1.
|
|
715
|
-
const start = node.getStart();
|
|
716
|
-
const bodyStart = body.getStart();
|
|
776
|
+
if (body && !ts_morph_1.ts.isClassDeclaration(node)) {
|
|
777
|
+
const start = node.getStart(sourceFile);
|
|
778
|
+
const bodyStart = body.getStart(sourceFile);
|
|
717
779
|
if (bodyStart > start) {
|
|
718
780
|
return normalizeSignatureText(fullText.slice(start, bodyStart));
|
|
719
781
|
}
|
|
720
782
|
}
|
|
721
|
-
const text = node.getText();
|
|
722
|
-
if (ts_morph_1.
|
|
783
|
+
const text = node.getText(sourceFile);
|
|
784
|
+
if (ts_morph_1.ts.isClassDeclaration(node)) {
|
|
723
785
|
const braceIndex = text.indexOf("{");
|
|
724
786
|
if (braceIndex >= 0) {
|
|
725
787
|
return normalizeSignatureText(text.slice(0, braceIndex));
|