@eagleoutice/flowr 2.11.0 → 2.12.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 +190 -260
- package/abstract-interpretation/data-frame/mappers/arguments.js +7 -1
- package/abstract-interpretation/domains/set-range-domain.js +1 -1
- package/abstract-interpretation/domains/set-upper-bound-domain.js +6 -2
- package/benchmark/slicer.d.ts +1 -1
- package/benchmark/slicer.js +3 -1
- package/benchmark/summarizer/second-phase/graph.js +5 -0
- package/cli/common/options.d.ts +8 -0
- package/cli/common/options.js +2 -0
- package/cli/common/scripts-info.d.ts +8 -0
- package/cli/flowr.js +1 -1
- package/cli/repl/commands/repl-commands.d.ts +1 -0
- package/cli/repl/commands/repl-commands.js +69 -17
- package/cli/repl/commands/repl-dataflow.js +48 -4
- package/cli/repl/commands/repl-main.d.ts +2 -0
- package/cli/repl/commands/repl-main.js +5 -0
- package/cli/repl/commands/repl-query.d.ts +4 -1
- package/cli/repl/commands/repl-query.js +72 -22
- package/cli/repl/commands/repl-signature.d.ts +7 -0
- package/cli/repl/commands/repl-signature.js +119 -0
- package/cli/repl/core.d.ts +8 -1
- package/cli/repl/core.js +46 -6
- package/cli/repl/ghost-hint.d.ts +37 -0
- package/cli/repl/ghost-hint.js +72 -0
- package/cli/repl/parser/slice-query-parser.d.ts +11 -1
- package/cli/repl/parser/slice-query-parser.js +45 -16
- package/cli/repl/print-version.d.ts +2 -4
- package/cli/repl/print-version.js +41 -23
- package/cli/repl/server/connection.js +19 -17
- package/cli/slicer-app.d.ts +2 -0
- package/cli/slicer-app.js +3 -3
- package/cli/wiki.d.ts +2 -2
- package/cli/wiki.js +2 -2
- package/config.d.ts +70 -13
- package/config.js +65 -7
- package/control-flow/cfg-dead-code.js +0 -1
- package/control-flow/control-flow-graph.js +6 -6
- package/control-flow/diff-cfg.js +2 -2
- package/control-flow/semantic-cfg-guided-visitor.js +2 -0
- package/core/print/slice-diff-ansi.js +8 -8
- package/core/steps/all/core/20-dataflow.d.ts +2 -2
- package/core/steps/all/static-slicing/00-slice.d.ts +5 -0
- package/core/steps/all/static-slicing/00-slice.js +1 -1
- package/core/steps/all/static-slicing/10-reconstruct.d.ts +7 -0
- package/core/steps/all/static-slicing/10-reconstruct.js +6 -2
- package/core/steps/pipeline/default-pipelines.d.ts +20 -16
- package/data/r-base-packages.generated.d.ts +44 -0
- package/data/r-base-packages.generated.js +32 -0
- package/data/r-base-primitives.generated.d.ts +1 -0
- package/data/r-base-primitives.generated.js +15 -0
- package/data/sigdb/sigdb.remote.json +112 -0
- package/dataflow/environments/built-in-proc-name.d.ts +4 -0
- package/dataflow/environments/built-in-proc-name.js +4 -0
- package/dataflow/environments/built-in.d.ts +14 -4
- package/dataflow/environments/built-in.js +13 -2
- package/dataflow/environments/data-masking-functions.d.ts +12 -0
- package/dataflow/environments/data-masking-functions.js +46 -0
- package/dataflow/environments/default-builtin-config.d.ts +72 -19
- package/dataflow/environments/default-builtin-config.js +48 -14
- package/dataflow/environments/diff.js +1 -1
- package/dataflow/environments/environment.js +1 -2
- package/dataflow/environments/identifier.d.ts +11 -4
- package/dataflow/environments/identifier.js +28 -10
- package/dataflow/environments/resolve-by-name.js +16 -2
- package/dataflow/extractor.js +6 -3
- package/dataflow/graph/call-graph.d.ts +2 -2
- package/dataflow/graph/df-helper.d.ts +4 -4
- package/dataflow/graph/diff-dataflow-graph.js +2 -2
- package/dataflow/graph/edge.d.ts +3 -3
- package/dataflow/graph/edge.js +3 -3
- package/dataflow/graph/graph-helper.d.ts +2 -2
- package/dataflow/internal/linker.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +7 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +20 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +1 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +2 -49
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +7 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +111 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +13 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +2 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +9 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +12 -4
- package/dataflow/internal/process/functions/call/common.js +8 -1
- package/dataflow/internal/process/functions/call/default-call-handling.js +6 -0
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +17 -0
- package/dataflow/internal/process/functions/call/known-call-handling.js +32 -0
- package/dataflow/internal/process/functions/call/named-call-handling.js +29 -7
- package/dataflow/internal/process/functions/process-argument.js +12 -1
- package/dataflow/internal/process/process-named-call.d.ts +18 -1
- package/dataflow/internal/process/process-named-call.js +94 -0
- package/dataflow/processor.d.ts +18 -0
- package/documentation/data/faq/faqs.js +5 -1
- package/documentation/doc-capabilities.js +1 -1
- package/documentation/doc-util/doc-cli-option.d.ts +10 -0
- package/documentation/doc-util/doc-cli-option.js +23 -0
- package/documentation/doc-util/doc-dfg.js +2 -1
- package/documentation/doc-util/doc-query.d.ts +9 -3
- package/documentation/doc-util/doc-query.js +9 -4
- package/documentation/wiki-dataflow-graph.js +8 -5
- package/documentation/wiki-interface.js +3 -2
- package/documentation/wiki-linter.js +1 -1
- package/documentation/wiki-linting-and-testing.js +4 -1
- package/documentation/wiki-mk/doc-context.d.ts +14 -0
- package/documentation/wiki-mk/doc-context.js +3 -0
- package/documentation/wiki-mk/doc-maker.js +3 -1
- package/documentation/wiki-query.js +19 -1
- package/documentation/wiki-setup.js +10 -7
- package/documentation/wiki-signature-database.d.ts +16 -0
- package/documentation/wiki-signature-database.js +293 -0
- package/linter/linter-format.d.ts +7 -0
- package/linter/linter-rules.d.ts +10 -9
- package/linter/rules/naming-convention.d.ts +1 -0
- package/linter/rules/naming-convention.js +2 -0
- package/linter/rules/no-leaked-credentials.js +1 -2
- package/linter/rules/roxygen-arguments.js +18 -5
- package/linter/rules/stop-with-call-arg.js +2 -2
- package/linter/rules/undefined-symbol-util.d.ts +36 -0
- package/linter/rules/undefined-symbol-util.js +149 -0
- package/linter/rules/undefined-symbol.d.ts +58 -17
- package/linter/rules/undefined-symbol.js +143 -33
- package/linter/rules/unused-definition.d.ts +8 -1
- package/linter/rules/unused-definition.js +126 -1
- package/package.json +23 -10
- package/project/context/abstract-flowr-analyzer-context.js +7 -1
- package/project/context/flowr-analyzer-context.d.ts +8 -0
- package/project/context/flowr-analyzer-context.js +10 -0
- package/project/context/flowr-analyzer-dependencies-context.d.ts +28 -4
- package/project/context/flowr-analyzer-dependencies-context.js +53 -1
- package/project/context/flowr-analyzer-files-context.d.ts +1 -0
- package/project/context/flowr-analyzer-files-context.js +2 -1
- package/project/context/flowr-analyzer-functions-context.js +1 -1
- package/project/context/flowr-file.d.ts +5 -0
- package/project/context/flowr-file.js +5 -0
- package/project/flowr-analyzer-builder.js +12 -2
- package/project/plugins/file-plugins/files/flowr-description-file.js +6 -3
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +9 -3
- package/project/plugins/file-plugins/files/flowr-news-file.js +1 -3
- package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.d.ts +26 -0
- package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.js +39 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +1 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +1 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +18 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +19 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +120 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +518 -0
- package/project/plugins/package-version-plugins/package.d.ts +5 -3
- package/project/plugins/package-version-plugins/package.js +27 -25
- package/project/plugins/plugin-registry.d.ts +3 -2
- package/project/plugins/plugin-registry.js +4 -2
- package/project/plugins/project-discovery/flowr-analyzer-gitignore-project-discovery-plugin.js +7 -2
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +3 -1
- package/project/sigdb/build.d.ts +131 -0
- package/project/sigdb/build.js +628 -0
- package/project/sigdb/codec.d.ts +51 -0
- package/project/sigdb/codec.js +122 -0
- package/project/sigdb/decode.d.ts +58 -0
- package/project/sigdb/decode.js +129 -0
- package/project/sigdb/decompress.d.ts +44 -0
- package/project/sigdb/decompress.js +176 -0
- package/project/sigdb/hash.d.ts +9 -0
- package/project/sigdb/hash.js +54 -0
- package/project/sigdb/index-format.d.ts +40 -0
- package/project/sigdb/index-format.js +28 -0
- package/project/sigdb/manifest.d.ts +68 -0
- package/project/sigdb/manifest.js +146 -0
- package/project/sigdb/reader.d.ts +250 -0
- package/project/sigdb/reader.js +692 -0
- package/project/sigdb/schema.d.ts +196 -0
- package/project/sigdb/schema.js +33 -0
- package/project/sigdb/sigdb-download.d.ts +65 -0
- package/project/sigdb/sigdb-download.js +237 -0
- package/project/sigdb/signature-match.d.ts +26 -0
- package/project/sigdb/signature-match.js +40 -0
- package/project/sigdb/version.d.ts +20 -0
- package/project/sigdb/version.js +55 -0
- package/queries/catalog/call-context-query/call-context-query-executor.js +1 -3
- package/queries/catalog/config-query/config-query-format.d.ts +3 -1
- package/queries/catalog/config-query/config-query-format.js +68 -9
- package/queries/catalog/dataflow-query/dataflow-query-format.js +11 -1
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +1 -1
- package/queries/catalog/linter-query/linter-query-executor.d.ts +2 -0
- package/queries/catalog/linter-query/linter-query-executor.js +6 -1
- package/queries/catalog/linter-query/linter-query-format.d.ts +2 -1
- package/queries/catalog/linter-query/linter-query-format.js +40 -8
- package/queries/catalog/project-query/project-query-executor.d.ts +15 -0
- package/queries/catalog/project-query/project-query-executor.js +96 -4
- package/queries/catalog/project-query/project-query-format.d.ts +44 -0
- package/queries/catalog/project-query/project-query-format.js +33 -2
- package/queries/catalog/signature-query/signature-query-executor.d.ts +29 -0
- package/queries/catalog/signature-query/signature-query-executor.js +461 -0
- package/queries/catalog/signature-query/signature-query-format.d.ts +138 -0
- package/queries/catalog/signature-query/signature-query-format.js +76 -0
- package/queries/catalog/signature-query/signature-query-render.d.ts +15 -0
- package/queries/catalog/signature-query/signature-query-render.js +155 -0
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +9 -3
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +10 -0
- package/queries/catalog/static-slice-query/static-slice-query-format.js +19 -1
- package/queries/query-print.js +5 -0
- package/queries/query.d.ts +10 -1
- package/queries/query.js +5 -2
- package/r-bridge/init.js +5 -1
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +10 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +55 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +16 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +27 -0
- package/r-bridge/lang-4.x/ast/parser/json/format.js +89 -2
- package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +2 -4
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +2 -1
- package/r-bridge/parser.d.ts +2 -0
- package/r-bridge/retriever.js +4 -1
- package/r-bridge/roxygen2/documentation-provider.js +2 -1
- package/r-bridge/shell.d.ts +5 -0
- package/r-bridge/shell.js +17 -1
- package/reconstruct/inline/source-inline-map.d.ts +48 -0
- package/reconstruct/inline/source-inline-map.js +94 -0
- package/reconstruct/reconstruct.d.ts +19 -2
- package/reconstruct/reconstruct.js +79 -16
- package/search/search-executor/search-generators.js +5 -22
- package/search/search-executor/search-transformer.js +10 -6
- package/slicing/criterion/parse.d.ts +22 -4
- package/slicing/criterion/parse.js +125 -18
- package/slicing/static/slice-call.d.ts +24 -1
- package/slicing/static/slice-call.js +90 -0
- package/slicing/static/static-slicer.d.ts +7 -0
- package/slicing/static/static-slicer.js +38 -3
- package/util/collections/arrays.d.ts +4 -5
- package/util/collections/arrays.js +7 -18
- package/util/hash.d.ts +14 -0
- package/util/hash.js +31 -0
- package/util/mermaid/dfg.d.ts +7 -2
- package/util/mermaid/dfg.js +53 -13
- package/util/r-base-packages.d.ts +19 -0
- package/util/r-base-packages.js +72 -0
- package/util/r-license.js +2 -10
- package/util/r-version.d.ts +45 -15
- package/util/r-version.js +97 -36
- package/util/range.d.ts +15 -0
- package/util/range.js +39 -0
- package/util/schema.d.ts +10 -0
- package/util/schema.js +22 -0
- package/util/text/ansi.d.ts +13 -1
- package/util/text/ansi.js +27 -4
- package/util/text/args.js +1 -2
- package/util/version.js +28 -8
- package/data/pkgdb/pkgdb-latest.json.br +0 -0
- package/data/pkgdb/pkgdb-tiny.json.br +0 -0
- package/documentation/wiki-package-database.d.ts +0 -9
- package/documentation/wiki-package-database.js +0 -63
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.d.ts +0 -63
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js +0 -174
- package/project/plugins/package-version-plugins/pkgdb.d.ts +0 -133
- package/project/plugins/package-version-plugins/pkgdb.js +0 -370
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dayToMillis = dayToMillis;
|
|
4
|
+
exports.releasesOf = releasesOf;
|
|
5
|
+
exports.newestVersion = newestVersion;
|
|
6
|
+
exports.resolveVersion = resolveVersion;
|
|
7
|
+
/**
|
|
8
|
+
* Version/date resolution over a {@link PkgBlob}: parsing stored version strings into comparable
|
|
9
|
+
* {@link RVersion}s, decoding the day-granularity release dates, and picking the effective version for a query.
|
|
10
|
+
* Split out of `../sigdb` so the reader/writer there stays focused on the byte format.
|
|
11
|
+
*/
|
|
12
|
+
const r_version_1 = require("../../util/r-version");
|
|
13
|
+
/** milliseconds since the Unix epoch for a stored day count (dates are stored at day granularity to save space) */
|
|
14
|
+
function dayToMillis(day) {
|
|
15
|
+
return day * 86_400_000;
|
|
16
|
+
}
|
|
17
|
+
/** the known releases of a blob, ascending by R-version order (empty when no dates were stored) */
|
|
18
|
+
function releasesOf(blob) {
|
|
19
|
+
if (!blob) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
return Object.entries(blob.dates)
|
|
23
|
+
.map(([ver, day]) => ({ version: r_version_1.RVersion.parseOrZero(ver), date: new Date(dayToMillis(day)) }))
|
|
24
|
+
.sort((a, b) => r_version_1.RVersion.compare(a.version.str, b.version.str));
|
|
25
|
+
}
|
|
26
|
+
/** the version with the newest release date (falling back to `latest`, then the highest by R-version order) */
|
|
27
|
+
function newestVersion(blob, latest) {
|
|
28
|
+
let best;
|
|
29
|
+
let bestDay = -Infinity;
|
|
30
|
+
for (const [ver, day] of Object.entries(blob.dates)) {
|
|
31
|
+
if (day > bestDay) {
|
|
32
|
+
bestDay = day;
|
|
33
|
+
best = ver;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (best !== undefined) {
|
|
37
|
+
return best;
|
|
38
|
+
}
|
|
39
|
+
if (blob.versions[latest]) {
|
|
40
|
+
return latest;
|
|
41
|
+
}
|
|
42
|
+
// no dates and no recorded latest: pick the highest by R's numeric-version order (not string order)
|
|
43
|
+
return r_version_1.RVersion.highest(Object.keys(blob.versions));
|
|
44
|
+
}
|
|
45
|
+
/** pick the version tuple: requested, else the package's latest, else the highest present by R-version order */
|
|
46
|
+
function resolveVersion(blob, latest, version) {
|
|
47
|
+
if (version && blob.versions[version]) {
|
|
48
|
+
return version;
|
|
49
|
+
}
|
|
50
|
+
if (blob.versions[latest]) {
|
|
51
|
+
return latest;
|
|
52
|
+
}
|
|
53
|
+
return r_version_1.RVersion.highest(Object.keys(blob.versions));
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -30,7 +30,6 @@ function makeReport(collector) {
|
|
|
30
30
|
if (!Array.isArray(subkinds[subkind])) {
|
|
31
31
|
subkinds[subkind] = [];
|
|
32
32
|
}
|
|
33
|
-
subkinds[subkind] ??= [];
|
|
34
33
|
const collectIn = subkinds[subkind];
|
|
35
34
|
for (const value of values) {
|
|
36
35
|
collectIn.push(value);
|
|
@@ -288,8 +287,7 @@ async function executeCallContextQueries({ analyzer }, queries) {
|
|
|
288
287
|
}
|
|
289
288
|
}
|
|
290
289
|
if (query.callTargetNamespace !== undefined) {
|
|
291
|
-
|
|
292
|
-
const pkg = identifier_1.Identifier.getNamespace(identifier_1.Identifier.toQualified((0, dfg_get_origin_1.getOriginInDfg)(dataflow.graph, nodeId)) ?? info.name);
|
|
290
|
+
const pkg = identifier_1.Identifier.getNamespace(identifier_1.Identifier.toQualified((0, dfg_get_origin_1.getOriginInDfg)(dataflow.graph, nodeId), info.name) ?? info.name);
|
|
293
291
|
if (pkg !== query.callTargetNamespace) {
|
|
294
292
|
continue;
|
|
295
293
|
}
|
|
@@ -2,7 +2,7 @@ import type { BaseQueryFormat, BaseQueryResult } from '../../base-query-format';
|
|
|
2
2
|
import { executeConfigQuery } from './config-query-executor';
|
|
3
3
|
import { type OutputFormatter } from '../../../util/text/ansi';
|
|
4
4
|
import Joi from 'joi';
|
|
5
|
-
import
|
|
5
|
+
import { FlowrConfig } from '../../../config';
|
|
6
6
|
import type { DeepPartial } from 'ts-essentials';
|
|
7
7
|
import type { ParsedQueryLine, Query } from '../../query';
|
|
8
8
|
import type { ReplOutput } from '../../../cli/repl/commands/repl-main';
|
|
@@ -10,6 +10,8 @@ import type { CommandCompletions } from '../../../cli/repl/core';
|
|
|
10
10
|
export interface ConfigQuery extends BaseQueryFormat {
|
|
11
11
|
readonly type: 'config';
|
|
12
12
|
readonly update?: DeepPartial<FlowrConfig>;
|
|
13
|
+
/** a `.`-separated path to inspect (read) a single config value instead of dumping the whole config (repl: `?path`) */
|
|
14
|
+
readonly inspect?: readonly string[];
|
|
13
15
|
}
|
|
14
16
|
export interface ConfigQueryResult extends BaseQueryResult {
|
|
15
17
|
readonly config: FlowrConfig;
|
|
@@ -8,19 +8,32 @@ const config_query_executor_1 = require("./config-query-executor");
|
|
|
8
8
|
const ansi_1 = require("../../../util/text/ansi");
|
|
9
9
|
const time_1 = require("../../../util/text/time");
|
|
10
10
|
const joi_1 = __importDefault(require("joi"));
|
|
11
|
+
const config_1 = require("../../../config");
|
|
11
12
|
const json_1 = require("../../../util/json");
|
|
13
|
+
const schema_1 = require("../../../util/schema");
|
|
12
14
|
function configReplCompleter(partialLine, _startingNewArg, config) {
|
|
13
15
|
if (partialLine.length === 0) {
|
|
14
|
-
//
|
|
15
|
-
return { completions: ['+'] };
|
|
16
|
+
// `+` updates a field, `?` inspects (reads) one
|
|
17
|
+
return { completions: ['+', '?'] };
|
|
16
18
|
}
|
|
17
|
-
else if (partialLine.length === 1 && partialLine[0].startsWith('+')) {
|
|
18
|
-
const
|
|
19
|
+
else if (partialLine.length === 1 && (partialLine[0].startsWith('+') || partialLine[0].startsWith('?'))) {
|
|
20
|
+
const inspect = partialLine[0].startsWith('?'); // a read: complete the key path, but never append `=`
|
|
21
|
+
const raw = partialLine[0].slice(1);
|
|
22
|
+
// once a value is being assigned (`key=...`), the path is fixed: complete the value (its type), not more keys
|
|
23
|
+
if (raw.includes('=')) {
|
|
24
|
+
if (inspect) {
|
|
25
|
+
return { completions: [] }; // `?` reads a value, it never assigns one
|
|
26
|
+
}
|
|
27
|
+
const eq = raw.indexOf('=');
|
|
28
|
+
const keyPath = raw.slice(0, eq).split('.').filter(p => p.length > 0);
|
|
29
|
+
const valuePart = raw.slice(eq + 1);
|
|
30
|
+
const prefix = `${partialLine[0].slice(0, 1)}${raw.slice(0, eq)}=`;
|
|
31
|
+
const values = configValueHints(configSchemaInfo(keyPath)).filter(v => v.startsWith(valuePart) && v !== valuePart);
|
|
32
|
+
return { completions: values.map(v => prefix + v) };
|
|
33
|
+
}
|
|
34
|
+
const path = raw.split('.').filter(p => p.length > 0);
|
|
19
35
|
const fullPath = path.slice();
|
|
20
36
|
const lastPath = partialLine[0].endsWith('.') ? '' : path.pop() ?? '';
|
|
21
|
-
if (lastPath.endsWith('=')) {
|
|
22
|
-
return { completions: [] };
|
|
23
|
-
}
|
|
24
37
|
const subConfig = path.reduce((obj, key) => (obj && obj[key] !== undefined && typeof obj[key] === 'object') ? obj[key] : obj, config);
|
|
25
38
|
if (subConfig && !(subConfig[lastPath] !== undefined && typeof subConfig[lastPath] !== 'object')) {
|
|
26
39
|
const have = Object.keys(subConfig)
|
|
@@ -33,11 +46,28 @@ function configReplCompleter(partialLine, _startingNewArg, config) {
|
|
|
33
46
|
return { completions: [`${partialLine[0].slice(0, 1)}${fullPath.join('.')}.`] };
|
|
34
47
|
}
|
|
35
48
|
}
|
|
36
|
-
|
|
49
|
+
const leaf = `${partialLine[0].slice(0, 1)}${fullPath.join('.')}`;
|
|
50
|
+
if (!inspect) {
|
|
51
|
+
const values = configValueHints(configSchemaInfo(fullPath)); // a boolean/enum offers its values, others a `<type>` hint
|
|
52
|
+
if (values.length > 0) {
|
|
53
|
+
return { completions: values.map(v => `${leaf}=${v}`) };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { completions: [`${leaf}${inspect ? '' : '='}`] };
|
|
37
57
|
}
|
|
38
58
|
return { completions: [] };
|
|
39
59
|
}
|
|
40
60
|
function configQueryLineParser(output, line, _config) {
|
|
61
|
+
if (line.length > 0 && line[0].startsWith('?')) {
|
|
62
|
+
// inspect a single key, e.g. `?solver.sigdb.enabled`
|
|
63
|
+
const path = line[0].slice(1).split('.').filter(p => p.length > 0);
|
|
64
|
+
if (path.length === 0) {
|
|
65
|
+
output.stdout(`Invalid config inspect syntax, must be of the form ${(0, ansi_1.bold)('?path.to.field', output.formatter)}`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return { query: [{ type: 'config', inspect: path }] };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
41
71
|
if (line.length > 0 && line[0].startsWith('+')) {
|
|
42
72
|
const [pathPart, ...valueParts] = line[0].slice(1).split('=');
|
|
43
73
|
// build the update object
|
|
@@ -100,12 +130,29 @@ function getValueAtPath(obj, path) {
|
|
|
100
130
|
}
|
|
101
131
|
return current;
|
|
102
132
|
}
|
|
133
|
+
let configSchemaDescription;
|
|
134
|
+
/** the Joi-schema type + description of a config path (from {@link FlowrConfig.Schema}), used to document a `?key` inspection */
|
|
135
|
+
function configSchemaInfo(path) {
|
|
136
|
+
configSchemaDescription ??= config_1.FlowrConfig.Schema.describe();
|
|
137
|
+
return (0, schema_1.descriptionPathInfo)(configSchemaDescription, path);
|
|
138
|
+
}
|
|
139
|
+
/** value completions for a config leaf: both booleans, an enum's members, or a compact `<type>` hint */
|
|
140
|
+
function configValueHints(info) {
|
|
141
|
+
if (info.type === 'boolean') {
|
|
142
|
+
return ['true', 'false'];
|
|
143
|
+
}
|
|
144
|
+
if (info.valids && info.valids.length > 0) {
|
|
145
|
+
return info.valids.map(v => JSON.stringify(v));
|
|
146
|
+
}
|
|
147
|
+
return info.type ? [`<${info.type}>`] : [];
|
|
148
|
+
}
|
|
103
149
|
exports.ConfigQueryDefinition = {
|
|
104
150
|
executor: config_query_executor_1.executeConfigQuery,
|
|
105
151
|
asciiSummarizer: (formatter, _analyzer, queryResults, result, queries) => {
|
|
106
152
|
const out = queryResults;
|
|
107
153
|
result.push(`Query: ${(0, ansi_1.bold)('config', formatter)} (${(0, time_1.printAsMs)(out['.meta'].timing, 0)})`);
|
|
108
154
|
const configQueries = queries.filter(q => q.type === 'config');
|
|
155
|
+
const inspects = configQueries.filter(q => q.inspect).map(q => q.inspect);
|
|
109
156
|
if (configQueries.some(q => q.update)) {
|
|
110
157
|
const updatedKeys = configQueries.flatMap(q => q.update ? collectKeysFromUpdate(q.update) : []);
|
|
111
158
|
result.push(' ╰ Updated configuration:');
|
|
@@ -115,6 +162,17 @@ exports.ConfigQueryDefinition = {
|
|
|
115
162
|
result.push(` - ${key}: ${JSON.stringify(newValue, json_1.jsonReplacer)}`);
|
|
116
163
|
}
|
|
117
164
|
}
|
|
165
|
+
else if (inspects.length > 0) {
|
|
166
|
+
result.push(' ╰ Config:');
|
|
167
|
+
for (const path of inspects) {
|
|
168
|
+
const info = configSchemaInfo(path);
|
|
169
|
+
const value = JSON.stringify(getValueAtPath(out.config, [...path]), json_1.jsonReplacer);
|
|
170
|
+
result.push(` - ${path.join('.')}${info.type ? ` ${(0, ansi_1.italic)(`(${info.type})`, formatter)}` : ''}: ${value}`);
|
|
171
|
+
if (info.description) {
|
|
172
|
+
result.push(` ${(0, ansi_1.italic)(info.description, formatter)}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
118
176
|
else {
|
|
119
177
|
result.push(` ╰ Config:\n${JSON.stringify(out.config, json_1.jsonReplacer, 4)}`);
|
|
120
178
|
}
|
|
@@ -124,7 +182,8 @@ exports.ConfigQueryDefinition = {
|
|
|
124
182
|
fromLine: configQueryLineParser,
|
|
125
183
|
schema: joi_1.default.object({
|
|
126
184
|
type: joi_1.default.string().valid('config').required().description('The type of the query.'),
|
|
127
|
-
update: joi_1.default.object().optional().description('An optional partial configuration to update the current configuration with before returning it. Only the provided fields will be updated, all other fields will remain unchanged.')
|
|
185
|
+
update: joi_1.default.object().optional().description('An optional partial configuration to update the current configuration with before returning it. Only the provided fields will be updated, all other fields will remain unchanged.'),
|
|
186
|
+
inspect: joi_1.default.array().items(joi_1.default.string()).optional().description('An optional `.`-separated path (as a string array) to read a single configuration value instead of returning the whole configuration.')
|
|
128
187
|
}).description('The config query retrieves the current configuration of the flowR instance and optionally also updates it.'),
|
|
129
188
|
flattenInvolvedNodes: () => []
|
|
130
189
|
};
|
|
@@ -9,12 +9,22 @@ const ansi_1 = require("../../../util/text/ansi");
|
|
|
9
9
|
const time_1 = require("../../../util/text/time");
|
|
10
10
|
const joi_1 = __importDefault(require("joi"));
|
|
11
11
|
const df_helper_1 = require("../../../dataflow/graph/df-helper");
|
|
12
|
+
/** Above this many characters, the mermaid.live link is dropped from the REPL output (large graphs produce megabyte-sized base64 urls). */
|
|
13
|
+
const MaxMermaidUrlLength = 8000;
|
|
12
14
|
exports.DataflowQueryDefinition = {
|
|
13
15
|
executor: dataflow_query_executor_1.executeDataflowQuery,
|
|
14
16
|
asciiSummarizer: (formatter, _analyzer, queryResults, result) => {
|
|
15
17
|
const out = queryResults;
|
|
16
18
|
result.push(`Query: ${(0, ansi_1.bold)('dataflow', formatter)} (${(0, time_1.printAsMs)(out['.meta'].timing, 0)})`);
|
|
17
|
-
|
|
19
|
+
const url = df_helper_1.Dataflow.visualize.mermaid.url(out.graph);
|
|
20
|
+
if (url.length <= MaxMermaidUrlLength) {
|
|
21
|
+
result.push(` ╰ [Dataflow Graph](${url})`);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const vertices = Array.from(out.graph.vertices(true)).length;
|
|
25
|
+
const edges = Array.from(out.graph.edges()).length;
|
|
26
|
+
result.push(` ╰ Dataflow Graph too large to link (${vertices} vertices, ${edges} edges, url would be ${url.length} chars); use ':df#' for more detail.`);
|
|
27
|
+
}
|
|
18
28
|
return true;
|
|
19
29
|
},
|
|
20
30
|
schema: joi_1.default.object({
|
|
@@ -51,7 +51,7 @@ async function executeDependenciesQuery({ analyzer, }, queries) {
|
|
|
51
51
|
functions.set(category, getFunctionsToCheck(undefined, category, undefined, false, value.functions));
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
const queryResults = functions.values().toArray().
|
|
54
|
+
const queryResults = !functions.values().toArray().some(f => f.length > 0) ? { kinds: {}, '.meta': { timing: 0 } } :
|
|
55
55
|
await (0, query_1.executeQueriesOfSameType)(data, functions.entries().flatMap(makeCallContextQuery).toArray());
|
|
56
56
|
const g = (0, dependencies_query_format_1.getAllCategories)(queries);
|
|
57
57
|
const enabled = query.enabledCategories;
|
|
@@ -2,6 +2,8 @@ import type { BasicQueryData } from '../../base-query-format';
|
|
|
2
2
|
import type { LinterQuery, LinterQueryResult } from './linter-query-format';
|
|
3
3
|
/**
|
|
4
4
|
* Executes the given linter queries using the provided analyzer.
|
|
5
|
+
* A query without an explicit rule list runs only the rules that are active by default.
|
|
5
6
|
* @see {@link executeLintingRule}
|
|
7
|
+
* @see {@link LinterRuleInformation#activeByDefault} - opts a rule out of the default rule set
|
|
6
8
|
*/
|
|
7
9
|
export declare function executeLinterQuery({ analyzer }: BasicQueryData, queries: readonly LinterQuery[]): Promise<LinterQueryResult>;
|
|
@@ -7,10 +7,15 @@ const linter_executor_1 = require("../../../linter/linter-executor");
|
|
|
7
7
|
const gas_1 = require("../../../gas");
|
|
8
8
|
/**
|
|
9
9
|
* Executes the given linter queries using the provided analyzer.
|
|
10
|
+
* A query without an explicit rule list runs only the rules that are active by default.
|
|
10
11
|
* @see {@link executeLintingRule}
|
|
12
|
+
* @see {@link LinterRuleInformation#activeByDefault} - opts a rule out of the default rule set
|
|
11
13
|
*/
|
|
12
14
|
async function executeLinterQuery({ analyzer }, queries) {
|
|
13
|
-
|
|
15
|
+
// no explicit rules: run only the rules that opt in via activeByDefault (default true)
|
|
16
|
+
const defaultRules = Object.keys(linter_rules_1.LintingRules)
|
|
17
|
+
.filter((name) => linter_rules_1.LintingRules[name].info.activeByDefault !== false);
|
|
18
|
+
const flattened = queries.flatMap(q => q.rules ?? defaultRules);
|
|
14
19
|
const distinct = new Set(flattened);
|
|
15
20
|
if (distinct.size !== flattened.length) {
|
|
16
21
|
const pretty = [...distinct].filter(r => flattened.indexOf(r) !== flattened.lastIndexOf(r)).map(r => typeof r === 'string' ? r : r.name).join(', ');
|
|
@@ -4,6 +4,7 @@ import Joi from 'joi';
|
|
|
4
4
|
import { executeLinterQuery } from './linter-query-executor';
|
|
5
5
|
import { type LintingRuleNames } from '../../../linter/linter-rules';
|
|
6
6
|
import { type ConfiguredLintingRule, LintingResultCertainty, LintingResults } from '../../../linter/linter-format';
|
|
7
|
+
import { type OutputFormatter } from '../../../util/text/ansi';
|
|
7
8
|
import type { FlowrConfig } from '../../../config';
|
|
8
9
|
import type { ReplOutput } from '../../../cli/repl/commands/repl-main';
|
|
9
10
|
import type { CommandCompletions } from '../../../cli/repl/core';
|
|
@@ -27,7 +28,7 @@ declare function linterQueryLineParser(output: ReplOutput, line: readonly string
|
|
|
27
28
|
declare function linterQueryCompleter(line: readonly string[], startingNewArg: boolean, _config: FlowrConfig): CommandCompletions;
|
|
28
29
|
export declare const LinterQueryDefinition: {
|
|
29
30
|
readonly executor: typeof executeLinterQuery;
|
|
30
|
-
readonly asciiSummarizer: (formatter:
|
|
31
|
+
readonly asciiSummarizer: (formatter: OutputFormatter, analyzer: import("../../../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider<import("../../../r-bridge/parser").KnownParser>, queryResults: BaseQueryResult, result: string[]) => true;
|
|
31
32
|
readonly completer: typeof linterQueryCompleter;
|
|
32
33
|
readonly fromLine: typeof linterQueryLineParser;
|
|
33
34
|
readonly schema: Joi.ObjectSchema<any>;
|
|
@@ -10,7 +10,6 @@ const linter_rules_1 = require("../../../linter/linter-rules");
|
|
|
10
10
|
const linter_format_1 = require("../../../linter/linter-format");
|
|
11
11
|
const ansi_1 = require("../../../util/text/ansi");
|
|
12
12
|
const time_1 = require("../../../util/text/time");
|
|
13
|
-
const doc_code_1 = require("../../../documentation/doc-util/doc-code");
|
|
14
13
|
const retriever_1 = require("../../../r-bridge/retriever");
|
|
15
14
|
const assert_1 = require("../../../util/assert");
|
|
16
15
|
function rulesFromInput(output, rulesPart) {
|
|
@@ -101,7 +100,7 @@ exports.LinterQueryDefinition = {
|
|
|
101
100
|
return true;
|
|
102
101
|
}
|
|
103
102
|
for (const [ruleName, results] of Object.entries(out.results)) {
|
|
104
|
-
addLintingRuleResult(ruleName, results, result);
|
|
103
|
+
addLintingRuleResult(ruleName, results, result, formatter);
|
|
105
104
|
}
|
|
106
105
|
return true;
|
|
107
106
|
},
|
|
@@ -125,27 +124,60 @@ exports.LinterQueryDefinition = {
|
|
|
125
124
|
}).filter(assert_1.isNotUndefined);
|
|
126
125
|
}
|
|
127
126
|
};
|
|
128
|
-
|
|
127
|
+
/** cap on findings shown per certainty before collapsing to a `+N more` line; the full set is in `:query*` JSON */
|
|
128
|
+
const MaxFindingsShown = 10;
|
|
129
|
+
function addLintingRuleResult(ruleName, results, result, formatter) {
|
|
129
130
|
const rule = linter_rules_1.LintingRules[ruleName];
|
|
130
|
-
|
|
131
|
+
const header = `${(0, ansi_1.bold)(rule.info.name, formatter)} (${ruleName})`;
|
|
131
132
|
if (linter_format_1.LintingResults.isError(results)) {
|
|
132
133
|
const error = linter_format_1.LintingResults.stringifyError(results).includes('At least one request must be set') ? 'No requests to lint for were found in the analysis.' : 'Error during execution of rule: ' + linter_format_1.LintingResults.stringifyError(results);
|
|
134
|
+
result.push(` ╰ ${header}:`);
|
|
133
135
|
result.push(` ╰ ${error}`);
|
|
134
136
|
return;
|
|
135
137
|
}
|
|
138
|
+
// a rule with no findings collapses to a single line (no per-certainty block, no metadata)
|
|
139
|
+
if (results.results.length === 0) {
|
|
140
|
+
result.push(` ╰ ${header}: ${(0, ansi_1.italic)('no findings', formatter)}`);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
result.push(` ╰ ${header}:`);
|
|
136
144
|
for (const certainty of [linter_format_1.LintingResultCertainty.Certain, linter_format_1.LintingResultCertainty.Uncertain]) {
|
|
137
145
|
const certaintyResults = results.results.filter(r => r.certainty === certainty);
|
|
138
146
|
if (certaintyResults.length) {
|
|
139
147
|
result.push(` ╰ ${certainty}:`);
|
|
140
|
-
for (const res of certaintyResults) {
|
|
148
|
+
for (const res of certaintyResults.slice(0, MaxFindingsShown)) {
|
|
141
149
|
const pretty = rule.prettyPrint[linter_format_1.LintingPrettyPrintContext.Query](res, results['.meta']);
|
|
142
|
-
result.push(` ╰ ${pretty}${res.quickFix ? ` (${res.quickFix.length} quick fix(es) available)` : ''}`);
|
|
150
|
+
result.push(` ╰ ${hyperlinkLocations(pretty, formatter)}${res.quickFix ? ` (${res.quickFix.length} quick fix(es) available)` : ''}`);
|
|
151
|
+
}
|
|
152
|
+
if (certaintyResults.length > MaxFindingsShown) {
|
|
153
|
+
result.push(` ╰ ${(0, ansi_1.italic)(`… +${certaintyResults.length - MaxFindingsShown} more (:query* for the full JSON)`, formatter)}`);
|
|
143
154
|
}
|
|
144
155
|
}
|
|
145
156
|
}
|
|
146
|
-
result.push(` ╰
|
|
157
|
+
result.push(` ╰ ${(0, ansi_1.italic)('Metadata', formatter)}: ${renderMetaData(results['.meta'])}`);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Matches an absolute file path (POSIX `/...` or Windows `X:\...`) with an extension, followed by `:` and a flowR
|
|
161
|
+
* position `<line>(.<col>)?(-<endline>.<endcol>)?`. Used to turn linting finding locations into clickable links.
|
|
162
|
+
*/
|
|
163
|
+
const locationPattern = /((?:[A-Za-z]:\\|\/)[^\s:]*\.[A-Za-z]+):(\d+(?:\.\d+)?(?:-\d+(?:\.\d+)?)?)/g;
|
|
164
|
+
/** Wrap every `path:loc` location in the given pretty string in a `file://path:line:col` hyperlink via the formatter. */
|
|
165
|
+
function hyperlinkLocations(pretty, formatter) {
|
|
166
|
+
return pretty.replace(locationPattern, (match, path, position) => {
|
|
167
|
+
const [line, col] = position.split('-')[0].split('.');
|
|
168
|
+
const url = `file://${path}:${line}${col ? `:${col}` : ''}`;
|
|
169
|
+
return formatter.hyperlink(match, url);
|
|
170
|
+
});
|
|
147
171
|
}
|
|
148
172
|
function renderMetaData(metadata) {
|
|
149
|
-
return Object.entries(metadata).map(
|
|
173
|
+
return Object.entries(metadata).map(([k, v]) => `${k}: ${renderMetaValue(v)}`).join(', ');
|
|
174
|
+
}
|
|
175
|
+
/** Render a metadata value; a nested object (e.g. suppression counts) becomes `(key=value, ...)`, omitting zero counts (`0` if all zero). */
|
|
176
|
+
function renderMetaValue(value) {
|
|
177
|
+
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
178
|
+
const nonZero = Object.entries(value).filter(([, v]) => v !== 0);
|
|
179
|
+
return nonZero.length === 0 ? '0' : `(${nonZero.map(([k, v]) => `${k}=${renderMetaValue(v)}`).join(', ')})`;
|
|
180
|
+
}
|
|
181
|
+
return JSON.stringify(value);
|
|
150
182
|
}
|
|
151
183
|
//# sourceMappingURL=linter-query-format.js.map
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import type { ProjectQuery, ProjectQueryResult } from './project-query-format';
|
|
2
|
+
import { ProjectKind } from './project-query-format';
|
|
2
3
|
import type { BasicQueryData } from '../../base-query-format';
|
|
4
|
+
import type { ReadOnlyFlowrAnalyzerFilesContext } from '../../../project/context/flowr-analyzer-files-context';
|
|
5
|
+
/**
|
|
6
|
+
* Classifies the {@link ProjectKind} of the given files context.
|
|
7
|
+
*
|
|
8
|
+
* A `DESCRIPTION` file unambiguously marks an R {@link ProjectKind.Package | package} and is available as soon
|
|
9
|
+
* as the project is loaded. The finer distinctions ({@link ProjectKind.ShinyApp | shiny app},
|
|
10
|
+
* {@link ProjectKind.Notebook | notebook}, {@link ProjectKind.Script | script} vs.
|
|
11
|
+
* {@link ProjectKind.Project | multi-file project}) rely on the project's source files, which are only known
|
|
12
|
+
* once the dataflow analysis has run; before that a non-package project reports {@link ProjectKind.Unknown}.
|
|
13
|
+
*
|
|
14
|
+
* This is a pure inspection of the files context and can be used standalone, independently of the project query.
|
|
15
|
+
* @param files - the (read-only) files context of an analyzer to classify
|
|
16
|
+
*/
|
|
17
|
+
export declare function classifyProject(files: ReadOnlyFlowrAnalyzerFilesContext): ProjectKind;
|
|
3
18
|
/**
|
|
4
19
|
* Executes the given project queries.
|
|
5
20
|
*/
|
|
@@ -1,8 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.classifyProject = classifyProject;
|
|
3
7
|
exports.executeProjectQuery = executeProjectQuery;
|
|
4
8
|
const log_1 = require("../../../util/log");
|
|
9
|
+
const project_query_format_1 = require("./project-query-format");
|
|
5
10
|
const flowr_file_1 = require("../../../project/context/flowr-file");
|
|
11
|
+
const r_base_packages_1 = require("../../../util/r-base-packages");
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
/**
|
|
14
|
+
* Collects dependency statistics from the project's `DESCRIPTION` file, cross-referenced with the
|
|
15
|
+
* loaded package database(s) to report how many dependencies we can cover.
|
|
16
|
+
*/
|
|
17
|
+
function collectDependencyStats(desc, deps, basePackages) {
|
|
18
|
+
const imports = desc.imports() ?? [];
|
|
19
|
+
const dependsAll = desc.depends() ?? [];
|
|
20
|
+
const rEntry = dependsAll.find(d => d.name === 'R');
|
|
21
|
+
const rVersion = rEntry?.derivedVersion?.raw;
|
|
22
|
+
const depends = dependsAll.filter(d => d.name !== 'R');
|
|
23
|
+
const suggests = desc.suggests() ?? [];
|
|
24
|
+
const linkingTo = desc.linkingTo() ?? [];
|
|
25
|
+
const runtime = new Set([...imports, ...depends, ...linkingTo].map(p => p.name));
|
|
26
|
+
let base = 0;
|
|
27
|
+
let covered = 0;
|
|
28
|
+
const first = [];
|
|
29
|
+
for (const name of runtime) {
|
|
30
|
+
const isBase = basePackages.has(name);
|
|
31
|
+
const resolved = isBase ? undefined : deps.getDependency(name);
|
|
32
|
+
if (isBase) {
|
|
33
|
+
base++;
|
|
34
|
+
}
|
|
35
|
+
else if (resolved?.namespaceInfo) {
|
|
36
|
+
covered++;
|
|
37
|
+
}
|
|
38
|
+
if (first.length < 3) {
|
|
39
|
+
first.push({ name, base: isBase, dbVersion: resolved?.resolvedVersion });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
imports: imports.length,
|
|
44
|
+
depends: depends.length,
|
|
45
|
+
suggests: suggests.length,
|
|
46
|
+
linkingTo: linkingTo.length,
|
|
47
|
+
runtime: runtime.size,
|
|
48
|
+
base,
|
|
49
|
+
covered,
|
|
50
|
+
first,
|
|
51
|
+
rVersion: rVersion && /\d/.test(rVersion) ? rVersion : undefined
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const notebookExtension = /\.(ipynb|rmd|qmd|rnw)$/;
|
|
55
|
+
/**
|
|
56
|
+
* Classifies the {@link ProjectKind} of the given files context.
|
|
57
|
+
*
|
|
58
|
+
* A `DESCRIPTION` file unambiguously marks an R {@link ProjectKind.Package | package} and is available as soon
|
|
59
|
+
* as the project is loaded. The finer distinctions ({@link ProjectKind.ShinyApp | shiny app},
|
|
60
|
+
* {@link ProjectKind.Notebook | notebook}, {@link ProjectKind.Script | script} vs.
|
|
61
|
+
* {@link ProjectKind.Project | multi-file project}) rely on the project's source files, which are only known
|
|
62
|
+
* once the dataflow analysis has run; before that a non-package project reports {@link ProjectKind.Unknown}.
|
|
63
|
+
*
|
|
64
|
+
* This is a pure inspection of the files context and can be used standalone, independently of the project query.
|
|
65
|
+
* @param files - the (read-only) files context of an analyzer to classify
|
|
66
|
+
*/
|
|
67
|
+
function classifyProject(files) {
|
|
68
|
+
if (files.getFilesByRole(flowr_file_1.FileRole.Description).length > 0) {
|
|
69
|
+
return project_query_format_1.ProjectKind.Package;
|
|
70
|
+
}
|
|
71
|
+
const names = new Set([
|
|
72
|
+
...files.getAllFiles().map(f => path_1.default.basename(f.path()).toLowerCase()),
|
|
73
|
+
...files.consideredFilesList().map(p => path_1.default.basename(p).toLowerCase())
|
|
74
|
+
]);
|
|
75
|
+
if (names.size === 0) {
|
|
76
|
+
return project_query_format_1.ProjectKind.Unknown;
|
|
77
|
+
}
|
|
78
|
+
if (names.has('app.r') || (names.has('ui.r') && names.has('server.r'))) {
|
|
79
|
+
return project_query_format_1.ProjectKind.ShinyApp;
|
|
80
|
+
}
|
|
81
|
+
for (const name of names) {
|
|
82
|
+
if (notebookExtension.test(name)) {
|
|
83
|
+
return project_query_format_1.ProjectKind.Notebook;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
let rSources = 0;
|
|
87
|
+
for (const name of names) {
|
|
88
|
+
if (name.endsWith('.r')) {
|
|
89
|
+
rSources++;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return rSources <= 1 ? project_query_format_1.ProjectKind.Script : project_query_format_1.ProjectKind.Project;
|
|
93
|
+
}
|
|
6
94
|
/**
|
|
7
95
|
* Executes the given project queries.
|
|
8
96
|
*/
|
|
@@ -16,23 +104,27 @@ async function executeProjectQuery({ analyzer }, queries) {
|
|
|
16
104
|
if (withDf) {
|
|
17
105
|
await analyzer.dataflow();
|
|
18
106
|
}
|
|
19
|
-
const
|
|
107
|
+
const ctx = analyzer.inspectContext();
|
|
108
|
+
const basePackages = new Set(ctx.config.project.basePackages ?? (0, r_base_packages_1.baseRPackages)(ctx.resolvedRVersion));
|
|
109
|
+
const descFile = ctx.files.getFilesByRole(flowr_file_1.FileRole.Description);
|
|
20
110
|
const desc = descFile[0];
|
|
21
111
|
const roleCounts = {};
|
|
22
112
|
for (const file of Object.values(flowr_file_1.FileRole)) {
|
|
23
|
-
roleCounts[file] =
|
|
113
|
+
roleCounts[file] = ctx.files.getFilesByRole(file).length;
|
|
24
114
|
}
|
|
25
115
|
return {
|
|
26
116
|
'.meta': {
|
|
27
117
|
timing: Date.now() - startTime
|
|
28
118
|
},
|
|
29
119
|
name: desc?.content().get('Package')?.[0] ?? desc?.content()?.get('Title')?.[0],
|
|
30
|
-
files: Array.from(
|
|
120
|
+
files: Array.from(ctx.files.consideredFilesList()),
|
|
31
121
|
authors: desc?.authors(),
|
|
32
122
|
encoding: desc?.content().get('Encoding')?.[0],
|
|
33
123
|
version: desc?.content().get('Version')?.[0],
|
|
34
124
|
licenses: desc?.license(),
|
|
35
|
-
roleCounts: roleCounts
|
|
125
|
+
roleCounts: roleCounts,
|
|
126
|
+
kind: classifyProject(ctx.files),
|
|
127
|
+
dependencies: desc ? collectDependencyStats(desc, ctx.deps, basePackages) : undefined
|
|
36
128
|
};
|
|
37
129
|
}
|
|
38
130
|
//# sourceMappingURL=project-query-executor.js.map
|
|
@@ -9,6 +9,46 @@ export interface ProjectQuery extends BaseQueryFormat {
|
|
|
9
9
|
/** Whether to include Dataflow information in the result. */
|
|
10
10
|
readonly withDf?: boolean;
|
|
11
11
|
}
|
|
12
|
+
/** The kind of project that flowR is analyzing. */
|
|
13
|
+
export declare enum ProjectKind {
|
|
14
|
+
/** An R package (has a `DESCRIPTION` file). */
|
|
15
|
+
Package = "package",
|
|
16
|
+
/** A single R script. */
|
|
17
|
+
Script = "script",
|
|
18
|
+
/** A Shiny application (`app.R`, or `ui.R` together with `server.R`). */
|
|
19
|
+
ShinyApp = "shiny-app",
|
|
20
|
+
/** A notebook or literate document (`.ipynb`, `.Rmd`, `.qmd`, `.rnw`). */
|
|
21
|
+
Notebook = "notebook",
|
|
22
|
+
/** A multi-file project that is not a package. */
|
|
23
|
+
Project = "project",
|
|
24
|
+
/** The kind could not be determined (e.g. before the files are known). */
|
|
25
|
+
Unknown = "unknown"
|
|
26
|
+
}
|
|
27
|
+
/** Statistics on the project's declared dependencies, cross-referenced with the package database. */
|
|
28
|
+
export interface ProjectDependencyStats {
|
|
29
|
+
/** Number of packages in the `Imports` field. */
|
|
30
|
+
readonly imports: number;
|
|
31
|
+
/** Number of packages in the `Depends` field (excluding the `R` version pseudo-package). */
|
|
32
|
+
readonly depends: number;
|
|
33
|
+
/** Number of packages in the `Suggests` field. */
|
|
34
|
+
readonly suggests: number;
|
|
35
|
+
/** Number of packages in the `LinkingTo` field. */
|
|
36
|
+
readonly linkingTo: number;
|
|
37
|
+
/** Number of unique runtime dependencies (`Imports`, `Depends`, and `LinkingTo` combined). */
|
|
38
|
+
readonly runtime: number;
|
|
39
|
+
/** How many of the runtime dependencies are base or recommended R packages. */
|
|
40
|
+
readonly base: number;
|
|
41
|
+
/** How many of the non-base runtime dependencies are covered by the loaded package database(s). */
|
|
42
|
+
readonly covered: number;
|
|
43
|
+
/** The first few runtime dependencies with the version the package database resolved them to, if any. */
|
|
44
|
+
readonly first: {
|
|
45
|
+
name: string;
|
|
46
|
+
base: boolean;
|
|
47
|
+
dbVersion?: string;
|
|
48
|
+
}[];
|
|
49
|
+
/** The required R version derived from the `Depends` field, if declared. */
|
|
50
|
+
readonly rVersion?: string;
|
|
51
|
+
}
|
|
12
52
|
export interface ProjectQueryResult extends BaseQueryResult {
|
|
13
53
|
/** The name of the project, if available. */
|
|
14
54
|
readonly name?: string;
|
|
@@ -24,6 +64,10 @@ export interface ProjectQueryResult extends BaseQueryResult {
|
|
|
24
64
|
readonly encoding?: string;
|
|
25
65
|
/** The version of the project, if available. */
|
|
26
66
|
readonly version?: string;
|
|
67
|
+
/** The classified kind of the project (e.g. package, script, shiny app). */
|
|
68
|
+
readonly kind?: ProjectKind;
|
|
69
|
+
/** Statistics on the project's declared dependencies, if a `DESCRIPTION` file is available. */
|
|
70
|
+
readonly dependencies?: ProjectDependencyStats;
|
|
27
71
|
}
|
|
28
72
|
export declare const ProjectQueryDefinition: {
|
|
29
73
|
readonly executor: typeof executeProjectQuery;
|