UNPKG

@backstage/cli

Version:

CLI for developing Backstage plugins and apps

116 lines (110 loc) 3.85 kB
'use strict'; var Lockfile = require('./Lockfile-eced6070.cjs.js'); require('minimatch'); require('@manypkg/get-packages'); require('chalk'); require('./yarn-6cd89e16.cjs.js'); require('./run-a0658306.cjs.js'); var index = require('./index-ce56dce5.cjs.js'); var partition = require('lodash/partition'); var cliNode = require('@backstage/cli-node'); require('fs-extra'); require('semver'); require('@yarnpkg/parsers'); require('@yarnpkg/lockfile'); require('@backstage/errors'); require('child_process'); require('util'); require('commander'); require('@backstage/cli-common'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var partition__default = /*#__PURE__*/_interopDefaultLegacy(partition); const INCLUDED = [/^@backstage\//]; const includedFilter = (name) => INCLUDED.some((pattern) => pattern.test(name)); const FORBID_DUPLICATES = [ /^@backstage\/core-app-api$/, /^@backstage\/plugin-/ ]; const ALLOW_DUPLICATES = [ /^@backstage\/core-plugin-api$/, // Duplicates of libraries are OK // TODO(Rugvip): Check this using package role instead /^@backstage\/plugin-.*-react$/, /^@backstage\/plugin-.*-node$/, /^@backstage\/plugin-.*-common$/ ]; const forbiddenDuplicatesFilter = (name) => FORBID_DUPLICATES.some((pattern) => pattern.test(name)) && !ALLOW_DUPLICATES.some((pattern) => pattern.test(name)); var lint = async (cmd) => { const fix = Boolean(cmd.fix); let success = true; const lockfilePath = index.paths.resolveTargetRoot("yarn.lock"); const lockfile = await Lockfile.Lockfile.load(lockfilePath); const result = lockfile.analyze({ filter: includedFilter, localPackages: cliNode.PackageGraph.fromPackages( await cliNode.PackageGraph.listTargetPackages() ) }); logArray( result.invalidRanges, "The following packages versions are invalid and can't be analyzed:", (e) => ` ${e.name} @ ${e.range}` ); if (fix) { lockfile.replaceVersions(result.newVersions); await lockfile.save(lockfilePath); } else { const [newVersionsForbidden, newVersionsAllowed] = partition__default["default"]( result.newVersions, ({ name }) => forbiddenDuplicatesFilter(name) ); if (newVersionsForbidden.length && !fix) { success = false; } logArray( newVersionsForbidden, "The following packages must be deduplicated, this can be done automatically with --fix", (e) => ` ${e.name} @ ${e.range} bumped from ${e.oldVersion} to ${e.newVersion}` ); logArray( newVersionsAllowed, "The following packages can be deduplicated, this can be done automatically with --fix", (e) => ` ${e.name} @ ${e.range} bumped from ${e.oldVersion} to ${e.newVersion}` ); } const [newRangesForbidden, newRangesAllowed] = partition__default["default"]( result.newRanges, ({ name }) => forbiddenDuplicatesFilter(name) ); if (newRangesForbidden.length) { success = false; } logArray( newRangesForbidden, "The following packages must be deduplicated by updating dependencies in package.json", (e) => ` ${e.name} @ ${e.oldRange} should be changed to ${e.newRange}` ); logArray( newRangesAllowed, "The following packages can be deduplicated by updating dependencies in package.json", (e) => ` ${e.name} @ ${e.oldRange} should be changed to ${e.newRange}` ); if (!success) { throw new Error("Failed versioning check"); } }; function logArray(arr, header, each) { if (arr.length === 0) { return; } console.log(header); console.log(); for (const e of arr) { console.log(each(e)); } console.log(); } exports["default"] = lint; exports.forbiddenDuplicatesFilter = forbiddenDuplicatesFilter; exports.includedFilter = includedFilter; //# sourceMappingURL=lint-ff1e8d45.cjs.js.map