477.index.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. exports.id = 477;
  3. exports.ids = [477];
  4. exports.modules = {
  5. /***/ 15477:
  6. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8. const policy = __webpack_require__(70535);
  9. const display_policy_1 = __webpack_require__(85655);
  10. const errors_1 = __webpack_require__(55191);
  11. async function displayPolicy(path) {
  12. try {
  13. const loadedPolicy = (await policy.load(path || process.cwd()));
  14. return await display_policy_1.display(loadedPolicy);
  15. }
  16. catch (error) {
  17. let adaptedError;
  18. if (error.code === 'ENOENT') {
  19. adaptedError = new errors_1.PolicyNotFoundError();
  20. }
  21. else {
  22. adaptedError = new errors_1.FailedToLoadPolicyError();
  23. adaptedError.innerError = error;
  24. }
  25. throw adaptedError;
  26. }
  27. }
  28. exports.default = displayPolicy;
  29. /***/ }),
  30. /***/ 85655:
  31. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  32. Object.defineProperty(exports, "__esModule", ({ value: true }));
  33. exports.display = void 0;
  34. const chalk_1 = __webpack_require__(32589);
  35. const snyk_policy_1 = __webpack_require__(70535);
  36. const config_1 = __webpack_require__(25425);
  37. async function display(policy) {
  38. const p = snyk_policy_1.demunge(policy, config_1.default.PUBLIC_VULN_DB_URL);
  39. const delimiter = '\n\n------------------------\n';
  40. let res = chalk_1.default.bold('Current Snyk policy, read from ' + policy.__filename + ' file') + '\n';
  41. res += 'Modified: ' + policy.__modified + '\n';
  42. res += 'Created: ' + policy.__created + '\n';
  43. res += p.patch.map(displayRule('Patch vulnerability')).join('\n');
  44. if (p.patch.length && p.ignore.length) {
  45. res += delimiter;
  46. }
  47. res += p.ignore.map(displayRule('Ignore')).join('\n');
  48. if (p.ignore.length && p.exclude.length) {
  49. res += delimiter;
  50. }
  51. res += p.exclude.map(displayRule('Exclude')).join('\n');
  52. return Promise.resolve(res);
  53. }
  54. exports.display = display;
  55. function displayRule(title) {
  56. return (rule, i) => {
  57. i += 1;
  58. const formattedTitle = title === 'Exclude'
  59. ? chalk_1.default.bold(`\n#${i} ${title}`) +
  60. ` the following ${chalk_1.default.bold(rule.id)} items/paths:\n`
  61. : chalk_1.default.bold(`\n#${i} ${title} ${rule.url}`) +
  62. ' in the following paths:\n';
  63. return (formattedTitle +
  64. rule.paths
  65. .map((p) => {
  66. return (p.path +
  67. (p.reason
  68. ? '\nReason: ' +
  69. p.reason +
  70. '\nExpires: ' +
  71. p.expires.toUTCString() +
  72. '\n'
  73. : '') +
  74. '\n');
  75. })
  76. .join('')
  77. .replace(/\s*$/, ''));
  78. };
  79. }
  80. /***/ })
  81. };
  82. ;
  83. //# sourceMappingURL=477.index.js.map