Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that Node.js version bumps are done in major releases #686

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"p-timeout": "^6.1.1",
"path-exists": "^5.0.0",
"pkg-dir": "^7.0.0",
"read-pkg": "^7.1.0",
"read-pkg-up": "^9.1.0",
"rxjs": "^7.8.0",
"semver": "^7.3.8",
Expand Down
17 changes: 15 additions & 2 deletions source/prerequisite-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import {execa} from 'execa';
import Version from './version.js';
import * as git from './git-util.js';
import * as npm from './npm/util.js';
import {getTagVersionPrefix} from './util.js';
import * as util from './util.js';

const prerequisiteTasks = (input, pkg, options) => {
const isExternalRegistry = npm.isExternalRegistry(pkg);
/** @type {Version} */
let newVersion = null;

const tasks = [
Expand Down Expand Up @@ -62,6 +63,18 @@ const prerequisiteTasks = (input, pkg, options) => {
newVersion = Version.getAndValidateNewVersionFrom(input, pkg.version);
},
},
{
title: 'Check for Node version bump',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: 'Check for Node version bump',
title: 'Check for Node.js version bump',

async task() {
// TODO: path
const nodeVersionIncreased = await util.hasNodeVersionIncreased(pkg, '');

if (nodeVersionIncreased && !newVersion.isMajor(input)) {
// TODO: better message
throw new Error('The Node version has increased, but this release is not a major version.');
}
},
},
{
title: 'Check for pre-release version',
task() {
Expand All @@ -75,7 +88,7 @@ const prerequisiteTasks = (input, pkg, options) => {
async task() {
await git.fetch();

const tagPrefix = await getTagVersionPrefix(options);
const tagPrefix = await util.getTagVersionPrefix(options);

await git.verifyTagDoesNotExistOnRemote(`${tagPrefix}${newVersion}`);
},
Expand Down
24 changes: 21 additions & 3 deletions source/util.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {readPackageUp} from 'read-pkg-up';
import {packageDirectory} from 'pkg-dir';
import {readPackage} from 'read-pkg';
import issueRegex from 'issue-regex';
import terminalLink from 'terminal-link';
import {execa} from 'execa';
import pMemoize from 'p-memoize';
import ow from 'ow';
import chalk from 'chalk';
import {packageDirectory} from 'pkg-dir';
import semver from 'semver';
import * as gitUtil from './git-util.js';
import * as npmUtil from './npm/util.js';

Expand Down Expand Up @@ -82,9 +84,14 @@ export const getNewFiles = async () => {
};
};

const getPackageJsonFromLastRelease = async pkgPath => {
const pkg = await gitUtil.readFileFromLastRelease(pkgPath);
// TODO: tests are failing, either sindresorhus/read-pkg#28 or use normalize-package-data
return readPackage(pkg);
};

export const getNewDependencies = async (newPkg, pkgPath) => {
let oldPkg = await gitUtil.readFileFromLastRelease(pkgPath);
oldPkg = JSON.parse(oldPkg);
const oldPkg = await getPackageJsonFromLastRelease(pkgPath);

const newDependencies = [];

Expand Down Expand Up @@ -120,3 +127,14 @@ export const getPreReleasePrefix = pMemoize(async options => {
return '';
}
});

export const hasNodeVersionIncreased = async (newPkg, pkgPath) => {
const oldPkg = await getPackageJsonFromLastRelease(pkgPath);

// TODO: what if `oldPkg` had a version but `newPkg` doesn't?
if (!oldPkg || !newPkg.engines.node) {
return false;
}

return semver.gt(newPkg.engines.node, oldPkg.engines.node);
};
6 changes: 6 additions & 0 deletions source/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export default class Version {
return Boolean(semver.prerelease(this.version));
}

// TODO: should this be validated? it's after `getNewVersionFrom` in tasks
// add test in test/version.js
isMajor(input) {
return semver.diff(this.version, input) === 'major';
}

satisfies(range) {
Version.validate(this.version);
return semver.satisfies(this.version, range, {
Expand Down