Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error checking on build. #163

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var fs = require('fs')
, utils = require('./utils')
, dirname = path.dirname
, basename = path.basename
, strtojs = require('string-to-js');
, strtojs = require('string-to-js')
, syntaxError = require('syntax-error');

/**
* Expose `Builder`.
Expand Down Expand Up @@ -658,15 +659,21 @@ Builder.prototype.buildType = function(type, fn, process){
// build files
if (conf[type]) {
conf[type].forEach(function(file){
var path = self.path(file);
var filepath = self.path(file);
batch.push(function(done){
var val = self._files[file];

// on disk
if (null == val) {
debug('read file %s', path);
fs.readFile(path, 'utf8', function(err, str){
debug('read file %s', filepath);
fs.readFile(filepath, 'utf8', function(err, str){
if (err) return fn(err);
if (path.extname(filepath) === '.js') {
err = syntaxError(str, filepath);
if (err) {
return fn(new Error('' + err));
}
}
done(null, process(self, file, str));
});
return
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"debug": "*",
"better-assert": "~0.1.0",
"cp": "~0.1.0",
"string-to-js": "0.0.1"
"string-to-js": "0.0.1",
"syntax-error": "~0.1.0"
},
"devDependencies": {
"mocha": "*",
Expand Down
12 changes: 10 additions & 2 deletions test/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Builder', function(){
var builder = new Builder('test/fixtures/hello');
builder.addLookup('test/fixtures');
builder.on('dependency', function(builder){
builder.dir.should.be.a('string');
builder.dir.should.be.an.instanceof(String);
builder.basename.should.equal('component-emitter');
done();
});
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('Builder', function(){
var builder = new Builder('test/fixtures/hello');
builder.addLookup('test/fixtures');
builder.on('dependency', function(builder){
builder.dir.should.be.a('string');
builder.dir.should.be.an.instanceof(String);
builder.basename.should.equal('component-emitter');
done();
});
Expand Down Expand Up @@ -444,4 +444,12 @@ describe('Builder', function(){
done();
})
})

it('should catch syntax error', function(done){
var builder = new Builder('test/fixtures/syntax-error');
builder.build(function(err){
err.message.should.include('ParseError: Unexpected identifier')
done()
})
})
})
7 changes: 7 additions & 0 deletions test/fixtures/syntax-error/component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "syntax-error",
"main": "index.js",
"scripts": [
"index.js"
]
}
1 change: 1 addition & 0 deletions test/fixtures/syntax-error/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abc def()