Skip to content

Commit

Permalink
fix(release): add comment to why we read json manually
Browse files Browse the repository at this point in the history
  • Loading branch information
varl committed Jun 30, 2021
1 parent fcde214 commit 084f5e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
4 changes: 1 addition & 3 deletions packages/utils/src/cmds/release.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { existsSync } = require('fs')
const path = require('path')
const { reporter } = require('@dhis2/cli-helpers-engine')
const { existsSync } = require('fs-extra')
const semanticRelease = require('semantic-release')
const getWorkspacePackages = require('../support/getWorkspacePackages')

Expand Down Expand Up @@ -65,8 +65,6 @@ function publisher(target = '', packages) {
}

const handler = async ({ publish }) => {
// set up the plugins and filter out any undefined elements

const rootPackageFile = path.join(process.cwd(), 'package.json')
const packages = [
rootPackageFile,
Expand Down
24 changes: 16 additions & 8 deletions packages/utils/src/support/semantic-release-app-hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ exports.verifyConditions = (config, context) => {
const { pkgRoot } = config
const { env } = context

// make sure to read the file from disk since it will have changed
// in a previous external step (semantic-release/npm), and if we use
// require here we get a cached result.
const packagePath = fs.readJsonSync(pkgRoot, 'package.json')

if (!fs.existsSync(packagePath)) {
throw new SemanticReleaseError(
`Failed to locate package.json file, does it exist in ${pkgRoot}?`,
'EMISSINGPACKAGE',
'package.json is necessary to automatically publish to the App Hub'
)
}

const configPath = path.join(pkgRoot, 'd2.config.js')

if (!fs.existsSync(configPath)) {
Expand All @@ -21,14 +33,6 @@ exports.verifyConditions = (config, context) => {
)
}

if (!fs.existsSync(packagePath)) {
throw new SemanticReleaseError(
`Failed to locate package.json file, does it exist in ${pkgRoot}?`,
'EMISSINGPACKAGE',
'package.json is necessary to automatically publish to the App Hub'
)
}

const d2Config = require(configPath)

if (d2Config.type === 'lib') {
Expand Down Expand Up @@ -72,6 +76,10 @@ exports.publish = async (config, context) => {
const { env, nextRelease } = context

const packagePath = path.join(pkgRoot, 'package.json')

// make sure to read the file from disk since it will have changed
// in a previous external step (semantic-release/npm), and if we use
// require here we get a cached result.
const pkg = fs.readJsonSync(packagePath)

if (semver.lt(pkg.version, nextRelease.version)) {
Expand Down

0 comments on commit 084f5e5

Please sign in to comment.