-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Breaking] bump to npm 10 and node 18; getDeprecationMessages now out…
…puts a single object instead of an array of them
- Loading branch information
Showing
11 changed files
with
156 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,11 @@ | ||
{ | ||
"root": true, | ||
|
||
"extends": "@ljharb", | ||
"extends": "@ljharb/eslint-config/node/18", | ||
|
||
"rules": { | ||
"id-length": [2, { "min": 1, "max": 30 }], | ||
"max-nested-callbacks": [2, 3], | ||
"max-statements-per-line": [2, { "max": 2 }], | ||
"no-unused-vars": [1] | ||
"no-unused-vars": 1, | ||
"prefer-rest-params": 0, | ||
}, | ||
|
||
"overrides": [ | ||
{ | ||
"files": "test/**", | ||
"rules": { | ||
"max-lines-per-function": 0, | ||
}, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,28 @@ | ||
'use strict'; | ||
|
||
var toStr = Object.prototype.toString; | ||
var slice = Array.prototype.slice; | ||
var isString = function (str) { return toStr.call(str) === '[object String]'; }; | ||
var isFunction = function (func) { return toStr.call(func) === '[object Function]'; }; | ||
const every = require('array.prototype.every'); | ||
const fromEntries = require('object.fromentries'); | ||
|
||
var promiseback = require('promiseback'); | ||
var Promise = require('./promise'); | ||
var assign = require('object.assign'); | ||
const isString = (str) => typeof str === 'string'; | ||
|
||
var getVersions = require('./versions'); | ||
var getDeprecationMessages = require('./messages'); | ||
const getVersions = require('./versions'); | ||
const getDeprecationMessages = require('./messages'); | ||
|
||
module.exports = function deprecations(packageName) { | ||
var callback; | ||
module.exports = function deprecations(packageName, ...morePackageNames) { | ||
if (arguments.length < 1) { | ||
throw new TypeError('at least 1 package name is required'); | ||
} else if (arguments.length > 1 && isFunction(arguments[arguments.length - 1])) { | ||
callback = arguments[arguments.length - 1]; | ||
} | ||
|
||
var modules = slice.call(arguments, 0, callback ? -1 : callback); | ||
if (!modules.every(isString)) { | ||
if (!every(arguments, isString)) { | ||
throw new TypeError('module names must all be strings'); | ||
} | ||
|
||
var deferred = promiseback(callback); | ||
process.nextTick(function () { | ||
var promises = modules.map(function (name) { | ||
return getVersions(name).then(function (versions) { | ||
return getDeprecationMessages(name, versions); | ||
}).then(function (data) { | ||
var moduleData = {}; | ||
moduleData[name] = assign.apply(null, [{}].concat(data)); | ||
return moduleData; | ||
}); | ||
}); | ||
Promise.all(promises).then(function (moduleDatas) { | ||
var modulesData = moduleDatas.reduce(function (acc, moduleData) { | ||
return assign(acc, moduleData); | ||
}, {}); | ||
deferred.resolve(modulesData); | ||
}, deferred.reject); | ||
}); | ||
return deferred.promise; | ||
return Promise.all(Array.from(arguments, async (name) => { | ||
const versions = await getVersions(name); | ||
return [ | ||
name, | ||
await getDeprecationMessages(name, versions), | ||
]; | ||
})).then(fromEntries); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,27 @@ | ||
'use strict'; | ||
|
||
var Promise = require('./promise'); | ||
var exec = require('child_process').exec; | ||
const { exec } = require('child_process'); | ||
const fromEntries = require('object.fromentries'); | ||
|
||
module.exports = function getDeprecationMessages(name, versions) { | ||
var promises = versions.map(function (version) { | ||
return new Promise(function (resolve, reject) { | ||
exec('npm info ' + name + '@' + version + ' deprecated --json --no-spin --silent', function (err, jsonMsg) { | ||
if (err) { return reject(err); } | ||
var message = String(jsonMsg).trim(); | ||
module.exports = async function getDeprecationMessages(name, versions) { | ||
return fromEntries(await Promise.all(versions.map(async (version) => { | ||
const jsonMsg = await new Promise((resolve, reject) => { | ||
exec(`npm info ${name}@${version} deprecated --json --no-spin --silent`, (err, data) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
const message = String(data).trim(); | ||
return message ? resolve(message) : resolve(); | ||
}); | ||
}).then(function (jsonMsg) { | ||
if (typeof jsonMsg !== 'undefined' && jsonMsg !== 'undefined') { | ||
return JSON.parse(jsonMsg); | ||
} | ||
return null; | ||
}).then(function (fullMsg) { | ||
var msg = fullMsg ? String(fullMsg).trim() : ''; | ||
var finalMessage; | ||
if (msg && msg.length > 0) { | ||
finalMessage = msg; | ||
} | ||
var finalData = {}; | ||
finalData[version] = finalMessage; | ||
return finalData; | ||
}); | ||
}); | ||
return Promise.all(promises); | ||
const fullMsg = typeof jsonMsg !== 'undefined' && jsonMsg !== 'undefined' ? JSON.parse(jsonMsg) : null; | ||
|
||
const msg = fullMsg ? String(fullMsg).trim() : ''; | ||
|
||
let finalMessage; | ||
if (msg && msg.length > 0) { | ||
finalMessage = msg; | ||
} | ||
return [version, finalMessage]; | ||
}))); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
'use strict'; | ||
|
||
var test = require('tape'); | ||
const test = require('tape'); | ||
|
||
var getMessages = require('../messages'); | ||
var Promise = require('../promise'); | ||
var versions = ['0.1.0', '0.2.0', '0.3.0']; | ||
const getMessages = require('../messages'); | ||
|
||
var name = 'forms'; | ||
const versions = ['0.1.0', '0.2.0', '0.3.0']; | ||
const name = 'forms'; | ||
|
||
test('returns a promise', async (t) => { | ||
const promise = getMessages(name, versions); | ||
|
||
test('returns a promise', function (t) { | ||
t.plan(1); | ||
var promise = getMessages(name, versions); | ||
t.ok(promise instanceof Promise, 'returns a promise'); | ||
|
||
return promise; | ||
}); | ||
|
||
test('gets deprecation messages', function (t) { | ||
var promise = getMessages(name, versions); | ||
var expected = [ | ||
{ '0.1.0': 'Please update to the latest version to ensure the latest security fixes in "qs"' }, | ||
{ '0.2.0': 'Please update to the latest version to ensure the latest security fixes in "qs"' }, | ||
{ '0.3.0': 'Please update to the latest version to ensure the latest security fixes in "qs"' } | ||
]; | ||
t.plan(1); | ||
promise.then(function (messages) { | ||
t.deepEqual(messages, expected); | ||
}, t.fail); | ||
test('gets deprecation messages', async (t) => { | ||
const expected = { | ||
'0.1.0': 'Please update to the latest version to ensure the latest security fixes in "qs"', | ||
'0.2.0': 'Please update to the latest version to ensure the latest security fixes in "qs"', | ||
'0.3.0': 'Please update to the latest version to ensure the latest security fixes in "qs"', | ||
}; | ||
|
||
const messages = await getMessages(name, versions); | ||
|
||
t.deepEqual(messages, expected); | ||
}); | ||
|
Oops, something went wrong.