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

fix: issue #7892 prevent package-lock.json creation without package.json #7960

Open
wants to merge 2 commits into
base: latest
Choose a base branch
from
Open
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions workspaces/arborist/bin/reify.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const fs = require('node:fs')
const path = require('node:path')
const Arborist = require('../')

const printTree = require('./lib/print-tree.js')
Expand Down Expand Up @@ -31,6 +33,13 @@ const printDiff = diff => {
}

module.exports = (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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant Promise.reject? and then you'd need to wrap the message in a new Error().

But we could just make this async and throw properly too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I have resolved this now.

}

const arb = new Arborist(options)
return arb
.reify(options)
Expand Down