@eagleoutice/flowr 2.17.7 → 2.17.9

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 (123) hide show
  1. package/abstract-interpretation/branch-paths.d.ts +10 -0
  2. package/abstract-interpretation/branch-paths.js +104 -10
  3. package/config.d.ts +1 -1
  4. package/config.js +40 -8
  5. package/control-flow/control-flow-graph.js +18 -2
  6. package/data/r-base-guards.generated.js +2 -2
  7. package/dataflow/environments/ambient-effect.js +4 -1
  8. package/dataflow/environments/built-in-props.d.ts +8 -2
  9. package/dataflow/environments/built-in-props.js +16 -5
  10. package/dataflow/environments/default-builtin-config/base-functions.js +1 -1
  11. package/dataflow/environments/default-builtin-config/guards.d.ts +1 -1
  12. package/dataflow/environments/default-builtin-config/guards.js +28 -0
  13. package/dataflow/environments/default-builtin-config/index.d.ts +8 -4
  14. package/dataflow/environments/default-builtin-config/index.js +9 -5
  15. package/dataflow/environments/default-builtin-config/parallel-execution.d.ts +1 -1
  16. package/dataflow/environments/default-builtin-config/parallel-execution.js +25 -0
  17. package/dataflow/environments/guard-facts.d.ts +28 -1
  18. package/dataflow/environments/pkg-name.d.ts +2 -0
  19. package/dataflow/environments/query-fn-props.d.ts +19 -15
  20. package/dataflow/environments/query-fn-props.js +46 -36
  21. package/dataflow/environments/removal-marker.d.ts +1 -1
  22. package/dataflow/environments/removal-marker.js +18 -3
  23. package/dataflow/environments/reserved-names.d.ts +6 -0
  24. package/dataflow/environments/reserved-names.js +14 -0
  25. package/dataflow/environments/resolve-by-name.js +5 -10
  26. package/dataflow/eval/resolve/alias-tracking.js +23 -6
  27. package/dataflow/extractor.js +103 -28
  28. package/dataflow/fn/argument-roles.d.ts +3 -0
  29. package/dataflow/fn/argument-roles.js +5 -5
  30. package/dataflow/fn/exceptions-of-function.d.ts +7 -0
  31. package/dataflow/fn/exceptions-of-function.js +15 -2
  32. package/dataflow/fn/function-props.d.ts +1 -1
  33. package/dataflow/fn/function-props.js +40 -18
  34. package/dataflow/fn/function-semantics.d.ts +3 -1
  35. package/dataflow/fn/function-semantics.js +2 -0
  36. package/dataflow/fn/guards/built-in-guards.js +2 -1
  37. package/dataflow/fn/guards/condition-grouping.d.ts +11 -0
  38. package/dataflow/fn/guards/condition-grouping.js +50 -3
  39. package/dataflow/fn/guards/function-guards.d.ts +10 -0
  40. package/dataflow/fn/guards/function-guards.js +130 -14
  41. package/dataflow/fn/guards/guard-claims.d.ts +2 -0
  42. package/dataflow/fn/guards/guard-claims.js +42 -2
  43. package/dataflow/fn/guards/guard-knowledge.d.ts +7 -1
  44. package/dataflow/fn/guards/guard-knowledge.js +50 -4
  45. package/dataflow/fn/guards/guard-term.js +10 -1
  46. package/dataflow/fn/higher-order-function.d.ts +15 -1
  47. package/dataflow/fn/higher-order-function.js +54 -10
  48. package/dataflow/graph/call-graph.d.ts +5 -0
  49. package/dataflow/graph/call-graph.js +51 -15
  50. package/dataflow/graph/df-helper.d.ts +2 -0
  51. package/dataflow/graph/df-helper.js +4 -2
  52. package/dataflow/graph/graph.d.ts +21 -0
  53. package/dataflow/graph/graph.js +63 -2
  54. package/dataflow/internal/linker.d.ts +20 -0
  55. package/dataflow/internal/linker.js +190 -24
  56. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +20 -12
  57. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +5 -3
  58. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +2 -1
  59. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +2 -0
  60. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +5 -0
  61. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +7 -3
  62. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +12 -5
  63. package/dataflow/internal/process/functions/call/deferred.d.ts +7 -2
  64. package/dataflow/internal/process/functions/call/deferred.js +63 -28
  65. package/dataflow/internal/process/functions/call/quoted.js +33 -7
  66. package/documentation/data/dfg/doc-ambient.js +3 -1
  67. package/documentation/wiki-normalized-ast.js +1 -1
  68. package/documentation/wiki-query.js +9 -3
  69. package/package.json +5 -3
  70. package/project/context/flowr-analyzer-context.d.ts +7 -4
  71. package/project/context/flowr-analyzer-context.js +8 -3
  72. package/project/context/flowr-analyzer-files-context.js +1 -0
  73. package/project/context/flowr-analyzer-functions-context.d.ts +2 -1
  74. package/project/context/flowr-analyzer-functions-context.js +9 -8
  75. package/project/flowr-analyzer.d.ts +7 -4
  76. package/project/flowr-analyzer.js +37 -8
  77. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +22 -0
  78. package/project/plugins/file-plugins/files/flowr-namespace-file.js +34 -0
  79. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +4 -1
  80. package/project/plugins/plugin-registry.d.ts +2 -2
  81. package/project/plugins/plugin-registry.js +1 -1
  82. package/project/sigdb/build.js +41 -2
  83. package/project/sigdb/decode.d.ts +3 -1
  84. package/project/sigdb/decode.js +45 -1
  85. package/project/sigdb/decompress.d.ts +5 -0
  86. package/project/sigdb/decompress.js +17 -1
  87. package/project/sigdb/manifest.d.ts +2 -1
  88. package/project/sigdb/manifest.js +12 -5
  89. package/project/sigdb/native-routines.d.ts +82 -0
  90. package/project/sigdb/native-routines.js +178 -0
  91. package/project/sigdb/reader.d.ts +21 -3
  92. package/project/sigdb/reader.js +35 -3
  93. package/project/sigdb/schema.d.ts +107 -3
  94. package/project/sigdb/schema.js +8 -2
  95. package/project/sigdb/sigdb-download.js +1 -1
  96. package/project/sigdb/sigdb-version.d.ts +7 -1
  97. package/project/sigdb/sigdb-version.js +12 -9
  98. package/project/sigdb/spec-query.d.ts +9 -4
  99. package/project/sigdb/spec-query.js +71 -45
  100. package/queries/catalog/call-context-query/call-context-query-executor.js +76 -29
  101. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.js +1 -12
  102. package/queries/catalog/inspect-fn-guards-query/inspect-fn-guards-query-format.d.ts +3 -0
  103. package/queries/catalog/inspect-fn-guards-query/inspect-fn-guards-query-format.js +3 -2
  104. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.d.ts +3 -0
  105. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.js +3 -2
  106. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.js +3 -1
  107. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.js +4 -2
  108. package/queries/catalog/signature-query/signature-query-executor.js +6 -2
  109. package/queries/catalog/signature-query/signature-query-format.d.ts +4 -0
  110. package/util/collections/bounded-map.d.ts +9 -0
  111. package/util/collections/bounded-map.js +22 -0
  112. package/util/collections/defaultmap.d.ts +5 -0
  113. package/util/collections/defaultmap.js +10 -0
  114. package/util/fixpoint.d.ts +6 -1
  115. package/util/fixpoint.js +45 -3
  116. package/util/flowr-version.d.ts +1 -1
  117. package/util/flowr-version.js +2 -2
  118. package/util/global-caches.d.ts +26 -0
  119. package/util/global-caches.js +43 -0
  120. package/util/monoid.js +2 -2
  121. package/util/quads.js +11 -3
  122. package/util/r-package-urls.d.ts +19 -0
  123. package/util/r-package-urls.js +41 -0
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BoundedMap = void 0;
4
+ /**
5
+ * A map that starts over once it holds {@link cap} entries, for memos whose keys come from the analyzed code
6
+ * and would otherwise grow with every program a long-running flowR sees.
7
+ */
8
+ class BoundedMap extends Map {
9
+ cap;
10
+ constructor(cap) {
11
+ super();
12
+ this.cap = cap;
13
+ }
14
+ set(key, value) {
15
+ if (this.size >= this.cap && !this.has(key)) {
16
+ this.clear();
17
+ }
18
+ return super.set(key, value);
19
+ }
20
+ }
21
+ exports.BoundedMap = BoundedMap;
22
+ //# sourceMappingURL=bounded-map.js.map
@@ -36,3 +36,8 @@ export declare class DefaultMap<K, V = K> {
36
36
  export declare function memoize<K, V>(fn: (key: K) => V, reentry?: {
37
37
  readonly answer: V;
38
38
  }): (key: K) => V;
39
+ /** The value of `key` in `map`, created by `create` and stored first if there is none (an `undefined` value counts as none). */
40
+ export declare function getOrSet<K, V>(map: {
41
+ get(key: K): V | undefined;
42
+ set(key: K, value: V): unknown;
43
+ }, key: K, create: () => V): V;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DefaultMap = void 0;
4
4
  exports.memoize = memoize;
5
+ exports.getOrSet = getOrSet;
5
6
  /**
6
7
  * A default map allows for a generator producing values automatically if you want to add something to a map that does not have a value associated with a given key.
7
8
  * This does not implement the default map interface as return types (and some future methods may) change
@@ -76,4 +77,13 @@ function memoize(fn, reentry) {
76
77
  return known.get(key);
77
78
  };
78
79
  }
80
+ /** The value of `key` in `map`, created by `create` and stored first if there is none (an `undefined` value counts as none). */
81
+ function getOrSet(map, key, create) {
82
+ let value = map.get(key);
83
+ if (value === undefined) {
84
+ value = create();
85
+ map.set(key, value);
86
+ }
87
+ return value;
88
+ }
79
89
  //# sourceMappingURL=defaultmap.js.map
@@ -26,11 +26,16 @@ export declare class ReachSummaries<K, V> {
26
26
  /**
27
27
  * @param next - the nodes a node leads to, asked for once per node
28
28
  * @param own - what a node contributes itself, asked for once per node after its successors
29
- * @param monoid - joins the values, its `concat` may return either of them if it subsumes the other but must not change them
29
+ * @param monoid - joins the values, its `concat` may return either of them if it subsumes the other but must not change them; joining a value again changes nothing, so each is joined once
30
30
  */
31
31
  constructor(next: (node: K) => Iterable<K>, own: (node: K) => V | undefined, monoid: Monoid<V>);
32
32
  of(node: K): V;
33
33
  }
34
+ /**
35
+ * The union of all sets, one of them if it holds all others: joining them pairwise copies what was joined so far for every set
36
+ * that adds to it, which for a large component of {@link ReachSummaries} (thousands of successors with sets of their own) is quadratic.
37
+ */
38
+ export declare function unionOfAllSets<T>(sets: readonly ReadonlySet<T>[]): ReadonlySet<T>;
34
39
  /** The union of both sets, one of them if it holds the other, so summaries share their sets wherever they can. */
35
40
  export declare function unionOfSets<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): ReadonlySet<T>;
