@grafema/util 0.3.0-beta
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/LICENSE +190 -0
- package/dist/api/GraphAPI.d.ts +87 -0
- package/dist/api/GraphAPI.d.ts.map +1 -0
- package/dist/api/GraphAPI.js +212 -0
- package/dist/api/GraphAPI.js.map +1 -0
- package/dist/api/GuaranteeAPI.d.ts +147 -0
- package/dist/api/GuaranteeAPI.d.ts.map +1 -0
- package/dist/api/GuaranteeAPI.js +290 -0
- package/dist/api/GuaranteeAPI.js.map +1 -0
- package/dist/config/ConfigLoader.d.ts +214 -0
- package/dist/config/ConfigLoader.d.ts.map +1 -0
- package/dist/config/ConfigLoader.js +441 -0
- package/dist/config/ConfigLoader.js.map +1 -0
- package/dist/config/index.d.ts +6 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +5 -0
- package/dist/config/index.js.map +1 -0
- package/dist/core/CoverageAnalyzer.d.ts +65 -0
- package/dist/core/CoverageAnalyzer.d.ts.map +1 -0
- package/dist/core/CoverageAnalyzer.js +199 -0
- package/dist/core/CoverageAnalyzer.js.map +1 -0
- package/dist/core/FileExplainer.d.ts +101 -0
- package/dist/core/FileExplainer.d.ts.map +1 -0
- package/dist/core/FileExplainer.js +140 -0
- package/dist/core/FileExplainer.js.map +1 -0
- package/dist/core/FileOverview.d.ts +124 -0
- package/dist/core/FileOverview.d.ts.map +1 -0
- package/dist/core/FileOverview.js +279 -0
- package/dist/core/FileOverview.js.map +1 -0
- package/dist/core/GrafemaUri.d.ts +66 -0
- package/dist/core/GrafemaUri.d.ts.map +1 -0
- package/dist/core/GrafemaUri.js +191 -0
- package/dist/core/GrafemaUri.js.map +1 -0
- package/dist/core/GraphBackend.d.ts +158 -0
- package/dist/core/GraphBackend.d.ts.map +1 -0
- package/dist/core/GraphBackend.js +85 -0
- package/dist/core/GraphBackend.js.map +1 -0
- package/dist/core/GraphFreshnessChecker.d.ts +33 -0
- package/dist/core/GraphFreshnessChecker.d.ts.map +1 -0
- package/dist/core/GraphFreshnessChecker.js +104 -0
- package/dist/core/GraphFreshnessChecker.js.map +1 -0
- package/dist/core/GuaranteeManager.d.ts +254 -0
- package/dist/core/GuaranteeManager.d.ts.map +1 -0
- package/dist/core/GuaranteeManager.js +447 -0
- package/dist/core/GuaranteeManager.js.map +1 -0
- package/dist/core/HashUtils.d.ts +24 -0
- package/dist/core/HashUtils.d.ts.map +1 -0
- package/dist/core/HashUtils.js +46 -0
- package/dist/core/HashUtils.js.map +1 -0
- package/dist/core/IncrementalReanalyzer.d.ts +33 -0
- package/dist/core/IncrementalReanalyzer.d.ts.map +1 -0
- package/dist/core/IncrementalReanalyzer.js +67 -0
- package/dist/core/IncrementalReanalyzer.js.map +1 -0
- package/dist/core/ResourceRegistry.d.ts +17 -0
- package/dist/core/ResourceRegistry.d.ts.map +1 -0
- package/dist/core/ResourceRegistry.js +32 -0
- package/dist/core/ResourceRegistry.js.map +1 -0
- package/dist/core/SemanticId.d.ts +159 -0
- package/dist/core/SemanticId.d.ts.map +1 -0
- package/dist/core/SemanticId.js +291 -0
- package/dist/core/SemanticId.js.map +1 -0
- package/dist/core/VersionManager.d.ts +166 -0
- package/dist/core/VersionManager.d.ts.map +1 -0
- package/dist/core/VersionManager.js +239 -0
- package/dist/core/VersionManager.js.map +1 -0
- package/dist/core/brandNodeInternal.d.ts +14 -0
- package/dist/core/brandNodeInternal.d.ts.map +1 -0
- package/dist/core/brandNodeInternal.js +4 -0
- package/dist/core/brandNodeInternal.js.map +1 -0
- package/dist/core/nodes/GuaranteeNode.d.ts +76 -0
- package/dist/core/nodes/GuaranteeNode.d.ts.map +1 -0
- package/dist/core/nodes/GuaranteeNode.js +118 -0
- package/dist/core/nodes/GuaranteeNode.js.map +1 -0
- package/dist/core/nodes/IssueNode.d.ts +73 -0
- package/dist/core/nodes/IssueNode.d.ts.map +1 -0
- package/dist/core/nodes/IssueNode.js +130 -0
- package/dist/core/nodes/IssueNode.js.map +1 -0
- package/dist/core/nodes/NodeKind.d.ts +104 -0
- package/dist/core/nodes/NodeKind.d.ts.map +1 -0
- package/dist/core/nodes/NodeKind.js +166 -0
- package/dist/core/nodes/NodeKind.js.map +1 -0
- package/dist/diagnostics/DiagnosticCollector.d.ts +103 -0
- package/dist/diagnostics/DiagnosticCollector.d.ts.map +1 -0
- package/dist/diagnostics/DiagnosticCollector.js +133 -0
- package/dist/diagnostics/DiagnosticCollector.js.map +1 -0
- package/dist/diagnostics/DiagnosticReporter.d.ts +122 -0
- package/dist/diagnostics/DiagnosticReporter.d.ts.map +1 -0
- package/dist/diagnostics/DiagnosticReporter.js +300 -0
- package/dist/diagnostics/DiagnosticReporter.js.map +1 -0
- package/dist/diagnostics/DiagnosticWriter.d.ts +31 -0
- package/dist/diagnostics/DiagnosticWriter.d.ts.map +1 -0
- package/dist/diagnostics/DiagnosticWriter.js +44 -0
- package/dist/diagnostics/DiagnosticWriter.js.map +1 -0
- package/dist/diagnostics/categories.d.ts +57 -0
- package/dist/diagnostics/categories.d.ts.map +1 -0
- package/dist/diagnostics/categories.js +71 -0
- package/dist/diagnostics/categories.js.map +1 -0
- package/dist/diagnostics/index.d.ts +17 -0
- package/dist/diagnostics/index.d.ts.map +1 -0
- package/dist/diagnostics/index.js +15 -0
- package/dist/diagnostics/index.js.map +1 -0
- package/dist/errors/GrafemaError.d.ts +200 -0
- package/dist/errors/GrafemaError.d.ts.map +1 -0
- package/dist/errors/GrafemaError.js +209 -0
- package/dist/errors/GrafemaError.js.map +1 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -0
- package/dist/instructions/index.d.ts +8 -0
- package/dist/instructions/index.d.ts.map +1 -0
- package/dist/instructions/index.js +20 -0
- package/dist/instructions/index.js.map +1 -0
- package/dist/instructions/onboarding.md +133 -0
- package/dist/knowledge/KnowledgeBase.d.ts +113 -0
- package/dist/knowledge/KnowledgeBase.d.ts.map +1 -0
- package/dist/knowledge/KnowledgeBase.js +420 -0
- package/dist/knowledge/KnowledgeBase.js.map +1 -0
- package/dist/knowledge/SemanticAddressResolver.d.ts +59 -0
- package/dist/knowledge/SemanticAddressResolver.d.ts.map +1 -0
- package/dist/knowledge/SemanticAddressResolver.js +160 -0
- package/dist/knowledge/SemanticAddressResolver.js.map +1 -0
- package/dist/knowledge/git-ingest.d.ts +58 -0
- package/dist/knowledge/git-ingest.d.ts.map +1 -0
- package/dist/knowledge/git-ingest.js +301 -0
- package/dist/knowledge/git-ingest.js.map +1 -0
- package/dist/knowledge/git-queries.d.ts +86 -0
- package/dist/knowledge/git-queries.d.ts.map +1 -0
- package/dist/knowledge/git-queries.js +177 -0
- package/dist/knowledge/git-queries.js.map +1 -0
- package/dist/knowledge/index.d.ts +14 -0
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +10 -0
- package/dist/knowledge/index.js.map +1 -0
- package/dist/knowledge/parser.d.ts +39 -0
- package/dist/knowledge/parser.d.ts.map +1 -0
- package/dist/knowledge/parser.js +292 -0
- package/dist/knowledge/parser.js.map +1 -0
- package/dist/knowledge/types.d.ts +133 -0
- package/dist/knowledge/types.d.ts.map +1 -0
- package/dist/knowledge/types.js +8 -0
- package/dist/knowledge/types.js.map +1 -0
- package/dist/logging/Logger.d.ts +98 -0
- package/dist/logging/Logger.d.ts.map +1 -0
- package/dist/logging/Logger.js +274 -0
- package/dist/logging/Logger.js.map +1 -0
- package/dist/notation/archetypes.d.ts +36 -0
- package/dist/notation/archetypes.d.ts.map +1 -0
- package/dist/notation/archetypes.js +173 -0
- package/dist/notation/archetypes.js.map +1 -0
- package/dist/notation/fold.d.ts +25 -0
- package/dist/notation/fold.d.ts.map +1 -0
- package/dist/notation/fold.js +598 -0
- package/dist/notation/fold.js.map +1 -0
- package/dist/notation/index.d.ts +18 -0
- package/dist/notation/index.d.ts.map +1 -0
- package/dist/notation/index.js +16 -0
- package/dist/notation/index.js.map +1 -0
- package/dist/notation/lodExtractor.d.ts +32 -0
- package/dist/notation/lodExtractor.d.ts.map +1 -0
- package/dist/notation/lodExtractor.js +149 -0
- package/dist/notation/lodExtractor.js.map +1 -0
- package/dist/notation/nameShortener.d.ts +22 -0
- package/dist/notation/nameShortener.d.ts.map +1 -0
- package/dist/notation/nameShortener.js +24 -0
- package/dist/notation/nameShortener.js.map +1 -0
- package/dist/notation/perspectives.d.ts +11 -0
- package/dist/notation/perspectives.d.ts.map +1 -0
- package/dist/notation/perspectives.js +16 -0
- package/dist/notation/perspectives.js.map +1 -0
- package/dist/notation/renderer.d.ts +31 -0
- package/dist/notation/renderer.d.ts.map +1 -0
- package/dist/notation/renderer.js +315 -0
- package/dist/notation/renderer.js.map +1 -0
- package/dist/notation/traceRenderer.d.ts +39 -0
- package/dist/notation/traceRenderer.d.ts.map +1 -0
- package/dist/notation/traceRenderer.js +358 -0
- package/dist/notation/traceRenderer.js.map +1 -0
- package/dist/notation/types.d.ts +66 -0
- package/dist/notation/types.d.ts.map +1 -0
- package/dist/notation/types.js +10 -0
- package/dist/notation/types.js.map +1 -0
- package/dist/queries/NodeContext.d.ts +81 -0
- package/dist/queries/NodeContext.d.ts.map +1 -0
- package/dist/queries/NodeContext.js +196 -0
- package/dist/queries/NodeContext.js.map +1 -0
- package/dist/queries/findCallsInFunction.d.ts +62 -0
- package/dist/queries/findCallsInFunction.d.ts.map +1 -0
- package/dist/queries/findCallsInFunction.js +169 -0
- package/dist/queries/findCallsInFunction.js.map +1 -0
- package/dist/queries/findContainingFunction.d.ts +57 -0
- package/dist/queries/findContainingFunction.d.ts.map +1 -0
- package/dist/queries/findContainingFunction.js +91 -0
- package/dist/queries/findContainingFunction.js.map +1 -0
- package/dist/queries/index.d.ts +18 -0
- package/dist/queries/index.d.ts.map +1 -0
- package/dist/queries/index.js +14 -0
- package/dist/queries/index.js.map +1 -0
- package/dist/queries/traceDataflow.d.ts +65 -0
- package/dist/queries/traceDataflow.d.ts.map +1 -0
- package/dist/queries/traceDataflow.js +754 -0
- package/dist/queries/traceDataflow.js.map +1 -0
- package/dist/queries/traceValues.d.ts +70 -0
- package/dist/queries/traceValues.d.ts.map +1 -0
- package/dist/queries/traceValues.js +373 -0
- package/dist/queries/traceValues.js.map +1 -0
- package/dist/queries/types.d.ts +166 -0
- package/dist/queries/types.d.ts.map +1 -0
- package/dist/queries/types.js +10 -0
- package/dist/queries/types.js.map +1 -0
- package/dist/schema/GraphSchemaExtractor.d.ts +53 -0
- package/dist/schema/GraphSchemaExtractor.d.ts.map +1 -0
- package/dist/schema/GraphSchemaExtractor.js +125 -0
- package/dist/schema/GraphSchemaExtractor.js.map +1 -0
- package/dist/schema/InterfaceSchemaExtractor.d.ts +73 -0
- package/dist/schema/InterfaceSchemaExtractor.d.ts.map +1 -0
- package/dist/schema/InterfaceSchemaExtractor.js +113 -0
- package/dist/schema/InterfaceSchemaExtractor.js.map +1 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +3 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/storage/backends/RFDBServerBackend.d.ts +356 -0
- package/dist/storage/backends/RFDBServerBackend.d.ts.map +1 -0
- package/dist/storage/backends/RFDBServerBackend.js +748 -0
- package/dist/storage/backends/RFDBServerBackend.js.map +1 -0
- package/dist/storage/backends/typeValidation.d.ts +47 -0
- package/dist/storage/backends/typeValidation.d.ts.map +1 -0
- package/dist/storage/backends/typeValidation.js +141 -0
- package/dist/storage/backends/typeValidation.js.map +1 -0
- package/dist/utils/findRfdbBinary.d.ts +67 -0
- package/dist/utils/findRfdbBinary.d.ts.map +1 -0
- package/dist/utils/findRfdbBinary.js +261 -0
- package/dist/utils/findRfdbBinary.js.map +1 -0
- package/dist/utils/lazyDownload.d.ts +43 -0
- package/dist/utils/lazyDownload.d.ts.map +1 -0
- package/dist/utils/lazyDownload.js +175 -0
- package/dist/utils/lazyDownload.js.map +1 -0
- package/dist/utils/moduleResolution.d.ts +134 -0
- package/dist/utils/moduleResolution.d.ts.map +1 -0
- package/dist/utils/moduleResolution.js +189 -0
- package/dist/utils/moduleResolution.js.map +1 -0
- package/dist/utils/resolveNodeFile.d.ts +13 -0
- package/dist/utils/resolveNodeFile.d.ts.map +1 -0
- package/dist/utils/resolveNodeFile.js +18 -0
- package/dist/utils/resolveNodeFile.js.map +1 -0
- package/dist/utils/startRfdbServer.d.ts +63 -0
- package/dist/utils/startRfdbServer.d.ts.map +1 -0
- package/dist/utils/startRfdbServer.js +142 -0
- package/dist/utils/startRfdbServer.js.map +1 -0
- package/dist/validation/PathValidator.d.ts +80 -0
- package/dist/validation/PathValidator.d.ts.map +1 -0
- package/dist/validation/PathValidator.js +252 -0
- package/dist/validation/PathValidator.js.map +1 -0
- package/dist/version.d.ts +11 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +26 -0
- package/dist/version.js.map +1 -0
- package/package.json +50 -0
- package/src/api/GraphAPI.ts +307 -0
- package/src/api/GuaranteeAPI.ts +402 -0
- package/src/config/ConfigLoader.ts +653 -0
- package/src/config/index.ts +13 -0
- package/src/core/CoverageAnalyzer.ts +243 -0
- package/src/core/FileExplainer.ts +179 -0
- package/src/core/FileOverview.ts +397 -0
- package/src/core/GrafemaUri.ts +216 -0
- package/src/core/GraphBackend.ts +266 -0
- package/src/core/GraphFreshnessChecker.ts +145 -0
- package/src/core/GuaranteeManager.ts +684 -0
- package/src/core/HashUtils.ts +48 -0
- package/src/core/IncrementalReanalyzer.ts +106 -0
- package/src/core/ResourceRegistry.ts +39 -0
- package/src/core/SemanticId.ts +423 -0
- package/src/core/VersionManager.ts +405 -0
- package/src/core/brandNodeInternal.ts +16 -0
- package/src/core/nodes/GuaranteeNode.ts +162 -0
- package/src/core/nodes/IssueNode.ts +177 -0
- package/src/core/nodes/NodeKind.ts +192 -0
- package/src/diagnostics/DiagnosticCollector.ts +170 -0
- package/src/diagnostics/DiagnosticReporter.ts +395 -0
- package/src/diagnostics/DiagnosticWriter.ts +50 -0
- package/src/diagnostics/categories.ts +104 -0
- package/src/diagnostics/index.ts +30 -0
- package/src/errors/GrafemaError.ts +297 -0
- package/src/index.ts +261 -0
- package/src/instructions/index.ts +21 -0
- package/src/instructions/onboarding.md +133 -0
- package/src/knowledge/KnowledgeBase.ts +486 -0
- package/src/knowledge/SemanticAddressResolver.ts +191 -0
- package/src/knowledge/git-ingest.ts +402 -0
- package/src/knowledge/git-queries.ts +269 -0
- package/src/knowledge/index.ts +29 -0
- package/src/knowledge/parser.ts +294 -0
- package/src/knowledge/types.ts +146 -0
- package/src/logging/Logger.ts +303 -0
- package/src/notation/archetypes.ts +189 -0
- package/src/notation/fold.ts +696 -0
- package/src/notation/index.ts +27 -0
- package/src/notation/lodExtractor.ts +177 -0
- package/src/notation/nameShortener.ts +24 -0
- package/src/notation/perspectives.ts +18 -0
- package/src/notation/renderer.ts +394 -0
- package/src/notation/traceRenderer.ts +458 -0
- package/src/notation/types.ts +79 -0
- package/src/queries/NodeContext.ts +280 -0
- package/src/queries/findCallsInFunction.ts +249 -0
- package/src/queries/findContainingFunction.ts +124 -0
- package/src/queries/index.ts +44 -0
- package/src/queries/traceDataflow.ts +838 -0
- package/src/queries/traceValues.ts +531 -0
- package/src/queries/types.ts +191 -0
- package/src/schema/GraphSchemaExtractor.ts +177 -0
- package/src/schema/InterfaceSchemaExtractor.ts +173 -0
- package/src/schema/index.ts +5 -0
- package/src/storage/backends/RFDBServerBackend.ts +895 -0
- package/src/storage/backends/typeValidation.ts +154 -0
- package/src/utils/findRfdbBinary.ts +288 -0
- package/src/utils/lazyDownload.ts +206 -0
- package/src/utils/moduleResolution.ts +271 -0
- package/src/utils/resolveNodeFile.ts +18 -0
- package/src/utils/startRfdbServer.ts +197 -0
- package/src/validation/PathValidator.ts +334 -0
- package/src/version.ts +28 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy binary downloader for Grafema.
|
|
3
|
+
*
|
|
4
|
+
* Downloads Haskell analyzer binaries from GitHub Releases on first use.
|
|
5
|
+
* Binaries are cached in ~/.grafema/bin/ and reused across projects.
|
|
6
|
+
*
|
|
7
|
+
* Asset naming convention: {binary-name}-{platform}
|
|
8
|
+
* Example: grafema-analyzer-darwin-arm64
|
|
9
|
+
*/
|
|
10
|
+
import { existsSync, mkdirSync, chmodSync, renameSync, unlinkSync, createWriteStream } from 'fs';
|
|
11
|
+
import { join } from 'path';
|
|
12
|
+
import { get as httpsGet } from 'https';
|
|
13
|
+
import { getPlatformDir } from './findRfdbBinary.js';
|
|
14
|
+
const GITHUB_REPO = 'Disentinel/grafema';
|
|
15
|
+
/** All analyzer binaries that can be lazy-downloaded. */
|
|
16
|
+
const DOWNLOADABLE_BINARIES = [
|
|
17
|
+
'grafema-analyzer',
|
|
18
|
+
'grafema-resolve',
|
|
19
|
+
'haskell-analyzer',
|
|
20
|
+
'haskell-resolve',
|
|
21
|
+
'grafema-rust-analyzer',
|
|
22
|
+
'grafema-rust-resolve',
|
|
23
|
+
'grafema-java-analyzer',
|
|
24
|
+
'java-resolve',
|
|
25
|
+
'java-parser',
|
|
26
|
+
'grafema-kotlin-analyzer',
|
|
27
|
+
'kotlin-resolve',
|
|
28
|
+
'kotlin-parser',
|
|
29
|
+
'jvm-cross-resolve',
|
|
30
|
+
'grafema-python-analyzer',
|
|
31
|
+
'python-resolve',
|
|
32
|
+
'grafema-go-analyzer',
|
|
33
|
+
'go-resolve',
|
|
34
|
+
'go-parser',
|
|
35
|
+
'grafema-cpp-analyzer',
|
|
36
|
+
'cpp-resolve',
|
|
37
|
+
];
|
|
38
|
+
/**
|
|
39
|
+
* Get the directory where lazy-downloaded binaries are stored.
|
|
40
|
+
*/
|
|
41
|
+
export function getGrafemaBinDir() {
|
|
42
|
+
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
43
|
+
return join(home, '.grafema', 'bin');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a binary name is eligible for lazy download.
|
|
47
|
+
*/
|
|
48
|
+
export function isDownloadable(binaryName) {
|
|
49
|
+
return DOWNLOADABLE_BINARIES.includes(binaryName);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Find a binary in ~/.grafema/bin/.
|
|
53
|
+
*/
|
|
54
|
+
export function findInGrafemaBin(binaryName) {
|
|
55
|
+
const binDir = getGrafemaBinDir();
|
|
56
|
+
const p = join(binDir, binaryName);
|
|
57
|
+
return existsSync(p) ? p : null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Simple HTTPS GET that follows redirects (GitHub uses 302 → S3).
|
|
61
|
+
*/
|
|
62
|
+
function httpsGetFollowRedirects(url) {
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
const req = httpsGet(url, { headers: { 'User-Agent': 'grafema-cli' } }, (res) => {
|
|
65
|
+
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
66
|
+
const location = res.headers.location;
|
|
67
|
+
if (!location)
|
|
68
|
+
return reject(new Error('Redirect without location'));
|
|
69
|
+
httpsGetFollowRedirects(location).then(resolve, reject);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
resolve(res);
|
|
73
|
+
});
|
|
74
|
+
req.on('error', reject);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Find the latest binaries-v* release tag from GitHub API.
|
|
79
|
+
*/
|
|
80
|
+
async function findLatestReleaseTag() {
|
|
81
|
+
const url = `https://api.github.com/repos/${GITHUB_REPO}/releases?per_page=30`;
|
|
82
|
+
const res = await httpsGetFollowRedirects(url);
|
|
83
|
+
const chunks = [];
|
|
84
|
+
for await (const chunk of res) {
|
|
85
|
+
chunks.push(chunk);
|
|
86
|
+
}
|
|
87
|
+
const body = Buffer.concat(chunks).toString('utf-8');
|
|
88
|
+
if (res.statusCode !== 200) {
|
|
89
|
+
throw new Error(`GitHub API returned ${res.statusCode}: ${body.slice(0, 200)}`);
|
|
90
|
+
}
|
|
91
|
+
const releases = JSON.parse(body);
|
|
92
|
+
const binRelease = releases.find(r => r.tag_name.startsWith('binaries-v'));
|
|
93
|
+
if (!binRelease) {
|
|
94
|
+
throw new Error('No binaries-v* release found on GitHub');
|
|
95
|
+
}
|
|
96
|
+
return binRelease.tag_name;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Download a single binary from a GitHub Release.
|
|
100
|
+
*
|
|
101
|
+
* @param binaryName - e.g. "grafema-analyzer"
|
|
102
|
+
* @param tag - e.g. "binaries-v0.3.0-beta"
|
|
103
|
+
* @param onProgress - optional callback for download progress
|
|
104
|
+
* @returns Path to the downloaded binary
|
|
105
|
+
*/
|
|
106
|
+
export async function downloadBinary(binaryName, tag, onProgress) {
|
|
107
|
+
const platform = getPlatformDir();
|
|
108
|
+
const assetName = `${binaryName}-${platform}`;
|
|
109
|
+
const binDir = getGrafemaBinDir();
|
|
110
|
+
// Ensure ~/.grafema/bin/ exists
|
|
111
|
+
if (!existsSync(binDir)) {
|
|
112
|
+
mkdirSync(binDir, { recursive: true });
|
|
113
|
+
}
|
|
114
|
+
const targetPath = join(binDir, binaryName);
|
|
115
|
+
const tmpPath = `${targetPath}.downloading`;
|
|
116
|
+
// Resolve tag
|
|
117
|
+
const releaseTag = tag || await findLatestReleaseTag();
|
|
118
|
+
const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/${releaseTag}/${assetName}`;
|
|
119
|
+
const log = onProgress || (() => { });
|
|
120
|
+
log(`Downloading ${binaryName} for ${platform}...`);
|
|
121
|
+
// Download to temp file
|
|
122
|
+
const res = await httpsGetFollowRedirects(downloadUrl);
|
|
123
|
+
if (res.statusCode !== 200) {
|
|
124
|
+
throw new Error(`Failed to download ${assetName}: HTTP ${res.statusCode}. ` +
|
|
125
|
+
`Check that release ${releaseTag} has asset ${assetName}.`);
|
|
126
|
+
}
|
|
127
|
+
const contentLength = parseInt(res.headers['content-length'] || '0', 10);
|
|
128
|
+
const sizeMB = contentLength > 0 ? `${(contentLength / 1024 / 1024).toFixed(1)}MB` : 'unknown size';
|
|
129
|
+
log(` ${assetName} (${sizeMB})`);
|
|
130
|
+
await new Promise((resolve, reject) => {
|
|
131
|
+
const file = createWriteStream(tmpPath);
|
|
132
|
+
res.pipe(file);
|
|
133
|
+
file.on('finish', () => { file.close(); resolve(); });
|
|
134
|
+
file.on('error', (err) => { unlinkSync(tmpPath); reject(err); });
|
|
135
|
+
res.on('error', (err) => { unlinkSync(tmpPath); reject(err); });
|
|
136
|
+
});
|
|
137
|
+
// Atomic rename + make executable
|
|
138
|
+
renameSync(tmpPath, targetPath);
|
|
139
|
+
chmodSync(targetPath, 0o755);
|
|
140
|
+
log(` Installed to ${targetPath}`);
|
|
141
|
+
return targetPath;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Ensure a binary exists, downloading it if missing and eligible.
|
|
145
|
+
*
|
|
146
|
+
* This is the main entry point for lazy downloading. Call it before
|
|
147
|
+
* spawning an analyzer binary. Returns the path if found or downloaded,
|
|
148
|
+
* null if the binary can't be obtained.
|
|
149
|
+
*
|
|
150
|
+
* @param binaryName - e.g. "grafema-analyzer"
|
|
151
|
+
* @param existingPath - path from findBinary() (null = not found locally)
|
|
152
|
+
* @param onProgress - optional callback for download progress
|
|
153
|
+
*/
|
|
154
|
+
export async function ensureBinary(binaryName, existingPath, onProgress) {
|
|
155
|
+
// Already found locally
|
|
156
|
+
if (existingPath)
|
|
157
|
+
return existingPath;
|
|
158
|
+
// Check ~/.grafema/bin/ first (may have been downloaded previously)
|
|
159
|
+
const cached = findInGrafemaBin(binaryName);
|
|
160
|
+
if (cached)
|
|
161
|
+
return cached;
|
|
162
|
+
// Not downloadable (e.g. rfdb-server, grafema-orchestrator — these must be in npm package)
|
|
163
|
+
if (!isDownloadable(binaryName))
|
|
164
|
+
return null;
|
|
165
|
+
// Download
|
|
166
|
+
try {
|
|
167
|
+
return await downloadBinary(binaryName, undefined, onProgress);
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
171
|
+
(onProgress || console.error)(`Failed to download ${binaryName}: ${msg}`);
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=lazyDownload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazyDownload.js","sourceRoot":"","sources":["../../src/utils/lazyDownload.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AACjG,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,WAAW,GAAG,oBAAoB,CAAC;AAEzC,yDAAyD;AACzD,MAAM,qBAAqB,GAAG;IAC5B,kBAAkB;IAClB,iBAAiB;IACjB,kBAAkB;IAClB,iBAAiB;IACjB,uBAAuB;IACvB,sBAAsB;IACtB,uBAAuB;IACvB,cAAc;IACd,aAAa;IACb,yBAAyB;IACzB,gBAAgB;IAChB,eAAe;IACf,mBAAmB;IACnB,yBAAyB;IACzB,gBAAgB;IAChB,qBAAqB;IACrB,YAAY;IACZ,WAAW;IACX,sBAAsB;IACtB,aAAa;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;IAC/D,OAAO,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,UAAkB;IAC/C,OAAO,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,CAAC;QAC7D,CAAC,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,sBAAsB,UAAU,KAAK,GAAG,EAAE,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module Resolution Utilities (REG-320)
|
|
3
|
+
*
|
|
4
|
+
* Unified module path resolution logic extracted from:
|
|
5
|
+
* - MountPointResolver.resolveImportSource()
|
|
6
|
+
* - JSModuleIndexer.resolveModulePath()
|
|
7
|
+
* - FunctionCallResolver._resolveImportPath()
|
|
8
|
+
* - IncrementalModuleIndexer.tryResolve()
|
|
9
|
+
*
|
|
10
|
+
* Provides consistent module resolution across all plugins.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Default file extensions to try when resolving modules.
|
|
14
|
+
* Order: exact match first, then JS variants, then TS variants.
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEFAULT_EXTENSIONS: string[];
|
|
17
|
+
/**
|
|
18
|
+
* Default index files to try when resolving directory imports.
|
|
19
|
+
* Order: JS variants first (most common), then TS variants.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_INDEX_FILES: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Options for module path resolution.
|
|
24
|
+
*
|
|
25
|
+
* @example Filesystem mode (default)
|
|
26
|
+
* ```ts
|
|
27
|
+
* resolveModulePath('/app/utils')
|
|
28
|
+
* // → '/app/utils.js' if exists
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example In-memory mode (for enrichment plugins)
|
|
32
|
+
* ```ts
|
|
33
|
+
* resolveModulePath('/app/utils', {
|
|
34
|
+
* useFilesystem: false,
|
|
35
|
+
* fileIndex: new Set(['/app/utils.ts'])
|
|
36
|
+
* })
|
|
37
|
+
* // → '/app/utils.ts'
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export interface ModuleResolutionOptions {
|
|
41
|
+
/**
|
|
42
|
+
* Use filesystem for path verification.
|
|
43
|
+
* Default: true
|
|
44
|
+
*
|
|
45
|
+
* When true: uses existsSync() to check if files exist
|
|
46
|
+
* When false: uses fileIndex.has() for lookup
|
|
47
|
+
*
|
|
48
|
+
* Performance note: For high-frequency calls during enrichment,
|
|
49
|
+
* use in-memory mode (useFilesystem: false) with a pre-built fileIndex.
|
|
50
|
+
* For indexing phase, filesystem mode is acceptable.
|
|
51
|
+
*/
|
|
52
|
+
useFilesystem?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Pre-built set of known file paths.
|
|
55
|
+
* Required when useFilesystem=false.
|
|
56
|
+
*
|
|
57
|
+
* Throws Error if useFilesystem=false and fileIndex is not provided.
|
|
58
|
+
*/
|
|
59
|
+
fileIndex?: Set<string> | null;
|
|
60
|
+
/**
|
|
61
|
+
* Extensions to try (in order).
|
|
62
|
+
* Default: ['', '.js', '.mjs', '.cjs', '.jsx', '.ts', '.tsx']
|
|
63
|
+
*
|
|
64
|
+
* Empty string '' means try exact path first.
|
|
65
|
+
*/
|
|
66
|
+
extensions?: string[];
|
|
67
|
+
/**
|
|
68
|
+
* Index files to try (in order).
|
|
69
|
+
* Default: ['index.js', 'index.ts', 'index.mjs', 'index.cjs', 'index.jsx', 'index.tsx']
|
|
70
|
+
*/
|
|
71
|
+
indexFiles?: string[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Resolve a base path to an actual file by trying extensions and index files.
|
|
75
|
+
*
|
|
76
|
+
* @param basePath - Absolute path (without extension) to resolve
|
|
77
|
+
* @param options - Resolution options (filesystem vs in-memory, extensions, index files)
|
|
78
|
+
* @returns Resolved file path or null if not found
|
|
79
|
+
*
|
|
80
|
+
* @example Filesystem mode (default)
|
|
81
|
+
* ```ts
|
|
82
|
+
* resolveModulePath('/app/utils')
|
|
83
|
+
* // → '/app/utils.js' (if exists)
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @example In-memory mode (for enrichment plugins)
|
|
87
|
+
* ```ts
|
|
88
|
+
* resolveModulePath('/app/utils', {
|
|
89
|
+
* useFilesystem: false,
|
|
90
|
+
* fileIndex: new Set(['/app/utils.ts'])
|
|
91
|
+
* })
|
|
92
|
+
* // → '/app/utils.ts'
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* Note: Symbolic links are followed by existsSync(). Assumes all paths
|
|
96
|
+
* are within the project workspace as determined by discovery phase.
|
|
97
|
+
*/
|
|
98
|
+
export declare function resolveModulePath(basePath: string, options?: ModuleResolutionOptions): string | null;
|
|
99
|
+
/**
|
|
100
|
+
* Check if import specifier is a relative import.
|
|
101
|
+
*
|
|
102
|
+
* @param specifier - The import specifier (e.g., './utils', 'lodash')
|
|
103
|
+
* @returns true if relative import (./ or ../), false otherwise
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* isRelativeImport('./utils') // true
|
|
108
|
+
* isRelativeImport('../shared') // true
|
|
109
|
+
* isRelativeImport('lodash') // false
|
|
110
|
+
* isRelativeImport('@scope/pkg') // false
|
|
111
|
+
* isRelativeImport('node:fs') // false
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function isRelativeImport(specifier: string): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Resolve relative import specifier to actual file path.
|
|
117
|
+
*
|
|
118
|
+
* Combines relative path resolution with module path resolution.
|
|
119
|
+
* Returns null for non-relative specifiers (bare modules, scoped packages).
|
|
120
|
+
*
|
|
121
|
+
* @param specifier - The import specifier (e.g., './utils', '../shared')
|
|
122
|
+
* @param containingFile - The file containing the import
|
|
123
|
+
* @param options - Resolution options
|
|
124
|
+
* @returns Resolved file path or null if not found or not relative
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* // From /project/src/main.js, import './utils'
|
|
129
|
+
* resolveRelativeSpecifier('./utils', '/project/src/main.js')
|
|
130
|
+
* // → '/project/src/utils.js' (if exists)
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function resolveRelativeSpecifier(specifier: string, containingFile: string, options?: ModuleResolutionOptions): string | null;
|
|
134
|
+
//# sourceMappingURL=moduleResolution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moduleResolution.d.ts","sourceRoot":"","sources":["../../src/utils/moduleResolution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH;;;GAGG;AACH,eAAO,MAAM,kBAAkB,UAAqD,CAAC;AAerF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,UAO/B,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAE/B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IAEtB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAgCD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,uBAAuB,GAChC,MAAM,GAAG,IAAI,CAuDf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,uBAAuB,GAChC,MAAM,GAAG,IAAI,CAYf"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module Resolution Utilities (REG-320)
|
|
3
|
+
*
|
|
4
|
+
* Unified module path resolution logic extracted from:
|
|
5
|
+
* - MountPointResolver.resolveImportSource()
|
|
6
|
+
* - JSModuleIndexer.resolveModulePath()
|
|
7
|
+
* - FunctionCallResolver._resolveImportPath()
|
|
8
|
+
* - IncrementalModuleIndexer.tryResolve()
|
|
9
|
+
*
|
|
10
|
+
* Provides consistent module resolution across all plugins.
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync, statSync } from 'fs';
|
|
13
|
+
import { dirname, extname, resolve, join } from 'path';
|
|
14
|
+
/**
|
|
15
|
+
* Default file extensions to try when resolving modules.
|
|
16
|
+
* Order: exact match first, then JS variants, then TS variants.
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULT_EXTENSIONS = ['', '.js', '.mjs', '.cjs', '.jsx', '.ts', '.tsx'];
|
|
19
|
+
/**
|
|
20
|
+
* TypeScript extension redirects (REG-426).
|
|
21
|
+
* Maps JS-family extensions to their TS equivalents.
|
|
22
|
+
* Used when an import specifies a .js extension but only a .ts file exists.
|
|
23
|
+
* This matches TypeScript's own module resolution behavior for ESM.
|
|
24
|
+
*/
|
|
25
|
+
const TS_EXTENSION_REDIRECTS = {
|
|
26
|
+
'.js': ['.ts', '.tsx'],
|
|
27
|
+
'.jsx': ['.tsx'],
|
|
28
|
+
'.mjs': ['.mts'],
|
|
29
|
+
'.cjs': ['.cts'],
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Default index files to try when resolving directory imports.
|
|
33
|
+
* Order: JS variants first (most common), then TS variants.
|
|
34
|
+
*/
|
|
35
|
+
export const DEFAULT_INDEX_FILES = [
|
|
36
|
+
'index.js',
|
|
37
|
+
'index.ts',
|
|
38
|
+
'index.mjs',
|
|
39
|
+
'index.cjs',
|
|
40
|
+
'index.jsx',
|
|
41
|
+
'index.tsx'
|
|
42
|
+
];
|
|
43
|
+
/**
|
|
44
|
+
* Check if path exists using the configured method.
|
|
45
|
+
*/
|
|
46
|
+
function pathExists(testPath, useFilesystem, fileIndex) {
|
|
47
|
+
if (useFilesystem) {
|
|
48
|
+
return existsSync(testPath);
|
|
49
|
+
}
|
|
50
|
+
return fileIndex?.has(testPath) ?? false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if path is a directory (filesystem mode only).
|
|
54
|
+
*/
|
|
55
|
+
function isDirectory(path, useFilesystem) {
|
|
56
|
+
if (!useFilesystem) {
|
|
57
|
+
// In in-memory mode, we can't check if it's a directory
|
|
58
|
+
// The fileIndex should only contain file paths, not directories
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
return statSync(path).isDirectory();
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolve a base path to an actual file by trying extensions and index files.
|
|
70
|
+
*
|
|
71
|
+
* @param basePath - Absolute path (without extension) to resolve
|
|
72
|
+
* @param options - Resolution options (filesystem vs in-memory, extensions, index files)
|
|
73
|
+
* @returns Resolved file path or null if not found
|
|
74
|
+
*
|
|
75
|
+
* @example Filesystem mode (default)
|
|
76
|
+
* ```ts
|
|
77
|
+
* resolveModulePath('/app/utils')
|
|
78
|
+
* // → '/app/utils.js' (if exists)
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example In-memory mode (for enrichment plugins)
|
|
82
|
+
* ```ts
|
|
83
|
+
* resolveModulePath('/app/utils', {
|
|
84
|
+
* useFilesystem: false,
|
|
85
|
+
* fileIndex: new Set(['/app/utils.ts'])
|
|
86
|
+
* })
|
|
87
|
+
* // → '/app/utils.ts'
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* Note: Symbolic links are followed by existsSync(). Assumes all paths
|
|
91
|
+
* are within the project workspace as determined by discovery phase.
|
|
92
|
+
*/
|
|
93
|
+
export function resolveModulePath(basePath, options) {
|
|
94
|
+
const useFilesystem = options?.useFilesystem ?? true;
|
|
95
|
+
const fileIndex = options?.fileIndex;
|
|
96
|
+
const extensions = options?.extensions ?? DEFAULT_EXTENSIONS;
|
|
97
|
+
const indexFiles = options?.indexFiles ?? DEFAULT_INDEX_FILES;
|
|
98
|
+
// Validation: fail fast if misconfigured
|
|
99
|
+
if (!useFilesystem && !fileIndex) {
|
|
100
|
+
throw new Error('fileIndex is required when useFilesystem=false');
|
|
101
|
+
}
|
|
102
|
+
// Handle empty path gracefully
|
|
103
|
+
if (!basePath) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
// Normalize path (remove trailing slash)
|
|
107
|
+
const normalizedPath = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath;
|
|
108
|
+
// Try extensions (including '' for exact match)
|
|
109
|
+
for (const ext of extensions) {
|
|
110
|
+
const testPath = normalizedPath + ext;
|
|
111
|
+
if (pathExists(testPath, useFilesystem, fileIndex)) {
|
|
112
|
+
// In filesystem mode, don't return directories
|
|
113
|
+
if (useFilesystem && ext === '' && isDirectory(testPath, useFilesystem)) {
|
|
114
|
+
// It's a directory, skip to index files
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
return testPath;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// TypeScript extension redirect (REG-426):
|
|
121
|
+
// import './foo.js' → try ./foo.ts when ./foo.js doesn't exist
|
|
122
|
+
const ext = extname(normalizedPath);
|
|
123
|
+
const tsAlternatives = TS_EXTENSION_REDIRECTS[ext];
|
|
124
|
+
if (tsAlternatives) {
|
|
125
|
+
const withoutExt = normalizedPath.slice(0, -ext.length);
|
|
126
|
+
for (const tsExt of tsAlternatives) {
|
|
127
|
+
const testPath = withoutExt + tsExt;
|
|
128
|
+
if (pathExists(testPath, useFilesystem, fileIndex)) {
|
|
129
|
+
return testPath;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Try index files in directory
|
|
134
|
+
for (const indexFile of indexFiles) {
|
|
135
|
+
const testPath = join(normalizedPath, indexFile);
|
|
136
|
+
if (pathExists(testPath, useFilesystem, fileIndex)) {
|
|
137
|
+
return testPath;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Check if import specifier is a relative import.
|
|
144
|
+
*
|
|
145
|
+
* @param specifier - The import specifier (e.g., './utils', 'lodash')
|
|
146
|
+
* @returns true if relative import (./ or ../), false otherwise
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* isRelativeImport('./utils') // true
|
|
151
|
+
* isRelativeImport('../shared') // true
|
|
152
|
+
* isRelativeImport('lodash') // false
|
|
153
|
+
* isRelativeImport('@scope/pkg') // false
|
|
154
|
+
* isRelativeImport('node:fs') // false
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export function isRelativeImport(specifier) {
|
|
158
|
+
return specifier.startsWith('./') || specifier.startsWith('../');
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Resolve relative import specifier to actual file path.
|
|
162
|
+
*
|
|
163
|
+
* Combines relative path resolution with module path resolution.
|
|
164
|
+
* Returns null for non-relative specifiers (bare modules, scoped packages).
|
|
165
|
+
*
|
|
166
|
+
* @param specifier - The import specifier (e.g., './utils', '../shared')
|
|
167
|
+
* @param containingFile - The file containing the import
|
|
168
|
+
* @param options - Resolution options
|
|
169
|
+
* @returns Resolved file path or null if not found or not relative
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* // From /project/src/main.js, import './utils'
|
|
174
|
+
* resolveRelativeSpecifier('./utils', '/project/src/main.js')
|
|
175
|
+
* // → '/project/src/utils.js' (if exists)
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export function resolveRelativeSpecifier(specifier, containingFile, options) {
|
|
179
|
+
// Only handle relative imports
|
|
180
|
+
if (!isRelativeImport(specifier)) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
// Resolve relative path to absolute base path
|
|
184
|
+
const dir = dirname(containingFile);
|
|
185
|
+
const basePath = resolve(dir, specifier);
|
|
186
|
+
// Use main resolution function
|
|
187
|
+
return resolveModulePath(basePath, options);
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=moduleResolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moduleResolution.js","sourceRoot":"","sources":["../../src/utils/moduleResolution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAEvD;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAErF;;;;;GAKG;AACH,MAAM,sBAAsB,GAA6B;IACvD,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,CAAC,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,UAAU;IACV,UAAU;IACV,WAAW;IACX,WAAW;IACX,WAAW;IACX,WAAW;CACZ,CAAC;AAyDF;;GAEG;AACH,SAAS,UAAU,CACjB,QAAgB,EAChB,aAAsB,EACtB,SAA8B;IAE9B,IAAI,aAAa,EAAE,CAAC;QAClB,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,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I,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8CAA8C;IAC9C,MAAM,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACpC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAEzC,+BAA+B;IAC/B,OAAO,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a node's file path to an absolute path.
|
|
3
|
+
*
|
|
4
|
+
* After REG-408, node.file stores paths relative to projectPath.
|
|
5
|
+
* This utility resolves them back to absolute for file system access.
|
|
6
|
+
* Also handles legacy absolute paths for backward compatibility.
|
|
7
|
+
*
|
|
8
|
+
* @param nodeFile - The file field from a graph node (relative or absolute)
|
|
9
|
+
* @param projectPath - The absolute project root path
|
|
10
|
+
* @returns Absolute file path
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveNodeFile(nodeFile: string, projectPath: string): string;
|
|
13
|
+
//# sourceMappingURL=resolveNodeFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveNodeFile.d.ts","sourceRoot":"","sources":["../../src/utils/resolveNodeFile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAG7E"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a node's file path to an absolute path.
|
|
3
|
+
*
|
|
4
|
+
* After REG-408, node.file stores paths relative to projectPath.
|
|
5
|
+
* This utility resolves them back to absolute for file system access.
|
|
6
|
+
* Also handles legacy absolute paths for backward compatibility.
|
|
7
|
+
*
|
|
8
|
+
* @param nodeFile - The file field from a graph node (relative or absolute)
|
|
9
|
+
* @param projectPath - The absolute project root path
|
|
10
|
+
* @returns Absolute file path
|
|
11
|
+
*/
|
|
12
|
+
import { isAbsolute, join } from 'path';
|
|
13
|
+
export function resolveNodeFile(nodeFile, projectPath) {
|
|
14
|
+
if (isAbsolute(nodeFile))
|
|
15
|
+
return nodeFile;
|
|
16
|
+
return join(projectPath, nodeFile);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=resolveNodeFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveNodeFile.js","sourceRoot":"","sources":["../../src/utils/resolveNodeFile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAExC,MAAM,UAAU,eAAe,CAAC,QAAgB,EAAE,WAAmB;IACnE,IAAI,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC1C,OAAO,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utility for starting rfdb-server
|
|
3
|
+
*
|
|
4
|
+
* Single authoritative function for spawning rfdb-server. All spawn sites
|
|
5
|
+
* (RFDBServerBackend, CLI server command, ParallelAnalysisRunner) delegate here.
|
|
6
|
+
*
|
|
7
|
+
* If pidPath is provided, checks for an existing server via PID file before
|
|
8
|
+
* spawning. Returns null when an existing server is detected (caller should
|
|
9
|
+
* not kill it).
|
|
10
|
+
*/
|
|
11
|
+
import { spawn, type ChildProcess } from 'child_process';
|
|
12
|
+
export interface StartRfdbServerOptions {
|
|
13
|
+
dbPath: string;
|
|
14
|
+
socketPath: string;
|
|
15
|
+
/** Override binary path; if absent, findRfdbBinary() is called */
|
|
16
|
+
binaryPath?: string;
|
|
17
|
+
/** If provided, PID file is written after spawn and checked before spawn */
|
|
18
|
+
pidPath?: string;
|
|
19
|
+
/** Socket poll timeout in ms (default: 5000) */
|
|
20
|
+
waitTimeoutMs?: number;
|
|
21
|
+
/** Optional logger for debug messages */
|
|
22
|
+
logger?: {
|
|
23
|
+
debug(msg: string): void;
|
|
24
|
+
};
|
|
25
|
+
/** Internal: dependency injection for testing */
|
|
26
|
+
_deps?: {
|
|
27
|
+
spawn?: typeof spawn;
|
|
28
|
+
findRfdbBinary?: () => string | null;
|
|
29
|
+
existsSync?: (path: string) => boolean;
|
|
30
|
+
unlinkSync?: (path: string) => void;
|
|
31
|
+
writeFileSync?: (path: string, data: string) => void;
|
|
32
|
+
readFileSync?: (path: string, encoding: 'utf8') => string;
|
|
33
|
+
killProcess?: (pid: number, signal: number) => boolean;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check if an existing server is running based on PID file.
|
|
38
|
+
*
|
|
39
|
+
* Returns:
|
|
40
|
+
* - 'alive' — PID file exists, process is alive, socket is present
|
|
41
|
+
* - 'stale' — PID file exists but process is dead or PID is invalid
|
|
42
|
+
* - 'none' — no PID file
|
|
43
|
+
*/
|
|
44
|
+
export declare function checkExistingServer(pidPath: string, socketPath: string, deps: {
|
|
45
|
+
existsSync: (path: string) => boolean;
|
|
46
|
+
readFileSync: (path: string, encoding: 'utf8') => string;
|
|
47
|
+
killProcess: (pid: number, signal: number) => boolean;
|
|
48
|
+
}): 'alive' | 'stale' | 'none';
|
|
49
|
+
/**
|
|
50
|
+
* Start an rfdb-server process (or detect existing one via PID file).
|
|
51
|
+
*
|
|
52
|
+
* 0. Check PID file for existing server (if pidPath provided)
|
|
53
|
+
* 1. Resolve binary (explicit or via findRfdbBinary)
|
|
54
|
+
* 2. Remove stale socket
|
|
55
|
+
* 3. Spawn detached process
|
|
56
|
+
* 4. Write PID file (if pidPath provided)
|
|
57
|
+
* 5. Poll for socket file up to waitTimeoutMs
|
|
58
|
+
* 6. Return ChildProcess (caller decides whether to kill later)
|
|
59
|
+
*
|
|
60
|
+
* Returns null if an existing server is already running (pidPath + alive PID).
|
|
61
|
+
*/
|
|
62
|
+
export declare function startRfdbServer(options: StartRfdbServerOptions): Promise<ChildProcess | null>;
|
|
63
|
+
//# sourceMappingURL=startRfdbServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startRfdbServer.d.ts","sourceRoot":"","sources":["../../src/utils/startRfdbServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAIzD,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yCAAyC;IACzC,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACtC,iDAAiD;IACjD,KAAK,CAAC,EAAE;QACN,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;QACrB,cAAc,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;QACrC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;QACvC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;QACpC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;QACrD,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;QAC1D,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;KACx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