@vercel/python-analysis 0.3.0 → 0.3.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.
@@ -1,400 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var requirements_txt_parser_exports = {};
20
- __export(requirements_txt_parser_exports, {
21
- convertRequirementsToPyprojectToml: () => convertRequirementsToPyprojectToml,
22
- parseRequirementsFile: () => parseRequirementsFile
23
- });
24
- module.exports = __toCommonJS(requirements_txt_parser_exports);
25
- var import_node_path = require("node:path");
26
- var import_pip_requirements_js = require("pip-requirements-js");
27
- var import_pep508 = require("./pep508");
28
- const PRIMARY_INDEX_NAME = "primary";
29
- const EXTRA_INDEX_PREFIX = "extra-";
30
- function parseGitUrl(url) {
31
- if (!url.startsWith("git+")) {
32
- return null;
33
- }
34
- let remaining = url.slice(4);
35
- let egg;
36
- const fragmentIdx = remaining.indexOf("#");
37
- if (fragmentIdx !== -1) {
38
- const fragment = remaining.slice(fragmentIdx + 1);
39
- remaining = remaining.slice(0, fragmentIdx);
40
- for (const part of fragment.split("&")) {
41
- const [key, value] = part.split("=");
42
- if (key === "egg" && value) {
43
- egg = value;
44
- }
45
- }
46
- }
47
- let ref;
48
- const lastSlashIdx = remaining.lastIndexOf("/");
49
- const atIdx = remaining.indexOf("@", lastSlashIdx > 0 ? lastSlashIdx : 0);
50
- if (atIdx !== -1 && atIdx > remaining.indexOf("://")) {
51
- ref = remaining.slice(atIdx + 1);
52
- remaining = remaining.slice(0, atIdx);
53
- }
54
- return {
55
- url: remaining,
56
- ref,
57
- egg
58
- };
59
- }
60
- function isGitUrl(url) {
61
- return url.startsWith("git+");
62
- }
63
- function extractPipArguments(fileContent) {
64
- const options = {
65
- requirementFiles: [],
66
- constraintFiles: [],
67
- extraIndexUrls: []
68
- };
69
- const lines = fileContent.split(/\r?\n/);
70
- const cleanedLines = [];
71
- for (let i = 0; i < lines.length; i++) {
72
- const line = lines[i];
73
- const trimmed = line.trim();
74
- if (trimmed === "" || trimmed.startsWith("#")) {
75
- cleanedLines.push(line);
76
- continue;
77
- }
78
- let fullLine = trimmed;
79
- let linesConsumed = 0;
80
- while (fullLine.endsWith("\\") && i + linesConsumed + 1 < lines.length) {
81
- linesConsumed++;
82
- fullLine = fullLine.slice(0, -1) + lines[i + linesConsumed].trim();
83
- }
84
- const extracted = tryExtractPipArgument(fullLine, options);
85
- if (extracted) {
86
- i += linesConsumed;
87
- } else {
88
- const strippedLine = stripInlineHashes(fullLine);
89
- if (strippedLine !== fullLine) {
90
- cleanedLines.push(strippedLine);
91
- } else {
92
- cleanedLines.push(line);
93
- for (let j = 1; j <= linesConsumed; j++) {
94
- cleanedLines.push(lines[i + j]);
95
- }
96
- }
97
- i += linesConsumed;
98
- }
99
- }
100
- return {
101
- cleanedContent: cleanedLines.join("\n"),
102
- options
103
- };
104
- }
105
- function tryExtractPipArgument(line, options) {
106
- if (line.startsWith("--requirement")) {
107
- const path = extractArgValue(line, "--requirement");
108
- if (path) {
109
- options.requirementFiles.push(path);
110
- return true;
111
- }
112
- }
113
- if (line.startsWith("--constraint")) {
114
- const path = extractArgValue(line, "--constraint");
115
- if (path) {
116
- options.constraintFiles.push(path);
117
- return true;
118
- }
119
- }
120
- if (line.startsWith("--index-url")) {
121
- const url = extractArgValue(line, "--index-url");
122
- if (url) {
123
- options.indexUrl = url;
124
- return true;
125
- }
126
- }
127
- if (line.startsWith("-i ") || line === "-i") {
128
- const match = line.match(/^-i\s+(\S+)/);
129
- if (match) {
130
- options.indexUrl = match[1];
131
- return true;
132
- }
133
- }
134
- if (line.startsWith("--extra-index-url")) {
135
- const url = extractArgValue(line, "--extra-index-url");
136
- if (url) {
137
- options.extraIndexUrls.push(url);
138
- return true;
139
- }
140
- }
141
- return false;
142
- }
143
- function stripInlineHashes(line) {
144
- return line.replace(/\s+--hash=\S+/g, "").trim();
145
- }
146
- function extractInlineHashes(line) {
147
- const hashes = [];
148
- const hashRegex = /--hash=(\S+)/g;
149
- let match;
150
- while ((match = hashRegex.exec(line)) != null) {
151
- hashes.push(match[1]);
152
- }
153
- return hashes;
154
- }
155
- function extractArgValue(line, option) {
156
- if (line.startsWith(`${option}=`)) {
157
- const value = line.slice(option.length + 1).trim();
158
- return value || null;
159
- }
160
- if (line.startsWith(`${option} `) || line.startsWith(`${option} `)) {
161
- const value = line.slice(option.length).trim();
162
- return value || null;
163
- }
164
- return null;
165
- }
166
- function convertRequirementsToPyprojectToml(fileContent, readFile) {
167
- const pyproject = {};
168
- const parsed = parseRequirementsFile(fileContent, readFile);
169
- const deps = [];
170
- const sources = {};
171
- for (const req of parsed.requirements) {
172
- deps.push((0, import_pep508.formatPep508)(req));
173
- if (req.source) {
174
- if (Object.prototype.hasOwnProperty.call(sources, req.name)) {
175
- sources[req.name].push(req.source);
176
- } else {
177
- sources[req.name] = [req.source];
178
- }
179
- }
180
- }
181
- if (deps.length > 0) {
182
- pyproject.project = {
183
- dependencies: deps
184
- };
185
- }
186
- const uv = {};
187
- const indexes = buildIndexEntries(parsed.pipOptions);
188
- if (indexes.length > 0) {
189
- uv.index = indexes;
190
- }
191
- if (Object.keys(sources).length > 0) {
192
- uv.sources = sources;
193
- }
194
- if (Object.keys(uv).length > 0) {
195
- pyproject.tool = { uv };
196
- }
197
- return pyproject;
198
- }
199
- function buildIndexEntries(pipOptions) {
200
- const indexes = [];
201
- if (pipOptions.indexUrl) {
202
- indexes.push({
203
- name: PRIMARY_INDEX_NAME,
204
- url: pipOptions.indexUrl,
205
- default: true
206
- });
207
- }
208
- for (let i = 0; i < pipOptions.extraIndexUrls.length; i++) {
209
- indexes.push({
210
- name: `${EXTRA_INDEX_PREFIX}${i + 1}`,
211
- url: pipOptions.extraIndexUrls[i]
212
- });
213
- }
214
- return indexes;
215
- }
216
- function parseRequirementsFile(fileContent, readFile) {
217
- const visited = /* @__PURE__ */ new Set();
218
- return parseRequirementsFileInternal(fileContent, readFile, visited);
219
- }
220
- function parseRequirementsFileInternal(fileContent, readFile, visited) {
221
- const { cleanedContent, options } = extractPipArguments(fileContent);
222
- const hashMap = buildHashMap(fileContent);
223
- const requirements = (0, import_pip_requirements_js.parsePipRequirementsFile)(cleanedContent);
224
- const normalized = [];
225
- const mergedOptions = {
226
- requirementFiles: [...options.requirementFiles],
227
- constraintFiles: [...options.constraintFiles],
228
- indexUrl: options.indexUrl,
229
- extraIndexUrls: [...options.extraIndexUrls]
230
- };
231
- for (const req of requirements) {
232
- if (req.type === "RequirementsFile") {
233
- mergedOptions.requirementFiles.push(req.path);
234
- continue;
235
- }
236
- if (req.type === "ConstraintsFile") {
237
- mergedOptions.constraintFiles.push(req.path);
238
- continue;
239
- }
240
- const norm = normalizeRequirement(req);
241
- if (norm != null) {
242
- const hashes = hashMap.get(norm.name.toLowerCase());
243
- if (hashes && hashes.length > 0) {
244
- norm.hashes = hashes;
245
- }
246
- normalized.push(norm);
247
- }
248
- }
249
- if (readFile) {
250
- for (const refPath of mergedOptions.requirementFiles) {
251
- const refPathKey = (0, import_node_path.normalize)(refPath);
252
- if (visited.has(refPathKey)) {
253
- continue;
254
- }
255
- visited.add(refPathKey);
256
- const refContent = readFile(refPath);
257
- if (refContent != null) {
258
- const refParsed = parseRequirementsFileInternal(
259
- refContent,
260
- readFile,
261
- visited
262
- );
263
- const existingNames = new Set(
264
- normalized.map((r) => r.name.toLowerCase())
265
- );
266
- for (const req of refParsed.requirements) {
267
- if (!existingNames.has(req.name.toLowerCase())) {
268
- normalized.push(req);
269
- existingNames.add(req.name.toLowerCase());
270
- }
271
- }
272
- if (refParsed.pipOptions.indexUrl) {
273
- mergedOptions.indexUrl = refParsed.pipOptions.indexUrl;
274
- }
275
- for (const url of refParsed.pipOptions.extraIndexUrls) {
276
- if (!mergedOptions.extraIndexUrls.includes(url)) {
277
- mergedOptions.extraIndexUrls.push(url);
278
- }
279
- }
280
- for (const constraintPath of refParsed.pipOptions.constraintFiles) {
281
- if (!mergedOptions.constraintFiles.includes(constraintPath)) {
282
- mergedOptions.constraintFiles.push(constraintPath);
283
- }
284
- }
285
- }
286
- }
287
- }
288
- return {
289
- requirements: normalized,
290
- pipOptions: mergedOptions
291
- };
292
- }
293
- function buildHashMap(fileContent) {
294
- const hashMap = /* @__PURE__ */ new Map();
295
- const lines = fileContent.split(/\r?\n/);
296
- for (let i = 0; i < lines.length; i++) {
297
- let line = lines[i].trim();
298
- if (line === "" || line.startsWith("#") || line.startsWith("-")) {
299
- continue;
300
- }
301
- while (line.endsWith("\\") && i + 1 < lines.length) {
302
- i++;
303
- line = line.slice(0, -1) + lines[i].trim();
304
- }
305
- const hashes = extractInlineHashes(line);
306
- if (hashes.length === 0) {
307
- continue;
308
- }
309
- const packageMatch = line.match(/^([a-zA-Z0-9][-a-zA-Z0-9._]*)/);
310
- if (packageMatch) {
311
- const packageName = packageMatch[1].toLowerCase();
312
- hashMap.set(packageName, hashes);
313
- }
314
- }
315
- return hashMap;
316
- }
317
- function normalizeRequirement(req) {
318
- if (req.type === "RequirementsFile" || req.type === "ConstraintsFile") {
319
- return null;
320
- }
321
- if (req.type === "ProjectURL") {
322
- return normalizeProjectURLRequirement(req);
323
- }
324
- if (req.type === "ProjectName") {
325
- return normalizeProjectNameRequirement(req);
326
- }
327
- return null;
328
- }
329
- function normalizeProjectNameRequirement(req) {
330
- const normalized = {
331
- name: req.name
332
- };
333
- if (req.extras && req.extras.length > 0) {
334
- normalized.extras = req.extras;
335
- }
336
- if (req.versionSpec && req.versionSpec.length > 0) {
337
- normalized.version = req.versionSpec.map((spec) => `${spec.operator}${spec.version}`).join(",");
338
- }
339
- if (req.environmentMarkerTree) {
340
- normalized.markers = formatEnvironmentMarkers(req.environmentMarkerTree);
341
- }
342
- return normalized;
343
- }
344
- function normalizeProjectURLRequirement(req) {
345
- const normalized = {
346
- name: req.name
347
- };
348
- if (req.extras && req.extras.length > 0) {
349
- normalized.extras = req.extras;
350
- }
351
- if (req.environmentMarkerTree) {
352
- normalized.markers = formatEnvironmentMarkers(req.environmentMarkerTree);
353
- }
354
- if (isGitUrl(req.url)) {
355
- const parsed = parseGitUrl(req.url);
356
- if (parsed) {
357
- const source = {
358
- git: parsed.url
359
- };
360
- if (parsed.ref) {
361
- source.rev = parsed.ref;
362
- }
363
- if (parsed.editable) {
364
- source.editable = true;
365
- }
366
- normalized.source = source;
367
- }
368
- }
369
- normalized.url = req.url;
370
- return normalized;
371
- }
372
- function formatEnvironmentMarkers(marker) {
373
- if (isEnvironmentMarkerNode(marker)) {
374
- const left = formatEnvironmentMarkers(marker.left);
375
- const right = formatEnvironmentMarkers(marker.right);
376
- return `(${left}) ${marker.operator} (${right})`;
377
- }
378
- const leaf = marker;
379
- const leftStr = formatMarkerValue(leaf.left);
380
- const rightStr = formatMarkerValue(leaf.right);
381
- return `${leftStr} ${leaf.operator} ${rightStr}`;
382
- }
383
- function isEnvironmentMarkerNode(marker) {
384
- if (typeof marker !== "object" || marker == null) {
385
- return false;
386
- }
387
- const op = marker.operator;
388
- return op === "and" || op === "or";
389
- }
390
- function formatMarkerValue(value) {
391
- if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
392
- return value;
393
- }
394
- return value;
395
- }
396
- // Annotate the CommonJS export names for ESM import in node:
397
- 0 && (module.exports = {
398
- convertRequirementsToPyprojectToml,
399
- parseRequirementsFile
400
- });
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var schema_exports = {};
20
- __export(schema_exports, {
21
- UvConfigSchema: () => UvConfigSchema,
22
- UvConfigWorkspaceSchema: () => UvConfigWorkspaceSchema,
23
- UvIndexEntrySchema: () => UvIndexEntrySchema
24
- });
25
- module.exports = __toCommonJS(schema_exports);
26
- var import_schema = require("./schema.zod");
27
- const UvConfigWorkspaceSchema = import_schema.uvConfigWorkspaceSchema.passthrough();
28
- const UvIndexEntrySchema = import_schema.uvIndexEntrySchema.passthrough();
29
- const UvConfigSchema = import_schema.uvConfigSchema.passthrough();
30
- // Annotate the CommonJS export names for ESM import in node:
31
- 0 && (module.exports = {
32
- UvConfigSchema,
33
- UvConfigWorkspaceSchema,
34
- UvIndexEntrySchema
35
- });
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var schema_zod_exports = {};
20
- __export(schema_zod_exports, {
21
- uvConfigSchema: () => uvConfigSchema,
22
- uvConfigWorkspaceSchema: () => uvConfigWorkspaceSchema,
23
- uvIndexEntrySchema: () => uvIndexEntrySchema
24
- });
25
- module.exports = __toCommonJS(schema_zod_exports);
26
- var import_zod = require("zod");
27
- var import_schema = require("./../requirement/schema.zod");
28
- const uvConfigWorkspaceSchema = import_zod.z.object({
29
- members: import_zod.z.array(import_zod.z.string()).optional(),
30
- exclude: import_zod.z.array(import_zod.z.string()).optional()
31
- });
32
- const uvIndexEntrySchema = import_zod.z.object({
33
- name: import_zod.z.string(),
34
- url: import_zod.z.string(),
35
- default: import_zod.z.boolean().optional(),
36
- explicit: import_zod.z.boolean().optional()
37
- });
38
- const uvConfigSchema = import_zod.z.object({
39
- sources: import_zod.z.record(import_zod.z.union([import_schema.dependencySourceSchema, import_zod.z.array(import_schema.dependencySourceSchema)])).optional(),
40
- index: import_zod.z.array(uvIndexEntrySchema).optional(),
41
- workspace: uvConfigWorkspaceSchema.optional()
42
- });
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- uvConfigSchema,
46
- uvConfigWorkspaceSchema,
47
- uvIndexEntrySchema
48
- });
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);