@trustify-da/trustify-da-javascript-client 0.3.0-ea.d71f957 → 0.3.0-ea.d9c1ae4

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.
@@ -0,0 +1,314 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { PackageURL } from 'packageurl-js';
4
+ import { parse as parseToml } from 'smol-toml';
5
+ import { getLicense } from '../license/license_utils.js';
6
+ import Sbom from '../sbom.js';
7
+ import { getCustom } from '../tools.js';
8
+ const ecosystem = 'pip';
9
+ const IGNORE_MARKERS = ['exhortignore', 'trustify-da-ignore'];
10
+ const DEFAULT_ROOT_NAME = 'default-pip-root';
11
+ const DEFAULT_ROOT_VERSION = '0.0.0';
12
+ /** @typedef {{name: string, version: string, children: string[]}} GraphEntry */
13
+ /** @typedef {{name: string, version: string, dependencies: DepTreeEntry[]}} DepTreeEntry */
14
+ /** @typedef {{directDeps: string[], graph: Map<string, GraphEntry>}} DependencyData */
15
+ /** @typedef {{ecosystem: string, content: string, contentType: string}} Provided */
16
+ export default class Base_pyproject {
17
+ /**
18
+ * @param {string} manifestName
19
+ * @returns {boolean}
20
+ */
21
+ isSupported(manifestName) {
22
+ return 'pyproject.toml' === manifestName;
23
+ }
24
+ /**
25
+ * @param {string} manifestDir
26
+ * @param {Object} [opts={}]
27
+ * @returns {boolean}
28
+ */
29
+ validateLockFile(manifestDir, opts = {}) {
30
+ return this._findLockFileDir(manifestDir, opts) != null;
31
+ }
32
+ /**
33
+ * Walk up from manifestDir to find the directory containing the lock file.
34
+ * Follows the same pattern as Base_javascript._findLockFileDir().
35
+ * @param {string} manifestDir
36
+ * @param {Object} [opts={}]
37
+ * @returns {string|null}
38
+ * @protected
39
+ */
40
+ _findLockFileDir(manifestDir, opts = {}) {
41
+ const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
42
+ if (workspaceDir) {
43
+ const dir = path.resolve(workspaceDir);
44
+ return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
45
+ }
46
+ let dir = path.resolve(manifestDir);
47
+ let parent = dir;
48
+ do {
49
+ dir = parent;
50
+ if (fs.existsSync(path.join(dir, this._lockFileName()))) {
51
+ return dir;
52
+ }
53
+ if (this._isWorkspaceRoot(dir)) {
54
+ return null;
55
+ }
56
+ parent = path.dirname(dir);
57
+ } while (parent !== dir);
58
+ return null;
59
+ }
60
+ /**
61
+ * Detect workspace root boundaries.
62
+ * Currently only uv has native workspace support ([tool.uv.workspace] in pyproject.toml).
63
+ * Poetry has no workspace/monorepo support (python-poetry/poetry#2270), so each
64
+ * poetry project is treated independently — see Python_poetry._findLockFileDir().
65
+ * @param {string} dir
66
+ * @returns {boolean}
67
+ * @protected
68
+ */
69
+ _isWorkspaceRoot(dir) {
70
+ const pyprojectPath = path.join(dir, 'pyproject.toml');
71
+ if (!fs.existsSync(pyprojectPath)) {
72
+ return false;
73
+ }
74
+ try {
75
+ const content = parseToml(fs.readFileSync(pyprojectPath, 'utf-8'));
76
+ if (content.tool?.uv?.workspace) {
77
+ return true;
78
+ }
79
+ }
80
+ catch (_) {
81
+ // ignore parse errors
82
+ }
83
+ return false;
84
+ }
85
+ /**
86
+ * Read project license from pyproject.toml, with fallback to LICENSE file.
87
+ * @param {string} manifestPath
88
+ * @returns {string|null}
89
+ */
90
+ readLicenseFromManifest(manifestPath) {
91
+ let fromManifest = null;
92
+ try {
93
+ let content = fs.readFileSync(manifestPath, 'utf-8');
94
+ let parsed = parseToml(content);
95
+ fromManifest = parsed.project?.license;
96
+ if (typeof fromManifest === 'object' && fromManifest != null) {
97
+ fromManifest = fromManifest.text || null;
98
+ }
99
+ if (!fromManifest) {
100
+ fromManifest = parsed.tool?.poetry?.license || null;
101
+ }
102
+ }
103
+ catch (_) {
104
+ // leave fromManifest as null
105
+ }
106
+ return getLicense(fromManifest, manifestPath);
107
+ }
108
+ /**
109
+ * @param {string} manifest - path to pyproject.toml
110
+ * @param {Object} [opts={}]
111
+ * @returns {Promise<Provided>}
112
+ */
113
+ async provideStack(manifest, opts = {}) {
114
+ return {
115
+ ecosystem,
116
+ content: await this._createSbom(manifest, opts, true),
117
+ contentType: 'application/vnd.cyclonedx+json'
118
+ };
119
+ }
120
+ /**
121
+ * @param {string} manifest - path to pyproject.toml
122
+ * @param {Object} [opts={}]
123
+ * @returns {Promise<Provided>}
124
+ */
125
+ async provideComponent(manifest, opts = {}) {
126
+ return {
127
+ ecosystem,
128
+ content: await this._createSbom(manifest, opts, false),
129
+ contentType: 'application/vnd.cyclonedx+json'
130
+ };
131
+ }
132
+ // --- abstract methods (subclasses must override) ---
133
+ /**
134
+ * @returns {string}
135
+ * @protected
136
+ */
137
+ _lockFileName() {
138
+ throw new TypeError('_lockFileName must be implemented');
139
+ }
140
+ /**
141
+ * @returns {string}
142
+ * @protected
143
+ */
144
+ _cmdName() {
145
+ throw new TypeError('_cmdName must be implemented');
146
+ }
147
+ /**
148
+ * Resolve dependencies using the tool-specific command and parser.
149
+ *
150
+ * @param {string} manifestDir - directory containing the target pyproject.toml
151
+ * @param {string} workspaceDir - workspace root (where the lock file lives);
152
+ * only used by providers that need workspace-level resolution (e.g. uv)
153
+ * @param {object} parsed - parsed pyproject.toml
154
+ * @param {Object} opts
155
+ * @returns {Promise<DependencyData>}
156
+ * @protected
157
+ */
158
+ // eslint-disable-next-line no-unused-vars
159
+ async _getDependencyData(manifestDir, workspaceDir, parsed, opts) {
160
+ throw new TypeError('_getDependencyData must be implemented');
161
+ }
162
+ // --- shared helpers ---
163
+ /**
164
+ * Canonicalize a Python package name per PEP 503.
165
+ * @param {string} name
166
+ * @returns {string}
167
+ * @protected
168
+ */
169
+ _canonicalize(name) {
170
+ return name.toLowerCase().replace(/[-_.]+/g, '-');
171
+ }
172
+ /**
173
+ * Get the project name from pyproject.toml.
174
+ * @param {object} parsed
175
+ * @returns {string|null}
176
+ * @protected
177
+ */
178
+ _getProjectName(parsed) {
179
+ return parsed.project?.name || parsed.tool?.poetry?.name || null;
180
+ }
181
+ /**
182
+ * Get the project version from pyproject.toml.
183
+ * @param {object} parsed
184
+ * @returns {string|null}
185
+ * @protected
186
+ */
187
+ _getProjectVersion(parsed) {
188
+ return parsed.project?.version || parsed.tool?.poetry?.version || null;
189
+ }
190
+ /**
191
+ * Scan raw pyproject.toml text for dependencies with ignore markers.
192
+ * @param {string} manifestPath
193
+ * @returns {Set<string>}
194
+ * @protected
195
+ */
196
+ _getIgnoredDeps(manifestPath) {
197
+ let ignored = new Set();
198
+ let content = fs.readFileSync(manifestPath, 'utf-8');
199
+ let lines = content.split(/\r?\n/);
200
+ for (let line of lines) {
201
+ if (!IGNORE_MARKERS.some(m => line.includes(m))) {
202
+ continue;
203
+ }
204
+ // PEP 621 style: "requests>=2.25" #exhortignore
205
+ let pep621Match = line.match(/^\s*"([^"]+)"/);
206
+ if (pep621Match) {
207
+ let reqStr = pep621Match[1];
208
+ let nameMatch = reqStr.match(/^([A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?)/);
209
+ if (nameMatch) {
210
+ ignored.add(this._canonicalize(nameMatch[1]));
211
+ }
212
+ continue;
213
+ }
214
+ // Poetry style: requests = "^2.25" #exhortignore
215
+ let poetryMatch = line.match(/^\s*([A-Za-z0-9][A-Za-z0-9._-]*)\s*=/);
216
+ if (poetryMatch) {
217
+ ignored.add(this._canonicalize(poetryMatch[1]));
218
+ }
219
+ }
220
+ return ignored;
221
+ }
222
+ /**
223
+ * Compute the set of graph nodes reachable from direct deps, excluding ignored.
224
+ * @param {Map<string, GraphEntry>} graph
225
+ * @param {string[]} directDeps
226
+ * @param {Set<string>} ignoredDeps
227
+ * @returns {Set<string>}
228
+ * @protected
229
+ */
230
+ _reachableNodes(graph, directDeps, ignoredDeps) {
231
+ let reachable = new Set();
232
+ let queue = directDeps.filter(k => !ignoredDeps.has(k) && graph.has(k));
233
+ while (queue.length > 0) {
234
+ let key = queue.shift();
235
+ if (reachable.has(key)) {
236
+ continue;
237
+ }
238
+ reachable.add(key);
239
+ for (let child of graph.get(key).children) {
240
+ if (!ignoredDeps.has(child) && graph.has(child) && !reachable.has(child)) {
241
+ queue.push(child);
242
+ }
243
+ }
244
+ }
245
+ return reachable;
246
+ }
247
+ /**
248
+ * @param {string} name
249
+ * @param {string} version
250
+ * @returns {PackageURL}
251
+ * @protected
252
+ */
253
+ _toPurl(name, version) {
254
+ return new PackageURL('pypi', undefined, name, version, undefined, undefined);
255
+ }
256
+ /**
257
+ * Create SBOM json string for a pyproject.toml project.
258
+ * @param {string} manifest - path to pyproject.toml
259
+ * @param {Object} opts
260
+ * @param {boolean} includeTransitive
261
+ * @returns {Promise<string>}
262
+ * @private
263
+ */
264
+ async _createSbom(manifest, opts, includeTransitive) {
265
+ let manifestDir = path.dirname(manifest);
266
+ let content = fs.readFileSync(manifest, 'utf-8');
267
+ let parsed = parseToml(content);
268
+ let workspaceDir = this._findLockFileDir(manifestDir, opts) || manifestDir;
269
+ let { directDeps, graph } = await this._getDependencyData(manifestDir, workspaceDir, parsed, opts);
270
+ let ignoredDeps = this._getIgnoredDeps(manifest);
271
+ let sbom = new Sbom();
272
+ let rootName = this._getProjectName(parsed) || DEFAULT_ROOT_NAME;
273
+ let rootVersion = this._getProjectVersion(parsed) || DEFAULT_ROOT_VERSION;
274
+ let rootPurl = this._toPurl(rootName, rootVersion);
275
+ let license = this.readLicenseFromManifest(manifest);
276
+ sbom.addRoot(rootPurl, license);
277
+ if (includeTransitive) {
278
+ let reachable = this._reachableNodes(graph, directDeps, ignoredDeps);
279
+ for (let key of directDeps) {
280
+ if (!reachable.has(key)) {
281
+ continue;
282
+ }
283
+ let entry = graph.get(key);
284
+ sbom.addDependency(rootPurl, this._toPurl(entry.name, entry.version));
285
+ }
286
+ for (let [key, entry] of graph) {
287
+ if (!reachable.has(key)) {
288
+ continue;
289
+ }
290
+ let parentPurl = this._toPurl(entry.name, entry.version);
291
+ for (let child of entry.children) {
292
+ if (!reachable.has(child)) {
293
+ continue;
294
+ }
295
+ let childEntry = graph.get(child);
296
+ sbom.addDependency(parentPurl, this._toPurl(childEntry.name, childEntry.version));
297
+ }
298
+ }
299
+ }
300
+ else {
301
+ for (let key of directDeps) {
302
+ if (ignoredDeps.has(key)) {
303
+ continue;
304
+ }
305
+ let entry = graph.get(key);
306
+ if (!entry) {
307
+ continue;
308
+ }
309
+ sbom.addDependency(rootPurl, this._toPurl(entry.name, entry.version));
310
+ }
311
+ }
312
+ return sbom.getAsJsonString(opts);
313
+ }
314
+ }
@@ -1,4 +1,5 @@
1
1
  export default class Javascript_npm extends Base_javascript {
2
2
  _listCmdArgs(includeTransitive: any): string[];
3
+ _buildDependencyTree(includeTransitive: any, opts?: {}): any;
3
4
  }
