@trustify-da/trustify-da-javascript-client 0.3.0-ea.e12bc82 → 0.3.0-ea.e258fba

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 (97) hide show
  1. package/README.md +367 -13
  2. package/dist/package.json +48 -28
  3. package/dist/src/analysis.d.ts +28 -5
  4. package/dist/src/analysis.js +99 -89
  5. package/dist/src/batch_opts.d.ts +24 -0
  6. package/dist/src/batch_opts.js +35 -0
  7. package/dist/src/cli.js +346 -9
  8. package/dist/src/cyclone_dx_sbom.d.ts +30 -3
  9. package/dist/src/cyclone_dx_sbom.js +95 -9
  10. package/dist/src/index.d.ts +202 -12
  11. package/dist/src/index.js +365 -30
  12. package/dist/src/license/index.d.ts +28 -0
  13. package/dist/src/license/index.js +103 -0
  14. package/dist/src/license/license_utils.d.ts +40 -0
  15. package/dist/src/license/license_utils.js +137 -0
  16. package/dist/src/license/licenses_api.d.ts +34 -0
  17. package/dist/src/license/licenses_api.js +98 -0
  18. package/dist/src/license/project_license.d.ts +20 -0
  19. package/dist/src/license/project_license.js +62 -0
  20. package/dist/src/oci_image/images.d.ts +4 -5
  21. package/dist/src/oci_image/images.js +15 -1
  22. package/dist/src/oci_image/utils.d.ts +7 -7
  23. package/dist/src/oci_image/utils.js +11 -2
  24. package/dist/src/package_version.d.ts +8 -0
  25. package/dist/src/package_version.js +31 -0
  26. package/dist/src/provider.d.ts +18 -5
  27. package/dist/src/provider.js +33 -5
  28. package/dist/src/providers/base_java.d.ts +68 -15
  29. package/dist/src/providers/base_java.js +82 -61
  30. package/dist/src/providers/base_javascript.d.ts +99 -12
  31. package/dist/src/providers/base_javascript.js +243 -27
  32. package/dist/src/providers/base_pyproject.d.ts +158 -0
  33. package/dist/src/providers/base_pyproject.js +322 -0
  34. package/dist/src/providers/containerfile_parser.d.ts +5 -0
  35. package/dist/src/providers/containerfile_parser.js +20 -0
  36. package/dist/src/providers/golang_gomodules.d.ts +30 -13
  37. package/dist/src/providers/golang_gomodules.js +219 -122
  38. package/dist/src/providers/gomod_parser.d.ts +4 -0
  39. package/dist/src/providers/gomod_parser.js +16 -0
  40. package/dist/src/providers/java_gradle.d.ts +76 -3
  41. package/dist/src/providers/java_gradle.js +323 -21
  42. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  43. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  44. package/dist/src/providers/java_maven.d.ts +45 -10
  45. package/dist/src/providers/java_maven.js +300 -14
  46. package/dist/src/providers/javascript_bun.d.ts +22 -0
  47. package/dist/src/providers/javascript_bun.js +141 -0
  48. package/dist/src/providers/javascript_npm.d.ts +19 -0
  49. package/dist/src/providers/javascript_npm.js +61 -1
  50. package/dist/src/providers/javascript_pnpm.d.ts +14 -1
  51. package/dist/src/providers/javascript_pnpm.js +55 -5
  52. package/dist/src/providers/javascript_yarn.d.ts +12 -0
  53. package/dist/src/providers/javascript_yarn.js +75 -2
  54. package/dist/src/providers/manifest.d.ts +2 -0
  55. package/dist/src/providers/manifest.js +28 -7
  56. package/dist/src/providers/marker_evaluator.d.ts +14 -0
  57. package/dist/src/providers/marker_evaluator.js +191 -0
  58. package/dist/src/providers/oci_dockerfile.d.ts +51 -0
  59. package/dist/src/providers/oci_dockerfile.js +177 -0
  60. package/dist/src/providers/processors/yarn_berry_processor.d.ts +6 -2
  61. package/dist/src/providers/processors/yarn_berry_processor.js +91 -7
  62. package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
  63. package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
  64. package/dist/src/providers/python_controller.d.ts +10 -3
  65. package/dist/src/providers/python_controller.js +122 -63
  66. package/dist/src/providers/python_pip.d.ts +16 -4
  67. package/dist/src/providers/python_pip.js +51 -58
  68. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  69. package/dist/src/providers/python_pip_pyproject.js +146 -0
  70. package/dist/src/providers/python_poetry.d.ts +98 -0
  71. package/dist/src/providers/python_poetry.js +286 -0
  72. package/dist/src/providers/python_uv.d.ts +46 -0
  73. package/dist/src/providers/python_uv.js +269 -0
  74. package/dist/src/providers/requirements_parser.d.ts +6 -0
  75. package/dist/src/providers/requirements_parser.js +24 -0
  76. package/dist/src/providers/rust_cargo.d.ts +56 -0
  77. package/dist/src/providers/rust_cargo.js +682 -0
  78. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  79. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  80. package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
  81. package/dist/src/remediate.d.ts +21 -0
  82. package/dist/src/remediate.js +149 -0
  83. package/dist/src/remediation.d.ts +57 -0
  84. package/dist/src/remediation.js +436 -0
  85. package/dist/src/remediation_report.d.ts +40 -0
  86. package/dist/src/remediation_report.js +159 -0
  87. package/dist/src/sbom.d.ts +28 -2
  88. package/dist/src/sbom.js +26 -4
  89. package/dist/src/tools.d.ts +48 -6
  90. package/dist/src/tools.js +138 -2
  91. package/dist/src/updaters/maven_updater.d.ts +26 -0
  92. package/dist/src/updaters/maven_updater.js +322 -0
  93. package/dist/src/updaters/toml_updater.d.ts +33 -0
  94. package/dist/src/updaters/toml_updater.js +244 -0
  95. package/dist/src/workspace.d.ts +70 -0
  96. package/dist/src/workspace.js +256 -0
  97. package/package.json +49 -29
