SIGN IN SIGN UP
yarnpkg / yarn UNCLAIMED

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry

41528 0 1 JavaScript
/* @flow */
2016-02-15 07:32:43 +00:00
/* eslint quotes: 0 */
import Lockfile from '../src/lockfile';
import stringify from '../src/lockfile/stringify.js';
import parse from '../src/lockfile/parse.js';
import nullify from '../src/util/map.js';
feat(checksums): add integrity field with sha512 authentication to yarn.lock (#5042) * test(fixtures): adjust yarn.lock and snapshots with integrity field as needed * test(integrity): adjust existing cases to integrity field authentication * test(fixtures): integrity field authentication cases * test(integrity): integration and unit tests for the lockfile integrity field * chore(deps): add ssri module * feat(checksums): add integrity field with sha512 authentication to yarn.lock * test(integrity): additional sri string options * fix(checksums): better error when algorithms are not supported * fix(checksums): proper error message for bad hash in node <= 6 * chore(integrity): fixed new flow issues * test(integrity): adjust additional test case * test(fixtures): additional integrity field authentication cases * fix(integrity): update integrity for offline-mirror cases * style(integrity): clarify conditional for flow * fix(integrity): throw sync error rather than rejecting it * Update yarn.lock with new integrity field * Upgrade ssri * Use the latest version of the SSRI package * Optimize integrity matching from lockfile a bit * Refactor digest support determination * test(error): fixed expected error wording * fix(checksum): fail validation on malformed hash or integrity * fix(test): verify integrity failure on malformed integrity string * test(fixtures): add install auth malformed integrity fixture * chore(deps): update dependency eslint-config-fb-strict to ^22.0.0 (#5570) **Summary** This Pull Request updates dependency eslint-config-fb-strict from ^20.1.0-delta.3 to ^22.0.0 **Test plan** `yarn lint` should pass. * chore(jest): Upgrade Jest flow types (#5573) **Summary** Follow up to #5569. **Test plan** `yarn lint` should pass without errors. * ci(appveyor): Fix AppVeyor tests (#5574) * ci(appveyor): Fix AppVeyor tests **Summary** Jest 22.4.x mocks the process object without a proper stub for `process.mainModule`. In our lifecycle code, we try to set `env.npm_execpath` when it is not defined by using `process.mainModule.filename`. When running tests on AppVeyor, we run Jest directly, thus we don't have `env.npm_execpath` set, triggering the `process.mainModule` code path which is also not set, causing tests to fail. **Test plan** AppVeyor builds should pass. * Fix tests * Add missing package cache * Bring --update-checksums back * Fix tests * Bring --update-checksums back * Fix Flow error * Fix error w/ updateChecksums * Update ssri semver in package.json * Stabilize TarballFetcher.fetch tests * Moar test fixes * test(update-checksums): make sure the flag works when integrity is malformed * fix(updateChecksums): minor issues and edge cases * Revert unrelated change ahead of 'imsnif/master' by 1 commit. * Slight refactor in lockfile parser * test(fixtures): update integrity and dep versions * fix(checksums): create integrity when importing from node_modules * test(fixtures): add integrity field to expected yarn.lock * Fixes error reporting * Fixes error reporting * Fixes tests
2018-08-01 17:26:34 +02:00
const ssri = require('ssri');
const objs = [{foo: 'bar'}, {foo: {}}, {foo: 'foo', bar: 'bar'}, {foo: 5}];
2016-02-10 20:20:49 +00:00
let i = 0;
2016-10-05 16:56:53 +01:00
for (const obj of objs) {
test(`parse/stringify ${++i}`, () => {
expect(parse(stringify(obj)).object).toEqual(nullify(obj));
});
}
2016-02-10 20:20:49 +00:00
test('parse', () => {
// Yaml
expect(parse('foo:\n bar\n').object).toEqual(nullify({foo: 'bar'}));
expect(parse('foo "bar"').object).toEqual(nullify({foo: 'bar'}));
expect(parse('"foo" "bar"').object).toEqual(nullify({foo: 'bar'}));
expect(parse('foo "bar"').object).toEqual(nullify({foo: 'bar'}));
expect(parse(`foo:\n bar "bar"`).object).toEqual(nullify({foo: {bar: 'bar'}}));
expect(parse(`foo:\n bar:\n foo "bar"`).object).toEqual(nullify({foo: {bar: {}, foo: 'bar'}}));
expect(parse(`foo:\n bar:\n foo "bar"`).object).toEqual(nullify({foo: {bar: {foo: 'bar'}}}));
expect(parse(`foo:\r\n bar:\r\n foo "bar"`).object).toEqual(nullify({foo: {bar: {foo: 'bar'}}}));
expect(parse('foo:\n bar:\n yes no\nbar:\n yes no').object).toEqual(
nullify({
foo: {
bar: {
yes: 'no',
},
},
2016-02-17 06:59:47 +00:00
bar: {
yes: 'no',
},
}),
);
expect(parse('foo:\r\n bar:\r\n yes no\r\nbar:\r\n yes no').object).toEqual(
nullify({
foo: {
bar: {
yes: 'no',
},
},
bar: {
yes: 'no',
},
}),
);
2016-01-31 22:58:39 +00:00
});
test('stringify', () => {
const obj = {foo: 'bar'};
expect(stringify({a: obj, b: obj}, true)).toEqual('a, b:\n foo bar\n');
2016-02-17 06:59:47 +00:00
});
test('Lockfile.fromDirectory', () => {});
2016-02-17 06:59:47 +00:00
test('Lockfile.getLocked', () => {
2016-10-05 21:05:44 +09:00
const lockfile = new Lockfile({
cache: {
foo: 'bar',
bar: {},
},
2016-02-17 06:59:47 +00:00
});
expect(!!lockfile.getLocked('foo')).toBeTruthy();
2016-02-17 06:59:47 +00:00
});
test('Lockfile.getLocked pointer', () => {
2016-10-05 21:05:44 +09:00
const lockfile = new Lockfile({
cache: {
foo: 'bar',
bar: {},
},
2016-02-17 06:59:47 +00:00
});
expect(!!lockfile.getLocked('foo')).toBeTruthy();
2016-02-17 06:59:47 +00:00
});
test('Lockfile.getLocked no cache', () => {
expect(!new Lockfile().getLocked('foobar')).toBeTruthy();
2016-02-17 06:59:47 +00:00
});
test('Lockfile.getLocked defaults', () => {
2016-10-05 21:05:44 +09:00
const pattern = new Lockfile({
cache: {
foobar: {
version: '0.0.0',
},
},
}).getLocked('foobar');
expect(pattern.registry).toBe('npm');
expect(pattern.uid).toBe('0.0.0');
expect(pattern.version).toBe('0.0.0');
2016-02-17 06:59:47 +00:00
});
test('Lockfile.getLocked unknown', () => {
new Lockfile({cache: {}}).getLocked('foobar');
2016-02-17 06:59:47 +00:00
});
test('Lockfile.getLockfile', () => {
2016-10-05 21:05:44 +09:00
const patterns = {
2016-02-17 06:59:47 +00:00
foobar: {
name: 'foobar',
version: '0.0.0',
_uid: '0.0.0',
2016-02-17 06:59:47 +00:00
dependencies: {},
optionalDependencies: {},
2016-08-22 16:37:11 +01:00
_reference: {
permissions: {},
2016-02-17 06:59:47 +00:00
},
2016-08-22 16:37:11 +01:00
_remote: {
resolved: 'http://example.com/foobar',
registry: 'npm',
},
2016-02-17 06:59:47 +00:00
},
barfoo: {
name: 'barfoo',
version: '0.0.1',
_uid: '0.1.0',
2016-02-17 06:59:47 +00:00
dependencies: {
yes: 'no',
2016-02-17 06:59:47 +00:00
},
optionalDependencies: {
no: 'yes',
2016-02-17 06:59:47 +00:00
},
2016-08-22 16:37:11 +01:00
_reference: {
2016-02-17 06:59:47 +00:00
permissions: {
foo: 'bar',
},
2016-02-17 06:59:47 +00:00
},
2016-08-22 16:37:11 +01:00
_remote: {
resolved: 'http://example.com/barfoo',
registry: 'yarn',
},
},
'foobar@2': {},
2016-02-17 06:59:47 +00:00
};
patterns['foobar@2'] = patterns.foobar;
2016-02-17 06:59:47 +00:00
2016-10-05 21:05:44 +09:00
const actual = new Lockfile().getLockfile(patterns);
2016-02-17 06:59:47 +00:00
2016-10-05 21:05:44 +09:00
const expectedFoobar = {
version: '0.0.0',
uid: undefined,
resolved: 'http://example.com/foobar',
registry: undefined,
dependencies: undefined,
optionalDependencies: undefined,
permissions: undefined,
};
2016-10-05 21:05:44 +09:00
const expected = {
2016-02-17 06:59:47 +00:00
barfoo: {
version: '0.0.1',
uid: '0.1.0',
resolved: 'http://example.com/barfoo',
registry: 'yarn',
dependencies: {yes: 'no'},
optionalDependencies: {no: 'yes'},
permissions: {foo: 'bar'},
2016-02-17 06:59:47 +00:00
},
2016-08-24 04:12:53 +01:00
foobar: expectedFoobar,
'foobar@2': expectedFoobar,
2016-02-17 06:59:47 +00:00
};
expect(actual).toEqual(expected);
2016-02-17 06:59:47 +00:00
});
test('Lockfile.getLockfile (sorting)', () => {
2016-10-05 21:05:44 +09:00
const patterns = {
foobar2: {
name: 'foobar',
version: '0.0.0',
uid: '0.0.0',
dependencies: {},
optionalDependencies: {},
2016-08-22 16:37:11 +01:00
_reference: {
permissions: {},
},
2016-08-22 16:37:11 +01:00
_remote: {
resolved: 'http://example.com/foobar',
registry: 'npm',
},
},
foobar1: {},
};
patterns.foobar1 = patterns.foobar2;
2016-10-05 21:05:44 +09:00
const actual = new Lockfile().getLockfile(patterns);
2016-10-05 21:05:44 +09:00
const expectedFoobar = {
name: 'foobar',
version: '0.0.0',
uid: undefined,
resolved: 'http://example.com/foobar',
registry: undefined,
dependencies: undefined,
optionalDependencies: undefined,
permissions: undefined,
};
2016-10-05 21:05:44 +09:00
const expected = {
foobar1: expectedFoobar,
foobar2: expectedFoobar,
};
expect(actual).toEqual(expected);
});
feat(checksums): add integrity field with sha512 authentication to yarn.lock (#5042) * test(fixtures): adjust yarn.lock and snapshots with integrity field as needed * test(integrity): adjust existing cases to integrity field authentication * test(fixtures): integrity field authentication cases * test(integrity): integration and unit tests for the lockfile integrity field * chore(deps): add ssri module * feat(checksums): add integrity field with sha512 authentication to yarn.lock * test(integrity): additional sri string options * fix(checksums): better error when algorithms are not supported * fix(checksums): proper error message for bad hash in node <= 6 * chore(integrity): fixed new flow issues * test(integrity): adjust additional test case * test(fixtures): additional integrity field authentication cases * fix(integrity): update integrity for offline-mirror cases * style(integrity): clarify conditional for flow * fix(integrity): throw sync error rather than rejecting it * Update yarn.lock with new integrity field * Upgrade ssri * Use the latest version of the SSRI package * Optimize integrity matching from lockfile a bit * Refactor digest support determination * test(error): fixed expected error wording * fix(checksum): fail validation on malformed hash or integrity * fix(test): verify integrity failure on malformed integrity string * test(fixtures): add install auth malformed integrity fixture * chore(deps): update dependency eslint-config-fb-strict to ^22.0.0 (#5570) **Summary** This Pull Request updates dependency eslint-config-fb-strict from ^20.1.0-delta.3 to ^22.0.0 **Test plan** `yarn lint` should pass. * chore(jest): Upgrade Jest flow types (#5573) **Summary** Follow up to #5569. **Test plan** `yarn lint` should pass without errors. * ci(appveyor): Fix AppVeyor tests (#5574) * ci(appveyor): Fix AppVeyor tests **Summary** Jest 22.4.x mocks the process object without a proper stub for `process.mainModule`. In our lifecycle code, we try to set `env.npm_execpath` when it is not defined by using `process.mainModule.filename`. When running tests on AppVeyor, we run Jest directly, thus we don't have `env.npm_execpath` set, triggering the `process.mainModule` code path which is also not set, causing tests to fail. **Test plan** AppVeyor builds should pass. * Fix tests * Add missing package cache * Bring --update-checksums back * Fix tests * Bring --update-checksums back * Fix Flow error * Fix error w/ updateChecksums * Update ssri semver in package.json * Stabilize TarballFetcher.fetch tests * Moar test fixes * test(update-checksums): make sure the flag works when integrity is malformed * fix(updateChecksums): minor issues and edge cases * Revert unrelated change ahead of 'imsnif/master' by 1 commit. * Slight refactor in lockfile parser * test(fixtures): update integrity and dep versions * fix(checksums): create integrity when importing from node_modules * test(fixtures): add integrity field to expected yarn.lock * Fixes error reporting * Fixes error reporting * Fixes tests
2018-08-01 17:26:34 +02:00
test('Lockfile.getLockfile handles integrity field', () => {
const integrity = ssri.parse('sha1-foo sha512-bar');
const patterns = {
foobar: {
name: 'foobar',
version: '0.0.0',
uid: '0.0.0',
dependencies: {},
optionalDependencies: {},
_reference: {
permissions: {},
},
_remote: {
resolved: 'http://example.com/foobar',
registry: 'npm',
integrity,
},
},
};
const actual = new Lockfile().getLockfile(patterns);
const expected = {
foobar: {
version: '0.0.0',
uid: undefined,
resolved: 'http://example.com/foobar',
registry: undefined,
dependencies: undefined,
optionalDependencies: undefined,
permissions: undefined,
integrity: integrity.toString().split(' ').sort().join(' '),
},
};
expect(actual).toEqual(expected);
});
test('parse single merge conflict', () => {
const file = `
a:
no "yes"
<<<<<<< HEAD
b:
foo "bar"
=======
c:
bar "foo"
>>>>>>> branch-a
d:
yes "no"
`;
const {type, object} = parse(file);
expect(type).toEqual('merge');
expect(object).toEqual({
a: {no: 'yes'},
b: {foo: 'bar'},
c: {bar: 'foo'},
d: {yes: 'no'},
});
});
test('parse single merge conflict with CRLF', () => {
const file =
'a:\r\n no "yes"\r\n\r\n<<<<<<< HEAD\r\nb:\r\n foo "bar"' +
'\r\n=======\r\nc:\r\n bar "foo"\r\n>>>>>>> branch-a' +
'\r\n\r\nd:\r\n yes "no"\r\n';
const {type, object} = parse(file);
expect(type).toEqual('merge');
expect(object).toEqual({
a: {no: 'yes'},
b: {foo: 'bar'},
c: {bar: 'foo'},
d: {yes: 'no'},
});
});
test('parse multiple merge conflicts', () => {
const file = `
a:
no "yes"
<<<<<<< HEAD
b:
foo "bar"
=======
c:
bar "foo"
>>>>>>> branch-a
d:
yes "no"
<<<<<<< HEAD
e:
foo "bar"
=======
f:
bar "foo"
>>>>>>> branch-b
`;
const {type, object} = parse(file);
expect(type).toEqual('merge');
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', () => {
const file = `
<<<<<<< HEAD
b:
foo: "bar
=======
c:
bar "foo"
>>>>>>> branch-a
`;
const {type, object} = parse(file);
expect(type).toEqual('conflict');
expect(Object.keys(object).length).toEqual(0);
});
test('discards common ancestors in merge conflicts', () => {
const file = `
<<<<<<< HEAD
b:
foo "bar"
||||||| common ancestor
d:
yes "no"
=======
c:
bar "foo"
>>>>>>> branch-a
`;
const {type, object} = parse(file);
expect(type).toEqual('merge');
expect(object).toEqual({
b: {foo: 'bar'},
c: {bar: 'foo'},
});
expect(object.d).toBe(undefined);
});