4
5
  import Base_javascript from './base_javascript.js';
@@ -12,4 +12,25 @@ export default class Javascript_npm extends Base_javascript {
12
12
  _updateLockFileCmdArgs() {
13
13
  return ['install', '--package-lock-only'];
14
14
  }
15
+ _buildDependencyTree(includeTransitive, opts = {}) {
16
+ // npm ls --json returns a single tree rooted at the workspace root.
17
+ // When analyzing a workspace member, its deps are nested under the
18
+ // root's dependencies keyed by the member name — extract that subtree
19
+ // so downstream analysis sees only the member's dependencies.
20
+ const tree = super._buildDependencyTree(includeTransitive, opts);
21
+ const memberName = this._getManifest().name;
22
+ if (tree.name === memberName) {
23
+ return tree;
24
+ }
25
+ const memberEntry = tree.dependencies?.[memberName];
26
+ if (memberEntry) {
27
+ return {
28
+ name: memberName,
29
+ version: memberEntry.version || this._getManifest().version,
30
+ dependencies: memberEntry.dependencies,
31
+ optionalDependencies: memberEntry.optionalDependencies,
32
+ };
33
+ }
34
+ return tree;
35
+ }
15
36
  }
@@ -7,15 +7,19 @@ export default class Javascript_pnpm extends Base_javascript {
7
7
  return "pnpm";
8
8
  }