@@ -1,5 +1,18 @@
1
1
  export default class Javascript_pnpm extends Base_javascript {
2
+ /**
3
+ * Parses `pnpm-lock.yaml` (lockfileVersion 9) into a hash map keyed by
4
+ * `name@version`. Entries in the `packages` section are keyed by
5
+ * `<name>@<version>` (optionally followed by a `(peer@x)` suffix); the
6
+ * `resolution.integrity` field holds an SRI string.
7
+ * @param {string} lockDir - Directory containing pnpm-lock.yaml
8
+ * @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
9
+ * @protected
10
+ */
11
+ protected _parseLockFileHashes(lockDir: string): Map<string, Array<{
12
+ alg: string;
13
+ content: string;
14
+ }>>;
2
15
  _listCmdArgs(includeTransitive: any): string[];
3
- _buildDependencyTree(includeTransitive: any, manifest: any): any;
16
+ _buildDependencyTree(includeTransitive: any, opts?: {}): any;
4
17
  }
5
18
  import Base_javascript from './base_javascript.js';
@@ -1,21 +1,71 @@
1
- import Base_javascript from './base_javascript.js';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { load as yamlLoad } from 'js-yaml';
4
+ import Base_javascript, { sriToHash } from './base_javascript.js';
2
5
  export default class Javascript_pnpm extends Base_javascript {
3
6
  _lockFileName() {
4
7
  return "pnpm-lock.yaml";
5
8
  }
9
+ /**
10
+ * Parses `pnpm-lock.yaml` (lockfileVersion 9) into a hash map keyed by
11
+ * `name@version`. Entries in the `packages` section are keyed by
12
+ * `<name>@<version>` (optionally followed by a `(peer@x)` suffix); the
13
+ * `resolution.integrity` field holds an SRI string.
14
+ * @param {string} lockDir - Directory containing pnpm-lock.yaml
15
+ * @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
16
+ * @protected
17
+ */
18
+ _parseLockFileHashes(lockDir) {
19
+ const map = new Map();
20
+ const lockPath = path.join(lockDir, this._lockFileName());
21
+ if (!fs.existsSync(lockPath)) {
22
+ return map;
23
+ }
24
+ let lock;
25
+ try {
26
+ lock = yamlLoad(fs.readFileSync(lockPath, 'utf-8'));
27
+ }
28
+ catch (_) {
29
+ return map;
30
+ }
31
+ const packages = lock?.packages || {};
32
+ for (const [key, entry] of Object.entries(packages)) {
33
+ const integrity = entry?.resolution?.integrity;
34
+ if (!key || !integrity) {
35
+ continue;
36
+ }
37
+ // Strip any peer-dependency suffix, then split name from version
38
+ const base = key.split('(')[0];
39
+ const at = base.lastIndexOf('@');
40
+ if (at <= 0) {
41
+ continue;
42
+ }
43
+ const name = base.slice(0, at);
44
+ const version = base.slice(at + 1);
45
+ const hash = sriToHash(integrity);
46
+ if (name && version && hash) {
47
+ map.set(`${name}@${version}`, [hash]);
48
+ }
49
+ }
50
+ return map;
51
+ }
6
52
  _cmdName() {
7
53
  return "pnpm";
8
54
  }
9
55
  _listCmdArgs(includeTransitive) {
10
- return ['ls', includeTransitive ? '--depth=Infinity' : '--depth=0', '--prod', '--json'];
56
+ return ['ls', includeTransitive ? '--depth=Infinity' : '--depth=0', '--prod', '--json', '-r'];
11
57
  }
12
58
  _updateLockFileCmdArgs() {
13
59
  return ['install', '--frozen-lockfile'];
14
60
  }
15
- _buildDependencyTree(includeTransitive, manifest) {
16
- const tree = super._buildDependencyTree(includeTransitive, manifest);
61
+ _buildDependencyTree(includeTransitive, opts = {}) {
62
+ // pnpm ls --json returns an array with one entry per workspace package.
63
+ // When analyzing a workspace member, find its entry by name instead of
64
+ // blindly taking the first element (which is the workspace root).
65
+ const tree = super._buildDependencyTree(includeTransitive, opts);
17
66
  if (Array.isArray(tree) && tree.length > 0) {
18
- return tree[0];
67
+ const memberName = this._getManifest().name;
68
+ return tree.find(pkg => pkg.name === memberName) || tree[0];
19
69
  }
20
70
  return {};
21
71
  }
@@ -1,5 +1,17 @@
1
1
  export default class Javascript_yarn extends Base_javascript {
2
2
  static VERSION_PATTERN: RegExp;
3
+ /**
4
+ * Parses `yarn.lock` into a hash map keyed by `name@version`. Supports both
5
+ * Yarn Classic (v1) entries with an `integrity` SRI field and Yarn Berry
6
+ * (v2+) entries with a `checksum` field.
7
+ * @param {string} lockDir - Directory containing yarn.lock
8
+ * @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
9
+ * @protected
10
+ */
11
+ protected _parseLockFileHashes(lockDir: string): Map<string, Array<{
12
+ alg: string;
13
+ content: string;
14
+ }>>;
3
15
  _listCmdArgs(includeTransitive: any, manifestDir: any): any;
4
16
  _updateLockFileCmdArgs(manifestDir: any): any;
5
17
  _setUp(manifestPath: any, opts: any): void;
@@ -1,12 +1,85 @@
1
- import Base_javascript from './base_javascript.js';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { parseSyml } from '@yarnpkg/parsers';
4
+ import Base_javascript, { sriToHash } from './base_javascript.js';
2
5
  import Yarn_berry_processor from './processors/yarn_berry_processor.js';
3
6
  import Yarn_classic_processor from './processors/yarn_classic_processor.js';
7
+ /**
8
+ * Converts a Yarn Berry `checksum` value to a CycloneDX hash object. Berry
9
+ * checksums are formatted as `<cacheKey>/<hex-sha512>`; the digest is the
10
+ * hex-encoded SHA-512 following the final slash.
11
+ * @param {string} checksum - The checksum field value
12
+ * @returns {{alg: string, content: string}|null} CycloneDX hash, or null
13
+ */
14
+ function berryChecksumToHash(checksum) {
15
+ if (typeof checksum !== 'string') {
16
+ return null;
17
+ }
18
+ const slash = checksum.lastIndexOf('/');
19
+ const hex = (slash >= 0 ? checksum.slice(slash + 1) : checksum).trim();
20
+ if (!/^[0-9a-f]+$/i.test(hex)) {
21
+ return null;
22
+ }
23
+ return { alg: 'SHA-512', content: hex.toLowerCase() };
24
+ }
4
25
  export default class Javascript_yarn extends Base_javascript {
5
26
  static VERSION_PATTERN = /^([0-9]+)\./;
6
27
  #processor;
7
28
  _lockFileName() {
8
29
  return "yarn.lock";
9
30
  }
31
+ /**
32
+ * Parses `yarn.lock` into a hash map keyed by `name@version`. Supports both
33
+ * Yarn Classic (v1) entries with an `integrity` SRI field and Yarn Berry
34
+ * (v2+) entries with a `checksum` field.
35
+ * @param {string} lockDir - Directory containing yarn.lock
36
+ * @returns {Map<string, Array<{alg: string, content: string}>>} Hash map
37
+ * @protected
38
+ */
39
+ _parseLockFileHashes(lockDir) {
40
+ const map = new Map();
41
+ const lockPath = path.join(lockDir, this._lockFileName());
42
+ if (!fs.existsSync(lockPath)) {
43
+ return map;
44
+ }
45
+ let content;
46
+ try {
47
+ content = fs.readFileSync(lockPath, 'utf-8');
48
+ }
49
+ catch (_) {
50
+ return map;
51
+ }
52
+ const parsed = parseSyml(content);
53
+ for (const [spec, entry] of Object.entries(parsed)) {
54
+ if (spec === '__metadata') {
55
+ continue;
56
+ }
57
+ const version = entry.version;
58
+ if (!version) {
59
+ continue;
60
+ }
61
+ let hash = null;
62
+ if (entry.integrity) {
63
+ hash = sriToHash(entry.integrity);
64
+ }
65
+ else if (entry.checksum) {
66
+ hash = berryChecksumToHash(entry.checksum);
67
+ }
68
+ if (!hash) {
69
+ continue;
70
+ }
71
+ // Handle comma-separated specifiers (e.g., "pkg@^1.0.0, pkg@^2.0.0")
72
+ for (const rawSpec of spec.split(',')) {
73
+ const trimmed = rawSpec.trim();
74
+ const atIndex = trimmed.lastIndexOf('@');
75
+ if (atIndex > 0) {
76
+ const name = trimmed.slice(0, atIndex);
77
+ map.set(`${name}@${version}`, [hash]);
78
+ }
79
+ }
80
+ }
81
+ return map;
82
+ }
10
83
  _cmdName() {
11
84
  return "yarn";
12
85
  }
@@ -34,6 +107,6 @@ export default class Javascript_yarn extends Base_javascript {
34
107
  return this.#processor.parseDepTreeOutput(output);
35
108
  }
36
109
  _addDependenciesToSbom(sbom, depTree) {
37
- this.#processor.addDependenciesToSbom(sbom, depTree);
110
+ this.#processor.addDependenciesToSbom(sbom, depTree, purl => this._hashesForPurl(purl));
38
111
  }
39
112
  }
@@ -2,6 +2,8 @@ export default class Manifest {
2
2
  constructor(manifestPath: any);
3
3
  manifestPath: any;
4
4
  dependencies: any[];
5
+ peerDependencies: any;
6
+ optionalDependencies: any;
5
7
  name: any;
6
8
  version: any;
7
9
  ignored: any[];
@@ -9,6 +9,8 @@ export default class Manifest {
9
9
  this.manifestPath = manifestPath;
10
10
  const content = this.loadManifest();
11
11
  this.dependencies = this.loadDependencies(content);
12
+ this.peerDependencies = content.peerDependencies || {};
13
+ this.optionalDependencies = content.optionalDependencies || {};
12
14
  this.name = content.name;
13
15
  this.version = content.version || DEFAULT_VERSION;
14
16
  this.ignored = this.loadIgnored(content);
@@ -27,21 +29,40 @@ export default class Manifest {
27
29
  }
28
30
  loadDependencies(content) {
29
31
  let deps = [];
30
- if (!content.dependencies) {
31
- return deps;
32
+ const depSources = [
33
+ content.dependencies,
34
+ content.peerDependencies,
35
+ content.optionalDependencies,
36
+ ];
37
+ for (const source of depSources) {
38
+ if (source) {
39
+ for (let dep in source) {
40
+ if (!deps.includes(dep)) {
41
+ deps.push(dep);
42
+ }
43
+ }
44
+ }
32
45
  }
33
- for (let dep in content.dependencies) {
34
- deps.push(dep);
46
+ // bundledDependencies is an array of package names (subset of dependencies)
47
+ if (Array.isArray(content.bundledDependencies)) {
48
+ for (const dep of content.bundledDependencies) {
49
+ if (!deps.includes(dep)) {
50
+ deps.push(dep);
51
+ }
52
+ }
35
53
  }
36
54
  return deps;
37
55
  }
38
56
  loadIgnored(content) {
39
57
  let deps = [];
40
- if (!content.exhortignore) {
58
+ // Prefer the new 'trustify-da-ignore' key, falling back to the legacy
59
+ // 'exhortignore' key for backwards compatibility.
60
+ let ignored = content['trustify-da-ignore'] || content.exhortignore;
61
+ if (!ignored) {
41
62
  return deps;
42
63
  }
43
- for (let i = 0; i < content.exhortignore.length; i++) {
44
- deps.push(toPurl("npm", content.exhortignore[i]));
64
+ for (let i = 0; i < ignored.length; i++) {
65
+ deps.push(toPurl("npm", ignored[i]));
45
66
  }
46
67
  return deps;
47
68
  }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Maps Node.js/OS values to PEP 508 marker variables.
3
+ * Example: on Linux, sys_platform='linux', platform_system='Linux', os_name='posix'
4
+ * @returns {Record<string, string>}
5
+ */
6
+ export function getEnvironmentMarkers(): Record<string, string>;
7
+ /**
8
+ * Evaluates a full PEP 508 marker expression against the current platform.
9
+ * Example: "sys_platform == 'win32' and python_version >= '3.8'" → false on Linux
10
+ * Empty/missing markers return true (unconditional dependency).
11
+ * @param {string} markerExpr
12
+ * @returns {boolean}
13
+ */
14
+ export function evaluateMarker(markerExpr: string): boolean;
@@ -0,0 +1,191 @@
1
+ // PEP 508 environment marker evaluator.
2
+ // Filters Python dependencies by platform/version markers so that e.g.
3
+ // "pywin32 ; sys_platform == 'win32'" is excluded on Linux/macOS.
4
+ // See https://peps.python.org/pep-0508/#environment-markers
5
+ import os from 'node:os';
6
+ import { getCustomPath, invokeCommand } from '../tools.js';
7
+ let cachedPythonVersions = undefined;
8
+ function getPythonVersions() {
9
+ if (cachedPythonVersions !== undefined) {
10
+ return cachedPythonVersions;
11
+ }
12
+ try {
13
+ let python = getCustomPath('python3');
14
+ let out = invokeCommand(python, ['-c', "import sys; v=sys.version_info; print(f'{v.major}.{v.minor} {v.major}.{v.minor}.{v.micro}')"], { timeout: 5000 }).toString().trim();
15
+ let [short, full] = out.split(' ');
16
+ cachedPythonVersions = { short, full };
17
+ }
18
+ catch {
19
+ cachedPythonVersions = null;
20
+ }
21
+ return cachedPythonVersions;
22
+ }
23
+ /**
24
+ * Maps Node.js/OS values to PEP 508 marker variables.
25
+ * Example: on Linux, sys_platform='linux', platform_system='Linux', os_name='posix'
26
+ * @returns {Record<string, string>}
27
+ */
28
+ export function getEnvironmentMarkers() {
29
+ let platform = process.platform;
30
+ let systemMap = { win32: 'Windows', linux: 'Linux', darwin: 'Darwin' };
31
+ let machine = typeof os.machine === 'function' ? os.machine() : process.arch;
32
+ let pyVer = getPythonVersions();
33
+ return {
34
+ sys_platform: platform,
35
+ platform_system: systemMap[platform] || platform,
36
+ os_name: platform === 'win32' ? 'nt' : 'posix',
37
+ platform_machine: machine,
38
+ platform_release: os.release(),
39
+ platform_version: os.version?.() || '',
40
+ python_version: pyVer?.short || '',
41
+ python_full_version: pyVer?.full || '',
42
+ implementation_name: 'cpython',
43
+ };
44
+ }
45
+ function compareVersions(left, right) {
46
+ let lParts = left.split('.').map(Number);
47
+ let rParts = right.split('.').map(Number);
48
+ let len = Math.max(lParts.length, rParts.length);
49
+ for (let i = 0; i < len; i++) {
50
+ let l = lParts[i] || 0;
51
+ let r = rParts[i] || 0;
52
+ if (l < r) {
53
+ return -1;
54
+ }
55
+ if (l > r) {
56
+ return 1;
57
+ }
58
+ }
59
+ return 0;
60
+ }
61
+ // Evaluates a single comparison like sys_platform == 'win32' or python_version >= '3.8'.
62
+ // Version-bearing variables (python_version, python_full_version) use numeric comparison;
63
+ // all others use string equality. Returns false when the env value is missing.
64
+ function evaluateComparison(variable, op, value, env) {
65
+ let envVal = env[variable];
66
+ if (envVal === undefined || envVal === '') {
67
+ return false;
68
+ }
69
+ let isVersion = variable.includes('version');
70
+ if (isVersion) {
71
+ let cmp = compareVersions(envVal, value);
72
+ switch (op) {
73
+ case '==': return cmp === 0;
74
+ case '!=': return cmp !== 0;
75
+ case '>=': return cmp >= 0;
76
+ case '<=': return cmp <= 0;
77
+ case '>': return cmp > 0;
78
+ case '<': return cmp < 0;
79
+ case '~=': {
80
+ let parts = value.split('.');
81
+ parts.pop();
82
+ let prefix = parts.join('.');
83
+ return envVal.startsWith(prefix) && cmp >= 0;
84
+ }
85
+ default: return true;
86
+ }
87
+ }
88
+ switch (op) {
89
+ case '==': return envVal === value;
90
+ case '!=': return envVal !== value;
91
+ case 'in': return value.includes(envVal);
92
+ case 'not in': return !value.includes(envVal);
93
+ default: return envVal === value;
94
+ }
95
+ }
96
+ // Parses a single marker comparison into {variable, op, value}.
97
+ // Handles both normal and reversed forms:
98
+ // "sys_platform == 'linux'" → { variable: 'sys_platform', op: '==', value: 'linux' }
99
+ // "'linux' == sys_platform" → { variable: 'sys_platform', op: '==', value: 'linux' }
100
+ function parseAtom(expr) {
101
+ // Normal form: variable op 'value'
102
+ let m = expr.match(/^\s*([\w.]+)\s*(~=|!=|==|>=|<=|>|<|not\s+in|in)\s*["']([^"']*)["']\s*$/);
103
+ if (m) {
104
+ return { variable: m[1], op: m[2].replace(/\s+/g, ' '), value: m[3] };
105
+ }
106
+ // Reversed form: 'value' op variable — reverse directional operators
107
+ let mReverse = expr.match(/^\s*["']([^"']*)['"]\s*(~=|!=|==|>=|<=|>|<|not\s+in|in)\s*([\w.]+)\s*$/);
108
+ if (mReverse) {
109
+ let reverseOp = { '<': '>', '>': '<', '<=': '>=', '>=': '<=' };
110
+ let op = mReverse[2].replace(/\s+/g, ' ');
111
+ return { variable: mReverse[3], op: reverseOp[op] || op, value: mReverse[1] };
112
+ }
113
+ return null;
114
+ }
115
+ /**
116
+ * Evaluates a full PEP 508 marker expression against the current platform.
117
+ * Example: "sys_platform == 'win32' and python_version >= '3.8'" → false on Linux
118
+ * Empty/missing markers return true (unconditional dependency).
119
+ * @param {string} markerExpr
120
+ * @returns {boolean}
121
+ */
122
+ export function evaluateMarker(markerExpr) {
123
+ if (!markerExpr || !markerExpr.trim()) {
124
+ return true;
125
+ }
126
+ let env = getEnvironmentMarkers();
127
+ return evaluateExpr(markerExpr.trim(), env);
128
+ }
129
+ function evaluateExpr(expr, env) {
130
+ let orParts = splitLogical(expr, ' or ');
131
+ if (orParts.length > 1) {
132
+ return orParts.some(part => evaluateExpr(part, env));
133
+ }
134
+ let andParts = splitLogical(expr, ' and ');
135
+ if (andParts.length > 1) {
136
+ return andParts.every(part => evaluateExpr(part, env));
137
+ }
138
+ let trimmed = expr.trim();
139
+ if (trimmed.startsWith('(') && trimmed.endsWith(')')) {
140
+ return evaluateExpr(trimmed.slice(1, -1), env);
141
+ }
142
+ let atom = parseAtom(trimmed);
143
+ if (!atom) {
144
+ return true;
145
+ }
146
+ return evaluateComparison(atom.variable, atom.op, atom.value, env);
147
+ }
148
+ // Splits an expression by " and " or " or " at the top level, skipping
149
+ // separators inside parentheses or quoted strings.
150
+ // Example: splitLogical("a == 'x' and (b == 'y' or c == 'z')", " and ")
151
+ // → ["a == 'x'", "(b == 'y' or c == 'z')"]
152
+ function splitLogical(expr, sep) {
153
+ let parts = [];
154
+ let depth = 0;
155
+ let current = '';
156
+ let i = 0;
157
+ let quoteChar = null;
158
+ while (i < expr.length) {
159
+ let ch = expr[i];
160
+ if (quoteChar) {
161
+ if (ch === quoteChar) {
162
+ quoteChar = null;
163
+ }
164
+ current += ch;
165
+ i++;
166
+ continue;
167
+ }
168
+ if (ch === '"' || ch === "'") {
169
+ quoteChar = ch;
170
+ current += ch;
171
+ i++;
172
+ continue;
173
+ }
174
+ if (ch === '(') {
175
+ depth++;
176
+ }
177
+ if (ch === ')') {
178
+ depth--;
179
+ }
180
+ if (depth === 0 && expr.substring(i, i + sep.length) === sep) {
181
+ parts.push(current);
182
+ current = '';
183
+ i += sep.length;
184
+ continue;
185
+ }
186
+ current += ch;
187
+ i++;
188
+ }
189
+ parts.push(current);
190
+ return parts.filter(p => p.trim());
191
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Parse all FROM instructions from a Dockerfile using tree-sitter to extract base image references.
3
+ * In multi-stage builds, every FROM line is returned so each image can be analyzed independently.
4
+ * ARG substitutions are resolved using declared default values. FROM lines with unresolvable
5
+ * variables (ARGs without defaults) are silently skipped.
6
+ * @param {string} manifestContent the content of the Dockerfile
7
+ * @returns {Promise<string[]>} array of image references from all resolvable FROM instructions
8
+ * @throws {Error} when no FROM instruction is found or when no FROM lines can be resolved
9
+ */
10
+ export function parseAllFromImages(manifestContent: string): Promise<string[]>;
11
+ declare namespace _default {
12
+ export { isSupported };
13
+ export { validateLockFile };
14
+ export { provideComponent };
15
+ export { provideStack };
16
+ export { readLicenseFromManifest };
17
+ export function packageManagerName(): string;
18
+ }
19
+ export default _default;
20
+ export type Provided = any;
21
+ /**
22
+ * Check if the given manifest name is a Dockerfile or Containerfile.
23
+ * Supports dot-suffixed variants such as Dockerfile.dev or Containerfile.prod.
24
+ * @param {string} manifestName the manifest file name to check
25
+ * @returns {boolean} true if the manifest is a Dockerfile or Containerfile
26
+ */
27
+ declare function isSupported(manifestName: string): boolean;
28
+ /**
29
+ * Dockerfiles have no lock file, so validation always passes.
30
+ * @returns {boolean} always true
31
+ */
32
+ declare function validateLockFile(): boolean;
33
+ /**
34
+ * Provide content and content type for Dockerfile component analysis.
35
+ * @param {string} manifest path to the Dockerfile
36
+ * @param {{}} [opts={}] optional various options to pass along the application
37
+ * @returns {Promise<Provided>}
38
+ */
39
+ declare function provideComponent(manifest: string, opts?: {}): Promise<Provided>;
40
+ /**
41
+ * Provide content and content type for Dockerfile stack analysis.
42
+ * @param {string} manifest path to the Dockerfile
43
+ * @param {{}} [opts={}] optional various options to pass along the application
44
+ * @returns {Promise<Provided>}
45
+ */
46
+ declare function provideStack(manifest: string, opts?: {}): Promise<Provided>;
47
+ /**
48
+ * Dockerfiles contain no license information.
49
+ * @returns {null} always null
50
+ */
51
+ declare function readLicenseFromManifest(): null;