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

Replace static "require" to dynamic "read" #137

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bin/lib/get-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const exec = require('shelljs').exec
const parseRepo = require('github-url-to-object')

function getDefaults (workPath, isEnterprise, callback) {
const pkg = require(path.resolve(workPath, 'package.json'))
const pkg = readJson(path.resolve(workPath, 'package.json'))
const lernaPath = path.resolve(workPath, 'lerna.json')

if (!Object.hasOwnProperty.call(pkg, 'repository')) {
Expand Down Expand Up @@ -49,7 +49,7 @@ function getDefaults (workPath, isEnterprise, callback) {
let lerna = {}
let errStr
if (fs.existsSync(lernaPath)) {
lerna = require(lernaPath) /* || {} */ // 👈 though I prefer this expression
lerna = readJson(lernaPath) /* || {} */ // 👈 though I prefer this expression
if (log.version !== lerna.version) {
errStr = 'CHANGELOG.md out of sync with lerna.json '
errStr += '(' + (log.version || log.title) + ' !== ' + lerna.version + ')'
Expand Down Expand Up @@ -87,5 +87,9 @@ function getTargetCommitish () {
return 'master'
}

function readJson(filePath) {
return JSON.parse(fs.readFileSync(filePath))
}

module.exports = getDefaults
module.exports.getTargetCommitish = getTargetCommitish