9
9
  _listCmdArgs(includeTransitive) {
10
- return ['ls', includeTransitive ? '--depth=Infinity' : '--depth=0', '--prod', '--json'];
10
+ return ['ls', includeTransitive ? '--depth=Infinity' : '--depth=0', '--prod', '--json', '-r'];
11
11
  }
12
12
  _updateLockFileCmdArgs() {
13
13
  return ['install', '--frozen-lockfile'];
14
14
  }
15
15
  _buildDependencyTree(includeTransitive, opts = {}) {
16
+ // pnpm ls --json returns an array with one entry per workspace package.
17
+ // When analyzing a workspace member, find its entry by name instead of
18
+ // blindly taking the first element (which is the workspace root).
16
19
  const tree = super._buildDependencyTree(includeTransitive, opts);
17
20
  if (Array.isArray(tree) && tree.length > 0) {
18
- return tree[0];
21
+ const memberName = this._getManifest().name;
22
+ return tree.find(pkg => pkg.name === memberName) || tree[0];
19
23
  }
20
24
  return {};
21
25
  }
@@ -15,7 +15,10 @@ export default class Yarn_berry_processor extends Yarn_processor {
15
15
  * @returns {string[]} Command arguments for listing dependencies
16
16
  */
17
17
  listCmdArgs(includeTransitive) {
18
- return ['info', includeTransitive ? '--recursive' : '--all', '--json'];
18
+ // --all is needed to include workspace members in the output
19
+ return includeTransitive
20
+ ? ['info', '--recursive', '--all', '--json']
21
+ : ['info', '--all', '--json'];
19
22
  }
20
23
  /**
21
24
  * Returns the command arguments for updating the lock file
@@ -68,7 +71,8 @@ export default class Yarn_berry_processor extends Yarn_processor {
68
71
  if (!name) {
69
72
  return false;
70
73
  }
71
- return name.endsWith("@workspace:.");
74
+ // Workspace members use paths like "member-a@workspace:packages/member-a", not just "@workspace:."
75
+ return name.startsWith(`${this._manifest.name}@workspace:`);
72
76
  }
73
77
  /**
74
78
  * Adds dependencies to the SBOM
@@ -95,7 +95,7 @@ export default class Python_controller {
95
95
  }
96
96
  /**
97
97
  * Parse the requirements.txt file using tree-sitter and return structured requirement data.
98
- * @return {Promise<{name: string, version: string|null}[]>}
98
+ * @return {Promise<{name: string, version: string|null, hasMarker: boolean}[]>}
99
99
  */
100
100
  async #parseRequirements() {
101
101
  const content = fs.readFileSync(this.pathToRequirements).toString();
@@ -107,7 +107,8 @@ export default class Python_controller {
107
107
  const version = versionMatches.length > 0
108
108
  ? versionMatches[0].captures.find(c => c.name === 'version').node.text
109
109
  : null;
110
- return { name, version };
110
+ const hasMarker = reqNode.children.some(c => c.type === 'marker_spec');
111
+ return { name, version, hasMarker };
111
112
  }));
