Skip to content

Commit

Permalink
replace js-yaml with yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisblossom committed Oct 22, 2019
1 parent 83ff4b1 commit 60337c9
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## HEAD

- Migrate from Flowtype to Typescript
- **Breaking change:** Use npm package [yaml](https://www.npmjs.com/package/yaml) to parse YAML instead of npm package [js-yaml](https://www.npmjs.com/package/js-yaml).
- **Breaking change:** Replace `searchSync` with `cosmiconfigSync.search` and replace `loadSync` with `cosmiconfigSync.load`

```js
Expand Down
1 change: 1 addition & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'yaml';
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,11 @@
]
},
"dependencies": {
"@types/js-yaml": "3.12.1",
"@types/parse-json": "4.0.0",
"import-fresh": "^3.1.0",
"js-yaml": "^3.13.1",
"parse-json": "^4.0.0",
"path-type": "^4.0.0"
"path-type": "^4.0.0",
"yaml": "^1.7.2"
},
"devDependencies": {
"@babel/cli": "7.4.4",
Expand Down
4 changes: 2 additions & 2 deletions src/loaders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import parseJson from 'parse-json';
import yaml from 'js-yaml';
import yaml from 'yaml';
import importFresh from 'import-fresh';
import { LoaderSync } from './index';
import { LoadersSync } from './types';
Expand All @@ -19,7 +19,7 @@ const loadJson: LoaderSync = function loadJson(filepath, content) {
};

const loadYaml: LoaderSync = function loadYaml(filepath, content) {
return yaml.safeLoad(content, { filename: filepath });
return yaml.parse(content, { prettyErrors: true });
};

const loaders: LoadersSync = { loadJs, loadJson, loadYaml };
Expand Down
4 changes: 2 additions & 2 deletions test/failed-directories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('throws error for invalid YAML in rc file', () => {
const explorerOptions = { stopDir: temp.absolutePath('a') };

const expectedError =
'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line';
'Nested mappings are not allowed in compact mappings at line 1, column 8:';

test('async', async () => {
await expect(
Expand Down Expand Up @@ -250,7 +250,7 @@ describe('throws error for invalid YAML in .foorc.yml', () => {
};

const expectedError =
'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line';
'Nested mappings are not allowed in compact mappings at line 1, column 8:';

test('async', async () => {
await expect(
Expand Down
2 changes: 1 addition & 1 deletion test/failed-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('throws error if defined YAML file has syntax error', () => {

const file = temp.absolutePath('foo-invalid.yaml');
const expectedError =
'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line in';
'Nested mappings are not allowed in compact mappings at line 1, column 6:';

test('async', async () => {
await expect(cosmiconfig('failed-files-tests').load(file)).rejects.toThrow(
Expand Down
19 changes: 14 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,13 @@
dependencies:
regenerator-runtime "^0.13.2"

"@babel/runtime@^7.6.3":
version "7.6.3"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.6.3.tgz#935122c74c73d2240cafd32ddb5fc2a6cd35cf1f"
integrity sha512-kq6anf9JGjW8Nt5rYfEuGRaEAaH1mkv3Bbu6rYvLOpPh/RusSJXuKPEAoZ7L7gybZkchE8+NV5g9vKF4AGAtsA==
dependencies:
regenerator-runtime "^0.13.2"

"@babel/template@^7.1.0", "@babel/template@^7.4.0", "@babel/template@^7.4.4", "@babel/template@^7.6.0":
version "7.6.0"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.6.0.tgz#7f0159c7f5012230dad64cca42ec9bdb5c9536e6"
Expand Down Expand Up @@ -940,11 +947,6 @@
dependencies:
"@types/jest-diff" "*"

"@types/js-yaml@3.12.1":
version "3.12.1"
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.12.1.tgz#5c6f4a1eabca84792fbd916f0cb40847f123c656"
integrity sha512-SGGAhXLHDx+PK4YLNcNGa6goPf9XRWQNAUUbffkwVGGXIxmDKWyGGL4inzq2sPmExu431Ekb9aEMn9BkPqEYFA==

"@types/minimatch@*":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
Expand Down Expand Up @@ -6477,6 +6479,13 @@ yallist@^3.0.0, yallist@^3.0.3:
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd"
integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==

yaml@^1.7.2:
version "1.7.2"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.7.2.tgz#f26aabf738590ab61efaca502358e48dc9f348b2"
integrity sha512-qXROVp90sb83XtAoqE8bP9RwAkTTZbugRUTm5YeFCBfNRPEp2YzTeqWiz7m5OORHzEvrA/qcGS8hp/E+MMROYw==
dependencies:
"@babel/runtime" "^7.6.3"

yargs-parser@^10.0.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-10.1.0.tgz#7202265b89f7e9e9f2e5765e0fe735a905edbaa8"
Expand Down

0 comments on commit 60337c9

Please sign in to comment.