Skip to content

Commit

Permalink
Added the Visionmedia YAML parser as fallback for backwards compatibi…
Browse files Browse the repository at this point in the history
…lity.
  • Loading branch information
enyo committed May 7, 2012
1 parent d956545 commit 8696be2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 23 additions & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*jsl:declare global */
// Dependencies
var Yaml = null, // External libraries are lazy-loaded
Coffee = null, // only if these file types exist.
VisionmediaYaml = null, // only if these file types exist.
Coffee = null,
FileSystem = require('fs');

// Static members
Expand Down Expand Up @@ -673,9 +674,27 @@ console.log("Writing runtime json file");
// Parse the file based on extension
try {
if (extension == 'yaml') {
// Lazy loading
Yaml = Yaml || require('js-yaml');
configObject = Yaml.load(t._stripYamlComments(fileContent));
if (!Yaml && !VisionmediaYaml) {
// Lazy loading
try {
// Try to load the better js-yaml module
Yaml = require('js-yaml');
}
catch (e) {
// If it doesn't exist, load the fallback visionmedia yaml module.
VisionmediaYaml = require('yaml');
}
}

if (Yaml) {
configObject = Yaml.load(t._stripYamlComments(fileContent));
}
else if (VisionmediaYaml) {
// The yaml library doesn't like strings that have newlines but don't
// end in a newline: https://github.com/visionmedia/js-yaml/issues/issue/13
fileContent += '\n';
configObject = VisionmediaYaml.eval(t._stripYamlComments(fileContent));
}
}
else if (extension == 'json') {
// Allow comments in JSON files
Expand Down
2 changes: 1 addition & 1 deletion test/config/runtime.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"Customers": {
"dbName": "override_from_runtime_json"
},
"watchThisValue": 92843
"watchThisValue": 57713
}

0 comments on commit 8696be2

Please sign in to comment.