112
113
  }
113
114
  #decideIfWindowsOrLinuxPath(fileName) {
@@ -224,7 +225,10 @@ export default class Python_controller {
224
225
  CachedEnvironmentDeps[packageName.replace("_", "-")] = pipDepTreeEntryForCache;
225
226
  });
226
227
  }
227
- parsedRequirements.forEach(({ name: depName, version: manifestVersion }) => {
228
+ parsedRequirements.forEach(({ name: depName, version: manifestVersion, hasMarker }) => {
229
+ if (hasMarker && CachedEnvironmentDeps[depName.toLowerCase()] === undefined) {
230
+ return;
231
+ }
228
232
  if (matchManifestVersions === "true" && manifestVersion != null) {
229
233
  let installedVersion;
230
234
  if (CachedEnvironmentDeps[depName.toLowerCase()] !== undefined) {
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Python provider for pyproject.toml files using PEP 621 format without a lock file.
3
+ * Uses `pip install --dry-run --ignore-installed --report` to resolve the full dependency tree.
4
+ * Acts as the fallback provider when no lock file (uv.lock/poetry.lock) is found.
5
+ */
6
+ export default class Python_pip_pyproject extends Base_pyproject {
7
+ /**
8
+ * Always returns true — pip provider is the fallback when no lock file is found.
9
+ * @param {string} manifestDir
10
+ * @param {{}} [opts={}]
11
+ * @returns {boolean}
12
+ */
13
+ validateLockFile(manifestDir: string, opts?: {}): boolean;
14
+ /**
15
+ * Get pip report output from env var override or by running pip.
16
+ * @param {string} manifestDir - directory containing pyproject.toml
17
+ * @param {{}} [opts={}]
18
+ * @returns {string} pip report JSON string
19
+ */
20
+ _getPipReportOutput(manifestDir: string, opts?: {}): string;
21
+ /**
22
+ * Parse pip report JSON and build dependency graph.
23
+ * @param {string} reportJson - pip report JSON string
24
+ * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
25
+ */
26
+ _parsePipReport(reportJson: string): {
27
+ directDeps: string[];
28
+ graph: Map<string, {
29
+ name: string;
30
+ version: string;
31
+ children: string[];
32
+ }>;
33
+ };
34
+ /**
35
+ * Check if a requires_dist entry is an extras-only dependency.
36
+ * @param {string} req - e.g. "PySocks!=1.5.7,>=1.5.6; extra == \"socks\""
37
+ * @returns {boolean}
38
+ */
39
+ _hasExtraMarker(req: string): boolean;
40
+ /**
41
+ * Extract package name from a requires_dist entry.
42
+ * @param {string} req - e.g. "charset_normalizer<4,>=2"
43
+ * @returns {string|null}
44
+ */
45
+ _extractDepName(req: string): string | null;
46
+ /**
47
+ * Resolve dependencies using pip install --dry-run --report.
48
+ * @param {string} manifestDir
49
+ * @param {string} _workspaceDir - unused (pip resolves from manifest directory)
50
+ * @param {object} parsed - parsed pyproject.toml
51
+ * @param {{}} [opts={}]
52
+ * @returns {Promise<{directDeps: string[], graph: Map}>}
53
+ */
54
+ _getDependencyData(manifestDir: string, _workspaceDir: string, parsed: object, opts?: {}): Promise<{
55
+ directDeps: string[];
56
+ graph: Map<any, any>;
57
+ }>;
58
+ _findEggInfoDirs(dir: any): string[];
59
+ _cleanupEggInfo(dir: any, existing: any): void;
60
+ }
61
+ import Base_pyproject from './base_pyproject.js';
@@ -0,0 +1,144 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js';
4
+ import Base_pyproject from './base_pyproject.js';
5
+ /**
6
+ * Python provider for pyproject.toml files using PEP 621 format without a lock file.
7
+ * Uses `pip install --dry-run --ignore-installed --report` to resolve the full dependency tree.
8
+ * Acts as the fallback provider when no lock file (uv.lock/poetry.lock) is found.
9
+ */
10
+ export default class Python_pip_pyproject extends Base_pyproject {
11
+ /** @returns {string} */
12
+ _lockFileName() {
13
+ return '.pip-lock-nonexistent';
14
+ }
15
+ /** @returns {string} */
16
+ _cmdName() {
17
+ return 'pip';
18
+ }
19
+ /**
20
+ * Always returns true — pip provider is the fallback when no lock file is found.
21
+ * @param {string} manifestDir
22
+ * @param {{}} [opts={}]
23
+ * @returns {boolean}
24
+ */
25
+ // eslint-disable-next-line no-unused-vars
26
+ validateLockFile(manifestDir, opts = {}) {
27
+ return true;
28
+ }
29
+ /**
30
+ * Get pip report output from env var override or by running pip.
31
+ * @param {string} manifestDir - directory containing pyproject.toml
32
+ * @param {{}} [opts={}]
33
+ * @returns {string} pip report JSON string
34
+ */
35
+ _getPipReportOutput(manifestDir, opts) {
36
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_PIP_REPORT')) {
37
+ return Buffer.from(process.env['TRUSTIFY_DA_PIP_REPORT'], 'base64').toString('ascii');
38
+ }
39
+ let pipBin = getCustomPath('pip3', opts);
40
+ try {
41
+ invokeCommand(pipBin, ['--version']);
42
+ }
43
+ catch {
44
+ pipBin = getCustomPath('pip', opts);
45
+ }
46
+ let eggInfoDirs = this._findEggInfoDirs(manifestDir);
47
+ let result = invokeCommand(pipBin, [
48
+ 'install', '--dry-run', '--ignore-installed', '--quiet', '--report', '-', '.'
49
+ ], { cwd: manifestDir }).toString();
50
+ this._cleanupEggInfo(manifestDir, eggInfoDirs);
51
+ return result;
52
+ }
53
+ /**
54
+ * Parse pip report JSON and build dependency graph.
55
+ * @param {string} reportJson - pip report JSON string
56
+ * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
57
+ */
58
+ _parsePipReport(reportJson) {
59
+ let report = JSON.parse(reportJson);
60
+ let packages = report.install || [];
61
+ let rootEntry = packages.find(p => p.download_info?.dir_info !== undefined);
62
+ let rootRequires = rootEntry?.metadata?.requires_dist || [];
63
+ let directDepNames = new Set();
64
+ for (let req of rootRequires) {
65
+ if (this._hasExtraMarker(req)) {
66
+ continue;
67
+ }
68
+ let name = this._extractDepName(req);
69
+ if (name) {
70
+ directDepNames.add(this._canonicalize(name));
71
+ }
72
+ }
73
+ let graph = new Map();
74
+ let nonRootPackages = packages.filter(p => p !== rootEntry);
75
+ for (let pkg of nonRootPackages) {
76
+ let name = pkg.metadata.name;
77
+ let version = pkg.metadata.version;
78
+ let key = this._canonicalize(name);
79
+ graph.set(key, { name, version, children: [] });
80
+ }
81
+ for (let pkg of nonRootPackages) {
82
+ let key = this._canonicalize(pkg.metadata.name);
83
+ let entry = graph.get(key);
84
+ let requires = pkg.metadata.requires_dist || [];
85
+ for (let req of requires) {
86
+ let depName = this._extractDepName(req);
87
+ if (!depName) {
88
+ continue;
89
+ }
90
+ let depKey = this._canonicalize(depName);
91
+ if (graph.has(depKey)) {
92
+ entry.children.push(depKey);
93
+ }
94
+ }
95
+ }
96
+ let directDeps = [...directDepNames].filter(key => graph.has(key));
97
+ return { directDeps, graph };
98
+ }
99
+ /**
100
+ * Check if a requires_dist entry is an extras-only dependency.
101
+ * @param {string} req - e.g. "PySocks!=1.5.7,>=1.5.6; extra == \"socks\""
102
+ * @returns {boolean}
103
+ */
104
+ _hasExtraMarker(req) {
105
+ return /;\s*.*extra\s*==/.test(req);
106
+ }
107
+ /**
108
+ * Extract package name from a requires_dist entry.
109
+ * @param {string} req - e.g. "charset_normalizer<4,>=2"
110
+ * @returns {string|null}
111
+ */
112
+ _extractDepName(req) {
113
+ let match = req.match(/^([A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?)/);
114
+ return match ? match[1] : null;
115
+ }
116
+ /**
117
+ * Resolve dependencies using pip install --dry-run --report.
118
+ * @param {string} manifestDir
119
+ * @param {string} _workspaceDir - unused (pip resolves from manifest directory)
120
+ * @param {object} parsed - parsed pyproject.toml
121
+ * @param {{}} [opts={}]
122
+ * @returns {Promise<{directDeps: string[], graph: Map}>}
123
+ */
124
+ // eslint-disable-next-line no-unused-vars
125
+ async _getDependencyData(manifestDir, _workspaceDir, parsed, opts) {
126
+ let reportOutput = this._getPipReportOutput(manifestDir, opts);
127
+ return this._parsePipReport(reportOutput);
128
+ }
129
+ _findEggInfoDirs(dir) {
130
+ try {
131
+ return fs.readdirSync(dir).filter(f => f.endsWith('.egg-info'));
132
+ }
133
+ catch {
134
+ return [];
135
+ }
136
+ }
137
+ _cleanupEggInfo(dir, existing) {
138
+ for (let entry of this._findEggInfoDirs(dir)) {
139
+ if (!existing.includes(entry)) {
140
+ fs.rmSync(path.join(dir, entry), { recursive: true, force: true });
141
+ }
142
+ }
143
+ }
144
+ }
@@ -0,0 +1,43 @@
1
+ export default class Python_poetry extends Base_pyproject {
2
+ /**
3
+ * Get poetry show --tree output.
4
+ * @param {string} manifestDir
5
+ * @param {boolean} hasDevGroup
6
+ * @param {Object} opts
7
+ * @returns {string}
8
+ */
9
+ _getPoetryShowTreeOutput(manifestDir: string, hasDevGroup: boolean, opts: any): string;
10
+ /**
11
+ * Get poetry show --all output (flat list with resolved versions).
12
+ * @param {string} manifestDir
13
+ * @param {Object} opts
14
+ * @returns {string}
15
+ */
16
+ _getPoetryShowAllOutput(manifestDir: string, opts: any): string;
17
+ /**
18
+ * Parse poetry show --all output into a version map.
19
+ * Lines look like: "name (!) 1.2.3 Description text..."
20
+ * or: "name 1.2.3 Description text..."
21
+ * @param {string} output
22
+ * @returns {Map<string, string>} canonical name -> version
23
+ */
24
+ _parsePoetryShowAll(output: string): Map<string, string>;
25
+ /**
26
+ * Parse poetry show --tree output into a dependency graph structure.
27
+ * Top-level lines (no indentation/tree chars) are direct deps: "name version description"
28
+ * Indented lines are transitive deps with tree chars: "├── name >=constraint"
29
+ *
30
+ * @param {string} treeOutput
31
+ * @param {Map<string, string>} versionMap - canonical name -> resolved version
32
+ * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
33
+ */
34
+ _parsePoetryTree(treeOutput: string, versionMap: Map<string, string>): {
35
+ directDeps: string[];
36
+ graph: Map<string, {
37
+ name: string;
38
+ version: string;
39
+ children: string[];
40
+ }>;
41
+ };
42
+ }
43
+ import Base_pyproject from './base_pyproject.js';