Skip to content

Commit

Permalink
fix: issue:7892 prevent package-lock.json creation without package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ignis committed Dec 5, 2024
1 parent 01f92e0 commit 01aab62
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions workspaces/arborist/bin/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,23 @@ const printDiff = diff => {
})
}

module.exports = (options, time) => {
module.exports = async (options, time) => {
// Check for package.json
if (!fs.existsSync(path.join(options.path, 'package.json'))) {
log.error('No package.json found in the current directory.')
log.error('Please navigate to the correct directory or run npm init.')
return Promise.resolve('Aborted due to missing package.json')
throw new Error('Aborted due to missing package.json')
}

const arb = new Arborist(options)
return arb
.reify(options)
.then(time)
.then(async ({ timing, result: tree }) => {
printTree(tree)
if (options.dryRun) {
printDiff(arb.diff)
}
if (tree.meta && options.save) {
await tree.meta.save()
}
return `resolved ${tree.inventory.size} deps in ${timing.seconds}`
})
const { timing, result: tree } = await arb.reify(options).then(time)

printTree(tree)
if (options.dryRun) {
printDiff(arb.diff)
}
if (tree.meta && options.save) {
await tree.meta.save()
}
return `resolved ${tree.inventory.size} deps in ${timing.seconds}`
}

0 comments on commit 01aab62

Please sign in to comment.