Comparing version 2.3.5 to 2.3.6
56
index.js
@@ -8,3 +8,4 @@ var os = require('os'), | ||
Minilog = require('minilog'), | ||
Cache = require('minitask').Cache; | ||
Cache = require('minitask').Cache, | ||
log = require('minilog')('api'); | ||
@@ -22,3 +23,6 @@ var homePath = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']; | ||
'cache-path': homePath + path.sep + '.gluejs-cache' + path.sep, | ||
include: [] | ||
include: [], | ||
_rename: {}, | ||
// set options here so that the cache hash does not change | ||
jobs: require('os').cpus().length * 2 | ||
}; | ||
@@ -73,29 +77,36 @@ } | ||
}); | ||
list.onRename = function(canonical, normalized) { | ||
self.options._rename[normalized] = canonical; | ||
}; | ||
// END LIST | ||
if(typeof dest == 'function') { | ||
var capture = new Capture(); | ||
// console.time('list enum'); | ||
capture.on('error', function(err) { | ||
console.error('Error in the capture stream: ', err); | ||
console.trace(); | ||
}); | ||
list.exec(function(err, files) { | ||
capture.once('finish', function() { | ||
dest(null, capture.get()); | ||
}); | ||
// console.timeEnd('list enum'); | ||
list.exec(function(err, files) { | ||
packageCommonJs({ files: files }, self.options, capture, function() { | ||
cache.end(); | ||
var capture; | ||
if(typeof dest == 'function') { | ||
capture = new Capture(); | ||
capture.on('error', function(err) { | ||
console.error('Error in the capture stream: ', err); | ||
console.trace(); | ||
}); | ||
}); | ||
} else if(dest.write) { | ||
// writable stream | ||
list.exec(function(err, files) { | ||
packageCommonJs({ files: files }, self.options, dest, function() { | ||
cache.end(); | ||
capture.once('finish', function() { | ||
dest(null, capture.get()); | ||
}); | ||
} | ||
// console.time('package files'); | ||
packageCommonJs({ files: files }, self.options, capture ? capture : dest, function() { | ||
// console.timeEnd('package files'); | ||
cache.end(); | ||
}); | ||
} | ||
}); | ||
}; | ||
@@ -109,2 +120,5 @@ | ||
} | ||
if(key == 'jobs') { | ||
log.info('Maximum number of parallel tasks:', this.options.jobs); | ||
} | ||
return this; | ||
@@ -111,0 +125,0 @@ }; |
@@ -44,3 +44,4 @@ var Transform = require('readable-stream').Transform; | ||
} | ||
this.push('}'); | ||
// newline here is important as the last line may be a unterminated comment | ||
this.push('\n}'); | ||
done(); | ||
@@ -47,0 +48,0 @@ }; |
@@ -5,2 +5,3 @@ var fs = require('fs'), | ||
resolve = require('browser-resolve'), | ||
nodeResolve = require('resolve'), | ||
List = require('minitask').list, | ||
@@ -20,3 +21,5 @@ Cache = require('minitask').Cache, | ||
var key = opts['cache-hash'] + '-dependencies', | ||
var depKey = opts['cache-hash'] + '-dependencies', | ||
resultKey = opts['cache-hash'] + '-dependencies-norm', | ||
renameKey = opts['cache-hash'] + '-dependencies-rename', | ||
noCache = false; // for easy dev | ||
@@ -31,9 +34,20 @@ | ||
} | ||
// cache the whole operation! | ||
var result = cache.file(filepath).data(resultKey); | ||
if (!noCache && Array.isArray(result)) { | ||
// console.log('using cached result', filepath, result); | ||
var renames = cache.file(filepath).data(renameKey); | ||
if(renames && Array.isArray(renames)) { | ||
self.onRename(renames[0], renames[1]); | ||
} | ||
return onDone(null, result); | ||
} | ||
var deps; | ||
log.info('Parsing:', filepath); | ||
log.info('Parsing:', filepath, result); | ||
// check the cache | ||
deps = cache.file(filepath).data(key); | ||
deps = cache.file(filepath).data(depKey); | ||
if (noCache || typeof deps === 'undefined') { | ||
@@ -44,7 +58,7 @@ try { | ||
console.log('parse error: ', filepath, e); | ||
cache.file(filepath).data(key, []); | ||
cache.file(filepath).data(depKey, []); | ||
return []; | ||
} | ||
// store result | ||
cache.file(filepath).data(key, deps); | ||
cache.file(filepath).data(depKey, deps); | ||
} else { | ||
@@ -57,9 +71,12 @@ // console.log('using cached result', filepath, deps); | ||
if(!deps || deps.length === 0) { | ||
// store result | ||
cache.file(filepath).data(resultKey, []); | ||
return onDone(null, []); | ||
} | ||
var queue = [], | ||
expected = deps.length, | ||
var expected = deps.length, | ||
complete = 0; | ||
result = []; | ||
// return deps.filter(function(dep) { | ||
@@ -73,12 +90,29 @@ // return !resolve.isCore(dep); | ||
if(err) { | ||
// console.log('resolve error: ', err, dep, filepath); | ||
// console.log('resolve error: ', err, dep, filepath, result); | ||
self._resolveErrors.push({ err: err, dep: dep, filepath: filepath }); | ||
if(complete == expected) { | ||
// store result | ||
cache.file(filepath).data(resultKey, result); | ||
return onDone(null, result); | ||
} | ||
return; | ||
} | ||
// browser-resolve may replace specific files with different names | ||
if(self.onRename) { | ||
var canonical = nodeResolve.sync(dep, { basedir: path.dirname(filepath) }); | ||
if(canonical != normalized) { | ||
self.onRename(canonical, normalized); | ||
cache.file(filepath).data(renameKey, [ canonical, normalized ]); | ||
} | ||
} | ||
// console.log('RESOLVE', normalized); | ||
queue.push(path.normalize(normalized)); | ||
result.push(path.normalize(normalized)); | ||
if(complete == expected) { | ||
return onDone(null, queue); | ||
// store result | ||
cache.file(filepath).data(resultKey, result); | ||
return onDone(null, result); | ||
} | ||
@@ -85,0 +119,0 @@ }); |
@@ -59,3 +59,3 @@ var fs = require('fs'), | ||
hasExclamationMark = plugin.length > 1; | ||
if (hasExclamationMark && plugin[0] && vendorPaths[name]) { | ||
if (hasExclamationMark && plugin[0]) { | ||
var pluginName = plugin[0], | ||
@@ -65,2 +65,10 @@ pluginPath = vendorPaths[name]; | ||
if (opts.plugins && opts.plugins[pluginName]) { | ||
if(opts.plugins[pluginName].load) { | ||
vendorPaths[name] = pluginPath = opts.plugins[pluginName].load(name); | ||
console.log(name, vendorPaths[name]); | ||
} | ||
// can return false from the load() resolution to skip | ||
if (!vendorPaths[name]) { | ||
return; | ||
} | ||
vendorComplete[name] = opts.plugins[pluginName](name, pluginPath); | ||
@@ -67,0 +75,0 @@ return; |
@@ -197,9 +197,16 @@ var fs = require('fs'), | ||
packageObj.files.forEach(function(item, index) { | ||
var fullpath = item.name, | ||
relname = path.relative(packageObj.basepath, item.name); | ||
var exportVariableName = options['export'] || 'App', | ||
filePath = item.name, | ||
relativeName = path.relative(packageObj.basepath, filePath), | ||
moduleName = relativeName; | ||
// check for renames via options._rename | ||
if(options._rename[filePath]) { | ||
moduleName = path.relative(packageObj.basepath, options._rename[filePath]); | ||
} | ||
// all dependencies already have a basepath and the names are | ||
// already relative to it, but this is not true for the main package | ||
if(current === 0 && relname.substr(0, basepath.length) == basepath) { | ||
relname = relname.substr(basepath.length); | ||
if(current === 0 && moduleName.substr(0, basepath.length) == basepath) { | ||
moduleName = moduleName.substr(basepath.length); | ||
} | ||
@@ -210,3 +217,3 @@ | ||
function(out, done) { | ||
out.write(JSON.stringify(relname) + ': '); | ||
out.write(JSON.stringify(moduleName) + ': '); | ||
done(); | ||
@@ -216,10 +223,10 @@ }); | ||
// wrap in a function to reduce file handle usage | ||
var task = new Task(item.tasks).input(function() { return fs.createReadStream(fullpath); } ); | ||
var task = new Task(item.tasks).input(function() { return fs.createReadStream(filePath); } ); | ||
// these are used to disambiguate cached results | ||
task.inputFilePath = fullpath; | ||
task.inputFilePath = filePath; | ||
task.taskHash = optsHash; | ||
task.once('hit', function() { | ||
cacheHits.push(fullpath); | ||
cacheHits.push(filePath); | ||
if(options.progress) { | ||
@@ -234,3 +241,3 @@ progress.tick(); | ||
} else { | ||
log.info(' Processing file', fullpath); | ||
log.info(' Processing file', filePath); | ||
} | ||
@@ -292,8 +299,2 @@ }); | ||
if(options.jobs) { | ||
log.info('Maximum number of parallel tasks:', options.jobs); | ||
} else { | ||
options.jobs = require('os').cpus().length * 2; | ||
} | ||
// update files by removing files in removed | ||
@@ -300,0 +301,0 @@ list.files = list.files.filter(function(obj) { |
{ | ||
"name": "gluejs", | ||
"description": "Build CommonJS modules for the browser via a chainable API", | ||
"version": "2.3.5", | ||
"version": "2.3.6", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Mikito Takada", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
357456
52
2231