36
41
  /** An equation system whose dependencies show only as a node's value is computed, see {@link DemandSolver}. */
package/util/fixpoint.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DemandSolver = exports.ReachSummaries = exports.StronglyConnected = void 0;
4
+ exports.unionOfAllSets = unionOfAllSets;
4
5
  exports.unionOfSets = unionOfSets;
5
6
  const monoid_1 = require("./monoid");
6
- const assert_1 = require("./assert");
7
+ const arrays_1 = require("./collections/arrays");
7
8
  /** the number of a node whose component is complete, see {@link StronglyConnected} */
8
9
  const Complete = -1;
9
10
  /** The strongly connected components of a graph whose successors are asked for only once a node is reached (Tarjan's algorithm, iterative). */
@@ -89,11 +90,25 @@ class ReachSummaries {
89
90
  /**
90
91
  * @param next - the nodes a node leads to, asked for once per node
91
92
  * @param own - what a node contributes itself, asked for once per node after its successors
92
- * @param monoid - joins the values, its `concat` may return either of them if it subsumes the other but must not change them
93
+ * @param monoid - joins the values, its `concat` may return either of them if it subsumes the other but must not change them; joining a value again changes nothing, so each is joined once
93
94
  */
94
95
  constructor(next, own, monoid) {
95
96
  this.components = new StronglyConnected(next, (members, successorsOf) => {
96
- const value = monoid_1.Monoid.fold(monoid, members.flatMap(m => [own(m), ...successorsOf(m).map(s => this.values.get(s))]).filter(assert_1.isNotUndefined));
97
+ /* each value once: a component may have millions of successors sharing the values of few components, and the members have none yet */
98
+ const values = new Set();
99
+ for (const m of members) {
100
+ const mine = own(m);
101
+ if (mine !== undefined) {
102
+ values.add(mine);
103
+ }
104
+ for (const s of successorsOf(m)) {
105
+ const theirs = this.values.get(s);
106
+ if (theirs !== undefined) {
107
+ values.add(theirs);
108
+ }
109
+ }
110
+ }
111
+ const value = monoid_1.Monoid.fold(monoid, [...values]);
97
112
  for (const m of members) {
98
113
  this.values.set(m, value);
99
114
  }
@@ -105,6 +120,33 @@ class ReachSummaries {
105
120
  }
106
121
  }
107
122
  exports.ReachSummaries = ReachSummaries;
123
+ /**
124
+ * The union of all sets, one of them if it holds all others: joining them pairwise copies what was joined so far for every set
125
+ * that adds to it, which for a large component of {@link ReachSummaries} (thousands of successors with sets of their own) is quadratic.
126
+ */
127
+ function unionOfAllSets(sets) {
128
+ /* the successors of a component often share the summary of one component they lead to */
129
+ const distinct = (0, arrays_1.uniqueArray)(sets);
130
+ if (distinct.length === 0) {
131
+ return new Set();
132
+ }
133
+ let largest = distinct[0];
134
+ for (const set of distinct) {
135
+ if (set.size > largest.size) {
136
+ largest = set;
137
+ }
138
+ }
139
+ if (distinct.every(set => set === largest || set.isSubsetOf(largest))) {
140
+ return largest;
141
+ }
142
+ const union = new Set(largest);
143
+ for (const set of distinct) {
144
+ for (const item of set) {
145
+ union.add(item);
146
+ }
147
+ }
148
+ return union;
149
+ }
108
150
  /** The union of both sets, one of them if it holds the other, so summaries share their sets wherever they can. */
109
151
  function unionOfSets(a, b) {
110
152
  if (a === b || b.size === 0 || (b.size <= a.size && b.isSubsetOf(a))) {
@@ -3,6 +3,6 @@
3
3
  * @module
4
4
  */
5
5
  import { SemVer } from 'semver';
6
- export declare const versionDate = "2026-11-15T17:22:01Z";
6
+ export declare const versionDate = "2026-11-21T09:17:49Z";
7
7
  /** Retrieves the current flowR version as a new {@link SemVer} object. */
8
8
  export declare function flowrVersion(): SemVer;
@@ -8,9 +8,9 @@ exports.flowrVersion = flowrVersion;
8
8
  */
9
9
  const semver_1 = require("semver");
10
10
  // this is automatically replaced with the current version by release-it
11
- const version = '2.17.7';
11
+ const version = '2.17.9';
12
12
  // this is automatically replaced with the release date by release-it (scripts/bump-version.ts)
13
- exports.versionDate = '2026-11-15T17:22:01Z';
13
+ exports.versionDate = '2026-11-21T09:17:49Z';
14
14
  /** Retrieves the current flowR version as a new {@link SemVer} object. */
15
15
  function flowrVersion() {
16
16
  return new semver_1.SemVer(version);
@@ -0,0 +1,26 @@
1
+ import { BoundedMap } from './collections/bounded-map';
2
+ /** What a cache that outlives a single analysis holds, deciding when it is released. */
3
+ export declare enum CacheScope {
4
+ /** data of the analyzed program, useless for another one: released by every reset of an analyzer (context) */
5
+ Analysis = "analysis",
6
+ /** a pure function of constant input (built-ins, config schema, databases): kept, but bounded */
7
+ Process = "process"
8
+ }
9
+ /**
10
+ * The module-level caches of flowR, so they can be released and inspected in one place.
11
+ * Each cache registers once under a fixed name, {@link FlowrAnalyzerContext#reset} releases the {@link CacheScope.Analysis} ones.
12
+ */
13
+ export declare const GlobalCaches: {
14
+ /** Register a cache under `name`, by how to tell its size and how to release it. */
15
+ readonly register: (this: void, name: string, scope: CacheScope, size: () => number | undefined, clear: () => void, cap?: number) => void;
16
+ /** A {@link BoundedMap} holding at most `cap` entries, registered under `name`. */
17
+ readonly map: <K, V>(this: void, name: string, scope: CacheScope, cap: number) => BoundedMap<K, V>;
18
+ /** Release every registered cache of the given scope. */
19
+ readonly clear: (this: void, scope: CacheScope) => void;
20
+ /** The size of every registered cache by name, for tests and diagnostics. */
21
+ readonly sizes: (this: void) => Record<string, {
22
+ readonly scope: CacheScope;
23
+ readonly size: number | undefined;
24
+ readonly cap: number | undefined;
25
+ }>;
26
+ };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GlobalCaches = exports.CacheScope = void 0;
4
+ const bounded_map_1 = require("./collections/bounded-map");
5
+ /** What a cache that outlives a single analysis holds, deciding when it is released. */
6
+ var CacheScope;
7
+ (function (CacheScope) {
8
+ /** data of the analyzed program, useless for another one: released by every reset of an analyzer (context) */
9
+ CacheScope["Analysis"] = "analysis";
10
+ /** a pure function of constant input (built-ins, config schema, databases): kept, but bounded */
11
+ CacheScope["Process"] = "process";
12
+ })(CacheScope || (exports.CacheScope = CacheScope = {}));
13
+ /** keyed by a fixed name per cache, so registering again (e.g., a module loaded twice) replaces instead of growing */
14
+ const registry = new Map();
15
+ /**
16
+ * The module-level caches of flowR, so they can be released and inspected in one place.
17
+ * Each cache registers once under a fixed name, {@link FlowrAnalyzerContext#reset} releases the {@link CacheScope.Analysis} ones.
18
+ */
19
+ exports.GlobalCaches = {
20
+ /** Register a cache under `name`, by how to tell its size and how to release it. */
21
+ register(name, scope, size, clear, cap) {
22
+ registry.set(name, { scope, size, clear, cap });
23
+ },
24
+ /** A {@link BoundedMap} holding at most `cap` entries, registered under `name`. */
25
+ map(name, scope, cap) {
26
+ const map = new bounded_map_1.BoundedMap(cap);
27
+ exports.GlobalCaches.register(name, scope, () => map.size, () => map.clear(), cap);
28
+ return map;
29
+ },
30
+ /** Release every registered cache of the given scope. */
31
+ clear(scope) {
32
+ for (const cache of registry.values()) {
33
+ if (cache.scope === scope) {
34
+ cache.clear();
35
+ }
36
+ }
37
+ },
38
+ /** The size of every registered cache by name, for tests and diagnostics. */
39
+ sizes() {
40
+ return Object.fromEntries(registry.entries().map(([name, c]) => [name, { scope: c.scope, size: c.size(), cap: c.cap }]));
41
+ }
42
+ };
43
+ //# sourceMappingURL=global-caches.js.map
package/util/monoid.js CHANGED
@@ -14,7 +14,7 @@ exports.Monoid = {
14
14
  name: 'Monoid',
15
15
  /** Combines all values, `empty` if there are none. */
16
16
  fold(monoid, values) {
17
- const all = [...values];
17
+ const all = Array.isArray(values) ? values : [...values];
18
18
  return monoid.concatAll?.(all) ?? all.reduce((a, b) => monoid.concat(a, b), monoid.empty);
19
19
  },
20
20
  /** Combines what `f` makes of each item, `empty` if there are none. */
@@ -25,7 +25,7 @@ exports.Monoid = {
25
25
  any: { empty: false, concat: (a, b) => a || b },
26
26
  /** The union of sets, which shares a set wherever it holds the other, see {@link unionOfSets}. */
27
27
  set() {
28
- return { empty: new Set(), concat: fixpoint_1.unionOfSets };
28
+ return { empty: new Set(), concat: fixpoint_1.unionOfSets, concatAll: fixpoint_1.unionOfAllSets };
29
29
  }
30
30
  };
31
31
  //# sourceMappingURL=monoid.js.map
package/util/quads.js CHANGED
@@ -33,6 +33,7 @@ const assert_1 = require("./assert");
33
33
  const defaultmap_1 = require("./collections/defaultmap");
34
34
  const literal = (v, n) => n3().DataFactory.literal(v, n);
35
35
  const log_1 = require("./log");
36
+ const global_caches_1 = require("./global-caches");
36
37
  const domain = 'https://uni-ulm.de/r-ast/';
37
38
  /** A deterministic counting id generator for quads. */
38
39
  function defaultQuadIdGenerator() {
@@ -66,9 +67,14 @@ function serialize2quads(obj, config) {
66
67
  const useConfig = (0, objects_1.deepMergeObject)(exports.DefaultQuadSerializationConfiguration, config);
67
68
  (0, assert_1.guard)((0, objects_1.isObjectOrArray)(obj), 'cannot serialize non-object to rdf!');
68
69
  (0, assert_1.guard)(!Array.isArray(obj), 'cannot serialize arrays (must wrap in object)!');
69
- store = new Set();
70
70
  const quads = [];
71
- serializeObject(obj, quads, useConfig);
71
+ try {
72
+ serializeObject(obj, quads, useConfig);
73
+ }
74
+ finally {
75
+ /* the objects seen are the analysis serialized, which must not outlive the call */
76
+ store.clear();
77
+ }
72
78
  return writer().quadsToString(quads);
73
79
  }
74
80
  /**
@@ -155,7 +161,9 @@ function processObjectEntry(key, value, obj, quads, config) {
155
161
  processLiteralEntry(value, key, obj, quads, config);
156
162
  }
157
163
  }
158
- let store = new Set();
164
+ /** the objects already serialized by the running {@link serialize2quads}, against cycles */
165
+ const store = new Set();
166
+ global_caches_1.GlobalCaches.register('quad-cycle-guard', global_caches_1.CacheScope.Analysis, () => store.size, () => store.clear());
159
167
  function guardCycle(obj) {
160
168
  // @ts-expect-error we do not care about the type here
161
169
  if ((0, objects_1.isObjectOrArray)(obj) && 'id' in obj) {
@@ -32,3 +32,22 @@ export interface RRepository {
32
32
  }
33
33
  /** the repositories the database records, keyed by the lowercase name it states */
34
34
  export declare const RRepositories: Record<string, RRepository>;
35
+ /** where to find a file of a package's sources, see {@link packageSourceUrl} */
36
+ export interface SourcePlace {
37
+ readonly version?: string;
38
+ /** the repository the version came from, as the database names it (`cran`, `bioc`, `runiverse:r-lib`, or a git url) */
39
+ readonly source?: string;
40
+ /** a package R ships, whose sources are R's own */
41
+ readonly base?: boolean;
42
+ readonly file?: string;
43
+ readonly line?: number;
44
+ readonly endLine?: number;
45
+ }
46
+ /** the web address of a git repository, `undefined` for anything that is none (`git@github.com:o/r.git` becomes `https://github.com/o/r`) */
47
+ export declare function gitWebUrl(source: string): string | undefined;
48
+ /**
49
+ * Where a file of a package's sources is online, at its lines: R's sources for a base package, CRAN's mirror at the
50
+ * version tag, the package's git repository at `HEAD` (repositories tag releases in no common way), an R-universe's repository, or
51
+ * Bioconductor's git browser; the repository's page when the file cannot be pointed at.
52
+ */
53
+ export declare function packageSourceUrl(pkg: BrandedNamespace, { version, source, base, file, line, endLine }: SourcePlace): string | undefined;
@@ -15,6 +15,8 @@ exports.baseManualIndexUrl = baseManualIndexUrl;
15
15
  exports.baseManualTopicUrl = baseManualTopicUrl;
16
16
  exports.rdrrPackageUrl = rdrrPackageUrl;
17
17
  exports.rdrrTopicUrl = rdrrTopicUrl;
18
+ exports.gitWebUrl = gitWebUrl;
19
+ exports.packageSourceUrl = packageSourceUrl;
18
20
  /** read-only GitHub mirror of R's own SVN; base packages live under `src/library/<pkg>` */
19
21
  const RSourceMirror = 'https://github.com/wch/r-source';
20
22
  /** read-only CRAN GitHub mirror base; `github.com/cran/<pkg>` mirrors every CRAN package and tags each release */
@@ -76,4 +78,43 @@ exports.RRepositories = {
76
78
  'omegahat': { label: 'Omegahat', home: pkg => `https://www.omegahat.net/${encodeURIComponent(pkg)}/` },
77
79
  'rforge': { label: 'R-Forge', home: pkg => `https://r-forge.r-project.org/projects/${encodeURIComponent(pkg)}/` }
78
80
  };
81
+ /** the fragment linking to the lines, `#L3` or `#L3-L9`, empty without a line */
82
+ function atLines(line, endLine) {
83
+ return line === undefined || line < 0 ? '' : endLine !== undefined && endLine > line ? `#L${line}-L${endLine}` : `#L${line}`;
84
+ }
85
+ /** the web address of a git repository, `undefined` for anything that is none (`git@github.com:o/r.git` becomes `https://github.com/o/r`) */
86
+ function gitWebUrl(source) {
87
+ const ssh = /^git@([^:]+):(.+?)(?:\.git)?\/?$/.exec(source);
88
+ if (ssh !== null) {
89
+ return `https://${ssh[1]}/${ssh[2]}`;
90
+ }
91
+ const https = /^(?:git\+)?https?:\/\/((?:github\.com|gitlab\.com|codeberg\.org|bitbucket\.org)\/[^/]+\/[^/#?]+?)(?:\.git)?\/?$/.exec(source);
92
+ return https === null ? undefined : `https://${https[1]}`;
93
+ }
94
+ /**
95
+ * Where a file of a package's sources is online, at its lines: R's sources for a base package, CRAN's mirror at the
96
+ * version tag, the package's git repository at `HEAD` (repositories tag releases in no common way), an R-universe's repository, or
97
+ * Bioconductor's git browser; the repository's page when the file cannot be pointed at.
98
+ */
99
+ function packageSourceUrl(pkg, { version, source, base, file, line, endLine }) {
100
+ const lines = atLines(line, endLine);
101
+ if (base === true) {
102
+ return file === undefined ? rSourceUrl(pkg, version) : rSourceUrl(pkg, version, file) + lines;
103
+ }
104
+ const kind = (source ?? 'cran').toLowerCase();
105
+ if (kind === 'cran') {
106
+ return file === undefined ? cranMirrorSourceUrl(pkg, version) : cranMirrorSourceUrl(pkg, version, file) + lines;
107
+ }
108
+ const git = source === undefined ? undefined : gitWebUrl(source);
109
+ const universe = /^r-?universe:([\w.-]+)$/.exec(kind)?.[1];
110
+ const repo = git ?? (universe === undefined ? undefined : `https://github.com/${universe}/${encodeURIComponent(pkg)}`);
111
+ if (repo !== undefined) {
112
+ const blob = repo.includes('gitlab.com') ? '/-/blob' : '/blob';
113
+ return file === undefined ? repo : `${repo}${blob}/HEAD/${file}${lines}`;
114
+ }
115
+ if (kind === 'bioc' || kind === 'bioconductor') {
116
+ return file === undefined ? exports.RRepositories['bioc'].home(pkg) : `https://code.bioconductor.org/browse/${encodeURIComponent(pkg)}/blob/devel/${file}${lines}`;
117
+ }
118
+ return exports.RRepositories[kind]?.home(pkg);
119
+ }
79
120
  //# sourceMappingURL=r-package-urls.js.map