@eagleoutice/flowr 2.10.10 → 2.11.1
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 +35 -27
- package/cli/common/options.d.ts +2 -108
- package/cli/common/options.js +3 -27
- package/cli/common/scripts-info.d.ts +2 -123
- package/cli/common/scripts-info.js +0 -17
- package/cli/flowr-main-options.d.ts +5 -0
- package/cli/flowr-main-options.js +10 -0
- package/cli/flowr.js +2 -2
- package/cli/repl/commands/repl-commands.js +7 -6
- package/cli/repl/print-version.d.ts +3 -1
- package/cli/repl/print-version.js +21 -2
- package/cli/repl/server/connection.d.ts +2 -0
- package/cli/repl/server/connection.js +40 -31
- package/cli/script-core/summarizer-core.js +13 -32
- package/cli/wiki.d.ts +2 -1
- package/cli/wiki.js +2 -0
- package/config.d.ts +9 -0
- package/config.js +10 -0
- package/control-flow/semantic-cfg-guided-visitor.js +1 -0
- package/core/steps/pipeline/default-pipelines.d.ts +146 -146
- package/data/pkgdb/pkgdb-latest.json.br +0 -0
- package/data/pkgdb/pkgdb-tiny.json.br +0 -0
- package/dataflow/environments/append.d.ts +1 -2
- package/dataflow/environments/append.js +3 -10
- package/dataflow/environments/apply-kill.d.ts +21 -0
- package/dataflow/environments/apply-kill.js +155 -0
- package/dataflow/environments/built-in-proc-name.d.ts +2 -0
- package/dataflow/environments/built-in-proc-name.js +2 -0
- package/dataflow/environments/built-in.d.ts +2 -0
- package/dataflow/environments/built-in.js +2 -0
- package/dataflow/environments/default-builtin-config.d.ts +63 -3
- package/dataflow/environments/default-builtin-config.js +40 -8
- package/dataflow/environments/environment.d.ts +49 -32
- package/dataflow/environments/environment.js +133 -18
- package/dataflow/environments/identifier.d.ts +10 -0
- package/dataflow/environments/identifier.js +23 -0
- package/dataflow/environments/overwrite.js +2 -10
- package/dataflow/environments/resolve-by-name.d.ts +1 -1
- package/dataflow/environments/resolve-by-name.js +10 -2
- package/dataflow/environments/scoping.d.ts +9 -2
- package/dataflow/environments/scoping.js +15 -2
- package/dataflow/extractor.js +23 -2
- package/dataflow/graph/df-helper.d.ts +8 -0
- package/dataflow/graph/df-helper.js +8 -0
- package/dataflow/graph/graph.d.ts +4 -1
- package/dataflow/graph/graph.js +5 -1
- package/dataflow/info.d.ts +26 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +1 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +7 -13
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +9 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +30 -47
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +17 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +8 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +9 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +37 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +391 -21
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +131 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +25 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +94 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +10 -3
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +30 -0
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +279 -0
- package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -1
- package/dataflow/internal/process/functions/call/named-call-handling.js +17 -0
- package/documentation/data/faq/faqs.js +3 -0
- package/documentation/data/interface/doc-writing-code.js +4 -80
- package/documentation/doc-util/doc-structure.js +1 -2
- package/documentation/wiki-core.js +2 -1
- package/documentation/wiki-dataflow-graph.js +35 -1
- package/documentation/wiki-interface.js +2 -2
- package/documentation/wiki-linter.js +2 -0
- package/documentation/wiki-overview.js +1 -14
- package/documentation/wiki-package-database.d.ts +9 -0
- package/documentation/wiki-package-database.js +63 -0
- package/documentation/wiki-query.js +1 -0
- package/linter/linter-rules.d.ts +23 -0
- package/linter/linter-rules.js +3 -1
- package/linter/rules/absolute-path.js +2 -1
- package/linter/rules/undefined-symbol.d.ts +39 -0
- package/linter/rules/undefined-symbol.js +80 -0
- package/package.json +4 -4
- package/project/cache/flowr-analyzer-cache.d.ts +2 -0
- package/project/cache/flowr-analyzer-cache.js +9 -1
- package/project/context/flowr-analyzer-dependencies-context.d.ts +16 -8
- package/project/context/flowr-analyzer-dependencies-context.js +39 -4
- package/project/context/flowr-analyzer-environment-context.d.ts +2 -4
- package/project/context/flowr-analyzer-environment-context.js +3 -4
- package/project/context/flowr-analyzer-files-context.d.ts +1 -0
- package/project/context/flowr-file.d.ts +2 -0
- package/project/context/flowr-file.js +2 -0
- package/project/flowr-analyzer-builder.js +3 -0
- package/project/flowr-analyzer.d.ts +2 -1
- package/project/flowr-analyzer.js +3 -1
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +13 -15
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +36 -13
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +27 -0
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +41 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +18 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +62 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.d.ts +63 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js +176 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +10 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +6 -0
- package/project/plugins/package-version-plugins/package.d.ts +3 -0
- package/project/plugins/package-version-plugins/package.js +12 -0
- package/project/plugins/package-version-plugins/pkgdb.d.ts +133 -0
- package/project/plugins/package-version-plugins/pkgdb.js +370 -0
- package/project/plugins/plugin-registry.d.ts +4 -1
- package/project/plugins/plugin-registry.js +7 -0
- package/queries/catalog/call-context-query/call-context-query-executor.js +8 -0
- package/queries/catalog/call-context-query/call-context-query-format.d.ts +2 -0
- package/queries/catalog/call-context-query/call-context-query-format.js +1 -0
- package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +8 -0
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +31 -3
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +3 -1
- package/queries/catalog/dependencies-query/dependencies-query-format.js +3 -2
- package/queries/catalog/dependencies-query/function-info/function-info.d.ts +1 -1
- package/queries/catalog/dependencies-query/function-info/other-path-functions.d.ts +2 -0
- package/queries/catalog/dependencies-query/function-info/other-path-functions.js +27 -0
- package/queries/catalog/dependencies-query/function-info/read-functions.js +5 -4
- package/queries/catalog/dependencies-query/function-info/visualize-functions.js +3 -1
- package/queries/catalog/linter-query/linter-query-executor.js +1 -0
- package/r-bridge/data/data.d.ts +2 -2
- package/r-bridge/data/data.js +2 -2
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +13 -4
- package/search/search-executor/search-enrichers.d.ts +1 -1
- package/search/search-executor/search-enrichers.js +7 -4
- package/util/mermaid/mermaid.d.ts +4 -0
- package/util/mermaid/mermaid.js +8 -1
- package/util/text/ansi.d.ts +10 -1
- package/util/text/ansi.js +17 -4
- package/util/version.js +10 -2
- package/cli/common/features.d.ts +0 -9
- package/cli/common/features.js +0 -35
- package/cli/script-core/statistics-core.d.ts +0 -6
- package/cli/script-core/statistics-core.js +0 -104
- package/cli/script-core/statistics-helper-core.d.ts +0 -6
- package/cli/script-core/statistics-helper-core.js +0 -86
- package/cli/statistics-app.d.ts +0 -11
- package/cli/statistics-app.js +0 -16
- package/cli/statistics-helper-app.d.ts +0 -11
- package/cli/statistics-helper-app.js +0 -14
- package/statistics/features/common-syntax-probability.d.ts +0 -38
- package/statistics/features/common-syntax-probability.js +0 -169
- package/statistics/features/feature.d.ts +0 -179
- package/statistics/features/feature.js +0 -38
- package/statistics/features/post-processing.d.ts +0 -18
- package/statistics/features/post-processing.js +0 -26
- package/statistics/features/supported/assignments/assignments.d.ts +0 -12
- package/statistics/features/supported/assignments/assignments.js +0 -56
- package/statistics/features/supported/assignments/post-process.d.ts +0 -6
- package/statistics/features/supported/assignments/post-process.js +0 -126
- package/statistics/features/supported/comments/comments.d.ts +0 -18
- package/statistics/features/supported/comments/comments.js +0 -143
- package/statistics/features/supported/comments/post-process.d.ts +0 -6
- package/statistics/features/supported/comments/post-process.js +0 -51
- package/statistics/features/supported/control-flow/control-flow.d.ts +0 -17
- package/statistics/features/supported/control-flow/control-flow.js +0 -69
- package/statistics/features/supported/control-flow/post-process.d.ts +0 -6
- package/statistics/features/supported/control-flow/post-process.js +0 -66
- package/statistics/features/supported/data-access/data-access.d.ts +0 -15
- package/statistics/features/supported/data-access/data-access.js +0 -122
- package/statistics/features/supported/data-access/post-process.d.ts +0 -6
- package/statistics/features/supported/data-access/post-process.js +0 -108
- package/statistics/features/supported/defined-functions/defined-functions.d.ts +0 -34
- package/statistics/features/supported/defined-functions/defined-functions.js +0 -145
- package/statistics/features/supported/defined-functions/post-process.d.ts +0 -6
- package/statistics/features/supported/defined-functions/post-process.js +0 -168
- package/statistics/features/supported/expression-list/post-process.d.ts +0 -6
- package/statistics/features/supported/expression-list/post-process.js +0 -45
- package/statistics/features/supported/expression-list/statistics-expression-list.d.ts +0 -9
- package/statistics/features/supported/expression-list/statistics-expression-list.js +0 -37
- package/statistics/features/supported/loops/loops.d.ts +0 -20
- package/statistics/features/supported/loops/loops.js +0 -81
- package/statistics/features/supported/loops/post-process.d.ts +0 -6
- package/statistics/features/supported/loops/post-process.js +0 -73
- package/statistics/features/supported/used-functions/post-process.d.ts +0 -6
- package/statistics/features/supported/used-functions/post-process.js +0 -176
- package/statistics/features/supported/used-functions/used-functions.d.ts +0 -24
- package/statistics/features/supported/used-functions/used-functions.js +0 -99
- package/statistics/features/supported/used-packages/post-process.d.ts +0 -6
- package/statistics/features/supported/used-packages/post-process.js +0 -122
- package/statistics/features/supported/used-packages/used-packages.d.ts +0 -16
- package/statistics/features/supported/used-packages/used-packages.js +0 -140
- package/statistics/features/supported/values/post-process.d.ts +0 -6
- package/statistics/features/supported/values/post-process.js +0 -73
- package/statistics/features/supported/values/values.d.ts +0 -14
- package/statistics/features/supported/values/values.js +0 -111
- package/statistics/features/supported/variables/post-process.d.ts +0 -15
- package/statistics/features/supported/variables/post-process.js +0 -126
- package/statistics/features/supported/variables/variables.d.ts +0 -15
- package/statistics/features/supported/variables/variables.js +0 -62
- package/statistics/meta-statistics.d.ts +0 -32
- package/statistics/meta-statistics.js +0 -16
- package/statistics/output/file-provider.d.ts +0 -36
- package/statistics/output/file-provider.js +0 -96
- package/statistics/output/print-stats.d.ts +0 -29
- package/statistics/output/print-stats.js +0 -81
- package/statistics/output/statistics-file.d.ts +0 -36
- package/statistics/output/statistics-file.js +0 -68
- package/statistics/statistics.d.ts +0 -29
- package/statistics/statistics.js +0 -108
- package/statistics/summarizer/auto-detect.d.ts +0 -5
- package/statistics/summarizer/auto-detect.js +0 -34
- package/statistics/summarizer/first-phase/process.d.ts +0 -6
- package/statistics/summarizer/first-phase/process.js +0 -81
- package/statistics/summarizer/post-process/clusterer.d.ts +0 -25
- package/statistics/summarizer/post-process/clusterer.js +0 -40
- package/statistics/summarizer/post-process/file-based-count.d.ts +0 -16
- package/statistics/summarizer/post-process/file-based-count.js +0 -47
- package/statistics/summarizer/post-process/histogram.d.ts +0 -57
- package/statistics/summarizer/post-process/histogram.js +0 -126
- package/statistics/summarizer/post-process/post-process-output.d.ts +0 -14
- package/statistics/summarizer/post-process/post-process-output.js +0 -102
- package/statistics/summarizer/second-phase/process.d.ts +0 -15
- package/statistics/summarizer/second-phase/process.js +0 -118
- package/statistics/summarizer/summarizer.d.ts +0 -34
- package/statistics/summarizer/summarizer.js +0 -141
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PkgDatabase = exports.PkgDbBuilder = exports.DefaultCranBase = exports.PkgDbSchema = exports.PkgDbMagic = void 0;
|
|
7
|
+
exports.cranBlobUrl = cranBlobUrl;
|
|
8
|
+
exports.validatePkgDb = validatePkgDb;
|
|
9
|
+
exports.defaultPkgDbPath = defaultPkgDbPath;
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const zlib_1 = __importDefault(require("zlib"));
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
/*
|
|
14
|
+
* Reader/writer for the `flowr-pkgdb` database (schema 4) produced by crawlr's `dump`.
|
|
15
|
+
* An export list mixes `strings`-pool indices (number) and inline single-use names.
|
|
16
|
+
* latest: pkgs[name] = [version, exported]. all: shares a `lists` pool and stores
|
|
17
|
+
* pkgs[name] = [latest, versions, nonCran?] with each version [ver, exported, internal?, deprecated?].
|
|
18
|
+
* Optional `all` definition locations: a `files` pool + locs[pkg][id] = [fileIndex, line] (latest only).
|
|
19
|
+
* CRAN urls are reconstructed on load. {@link PkgDbBuilder} writes, {@link PkgDatabase} reads - both in flowR.
|
|
20
|
+
*/
|
|
21
|
+
exports.PkgDbMagic = 'flowr-pkgdb';
|
|
22
|
+
exports.PkgDbSchema = 4;
|
|
23
|
+
exports.DefaultCranBase = 'https://cran.r-project.org/src/contrib/';
|
|
24
|
+
/** Reconstruct the CRAN source blob link; the newest non-archived version lives under `src/contrib`, every other under `Archive`. */
|
|
25
|
+
function cranBlobUrl(cranBase, pkg, version, opts) {
|
|
26
|
+
if (!opts.cran) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const base = cranBase.endsWith('/') ? cranBase : cranBase + '/';
|
|
30
|
+
return version === opts.latest && !opts.archived
|
|
31
|
+
? `${base}${pkg}_${version}.tar.gz`
|
|
32
|
+
: `${base}Archive/${pkg}/${pkg}_${version}.tar.gz`;
|
|
33
|
+
}
|
|
34
|
+
/** Validate the structural invariants of a decoded database, throwing a descriptive error on failure. */
|
|
35
|
+
function validatePkgDb(o) {
|
|
36
|
+
const fail = (msg) => {
|
|
37
|
+
throw new Error(`invalid flowr-pkgdb database: ${msg}`);
|
|
38
|
+
};
|
|
39
|
+
if (typeof o !== 'object' || o === null) {
|
|
40
|
+
fail('not an object');
|
|
41
|
+
}
|
|
42
|
+
const db = o;
|
|
43
|
+
if (db.format !== exports.PkgDbMagic) {
|
|
44
|
+
fail(`missing/invalid format (expected "${exports.PkgDbMagic}")`);
|
|
45
|
+
}
|
|
46
|
+
if (db.schema !== exports.PkgDbSchema) {
|
|
47
|
+
fail(`unsupported schema version ${String(db.schema)} (expected ${exports.PkgDbSchema})`);
|
|
48
|
+
}
|
|
49
|
+
if (db.scope !== 'latest' && db.scope !== 'all') {
|
|
50
|
+
fail(`invalid scope ${String(db.scope)}`);
|
|
51
|
+
}
|
|
52
|
+
if (!Array.isArray(db.strings)) {
|
|
53
|
+
fail('missing strings pool');
|
|
54
|
+
}
|
|
55
|
+
if (typeof db.pkgs !== 'object' || db.pkgs === null) {
|
|
56
|
+
fail('missing pkgs');
|
|
57
|
+
}
|
|
58
|
+
if (db.scope === 'all' && !Array.isArray(db.lists)) {
|
|
59
|
+
fail('all-scope database is missing the lists pool');
|
|
60
|
+
}
|
|
61
|
+
if (typeof db.content !== 'object' || db.content === null || typeof db.content.version !== 'number') {
|
|
62
|
+
fail('missing/invalid content header');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** portable gunzip (Node + browser + VS Code) via the Web Streams API */
|
|
66
|
+
async function gunzip(bytes) {
|
|
67
|
+
return new Response(new Blob([bytes]).stream().pipeThrough(new DecompressionStream('gzip'))).text();
|
|
68
|
+
}
|
|
69
|
+
function isGzip(bytes) {
|
|
70
|
+
return bytes[0] === 0x1f && bytes[1] === 0x8b;
|
|
71
|
+
}
|
|
72
|
+
/** richest first: `all` carries every version, `latest`/`tiny` only the current one */
|
|
73
|
+
const PkgDbScopeOrder = ['all', 'latest', 'tiny'];
|
|
74
|
+
/** layouts a bundled database may sit in, relative to a search root */
|
|
75
|
+
const PkgDbSubDirs = ['data/pkgdb', 'src/data/pkgdb', 'dist/src/data/pkgdb'];
|
|
76
|
+
/** roots to search for a bundled database; extendable via `$FLOWR_PKGDB_DIR` (path-delimiter separated) */
|
|
77
|
+
function pkgDbSearchRoots(extra) {
|
|
78
|
+
const roots = [...(extra ?? [])];
|
|
79
|
+
const env = typeof process !== 'undefined' ? process.env?.FLOWR_PKGDB_DIR : undefined;
|
|
80
|
+
if (env) {
|
|
81
|
+
roots.push(...env.split(path_1.default.delimiter).filter(Boolean));
|
|
82
|
+
}
|
|
83
|
+
if (typeof __dirname !== 'undefined') {
|
|
84
|
+
roots.push(__dirname);
|
|
85
|
+
}
|
|
86
|
+
if (typeof process !== 'undefined' && typeof process.cwd === 'function') {
|
|
87
|
+
roots.push(process.cwd());
|
|
88
|
+
}
|
|
89
|
+
return roots;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Location of a bundled database, found by walking up from several roots (this module,
|
|
93
|
+
* `$FLOWR_PKGDB_DIR`, the working directory) across the dev (`src`) and build (`dist`) layouts. With
|
|
94
|
+
* no `scope` it returns the richest available tier (brotli, then gzip, then plain json). Node only
|
|
95
|
+
* (needs `fs`); pass `searchRoots` to override where it looks.
|
|
96
|
+
*/
|
|
97
|
+
function defaultPkgDbPath(scope, searchRoots) {
|
|
98
|
+
if (typeof fs_1.default?.existsSync !== 'function') {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
const scopes = scope ? [scope] : PkgDbScopeOrder;
|
|
102
|
+
for (const root of pkgDbSearchRoots(searchRoots)) {
|
|
103
|
+
for (let dir = root, i = 0; i < 10; i++) {
|
|
104
|
+
for (const sub of PkgDbSubDirs) {
|
|
105
|
+
for (const s of scopes) {
|
|
106
|
+
for (const suffix of ['.br', '.gz', '']) {
|
|
107
|
+
const candidate = path_1.default.join(dir, sub, `pkgdb-${s}.json${suffix}`);
|
|
108
|
+
if (fs_1.default.existsSync(candidate)) {
|
|
109
|
+
return candidate;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const parent = path_1.default.dirname(dir);
|
|
115
|
+
if (parent === dir) {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
dir = parent;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
/** portable non-cryptographic 64-bit hash (cyrb53), hex, for update detection */
|
|
124
|
+
function hash53(str) {
|
|
125
|
+
let h1 = 0xdeadbeef, h2 = 0x41c6ce57;
|
|
126
|
+
for (let i = 0; i < str.length; i++) {
|
|
127
|
+
const ch = str.charCodeAt(i);
|
|
128
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
129
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
130
|
+
}
|
|
131
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
132
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
133
|
+
return (h2 >>> 0).toString(16).padStart(8, '0') + (h1 >>> 0).toString(16).padStart(8, '0');
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Serializes a {@link PkgDb}. Accumulate per-version exports with {@link addPackage}/{@link addVersion},
|
|
137
|
+
* then {@link build} a scope. The multi-use string pool is computed per scope; the `latest` scope may
|
|
138
|
+
* be pruned to the most-downloaded packages. This is the counterpart of {@link PkgDatabase} (the reader).
|
|
139
|
+
*/
|
|
140
|
+
class PkgDbBuilder {
|
|
141
|
+
raw = new Map();
|
|
142
|
+
versionCount = 0;
|
|
143
|
+
addPackage(name, opts) {
|
|
144
|
+
const p = this.raw.get(name);
|
|
145
|
+
if (p) {
|
|
146
|
+
p.latest = opts.latest;
|
|
147
|
+
p.archived = opts.archived ?? p.archived;
|
|
148
|
+
p.downloads = opts.downloads ?? p.downloads;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
this.raw.set(name, { latest: opts.latest, archived: opts.archived ?? false, downloads: opts.downloads ?? 0, versions: new Map() });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
addVersion(name, version, exports) {
|
|
155
|
+
const p = this.raw.get(name) ?? { latest: version, archived: false, downloads: 0, versions: new Map() };
|
|
156
|
+
if (!this.raw.has(name)) {
|
|
157
|
+
this.raw.set(name, p);
|
|
158
|
+
}
|
|
159
|
+
p.versions.set(version, exports);
|
|
160
|
+
this.versionCount++;
|
|
161
|
+
}
|
|
162
|
+
relevant(scope, prune) {
|
|
163
|
+
if (scope === 'all') {
|
|
164
|
+
const out = [];
|
|
165
|
+
for (const [name, p] of this.raw) {
|
|
166
|
+
for (const [version, ex] of p.versions) {
|
|
167
|
+
out.push({ name, version, ex });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
let pkgs = [...this.raw].filter(([, p]) => p.downloads >= prune.minDownloads && p.versions.has(p.latest));
|
|
173
|
+
if (prune.topN !== undefined && pkgs.length > prune.topN) {
|
|
174
|
+
pkgs = pkgs.sort((a, b) => b[1].downloads - a[1].downloads).slice(0, prune.topN);
|
|
175
|
+
}
|
|
176
|
+
return pkgs.map(([name, p]) => ({ name, version: p.latest, ex: p.versions.get(p.latest) }));
|
|
177
|
+
}
|
|
178
|
+
buildPool(relevant, scope) {
|
|
179
|
+
const freq = new Map();
|
|
180
|
+
for (const { ex } of relevant) {
|
|
181
|
+
const names = scope === 'all' ? [...ex.exported, ...ex.internal, ...ex.deprecated] : ex.exported;
|
|
182
|
+
for (const name of names) {
|
|
183
|
+
freq.set(name, (freq.get(name) ?? 0) + 1);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const strings = [...freq.entries()].filter(([, c]) => c >= 2).sort((a, b) => b[1] - a[1]).map(([n]) => n);
|
|
187
|
+
return { strings, index: new Map(strings.map((n, i) => [n, i])) };
|
|
188
|
+
}
|
|
189
|
+
build(scope, meta) {
|
|
190
|
+
const relevant = this.relevant(scope, { minDownloads: meta.minDownloads ?? 0, topN: meta.topN });
|
|
191
|
+
const { strings, index } = this.buildPool(relevant, scope);
|
|
192
|
+
const encode = (names) => [...new Set(names)].sort().map(n => index.get(n) ?? n);
|
|
193
|
+
const content = {
|
|
194
|
+
version: meta.version, date: meta.date, hash: '', generated: meta.generated,
|
|
195
|
+
packages: scope === 'latest' ? relevant.length : this.raw.size, versions: this.versionCount
|
|
196
|
+
};
|
|
197
|
+
const cranBase = meta.cranBase && meta.cranBase !== exports.DefaultCranBase ? meta.cranBase : undefined;
|
|
198
|
+
const archived = [];
|
|
199
|
+
let db;
|
|
200
|
+
if (scope === 'latest') {
|
|
201
|
+
const noncran = [];
|
|
202
|
+
const pkgs = {};
|
|
203
|
+
for (const { name, version, ex } of relevant) {
|
|
204
|
+
pkgs[name] = [version, encode(ex.exported)];
|
|
205
|
+
if (this.raw.get(name)?.archived) {
|
|
206
|
+
archived.push(name);
|
|
207
|
+
}
|
|
208
|
+
if (!ex.cran) {
|
|
209
|
+
noncran.push(name);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
db = { format: exports.PkgDbMagic, schema: exports.PkgDbSchema, scope, content, cranBase, strings, pkgs,
|
|
213
|
+
...(archived.length ? { archived } : {}), ...(noncran.length ? { noncran } : {}) };
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
const lists = [];
|
|
217
|
+
const listIndex = new Map();
|
|
218
|
+
const internList = (names) => {
|
|
219
|
+
const enc = encode(names);
|
|
220
|
+
const key = JSON.stringify(enc);
|
|
221
|
+
let idx = listIndex.get(key);
|
|
222
|
+
if (idx === undefined) {
|
|
223
|
+
idx = lists.length;
|
|
224
|
+
lists.push(enc);
|
|
225
|
+
listIndex.set(key, idx);
|
|
226
|
+
}
|
|
227
|
+
return idx;
|
|
228
|
+
};
|
|
229
|
+
internList([]);
|
|
230
|
+
const files = [];
|
|
231
|
+
const fileIndex = new Map();
|
|
232
|
+
const internFile = (f) => {
|
|
233
|
+
let idx = fileIndex.get(f);
|
|
234
|
+
if (idx === undefined) {
|
|
235
|
+
idx = files.length;
|
|
236
|
+
files.push(f);
|
|
237
|
+
fileIndex.set(f, idx);
|
|
238
|
+
}
|
|
239
|
+
return idx;
|
|
240
|
+
};
|
|
241
|
+
const locs = {};
|
|
242
|
+
const pkgs = {};
|
|
243
|
+
for (const [name, p] of this.raw) {
|
|
244
|
+
const versions = [];
|
|
245
|
+
const nc = [];
|
|
246
|
+
for (const [version, ex] of p.versions) {
|
|
247
|
+
const e = internList(ex.exported), i = internList(ex.internal), d = internList(ex.deprecated);
|
|
248
|
+
versions.push(d !== 0 ? [version, e, i, d] : i !== 0 ? [version, e, i] : [version, e]);
|
|
249
|
+
if (!ex.cran) {
|
|
250
|
+
nc.push(version);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
pkgs[name] = nc.length ? [p.latest, versions, nc] : [p.latest, versions];
|
|
254
|
+
if (p.archived) {
|
|
255
|
+
archived.push(name);
|
|
256
|
+
}
|
|
257
|
+
// optional: record the latest version's definition locations, if the source carried them
|
|
258
|
+
const latestLoc = p.versions.get(p.latest)?.locations;
|
|
259
|
+
if (latestLoc && latestLoc.size > 0) {
|
|
260
|
+
const entry = {};
|
|
261
|
+
for (const [id, [file, line]] of latestLoc) {
|
|
262
|
+
entry[id] = [internFile(file), line];
|
|
263
|
+
}
|
|
264
|
+
locs[name] = entry;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
db = { format: exports.PkgDbMagic, schema: exports.PkgDbSchema, scope, content, cranBase, strings, lists, pkgs,
|
|
268
|
+
...(archived.length ? { archived } : {}),
|
|
269
|
+
...(files.length ? { files, locs } : {}) };
|
|
270
|
+
}
|
|
271
|
+
return { ...db, content: { ...content, hash: hash53(JSON.stringify(db)) } };
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
exports.PkgDbBuilder = PkgDbBuilder;
|
|
275
|
+
class PkgDatabase {
|
|
276
|
+
db;
|
|
277
|
+
archived;
|
|
278
|
+
noncran;
|
|
279
|
+
constructor(db) {
|
|
280
|
+
this.db = db;
|
|
281
|
+
this.archived = new Set(db.archived ?? []);
|
|
282
|
+
this.noncran = new Set(db.noncran ?? []);
|
|
283
|
+
}
|
|
284
|
+
get content() {
|
|
285
|
+
return this.db.content;
|
|
286
|
+
}
|
|
287
|
+
get scope() {
|
|
288
|
+
return this.db.scope;
|
|
289
|
+
}
|
|
290
|
+
/** parse an already-loaded object (validates the schema, throwing a descriptive error on failure) */
|
|
291
|
+
static fromObject(obj) {
|
|
292
|
+
validatePkgDb(obj);
|
|
293
|
+
return new PkgDatabase(obj);
|
|
294
|
+
}
|
|
295
|
+
/** portable async load from raw bytes (gzip auto-detected) */
|
|
296
|
+
static async fromBytes(bytes) {
|
|
297
|
+
const text = isGzip(bytes) ? await gunzip(bytes) : new TextDecoder().decode(bytes);
|
|
298
|
+
return PkgDatabase.fromObject(JSON.parse(text));
|
|
299
|
+
}
|
|
300
|
+
/** portable async load from a URL (works in Node 18+, browser and VS Code) */
|
|
301
|
+
static async fromUrl(url) {
|
|
302
|
+
return PkgDatabase.fromBytes(new Uint8Array(await (await fetch(url)).arrayBuffer()));
|
|
303
|
+
}
|
|
304
|
+
/** synchronous load from a local file (Node only; brotli by `.br`, else gzip auto-detected, else plain) */
|
|
305
|
+
static fromFileSync(file) {
|
|
306
|
+
const raw = fs_1.default.readFileSync(file);
|
|
307
|
+
const bytes = new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength);
|
|
308
|
+
const text = file.endsWith('.br') ? zlib_1.default.brotliDecompressSync(raw).toString('utf8')
|
|
309
|
+
: isGzip(bytes) ? zlib_1.default.gunzipSync(raw).toString('utf8')
|
|
310
|
+
: raw.toString('utf8');
|
|
311
|
+
return PkgDatabase.fromObject(JSON.parse(text));
|
|
312
|
+
}
|
|
313
|
+
has(pkg) {
|
|
314
|
+
return this.db.pkgs[pkg] !== undefined;
|
|
315
|
+
}
|
|
316
|
+
decode(list) {
|
|
317
|
+
return (list ?? []).map(x => typeof x === 'number' ? this.db.strings[x] : x);
|
|
318
|
+
}
|
|
319
|
+
result(pkg, version, latest, cran, exported, internal, deprecated, locations) {
|
|
320
|
+
const cranBase = this.db.cranBase ?? exports.DefaultCranBase;
|
|
321
|
+
return {
|
|
322
|
+
version, exported, internal, deprecated, cran,
|
|
323
|
+
cranUrl: cranBlobUrl(cranBase, pkg, version, { latest, archived: this.archived.has(pkg), cran }),
|
|
324
|
+
...(locations ? { locations } : {})
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
/** definition locations of the latest version, if the (`all`-scope) database carries them */
|
|
328
|
+
locations(pkg) {
|
|
329
|
+
if (this.db.scope !== 'all' || !this.db.locs || !this.db.files) {
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
const entry = this.db.locs[pkg];
|
|
333
|
+
if (!entry) {
|
|
334
|
+
return undefined;
|
|
335
|
+
}
|
|
336
|
+
const files = this.db.files;
|
|
337
|
+
const map = new Map();
|
|
338
|
+
for (const id in entry) {
|
|
339
|
+
const [fileIdx, line] = entry[id];
|
|
340
|
+
map.set(id, { file: files[fileIdx], line });
|
|
341
|
+
}
|
|
342
|
+
return map;
|
|
343
|
+
}
|
|
344
|
+
/** look up the identifiers of a package (defaulting to its latest version) */
|
|
345
|
+
lookup(pkg, version) {
|
|
346
|
+
if (this.db.scope === 'latest') {
|
|
347
|
+
const entry = this.db.pkgs[pkg];
|
|
348
|
+
if (!entry) {
|
|
349
|
+
return undefined;
|
|
350
|
+
}
|
|
351
|
+
return this.result(pkg, entry[0], entry[0], !this.noncran.has(pkg), this.decode(entry[1]), [], []);
|
|
352
|
+
}
|
|
353
|
+
const entry = this.db.pkgs[pkg];
|
|
354
|
+
if (!entry) {
|
|
355
|
+
return undefined;
|
|
356
|
+
}
|
|
357
|
+
const [latest, versions, nc] = entry;
|
|
358
|
+
const vt = (version ? versions.find(v => v[0] === version) : undefined)
|
|
359
|
+
?? versions.find(v => v[0] === latest) ?? versions[versions.length - 1];
|
|
360
|
+
if (!vt) {
|
|
361
|
+
return undefined;
|
|
362
|
+
}
|
|
363
|
+
const lists = this.db.lists;
|
|
364
|
+
// locations are only stored for the latest version
|
|
365
|
+
const locations = vt[0] === latest ? this.locations(pkg) : undefined;
|
|
366
|
+
return this.result(pkg, vt[0], latest, !nc?.includes(vt[0]), this.decode(lists[vt[1]]), this.decode(lists[vt[2] ?? 0]), this.decode(lists[vt[3] ?? 0]), locations);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
exports.PkgDatabase = PkgDatabase;
|
|
370
|
+
//# sourceMappingURL=pkgdb.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { FlowrAnalyzerPlugin } from './flowr-analyzer-plugin';
|
|
2
2
|
import { FlowrAnalyzerDescriptionFilePlugin } from './file-plugins/flowr-analyzer-description-file-plugin';
|
|
3
3
|
import { FlowrAnalyzerPackageVersionsDescriptionFilePlugin } from './package-version-plugins/flowr-analyzer-package-versions-description-file-plugin';
|
|
4
|
+
import { FlowrAnalyzerPackageVersionsPkgDbPlugin } from './package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin';
|
|
5
|
+
import { FlowrAnalyzerPackageVersionsRenvPlugin, FlowrAnalyzerPackageVersionsRvPlugin } from './package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin';
|
|
4
6
|
import { FlowrAnalyzerLoadingOrderDescriptionFilePlugin } from './loading-order-plugins/flowr-analyzer-loading-order-description-file-plugin';
|
|
5
7
|
import { FlowrAnalyzerRmdFilePlugin } from './file-plugins/notebooks/flowr-analyzer-rmd-file-plugin';
|
|
6
8
|
import { FlowrAnalyzerQmdFilePlugin } from './file-plugins/notebooks/flowr-analyzer-qmd-file-plugin';
|
|
@@ -10,13 +12,14 @@ import { FlowrAnalyzerNewsFilePlugin } from './file-plugins/flowr-analyzer-news-
|
|
|
10
12
|
import { FlowrAnalyzerMetaVignetteFilesPlugin } from './file-plugins/flowr-analyzer-vignette-file-plugin';
|
|
11
13
|
import { FlowrAnalyzerMetaTestFilesPlugin } from './file-plugins/flowr-analyzer-test-file-plugin';
|
|
12
14
|
import { FlowrAnalyzerLicenseFilePlugin } from './file-plugins/flowr-analyzer-license-file-plugin';
|
|
15
|
+
import { FlowrAnalyzerVirtualEnvFilePlugin } from './file-plugins/flowr-analyzer-virtualenv-file-plugin';
|
|
13
16
|
import { FlowrAnalyzerMetaDescriptionFilePlugin } from './package-version-plugins/flowr-analyzer-meta-description-file-plugin';
|
|
14
17
|
import { FlowrAnalyzerSweaveFilePlugin } from './file-plugins/notebooks/flowr-analyzer-sweave-file-plugin';
|
|
15
18
|
import { FlowrAnalyzerGitignoreProjectDiscoveryPlugin } from './project-discovery/flowr-analyzer-gitignore-project-discovery-plugin';
|
|
16
19
|
/**
|
|
17
20
|
* The built-in Flowr Analyzer plugins that are always available.
|
|
18
21
|
*/
|
|
19
|
-
export declare const BuiltInPlugins: [["file:description", typeof FlowrAnalyzerDescriptionFilePlugin], ["versions:description", typeof FlowrAnalyzerPackageVersionsDescriptionFilePlugin], ["loading-order:description", typeof FlowrAnalyzerLoadingOrderDescriptionFilePlugin], ["meta:description", typeof FlowrAnalyzerMetaDescriptionFilePlugin], ["files:vignette", typeof FlowrAnalyzerMetaVignetteFilesPlugin], ["files:test", typeof FlowrAnalyzerMetaTestFilesPlugin], ["file:rmd", typeof FlowrAnalyzerRmdFilePlugin], ["file:qmd", typeof FlowrAnalyzerQmdFilePlugin], ["file:rnw", typeof FlowrAnalyzerSweaveFilePlugin], ["file:ipynb", typeof FlowrAnalyzerJupyterFilePlugin], ["file:namespace", typeof FlowrAnalyzerNamespaceFilesPlugin], ["file:news", typeof FlowrAnalyzerNewsFilePlugin], ["file:license", typeof FlowrAnalyzerLicenseFilePlugin], ["project-discovery:gitignore", typeof FlowrAnalyzerGitignoreProjectDiscoveryPlugin]];
|
|
22
|
+
export declare const BuiltInPlugins: [["file:description", typeof FlowrAnalyzerDescriptionFilePlugin], ["versions:description", typeof FlowrAnalyzerPackageVersionsDescriptionFilePlugin], ["versions:pkgdb", typeof FlowrAnalyzerPackageVersionsPkgDbPlugin], ["versions:renv", typeof FlowrAnalyzerPackageVersionsRenvPlugin], ["versions:rv", typeof FlowrAnalyzerPackageVersionsRvPlugin], ["loading-order:description", typeof FlowrAnalyzerLoadingOrderDescriptionFilePlugin], ["meta:description", typeof FlowrAnalyzerMetaDescriptionFilePlugin], ["files:vignette", typeof FlowrAnalyzerMetaVignetteFilesPlugin], ["files:test", typeof FlowrAnalyzerMetaTestFilesPlugin], ["file:rmd", typeof FlowrAnalyzerRmdFilePlugin], ["file:qmd", typeof FlowrAnalyzerQmdFilePlugin], ["file:rnw", typeof FlowrAnalyzerSweaveFilePlugin], ["file:ipynb", typeof FlowrAnalyzerJupyterFilePlugin], ["file:namespace", typeof FlowrAnalyzerNamespaceFilesPlugin], ["file:news", typeof FlowrAnalyzerNewsFilePlugin], ["file:license", typeof FlowrAnalyzerLicenseFilePlugin], ["file:virtualenv", typeof FlowrAnalyzerVirtualEnvFilePlugin], ["project-discovery:gitignore", typeof FlowrAnalyzerGitignoreProjectDiscoveryPlugin]];
|
|
20
23
|
export type BuiltInFlowrPluginName = typeof BuiltInPlugins[number][0];
|
|
21
24
|
export type BuiltInFlowrPluginArgs<N extends BuiltInFlowrPluginName> = N extends typeof BuiltInPlugins[number][0] ? ConstructorParameters<Extract<typeof BuiltInPlugins[number], [N, PluginProducer]>[1]> : never;
|
|
22
25
|
type PluginProducer = new (...args: never[]) => FlowrAnalyzerPlugin;
|
|
@@ -6,6 +6,8 @@ exports.getPlugin = getPlugin;
|
|
|
6
6
|
exports.makePlugin = makePlugin;
|
|
7
7
|
const flowr_analyzer_description_file_plugin_1 = require("./file-plugins/flowr-analyzer-description-file-plugin");
|
|
8
8
|
const flowr_analyzer_package_versions_description_file_plugin_1 = require("./package-version-plugins/flowr-analyzer-package-versions-description-file-plugin");
|
|
9
|
+
const flowr_analyzer_package_versions_pkgdb_plugin_1 = require("./package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin");
|
|
10
|
+
const flowr_analyzer_package_versions_lockfile_plugin_1 = require("./package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin");
|
|
9
11
|
const flowr_analyzer_loading_order_description_file_plugin_1 = require("./loading-order-plugins/flowr-analyzer-loading-order-description-file-plugin");
|
|
10
12
|
const flowr_analyzer_rmd_file_plugin_1 = require("./file-plugins/notebooks/flowr-analyzer-rmd-file-plugin");
|
|
11
13
|
const flowr_analyzer_qmd_file_plugin_1 = require("./file-plugins/notebooks/flowr-analyzer-qmd-file-plugin");
|
|
@@ -16,6 +18,7 @@ const flowr_analyzer_news_file_plugin_1 = require("./file-plugins/flowr-analyzer
|
|
|
16
18
|
const flowr_analyzer_vignette_file_plugin_1 = require("./file-plugins/flowr-analyzer-vignette-file-plugin");
|
|
17
19
|
const flowr_analyzer_test_file_plugin_1 = require("./file-plugins/flowr-analyzer-test-file-plugin");
|
|
18
20
|
const flowr_analyzer_license_file_plugin_1 = require("./file-plugins/flowr-analyzer-license-file-plugin");
|
|
21
|
+
const flowr_analyzer_virtualenv_file_plugin_1 = require("./file-plugins/flowr-analyzer-virtualenv-file-plugin");
|
|
19
22
|
const flowr_analyzer_meta_description_file_plugin_1 = require("./package-version-plugins/flowr-analyzer-meta-description-file-plugin");
|
|
20
23
|
const flowr_analyzer_sweave_file_plugin_1 = require("./file-plugins/notebooks/flowr-analyzer-sweave-file-plugin");
|
|
21
24
|
const flowr_analyzer_gitignore_project_discovery_plugin_1 = require("./project-discovery/flowr-analyzer-gitignore-project-discovery-plugin");
|
|
@@ -25,6 +28,9 @@ const flowr_analyzer_gitignore_project_discovery_plugin_1 = require("./project-d
|
|
|
25
28
|
exports.BuiltInPlugins = [
|
|
26
29
|
['file:description', flowr_analyzer_description_file_plugin_1.FlowrAnalyzerDescriptionFilePlugin],
|
|
27
30
|
['versions:description', flowr_analyzer_package_versions_description_file_plugin_1.FlowrAnalyzerPackageVersionsDescriptionFilePlugin],
|
|
31
|
+
['versions:pkgdb', flowr_analyzer_package_versions_pkgdb_plugin_1.FlowrAnalyzerPackageVersionsPkgDbPlugin],
|
|
32
|
+
['versions:renv', flowr_analyzer_package_versions_lockfile_plugin_1.FlowrAnalyzerPackageVersionsRenvPlugin],
|
|
33
|
+
['versions:rv', flowr_analyzer_package_versions_lockfile_plugin_1.FlowrAnalyzerPackageVersionsRvPlugin],
|
|
28
34
|
['loading-order:description', flowr_analyzer_loading_order_description_file_plugin_1.FlowrAnalyzerLoadingOrderDescriptionFilePlugin],
|
|
29
35
|
['meta:description', flowr_analyzer_meta_description_file_plugin_1.FlowrAnalyzerMetaDescriptionFilePlugin],
|
|
30
36
|
['files:vignette', flowr_analyzer_vignette_file_plugin_1.FlowrAnalyzerMetaVignetteFilesPlugin],
|
|
@@ -36,6 +42,7 @@ exports.BuiltInPlugins = [
|
|
|
36
42
|
['file:namespace', flowr_analyzer_namespace_files_plugin_1.FlowrAnalyzerNamespaceFilesPlugin],
|
|
37
43
|
['file:news', flowr_analyzer_news_file_plugin_1.FlowrAnalyzerNewsFilePlugin],
|
|
38
44
|
['file:license', flowr_analyzer_license_file_plugin_1.FlowrAnalyzerLicenseFilePlugin],
|
|
45
|
+
['file:virtualenv', flowr_analyzer_virtualenv_file_plugin_1.FlowrAnalyzerVirtualEnvFilePlugin],
|
|
39
46
|
['project-discovery:gitignore', flowr_analyzer_gitignore_project_discovery_plugin_1.FlowrAnalyzerGitignoreProjectDiscoveryPlugin]
|
|
40
47
|
];
|
|
41
48
|
/**
|
|
@@ -12,6 +12,7 @@ const cfg_kind_1 = require("../../../project/cfg-kind");
|
|
|
12
12
|
const extract_cfg_1 = require("../../../control-flow/extract-cfg");
|
|
13
13
|
const identify_link_to_relation_1 = require("./identify-link-to-relation");
|
|
14
14
|
const identifier_1 = require("../../../dataflow/environments/identifier");
|
|
15
|
+
const dfg_get_origin_1 = require("../../../dataflow/origin/dfg-get-origin");
|
|
15
16
|
const queue_1 = require("../../../util/collections/queue");
|
|
16
17
|
/* if the node is effected by nse, we have an ingoing nse edge */
|
|
17
18
|
function isQuoted(node, graph) {
|
|
@@ -286,6 +287,13 @@ async function executeCallContextQueries({ analyzer }, queries) {
|
|
|
286
287
|
continue;
|
|
287
288
|
}
|
|
288
289
|
}
|
|
290
|
+
if (query.callTargetNamespace !== undefined) {
|
|
291
|
+
// the resolved package (a loaded-library export) or the call's explicit namespace
|
|
292
|
+
const pkg = identifier_1.Identifier.getNamespace(identifier_1.Identifier.toQualified((0, dfg_get_origin_1.getOriginInDfg)(dataflow.graph, nodeId)) ?? info.name);
|
|
293
|
+
if (pkg !== query.callTargetNamespace) {
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
289
297
|
if (isQuoted(nodeId, dataflow.graph)) {
|
|
290
298
|
/* if the call is quoted, we do not want to link to it */
|
|
291
299
|
continue;
|
|
@@ -35,6 +35,8 @@ export interface DefaultCallContextQueryFormat<RegexType extends CallNameTypes>
|
|
|
35
35
|
* Request this specifically to gain all call targets we can resolve.
|
|
36
36
|
*/
|
|
37
37
|
readonly callTargets?: CallTargets;
|
|
38
|
+
/** Only keep calls that resolve to (or are explicitly qualified with) this package, e.g. `bar` to find `bar::foo` / `foo()` after `library(bar)`. */
|
|
39
|
+
readonly callTargetNamespace?: string;
|
|
38
40
|
/** Consider a case like `f <- function_of_interest`, do you want uses of `f` to be included in the results? */
|
|
39
41
|
readonly includeAliases?: boolean;
|
|
40
42
|
/** Should we ignore default values for parameters in the results? */
|
|
@@ -39,6 +39,7 @@ exports.CallContextQueryDefinition = {
|
|
|
39
39
|
kind: joi_1.default.string().optional().description('The kind of the call, this can be used to group calls together (e.g., linking `plot` to `visualize`). Defaults to `.`'),
|
|
40
40
|
subkind: joi_1.default.string().optional().description('The subkind of the call, this can be used to uniquely identify the respective call type when grouping the output (e.g., the normalized name, linking `ggplot` to `plot`). Defaults to `.`'),
|
|
41
41
|
callTargets: joi_1.default.string().valid(...Object.values(identify_link_to_last_call_relation_1.CallTargets)).optional().description('Call targets the function may have. This defaults to `any`. Request this specifically to gain all call targets we can resolve.'),
|
|
42
|
+
callTargetNamespace: joi_1.default.string().optional().description('Only keep calls that resolve to (or are explicitly qualified with) this package (e.g. `bar` to find `bar::foo`).'),
|
|
42
43
|
ignoreParameterValues: joi_1.default.boolean().optional().description('Should we ignore default values for parameters in the results?'),
|
|
43
44
|
includeAliases: joi_1.default.boolean().optional().description('Consider a case like `f <- function_of_interest`, do you want uses of `f` to be included in the results?'),
|
|
44
45
|
fileFilter: joi_1.default.object({
|
|
@@ -42,6 +42,14 @@ function satisfiesCallTargets(info, graph, callTarget) {
|
|
|
42
42
|
.map(([t]) => t)
|
|
43
43
|
.toArray();
|
|
44
44
|
let builtIn = false;
|
|
45
|
+
/*
|
|
46
|
+
* a resolved call target that is itself a built-in - a base builtin or a loaded-package export
|
|
47
|
+
* like `ggplot2::ggplot` (added by `library()`) - is a global resolution, so such calls count
|
|
48
|
+
* as global for every call-context query (`callTargetNamespace` then narrows down to the package).
|
|
49
|
+
*/
|
|
50
|
+
if (callTargets.some(t => node_id_1.NodeId.isBuiltIn(t))) {
|
|
51
|
+
builtIn = true;
|
|
52
|
+
}
|
|
45
53
|
if (info.environment !== undefined) {
|
|
46
54
|
/*
|
|
47
55
|
* for performance and scoping reasons, flowR will not identify the global linkage,
|
|
@@ -4,6 +4,8 @@ exports.executeDependenciesQuery = executeDependenciesQuery;
|
|
|
4
4
|
const query_1 = require("../../query");
|
|
5
5
|
const dependencies_query_format_1 = require("./dependencies-query-format");
|
|
6
6
|
const vertex_1 = require("../../../dataflow/graph/vertex");
|
|
7
|
+
const identifier_1 = require("../../../dataflow/environments/identifier");
|
|
8
|
+
const dfg_get_origin_1 = require("../../../dataflow/origin/dfg-get-origin");
|
|
7
9
|
const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
|
|
8
10
|
const objects_1 = require("../../../util/objects");
|
|
9
11
|
const function_info_1 = require("./function-info/function-info");
|
|
@@ -12,6 +14,7 @@ const resolve_argument_1 = require("../../../dataflow/eval/resolve/resolve-argum
|
|
|
12
14
|
const assert_1 = require("../../../util/assert");
|
|
13
15
|
const log_1 = require("../../../util/log");
|
|
14
16
|
const model_1 = require("../../../r-bridge/lang-4.x/ast/model/model");
|
|
17
|
+
const graph_1 = require("../../../dataflow/graph/graph");
|
|
15
18
|
/**
|
|
16
19
|
* Executes a dependencies query.
|
|
17
20
|
*/
|
|
@@ -100,6 +103,18 @@ function getResults(queries, { dataflow, config, normalize }, results, kind, fun
|
|
|
100
103
|
for (const { id, linkedIds } of results) {
|
|
101
104
|
const vertex = dfg.getVertex(id);
|
|
102
105
|
const info = functionMap.get(name);
|
|
106
|
+
// the qualified call name (`dplyr::filter` for a bare `filter()` after `library(dplyr)`),
|
|
107
|
+
// falling back to the plain called name when the call does not resolve to a loaded package
|
|
108
|
+
const functionName = identifier_1.Identifier.toQualified((0, dfg_get_origin_1.getOriginInDfg)(dfg, id)) ?? vertex.name;
|
|
109
|
+
// a call qualified to (or resolved via a loaded library to) a different package than the
|
|
110
|
+
// function's is not this function - e.g. purrr::map, or a bare map() after library(purrr),
|
|
111
|
+
// is not the maps `map` plot; bare/matching-namespace calls still count.
|
|
112
|
+
if (info.package !== undefined) {
|
|
113
|
+
const callNamespace = identifier_1.Identifier.getNamespace(functionName);
|
|
114
|
+
if (callNamespace !== undefined && callNamespace !== info.package) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
103
118
|
const args = (0, resolve_argument_1.getArgumentStringValue)(vars, dfg, vertex, info.argIdx, info.argName, info.resolveValue, ictx);
|
|
104
119
|
const linkedArgs = collectValuesFromLinks(args, { dataflow, config, ctx: ictx }, linkedIds);
|
|
105
120
|
const linked = dropInfoOnLinkedIds(linkedIds);
|
|
@@ -123,6 +138,19 @@ function getResults(queries, { dataflow, config, normalize }, results, kind, fun
|
|
|
123
138
|
}
|
|
124
139
|
return false;
|
|
125
140
|
}
|
|
141
|
+
function ignoreOnArgSet() {
|
|
142
|
+
if (info.ignoreIf !== 'arg-set') {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const hasArg = (name, index) => vertex.args.some((arg, idx) => graph_1.FunctionArgument.isNamed(arg) && arg.name === name ||
|
|
146
|
+
graph_1.FunctionArgument.isPositional(arg) && idx === index);
|
|
147
|
+
if (hasArg(info.argName, info.argIdx)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const margs = info.additionalArgs?.argSet;
|
|
151
|
+
(0, assert_1.guard)(margs, 'Need additional argument argSet when checking for arg-set');
|
|
152
|
+
return hasArg(margs.argName, margs.argIdx);
|
|
153
|
+
}
|
|
126
154
|
const foundValues = linkedArgs ?? args;
|
|
127
155
|
if (!foundValues) {
|
|
128
156
|
if (info.ignoreIf === 'arg-missing') {
|
|
@@ -133,7 +161,7 @@ function getResults(queries, { dataflow, config, normalize }, results, kind, fun
|
|
|
133
161
|
}
|
|
134
162
|
const record = (0, objects_1.compactRecord)({
|
|
135
163
|
nodeId: id,
|
|
136
|
-
functionName
|
|
164
|
+
functionName,
|
|
137
165
|
lexemeOfArgument: undefined,
|
|
138
166
|
linkedIds: linked?.length ? linked : undefined,
|
|
139
167
|
value: info.defaultValue ?? defaultValue
|
|
@@ -157,7 +185,7 @@ function getResults(queries, { dataflow, config, normalize }, results, kind, fun
|
|
|
157
185
|
continue;
|
|
158
186
|
}
|
|
159
187
|
}
|
|
160
|
-
else if (ignoreOnArgVal()) {
|
|
188
|
+
else if (ignoreOnArgVal() || ignoreOnArgSet()) {
|
|
161
189
|
continue;
|
|
162
190
|
}
|
|
163
191
|
for (const [arg, values] of foundValues.entries()) {
|
|
@@ -169,7 +197,7 @@ function getResults(queries, { dataflow, config, normalize }, results, kind, fun
|
|
|
169
197
|
const dep = resolvedValue ? d.getDependency(resolvedValue) ?? undefined : undefined;
|
|
170
198
|
finalResults.push((0, objects_1.compactRecord)({
|
|
171
199
|
nodeId: id,
|
|
172
|
-
functionName
|
|
200
|
+
functionName,
|
|
173
201
|
lexemeOfArgument: getLexeme(value, arg),
|
|
174
202
|
linkedIds: linked?.length ? linked : undefined,
|
|
175
203
|
value: resolvedValue ?? info.defaultValue ?? defaultValue,
|
|
@@ -7,6 +7,7 @@ import type { CallContextQueryResult } from '../call-context-query/call-context-
|
|
|
7
7
|
import type { Range } from 'semver';
|
|
8
8
|
import type { AsyncOrSync, MarkOptional } from 'ts-essentials';
|
|
9
9
|
import type { NamespaceInfo } from '../../../project/plugins/file-plugins/files/flowr-namespace-file';
|
|
10
|
+
import { Identifier } from '../../../dataflow/environments/identifier';
|
|
10
11
|
export declare const Unknown = "unknown";
|
|
11
12
|
export interface DependencyCategorySettings {
|
|
12
13
|
queryDisplayName?: string;
|
|
@@ -70,7 +71,8 @@ export type DependenciesQueryResult = BaseQueryResult & {
|
|
|
70
71
|
};
|
|
71
72
|
export interface DependencyInfo extends Record<string, unknown> {
|
|
72
73
|
nodeId: NodeId;
|
|
73
|
-
|
|
74
|
+
/** the called name; an {@link Identifier}, so a namespaced call like `maps::map` keeps its package */
|
|
75
|
+
functionName: Identifier;
|
|
74
76
|
linkedIds?: readonly NodeId[];
|
|
75
77
|
/** the lexeme is presented whenever the specific info is of {@link Unknown} */
|
|
76
78
|
lexemeOfArgument?: string;
|
|
@@ -76,12 +76,13 @@ function printResultSection(title, infos, result) {
|
|
|
76
76
|
}
|
|
77
77
|
result.push(` ╰ ${title}`);
|
|
78
78
|
const grouped = infos.reduce(function (groups, i) {
|
|
79
|
-
const
|
|
79
|
+
const key = identifier_1.Identifier.toString(i.functionName);
|
|
80
|
+
const array = groups.get(key);
|
|
80
81
|
if (array) {
|
|
81
82
|
array.push(i);
|
|
82
83
|
}
|
|
83
84
|
else {
|
|
84
|
-
groups.set(
|
|
85
|
+
groups.set(key, [i]);
|
|
85
86
|
}
|
|
86
87
|
return groups;
|
|
87
88
|
}, new Map());
|
|
@@ -29,7 +29,7 @@ export interface FunctionInfo extends FunctionArgInfo {
|
|
|
29
29
|
/** default value for the argument if no binding value is found, please be aware, that categories can define global defaults, these are overwritten by the per-function defaults */
|
|
30
30
|
defaultValue?: string;
|
|
31
31
|
/** the function is not to be counted as a dependency if the argument is missing */
|
|
32
|
-
ignoreIf?: 'arg-missing' | 'mode-only-read' | 'mode-only-write' | 'arg-true' | 'arg-false';
|
|
32
|
+
ignoreIf?: 'arg-missing' | 'mode-only-read' | 'mode-only-write' | 'arg-true' | 'arg-false' | 'arg-set';
|
|
33
33
|
/** additional info on arguments - e.g. for the mode flag */
|
|
34
34
|
additionalArgs?: Record<string, FunctionArgInfo>;
|
|
35
35
|
/** string replacements to apply to resolved values, e.g. `{ '': 'stdin' }` */
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OtherPathFunctions = void 0;
|
|
4
|
+
exports.OtherPathFunctions = [
|
|
5
|
+
{ package: 'base', name: 'setwd', argIdx: 0, argName: 'dir', resolveValue: true },
|
|
6
|
+
{ package: 'base', name: 'basename', argIdx: 0, argName: 'path', resolveValue: true },
|
|
7
|
+
{ package: 'base', name: 'dirname', argIdx: 0, argName: 'path', resolveValue: true },
|
|
8
|
+
{ package: 'base', name: 'normalizePath', argIdx: 0, argName: 'path', resolveValue: true },
|
|
9
|
+
{ package: 'base', name: 'file.info', argIdx: 'unnamed', resolveValue: true },
|
|
10
|
+
{ package: 'base', name: 'file.mode', argIdx: 'unnamed', resolveValue: true },
|
|
11
|
+
{ package: 'base', name: 'file.mtime', argIdx: 'unnamed', resolveValue: true },
|
|
12
|
+
{ package: 'base', name: 'file.size', argIdx: 'unnamed', resolveValue: true },
|
|
13
|
+
{ package: 'base', name: 'file.create', argIdx: 'unnamed', resolveValue: true },
|
|
14
|
+
{ package: 'base', name: 'file.exists', argIdx: 'unnamed', resolveValue: true },
|
|
15
|
+
{ package: 'base', name: 'file.remove', argIdx: 'unnamed', resolveValue: true },
|
|
16
|
+
{ package: 'base', name: 'file.rename', argIdx: 0, argName: 'from', resolveValue: true },
|
|
17
|
+
{ package: 'base', name: 'file.append', argIdx: 0, argName: 'file1', resolveValue: true },
|
|
18
|
+
{ package: 'base', name: 'file.copy', argIdx: 0, argName: 'from', resolveValue: true },
|
|
19
|
+
{ package: 'base', name: 'file.symlink', argIdx: 0, argName: 'from', resolveValue: true },
|
|
20
|
+
{ package: 'base', name: 'file.link', argIdx: 0, argName: 'from', resolveValue: true },
|
|
21
|
+
{ package: 'base', name: 'Sys.junction', argIdx: 0, argName: 'from', resolveValue: true },
|
|
22
|
+
{ package: 'base', name: 'dir.exists', argIdx: 0, argName: 'path', resolveValue: true },
|
|
23
|
+
{ package: 'base', name: 'list.files', argIdx: 0, argName: 'path', resolveValue: true, defaultValue: '.' },
|
|
24
|
+
{ package: 'base', name: 'list.dirs', argIdx: 0, argName: 'path', resolveValue: true, defaultValue: '.' },
|
|
25
|
+
{ package: 'base', name: 'dir', argIdx: 0, argName: 'path', resolveValue: true, defaultValue: '.' }
|
|
26
|
+
];
|
|
27
|
+
//# sourceMappingURL=other-path-functions.js.map
|