codebase-onboarder 0.6.0 → 0.7.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/README.md +174 -46
- package/bin/build-if-source.js +23 -0
- package/cli/commands.d.ts +26 -0
- package/cli/commands.js +836 -811
- package/cli/commands.js.map +1 -0
- package/cli/explorer/advanced.d.ts +14 -0
- package/cli/explorer/advanced.js +321 -329
- package/cli/explorer/advanced.js.map +1 -0
- package/cli/explorer/app.d.ts +1 -0
- package/cli/explorer/app.js +384 -313
- package/cli/explorer/app.js.map +1 -0
- package/cli/explorer/assistant.d.ts +9 -0
- package/cli/explorer/assistant.js +58 -0
- package/cli/explorer/assistant.js.map +1 -0
- package/cli/explorer/commands.d.ts +17 -0
- package/cli/explorer/commands.js +368 -302
- package/cli/explorer/commands.js.map +1 -0
- package/cli/explorer/featureViews.d.ts +124 -0
- package/cli/explorer/featureViews.js +179 -0
- package/cli/explorer/featureViews.js.map +1 -0
- package/cli/explorer/github.d.ts +21 -0
- package/cli/explorer/github.js +42 -44
- package/cli/explorer/github.js.map +1 -0
- package/cli/explorer/graphs.d.ts +7 -0
- package/cli/explorer/graphs.js +90 -95
- package/cli/explorer/graphs.js.map +1 -0
- package/cli/explorer/picker.d.ts +22 -0
- package/cli/explorer/picker.js +150 -0
- package/cli/explorer/picker.js.map +1 -0
- package/cli/explorer/report.d.ts +85 -0
- package/cli/explorer/report.js +60 -0
- package/cli/explorer/report.js.map +1 -0
- package/cli/explorer/session.d.ts +449 -0
- package/cli/explorer/session.js +143 -144
- package/cli/explorer/session.js.map +1 -0
- package/cli/explorer/views.d.ts +19 -0
- package/cli/explorer/views.js +465 -482
- package/cli/explorer/views.js.map +1 -0
- package/cli/explorer/wrap.d.ts +1 -0
- package/cli/explorer/wrap.js +28 -44
- package/cli/explorer/wrap.js.map +1 -0
- package/cli/main.d.ts +1 -0
- package/cli/main.js +214 -161
- package/cli/main.js.map +1 -0
- package/cli/prompt.d.ts +5 -0
- package/cli/prompt.js +84 -80
- package/cli/prompt.js.map +1 -0
- package/cli/scanOptions.d.ts +2 -0
- package/cli/scanOptions.js +11 -0
- package/cli/scanOptions.js.map +1 -0
- package/cli/ui.d.ts +33 -0
- package/cli/ui.js +35 -44
- package/cli/ui.js.map +1 -0
- package/cli/wizard.d.ts +187 -0
- package/cli/wizard.js +304 -284
- package/cli/wizard.js.map +1 -0
- package/package.json +15 -4
- package/public/app.d.ts +1 -0
- package/public/app.js +1057 -1009
- package/public/app.js.map +1 -0
- package/public/browser.d.ts +68 -0
- package/public/browser.js +2 -0
- package/public/browser.js.map +1 -0
- package/public/index.html +30 -13
- package/public/js/about.d.ts +6 -0
- package/public/js/about.js +152 -172
- package/public/js/about.js.map +1 -0
- package/public/js/aiDraft.d.ts +3 -0
- package/public/js/aiDraft.js +116 -124
- package/public/js/aiDraft.js.map +1 -0
- package/public/js/analysisPanel.d.ts +7 -0
- package/public/js/analysisPanel.js +166 -166
- package/public/js/analysisPanel.js.map +1 -0
- package/public/js/analysisReport.d.ts +38 -0
- package/public/js/analysisReport.js +105 -110
- package/public/js/analysisReport.js.map +1 -0
- package/public/js/api.d.ts +26 -0
- package/public/js/api.js +176 -167
- package/public/js/api.js.map +1 -0
- package/public/js/atlas.d.ts +6 -0
- package/public/js/atlas.js +50 -58
- package/public/js/atlas.js.map +1 -0
- package/public/js/blameView.d.ts +2 -0
- package/public/js/blameView.js +36 -37
- package/public/js/blameView.js.map +1 -0
- package/public/js/codeTab.d.ts +3 -0
- package/public/js/codeTab.js +175 -180
- package/public/js/codeTab.js.map +1 -0
- package/public/js/codeViewer.d.ts +5 -0
- package/public/js/codeViewer.js +162 -150
- package/public/js/codeViewer.js.map +1 -0
- package/public/js/components/FileChip.d.ts +9 -0
- package/public/js/components/FileChip.js +45 -49
- package/public/js/components/FileChip.js.map +1 -0
- package/public/js/components/MetricSparkline.d.ts +7 -0
- package/public/js/components/MetricSparkline.js +35 -44
- package/public/js/components/MetricSparkline.js.map +1 -0
- package/public/js/components/RiskBadge.d.ts +9 -0
- package/public/js/components/RiskBadge.js +55 -63
- package/public/js/components/RiskBadge.js.map +1 -0
- package/public/js/deepAnalysisView.d.ts +99 -0
- package/public/js/deepAnalysisView.js +282 -302
- package/public/js/deepAnalysisView.js.map +1 -0
- package/public/js/diagramPane.d.ts +8 -0
- package/public/js/diagramPane.js +133 -135
- package/public/js/diagramPane.js.map +1 -0
- package/public/js/diffView.d.ts +6 -0
- package/public/js/diffView.js +222 -209
- package/public/js/diffView.js.map +1 -0
- package/public/js/docsView.d.ts +2 -0
- package/public/js/docsView.js +441 -442
- package/public/js/docsView.js.map +1 -0
- package/public/js/dom.d.ts +189 -0
- package/public/js/dom.js +5 -0
- package/public/js/dom.js.map +1 -0
- package/public/js/fileSourceBrowser.d.ts +5 -0
- package/public/js/fileSourceBrowser.js +33 -41
- package/public/js/fileSourceBrowser.js.map +1 -0
- package/public/js/flameGraph.d.ts +5 -0
- package/public/js/flameGraph.js +62 -72
- package/public/js/flameGraph.js.map +1 -0
- package/public/js/forceGraph.d.ts +10 -0
- package/public/js/forceGraph.js +581 -556
- package/public/js/forceGraph.js.map +1 -0
- package/public/js/heatmap.d.ts +4 -0
- package/public/js/heatmap.js +142 -164
- package/public/js/heatmap.js.map +1 -0
- package/public/js/highlight.d.ts +2 -0
- package/public/js/highlight.js +116 -107
- package/public/js/highlight.js.map +1 -0
- package/public/js/html.d.ts +2 -0
- package/public/js/html.js +14 -44
- package/public/js/html.js.map +1 -0
- package/public/js/insightsView.d.ts +5 -0
- package/public/js/insightsView.js +93 -111
- package/public/js/insightsView.js.map +1 -0
- package/public/js/inspector.d.ts +37 -0
- package/public/js/inspector.js +416 -445
- package/public/js/inspector.js.map +1 -0
- package/public/js/llm.d.ts +113 -0
- package/public/js/llm.js +233 -272
- package/public/js/llm.js.map +1 -0
- package/public/js/mapView.d.ts +3 -0
- package/public/js/mapView.js +121 -120
- package/public/js/mapView.js.map +1 -0
- package/public/js/markdown.d.ts +3 -0
- package/public/js/markdown.js +84 -91
- package/public/js/markdown.js.map +1 -0
- package/public/js/mindmap.d.ts +32 -0
- package/public/js/mindmap.js +244 -259
- package/public/js/mindmap.js.map +1 -0
- package/public/js/mobilePanels.d.ts +5 -0
- package/public/js/mobilePanels.js +50 -0
- package/public/js/mobilePanels.js.map +1 -0
- package/public/js/repoFiles.d.ts +12 -0
- package/public/js/repoFiles.js +28 -27
- package/public/js/repoFiles.js.map +1 -0
- package/public/js/reviewView.d.ts +28 -0
- package/public/js/reviewView.js +256 -0
- package/public/js/reviewView.js.map +1 -0
- package/public/js/sbomView.d.ts +3 -0
- package/public/js/sbomView.js +59 -67
- package/public/js/sbomView.js.map +1 -0
- package/public/js/scanCache.d.ts +16 -0
- package/public/js/scanCache.js +67 -65
- package/public/js/scanCache.js.map +1 -0
- package/public/js/search.d.ts +7 -0
- package/public/js/search.js +868 -800
- package/public/js/search.js.map +1 -0
- package/public/js/searchLocal.d.ts +42 -0
- package/public/js/searchLocal.js +87 -0
- package/public/js/searchLocal.js.map +1 -0
- package/public/js/serverSettings.d.ts +5 -0
- package/public/js/serverSettings.js +153 -164
- package/public/js/serverSettings.js.map +1 -0
- package/public/js/state.d.ts +798 -0
- package/public/js/state.js +114 -122
- package/public/js/state.js.map +1 -0
- package/public/js/tour.d.ts +6 -0
- package/public/js/tour.js +5 -7
- package/public/js/tour.js.map +1 -0
- package/public/js/transitions.d.ts +2 -0
- package/public/js/transitions.js +9 -10
- package/public/js/transitions.js.map +1 -0
- package/public/js/tree.d.ts +12 -0
- package/public/js/tree.js +157 -154
- package/public/js/tree.js.map +1 -0
- package/public/js/workflowsView.d.ts +3 -0
- package/public/js/workflowsView.js +15 -22
- package/public/js/workflowsView.js.map +1 -0
- package/public/search.css +495 -0
- package/public/styles.css +163 -346
- package/public/workbench.css +166 -0
- package/server/apiAuth.d.ts +3 -0
- package/server/apiAuth.js +18 -20
- package/server/apiAuth.js.map +1 -0
- package/server/apiDiff.d.ts +2 -0
- package/server/apiDiff.js +20 -18
- package/server/apiDiff.js.map +1 -0
- package/server/apiDocs.d.ts +2 -0
- package/server/apiDocs.js +38 -40
- package/server/apiDocs.js.map +1 -0
- package/server/apiFile.d.ts +1 -0
- package/server/apiFile.js +14 -17
- package/server/apiFile.js.map +1 -0
- package/server/apiGitBlame.d.ts +2 -0
- package/server/apiGitBlame.js +50 -51
- package/server/apiGitBlame.js.map +1 -0
- package/server/apiMcp.d.ts +4 -0
- package/server/apiMcp.js +64 -66
- package/server/apiMcp.js.map +1 -0
- package/server/apiReview.d.ts +2 -0
- package/server/apiReview.js +45 -0
- package/server/apiReview.js.map +1 -0
- package/server/apiScan.d.ts +5 -0
- package/server/apiScan.js +90 -71
- package/server/apiScan.js.map +1 -0
- package/server/apiSearch.d.ts +33 -0
- package/server/apiSearch.js +184 -200
- package/server/apiSearch.js.map +1 -0
- package/server/apiSettings.d.ts +4 -0
- package/server/apiSettings.js +84 -85
- package/server/apiSettings.js.map +1 -0
- package/server/apiTools.d.ts +3 -0
- package/server/apiTools.js +55 -56
- package/server/apiTools.js.map +1 -0
- package/server/auth.d.ts +5 -0
- package/server/auth.js +54 -51
- package/server/auth.js.map +1 -0
- package/server/config.d.ts +42 -0
- package/server/config.js +189 -194
- package/server/config.js.map +1 -0
- package/server/daemon.d.ts +12 -0
- package/server/daemon.js +124 -114
- package/server/daemon.js.map +1 -0
- package/server/fileSourceNode.d.ts +2 -0
- package/server/fileSourceNode.js +34 -36
- package/server/fileSourceNode.js.map +1 -0
- package/server/gitClone.d.ts +9 -0
- package/server/gitClone.js +59 -61
- package/server/gitClone.js.map +1 -0
- package/server/gitDiff.d.ts +36 -0
- package/server/gitDiff.js +271 -169
- package/server/gitDiff.js.map +1 -0
- package/server/gitHistory.d.ts +12 -0
- package/server/gitHistory.js +80 -80
- package/server/gitHistory.js.map +1 -0
- package/server/gitRemote.d.ts +12 -0
- package/server/gitRemote.js +37 -38
- package/server/gitRemote.js.map +1 -0
- package/server/htmlText.d.ts +4 -0
- package/server/htmlText.js +16 -23
- package/server/htmlText.js.map +1 -0
- package/server/http.d.ts +5 -0
- package/server/http.js +27 -30
- package/server/http.js.map +1 -0
- package/server/httpGuards.d.ts +2 -0
- package/server/httpGuards.js +47 -43
- package/server/httpGuards.js.map +1 -0
- package/server/https.d.ts +34 -0
- package/server/https.js +121 -111
- package/server/https.js.map +1 -0
- package/server/index.d.ts +40 -0
- package/server/index.js +139 -147
- package/server/index.js.map +1 -0
- package/server/layout.d.ts +26 -0
- package/server/layout.js +59 -64
- package/server/layout.js.map +1 -0
- package/server/llmProxy.d.ts +3 -0
- package/server/llmProxy.js +137 -135
- package/server/llmProxy.js.map +1 -0
- package/server/logger.d.ts +38 -0
- package/server/logger.js +198 -211
- package/server/logger.js.map +1 -0
- package/server/mcp/analysis.d.ts +29 -0
- package/server/mcp/analysis.js +99 -120
- package/server/mcp/analysis.js.map +1 -0
- package/server/mcp/http.d.ts +9 -0
- package/server/mcp/http.js +128 -137
- package/server/mcp/http.js.map +1 -0
- package/server/mcp/runner.d.ts +68 -0
- package/server/mcp/runner.js +208 -218
- package/server/mcp/runner.js.map +1 -0
- package/server/mcp/server.d.ts +29 -0
- package/server/mcp/server.js +166 -179
- package/server/mcp/server.js.map +1 -0
- package/server/mcp/standalone.d.ts +1 -0
- package/server/mcp/standalone.js +8 -10
- package/server/mcp/standalone.js.map +1 -0
- package/server/mcp/tools.d.ts +2020 -0
- package/server/mcp/tools.js +523 -574
- package/server/mcp/tools.js.map +1 -0
- package/server/paths.d.ts +3 -0
- package/server/paths.js +17 -15
- package/server/paths.js.map +1 -0
- package/server/pidfile.d.ts +9 -0
- package/server/pidfile.js +43 -45
- package/server/pidfile.js.map +1 -0
- package/server/review.d.ts +5 -0
- package/server/review.js +35 -0
- package/server/review.js.map +1 -0
- package/server/router.d.ts +33 -0
- package/server/router.js +191 -197
- package/server/router.js.map +1 -0
- package/server/scanRequest.d.ts +3 -0
- package/server/scanRequest.js +36 -0
- package/server/scanRequest.js.map +1 -0
- package/server/searchIndex.d.ts +17 -0
- package/server/searchIndex.js +83 -80
- package/server/searchIndex.js.map +1 -0
- package/server/sessions.d.ts +14 -0
- package/server/sessions.js +62 -70
- package/server/sessions.js.map +1 -0
- package/server/startup.d.ts +118 -0
- package/server/startup.js +143 -148
- package/server/startup.js.map +1 -0
- package/server/static.d.ts +6 -0
- package/server/static.js +28 -31
- package/server/static.js.map +1 -0
- package/server/tools/install.d.ts +4 -0
- package/server/tools/install.js +176 -185
- package/server/tools/install.js.map +1 -0
- package/server/tools/parse.d.ts +8 -0
- package/server/tools/parse.js +112 -114
- package/server/tools/parse.js.map +1 -0
- package/server/tools/platform.d.ts +9 -0
- package/server/tools/platform.js +49 -47
- package/server/tools/platform.js.map +1 -0
- package/server/tools/registry.d.ts +137 -0
- package/server/tools/registry.js +173 -172
- package/server/tools/registry.js.map +1 -0
- package/server/tools/scan.d.ts +34 -0
- package/server/tools/scan.js +89 -98
- package/server/tools/scan.js.map +1 -0
- package/server/tools.d.ts +34 -0
- package/server/tools.js +94 -107
- package/server/tools.js.map +1 -0
- package/server/tunnel.d.ts +29 -0
- package/server/tunnel.js +61 -66
- package/server/tunnel.js.map +1 -0
- package/shared/analyzer/docs.d.ts +16 -0
- package/shared/analyzer/docs.js +99 -93
- package/shared/analyzer/docs.js.map +1 -0
- package/shared/analyzer/explainLocal.d.ts +4 -0
- package/shared/analyzer/explainLocal.js +122 -142
- package/shared/analyzer/explainLocal.js.map +1 -0
- package/shared/analyzer/github.d.ts +37 -0
- package/shared/analyzer/github.js +41 -43
- package/shared/analyzer/github.js.map +1 -0
- package/shared/analyzer/graph.d.ts +41 -0
- package/shared/analyzer/graph.js +393 -400
- package/shared/analyzer/graph.js.map +1 -0
- package/shared/analyzer/health.d.ts +33 -0
- package/shared/analyzer/health.js +197 -193
- package/shared/analyzer/health.js.map +1 -0
- package/shared/analyzer/history.d.ts +29 -0
- package/shared/analyzer/history.js +110 -111
- package/shared/analyzer/history.js.map +1 -0
- package/shared/analyzer/jsonConfig.d.ts +2 -0
- package/shared/analyzer/jsonConfig.js +61 -0
- package/shared/analyzer/jsonConfig.js.map +1 -0
- package/shared/analyzer/languages/csharp.d.ts +26 -0
- package/shared/analyzer/languages/csharp.js +83 -88
- package/shared/analyzer/languages/csharp.js.map +1 -0
- package/shared/analyzer/languages/generic.d.ts +23 -0
- package/shared/analyzer/languages/generic.js +94 -105
- package/shared/analyzer/languages/generic.js.map +1 -0
- package/shared/analyzer/languages/go.d.ts +24 -0
- package/shared/analyzer/languages/go.js +45 -54
- package/shared/analyzer/languages/go.js.map +1 -0
- package/shared/analyzer/languages/index.d.ts +6 -0
- package/shared/analyzer/languages/index.js +19 -20
- package/shared/analyzer/languages/index.js.map +1 -0
- package/shared/analyzer/languages/java.d.ts +20 -0
- package/shared/analyzer/languages/java.js +73 -78
- package/shared/analyzer/languages/java.js.map +1 -0
- package/shared/analyzer/languages/javascript.d.ts +12 -0
- package/shared/analyzer/languages/javascript.js +258 -209
- package/shared/analyzer/languages/javascript.js.map +1 -0
- package/shared/analyzer/languages/python.d.ts +23 -0
- package/shared/analyzer/languages/python.js +92 -100
- package/shared/analyzer/languages/python.js.map +1 -0
- package/shared/analyzer/languages/rust.d.ts +17 -0
- package/shared/analyzer/languages/rust.js +96 -98
- package/shared/analyzer/languages/rust.js.map +1 -0
- package/shared/analyzer/languages/typescript.d.ts +11 -0
- package/shared/analyzer/languages/typescript.js +117 -116
- package/shared/analyzer/languages/typescript.js.map +1 -0
- package/shared/analyzer/licenses.d.ts +18 -0
- package/shared/analyzer/licenses.js +130 -133
- package/shared/analyzer/licenses.js.map +1 -0
- package/shared/analyzer/metrics.d.ts +20 -0
- package/shared/analyzer/metrics.js +112 -104
- package/shared/analyzer/metrics.js.map +1 -0
- package/shared/analyzer/pathUtil.d.ts +10 -0
- package/shared/analyzer/pathUtil.js +29 -35
- package/shared/analyzer/pathUtil.js.map +1 -0
- package/shared/analyzer/patterns.d.ts +11 -0
- package/shared/analyzer/patterns.js +231 -253
- package/shared/analyzer/patterns.js.map +1 -0
- package/shared/analyzer/scan.d.ts +62 -0
- package/shared/analyzer/scan.js +451 -442
- package/shared/analyzer/scan.js.map +1 -0
- package/shared/analyzer/scanControl.d.ts +11 -0
- package/shared/analyzer/scanControl.js +62 -0
- package/shared/analyzer/scanControl.js.map +1 -0
- package/shared/analyzer/security.d.ts +18 -0
- package/shared/analyzer/security.js +159 -159
- package/shared/analyzer/security.js.map +1 -0
- package/shared/analyzer/services.d.ts +5 -0
- package/shared/analyzer/services.js +141 -138
- package/shared/analyzer/services.js.map +1 -0
- package/shared/analyzer/stack.d.ts +6 -0
- package/shared/analyzer/stack.js +134 -141
- package/shared/analyzer/stack.js.map +1 -0
- package/shared/analyzer/tour.d.ts +2 -0
- package/shared/analyzer/tour.js +45 -53
- package/shared/analyzer/tour.js.map +1 -0
- package/shared/analyzer/util.d.ts +8 -0
- package/shared/analyzer/util.js +130 -76
- package/shared/analyzer/util.js.map +1 -0
- package/shared/analyzer/workflows.d.ts +8 -0
- package/shared/analyzer/workflows.js +139 -134
- package/shared/analyzer/workflows.js.map +1 -0
- package/shared/contracts.d.ts +250 -0
- package/shared/contracts.js +2 -0
- package/shared/contracts.js.map +1 -0
- package/shared/diagram/aiFacts.d.ts +35 -0
- package/shared/diagram/aiFacts.js +102 -105
- package/shared/diagram/aiFacts.js.map +1 -0
- package/shared/diagram/aiMermaid.d.ts +5 -0
- package/shared/diagram/aiMermaid.js +46 -45
- package/shared/diagram/aiMermaid.js.map +1 -0
- package/shared/diagram/atlas.d.ts +16 -0
- package/shared/diagram/atlas.js +51 -60
- package/shared/diagram/atlas.js.map +1 -0
- package/shared/diagram/mermaid.d.ts +43 -0
- package/shared/diagram/mermaid.js +348 -370
- package/shared/diagram/mermaid.js.map +1 -0
- package/shared/review/contracts.d.ts +95 -0
- package/shared/review/contracts.js +2 -0
- package/shared/review/contracts.js.map +1 -0
- package/shared/review/review.d.ts +10 -0
- package/shared/review/review.js +184 -0
- package/shared/review/review.js.map +1 -0
- package/shared/search/query.d.ts +32 -0
- package/shared/search/query.js +395 -388
- package/shared/search/query.js.map +1 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const extensions: string[];
|
|
2
|
+
export declare function analyze(source: any, path: any): {
|
|
3
|
+
imports: any[];
|
|
4
|
+
exports: any[];
|
|
5
|
+
functions: any[];
|
|
6
|
+
classes: any[];
|
|
7
|
+
calls: any[];
|
|
8
|
+
hasMain: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function packageNameOf(spec: any): any;
|
|
11
|
+
export declare function resolveImport(spec: any, fromPath: any, has: any, context?: Record<string, any>, meta?: Record<string, any>): {
|
|
12
|
+
unresolved?: undefined;
|
|
13
|
+
external: any;
|
|
14
|
+
path?: undefined;
|
|
15
|
+
} | {
|
|
16
|
+
unresolved?: undefined;
|
|
17
|
+
external?: undefined;
|
|
18
|
+
path: any;
|
|
19
|
+
} | {
|
|
20
|
+
external?: undefined;
|
|
21
|
+
path?: undefined;
|
|
22
|
+
unresolved: any;
|
|
23
|
+
};
|
|
@@ -9,123 +9,112 @@
|
|
|
9
9
|
// include/import/require/use lines plus the obvious function and class
|
|
10
10
|
// shapes. It is enough to place these files on the map; treating it as more
|
|
11
11
|
// than that would be lying.
|
|
12
|
-
|
|
13
12
|
import { blankComments, lineCounter, uniqueBy } from '../util.js';
|
|
14
13
|
import { dirOf, joinPath, baseName } from '../pathUtil.js';
|
|
15
|
-
|
|
16
14
|
export const extensions = ['.c', '.h', '.cc', '.cpp', '.hpp', '.rb', '.php'];
|
|
17
|
-
|
|
18
15
|
const BY_EXT = {
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
c: 'c', h: 'c', cc: 'c', cpp: 'c', hpp: 'c',
|
|
17
|
+
rb: 'ruby', php: 'php',
|
|
21
18
|
};
|
|
22
|
-
|
|
23
19
|
const CONTROL = new Set(['if', 'for', 'while', 'switch', 'catch', 'return', 'sizeof', 'do', 'else']);
|
|
24
|
-
|
|
25
20
|
export function analyze(source, path) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
const family = BY_EXT[path.slice(path.lastIndexOf('.') + 1)] || 'c';
|
|
22
|
+
const clean = blankComments(source, { lineChar: family === 'ruby' ? '#' : '//' });
|
|
23
|
+
const lineAt = lineCounter(clean);
|
|
24
|
+
const imports = [];
|
|
25
|
+
const functions = [];
|
|
26
|
+
const classes = [];
|
|
27
|
+
if (family === 'c') {
|
|
28
|
+
for (const m of clean.matchAll(/^[ \t]*#[ \t]*include[ \t]*"([^"]+)"/gm)) {
|
|
29
|
+
imports.push({ spec: m[1], local: true, line: lineAt(m.index) });
|
|
30
|
+
}
|
|
31
|
+
for (const m of clean.matchAll(/^[ \t]*#[ \t]*include[ \t]*<([^>]+)>/gm)) {
|
|
32
|
+
imports.push({ spec: m[1], local: false, line: lineAt(m.index) });
|
|
33
|
+
}
|
|
34
|
+
for (const m of clean.matchAll(/^[A-Za-z_][\w\s\*]*?\s+([\w]+)\s*\([^;{}]*\)\s*\{/gm)) {
|
|
35
|
+
if (!CONTROL.has(m[1]))
|
|
36
|
+
functions.push({ name: m[1], kind: 'function', line: lineAt(m.index) });
|
|
37
|
+
}
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
if (family === 'ruby') {
|
|
40
|
+
for (const m of clean.matchAll(/^[ \t]*require_relative\s+['"]([^'"]+)['"]/gm)) {
|
|
41
|
+
imports.push({ spec: m[1], kind: 'require_relative', line: lineAt(m.index) });
|
|
42
|
+
}
|
|
43
|
+
for (const m of clean.matchAll(/^[ \t]*require\s+['"]([^'"]+)['"]/gm)) {
|
|
44
|
+
imports.push({ spec: m[1], kind: 'require', line: lineAt(m.index) });
|
|
45
|
+
}
|
|
46
|
+
for (const m of clean.matchAll(/^[ \t]*def\s+([\w!?]+)/gm)) {
|
|
47
|
+
functions.push({ name: m[1], kind: 'function', line: lineAt(m.index) });
|
|
48
|
+
}
|
|
49
|
+
for (const m of clean.matchAll(/^[ \t]*(?:class|module)\s+([\w:]+)/gm)) {
|
|
50
|
+
classes.push({ name: m[1], line: lineAt(m.index) });
|
|
51
|
+
}
|
|
40
52
|
}
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
if (family === 'php') {
|
|
54
|
+
for (const m of clean.matchAll(/\b(?:require|include)(?:_once)?\s*\(?\s*['"]([^'"]+)['"]/g)) {
|
|
55
|
+
imports.push({ spec: m[1], kind: 'require', line: lineAt(m.index) });
|
|
56
|
+
}
|
|
57
|
+
for (const m of clean.matchAll(/^[ \t]*use\s+([\w\\]+)\s*;/gm)) {
|
|
58
|
+
imports.push({ spec: m[1], kind: 'use', line: lineAt(m.index) });
|
|
59
|
+
}
|
|
60
|
+
for (const m of clean.matchAll(/\bfunction\s+([\w]+)\s*\(/g)) {
|
|
61
|
+
functions.push({ name: m[1], kind: 'function', line: lineAt(m.index) });
|
|
62
|
+
}
|
|
63
|
+
for (const m of clean.matchAll(/\bclass\s+([\w]+)/g)) {
|
|
64
|
+
classes.push({ name: m[1], line: lineAt(m.index) });
|
|
65
|
+
}
|
|
43
66
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
for (const m of clean.matchAll(/^[ \t]*def\s+([\w!?]+)/gm)) {
|
|
54
|
-
functions.push({ name: m[1], kind: 'function', line: lineAt(m.index) });
|
|
55
|
-
}
|
|
56
|
-
for (const m of clean.matchAll(/^[ \t]*(?:class|module)\s+([\w:]+)/gm)) {
|
|
57
|
-
classes.push({ name: m[1], line: lineAt(m.index) });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (family === 'php') {
|
|
62
|
-
for (const m of clean.matchAll(/\b(?:require|include)(?:_once)?\s*\(?\s*['"]([^'"]+)['"]/g)) {
|
|
63
|
-
imports.push({ spec: m[1], kind: 'require', line: lineAt(m.index) });
|
|
64
|
-
}
|
|
65
|
-
for (const m of clean.matchAll(/^[ \t]*use\s+([\w\\]+)\s*;/gm)) {
|
|
66
|
-
imports.push({ spec: m[1], kind: 'use', line: lineAt(m.index) });
|
|
67
|
-
}
|
|
68
|
-
for (const m of clean.matchAll(/\bfunction\s+([\w]+)\s*\(/g)) {
|
|
69
|
-
functions.push({ name: m[1], kind: 'function', line: lineAt(m.index) });
|
|
70
|
-
}
|
|
71
|
-
for (const m of clean.matchAll(/\bclass\s+([\w]+)/g)) {
|
|
72
|
-
classes.push({ name: m[1], line: lineAt(m.index) });
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
imports: uniqueBy(imports, (i) => i.spec + ':' + (i.kind || '')),
|
|
78
|
-
exports: [],
|
|
79
|
-
functions,
|
|
80
|
-
classes,
|
|
81
|
-
calls: [],
|
|
82
|
-
hasMain: family === 'c' && /\bint\s+main\s*\(/.test(clean),
|
|
83
|
-
};
|
|
67
|
+
return {
|
|
68
|
+
imports: uniqueBy(imports, (i) => i.spec + ':' + (i.kind || '')),
|
|
69
|
+
exports: [],
|
|
70
|
+
functions,
|
|
71
|
+
classes,
|
|
72
|
+
calls: [],
|
|
73
|
+
hasMain: family === 'c' && /\bint\s+main\s*\(/.test(clean),
|
|
74
|
+
};
|
|
84
75
|
}
|
|
85
|
-
|
|
86
76
|
export function packageNameOf(spec) {
|
|
87
|
-
|
|
88
|
-
|
|
77
|
+
if (spec.endsWith('.h') || spec.endsWith('.hpp'))
|
|
78
|
+
return spec;
|
|
79
|
+
return spec.split(/[.:/\\]/)[0] || spec;
|
|
89
80
|
}
|
|
90
|
-
|
|
91
81
|
export function resolveImport(spec, fromPath, has, context = {}, meta = {}) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
}
|
|
130
|
-
return { unresolved: spec };
|
|
82
|
+
const fromDir = dirOf(fromPath);
|
|
83
|
+
const { findByName = () => null } = context;
|
|
84
|
+
// C angle-bracket includes like <stdio.h> are explicitly external
|
|
85
|
+
if (meta.local === false && meta.kind !== 'mod' && meta.kind !== 'use' && meta.kind !== 'import') {
|
|
86
|
+
return { external: packageNameOf(spec) };
|
|
87
|
+
}
|
|
88
|
+
const cleaned = spec.replace(/::/g, '/').replace(/\\/g, '/').replace(/\./g, '/');
|
|
89
|
+
const lastDot = spec.lastIndexOf('.');
|
|
90
|
+
const lastSlash = Math.max(spec.lastIndexOf('/'), spec.lastIndexOf('\\'));
|
|
91
|
+
const lastColon = spec.lastIndexOf('::');
|
|
92
|
+
const lastSep = Math.max(lastDot, lastSlash, lastColon >= 0 ? lastColon + 1 : -1);
|
|
93
|
+
const lastSegment = lastSep >= 0 ? spec.slice(lastSep + 1) : spec;
|
|
94
|
+
// Only the extensions this module owns. Java/Rust have their own resolvers.
|
|
95
|
+
const candidates = [
|
|
96
|
+
joinPath(fromDir, spec),
|
|
97
|
+
joinPath(fromDir, spec) + '.rb',
|
|
98
|
+
joinPath(fromDir, cleaned) + '.rb',
|
|
99
|
+
joinPath(fromDir, cleaned) + '.php',
|
|
100
|
+
joinPath(fromDir, spec) + '.php',
|
|
101
|
+
];
|
|
102
|
+
for (const cand of candidates) {
|
|
103
|
+
if (cand && has(cand))
|
|
104
|
+
return { path: cand };
|
|
105
|
+
}
|
|
106
|
+
// Last resort for quoted includes: match on the file name anywhere.
|
|
107
|
+
if (lastSegment && lastSegment !== '*') {
|
|
108
|
+
const hitPhp = findByName(lastSegment + '.php');
|
|
109
|
+
if (hitPhp)
|
|
110
|
+
return { path: hitPhp };
|
|
111
|
+
}
|
|
112
|
+
const hit = findByName(baseName(spec));
|
|
113
|
+
if (hit)
|
|
114
|
+
return { path: hit };
|
|
115
|
+
if (meta.kind === 'use' || meta.kind === 'import' || meta.kind === 'require' || meta.local === false) {
|
|
116
|
+
return { external: packageNameOf(spec) };
|
|
117
|
+
}
|
|
118
|
+
return { unresolved: spec };
|
|
131
119
|
}
|
|
120
|
+
//# sourceMappingURL=generic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic.js","sourceRoot":"","sources":["../../../src/shared/analyzer/languages/generic.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,0EAA0E;AAC1E,0EAA0E;AAC1E,+CAA+C;AAC/C,EAAE;AACF,wEAAwE;AACxE,uEAAuE;AACvE,4EAA4E;AAC5E,4BAA4B;AAE5B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE3D,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAE7E,MAAM,MAAM,GAAG;IACb,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;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K,GAAG,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,UAAU,CAAC,WAAW,GAAG,MAAM,CAAC,CAAC;QAChD,IAAI,MAAM;YAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IACtC,CAAC;IACD,MAAM,GAAG,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACvC,IAAI,GAAG;QAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAE9B,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;QACrG,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;IAC3C,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["// Generic analyzer for C/C++, Ruby, and PHP — the languages that don't have\n// a dedicated module. Java, Rust, and C# each have their own analyzer in this\n// directory and are dispatched first by `languages/index.js`; the blocks for\n// them used to live here, before they had anywhere better to go, and were\n// removed when those files landed so the dispatch table is the only place\n// that decides which family a file belongs to.\n//\n// The work this module does is deliberately cheap: a regex pass for the\n// include/import/require/use lines plus the obvious function and class\n// shapes. It is enough to place these files on the map; treating it as more\n// than that would be lying.\n\nimport { blankComments, lineCounter, uniqueBy } from '../util.js';\nimport { dirOf, joinPath, baseName } from '../pathUtil.js';\n\nexport const extensions = ['.c', '.h', '.cc', '.cpp', '.hpp', '.rb', '.php'];\n\nconst BY_EXT = {\n c: 'c', h: 'c', cc: 'c', cpp: 'c', hpp: 'c',\n rb: 'ruby', php: 'php',\n};\n\nconst CONTROL = new Set(['if', 'for', 'while', 'switch', 'catch', 'return', 'sizeof', 'do', 'else']);\n\nexport function analyze(source, path) {\n const family = BY_EXT[path.slice(path.lastIndexOf('.') + 1)] || 'c';\n const clean = blankComments(source, { lineChar: family === 'ruby' ? '#' : '//' });\n const lineAt = lineCounter(clean);\n\n const imports = [];\n const functions = [];\n const classes = [];\n\n if (family === 'c') {\n for (const m of clean.matchAll(/^[ \\t]*#[ \\t]*include[ \\t]*\"([^\"]+)\"/gm)) {\n imports.push({ spec: m[1], local: true, line: lineAt(m.index) });\n }\n for (const m of clean.matchAll(/^[ \\t]*#[ \\t]*include[ \\t]*<([^>]+)>/gm)) {\n imports.push({ spec: m[1], local: false, line: lineAt(m.index) });\n }\n for (const m of clean.matchAll(/^[A-Za-z_][\\w\\s\\*]*?\\s+([\\w]+)\\s*\\([^;{}]*\\)\\s*\\{/gm)) {\n if (!CONTROL.has(m[1])) functions.push({ name: m[1], kind: 'function', line: lineAt(m.index) });\n }\n }\n\n if (family === 'ruby') {\n for (const m of clean.matchAll(/^[ \\t]*require_relative\\s+['\"]([^'\"]+)['\"]/gm)) {\n imports.push({ spec: m[1], kind: 'require_relative', line: lineAt(m.index) });\n }\n for (const m of clean.matchAll(/^[ \\t]*require\\s+['\"]([^'\"]+)['\"]/gm)) {\n imports.push({ spec: m[1], kind: 'require', line: lineAt(m.index) });\n }\n for (const m of clean.matchAll(/^[ \\t]*def\\s+([\\w!?]+)/gm)) {\n functions.push({ name: m[1], kind: 'function', line: lineAt(m.index) });\n }\n for (const m of clean.matchAll(/^[ \\t]*(?:class|module)\\s+([\\w:]+)/gm)) {\n classes.push({ name: m[1], line: lineAt(m.index) });\n }\n }\n\n if (family === 'php') {\n for (const m of clean.matchAll(/\\b(?:require|include)(?:_once)?\\s*\\(?\\s*['\"]([^'\"]+)['\"]/g)) {\n imports.push({ spec: m[1], kind: 'require', line: lineAt(m.index) });\n }\n for (const m of clean.matchAll(/^[ \\t]*use\\s+([\\w\\\\]+)\\s*;/gm)) {\n imports.push({ spec: m[1], kind: 'use', line: lineAt(m.index) });\n }\n for (const m of clean.matchAll(/\\bfunction\\s+([\\w]+)\\s*\\(/g)) {\n functions.push({ name: m[1], kind: 'function', line: lineAt(m.index) });\n }\n for (const m of clean.matchAll(/\\bclass\\s+([\\w]+)/g)) {\n classes.push({ name: m[1], line: lineAt(m.index) });\n }\n }\n\n return {\n imports: uniqueBy(imports, (i) => i.spec + ':' + (i.kind || '')),\n exports: [],\n functions,\n classes,\n calls: [],\n hasMain: family === 'c' && /\\bint\\s+main\\s*\\(/.test(clean),\n };\n}\n\nexport function packageNameOf(spec) {\n if (spec.endsWith('.h') || spec.endsWith('.hpp')) return spec;\n return spec.split(/[.:/\\\\]/)[0] || spec;\n}\n\nexport function resolveImport(spec, fromPath, has, context: Record<string, any> = {}, meta: Record<string, any> = {}) {\n const fromDir = dirOf(fromPath);\n const { findByName = () => null } = context;\n\n // C angle-bracket includes like <stdio.h> are explicitly external\n if (meta.local === false && meta.kind !== 'mod' && meta.kind !== 'use' && meta.kind !== 'import') {\n return { external: packageNameOf(spec) };\n }\n\n const cleaned = spec.replace(/::/g, '/').replace(/\\\\/g, '/').replace(/\\./g, '/');\n const lastDot = spec.lastIndexOf('.');\n const lastSlash = Math.max(spec.lastIndexOf('/'), spec.lastIndexOf('\\\\'));\n const lastColon = spec.lastIndexOf('::');\n const lastSep = Math.max(lastDot, lastSlash, lastColon >= 0 ? lastColon + 1 : -1);\n const lastSegment = lastSep >= 0 ? spec.slice(lastSep + 1) : spec;\n\n // Only the extensions this module owns. Java/Rust have their own resolvers.\n const candidates = [\n joinPath(fromDir, spec),\n joinPath(fromDir, spec) + '.rb',\n joinPath(fromDir, cleaned) + '.rb',\n joinPath(fromDir, cleaned) + '.php',\n joinPath(fromDir, spec) + '.php',\n ];\n for (const cand of candidates) {\n if (cand && has(cand)) return { path: cand };\n }\n\n // Last resort for quoted includes: match on the file name anywhere.\n if (lastSegment && lastSegment !== '*') {\n const hitPhp = findByName(lastSegment + '.php');\n if (hitPhp) return { path: hitPhp };\n }\n const hit = findByName(baseName(spec));\n if (hit) return { path: hit };\n\n if (meta.kind === 'use' || meta.kind === 'import' || meta.kind === 'require' || meta.local === false) {\n return { external: packageNameOf(spec) };\n }\n return { unresolved: spec };\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const extensions: string[];
|
|
2
|
+
export declare function analyze(source: any, path: any): {
|
|
3
|
+
imports: any[];
|
|
4
|
+
exports: any[];
|
|
5
|
+
functions: any[];
|
|
6
|
+
classes: any[];
|
|
7
|
+
calls: any[];
|
|
8
|
+
hasMain: boolean;
|
|
9
|
+
packageName: any;
|
|
10
|
+
};
|
|
11
|
+
export declare function packageNameOf(spec: any): any;
|
|
12
|
+
export declare function resolveImport(spec: any, fromPath: any, has: any, context?: Record<string, any>): {
|
|
13
|
+
packageDir: any;
|
|
14
|
+
unresolved?: undefined;
|
|
15
|
+
external?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
packageDir?: undefined;
|
|
18
|
+
unresolved: any;
|
|
19
|
+
external?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
packageDir?: undefined;
|
|
22
|
+
unresolved?: undefined;
|
|
23
|
+
external: any;
|
|
24
|
+
};
|
|
@@ -1,70 +1,61 @@
|
|
|
1
1
|
// Go. Package-oriented: imports resolve to directories, and the scanner maps
|
|
2
2
|
// a directory to the Go files inside it.
|
|
3
|
-
|
|
4
3
|
import { blankComments, lineCounter, uniqueBy } from '../util.js';
|
|
5
|
-
|
|
6
4
|
export const extensions = ['.go'];
|
|
7
|
-
|
|
8
5
|
const IMPORT_SINGLE_RE = /^[ \t]*import\s+(?:[\w.]+\s+)?"([^"]+)"/gm;
|
|
9
6
|
const IMPORT_BLOCK_RE = /\bimport\s*\(([\s\S]*?)\)/g;
|
|
10
7
|
const QUOTED_RE = /"([^"]+)"/g;
|
|
11
8
|
const FUNC_RE = /^func\s+(?:\(([^)]*)\)\s*)?([\w]+)\s*\(/gm;
|
|
12
9
|
const PACKAGE_RE = /^package\s+([\w]+)/m;
|
|
13
|
-
|
|
14
10
|
export function analyze(source, path) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
imports.push({ spec: m[1], line: lineAt(m.index) });
|
|
21
|
-
}
|
|
22
|
-
for (const m of clean.matchAll(IMPORT_BLOCK_RE)) {
|
|
23
|
-
for (const q of m[1].matchAll(QUOTED_RE)) {
|
|
24
|
-
imports.push({ spec: q[1], line: lineAt(m.index) });
|
|
11
|
+
const clean = blankComments(source);
|
|
12
|
+
const lineAt = lineCounter(clean);
|
|
13
|
+
const imports = [];
|
|
14
|
+
for (const m of clean.matchAll(IMPORT_SINGLE_RE)) {
|
|
15
|
+
imports.push({ spec: m[1], line: lineAt(m.index) });
|
|
25
16
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
17
|
+
for (const m of clean.matchAll(IMPORT_BLOCK_RE)) {
|
|
18
|
+
for (const q of m[1].matchAll(QUOTED_RE)) {
|
|
19
|
+
imports.push({ spec: q[1], line: lineAt(m.index) });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const functions = [];
|
|
23
|
+
for (const m of clean.matchAll(FUNC_RE)) {
|
|
24
|
+
functions.push({
|
|
25
|
+
name: m[2],
|
|
26
|
+
kind: m[1] ? 'method' : 'function',
|
|
27
|
+
receiver: m[1] ? m[1].replace(/[*]/g, '').trim().split(/\s+/).pop() : undefined,
|
|
28
|
+
line: lineAt(m.index),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const pkg = (clean.match(PACKAGE_RE) || [])[1] || '';
|
|
32
|
+
const hasMain = pkg === 'main' && /^func\s+main\s*\(\s*\)/m.test(clean);
|
|
33
|
+
const exports = functions
|
|
34
|
+
.filter((f) => /^[A-Z]/.test(f.name))
|
|
35
|
+
.map((f) => ({ name: f.name, kind: f.kind }));
|
|
36
|
+
return {
|
|
37
|
+
imports: uniqueBy(imports, (i) => i.spec),
|
|
38
|
+
exports: uniqueBy(exports, (e) => e.name),
|
|
39
|
+
functions,
|
|
40
|
+
classes: [],
|
|
41
|
+
calls: [],
|
|
42
|
+
hasMain,
|
|
43
|
+
packageName: pkg,
|
|
44
|
+
};
|
|
54
45
|
}
|
|
55
|
-
|
|
56
46
|
export function packageNameOf(spec) {
|
|
57
|
-
|
|
47
|
+
return spec.split('/')[0].includes('.') ? spec.split('/').slice(0, 3).join('/') : spec.split('/')[0];
|
|
58
48
|
}
|
|
59
|
-
|
|
60
49
|
export function resolveImport(spec, fromPath, has, context = {}) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
50
|
+
const { modulePath = '', hasDir = () => false } = context;
|
|
51
|
+
if (modulePath && (spec === modulePath || spec.startsWith(modulePath + '/'))) {
|
|
52
|
+
const dir = spec.slice(modulePath.length).replace(/^\//, '');
|
|
53
|
+
if (hasDir(dir))
|
|
54
|
+
return { packageDir: dir };
|
|
55
|
+
return { unresolved: spec };
|
|
56
|
+
}
|
|
57
|
+
// Without a go.mod we guess: no dot in the first segment usually means the
|
|
58
|
+
// standard library; anything else is treated as an external module.
|
|
59
|
+
return { external: packageNameOf(spec) };
|
|
70
60
|
}
|
|
61
|
+
//# sourceMappingURL=go.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"go.js","sourceRoot":"","sources":["../../../src/shared/analyzer/languages/go.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,yCAAyC;AAEzC,OAAO,EAAE,aAA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;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAI;IAChC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACvG,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,GAAwB,EAAE;IAClF,MAAM,EAAE,UAAU,GAAG,EAAE,EAAE,MAAM,GAAG,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC;IAC1D,IAAI,UAAU,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC;QAC7E,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC7D,IAAI,MAAM,CAAC,GAAG,CAAC;YAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC;QAC5C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAC9B,CAAC;IACD,2EAA2E;IAC3E,oEAAoE;IACpE,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["// Go. Package-oriented: imports resolve to directories, and the scanner maps\n// a directory to the Go files inside it.\n\nimport { blankComments, lineCounter, uniqueBy } from '../util.js';\n\nexport const extensions = ['.go'];\n\nconst IMPORT_SINGLE_RE = /^[ \\t]*import\\s+(?:[\\w.]+\\s+)?\"([^\"]+)\"/gm;\nconst IMPORT_BLOCK_RE = /\\bimport\\s*\\(([\\s\\S]*?)\\)/g;\nconst QUOTED_RE = /\"([^\"]+)\"/g;\nconst FUNC_RE = /^func\\s+(?:\\(([^)]*)\\)\\s*)?([\\w]+)\\s*\\(/gm;\nconst PACKAGE_RE = /^package\\s+([\\w]+)/m;\n\nexport function analyze(source, path) {\n const clean = blankComments(source);\n const lineAt = lineCounter(clean);\n\n const imports = [];\n for (const m of clean.matchAll(IMPORT_SINGLE_RE)) {\n imports.push({ spec: m[1], line: lineAt(m.index) });\n }\n for (const m of clean.matchAll(IMPORT_BLOCK_RE)) {\n for (const q of m[1].matchAll(QUOTED_RE)) {\n imports.push({ spec: q[1], line: lineAt(m.index) });\n }\n }\n\n const functions = [];\n for (const m of clean.matchAll(FUNC_RE)) {\n functions.push({\n name: m[2],\n kind: m[1] ? 'method' : 'function',\n receiver: m[1] ? m[1].replace(/[*]/g, '').trim().split(/\\s+/).pop() : undefined,\n line: lineAt(m.index),\n });\n }\n\n const pkg = (clean.match(PACKAGE_RE) || [])[1] || '';\n const hasMain = pkg === 'main' && /^func\\s+main\\s*\\(\\s*\\)/m.test(clean);\n\n const exports = functions\n .filter((f) => /^[A-Z]/.test(f.name))\n .map((f) => ({ name: f.name, kind: f.kind }));\n\n return {\n imports: uniqueBy(imports, (i) => i.spec),\n exports: uniqueBy(exports, (e) => e.name),\n functions,\n classes: [],\n calls: [],\n hasMain,\n packageName: pkg,\n };\n}\n\nexport function packageNameOf(spec) {\n return spec.split('/')[0].includes('.') ? spec.split('/').slice(0, 3).join('/') : spec.split('/')[0];\n}\n\nexport function resolveImport(spec, fromPath, has, context: Record<string, any> = {}) {\n const { modulePath = '', hasDir = () => false } = context;\n if (modulePath && (spec === modulePath || spec.startsWith(modulePath + '/'))) {\n const dir = spec.slice(modulePath.length).replace(/^\\//, '');\n if (hasDir(dir)) return { packageDir: dir };\n return { unresolved: spec };\n }\n // Without a go.mod we guess: no dot in the first segment usually means the\n // standard library; anything else is treated as an external module.\n return { external: packageNameOf(spec) };\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LanguageAnalyzer } from '../../contracts.js';
|
|
2
|
+
export declare const languages: LanguageAnalyzer[];
|
|
3
|
+
export declare function languageFor(path: string): LanguageAnalyzer | null;
|
|
4
|
+
export declare function languageLabel(id: string, { short }?: {
|
|
5
|
+
short?: boolean;
|
|
6
|
+
}): string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// Language registry. Order matters: the first match on extension wins.
|
|
2
|
-
|
|
3
2
|
import * as typescript from './typescript.js';
|
|
4
3
|
import * as javascript from './javascript.js';
|
|
5
4
|
import * as python from './python.js';
|
|
@@ -8,36 +7,36 @@ import * as rust from './rust.js';
|
|
|
8
7
|
import * as java from './java.js';
|
|
9
8
|
import * as csharp from './csharp.js';
|
|
10
9
|
import * as generic from './generic.js';
|
|
11
|
-
|
|
12
10
|
export const languages = [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
{ id: 'typescript', label: 'TypeScript', short: 'TS', ...typescript },
|
|
12
|
+
{ id: 'javascript', label: 'JavaScript', short: 'JS', ...javascript },
|
|
13
|
+
{ id: 'python', label: 'Python', short: 'Python', ...python },
|
|
14
|
+
{ id: 'go', label: 'Go', short: 'Go', ...go },
|
|
15
|
+
{ id: 'rust', label: 'Rust', short: 'Rust', ...rust },
|
|
16
|
+
{ id: 'java', label: 'Java', short: 'Java', ...java },
|
|
17
|
+
{ id: 'csharp', label: 'C#', short: 'C#', ...csharp },
|
|
18
|
+
{ id: 'generic', label: 'C / Ruby / PHP', short: 'C/Ruby/…', ...generic },
|
|
21
19
|
];
|
|
22
|
-
|
|
23
20
|
const byExtension = new Map();
|
|
24
21
|
for (const lang of languages) {
|
|
25
|
-
|
|
22
|
+
for (const ext of lang.extensions)
|
|
23
|
+
byExtension.set(ext, lang);
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
export function languageFor(path) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const i = path.lastIndexOf('.');
|
|
27
|
+
if (i === -1)
|
|
28
|
+
return null;
|
|
29
|
+
return byExtension.get(path.slice(i).toLowerCase()) || null;
|
|
32
30
|
}
|
|
33
|
-
|
|
34
31
|
// Display names for a language id. Both spellings were previously hardcoded in
|
|
35
32
|
// two places that had drifted apart — a `generic` file was labelled "C/Java/…"
|
|
36
33
|
// in one panel and "C/Java/Rust/Ruby/PHP" in another. The registry already knew
|
|
37
34
|
// the answer; now it is the only one that does. An unknown id comes back as
|
|
38
35
|
// itself, so a new language shows up as a lowercase word rather than nothing.
|
|
39
36
|
export function languageLabel(id, { short = false } = {}) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
const lang = languages.find((l) => l.id === id);
|
|
38
|
+
if (!lang)
|
|
39
|
+
return String(id);
|
|
40
|
+
return short ? lang.short : lang.label;
|
|
43
41
|
}
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shared/analyzer/languages/index.ts"],"names":[],"mappings":"AACA,uEAAuE;AAEvE,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,SAAS,GAAuB;IAC3C,EAAE,EAAE,EAAE,YAAY,E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,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,IAAI,CAAC;AAC9D,CAAC;AAED,+EAA+E;AAC/E,+EAA+E;AAC/E,gFAAgF;AAChF,4EAA4E;AAC5E,8EAA8E;AAC9E,MAAM,UAAU,aAAa,CAAC,EAAU,EAAE,EAAE,KAAK,GAAG,KAAK,EAAE,GAAwB,EAAE;IACnF,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAChD,IAAI,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC;IAC7B,OAAO,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;AACzC,CAAC","sourcesContent":["import type { LanguageAnalyzer } from '../../contracts.js';\n// Language registry. Order matters: the first match on extension wins.\n\nimport * as typescript from './typescript.js';\nimport * as javascript from './javascript.js';\nimport * as python from './python.js';\nimport * as go from './go.js';\nimport * as rust from './rust.js';\nimport * as java from './java.js';\nimport * as csharp from './csharp.js';\nimport * as generic from './generic.js';\n\nexport const languages: LanguageAnalyzer[] = [\n { id: 'typescript', label: 'TypeScript', short: 'TS', ...typescript },\n { id: 'javascript', label: 'JavaScript', short: 'JS', ...javascript },\n { id: 'python', label: 'Python', short: 'Python', ...python },\n { id: 'go', label: 'Go', short: 'Go', ...go },\n { id: 'rust', label: 'Rust', short: 'Rust', ...rust },\n { id: 'java', label: 'Java', short: 'Java', ...java },\n { id: 'csharp', label: 'C#', short: 'C#', ...csharp },\n { id: 'generic', label: 'C / Ruby / PHP', short: 'C/Ruby/…', ...generic },\n];\n\nconst byExtension = new Map<string, LanguageAnalyzer>();\nfor (const lang of languages) {\n for (const ext of lang.extensions) byExtension.set(ext, lang);\n}\n\nexport function languageFor(path: string): LanguageAnalyzer | null {\n const i = path.lastIndexOf('.');\n if (i === -1) return null;\n return byExtension.get(path.slice(i).toLowerCase()) || null;\n}\n\n// Display names for a language id. Both spellings were previously hardcoded in\n// two places that had drifted apart — a `generic` file was labelled \"C/Java/…\"\n// in one panel and \"C/Java/Rust/Ruby/PHP\" in another. The registry already knew\n// the answer; now it is the only one that does. An unknown id comes back as\n// itself, so a new language shows up as a lowercase word rather than nothing.\nexport function languageLabel(id: string, { short = false }: { short?: boolean } = {}): string {\n const lang = languages.find((l) => l.id === id);\n if (!lang) return String(id);\n return short ? lang.short : lang.label;\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const extensions: string[];
|
|
2
|
+
export declare function analyze(source: any, path: any): {
|
|
3
|
+
imports: any[];
|
|
4
|
+
exports: {
|
|
5
|
+
name: any;
|
|
6
|
+
kind: string;
|
|
7
|
+
}[];
|
|
8
|
+
functions: any[];
|
|
9
|
+
classes: any[];
|
|
10
|
+
hasMain: boolean;
|
|
11
|
+
packageName: any;
|
|
12
|
+
};
|
|
13
|
+
export declare function sourceRootFor(fromPath: any, packageName: any): string;
|
|
14
|
+
export declare function resolveImport(spec: any, fromPath: any, has: any, context?: Record<string, any>, meta?: Record<string, any>): {
|
|
15
|
+
unresolved: any;
|
|
16
|
+
path?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
unresolved?: undefined;
|
|
19
|
+
path: any;
|
|
20
|
+
};
|