Skip to content

Commit

Permalink
Fix a crash in the new dependency check
Browse files Browse the repository at this point in the history
Fixes #697
Fixes #696
  • Loading branch information
sindresorhus committed May 28, 2023
1 parent c113539 commit beb7db1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions source/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export const getNewDependencies = async (newPkg, rootDir) => {

const newDependencies = [];

for (const dependency of Object.keys(newPkg.dependencies)) {
if (!oldPkg.dependencies[dependency]) {
for (const dependency of Object.keys(newPkg.dependencies ?? {})) {
if (!oldPkg.dependencies?.[dependency]) {
newDependencies.push(dependency);
}
}
Expand Down
14 changes: 11 additions & 3 deletions source/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ export default class Version {
}

static verifyRequirementSatisfied(dependency, version) {
const depRange = pkg.engines[dependency];
if (!new Version(version).satisfies(depRange)) {
throw new Error(`Please upgrade to ${dependency}${depRange}`);
if (!pkg.engines?.node) {
throw new Error('Please include a `engines.node` field in your package.json');
}

const versionRange = pkg.engines?.[dependency];
if (!versionRange) {
return;
}

if (!new Version(version).satisfies(versionRange)) {
throw new Error(`Please upgrade to ${dependency}${versionRange}`);
}
}

Expand Down

0 comments on commit beb7db1

Please sign in to comment.