@leverege/build-tools 1.8.4 → 1.10.0

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,158 +0,0 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es7.symbol.async-iterator");
4
-
5
- require("core-js/modules/es6.symbol");
6
-
7
- require("core-js/modules/es6.regexp.split");
8
-
9
- require("core-js/modules/web.dom.iterable");
10
-
11
- require("core-js/modules/es6.array.iterator");
12
-
13
- require("core-js/modules/es6.object.to-string");
14
-
15
- require("core-js/modules/es6.object.keys");
16
-
17
- require("core-js/modules/es6.array.find");
18
-
19
- require("core-js/modules/es6.object.assign");
20
-
21
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
22
-
23
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
-
25
- var groupBy = require('lodash.groupby');
26
-
27
- var keyBy = require('lodash.keyby');
28
-
29
- var countBy = require('lodash.countby');
30
-
31
- var orderBy = require('lodash.orderby');
32
-
33
- var map = require('lodash.map');
34
-
35
- var first = require('lodash.first');
36
-
37
- module.exports = function () {
38
- var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
39
-
40
- function affectsProd(resolves) {
41
- return !(config['prod-only'] && resolves.every(function (_ref) {
42
- var dev = _ref.dev;
43
- return dev;
44
- }));
45
- }
46
-
47
- function requireAttention(auditResult) {
48
- var actions = auditResult.actions,
49
- advisories = auditResult.advisories;
50
- var reviewActions = actions.filter(function (_ref2) {
51
- var action = _ref2.action,
52
- resolves = _ref2.resolves,
53
- isMajor = _ref2.isMajor;
54
- return (action === 'review' || isMajor) && affectsProd(resolves);
55
- });
56
- var reviewAdvisories = reviewActions.reduce(function (acc, _ref3) {
57
- var resolves = _ref3.resolves;
58
- var advisoriesToInclude = resolves.reduce(function (result, _ref4) {
59
- var id = _ref4.id;
60
- return Object.assign({}, result, _defineProperty({}, id, advisories[id]));
61
- }, {});
62
- return Object.assign({}, acc, advisoriesToInclude);
63
- }, {});
64
- return Object.assign({}, auditResult, {
65
- actions: reviewActions,
66
- advisories: reviewAdvisories
67
- });
68
- }
69
-
70
- function getHighestSeverity(_ref5) {
71
- var advisories = _ref5.advisories;
72
-
73
- var _loop = function _loop() {
74
- var severity = _arr[_i];
75
-
76
- if (Object.keys(advisories).find(function (key) {
77
- return advisories[key].severity === severity;
78
- })) {
79
- return {
80
- v: severity
81
- };
82
- }
83
- };
84
-
85
- for (var _i = 0, _arr = ['critical', 'high', 'moderate', 'low']; _i < _arr.length; _i++) {
86
- var _ret = _loop();
87
-
88
- if (_typeof(_ret) === "object") return _ret.v;
89
- }
90
- }
91
-
92
- function filterAuditResultsBySeverity(auditResult, highestSeverity) {
93
- var actions = auditResult.actions,
94
- advisories = auditResult.advisories;
95
- var groupedAdvisories = groupBy(advisories, 'severity');
96
- var advisoriesForSeverity = keyBy(groupedAdvisories[highestSeverity], 'id');
97
- var actionsForSeverity = actions.reduce(function (acc, action) {
98
- var resolvesSevereAdvisory = action.resolves.some(function (_ref6) {
99
- var id = _ref6.id;
100
- return advisoriesForSeverity[id];
101
- });
102
- return resolvesSevereAdvisory ? [].concat(acc, action) : acc;
103
- }, []);
104
- return Object.assign({}, auditResult, {
105
- actions: actionsForSeverity,
106
- advisories: advisories
107
- });
108
- }
109
-
110
- function getAutoFixCount(auditResult) {
111
- return auditResult.actions.filter(function (_ref7) {
112
- var action = _ref7.action,
113
- resolves = _ref7.resolves,
114
- isMajor = _ref7.isMajor;
115
- return action !== 'review' && !isMajor && affectsProd(resolves);
116
- }).length;
117
- }
118
-
119
- function findRootLibs(resolves) {
120
- return resolves.reduce(function (acc, resolve) {
121
- return [].concat(acc, resolve.path.split('>')[0]);
122
- }, []);
123
- }
124
-
125
- function getMostProblematicDependency(_ref8) {
126
- var actions = _ref8.actions;
127
- var rootLibraries = actions.reduce(function (libs, _ref9) {
128
- var resolves = _ref9.resolves;
129
- return [].concat(libs, findRootLibs(resolves));
130
- }, []);
131
- return first(orderBy(map(countBy(rootLibraries), function (count, lib) {
132
- return {
133
- count: count,
134
- name: lib
135
- };
136
- }), function (_ref10) {
137
- var count = _ref10.count;
138
- return count;
139
- }, ['desc']));
140
- }
141
-
142
- return function help(npmAuditResultJson) {
143
- var npmAuditResult = JSON.parse(npmAuditResultJson);
144
- var resultsThatRequireAttention = requireAttention(npmAuditResult);
145
- var highestSeverity = getHighestSeverity(resultsThatRequireAttention);
146
- var auditResult = filterAuditResultsBySeverity(resultsThatRequireAttention, highestSeverity);
147
- var autoFixCount = getAutoFixCount(npmAuditResult);
148
- var exitCode = config['exit-zero'] || !auditResult.actions.length && !autoFixCount ? 0 : 1;
149
- return {
150
- npmAuditResult: npmAuditResult,
151
- auditResult: auditResult,
152
- autoFixCount: autoFixCount,
153
- mostProblematicDependency: getMostProblematicDependency(resultsThatRequireAttention),
154
- highestSeverity: highestSeverity,
155
- exitCode: exitCode
156
- };
157
- };
158
- };
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- require("core-js/modules/es6.object.assign");
5
-
6
- var getStdin = require('get-stdin');
7
-
8
- var options = require('minimist')(process.argv.slice(2));
9
-
10
- var help = require('./help');
11
-
12
- var report = require('./report');
13
-
14
- var defaults = {
15
- 'exit-zero': false,
16
- 'prod-only': false
17
- };
18
- var config = Object.assign({}, defaults, options);
19
- getStdin().then(help(config)).then(function (result) {
20
- return report(result).then(function (theReport) {
21
- console.log(theReport);
22
- process.exit(result.exitCode);
23
- });
24
- }).catch(function (error) {
25
- console.error(error);
26
- process.exit(1);
27
- });
@@ -1,91 +0,0 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es6.promise");
4
-
5
- require("regenerator-runtime/runtime");
6
-
7
- require("core-js/modules/web.dom.iterable");
8
-
9
- require("core-js/modules/es6.array.iterator");
10
-
11
- require("core-js/modules/es6.object.to-string");
12
-
13
- require("core-js/modules/es6.object.keys");
14
-
15
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
16
-
17
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
18
-
19
- var auditReport = require('npm-audit-report');
20
-
21
- var chalk = require('chalk');
22
-
23
- function automaticFixes(autoFixCount) {
24
- return autoFixCount ? "run ".concat(chalk.yellow('`npm audit fix`'), " to automatically fix ").concat(chalk.yellow(autoFixCount), " issues. These should all be non-breaking upgrades, so don't stress.") : '';
25
- }
26
-
27
- function fixesToReview(_ref, highestSeverity) {
28
- var actions = _ref.actions,
29
- advisories = _ref.advisories;
30
- var advisoryIds = Object.keys(advisories);
31
-
32
- if (!actions.length || !advisoryIds.length) {
33
- return '';
34
- }
35
-
36
- return "Resolve the ".concat(chalk.green(actions.length), " ").concat(chalk.green(highestSeverity), " severity issues above and run this command again to move to the next severity.");
37
- }
38
-
39
- function mostProblematic(mostProblematicDependency) {
40
- if (!mostProblematicDependency) {
41
- return '';
42
- }
43
-
44
- var name = mostProblematicDependency.name,
45
- count = mostProblematicDependency.count;
46
- return count && count > 2 ? "The most problematic dependency seems to be ".concat(chalk.blue(name), " with ").concat(chalk.blue(count), " issue").concat(count ? 's' : '', " that need your attention.") : '';
47
- }
48
-
49
- module.exports =
50
- /*#__PURE__*/
51
- function () {
52
- var _printFullReport = _asyncToGenerator(
53
- /*#__PURE__*/
54
- regeneratorRuntime.mark(function _callee(_ref2) {
55
- var npmAuditResult, auditResult, autoFixCount, mostProblematicDependency, highestSeverity, _ref3, report, hints, help;
56
-
57
- return regeneratorRuntime.wrap(function _callee$(_context) {
58
- while (1) {
59
- switch (_context.prev = _context.next) {
60
- case 0:
61
- npmAuditResult = _ref2.npmAuditResult, auditResult = _ref2.auditResult, autoFixCount = _ref2.autoFixCount, mostProblematicDependency = _ref2.mostProblematicDependency, highestSeverity = _ref2.highestSeverity;
62
- _context.next = 3;
63
- return auditReport(npmAuditResult, {
64
- reporter: 'install',
65
- withColor: true,
66
- withUnicode: true
67
- });
68
-
69
- case 3:
70
- _ref3 = _context.sent;
71
- report = _ref3.report;
72
- hints = [].concat(automaticFixes(autoFixCount)).concat(fixesToReview(auditResult, highestSeverity)).concat(mostProblematic(mostProblematicDependency)).filter(Boolean);
73
- help = hints.length ? "\n\n".concat(chalk.green('=== A little bit of help ==='), "\n\nWhere to start:\n").concat(hints.reduce(function (acc, hint) {
74
- return "".concat(acc, "\n- ").concat(hint, "\n");
75
- }, ''), "\n") : '';
76
- return _context.abrupt("return", "".concat(report).concat(help));
77
-
78
- case 8:
79
- case "end":
80
- return _context.stop();
81
- }
82
- }
83
- }, _callee);
84
- }));
85
-
86
- function printFullReport(_x) {
87
- return _printFullReport.apply(this, arguments);
88
- }
89
-
90
- return printFullReport;
91
- }();
@@ -1,83 +0,0 @@
1
- const groupBy = require( 'lodash.groupby' )
2
- const keyBy = require( 'lodash.keyby' )
3
- const countBy = require( 'lodash.countby' )
4
- const orderBy = require( 'lodash.orderby' )
5
- const map = require( 'lodash.map' )
6
- const first = require( 'lodash.first' )
7
-
8
- module.exports = ( config = {} ) => {
9
- function affectsProd( resolves ) {
10
- return !( config['prod-only'] && resolves.every( ( { dev } ) => dev ) );
11
- }
12
-
13
- function requireAttention( auditResult ) {
14
- const { actions, advisories } = auditResult;
15
- const reviewActions = actions.filter( ( { action, resolves, isMajor } ) => ( action === 'review' || isMajor ) && affectsProd( resolves ) );
16
- const reviewAdvisories = reviewActions.reduce( ( acc, { resolves } ) => {
17
- const advisoriesToInclude = resolves.reduce( ( result, { id } ) => Object.assign( {}, result, { [id] : advisories[id] } ), {} );
18
- return Object.assign( {}, acc, advisoriesToInclude );
19
- }, {} );
20
- return Object.assign( {}, auditResult, { actions : reviewActions, advisories : reviewAdvisories } );
21
- }
22
-
23
- function getHighestSeverity( { advisories } ) {
24
- for ( const severity of [ 'critical', 'high', 'moderate', 'low' ] ) {
25
- if ( Object.keys( advisories ).find( key => advisories[key].severity === severity ) ) {
26
- return severity;
27
- }
28
- }
29
- }
30
-
31
- function filterAuditResultsBySeverity( auditResult, highestSeverity ) {
32
- const { actions, advisories } = auditResult;
33
- const groupedAdvisories = groupBy( advisories, 'severity' );
34
- const advisoriesForSeverity = keyBy( groupedAdvisories[highestSeverity], 'id' );
35
- const actionsForSeverity = actions.reduce( ( acc, action ) => {
36
- const resolvesSevereAdvisory = action.resolves.some( ( { id } ) => advisoriesForSeverity[id] );
37
- return resolvesSevereAdvisory ? [].concat( acc, action ) : acc;
38
- }, [] );
39
- return Object.assign( {}, auditResult, { actions : actionsForSeverity, advisories } );
40
- }
41
-
42
- function getAutoFixCount( auditResult ) {
43
- return auditResult.actions.filter( ( { action, resolves, isMajor } ) => action !== 'review' &&
44
- !isMajor &&
45
- affectsProd( resolves ) ).length;
46
- }
47
-
48
- function findRootLibs( resolves ) {
49
- return resolves.reduce( ( acc, resolve ) => [].concat( acc, resolve.path.split( '>' )[0] ), [] );
50
- }
51
-
52
- function getMostProblematicDependency( { actions } ) {
53
- const rootLibraries = actions.reduce( ( libs, { resolves } ) => [].concat( libs, findRootLibs( resolves ) ), [] );
54
-
55
- return first(
56
- orderBy(
57
- map(
58
- countBy( rootLibraries ),
59
- ( count, lib ) => ( { count, name : lib } )
60
- ),
61
- ( { count } ) => count, [ 'desc' ]
62
- )
63
- )
64
- }
65
-
66
- return function help( npmAuditResultJson ) {
67
-
68
- const npmAuditResult = JSON.parse( npmAuditResultJson );
69
- const resultsThatRequireAttention = requireAttention( npmAuditResult );
70
- const highestSeverity = getHighestSeverity( resultsThatRequireAttention );
71
- const auditResult = filterAuditResultsBySeverity( resultsThatRequireAttention, highestSeverity );
72
- const autoFixCount = getAutoFixCount( npmAuditResult );
73
- const exitCode = config['exit-zero'] || ( !auditResult.actions.length && !autoFixCount ) ? 0 : 1;
74
- return {
75
- npmAuditResult,
76
- auditResult,
77
- autoFixCount,
78
- mostProblematicDependency : getMostProblematicDependency( resultsThatRequireAttention ),
79
- highestSeverity,
80
- exitCode,
81
- };
82
- };
83
- };
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const getStdin = require( 'get-stdin' );
4
- const options = require( 'minimist' )( process.argv.slice( 2 ) );
5
- const help = require( './help' );
6
- const report = require( './report' );
7
-
8
- const defaults = {
9
- 'exit-zero' : false,
10
- 'prod-only' : false,
11
- };
12
-
13
- const config = Object.assign( {}, defaults, options );
14
-
15
- getStdin()
16
- .then( help( config ) )
17
- .then( result => report( result )
18
- .then( ( theReport ) => {
19
- console.log( theReport );
20
- process.exit( result.exitCode );
21
- } ) )
22
- .catch( ( error ) => {
23
- console.error( error );
24
- process.exit( 1 );
25
- } );
@@ -1,54 +0,0 @@
1
- const auditReport = require( 'npm-audit-report' );
2
- const chalk = require( 'chalk' );
3
-
4
- function automaticFixes( autoFixCount ) {
5
- return autoFixCount ?
6
- `run ${chalk.yellow( '`npm audit fix`' )} to automatically fix ${chalk.yellow( autoFixCount )} issues. These should all be non-breaking upgrades, so don't stress.` :
7
- '';
8
- }
9
-
10
- function fixesToReview( { actions, advisories }, highestSeverity ) {
11
- const advisoryIds = Object.keys( advisories );
12
- if ( !actions.length || !advisoryIds.length ) {
13
- return '';
14
- }
15
- return `Resolve the ${chalk.green( actions.length )} ${chalk.green( highestSeverity )} severity issues above and run this command again to move to the next severity.`;
16
- }
17
-
18
- function mostProblematic( mostProblematicDependency ) {
19
- if ( !mostProblematicDependency ) {
20
- return '';
21
- }
22
- const { name, count } = mostProblematicDependency;
23
- return count && count > 2 ?
24
- `The most problematic dependency seems to be ${chalk.blue( name )} with ${chalk.blue( count )} issue${count ? 's' : ''} that need your attention.` :
25
- '';
26
- }
27
-
28
- module.exports = async function printFullReport( { npmAuditResult, auditResult, autoFixCount, mostProblematicDependency, highestSeverity } ) {
29
- const { report } = await auditReport( npmAuditResult, {
30
- reporter : 'install',
31
- withColor : true,
32
- withUnicode : true,
33
- } );
34
-
35
- const hints = []
36
- .concat( automaticFixes( autoFixCount ) )
37
- .concat( fixesToReview( auditResult, highestSeverity ) )
38
- .concat( mostProblematic( mostProblematicDependency ) )
39
- .filter( Boolean );
40
-
41
- const help = hints.length ?
42
- `
43
-
44
- ${chalk.green( '=== A little bit of help ===' )}
45
-
46
- Where to start:
47
- ${hints.reduce( ( acc, hint ) => `${acc}
48
- - ${hint}
49
- `, '' )}
50
- ` :
51
- '';
52
-
53
- return `${report}${help}`;
54
- };