Skip to content

Commit

Permalink
Fix workspace query handling (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
job13er authored Sep 28, 2023
1 parent 56ec85d commit e2a88fa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/bumpr.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const {cloneDeep, get, truncate} = _
*/
function getPackages() {
Logger.log('About to query npm for workspace info')
return exec('npm query .workspace', {cwd: '.', maxBuffer: 1024 * 1024}).then((output) => {
return exec('npm query .workspace', {cwd: '.', maxBuffer: 1024 * 1024}).then(({stdout}) => {
const output = stdout.trim()
Logger.log(`Output from "npm query .workspace": ${truncate(output, {length: 50})}`)
const packages = JSON.parse(output).map((entry) => entry.location)
return packages.length === 0 ? ['.'] : packages
Expand Down
12 changes: 1 addition & 11 deletions src/package.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import {readFileSync} from 'fs'
import _ from 'lodash'
import path from 'path'
import * as url from 'url'

const dirname = url.fileURLToPath(new URL('.', import.meta.url))
const pathToPkg = path.join(dirname, '..', 'package.json')
if (process.env.VERBOSE) {
console.log(`Path to package.json: ${pathToPkg}`)
}
const contents = readFileSync(pathToPkg, {encoding: 'utf-8'})
if (process.env.VERBOSE) {
console.log(`Contents of package.json: ${_.truncate(contents, {length: 50})}`)
}

const pkg = JSON.parse(contents)
const pkg = JSON.parse(readFileSync(path.join(dirname, '..', 'package.json'), {encoding: 'utf-8'}))

export const {name, version} = pkg
export default pkg
3 changes: 2 additions & 1 deletion src/tests/bumpr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class FileNotFoundError extends Error {
}

function setupPkgs(pkgs = []) {
exec.mockReturnValueOnce(Promise.resolve(JSON.stringify(pkgs)))
const response = {stdout: JSON.stringify(pkgs)}
exec.mockReturnValueOnce(Promise.resolve(response))
}

/**
Expand Down

0 comments on commit e2a88fa

Please sign in to comment.