-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: when packages are filter due to engine not matching, we need to…
… print it out, just like we do in peer checks #1422
- Loading branch information
1 parent
42075d6
commit f19e948
Showing
20 changed files
with
267 additions
and
44 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import ProgressBar from 'progress' | ||
import { Index } from '../types/IndexType' | ||
import { Options } from '../types/Options' | ||
import { Version } from '../types/Version' | ||
import getPackageManager from './getPackageManager' | ||
|
||
/** | ||
* Get the engines.node versions from the NPM repository based on the version target. | ||
* | ||
* @param packageMap An object whose keys are package name and values are version | ||
* @param [options={}] Options. | ||
* @returns Promised {packageName: engines.node} collection | ||
*/ | ||
async function getEnginesNodeFromRegistry(packageMap: Index<Version>, options: Options) { | ||
const packageManager = getPackageManager(options, options.packageManager) | ||
if (!packageManager.getEngines) return {} | ||
|
||
const numItems = Object.keys(packageMap).length | ||
let bar: ProgressBar | ||
if (!options.json && options.loglevel !== 'silent' && options.loglevel !== 'verbose' && numItems > 0) { | ||
bar = new ProgressBar('[:bar] :current/:total :percent', { total: numItems, width: 20 }) | ||
bar.render() | ||
} | ||
|
||
return Object.entries(packageMap).reduce(async (accumPromise, [pkg, version]) => { | ||
const enginesNode = (await packageManager.getEngines!(pkg, version)).node | ||
if (bar) { | ||
bar.tick() | ||
} | ||
const accum = await accumPromise | ||
return { ...accum, [pkg]: enginesNode } | ||
}, Promise.resolve<Index<Version | undefined>>({})) | ||
} | ||
|
||
export default getEnginesNodeFromRegistry |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { minVersion, satisfies } from 'semver' | ||
import { IgnoredUpgradeDueToEnginesNode } from '../types/IgnoredUpgradeDueToEnginesNode' | ||
import { Index } from '../types/IndexType' | ||
import { Maybe } from '../types/Maybe' | ||
import { Options } from '../types/Options' | ||
import { Version } from '../types/Version' | ||
import { VersionSpec } from '../types/VersionSpec' | ||
import getEnginesNodeFromRegistry from './getEnginesNodeFromRegistry' | ||
import upgradePackageDefinitions from './upgradePackageDefinitions' | ||
|
||
/** Checks if package.json min node version satisfies given package engine.node spec */ | ||
const satisfiesNodeEngine = (enginesNode: Maybe<Version>, optionsEnginesNodeMinVersion: string) => | ||
!enginesNode || satisfies(optionsEnginesNodeMinVersion, enginesNode) | ||
|
||
/** Get all upgrades that are ignored due to incompatible engines.node. */ | ||
export async function getIgnoredUpgradesDueToEnginesNode( | ||
current: Index<VersionSpec>, | ||
upgraded: Index<VersionSpec>, | ||
options: Options = {}, | ||
) { | ||
if (!options.nodeEngineVersion) return {} | ||
const optionsEnginesNodeMinVersion = minVersion(options.nodeEngineVersion)?.version | ||
if (!optionsEnginesNodeMinVersion) return {} | ||
const [upgradedLatestVersions] = await upgradePackageDefinitions(current, { | ||
...options, | ||
enginesNode: false, | ||
nodeEngineVersion: undefined, | ||
loglevel: 'silent', | ||
}) | ||
const enginesNodes = await getEnginesNodeFromRegistry(upgradedLatestVersions, options) | ||
return Object.entries(upgradedLatestVersions) | ||
.filter( | ||
([pkgName, newVersion]) => | ||
upgraded[pkgName] !== newVersion && !satisfiesNodeEngine(enginesNodes[pkgName], optionsEnginesNodeMinVersion), | ||
) | ||
.reduce( | ||
(accum, [pkgName, newVersion]) => ({ | ||
...accum, | ||
[pkgName]: { | ||
from: current[pkgName], | ||
to: newVersion, | ||
enginesNode: enginesNodes[pkgName]!, | ||
}, | ||
}), | ||
{} as Index<IgnoredUpgradeDueToEnginesNode>, | ||
) | ||
} | ||
|
||
export default getIgnoredUpgradesDueToEnginesNode |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Version } from './Version' | ||
|
||
/** An object that represents an upgrade that was ignored due to mismatch of engines.node */ | ||
export interface IgnoredUpgradeDueToEnginesNode { | ||
from: Version | ||
to: Version | ||
enginesNode: Version | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Index } from './IndexType' | ||
import { Version } from './Version' | ||
|
||
/** An object that represents an upgrade that was ignored due to peer dependencies, along with the reason. */ | ||
export interface IgnoredUpgradeDueToPeerDeps { | ||
from: Version | ||
to: Version | ||
reason: Index<string> | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { chalkInit } from '../src/lib/chalk' | ||
import getEnginesNodeFromRegistry from '../src/lib/getEnginesNodeFromRegistry' | ||
import chaiSetup from './helpers/chaiSetup' | ||
|
||
chaiSetup() | ||
|
||
describe('getEnginesNodeFromRegistry', function () { | ||
it('single package', async () => { | ||
await chalkInit() | ||
const data = await getEnginesNodeFromRegistry({ del: '2.0.0' }, {}) | ||
data.should.deep.equal({ | ||
del: '>=0.10.0', | ||
}) | ||
}) | ||
|
||
it('single package empty', async () => { | ||
await chalkInit() | ||
const data = await getEnginesNodeFromRegistry({ 'ncu-test-return-version': '1.0' }, {}) | ||
data.should.deep.equal({ 'ncu-test-return-version': undefined }) | ||
}) | ||
|
||
it('multiple packages', async () => { | ||
await chalkInit() | ||
const data = await getEnginesNodeFromRegistry( | ||
{ | ||
'ncu-test-return-version': '1.0.0', | ||
'ncu-test-peer': '1.0.0', | ||
del: '2.0.0', | ||
}, | ||
{}, | ||
) | ||
data.should.deep.equal({ | ||
'ncu-test-return-version': undefined, | ||
'ncu-test-peer': undefined, | ||
del: '>=0.10.0', | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.