Skip to content

Commit

Permalink
Avoid setting launchEditor if no $EDITOR is setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed May 15, 2020
1 parent 8c366c6 commit 721360c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
21 changes: 21 additions & 0 deletions __tests__/bin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const execa = require('execa');

const BIN_PATH = require.resolve('../bin/rwjblue-release-it-setup');
const ROOT = process.cwd();
const EDITOR = 'EDITOR' in process.env ? process.env.EDITOR : null;

function exec(args) {
return execa(process.execPath, ['--unhandled-rejections=strict', BIN_PATH, ...args]);
Expand All @@ -18,10 +19,20 @@ describe('main binary', function () {
project = new Project('some-thing-cool', '0.1.0');
project.writeSync();
process.chdir(path.join(project.root, project.name));

// ensure an EDITOR is present
process.env.EDITOR = '/bin/whatever';
});

afterEach(function () {
process.chdir(ROOT);

// reset process.env.EDITOR to initial state
if (EDITOR === null) {
delete process.env.EDITOR;
} else {
process.env.EDITOR = EDITOR;
}
});

it('adds CHANGELOG.md file', async function () {
Expand Down Expand Up @@ -178,6 +189,16 @@ describe('main binary', function () {
`);
});

it('does not add launchEditor if no $EDITOR is found', async function () {
delete process.env.EDITOR;

await exec(['--no-install', '--no-label-updates']);

let pkg = JSON.parse(fs.readFileSync('package.json', { encoding: 'utf8' }));

expect(pkg['release-it'].plugins['release-it-lerna-changelog'].launchEditor).toBeFalsy();
});

it('adds release-it configuration for monorepos to package.json', async function () {
project.pkg.workspaces = ['packages/*'];
project.writeSync();
Expand Down
16 changes: 14 additions & 2 deletions bin/rwjblue-release-it-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ const util = require('util');
const execa = require('execa');
const sortPackageJson = require('sort-package-json');
const getRepoInfoFromURL = require('hosted-git-info').fromUrl;
const gitconfig = util.promisify(require('gitconfiglocal'));
const semver = require('semver');
const which = require('which');

const skipInstall = process.argv.includes('--no-install');
const skipLabels = process.argv.includes('--no-label-updates');
const labelsOnly = process.argv.includes('--labels-only');
const update = process.argv.includes('--update');
const gitconfig = util.promisify(require('gitconfiglocal'));

const RELEASE_IT_VERSION = (() => {
let pkg = require('../package');
Expand All @@ -33,6 +35,16 @@ const RELEASE_IT_YARN_WORKSPACES_VERSION = (() => {

const DETECT_TRAILING_WHITESPACE = /\s+$/;

function hasEditor() {
let EDITOR = process.env.EDITOR;

if (!EDITOR) {
EDITOR = which.sync('editor', { nothrow: true });
}

return !!EDITOR;
}

function getDependencyRange(theirs, ours) {
if (theirs) {
let ourRange = new semver.Range(ours);
Expand Down Expand Up @@ -113,7 +125,7 @@ async function updatePackageJSON() {
releaseItConfig.plugins['release-it-lerna-changelog'] = Object.assign(
{
infile: 'CHANGELOG.md',
launchEditor: true,
launchEditor: hasEditor(),
},
releaseItConfig.plugins['release-it-lerna-changelog']
);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"github-label-sync": "^1.6.0",
"hosted-git-info": "^3.0.4",
"semver": "^7.3.2",
"sort-package-json": "^1.42.2"
"sort-package-json": "^1.42.2",
"which": "^2.0.2"
},
"devDependencies": {
"eslint": "^7.0.0",
Expand Down

0 comments on commit 721360c

Please sign in to comment.