diff --git a/bin/release-it.js b/bin/release-it.js index c715f5b1..445b86a7 100755 --- a/bin/release-it.js +++ b/bin/release-it.js @@ -2,8 +2,10 @@ import updater from 'update-notifier'; import parseArgs from 'yargs-parser'; -import pkg from '../package.json'; import release from '../lib/index.js'; +import { readJSON } from '../lib/util'; + +const pkg = readJSON('../package.json'); const aliases = { c: 'config', diff --git a/lib/cli.js b/lib/cli.js index 9be7a6cc..7e3f3b3c 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,6 +1,8 @@ -import pkg from '../package.json'; +import { readJSON } from '../lib/util'; import Log from './log'; +const pkg = readJSON('../package.json'); + const log = new Log(); const helpText = `Release It! v${pkg.version} diff --git a/lib/config.js b/lib/config.js index 83d7e666..0c6057f4 100644 --- a/lib/config.js +++ b/lib/config.js @@ -5,10 +5,10 @@ import yaml from 'yaml'; import _ from 'lodash'; import isCI from 'is-ci'; import _debug from 'debug'; -import defaultConfig from '../config/release-it.json'; -import { getSystemInfo } from './util'; +import { readJSON, getSystemInfo } from './util'; const debug = _debug('release-it:config'); +const defaultConfig = readJSON('../config/release-it.json'); const searchPlaces = [ 'package.json', diff --git a/lib/deprecated.js b/lib/deprecated.js index ed8ba8ed..93b6e584 100644 --- a/lib/deprecated.js +++ b/lib/deprecated.js @@ -1,7 +1,9 @@ import Deprecated from 'deprecated-obj'; -import deprecated from '../config/deprecated.json'; +import { readJSON } from './util'; import Log from './log'; +const deprecated = readJSON('../config/deprecated.json'); + export default (config, log = new Log()) => { const deprecations = new Deprecated(deprecated, config); const compliant = deprecations.getCompliant(); diff --git a/lib/metrics.js b/lib/metrics.js index a7c8d153..1b5f168a 100644 --- a/lib/metrics.js +++ b/lib/metrics.js @@ -4,9 +4,10 @@ import { v4 as uuidv4 } from 'uuid'; import osName from 'os-name'; import isCi from 'is-ci'; import _debug from 'debug'; -import pkg from '../package.json'; +import { readJSON } from './util'; const debug = _debug('release-it:metrics'); +const pkg = readJSON('../package.json'); const noop = Promise.resolve(); diff --git a/lib/plugin/GitRelease.js b/lib/plugin/GitRelease.js index 7f617735..bc548a18 100644 --- a/lib/plugin/GitRelease.js +++ b/lib/plugin/GitRelease.js @@ -1,7 +1,9 @@ import _ from 'lodash'; -import defaultConfig from '../../config/release-it.json'; +import { readJSON } from '../util'; import GitBase from './GitBase'; +const defaultConfig = readJSON('../../config.release-it.json'); + class GitRelease extends GitBase { static isEnabled(options) { return options.release; diff --git a/lib/plugin/github/GitHub.js b/lib/plugin/github/GitHub.js index 0600c586..94550f09 100644 --- a/lib/plugin/github/GitHub.js +++ b/lib/plugin/github/GitHub.js @@ -5,11 +5,12 @@ import globby from 'globby'; import mime from 'mime-types'; import _ from 'lodash'; import retry from 'async-retry'; -import pkg from '../../../package.json'; -import { format, parseVersion, e } from '../../util'; +import { format, parseVersion, readJSON, e } from '../../util'; import Release from '../GitRelease'; import prompts from './prompts'; +const pkg = readJSON('../../../package.json'); + const docs = 'https://git.io/release-it-github'; const RETRY_CODES = [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]; diff --git a/lib/util.js b/lib/util.js index 43d69fc3..962576fb 100644 --- a/lib/util.js +++ b/lib/util.js @@ -4,9 +4,12 @@ import _ from 'lodash'; import gitUrlParse from 'git-url-parse'; import semver from 'semver'; import osName from 'os-name'; -import pkg from '../package.json'; import Log from './log'; +const readJSON = async file => JSON.parse(fs.readFileSync(file, 'utf8')); + +const pkg = readJSON('../package.json'); + const log = new Log(); const getSystemInfo = () => { @@ -97,5 +100,6 @@ export { parseGitUrl, hasAccess, parseVersion, + readJSON, e }; diff --git a/test/cli.js b/test/cli.js index 57e9cc83..dfe1fa9a 100644 --- a/test/cli.js +++ b/test/cli.js @@ -1,7 +1,9 @@ import test from 'ava'; import mockStdIo from 'mock-stdio'; -import pkg from '../package.json'; import { version, help } from '../lib/cli'; +import { readJSON } from './util'; + +const pkg = readJSON('../package.json'); test('should print version', t => { mockStdIo.start(); diff --git a/test/config.js b/test/config.js index 81b08312..9764ff8f 100644 --- a/test/config.js +++ b/test/config.js @@ -1,7 +1,9 @@ import test from 'ava'; import mock from 'mock-fs'; import Config from '../lib/config'; -import defaultConfig from '../config/release-it.json'; +import { readJSON } from './util'; + +const defaultConfig = readJSON('../config/release-it.json'); const localConfig = { github: { release: true } }; diff --git a/test/git.init.js b/test/git.init.js index 052016bc..0edb3761 100644 --- a/test/git.init.js +++ b/test/git.init.js @@ -2,10 +2,11 @@ import test from 'ava'; import sh from 'shelljs'; import Shell from '../lib/shell'; import Git from '../lib/plugin/git/Git'; -import { git } from '../config/release-it.json'; -import { factory } from './util'; +import { factory, readJSON } from './util'; import { mkTmpDir, gitAdd } from './util/helpers'; +const { git } = readJSON('../config/release-it.json'); + test.serial.beforeEach(t => { const bare = mkTmpDir(); const target = mkTmpDir();