From 01f92e039187ab59392b4adb276ccca78692deaf Mon Sep 17 00:00:00 2001 From: kyle-ignis Date: Wed, 4 Dec 2024 21:50:08 -0700 Subject: [PATCH] fix: issue #7892 prevent package-lock.json creation without package.json --- workspaces/arborist/bin/reify.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/workspaces/arborist/bin/reify.js b/workspaces/arborist/bin/reify.js index 3f3aafe8ab9bb..7a00d28b59435 100644 --- a/workspaces/arborist/bin/reify.js +++ b/workspaces/arborist/bin/reify.js @@ -1,3 +1,5 @@ +const fs = require('node:fs') +const path = require('node:path') const Arborist = require('../') const printTree = require('./lib/print-tree.js') @@ -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') + } + const arb = new Arborist(options) return arb .reify(options)