Comparing version 2.2.1 to 2.2.2
10
index.js
@@ -133,3 +133,3 @@ var os = require('os'), | ||
API.middleware = function (opts) { | ||
// -- Set some sane defaults | ||
@@ -143,4 +143,4 @@ opts = opts || {}; | ||
var glue = new API() | ||
.include(opts.include) // Use API function to define | ||
.basepath(opts.basepath) // Use API function to define | ||
.include(opts.include) // Use API function to define | ||
.basepath(opts.basepath); // Use API function to define | ||
@@ -151,3 +151,3 @@ // -- All other options are set by clobbering the glue.options hash | ||
}); | ||
// -- Middleware to return | ||
@@ -164,3 +164,3 @@ return function (req, res, next) { | ||
glue.render(res); | ||
} | ||
}; | ||
}; | ||
@@ -167,0 +167,0 @@ |
@@ -12,8 +12,13 @@ var spawn = require('child_process').spawn; | ||
// 1) not whitespace, not quote followed by not whitespace OR | ||
// 2) double quote followed by not double quote or escaped double quote followed by double quote OR | ||
// 3) single quote followed by not single quote or escaped single quote followed by single quote | ||
options.task = options.task.match(/([^ \t\r\n"'][^ \t\r\n]*)|"(?:[\]["]|[^"])+"|'(?:[\][']|[^'])+'/g); | ||
// 2) double quote followed by not double quote or escaped double quote followed by double OR | ||
// 3) single quote followed by not single quote or escaped single quote followed by single | ||
options.task = options.task.match( | ||
/([^ \t\r\n"'][^ \t\r\n]*)|"(?:[\]["]|[^"])+"|'(?:[\][']|[^'])+'/g | ||
); | ||
// since we're using uv_spawn which calls out to exec(3), we need to exclude the beginning quotes | ||
options.task = options.task.map(function(i, index) { | ||
if(index > 0 && i.charAt(0) == i.charAt(i.length-1) && (i.charAt(0) == '"' || i.charAt(0) == "'")) { | ||
if (index > 0 && | ||
i.charAt(0) == i.charAt(i.length-1) && | ||
(i.charAt(0) == '"' || i.charAt(0) == "'") | ||
) { | ||
return i.substring(1, i.length-1); | ||
@@ -32,3 +37,4 @@ } | ||
console.log(''); | ||
console.log('spawn-task: "' +options.task.join(' ')+ '" on "'+ options.name+ '" exited with nonzero exit code: '+ code); | ||
console.log('spawn-task: "' + options.task.join(' ') + '" on "' + | ||
options.name+ '" exited with nonzero exit code: '+ code); | ||
task.emit('error', new Error('Child process exited with nonzero exit code: '+ code)); | ||
@@ -35,0 +41,0 @@ } |
@@ -32,3 +32,3 @@ var Transform = require('readable-stream').Transform; | ||
} else { | ||
this.push(this.buffer.trim() + ';}'); | ||
this.push(this.buffer.trim() + ';\n}'); | ||
} | ||
@@ -35,0 +35,0 @@ done(); |
// This task calculates the longest common substring among the file paths | ||
function check(obj) { | ||
return (obj.name.charAt(index) == first.name.charAt(index)); | ||
} | ||
module.exports = function(list) { | ||
@@ -8,5 +13,3 @@ var index = 0, | ||
while(list.files.every(function(obj) { | ||
return (obj.name.charAt(index) == first.name.charAt(index)); | ||
}) && index < first.name.length) { | ||
while(list.files.every(check) && index < first.name.length) { | ||
index++; | ||
@@ -13,0 +16,0 @@ } |
@@ -83,7 +83,2 @@ var fs = require('fs'), | ||
function getPackage(root, currentPath, packageIndex) { | ||
var relPath = currentPath; | ||
// relative path excludes the package basepath for the current package | ||
if(packages[packageIndex].basepath) { | ||
relPath = currentPath.substr(packages[packageIndex].basepath.length); | ||
} | ||
// handle files | ||
@@ -110,3 +105,3 @@ if(root['.']) { | ||
mainFile = path.basename(file.name); | ||
packageName = mainFile.replace(/(\.js|\.json)$/, ''), | ||
packageName = mainFile.replace(/(\.js|\.json)$/, ''); | ||
packageBase = path.dirname(file.name) + '/'; | ||
@@ -174,3 +169,5 @@ index = packages.length; | ||
// console.log(require('util').inspect(list.packages, null, 5, true), require('util').inspect(packages, null, 5, true)); | ||
// var util = require('util'); | ||
// console.log(util.inspect(list.packages, null, 5, true), | ||
// util.inspect(packages, null, 5, true)); | ||
@@ -177,0 +174,0 @@ list.packages = packages; |
@@ -12,3 +12,6 @@ var fs = require('fs'), | ||
function next() { | ||
var last = runner({ stdout: fs.createReadStream(list.files[current].name) }, [ require('../file-tasks/wrap-commonjs-web.js')]); | ||
var last = runner( | ||
{ stdout: fs.createReadStream(list.files[current].name) }, | ||
[ require('../file-tasks/wrap-commonjs-web.js')] | ||
); | ||
last.stdout.on('end', function() { | ||
@@ -15,0 +18,0 @@ if(current == list.files.length){ |
@@ -31,7 +31,8 @@ var fs = require('fs'), | ||
replaced = Object.keys(options.replaced || {}).map(function(key) { | ||
return JSON.stringify(key) + ': '+ '{ exports: ' + options.replaced[key] + ' }' | ||
return JSON.stringify(key) + ': '+ '{ exports: ' + options.replaced[key] + ' }'; | ||
}).join(',\n'), | ||
// remapped modules (e.g. assert => require('chai').assert | ||
remapped = Object.keys(options.remap || {}).map(function(key) { | ||
return JSON.stringify(key) + ': '+ 'function(module, exports, require) { module.exports = ' + options.remap[key] + ' }'; | ||
return JSON.stringify(key) + ': '+ | ||
'function(module, exports, require) { module.exports = ' + options.remap[key] + ' }'; | ||
}).join(',\n'), | ||
@@ -45,3 +46,3 @@ // commands | ||
// console.log(util.inspect(list.files.map(function(item) { return item.name; }), false, 20, true)); | ||
// console.log(util.inspect(list.files.map(function(i) { return i.name; }), false, 20, true)); | ||
@@ -67,3 +68,4 @@ // exclude files using the npmjs defaults for file and path exclusions | ||
excludeList = excludeList.concat( | ||
(Array.isArray(options['exclude']) ? options['exclude'] : [ options['exclude'] ]).map(function(expr) { | ||
(Array.isArray(options['exclude']) ? options['exclude'] : [ options['exclude'] ]) | ||
.map(function(expr) { | ||
return new RegExp(expr); | ||
@@ -80,3 +82,4 @@ }) | ||
// - generate `.packages` from `.files` (by grouping the set of `.files` into distinct dependencies) | ||
// - generate `.packages` from `.files` | ||
// (by grouping the set of `.files` into distinct dependencies) | ||
// ... and infer the package main file | ||
@@ -148,13 +151,39 @@ inferPackages(list, { main: options.main, basepath: basepath }); | ||
} | ||
// store dependency references | ||
Object.keys(packageObj.dependenciesById).forEach(function(name) { | ||
var uid = packageObj.dependenciesById[name], | ||
index; | ||
// find the package in the (possibly altered) packages list by unique id | ||
list.packages.some(function(item, itemIndex) { | ||
var match = (item.uid == uid); | ||
if(match) { | ||
index = itemIndex; | ||
} | ||
return match; | ||
}); | ||
// require.m[n]['foo'] = { c: 1, m: 'lib/index.js' } | ||
out.write( | ||
JSON.stringify(name) + ': ' + JSON.stringify({ | ||
c: index, | ||
m: list.packages[index].main | ||
})); | ||
out.write(',\n'); | ||
}); | ||
done(); | ||
}); | ||
// stream each file in serial order | ||
// Also does filtering: if no tasks match, a file is excluded | ||
packageObj.files = packageObj.files.filter(function(item, innerCurrent) { | ||
var fullpath = item.name, | ||
relname = path.relative(packageObj.basepath, item.name), | ||
tasks = getFileTasks(item, packageObj, commands); | ||
if(tasks.length == 0) { | ||
log.info('Excluded non-js/non-json file:', relname); | ||
// filter files (and generate tasks) | ||
packageObj.files = packageObj.files.filter(function(item) { | ||
if(!fs.existsSync(item.name)) { | ||
throw new Error('File not found: ' + item.name + ' Basepath = "' + | ||
packageObj.basepath + '", filename="' + item.name + '"'); | ||
} | ||
item.tasks = getFileTasks(item, packageObj, commands); | ||
if(item.tasks.length === 0) { | ||
log.info('Excluded non-js/non-json file:', path.relative(packageObj.basepath, item.name)); | ||
// also update list.files | ||
@@ -164,3 +193,11 @@ removed.push(item.name); | ||
} | ||
return true; // do not filter out this file | ||
}); | ||
// stream each file in serial order | ||
var totalFiles = packageObj.files.length; | ||
packageObj.files.forEach(function(item, index) { | ||
var fullpath = item.name, | ||
relname = path.relative(packageObj.basepath, item.name); | ||
// all dependencies already have a basepath and the names are | ||
@@ -172,7 +209,2 @@ // already relative to it, but this is not true for the main package | ||
if(!fs.existsSync(fullpath)) { | ||
throw new Error('File not found: '+fullpath+' Basepath = "' + | ||
packageObj.basepath+'", filename="' + relname +'"'); | ||
} | ||
// add the first task | ||
@@ -185,3 +217,3 @@ packageTasks.push( | ||
var flow = new Flow(tasks).input(fs.createReadStream(fullpath)); | ||
var flow = new Flow(item.tasks).input(fs.createReadStream(fullpath)); | ||
@@ -211,7 +243,11 @@ // these are used to disambiguate cached results | ||
function(out, done) { | ||
out.write(',\n'); | ||
// determining when to write the last common becomes easy | ||
// when files are processed last | ||
if(index == totalFiles - 1) { | ||
out.write('\n'); | ||
} else { | ||
out.write(',\n'); | ||
} | ||
done(); | ||
}); | ||
return true; // do not filter out this file | ||
}); | ||
@@ -221,26 +257,2 @@ | ||
packageTasks.push(function(out, done) { | ||
// store dependency references | ||
Object.keys(packageObj.dependenciesById).forEach(function(name) { | ||
var uid = packageObj.dependenciesById[name], | ||
index; | ||
// find the package in the (possibly altered) packages list by unique id | ||
list.packages.some(function(item, itemIndex) { | ||
var match = (item.uid == uid); | ||
if(match) { | ||
index = itemIndex; | ||
} | ||
return match; | ||
}); | ||
// require.m[n]['foo'] = { c: 1, m: 'lib/index.js' } | ||
out.write( | ||
JSON.stringify(name) + ': ' + JSON.stringify({ | ||
c: index, | ||
m: list.packages[index].main | ||
})); | ||
out.write(',\n'); | ||
}); | ||
out.write('};\n'); | ||
@@ -263,3 +275,4 @@ done(); | ||
out.write('if (typeof define === "function" && define.amd) {'); | ||
out.write('define('+JSON.stringify(exportVariableName)+', function() { return require(\'' + packageRootFileName + '\'); });\n'); | ||
out.write('define(' + JSON.stringify(exportVariableName) + | ||
', function() { return require(\'' + packageRootFileName + '\'); });\n'); | ||
out.write('}\n'); | ||
@@ -288,3 +301,4 @@ } | ||
if(cacheHits.length > 0) { | ||
console.log('Cache hits (' + options['cache-path'] + '):', cacheHits.length, '/', list.files.length, 'files'); | ||
console.log('Cache hits (' + options['cache-path'] + '):', | ||
cacheHits.length, '/', list.files.length, 'files'); | ||
// exclude cached files | ||
@@ -330,3 +344,5 @@ list.packages.forEach(function(pack, index) { | ||
onDone: function() { | ||
onDone && onDone(); | ||
if(typeof onDone === 'function') { | ||
onDone(); | ||
} | ||
} | ||
@@ -333,0 +349,0 @@ }); |
@@ -15,4 +15,6 @@ /*! | ||
require = function(p, context, parent){ | ||
context || (context = 0); | ||
require = function(p, context, parent) { | ||
if(!context) { | ||
context = 0; | ||
} | ||
var path = require.resolve(p, context), | ||
@@ -40,3 +42,3 @@ mod = require.m[context][path]; | ||
return mod.exports; | ||
} | ||
}; | ||
@@ -51,3 +53,3 @@ /** | ||
require.resolve = function(path, context){ | ||
require.resolve = function(path, context) { | ||
var orig = path, | ||
@@ -73,4 +75,3 @@ reg = path + '.js', | ||
var path = relativeTo.split('/') | ||
, segs = p.split('/'); | ||
var path = relativeTo.split('/'), segs = p.split('/'); | ||
path.pop(); | ||
@@ -77,0 +78,0 @@ |
{ | ||
"name": "gluejs", | ||
"description": "Build CommonJS modules for the browser via a chainable API", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Mikito Takada", |
Sorry, the diff of this file is not supported yet
91203
39
1594