@eagleoutice/flowr 2.17.0 → 2.17.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.
Files changed (67) hide show
  1. package/README.md +8 -8
  2. package/config.d.ts +32 -0
  3. package/config.js +22 -2
  4. package/dataflow/environments/built-in-props.d.ts +16 -2
  5. package/dataflow/environments/built-in-props.js +23 -3
  6. package/dataflow/environments/built-in.js +13 -3
  7. package/dataflow/environments/default-builtin-config.d.ts +268 -7
  8. package/dataflow/environments/default-builtin-config.js +72 -13
  9. package/dataflow/environments/identifier.d.ts +7 -1
  10. package/dataflow/extractor.js +49 -14
  11. package/dataflow/fn/function-semantics.d.ts +1 -0
  12. package/linter/rules/network-functions.js +10 -2
  13. package/linter/rules/unused-import.js +11 -1
  14. package/package.json +1 -1
  15. package/project/cache/flowr-analyzer-cache.d.ts +4 -0
  16. package/project/cache/flowr-analyzer-cache.js +11 -0
  17. package/project/context/flowr-analyzer-dependencies-context.d.ts +3 -0
  18. package/project/context/flowr-analyzer-dependencies-context.js +6 -0
  19. package/project/context/flowr-file.d.ts +2 -2
  20. package/project/context/flowr-file.js +2 -2
  21. package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +39 -4
  22. package/project/plugins/file-plugins/files/flowr-manifest-files.js +134 -30
  23. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +1 -1
  24. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +7 -0
  25. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +14 -1
  26. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +1 -1
  27. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -3
  28. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.d.ts +18 -5
  29. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.js +43 -15
  30. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +12 -0
  31. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +31 -2
  32. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.d.ts +58 -0
  33. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.js +237 -0
  34. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +8 -0
  35. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +8 -0
  36. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +7 -0
  37. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +24 -18
  38. package/project/plugins/plugin-registry.d.ts +5 -4
  39. package/project/plugins/plugin-registry.js +6 -0
  40. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +4 -4
  41. package/project/sigdb/decode.js +13 -3
  42. package/project/sigdb/memory-source.d.ts +6 -4
  43. package/project/sigdb/memory-source.js +6 -5
  44. package/project/sigdb/on-demand/fetch.d.ts +18 -0
  45. package/project/sigdb/on-demand/fetch.js +127 -0
  46. package/project/sigdb/on-demand/package-sources.d.ts +40 -0
  47. package/project/sigdb/on-demand/package-sources.js +263 -0
  48. package/project/sigdb/on-demand/recoverer.d.ts +40 -0
  49. package/project/sigdb/on-demand/recoverer.js +169 -0
  50. package/project/sigdb/on-demand/remote-sources.d.ts +72 -0
  51. package/project/sigdb/on-demand/remote-sources.js +132 -0
  52. package/project/sigdb/on-demand/tar.d.ts +19 -0
  53. package/project/sigdb/on-demand/tar.js +119 -0
  54. package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +5 -0
  55. package/queries/catalog/dependencies-query/function-info/derived-functions.js +17 -1
  56. package/queries/catalog/dependencies-query/function-info/read-functions.js +3 -1
  57. package/queries/catalog/dependencies-query/function-info/write-functions.js +11 -1
  58. package/r-bridge/data/data.d.ts +29 -0
  59. package/r-bridge/data/data.js +23 -0
  60. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +4 -0
  61. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +8 -0
  62. package/taint-analysis/predefined/secret-analysis.js +7 -2
  63. package/taint-analysis/taint-mapping.d.ts +5 -2
  64. package/taint-analysis/taint-mapping.js +17 -6
  65. package/util/flowr-version.d.ts +1 -1
  66. package/util/flowr-version.js +2 -2
  67. package/util/r-version.js +4 -2
@@ -3,11 +3,20 @@ import type { DeepReadonly } from 'ts-essentials';
3
3
  import type { DeclaredPackages } from '../../../context/flowr-analyzer-meta-context';
4
4
  import { Package } from '../../package-version-plugins/package';
5
5
  export declare const manifestFileLog: import("tslog").Logger<import("tslog").ILogObj>;
6
+ /** what a project manifest declares, whether it is a file of its own or a block within a script */
7
+ export interface ProjectManifest {
8
+ /** unlike the `Package` of a `DESCRIPTION` this is no namespace, such a project is no package */
9
+ projectName(): string | undefined;
10
+ /** `undefined` if the manifest only states a requirement like `>=4.0.0` */
11
+ rVersion(): string | undefined;
12
+ /** grouped as a `DESCRIPTION` groups them */
13
+ declares(): DeclaredPackages;
14
+ }
6
15
  /**
7
- * A project manifest that is no `DESCRIPTION` (an rv `rproject.toml`, a uvr `uvr.toml`).
16
+ * A project manifest that is no `DESCRIPTION` (an rv `rproject.toml`, a uvr `uvr.toml`, a rig `rproj.toml`).
8
17
  * Prefer the static `from` method of the concrete subclass, which avoids re-wrapping and handles roles.
9
18
  */
