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

Adds support for parsing Yaml files #7300

Merged
merged 5 commits into from
May 24, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa

## Master

- Yarn will tolerate Yaml at parse time. Full support isn't ready yet and will only come at the next major.

[#7300](https://github.com/yarnpkg/yarn/pull/7300) - [**Maël Nison**](https://twitter.com/arcanis)

## 1.16.0

- Retries downloading a package on `yarn install` when we get a ETIMEDOUT error.

[#7163](https://github.com/yarnpkg/yarn/pull/7163) - [**Vincent Bailly**](https://github.com/VincentBailly)
[#7163](https://github.com/yarnpkg/yarn/pull/7163) - [**Vincent Bailly**](https://github.com/VincentBailly)

- Implements `yarn audit --level [severity]` flag to filter the audit command's output.

[#6716](https://github.com/yarnpkg/yarn/pull/6716) - [**Rogério Vicente**](https://twitter.com/rogeriopvl)
[#6716](https://github.com/yarnpkg/yarn/pull/6716) - [**Rogério Vicente**](https://twitter.com/rogeriopvl)

- Implements `yarn audit --groups group_name [group_name ...]`.

Expand Down
5 changes: 4 additions & 1 deletion __tests__/lockfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ for (const obj of objs) {
}

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'}));
Expand Down Expand Up @@ -337,7 +340,7 @@ test('parse merge conflict fail', () => {
const file = `
<<<<<<< HEAD
b:
foo "bar
foo: "bar
=======
c:
bar "foo"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"is-builtin-module": "^2.0.0",
"is-ci": "^1.0.10",
"is-webpack-bundle": "^1.0.0",
"js-yaml": "^3.13.1",
"leven": "^2.0.0",
"loud-rejection": "^1.2.0",
"micromatch": "^2.3.11",
Expand Down
14 changes: 13 additions & 1 deletion src/lockfile/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {LOCKFILE_VERSION} from '../constants.js';
import {MessageError} from '../errors.js';
import map from '../util/map.js';

const {safeLoad, FAILSAFE_SCHEMA} = require('js-yaml');

type Token = {
line: number,
col: number,
Expand Down Expand Up @@ -382,7 +384,17 @@ function hasMergeConflicts(str: string): boolean {
function parse(str: string, fileLoc: string): Object {
const parser = new Parser(str, fileLoc);
parser.next();
return parser.parse();
try {
return parser.parse();
} catch (error1) {
try {
return safeLoad(str, {
schema: FAILSAFE_SCHEMA,
});
} catch (error2) {
throw error1;
}
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4681,6 +4681,14 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

js-yaml@^3.13.1:
version "3.13.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847"
integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"

js-yaml@^3.7.0, js-yaml@^3.8.4:
version "3.12.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1"
Expand Down