Skip to content

Commit c76987a

Browse files
Check if yarn.lock is ignored before throwing error (#582)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent 8f812e0 commit c76987a

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

source/git-util.js

+15
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,18 @@ exports.verifyRecentGitVersion = async () => {
226226

227227
verifyRequirementSatisfied('git', installedVersion);
228228
};
229+
230+
exports.checkIfFileGitIgnored = async pathToFile => {
231+
try {
232+
const {stdout} = await execa('git', ['check-ignore', pathToFile]);
233+
return Boolean(stdout);
234+
} catch (error) {
235+
// If file is not ignored, `git check-ignore` throws an empty error and exits.
236+
// Check that and return false so as not to throw an unwanted error.
237+
if (error.stdout === '' && error.stderr === '') {
238+
return false;
239+
}
240+
241+
throw error;
242+
}
243+
};

source/index.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,21 @@ module.exports = async (input = 'patch', options) => {
128128
{
129129
title: 'Installing dependencies using Yarn',
130130
enabled: () => options.yarn === true,
131-
task: () => exec('yarn', ['install', '--frozen-lockfile', '--production=false']).pipe(
132-
catchError(error => {
133-
if (error.stderr.startsWith('error Your lockfile needs to be updated')) {
134-
return throwError(new Error('yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again.'));
135-
}
131+
task: () => {
132+
return exec('yarn', ['install', '--frozen-lockfile', '--production=false']).pipe(
133+
catchError(async error => {
134+
if ((!error.stderr.startsWith('error Your lockfile needs to be updated'))) {
135+
return;
136+
}
136137

137-
return throwError(error);
138-
})
139-
)
138+
if (await git.checkIfFileGitIgnored('yarn.lock')) {
139+
return;
140+
}
141+
142+
throw new Error('yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again.');
143+
})
144+
);
145+
}
140146
},
141147
{
142148
title: 'Installing dependencies using npm',

0 commit comments

Comments
 (0)