10
- export declare abstract class FlowrManifestFile<Content extends StringableContent = StringableContent> extends FlowrWrappedFile<Content> {
19
+ export declare abstract class FlowrManifestFile<Content extends StringableContent = StringableContent> extends FlowrWrappedFile<Content> implements ProjectManifest {
11
20
  /** unlike the `Package` of a `DESCRIPTION` this is no namespace, such a project is no package */
12
21
  abstract projectName(): string | undefined;
13
22
  /** `undefined` if the manifest only states a requirement like `>=4.0.0` */
@@ -50,7 +59,33 @@ export declare class FlowrUvrManifestFile extends FlowrManifestFile<DeepReadonly
50
59
  /** uvr usually states a requirement (`>=4.0.0`), which pins nothing; the `uvr.lock` holds the resolved version */
51
60
  rVersion(): string | undefined;
52
61
  declares(): DeclaredPackages;
53
- /** a table mapping the name to a bare requirement (`">=3.0.0"`, `"*"`) or to one with its origin (`{ version = ..., git = ... }`) */
54
- private packagesOf;
55
62
  }
63
+ /**
64
+ * The tables of a [rig](https://rig.r-lib.org/proj-guide.html) project manifest (`src/rproj.rs` of rig), of which a
65
+ * script states `[dependencies]` in its inline block.
66
+ */
67
+ interface RigManifest {
68
+ project?: {
69
+ name?: unknown;
70
+ };
71
+ dependencies?: unknown;
72
+ 'linking-dependencies'?: unknown;
73
+ 'dependency-groups'?: unknown;
74
+ 'optional-dependencies'?: unknown;
75
+ }
76
+ /** The `rproj.toml` of a [rig](https://rig.r-lib.org/proj-guide.html) project, lifted by {@link FlowrRigProjectFile.from}. */
77
+ export declare class FlowrRigProjectFile extends FlowrManifestFile<DeepReadonly<RigManifest>> {
78
+ protected loadContent(): RigManifest;
79
+ projectName(): string | undefined;
80
+ rVersion(): string | undefined;
81
+ declares(): DeclaredPackages;
82
+ }
83
+ /**
84
+ * The manifest a rig script states inline, read as rig reads it (`src/script_meta.rs` of rig): the one comment block
85
+ * opened by a line that is exactly `# /// script` (or `## /// script`), anywhere in the file, and closed by `# ///`
86
+ * with the same marker. Every line in between starts with that marker, and without it (and one space) the lines are
87
+ * TOML holding `[dependencies]`, `[[repository]]` and `[tool]`. As rig refuses to run the script otherwise, a second
88
+ * block, an unclosed block, a line without the marker, broken TOML or any other table declare nothing.
89
+ */
90
+ export declare function rigScriptManifest(code: string, origin: string): ProjectManifest | undefined;
56
91
  export {};
@@ -1,28 +1,65 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FlowrUvrManifestFile = exports.FlowrRProjectFile = exports.FlowrManifestFile = exports.manifestFileLog = void 0;
3
+ exports.FlowrRigProjectFile = exports.FlowrUvrManifestFile = exports.FlowrRProjectFile = exports.FlowrManifestFile = exports.manifestFileLog = void 0;
4
+ exports.rigScriptManifest = rigScriptManifest;
4
5
  const flowr_file_1 = require("../../../context/flowr-file");
5
6
  const package_1 = require("../../package-version-plugins/package");
6
7
  const smol_toml_1 = require("smol-toml");
7
8
  const log_1 = require("../../../../util/log");
8
9
  exports.manifestFileLog = log_1.log.getSubLogger({ name: 'flowr-manifest-file' });
9
10
  /**
10
- * A project manifest that is no `DESCRIPTION` (an rv `rproject.toml`, a uvr `uvr.toml`).
11
+ * A project manifest that is no `DESCRIPTION` (an rv `rproject.toml`, a uvr `uvr.toml`, a rig `rproj.toml`).
11
12
  * Prefer the static `from` method of the concrete subclass, which avoids re-wrapping and handles roles.
12
13
  */
13
14
  class FlowrManifestFile extends flowr_file_1.FlowrWrappedFile {
14
15
  /** the parsed TOML of the wrapped file, empty (with a warning) if it does not parse */
15
16
  parseTomlContent() {
16
- try {
17
- return (0, smol_toml_1.parse)(this.wrapped.content().toString());
18
- }
19
- catch (e) {
20
- exports.manifestFileLog.warn(`Could not parse ${this.wrapped.path()}: ${e.message}`);
21
- return {};
22
- }
17
+ return parseTomlOrEmpty(this.wrapped.content().toString(), this.wrapped.path());
23
18
  }
24
19
  }
25
20
  exports.FlowrManifestFile = FlowrManifestFile;
21
+ function parseTomlOrEmpty(toml, origin) {
22
+ try {
23
+ return (0, smol_toml_1.parse)(toml);
24
+ }
25
+ catch (e) {
26
+ exports.manifestFileLog.warn(`Could not parse ${origin}: ${e.message}`);
27
+ return {};
28
+ }
29
+ }
30
+ /** a requirement that starts with a version (`4.4`) pins one; `>= 4.4` or `*` only constrains */
31
+ function pinnedVersion(version) {
32
+ const trimmed = typeof version === 'string' ? version.trim() : '';
33
+ return /^\d/.test(trimmed) ? trimmed : undefined;
34
+ }
35
+ /**
36
+ * The entries of a table mapping a package name to a bare requirement (`">=3.0.0"`, `"*"`, `">= 1.0, < 2.0"`) or to
37
+ * one with its origin (`{ version = ..., git = ... }`), as uvr and rig write them. Anything else (an array such as
38
+ * rig's `include-groups`) names no package.
39
+ */
40
+ function dependencyEntries(table) {
41
+ // an array is no such table, and its indices would pass as package names
42
+ if (!isTable(table)) {
43
+ return [];
44
+ }
45
+ return Object.entries(table).filter((e) => e[0].length > 0 && (typeof e[1] === 'string' || isTable(e[1])));
46
+ }
47
+ function isTable(value) {
48
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
49
+ }
50
+ function packageOf([name, spec]) {
51
+ const version = typeof spec === 'string' ? spec : spec.version;
52
+ // `*` accepts anything, so it constrains nothing
53
+ const range = typeof version === 'string' && version !== '*' ? package_1.Package.parsePkgVersionRange(undefined, version) : undefined;
54
+ return new package_1.Package({ name, type: 'package', versionConstraints: range ? [range] : undefined });
55
+ }
56
+ function packagesOf(table) {
57
+ return dependencyEntries(table).map(packageOf);
58
+ }
59
+ /** the packages of every table in `groups` (`[dependency-groups.dev]`, `[optional-dependencies.plot]`) */
60
+ function packagesOfGroups(groups) {
61
+ return isTable(groups) ? Object.values(groups).flatMap(packagesOf) : [];
62
+ }
26
63
  /** The `rproject.toml` of an [rv](https://a2-ai.github.io/rv-docs/) project, lifted by {@link FlowrRProjectFile.from}. */
27
64
  class FlowrRProjectFile extends FlowrManifestFile {
28
65
  loadContent() {
@@ -69,34 +106,101 @@ class FlowrUvrManifestFile extends FlowrManifestFile {
69
106
  }
70
107
  /** uvr usually states a requirement (`>=4.0.0`), which pins nothing; the `uvr.lock` holds the resolved version */
71
108
  rVersion() {
72
- const version = this.content().project?.r_version;
73
- const trimmed = typeof version === 'string' ? version.trim() : '';
74
- return /^\d/.test(trimmed) ? trimmed : undefined;
109
+ return pinnedVersion(this.content().project?.r_version);
75
110
  }
76
111
  declares() {
77
112
  return {
78
- imports: this.packagesOf(this.content().dependencies),
79
- suggests: this.packagesOf(this.content()['dev-dependencies'])
113
+ imports: packagesOf(this.content().dependencies),
114
+ suggests: packagesOf(this.content()['dev-dependencies'])
80
115
  };
81
116
  }
82
- /** a table mapping the name to a bare requirement (`">=3.0.0"`, `"*"`) or to one with its origin (`{ version = ..., git = ... }`) */
83
- packagesOf(table) {
84
- // an array is no such table, and its indices would pass as package names
85
- if (typeof table !== 'object' || table === null || Array.isArray(table)) {
86
- return [];
117
+ }
118
+ exports.FlowrUvrManifestFile = FlowrUvrManifestFile;
119
+ function rigRVersion(manifest) {
120
+ const deps = manifest.dependencies;
121
+ return isTable(deps) ? pinnedVersion(deps.R) : undefined;
122
+ }
123
+ /**
124
+ * Grouped as a `DESCRIPTION` groups them: `R` in `[dependencies]` is the requirement on R itself (`Depends`), an entry
125
+ * marked `enhances = true` is an `Enhances`, `[linking-dependencies]` is `LinkingTo`. Dependency groups and optional
126
+ * dependencies are reported but not needed to run the project, like `Suggests`.
127
+ */
128
+ function rigDeclares(manifest) {
129
+ const deps = dependencyEntries(manifest.dependencies);
130
+ const enhances = (e) => typeof e[1] !== 'string' && e[1].enhances === true;
131
+ return {
132
+ depends: deps.filter(e => e[0] === 'R').map(packageOf),
133
+ imports: deps.filter(e => e[0] !== 'R' && !enhances(e)).map(packageOf),
134
+ enhances: deps.filter(enhances).map(packageOf),
135
+ linkingTo: packagesOf(manifest['linking-dependencies']),
136
+ suggests: [...packagesOfGroups(manifest['dependency-groups']), ...packagesOfGroups(manifest['optional-dependencies'])]
137
+ };
138
+ }
139
+ /** The `rproj.toml` of a [rig](https://rig.r-lib.org/proj-guide.html) project, lifted by {@link FlowrRigProjectFile.from}. */
140
+ class FlowrRigProjectFile extends FlowrManifestFile {
141
+ loadContent() {
142
+ return this.parseTomlContent();
143
+ }
144
+ projectName() {
145
+ const name = this.content().project?.name;
146
+ return typeof name === 'string' ? name : undefined;
147
+ }
148
+ rVersion() {
149
+ return rigRVersion(this.content());
150
+ }
151
+ declares() {
152
+ return rigDeclares(this.content());
153
+ }
154
+ }
155
+ exports.FlowrRigProjectFile = FlowrRigProjectFile;
156
+ /** the comment markers a rig script block may use, `##` first as `#` is its prefix */
157
+ const RigBlockMarkers = ['##', '#'];
158
+ /** the only tables a script block may hold, rig rejects the script for any other */
159
+ const RigScriptTables = new Set(['dependencies', 'repository', 'tool']);
160
+ /**
161
+ * The manifest a rig script states inline, read as rig reads it (`src/script_meta.rs` of rig): the one comment block
162
+ * opened by a line that is exactly `# /// script` (or `## /// script`), anywhere in the file, and closed by `# ///`
163
+ * with the same marker. Every line in between starts with that marker, and without it (and one space) the lines are
164
+ * TOML holding `[dependencies]`, `[[repository]]` and `[tool]`. As rig refuses to run the script otherwise, a second
165
+ * block, an unclosed block, a line without the marker, broken TOML or any other table declare nothing.
166
+ */
167
+ function rigScriptManifest(code, origin) {
168
+ const lines = code.split('\n').map(l => l.replace(/\r$/, ''));
169
+ const opens = lines.flatMap((line, i) => {
170
+ const marker = RigBlockMarkers.find(m => line.trimEnd() === `${m} /// script`);
171
+ return marker === undefined ? [] : [{ i, marker }];
172
+ });
173
+ if (opens.length !== 1) {
174
+ return undefined;
175
+ }
176
+ const { i: start, marker } = opens[0];
177
+ const body = [];
178
+ for (const line of lines.slice(start + 1)) {
179
+ if (line.trimEnd() === `${marker} ///`) {
180
+ return rigScriptOf(body.join('\n'), origin);
87
181
  }
88
- const out = [];
89
- for (const [name, spec] of Object.entries(table)) {
90
- if (name.length === 0) {
91
- continue;
92
- }
93
- const version = typeof spec === 'string' ? spec : spec?.version;
94
- // `*` accepts anything, so it constrains nothing
95
- const range = typeof version === 'string' && version !== '*' ? package_1.Package.parsePkgVersionRange(undefined, version) : undefined;
96
- out.push(new package_1.Package({ name, type: 'package', versionConstraints: range ? [range] : undefined }));
182
+ if (!line.startsWith(marker)) {
183
+ return undefined;
97
184
  }
98
- return out;
185
+ const rest = line.slice(marker.length);
186
+ body.push(rest.startsWith(' ') ? rest.slice(1) : rest);
99
187
  }
188
+ return undefined;
189
+ }
190
+ function rigScriptOf(toml, origin) {
191
+ let parsed;
192
+ try {
193
+ parsed = (0, smol_toml_1.parse)(toml);
194
+ }
195
+ catch (e) {
196
+ exports.manifestFileLog.warn(`Could not parse the rig script block of ${origin}: ${e.message}`);
197
+ return undefined;
198
+ }
199
+ if (Object.keys(parsed).some(k => !RigScriptTables.has(k))) {
200
+ exports.manifestFileLog.warn(`The rig script block of ${origin} holds a table rig does not allow, rig would not run it`);
201
+ return undefined;
202
+ }
203
+ const manifest = { dependencies: parsed.dependencies };
204
+ return { projectName: () => undefined, rVersion: () => rigRVersion(manifest), declares: () => rigDeclares(manifest) };
100
205
  }
101
- exports.FlowrUvrManifestFile = FlowrUvrManifestFile;
102
206
  //# sourceMappingURL=flowr-manifest-files.js.map
@@ -77,7 +77,7 @@ class FlowrRMarkdownFile extends flowr_file_1.FlowrFile {
77
77
  ctx: this.context,
78
78
  referenceChain: [this.path()]
79
79
  });
80
- if (childPath === undefined) {
80
+ if (childPath === undefined || childPath.length === 0) {
81
81
  continue;
82
82
  }
83
83
  if (childPath.length > 1) {
@@ -23,4 +23,11 @@ export declare class FlowrAnalyzerUvrManifestFilePlugin extends FlowrAnalyzerMan
23
23
  constructor(pathPattern?: RegExp);
24
24
  process(_ctx: FlowrAnalyzerContext, file: FlowrFileProvider): [FlowrFileProvider, true];
25
25
  }
26
+ /** Lifts a rig `rproj.toml` to a {@link FlowrRigProjectFile}. */
27
+ export declare class FlowrAnalyzerRigProjectFilePlugin extends FlowrAnalyzerManifestFilePlugin {
28
+ readonly name = "flowr-analyzer-rig-project-file-plugin";
29
+ readonly description = "Marks the rproj.toml manifest of a rig project.";
30
+ constructor(pathPattern?: RegExp);
31
+ process(_ctx: FlowrAnalyzerContext, file: FlowrFileProvider): [FlowrFileProvider, true];
32
+ }
26
33
  export {};
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FlowrAnalyzerUvrManifestFilePlugin = exports.FlowrAnalyzerRProjectFilePlugin = void 0;
3
+ exports.FlowrAnalyzerRigProjectFilePlugin = exports.FlowrAnalyzerUvrManifestFilePlugin = exports.FlowrAnalyzerRProjectFilePlugin = void 0;
4
4
  const flowr_analyzer_file_plugin_1 = require("./flowr-analyzer-file-plugin");
5
5
  const semver_1 = require("semver");
6
6
  const flowr_file_1 = require("../../context/flowr-file");
7
7
  const flowr_manifest_files_1 = require("./files/flowr-manifest-files");
8
8
  const RProjectFilePattern = /^rproject\.toml$/i;
9
9
  const UvrManifestFilePattern = /^uvr\.toml$/i;
10
+ const RigProjectFilePattern = /^rproj\.toml$/i;
10
11
  /**
11
12
  * Tags a project manifest with the {@link FileRole.Manifest} role and lifts it, so the meta plugins reading it
12
13
  * can look it up by role.
@@ -38,4 +39,16 @@ class FlowrAnalyzerUvrManifestFilePlugin extends FlowrAnalyzerManifestFilePlugin
38
39
  }
39
40
  }
40
41
  exports.FlowrAnalyzerUvrManifestFilePlugin = FlowrAnalyzerUvrManifestFilePlugin;
42
+ /** Lifts a rig `rproj.toml` to a {@link FlowrRigProjectFile}. */
43
+ class FlowrAnalyzerRigProjectFilePlugin extends FlowrAnalyzerManifestFilePlugin {
44
+ name = 'flowr-analyzer-rig-project-file-plugin';
45
+ description = 'Marks the rproj.toml manifest of a rig project.';
46
+ constructor(pathPattern = RigProjectFilePattern) {
47
+ super(pathPattern);
48
+ }
49
+ process(_ctx, file) {
50
+ return [flowr_manifest_files_1.FlowrRigProjectFile.from(file, flowr_file_1.FileRole.Manifest), true];
51
+ }
52
+ }
53
+ exports.FlowrAnalyzerRigProjectFilePlugin = FlowrAnalyzerRigProjectFilePlugin;
41
54
  //# sourceMappingURL=flowr-analyzer-manifest-file-plugin.js.map
@@ -7,7 +7,7 @@ import { FileRole } from '../../context/flowr-file';
7
7
  */
8
8
  export declare class FlowrAnalyzerVirtualEnvFilePlugin extends FlowrAnalyzerRoleFilePlugin {
9
9
  readonly name = "flowr-analyzer-virtualenv-files-plugin";
10
- readonly description = "Marks virtual-environment lockfiles (renv.lock, rv.lock, uvr.lock).";
10
+ readonly description = "Marks virtual-environment lockfiles (renv.lock, rv.lock, uvr.lock, packrat.lock, rig lockfiles).";
11
11
  readonly version: SemVer;
12
12
  protected readonly roles: FileRole[];
13
13
  /**
@@ -4,15 +4,15 @@ exports.FlowrAnalyzerVirtualEnvFilePlugin = void 0;
4
4
  const flowr_analyzer_file_plugin_1 = require("./flowr-analyzer-file-plugin");
5
5
  const semver_1 = require("semver");
6
6
  const flowr_file_1 = require("../../context/flowr-file");
7
- /** Lockfiles pinning a project's package environment (`renv.lock`, `rv.lock`, `uvr.lock`, `packrat.lock`). */
8
- const VirtualEnvFilePattern = /^(renv|rv|uvr|packrat)\.lock$/i;
7
+ /** Lockfiles pinning a project's package environment (`renv.lock`, `rv.lock`, `uvr.lock`, `packrat.lock`, rig's `rproj.lock` and `<script>.R.lock`). */
8
+ const VirtualEnvFilePattern = /^(renv|rv|uvr|packrat|rproj|.+\.r)\.lock$/i;
9
9
  /**
10
10
  * Tags a project's virtual-environment lockfiles with the {@link FileRole.VirtualEnv} role, so the version
11
11
  * plugins that read them can look them up by role instead of scanning every project file.
12
12
  */
13
13
  class FlowrAnalyzerVirtualEnvFilePlugin extends flowr_analyzer_file_plugin_1.FlowrAnalyzerRoleFilePlugin {
14
14
  name = 'flowr-analyzer-virtualenv-files-plugin';
15
- description = 'Marks virtual-environment lockfiles (renv.lock, rv.lock, uvr.lock).';
15
+ description = 'Marks virtual-environment lockfiles (renv.lock, rv.lock, uvr.lock, packrat.lock, rig lockfiles).';
16
16
  version = new semver_1.SemVer('0.1.0');
17
17
  roles = [flowr_file_1.FileRole.VirtualEnv];
18
18
  /**
@@ -1,11 +1,8 @@
1
1
  import { FlowrAnalyzerPackageVersionsPlugin } from './flowr-analyzer-package-versions-plugin';
2
2
  import { SemVer } from 'semver';
3
3
  import type { FlowrAnalyzerContext } from '../../context/flowr-analyzer-context';
4
- import { FlowrRProjectFile, FlowrUvrManifestFile } from '../file-plugins/files/flowr-manifest-files';
5
- /**
6
- * Extracts the project metadata and the declared dependencies from a project manifest. The name is contributed
7
- * without a namespace: such a project is no package, so `a::b` must not resolve against it.
8
- */
4
+ import { FlowrRigProjectFile, FlowrRProjectFile, FlowrUvrManifestFile } from '../file-plugins/files/flowr-manifest-files';
5
+ /** Extracts the project metadata and the declared dependencies from a project manifest. */
9
6
  declare abstract class FlowrAnalyzerMetaManifestFilePlugin extends FlowrAnalyzerPackageVersionsPlugin {
10
7
  readonly version: SemVer;
11
8
  /** the manifest flavor this plugin reads, the others are left to their own plugin */
@@ -24,4 +21,20 @@ export declare class FlowrAnalyzerMetaUvrManifestFilePlugin extends FlowrAnalyze
24
21
  readonly description = "Extracts project meta information and dependencies from a uvr.toml.";
25
22
  protected readonly reads: typeof FlowrUvrManifestFile;
26
23
  }
24
+ /** Reads a rig `rproj.toml`, whose dependency groups and optional dependencies land in `suggests`. */
25
+ export declare class FlowrAnalyzerMetaRigProjectFilePlugin extends FlowrAnalyzerMetaManifestFilePlugin {
26
+ readonly name = "flowr-analyzer-meta-rig-project-file-plugin";
27
+ readonly description = "Extracts project meta information and dependencies from a rig rproj.toml.";
28
+ protected readonly reads: typeof FlowrRigProjectFile;
29
+ }
30
+ /**
31
+ * Reads the inline `# /// script` block a rig script states its dependencies in (see {@link rigScriptManifest}),
32
+ * in R scripts and notebooks alike, as the code of a notebook is what its top is checked for.
33
+ */
34
+ export declare class FlowrAnalyzerMetaRigScriptPlugin extends FlowrAnalyzerPackageVersionsPlugin {
35
+ readonly name = "flowr-analyzer-meta-rig-script-plugin";
36
+ readonly description = "Extracts the dependencies a rig script declares in its inline # /// script block.";
37
+ readonly version: SemVer;
38
+ process(ctx: FlowrAnalyzerContext): void;
39
+ }
27
40
  export {};
@@ -1,31 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FlowrAnalyzerMetaUvrManifestFilePlugin = exports.FlowrAnalyzerMetaRProjectFilePlugin = void 0;
3
+ exports.FlowrAnalyzerMetaRigScriptPlugin = exports.FlowrAnalyzerMetaRigProjectFilePlugin = exports.FlowrAnalyzerMetaUvrManifestFilePlugin = exports.FlowrAnalyzerMetaRProjectFilePlugin = void 0;
4
4
  const flowr_analyzer_package_versions_plugin_1 = require("./flowr-analyzer-package-versions-plugin");
5
5
  const semver_1 = require("semver");
6
6
  const flowr_file_1 = require("../../context/flowr-file");
7
7
  const flowr_analyzer_meta_context_1 = require("../../context/flowr-analyzer-meta-context");
8
8
  const flowr_manifest_files_1 = require("../file-plugins/files/flowr-manifest-files");
9
9
  /**
10
- * Extracts the project metadata and the declared dependencies from a project manifest. The name is contributed
11
- * without a namespace: such a project is no package, so `a::b` must not resolve against it.
10
+ * Contributes what a manifest declares: its metadata, and the packages needed to run the project. The name is
11
+ * contributed without a namespace, such a project is no package, so `a::b` must not resolve against it.
12
12
  */
13
+ function contributeManifest(ctx, manifest) {
14
+ const declares = manifest.declares();
15
+ ctx.meta.contribute({
16
+ name: manifest.projectName(),
17
+ rVersion: manifest.rVersion(),
18
+ declares
19
+ }, flowr_analyzer_meta_context_1.MetaPriority.Manifest);
20
+ // like a `DESCRIPTION` `Suggests`, anything but the imports (and depends) is reported but not needed to run the project
21
+ for (const pkg of [...declares.depends ?? [], ...declares.imports ?? []]) {
22
+ ctx.deps.addDeclaredDependency(pkg);
23
+ }
24
+ }
25
+ /** Extracts the project metadata and the declared dependencies from a project manifest. */
13
26
  class FlowrAnalyzerMetaManifestFilePlugin extends flowr_analyzer_package_versions_plugin_1.FlowrAnalyzerPackageVersionsPlugin {
14
27
  version = new semver_1.SemVer('0.1.0');
15
28
  process(ctx) {
16
29
  for (const file of ctx.files.getFilesByRole(flowr_file_1.FileRole.Manifest)) {
17
- if (!(file instanceof this.reads)) {
18
- continue;
19
- }
20
- const declares = file.declares();
21
- ctx.meta.contribute({
22
- name: file.projectName(),
23
- rVersion: file.rVersion(),
24
- declares
25
- }, flowr_analyzer_meta_context_1.MetaPriority.Manifest);
26
- // like a `DESCRIPTION` `Suggests`, anything but the imports is reported but not needed to run the project
27
- for (const pkg of declares.imports ?? []) {
28
- ctx.deps.addDeclaredDependency(pkg);
30
+ if (file instanceof this.reads) {
31
+ contributeManifest(ctx, file);
29
32
  }
30
33
  }
31
34
  }
@@ -44,4 +47,29 @@ class FlowrAnalyzerMetaUvrManifestFilePlugin extends FlowrAnalyzerMetaManifestFi
44
47
  reads = flowr_manifest_files_1.FlowrUvrManifestFile;
45
48
  }
46
49
  exports.FlowrAnalyzerMetaUvrManifestFilePlugin = FlowrAnalyzerMetaUvrManifestFilePlugin;
50
+ /** Reads a rig `rproj.toml`, whose dependency groups and optional dependencies land in `suggests`. */
51
+ class FlowrAnalyzerMetaRigProjectFilePlugin extends FlowrAnalyzerMetaManifestFilePlugin {
52
+ name = 'flowr-analyzer-meta-rig-project-file-plugin';
53
+ description = 'Extracts project meta information and dependencies from a rig rproj.toml.';
54
+ reads = flowr_manifest_files_1.FlowrRigProjectFile;
55
+ }
56
+ exports.FlowrAnalyzerMetaRigProjectFilePlugin = FlowrAnalyzerMetaRigProjectFilePlugin;
57
+ /**
58
+ * Reads the inline `# /// script` block a rig script states its dependencies in (see {@link rigScriptManifest}),
59
+ * in R scripts and notebooks alike, as the code of a notebook is what its top is checked for.
60
+ */
61
+ class FlowrAnalyzerMetaRigScriptPlugin extends flowr_analyzer_package_versions_plugin_1.FlowrAnalyzerPackageVersionsPlugin {
62
+ name = 'flowr-analyzer-meta-rig-script-plugin';
63
+ description = 'Extracts the dependencies a rig script declares in its inline # /// script block.';
64
+ version = new semver_1.SemVer('0.1.0');
65
+ process(ctx) {
66
+ for (const file of ctx.files.getFilesByRole(flowr_file_1.FileRole.Source)) {
67
+ const manifest = (0, flowr_manifest_files_1.rigScriptManifest)(file.content().toString(), file.path());
68
+ if (manifest !== undefined) {
69
+ contributeManifest(ctx, manifest);
70
+ }
71
+ }
72
+ }
73
+ }
74
+ exports.FlowrAnalyzerMetaRigScriptPlugin = FlowrAnalyzerMetaRigScriptPlugin;
47
75
  //# sourceMappingURL=flowr-analyzer-meta-manifest-file-plugin.js.map
@@ -32,3 +32,15 @@ export declare class FlowrAnalyzerPackageVersionsUvrPlugin extends FlowrAnalyzer
32
32
  readonly version: SemVer;
33
33
  process(ctx: FlowrAnalyzerContext): void;
34
34
  }
35
+ /** a rig lockfile: the project's `rproj.lock`, or `analysis.R.lock` beside the script `analysis.R` */
36
+ export declare const RigLockFilePattern: RegExp;
37
+ /**
38
+ * Reads package versions from a rig lockfile (TOML). rig solves one target per R version and platform, and the
39
+ * targets may pin a package (or R) differently, so only what all targets listing it agree on is a pin.
40
+ */
41
+ export declare class FlowrAnalyzerPackageVersionsRigPlugin extends FlowrAnalyzerPackageVersionsPlugin {
42
+ readonly name = "flowr-analyzer-package-versions-rig-plugin";
43
+ readonly description = "Extracts package versions from a rig rproj.lock or script lockfile.";
44
+ readonly version: SemVer;
45
+ process(ctx: FlowrAnalyzerContext): void;
46
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FlowrAnalyzerPackageVersionsUvrPlugin = exports.FlowrAnalyzerPackageVersionsRvPlugin = exports.FlowrAnalyzerPackageVersionsPackratPlugin = exports.FlowrAnalyzerPackageVersionsRenvPlugin = exports.lockfileLog = void 0;
3
+ exports.FlowrAnalyzerPackageVersionsRigPlugin = exports.RigLockFilePattern = exports.FlowrAnalyzerPackageVersionsUvrPlugin = exports.FlowrAnalyzerPackageVersionsRvPlugin = exports.FlowrAnalyzerPackageVersionsPackratPlugin = exports.FlowrAnalyzerPackageVersionsRenvPlugin = exports.lockfileLog = void 0;
4
4
  exports.pin = pin;
5
5
  const flowr_analyzer_package_versions_plugin_1 = require("./flowr-analyzer-package-versions-plugin");
6
6
  const semver_1 = require("semver");
@@ -14,7 +14,10 @@ const flowr_description_file_1 = require("../file-plugins/files/flowr-descriptio
14
14
  exports.lockfileLog = log_1.log.getSubLogger({ name: 'flowr-analyzer-package-versions-lockfile-plugin' });
15
15
  /** The {@link FileRole.VirtualEnv} lockfiles named `name` (e.g. `renv.lock`), matched case-insensitively like the role is assigned. */
16
16
  function virtualEnvFiles(ctx, name) {
17
- return ctx.files.getFilesByRole(flowr_file_1.FileRole.VirtualEnv).filter(f => (0, built_in_source_1.platformBasename)(f.path()).toLowerCase() === name);
17
+ return ctx.files.getFilesByRole(flowr_file_1.FileRole.VirtualEnv).filter(f => {
18
+ const base = (0, built_in_source_1.platformBasename)(f.path());
19
+ return typeof name === 'string' ? base.toLowerCase() === name : name.test(base);
20
+ });
18
21
  }
19
22
  /** Declares the dependency `name` pinned to the given `version`. */
20
23
  function pin(ctx, name, version) {
@@ -113,4 +116,30 @@ class FlowrAnalyzerPackageVersionsUvrPlugin extends flowr_analyzer_package_versi
113
116
  }
114
117
  }
115
118
  exports.FlowrAnalyzerPackageVersionsUvrPlugin = FlowrAnalyzerPackageVersionsUvrPlugin;
119
+ /** a rig lockfile: the project's `rproj.lock`, or `analysis.R.lock` beside the script `analysis.R` */
120
+ exports.RigLockFilePattern = /^(rproj|.+\.r)\.lock$/i;
121
+ /**
122
+ * Reads package versions from a rig lockfile (TOML). rig solves one target per R version and platform, and the
123
+ * targets may pin a package (or R) differently, so only what all targets listing it agree on is a pin.
124
+ */
125
+ class FlowrAnalyzerPackageVersionsRigPlugin extends flowr_analyzer_package_versions_plugin_1.FlowrAnalyzerPackageVersionsPlugin {
126
+ name = 'flowr-analyzer-package-versions-rig-plugin';
127
+ description = 'Extracts package versions from a rig rproj.lock or script lockfile.';
128
+ version = new semver_1.SemVer('0.1.0');
129
+ process(ctx) {
130
+ pinFromTomlLock(ctx, exports.RigLockFilePattern, lock => {
131
+ const targets = Array.isArray(lock.targets) ? lock.targets : [];
132
+ const versions = new Map();
133
+ for (const p of targets.flatMap((t) => Array.isArray(t.packages) ? t.packages : [])) {
134
+ (versions.get(p.package) ?? versions.set(p.package, new Set()).get(p.package))?.add(p.version);
135
+ }
136
+ const rVersions = new Set(targets.map(t => t.r_version));
137
+ return {
138
+ rVersion: rVersions.size === 1 ? [...rVersions][0] : undefined,
139
+ packages: [...versions].filter(([, vs]) => vs.size === 1).map(([name, vs]) => ({ name, version: [...vs][0] }))
140
+ };
141
+ });
142
+ }
143
+ }
144
+ exports.FlowrAnalyzerPackageVersionsRigPlugin = FlowrAnalyzerPackageVersionsRigPlugin;
116
145
  //# sourceMappingURL=flowr-analyzer-package-versions-lockfile-plugin.js.map
@@ -0,0 +1,58 @@
1
+ import { SemVer } from 'semver';
2
+ import { FlowrAnalyzerPackageVersionsPlugin } from './flowr-analyzer-package-versions-plugin';
3
+ import type { FlowrAnalyzerContext } from '../../context/flowr-analyzer-context';
4
+ import type { NormalizedAst } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
5
+ import type { PackageSignatureSource } from '../../sigdb/reader';
6
+ import { type OnDemandOptions } from '../../sigdb/on-demand/recoverer';
7
+ import { type FetchBytes, type OnDemandSource } from '../../sigdb/on-demand/remote-sources';
8
+ import type { BuiltInIndex } from '../../../dataflow/environments/query-fn-props';
9
+ /** What the code says about the packages it uses: their names, and the repositories it installs some of them from. */
10
+ export declare function packagesNamedIn(ast: NormalizedAst): {
11
+ names: Set<string>;
12
+ github: Map<string, string>;
13
+ };
14
+ /**
15
+ * The names of the security-relevant built-ins, see {@link SecurityRelevant}, and of those with an argument open
16
+ * to injection or naming a resource. A package flowR fetched on demand is no package anyone vetted, so it may not
17
+ * export one of these: `library(evil)` exporting `system` would otherwise turn every later `system(cmd)` into a
18
+ * call of `evil::system`, which no analysis looking for `system` would see.
19
+ */
20
+ export declare function shieldedNames(index: BuiltInIndex): ReadonlySet<string>;
21
+ /**
22
+ * Recovers packages no signature database knows from their sources when the analyzed code uses them: before the
23
+ * dataflow is built it fetches the source of every package the code loads or names with `::` that nothing else
24
+ * resolves, from GitHub (the repository the project installs it from or the configuration names), CRAN, or
25
+ * Bioconductor, and serves their exports and the formals of their functions. Off unless
26
+ * `solver.sigdb.onDemand.enabled` says otherwise, never in secure mode, and only for packages nothing else knows.
27
+ * Further sources come in through the constructor.
28
+ */
29
+ export declare class FlowrAnalyzerPackageVersionsOnDemandPlugin extends FlowrAnalyzerPackageVersionsPlugin {
30
+ readonly name = "flowr-analyzer-package-versions-on-demand-plugin";
31
+ readonly description = "Fetches the sources of packages no database knows from CRAN, Bioconductor, or GitHub.";
32
+ readonly version: SemVer;
33
+ private readonly overrides?;
34
+ private readonly extraSources;
35
+ private readonly fetchBytes;
36
+ private readonly recovered;
37
+ private source;
38
+ private recoverer;
39
+ private parser;
40
+ private shielded;
41
+ /**
42
+ * @param overrides - options replacing what `solver.sigdb.onDemand` states, `enabled` included
43
+ * @param extraSources - sources besides the built-in ones, used where `sources` lists their name (or after the listed ones if it does not)
44
+ * @param fetchBytes - how to download, HTTPS to public hosts and the configured mirrors by default
45
+ */
46
+ constructor(overrides?: Partial<OnDemandOptions>, extraSources?: readonly OnDemandSource[], fetchBytes?: FetchBytes);
47
+ private optionsOf;
48
+ private sourcesOf;
49
+ private recovererOf;
50
+ /** whether the options allow recovering `name` at all */
51
+ private static wanted;
52
+ /** keeps the package, without the exports that would take over a security-relevant built-in, see {@link shieldedNames} */
53
+ private remember;
54
+ process(ctx: FlowrAnalyzerContext): void;
55
+ prepare(ctx: FlowrAnalyzerContext, ast: NormalizedAst): Promise<void>;
56
+ signatureSources(): readonly PackageSignatureSource[];
57
+ packagesExporting(name: string): readonly string[];
58
+ }