Skip to content

Commit

Permalink
Nits
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer committed Jul 7, 2017
1 parent 6eef7da commit 2c8a0b2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
30 changes: 18 additions & 12 deletions __tests__/lockfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@ d:

const {type, object} = parse(file);
expect(type).toEqual('merge');
expect(object.a.no).toEqual('yes');
expect(object.b.foo).toEqual('bar');
expect(object.c.bar).toEqual('foo');
expect(object.d.yes).toEqual('no');
expect(object).toEqual({
a: {no: 'yes'},
b: {foo: 'bar'},
c: {bar: 'foo'},
d: {yes: 'no'},
});
});

test('parse multiple merge conflicts', () => {
Expand Down Expand Up @@ -246,12 +248,14 @@ f:

const {type, object} = parse(file);
expect(type).toEqual('merge');
expect(object.a.no).toEqual('yes');
expect(object.b.foo).toEqual('bar');
expect(object.c.bar).toEqual('foo');
expect(object.d.yes).toEqual('no');
expect(object.e.foo).toEqual('bar');
expect(object.f.bar).toEqual('foo');
expect(object).toEqual({
a: {no: 'yes'},
b: {foo: 'bar'},
c: {bar: 'foo'},
d: {yes: 'no'},
e: {foo: 'bar'},
f: {bar: 'foo'},
});
});

test('parse merge conflict fail', () => {
Expand Down Expand Up @@ -286,7 +290,9 @@ c:

const {type, object} = parse(file);
expect(type).toEqual('merge');
expect(object.b.foo).toEqual('bar');
expect(object.c.bar).toEqual('foo');
expect(object).toEqual({
b: {foo: 'bar'},
c: {bar: 'foo'},
});
expect(object.d).toBe(undefined);
});
16 changes: 8 additions & 8 deletions src/lockfile/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,25 +337,25 @@ function extractConflictVariants(str: string): [string, string] {
if (line.startsWith(MERGE_CONFLICT_START)) {
// get the first variant
while (lines.length) {
const line = lines.shift();
if (line === MERGE_CONFLICT_SEP) {
const conflictLine = lines.shift();
if (conflictLine === MERGE_CONFLICT_SEP) {
skip = false;
break;
} else if (skip || line.startsWith(MERGE_CONFLICT_ANCESTOR)) {
} else if (skip || conflictLine.startsWith(MERGE_CONFLICT_ANCESTOR)) {
skip = true;
continue;
} else {
variants[0].push(line);
variants[0].push(conflictLine);
}
}

// get the second variant
while (lines.length) {
const line = lines.shift();
if (line.startsWith(MERGE_CONFLICT_END)) {
const conflictLine = lines.shift();
if (conflictLine.startsWith(MERGE_CONFLICT_END)) {
break;
} else {
variants[1].push(line);
variants[1].push(conflictLine);
}
}
} else {
Expand All @@ -371,7 +371,7 @@ function extractConflictVariants(str: string): [string, string] {
* Check if a lockfile has merge conflicts.
*/
function hasMergeConflicts(str: string): boolean {
return str.includes(MERGE_CONFLICT_START);
return str.includes(MERGE_CONFLICT_START) && str.includes(MERGE_CONFLICT_SEP) && str.includes(MERGE_CONFLICT_END);
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/registries/npm-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import envReplace from '../util/env-replace.js';
import Registry from './base-registry.js';
import {addSuffix} from '../util/misc';
import {getPosixPath, resolveWithHome} from '../util/path';
import isRequestToRegistry from './is-request-to-registry.js';

const userHome = require('../util/user-home-dir').default;
const path = require('path');
Expand Down

0 comments on commit 2c8a0b2

Please sign in to comment.