Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the Visionmedia YAML parser as fallback for backwards compatibi…

…lity.
  • Loading branch information...
commit 8696be2b08d289798f6d565aae12ece402f9cd00 1 parent d956545
@enyo enyo authored
Showing with 24 additions and 5 deletions.
  1. +23 −4 lib/config.js
  2. +1 −1  test/config/runtime.json
View
27 lib/config.js
@@ -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
@@ -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
View
2  test/config/runtime.json
@@ -5,5 +5,5 @@
"Customers": {
"dbName": "override_from_runtime_json"
},
- "watchThisValue": 92843
+ "watchThisValue": 57713
}
Please sign in to comment.
Something went wrong with that request. Please try again.