Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions bin/lb-ng.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var SG = require('strong-globalize');
SG.SetRootDir(path.resolve(__dirname, '..'));
var g = SG();
var fs = require('fs');
var Promise = require('bluebird');
var semver = require('semver');
var optimist = require('optimist');
var generator = require('loopback-sdk-angular');
Expand Down Expand Up @@ -55,9 +56,13 @@ function runGenerator() {
// used to have a bug where it prevented the application from exiting.
// To work around that issue, we are explicitly exiting here.
//
// The exit is deferred to the next tick in order to prevent the Node bug:
// The exit is deferred to both stdout and err is drained
// in order to prevent the Node bug:
// https://github.com/joyent/node/issues/3584
process.nextTick(function() {
Promise.all([
waitForEvent(process.stdout, 'drain'),
waitForEvent(process.stderr, 'drain')
]).then(function() {
process.exit();
});
}
Expand All @@ -79,3 +84,10 @@ function assertLoopBackVersion() {
process.exit(1);
}
}

function waitForEvent(obj, name) {
return new Promise(function(resolve, reject) {
obj.once(name, resolve);
obj.once('error', reject);
});
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"node": ">= 0.8.0"
},
"dependencies": {
"bluebird": "^1.2.4",
"loopback-sdk-angular": "^1.1.1",
"optimist": "^0.6.1",
"semver": "^2.2.1",
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
var loopback = require('loopback');
var app = loopback();

// model creation is added so output has enough content to reproduce
// issue where node v6 to chunk output of child_process and
// nextTick exit before finish writing (see PR #45)
app.dataSource('db', { connector: 'memory' });
var User = loopback.createModel('User');
app.model(User, { dataSource: 'db' });

@davidcheung davidcheung Jul 15, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add something to the app template so my stdout buffer is long enough to have this error, open to suggestions of alternative ways to achieve this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine. Can you please add a comment explaining that this is needed in order to have the script long enough to trigger output truncation?

app.set('restApiRoot', '/rest-api-root');

module.exports = app;
7 changes: 7 additions & 0 deletions test/lb-ng.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ describe('lb-ng', function() {
});
});

it('does not truncate the output', function() {
return runLbNg(sampleAppJs)
.spread(function(script, stderr) {
expect(script).to.match(/\}\)\(window, window.angular\);/);
});
});

//-- Helpers --

function runLbNg() {
Expand Down