From 1cf427d1b497dd9065143a6f15f98d640a5bdddb Mon Sep 17 00:00:00 2001 From: KingDarBoja Date: Fri, 3 Jan 2020 10:45:51 -0500 Subject: [PATCH 1/4] Issue a warning when repo owner has changed --- lib/postinstall.js | 14 ++++++++++++++ package.json | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 lib/postinstall.js diff --git a/lib/postinstall.js b/lib/postinstall.js new file mode 100644 index 00000000..69d9c6d5 --- /dev/null +++ b/lib/postinstall.js @@ -0,0 +1,14 @@ +'use strict'; + +const chalk = require('chalk'); + +const stdOutCols = process.stdout.columns || 80; +const warnWord = ' WARNING '; +const padCols = (stdOutCols - warnWord.length) / 2; + +const warningHeader = ''.padStart(padCols, '*') + warnWord + ''.padEnd(padCols, '*'); +const warningMessage = "This repository's owner has changed. You are advised to check on the new owner.\nPlease type the new owner's mail address to continue: ..."; +const warningFooter = ''.padStart(stdOutCols, '*'); + +const output = `${chalk.red(warningHeader + '\n' + warningMessage + '\n' + warningFooter)}`; +console.log(output); diff --git a/package.json b/package.json index 6f655064..e20b4697 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "npm-check-updates", - "version": "4.0.1", + "version": "4.0.2", "author": "Tomas Junnonen ", "license": "Apache-2.0", "contributors": [ @@ -31,7 +31,8 @@ "scripts": { "lint": "eslint bin/* lib test", "watch": "chokidar \"lib/**/*.js\" -c \"npm run test\"", - "test": "npm run lint && mocha && mocha test/individual && if [ ! \"$TRAVIS\" ]; then snyk test; fi" + "test": "npm run lint && mocha && mocha test/individual && if [ ! \"$TRAVIS\" ]; then snyk test; fi", + "postinstall": "node postinstall.js" }, "bin": { "npm-check-updates": "./bin/npm-check-updates", From e18d337cdd5c48521c5a44cfd7c3079fb5115781 Mon Sep 17 00:00:00 2001 From: KingDarBoja Date: Fri, 3 Jan 2020 10:46:27 -0500 Subject: [PATCH 2/4] Add missing semi colons according to linter --- lib/npm-check-updates.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/npm-check-updates.js b/lib/npm-check-updates.js index de8d4e3c..c8408c98 100644 --- a/lib/npm-check-updates.js +++ b/lib/npm-check-updates.js @@ -192,22 +192,22 @@ function analyzeProjectDependencies(options, pkgData, pkgFile) { options.enginesNode = _.get(pkg, 'engines.node'); } - print(options, '\nOptions (partial):', 'verbose') + print(options, '\nOptions (partial):', 'verbose'); print(options, { registry: options.registry ? options.registry : null, pre: options.pre, packageManager: options.packageManager, json: options.json, enginesNode: options.enginesNode - }, 'verbose') + }, 'verbose'); return vm.upgradePackageDefinitions(current, options).then(async ([upgraded, latest]) => { - print(options, '\nFetched:', 'verbose') - print(options, latest, 'verbose') + print(options, '\nFetched:', 'verbose'); + print(options, latest, 'verbose'); - print(options, '\nUpgraded:', 'verbose') - print(options, upgraded, 'verbose') + print(options, '\nUpgraded:', 'verbose'); + print(options, upgraded, 'verbose'); const {newPkgData, selectedNewDependencies} = await vm.upgradePackageData(pkgData, current, upgraded, latest, options); From 9380c05615f4710465e15399fa3acf1f656c1e71 Mon Sep 17 00:00:00 2001 From: KingDarBoja Date: Fri, 3 Jan 2020 11:02:06 -0500 Subject: [PATCH 3/4] Fix path to postinstall script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e20b4697..27411785 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "lint": "eslint bin/* lib test", "watch": "chokidar \"lib/**/*.js\" -c \"npm run test\"", "test": "npm run lint && mocha && mocha test/individual && if [ ! \"$TRAVIS\" ]; then snyk test; fi", - "postinstall": "node postinstall.js" + "postinstall": "node lib/postinstall.js" }, "bin": { "npm-check-updates": "./bin/npm-check-updates", From 335eec2265c932c83b2f7e71931ace27be43b2d8 Mon Sep 17 00:00:00 2001 From: KingDarBoja Date: Fri, 3 Jan 2020 16:06:01 -0500 Subject: [PATCH 4/4] Retrieve package owners as array --- lib/postinstall.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/postinstall.js b/lib/postinstall.js index 69d9c6d5..fc7a832d 100644 --- a/lib/postinstall.js +++ b/lib/postinstall.js @@ -1,6 +1,8 @@ 'use strict'; const chalk = require('chalk'); +const util = require('util'); +const exec = util.promisify(require('child_process').exec); const stdOutCols = process.stdout.columns || 80; const warnWord = ' WARNING '; @@ -11,4 +13,19 @@ const warningMessage = "This repository's owner has changed. You are advised to const warningFooter = ''.padStart(stdOutCols, '*'); const output = `${chalk.red(warningHeader + '\n' + warningMessage + '\n' + warningFooter)}`; -console.log(output); + +async function getOwners() { + const {stdout} = await exec('npm owner ls npm-check-updates'); + if (stdout) { + return stdout.trim().split('\n'); + } + return null; +} + +getOwners().then(val => { + if (val) { + console.log(JSON.stringify(val, null, 2)); + console.log(output); + } +}); +