UNPKG

pip-requirements-js

Version:

A robust parser for requirements.txt files

96 lines 4.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RequirementsSyntaxError = exports.semantics = void 0; const pep_508_ohm_bundle_1 = __importDefault(require("./pep-508.ohm-bundle")); exports.semantics = pep_508_ohm_bundle_1.default.createSemantics(); /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ exports.semantics.addOperation('extract', { /* eslint-disable @typescript-eslint/no-unused-vars */ File: (linesList) => linesList .asIteration() .children.map((line) => line.extract()) .filter(Boolean), Line: (req, _comment) => { var _a; return ((_a = req.child(0)) === null || _a === void 0 ? void 0 : _a.extract()) || null; }, NameReq: (name, extras, versionSpec, markers) => { var _a, _b; return ({ type: 'ProjectName', name: name.sourceString, versionSpec: versionSpec.extract(), extras: (_a = extras.child(0)) === null || _a === void 0 ? void 0 : _a.extract(), environmentMarkerTree: (_b = markers.child(0)) === null || _b === void 0 ? void 0 : _b.extract(), }); }, UrlReq: (name, extras, url, _space, markers) => { var _a, _b; return ({ type: 'ProjectURL', name: name.sourceString, url: url.extract(), extras: (_a = extras.child(0)) === null || _a === void 0 ? void 0 : _a.extract(), environmentMarkerTree: (_b = markers.child(0)) === null || _b === void 0 ? void 0 : _b.extract(), }); }, Extras: (_open, extrasList, _close) => extrasList.asIteration().children.map((extra) => extra.sourceString), RequirementsReq: (_dashR, filePath) => ({ type: 'RequirementsFile', path: filePath.sourceString, }), ConstraintsReq: (_dashC, filePath) => ({ type: 'ConstraintsFile', path: filePath.sourceString, }), UrlSpec: (_at, uriReference) => uriReference.sourceString, QuotedMarker: (_semi, marker) => marker.extract(), MarkerOr_node: (left, _or, right) => ({ operator: 'or', left: left.extract(), right: right.extract(), }), MarkerAnd_node: (left, _and, right) => ({ operator: 'and', left: left.extract(), right: right.extract(), }), MarkerExpr_leaf: (left, operator, right) => ({ left: left.sourceString, operator: operator.sourceString, right: right.sourceString, }), MarkerExpr_node: (_open, marker, _close) => marker.extract(), VersionSpec_parenthesized: (_open, versionMany, _close) => versionMany.extract() || [], VersionMany: (versionOnesList) => { const versionOnes = versionOnesList.asIteration().children; if (versionOnes.length === 0) { return undefined; } return versionOnes.map((versionOne) => versionOne.extract()); }, VersionOne: (operator, version) => ({ operator: operator.sourceString, version: version.sourceString, }), /* eslint-enable @typescript-eslint/no-unused-vars */ }); /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ exports.semantics.addOperation('extractLoosely', { /* eslint-disable @typescript-eslint/no-unused-vars */ LooseFile: (linesList) => linesList .asIteration() .children.map((line) => line.extractLoosely()) .filter(Boolean), LooseLine: (req, _comment) => { var _a; return ((_a = req.child(0)) === null || _a === void 0 ? void 0 : _a.extractLoosely()) || null; }, LooseNameReq: (name, _extras, _versionSpec, _markers) => ({ type: 'ProjectName', name: name.sourceString, }), LooseNonNameReq: (_) => null, /* eslint-enable @typescript-eslint/no-unused-vars */ }); class RequirementsSyntaxError extends Error { } exports.RequirementsSyntaxError = RequirementsSyntaxError; //# sourceMappingURL=semantics.js.map