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
feat(config): support TOML configuration files #4877
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a0231f6
Add initial support for TOML in configuration files
jorgegonzalez ace7496
Merge branch 'master' into master
jorgegonzalez 199c36a
Missed brace
jorgegonzalez 49aa533
Fix snapshots
jorgegonzalez 1c9e2b2
refactor: move loadToml to utils
jorgegonzalez 99b9ccd
Use @iarna/toml
jorgegonzalez 7dfe0b3
Add tests for loadToml
jorgegonzalez 6a0cda3
Fix test for CI
jorgegonzalez 3a7d0a6
Remove jest-extended
jorgegonzalez 8e88fb1
Create snapshot for load-toml
jorgegonzalez c8e30f8
Add feat to docs
jorgegonzalez c293380
lint docs
jorgegonzalez f55cf61
Use @iarna/toml/parse-string
jorgegonzalez 34b1f7c
Change path string
jorgegonzalez File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"use strict"; | ||
|
||
const toml = require("@iarna/toml"); | ||
|
||
module.exports = function(filePath, content) { | ||
try { | ||
return toml.parse(content); | ||
} catch (error) { | ||
error.message = `TOML Error in ${filePath}:\n${error.message}`; | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tests_integration/__tests__/__snapshots__/load-toml.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`TOML loads toml successfully 1`] = ` | ||
Object { | ||
"database": Object { | ||
"connection_max": 5000, | ||
"enabled": true, | ||
"ports": Array [ | ||
8001, | ||
8001, | ||
8002, | ||
], | ||
"server": "192.168.1.1", | ||
Symbol(type): Symbol(table), | ||
Symbol(declared): true, | ||
}, | ||
"owner": Object { | ||
"dob": 1979-05-27T15:32:00.000Z, | ||
"name": "Tom Preston-Werner", | ||
Symbol(type): Symbol(table), | ||
Symbol(declared): true, | ||
}, | ||
"title": "TOML Example", | ||
Symbol(type): Symbol(table), | ||
Symbol(declared): false, | ||
} | ||
`; | ||
|
||
exports[`TOML throws error on incorrect toml 1`] = ` | ||
"TOML Error in load-toml.js: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
Unknown character \\"47\\" at row 1, col 2, pos 1: | ||
1> ///ERROR/// | ||
^ | ||
|
||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"use strict"; | ||
|
||
const loadToml = require("../../src/utils/load-toml"); | ||
|
||
describe("TOML", () => { | ||
const currentFile = "load-toml.js"; | ||
|
||
const exampleToml = ` | ||
# This is a TOML document. | ||
title = "TOML Example" | ||
[owner] | ||
name = "Tom Preston-Werner" | ||
dob = 1979-05-27T07:32:00-08:00 # First class dates | ||
[database] | ||
server = "192.168.1.1" | ||
ports = [ 8001, 8001, 8002 ] | ||
connection_max = 5000 | ||
enabled = true | ||
`; | ||
|
||
const wrongToml = "///ERROR///"; | ||
|
||
test("loads toml successfully", () => { | ||
const parsedToml = loadToml(currentFile, exampleToml); | ||
expect(parsedToml).toMatchSnapshot(); | ||
}); | ||
|
||
test("throws error on incorrect toml", () => { | ||
expect(() => { | ||
loadToml(currentFile, wrongToml); | ||
}).toThrow(); | ||
|
||
expect(() => { | ||
loadToml(currentFile, wrongToml); | ||
}).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
trailingComma = "all" | ||
singleQuote = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function rcToml() { | ||
console.log.apply(null, [ | ||
"rc-toml/file.js", | ||
"should have trailing comma", | ||
"and single quotes" | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use
@iarna/toml/parse-string
to further reduce the bundle size.