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

Check if yarn.lock is ignored before throwing error #582

Merged
merged 7 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions source/git-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,18 @@ exports.verifyRecentGitVersion = async () => {

verifyRequirementSatisfied('git', installedVersion);
};

exports.checkIfFileGitIgnored = async pathToFile => {
try {
const {stdout} = await execa('git', ['check-ignore', pathToFile]);
return Boolean(stdout);
} catch (error) {
// If file is not ignored, `git check-ignore` throws an empty error and exits.
// Check that and return false so as not to throw an unwanted error.
if (error.stdout === '' && error.stderr === '') {
dopecodez marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

throw error;
}
};
22 changes: 14 additions & 8 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,21 @@ module.exports = async (input = 'patch', options) => {
{
title: 'Installing dependencies using Yarn',
enabled: () => options.yarn === true,
task: () => exec('yarn', ['install', '--frozen-lockfile', '--production=false']).pipe(
catchError(error => {
if (error.stderr.startsWith('error Your lockfile needs to be updated')) {
return throwError(new Error('yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again.'));
}
task: () => {
return exec('yarn', ['install', '--frozen-lockfile', '--production=false']).pipe(
catchError(async error => {
dopecodez marked this conversation as resolved.
Show resolved Hide resolved
if ((!error.stderr.startsWith('error Your lockfile needs to be updated'))) {
return;
}

return throwError(error);
})
)
if (await git.checkIfFileGitIgnored('yarn.lock')) {
return;
}

throw new Error('yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again.');
})
);
}
},
{
title: 'Installing dependencies using npm',
Expand Down