From cd24e98f438f5276e7b776c9bec16c83be88f999 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 16 Aug 2024 11:28:17 +0400 Subject: [PATCH] build: change command / fix test --- lib/post-install.js | 3 -- lib/pre-install.js | 1 - lib/reporters/ci-icon.js | 2 - lib/reporters/ci-reporter.js | 4 +- lib/reporters/elegant-status-reporter.js | 6 +-- lib/reporters/env-type.js | 1 - src/utils/npm-audit.js | 26 ++++++------- src/validations/vulnerable-dependencies.js | 19 ++++++---- test/13-integration-tests.js | 6 +-- test/14-npm-integration-tests.js | 37 ++++++------------- test/15-npx-integration-tests.js | 18 +++------ ...16-npx-integration-with-npm-audit-tests.js | 2 +- ...on-with-sensitive-data-validation-tests.js | 2 +- 13 files changed, 50 insertions(+), 77 deletions(-) diff --git a/lib/post-install.js b/lib/post-install.js index 825bdc9c..f93b8d64 100644 --- a/lib/post-install.js +++ b/lib/post-install.js @@ -2,7 +2,6 @@ const fileExists = require('fs').existsSync; const pathJoin = require('path').join; - function isNpxInstall() { try { const getNpmArgs = require('./utils/get-npm-args'); @@ -12,12 +11,10 @@ function isNpxInstall() { return false; } } - (function postInstall(currentDir) { if (isNpxInstall()) { return; } - const jsFile = pathJoin(currentDir || __dirname, 'init.js'); if (fileExists(jsFile)) { const initConfiguration = require(jsFile); diff --git a/lib/pre-install.js b/lib/pre-install.js index e3294530..1b178220 100644 --- a/lib/pre-install.js +++ b/lib/pre-install.js @@ -2,7 +2,6 @@ const fileExists = require('fs').existsSync; const pathJoin = require('path').join; - (function preInstall(currentDir) { const jsFile = pathJoin( currentDir || __dirname, diff --git a/lib/reporters/ci-icon.js b/lib/reporters/ci-icon.js index 19e32a03..e426bea7 100644 --- a/lib/reporters/ci-icon.js +++ b/lib/reporters/ci-icon.js @@ -1,7 +1,6 @@ 'use strict'; const os = require('os'); - module.exports.success = function() { const isTeamcity = require('./env-type').isTeamcity(); const platform = os.platform(); @@ -13,7 +12,6 @@ module.exports.success = function() { } return '✓'; }; - module.exports.error = function() { const isTeamcity = require('./env-type').isTeamcity(); const platform = os.platform(); diff --git a/lib/reporters/ci-reporter.js b/lib/reporters/ci-reporter.js index 496104c5..59325014 100644 --- a/lib/reporters/ci-reporter.js +++ b/lib/reporters/ci-reporter.js @@ -1,4 +1,5 @@ 'use strict'; + /** * Why there is no import of third-party modules at the root of this file? * Required modules may not be available at some point @@ -11,7 +12,6 @@ * CI reporter. * @module reporters/ci-reporter */ - module.exports = { /** * name of the reporter. Must be unique among all reporters. @@ -41,7 +41,6 @@ module.exports = { if (npxArgs && npxArgs['--ci']) { return true; } - const isCI = require('./env-type').isCI(); return isCI; }, @@ -79,7 +78,6 @@ function reportRunningTask(taskname) { ? console.log(`${icon.success()} ${taskname}`) : console.log(`${icon.error()} ${taskname}`); } - return done; } diff --git a/lib/reporters/elegant-status-reporter.js b/lib/reporters/elegant-status-reporter.js index d1b9b078..5df6042c 100644 --- a/lib/reporters/elegant-status-reporter.js +++ b/lib/reporters/elegant-status-reporter.js @@ -1,4 +1,5 @@ 'use strict'; + /** * Why there is no import of third-party modules at the root of this file? * Required modules may not be available at some point @@ -11,7 +12,6 @@ * elegant status reporter. * @module reporters/elegant-status-reporter */ - module.exports = { /** * name of the reporter. Must be unique among all reporters. @@ -171,7 +171,7 @@ function formatAsElegantPath(path, sep) { // prettier-ignore const result = packages.map(item => item.trim()).map((item, index) => { - return index === lastIndex ? chalk.red.bold(item) : item; - }).join(' -> '); + return index === lastIndex ? chalk.red.bold(item) : item; + }).join(' -> '); return result; } diff --git a/lib/reporters/env-type.js b/lib/reporters/env-type.js index 5cbe27b1..260dfa6e 100644 --- a/lib/reporters/env-type.js +++ b/lib/reporters/env-type.js @@ -3,7 +3,6 @@ module.exports.isCI = function() { return require('is-ci') === true; }; - module.exports.isTeamcity = function() { return 'TEAMCITY_VERSION' in process.env; }; diff --git a/src/utils/npm-audit.js b/src/utils/npm-audit.js index ec7a094c..f67a063b 100644 --- a/src/utils/npm-audit.js +++ b/src/utils/npm-audit.js @@ -196,20 +196,20 @@ function removeIgnoredVulnerabilities(response, options) { function filterIgnoredVulnerabilities(vulnerabilities, ignoredVulnerabilities) { const isIgnoredVulnerability = ({ url }) => { - return !ignoredVulnerabilities - .some(ignoredVulnerability => { - return url ? url.indexOf(ignoredVulnerability) > 0 : false; - }); - } + return !ignoredVulnerabilities.some((ignoredVulnerability) => { + return url ? url.indexOf(ignoredVulnerability) > 0 : false; + }); + }; return Object.keys(vulnerabilities) .map((vulnerability) => { - vulnerabilities[vulnerability].via = vulnerabilities[vulnerability].via - .filter(isIgnoredVulnerability); + vulnerabilities[vulnerability].via = vulnerabilities[ + vulnerability + ].via.filter(isIgnoredVulnerability); return vulnerabilities[vulnerability]; }) - .filter(vulnerability => vulnerability.via.length === 0); + .filter((vulnerability) => vulnerability.via.length === 0); } /** @@ -463,11 +463,11 @@ function removeIgnoredLevels(response, options) { } function filterIgnoredLevels(vulnerabilities, filteredLevels) { - return Object.keys(vulnerabilities).filter( - (vulnerability) => { - return filteredLevels.indexOf(vulnerabilities[vulnerability].severity) < 0; - } - ); + return Object.keys(vulnerabilities).filter((vulnerability) => { + return ( + filteredLevels.indexOf(vulnerabilities[vulnerability].severity) < 0 + ); + }); } /** diff --git a/src/validations/vulnerable-dependencies.js b/src/validations/vulnerable-dependencies.js index 423663d9..c2bfa698 100644 --- a/src/validations/vulnerable-dependencies.js +++ b/src/validations/vulnerable-dependencies.js @@ -39,12 +39,15 @@ module.exports = { Object.keys(result.vulnerabilities).forEach( (vulnerability) => { - result.vulnerabilities[vulnerability].nodes - .forEach((path) => { - const formattedPath = summaryOf(path.replace(/^node_modules\//g, '')); + result.vulnerabilities[ + vulnerability + ].nodes.forEach((path) => { + const formattedPath = summaryOf( + path.replace(/^node_modules\//g, '') + ); - errs.add(formattedPath); - }); + errs.add(formattedPath); + }); } ); const distinctAndSortedErrors = Array.from( @@ -71,9 +74,11 @@ module.exports = { }; function vulnerabilitiesFoundIn(result) { - return result && + return ( + result && result.vulnerabilities && - Object.keys(result.vulnerabilities).length > 0; + Object.keys(result.vulnerabilities).length > 0 + ); } function auditErrorFoundIn(result) { diff --git a/test/13-integration-tests.js b/test/13-integration-tests.js index f33f586f..ffc46d67 100644 --- a/test/13-integration-tests.js +++ b/test/13-integration-tests.js @@ -695,9 +695,7 @@ describe('Integration tests', () => { ? assert(err.message.indexOf('Vulnerability found') > -1) : assert(err.message.indexOf('Cannot check vulnerable dependencies') > -1) )); - ['lodash@4.16.4', 'testcafe@0.19.2'].forEach(function( - dependency - ) { + ['lodash@4.16.4', 'testcafe@0.19.2'].forEach(function(dependency) { const name = dependency.split('@')[0]; const version = dependency.split('@')[1]; it(`Should fail on transitive dependency inside ${dependency}`, () => @@ -1182,7 +1180,7 @@ describe('Integration tests', () => { err.message.indexOf('operation not permitted') > -1 || err.message.indexOf('You must be logged in to publish packages') > -1 || //https://github.com/npm/cli/issues/1637 - err.message.indexOf('npm ERR! 404 Not Found - PUT https://registry.npmjs.org/testing-repo - Not found') > -1 || + err.message.indexOf('404 Not Found - PUT https://registry.npmjs.org/testing-repo - Not found') > -1 || err.message.indexOf('You may not perform that action with these credentials') > -1 || err.message.indexOf('This command requires you to be logged in to https://registry.npmjs.org/') > -1 ); diff --git a/test/14-npm-integration-tests.js b/test/14-npm-integration-tests.js index 2bfc2415..1c119309 100644 --- a/test/14-npm-integration-tests.js +++ b/test/14-npm-integration-tests.js @@ -12,7 +12,7 @@ const packageName = require('./utils/publish-please-version-under-test'); const nodeInfos = require('../lib/utils/get-node-infos').getNodeInfosSync(); const shouldUsePrePublishOnlyScript = nodeInfos.shouldUsePrePublishOnlyScript; const lineSeparator = '----------------------------------'; -const packagePath = `../${packageName.replace('@','-')}.tgz`; +const packagePath = `../${packageName.replace('@', '-')}.tgz`; const writePublishFile = () => { writeFile( @@ -112,13 +112,9 @@ describe('npm integration tests', () => { it('Should not install globally', () => { return Promise.resolve() + .then(() => console.log(`> npm install -g ${packageName}`)) .then(() => - console.log(`> npm install -g ${packageName}`) - ) - .then(() => - exec( - `npm install -g --foreground-scripts ${packagePath}` - ) + exec(`npm install -g --foreground-scripts ${packagePath}`) ) .then(() => { throw new Error('Promise rejection expected'); @@ -130,11 +126,10 @@ describe('npm integration tests', () => { it.skip('Should install locally', () => { return Promise.resolve() + .then(() => console.log(`> npm install --save-dev ${packageName}`)) .then(() => - console.log(`> npm install --save-dev ${packageName}`) - ) - .then(() => - exec(`npm install --foreground-scripts --save-dev ${packagePath}` + exec( + `npm install --foreground-scripts --save-dev ${packagePath}` ) ) .then(() => { @@ -248,11 +243,7 @@ describe('npm integration tests', () => { console.log(readFile('.auditignore').toString()); console.log(''); }) - .then(() => - console.log( - `> npm install --save-dev ${packageName}` - ) - ) + .then(() => console.log(`> npm install --save-dev ${packageName}`)) .then(() => exec( /* prettier-ignore */ @@ -317,11 +308,7 @@ describe('npm integration tests', () => { console.log(readFile('.auditignore').toString()); console.log(''); }) - .then(() => - console.log( - `> npm install --save-dev ${packageName}` - ) - ) + .then(() => console.log(`> npm install --save-dev ${packageName}`)) .then(() => exec( /* prettier-ignore */ @@ -376,9 +363,7 @@ describe('npm integration tests', () => { it('Should abort the publishing workflow when npm version < 6.1.0 and vulnerability check is enabled in .publishrc config file', () => { return Promise.resolve() .then(() => - console.log( - `> npm install --save-dev ${packageName}` - ) + console.log(`> npm install --save-dev ${packageName}`) ) .then(() => exec( @@ -433,7 +418,9 @@ describe('npm integration tests', () => { it('Should abort the dry-mode workflow when npm version < 6.1.0 and vulnerability check is enabled in .publishrc config file', () => { return Promise.resolve() - .then(() => console.log(`> npm install --save-dev ${packageName}`)) + .then(() => + console.log(`> npm install --save-dev ${packageName}`) + ) .then(() => exec( /* prettier-ignore */ diff --git a/test/15-npx-integration-tests.js b/test/15-npx-integration-tests.js index 1c235afb..aef0f2db 100644 --- a/test/15-npx-integration-tests.js +++ b/test/15-npx-integration-tests.js @@ -10,7 +10,7 @@ const exec = require('cp-sugar').exec; const packageName = require('./utils/publish-please-version-under-test'); const nodeInfos = require('../lib/utils/get-node-infos').getNodeInfosSync(); const lineSeparator = '----------------------------------'; -const packagePath = `../${packageName.replace('@','-')}.tgz`; +const packagePath = `../${packageName.replace('@', '-')}.tgz`; /* eslint-disable max-nested-callbacks */ describe('npx integration tests', () => { @@ -91,9 +91,7 @@ describe('npx integration tests', () => { pkg.scripts = scripts; writeFile('package.json', JSON.stringify(pkg, null, 2)); }) - .then(() => - console.log(`> npx ${packageName} --dry-run`) - ) + .then(() => console.log(`> npx ${packageName} --dry-run`)) .then(() => exec( /* prettier-ignore */ @@ -153,9 +151,7 @@ describe('npx integration tests', () => { }) ); }) - .then(() => - console.log(`> npx ${packageName} --dry-run`) - ) + .then(() => console.log(`> npx ${packageName} --dry-run`)) .then(() => exec( /* prettier-ignore */ @@ -213,9 +209,7 @@ describe('npx integration tests', () => { }) ); }) - .then(() => - console.log(`> npx ${packageName} --dry-run --ci`) - ) + .then(() => console.log(`> npx ${packageName} --dry-run --ci`)) .then(() => exec( /* prettier-ignore */ @@ -469,9 +463,7 @@ describe('npx integration tests', () => { }) ); }) - .then(() => - console.log(`> npx ${packageName} --dry-run`) - ) + .then(() => console.log(`> npx ${packageName} --dry-run`)) .then(() => exec( /* prettier-ignore */ diff --git a/test/16-npx-integration-with-npm-audit-tests.js b/test/16-npx-integration-with-npm-audit-tests.js index 8257d707..3f519812 100644 --- a/test/16-npx-integration-with-npm-audit-tests.js +++ b/test/16-npx-integration-with-npm-audit-tests.js @@ -11,7 +11,7 @@ const packageName = require('./utils/publish-please-version-under-test'); const nodeInfos = require('../lib/utils/get-node-infos').getNodeInfosSync(); const EOL = require('os').EOL; const lineSeparator = '----------------------------------'; -const packagePath = `../${packageName.replace('@','-')}.tgz`; +const packagePath = `../${packageName.replace('@', '-')}.tgz`; /* eslint-disable max-nested-callbacks */ describe('npx integration tests with npm audit', () => { diff --git a/test/17-npx-integration-with-sensitive-data-validation-tests.js b/test/17-npx-integration-with-sensitive-data-validation-tests.js index 0ab5aa46..04c250fb 100644 --- a/test/17-npx-integration-with-sensitive-data-validation-tests.js +++ b/test/17-npx-integration-with-sensitive-data-validation-tests.js @@ -14,7 +14,7 @@ const EOL = require('os').EOL; const pathJoin = require('path').join; const touch = require('./utils/touch-file-sync'); const lineSeparator = '----------------------------------'; -const packagePath = `../${packageName.replace('@','-')}.tgz`; +const packagePath = `../${packageName.replace('@', '-')}.tgz`; /* eslint-disable max-nested-callbacks */ describe('npx integration tests with sensitive-data validation', () => {