Skip to content

Commit

Permalink
Auto merge of #6452 - ember-cli:lazily-install-fs-monitor, r=rwjblue
Browse files Browse the repository at this point in the history
Lazily install fs monitor

Only install fs monitor if `process.env.BROCCOLI_VIZ`.  There's no reason to
monitor fs operations if we're not going to actually output them.
  • Loading branch information
homu committed Nov 22, 2016
2 parents 214b5c8 + 6a2ee17 commit d0c12d7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/models/builder.js
Expand Up @@ -12,15 +12,26 @@ var chalk = require('chalk');
var attemptNeverIndex = require('../utilities/attempt-never-index');
var findBuildFile = require('../utilities/find-build-file');

var FSMonitor = require('heimdalljs-fs-monitor');
var monitor = new FSMonitor();
monitor.start();

var Sync = require('tree-sync');

var signalsTrapped = false;
var buildCount = 0;

function _enableFSMonitorIfVizEnabled() {
var FSMonitor = require('heimdalljs-fs-monitor');
var monitor = new FSMonitor();
if (vizEnabled()) {
monitor.start();
}
return monitor;
}

_enableFSMonitorIfVizEnabled();

function vizEnabled() {
return !!process.env.BROCCOLI_VIZ;
}

function outputViz(count, result) {
var nodes = result.graph.__heimdall__.toJSONSubgraph();

Expand Down Expand Up @@ -216,7 +227,7 @@ module.exports = Task.extend({
})
.then(function(result) {

if (process.env.BROCCOLI_VIZ) {
if (vizEnabled()) {
outputViz(buildCount++, result);
}
return result;
Expand Down Expand Up @@ -307,3 +318,5 @@ module.exports = Task.extend({
}
}
});

module.exports._enableFSMonitorIfVizEnabled = _enableFSMonitorIfVizEnabled;
28 changes: 28 additions & 0 deletions tests/unit/models/builder-test.js
Expand Up @@ -21,6 +21,34 @@ var tmproot = path.join(root, 'tmp');
describe('models/builder.js', function() {
var addon, builder, buildResults, tmpdir;

describe('._enableFSMonitorIfVizEnabled', function() {
var originalBroccoliViz = process.env.BROCCOLI_VIZ;

afterEach(function() {
delete process.env.BROCCOLI_VIZ;
});

it('if VIZ is enabled, monitor', function() {
process.env.BROCCOLI_VIZ = '1';
var monitor = Builder._enableFSMonitorIfVizEnabled();
try {
expect(monitor.state).to.eql('active');
} finally {
monitor.stop();
}
});

it('if VIZ is NOT enabled, monitor', function() {
var monitor = Builder._enableFSMonitorIfVizEnabled();
try {
expect(monitor.state).to.eql('idle');
} finally {
monitor.stop();
}
});

});

describe('Windows CTRL + C Capture', function() {
var originalPlatform, originalStdin;

Expand Down

0 comments on commit d0c12d7

Please sign in to comment.