Skip to content

Commit

Permalink
fix: better error for no lockfile found
Browse files Browse the repository at this point in the history
  • Loading branch information
gabidobo committed Mar 6, 2023
1 parent ca14b7c commit 4c430d9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/files/lockfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ const {parseSyml} = require('@yarnpkg/parsers');

const loadLockfiles = async (appPath) => {
const lockfiles = {};
let lockfileFound = false;

// NPM
try {
const lockfileContent = await fs.promises.readFile(path.join(appPath, 'package-lock.json'), {
encoding: 'utf-8',
});
lockfileFound = true;
try {
const lockfileData = JSON.parse(lockfileContent);
lockfiles.npm = {
Expand All @@ -30,6 +32,7 @@ const loadLockfiles = async (appPath) => {
const lockfileContent = await fs.promises.readFile(path.join(appPath, 'yarn.lock'), {
encoding: 'utf-8',
});
lockfileFound = true;
const versionMatch = lockfileContent.match(/yarn lockfile v(\d+)/);
if (versionMatch) {
try {
Expand Down Expand Up @@ -69,7 +72,8 @@ const loadLockfiles = async (appPath) => {
} catch {}

// PNPM
if (existsWantedLockfile(appPath)) {
if (await existsWantedLockfile(appPath)) {
lockfileFound = true;
try {
const lockfileData = await readWantedLockfile(appPath, {});
lockfiles.pnpm = {
Expand All @@ -82,6 +86,10 @@ const loadLockfiles = async (appPath) => {
}
}

if (!lockfileFound) {
throw new Error('No lockfile found');
}

return lockfiles;
};

Expand Down

0 comments on commit 4c430d9

Please sign in to comment.