UNPKG

@coat/cli

Version:

TODO: See #3

79 lines (78 loc) 3.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateCoatManifestDependencies = validateCoatManifestDependencies; var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject")); var _formatPropertyPath = require("../format-property-path"); var _handleUnknownProperties = require("../handle-unknown-properties"); var _validationIssue = require("../validation-issue"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function* validateDependenciesType(dependencies, propertyName) { if (typeof dependencies === "undefined") { return; } const propertyPath = ["dependencies", propertyName]; const messagePrefix = (0, _formatPropertyPath.formatPropertyPath)(propertyPath); if (!(0, _isPlainObject.default)(dependencies)) { yield { type: _validationIssue.ValidationIssueType.Error, message: `${messagePrefix} must be an object.`, propertyPath, shortMessage: "must be an object." }; } else { const dependencyEntries = Object.entries(dependencies); for (const [dependencyKey, dependencyVersion] of dependencyEntries) { // Should not contain any empty key if (dependencyKey === "") { yield { type: _validationIssue.ValidationIssueType.Error, message: `${messagePrefix} must not contain an empty dependency name.`, propertyPath, shortMessage: "must not contain an empty dependency name." }; } if (typeof dependencyVersion !== "string" || !dependencyVersion) { // Should not contain an empty version for a dependency yield { type: _validationIssue.ValidationIssueType.Error, message: `${(0, _formatPropertyPath.formatPropertyPath)(["dependencies", propertyName, dependencyKey])} dependency version must not be empty.`, propertyPath: [...propertyPath, dependencyKey], shortMessage: "dependency version must not be empty." }; } } } } function* validateCoatManifestDependencies(dependenciesProp) { if (typeof dependenciesProp !== "undefined") { if (typeof dependenciesProp !== "object" || Array.isArray(dependenciesProp) || dependenciesProp === null) { yield { type: _validationIssue.ValidationIssueType.Error, message: `${(0, _formatPropertyPath.formatPropertyPath)(["dependencies"])} must be an object.`, propertyPath: ["dependencies"], shortMessage: "must be an object." }; return; } const { dependencies, devDependencies, optionalDependencies, peerDependencies, ...additionalDependenciesProps } = dependenciesProp; yield* validateDependenciesType(dependencies, "dependencies"); yield* validateDependenciesType(devDependencies, "devDependencies"); yield* validateDependenciesType(optionalDependencies, "optionalDependencies"); yield* validateDependenciesType(peerDependencies, "peerDependencies"); const additionalDependenciesPropsKeys = Object.keys(additionalDependenciesProps); yield* (0, _handleUnknownProperties.handleUnknownProperties)({ unknownProps: additionalDependenciesPropsKeys, declaredProps: Object.keys(dependenciesProp), allOptionalProps: ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"], propertyPrefixPath: ["dependencies"] }); } }