Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 82c76ed

Browse files
committed
Fix the circular reference problem in the log file, which occurred when
the Handlebars engine was in use.
1 parent 8ac9b6e commit 82c76ed

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

builder/patternlab.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,21 @@ var patternlab_engine = function () {
4747
}
4848

4949
function printDebug() {
50+
// A replacer function to pass to stringify below; this is here to prevent
51+
// the debug output from blowing up into a massive fireball of circular
52+
// references. This happens specifically with the Handlebars engine. Remove
53+
// if you like 180MB log files.
54+
function propertyStringReplacer(key, value) {
55+
if (key === 'engine' && value.engineName) {
56+
return '{' + value.engineName + ' engine object}';
57+
}
58+
return value;
59+
}
60+
5061
//debug file can be written by setting flag on config.json
5162
if(patternlab.config.debug){
5263
console.log('writing patternlab debug file to ./patternlab.json');
53-
// fs.outputFileSync('./patternlab.json', JSON.stringify(patternlab, null, 3));
54-
fs.outputFileSync('./patternlab.json', util.inspect(patternlab, {
55-
depth: null
56-
}));
64+
fs.outputFileSync('./patternlab.json', JSON.stringify(patternlab, propertyStringReplacer, 3));
5765
}
5866
}
5967

0 commit comments

Comments
 (0)