Skip to content

Commit

Permalink
Fixes jdan#113. debug('name') should only be called once in a module.
Browse files Browse the repository at this point in the history
  • Loading branch information
natelaws committed Apr 19, 2015
1 parent 00d4243 commit 63ddb0d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var https = require('https');
var fs = require('fs');
var path = require('path');
var normalizePath;
var debugInited = false;


/**
Expand Down Expand Up @@ -260,10 +261,13 @@ module.exports = function (inputPath, shouldDebug) {
// variable, and manually invoke `debug.enable()`.
// This is messy because typically debug would be called with `helper` in
// the require line, but after that point we lose access to `.enable()`.
if (shouldDebug) {
debug.enable('*');
if (!debugInited) {
if (shouldDebug) {
debug.enable('*');
}
debug = debug('helper');
debugInited = true;
}
debug = debug('helper');

// TODO: I bet we can simply all this nonsense with a chdir()
normalizePath = function (pathname) {
Expand Down
10 changes: 7 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var mustache = require('mustache');

var clone = require('./clone');
var helper;
var debugInited = false;


/**
Expand All @@ -25,10 +26,13 @@ function Cleaver(document, options, includePath) {
this.options = clone(options) || {};
this.path = path.resolve(includePath || '.');

if (this.options.debug) {
debug.enable('*');
if (!debugInited) {
if (this.options.debug) {
debug.enable('*');
}
debug = debug('cleaver');
debugInited = true;
}
debug = debug('cleaver');

/**
* Require helper using `this.path` as a context for where to locate any
Expand Down

0 comments on commit 63ddb0d

Please sign in to comment.