Skip to content

Commit

Permalink
Add check for lock file name before applying
Browse files Browse the repository at this point in the history
  • Loading branch information
kopach committed Jun 6, 2020
1 parent 98f7ccc commit dbcc8dd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/lockfix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { log } from './logger';
export default async function lockfix(): Promise<void> {
log('🎬 Starting...');

if (!(await isAnythingToCommit())) {
log('🤔 nothing to do for me, exiting...');
if (!(await isAnyUncommitedChnage())) {
log('🤔 Nothing to do for me, exiting...');

return;
}
Expand Down Expand Up @@ -42,16 +42,23 @@ export default async function lockfix(): Promise<void> {
log('✅ Done');
}

async function isAnythingToCommit(): Promise<boolean> {
async function isAnyUncommitedChnage(): Promise<boolean> {
const result: string = (await execa('git', ['status', '--porcelain'])).stdout;

if (!result) {
if (!result || !isChnagendLockFile(result)) {
return Promise.resolve(false);
}

return Promise.resolve(true);
}

function isChnagendLockFile(str: string): boolean {
return (
str.indexOf('package-lock.json') !== -1 ||
str.indexOf('npm-shrinkwrap.json') !== -1
);
}

async function printRevertInstructions(): Promise<void> {
const commitHash: string = (await execa('git', ['rev-parse', 'HEAD'])).stdout;

Expand Down

0 comments on commit dbcc8dd

Please sign in to comment.