component-builder
Advanced tools
Comparing version 0.10.0 to 0.11.0
0.11.0 / 2013-12-29 | ||
================== | ||
* remove require aliases. Closes #117 | ||
* make better-assert a development dependency | ||
* normalize URLs in CSS files | ||
0.10.0 / 2013-10-17 | ||
@@ -3,0 +10,0 @@ ================== |
@@ -21,2 +21,4 @@ /** | ||
, basename = path.basename | ||
, resolveURL = require('url').resolve | ||
, requires = require('requires') | ||
, strtojs = require('string-to-js'); | ||
@@ -463,3 +465,2 @@ | ||
batch.push(this.buildTemplates.bind(this)); | ||
batch.push(this.buildAliases.bind(this)); | ||
batch.push(this.buildStyles.bind(this)); | ||
@@ -475,5 +476,4 @@ batch.push(this.buildImages.bind(this)); | ||
var templates = res.shift(); | ||
var require = res.shift(); | ||
var custom = self._js; | ||
var js = [scripts, json, templates, require, custom].filter(empty).join('\n'); | ||
var js = [scripts, json, templates, custom].filter(empty).join('\n'); | ||
@@ -492,128 +492,2 @@ fn(null, { | ||
/** | ||
* Build require() aliases. | ||
* | ||
* This is necessary to allow | ||
* several components of the same | ||
* name to be used. For example "learnboost/popover" | ||
* and "visionmedia/popover" may co-exist within | ||
* an application using this technique, as they | ||
* are linked as shown here: | ||
* | ||
* ./user | ||
* ./deps | ||
* ./inherit -> component-inherit | ||
* | ||
* ./animal | ||
* ./deps | ||
* ./inherit -> component-inherit | ||
* | ||
* ./component-inherit | ||
* | ||
* ./pet-list | ||
* ./deps | ||
* ./pet -> pet | ||
* | ||
* ./user-list | ||
* ./deps | ||
* ./user -> user | ||
* | ||
* ./boot | ||
* ./deps | ||
* ./pet-list -> pets-list | ||
* ./user-list -> pets-list | ||
* | ||
* Root-level dependencies are exposed at the global | ||
* level so that users may utilize components with | ||
* script tags within other frameworks etc. | ||
* | ||
* TODO: buildScripts() should do this, so that | ||
* lazily-built components do not omit aliases. | ||
* | ||
* TODO: refactor, this is nasty | ||
* | ||
* @param {Function} fn | ||
* @api private | ||
*/ | ||
Builder.prototype.buildAliases = function(fn){ | ||
var self = this; | ||
var aliases = []; | ||
var batch = new Batch; | ||
if (self.hasDependencies()) { | ||
Object.keys(self.dependencies()).forEach(function(dep){ | ||
batch.push(function(done){ | ||
dep = normalize(dep); | ||
self.lookup(dep, function(err, dir){ | ||
if (err) return done(err); | ||
var builder = new Builder(dir, self); | ||
var conf = builder.config; | ||
self.emit('dependency', builder); | ||
if (!conf.scripts) return done(null, ''); | ||
var main = conf.main; | ||
var name = conf.name; | ||
var aliases = conf.scripts.map(function(script){ | ||
var alias = self.root | ||
? self.config.name + '/deps/' + name + '/' + script | ||
: self.basename + '/deps/' + name + '/' + script; | ||
return builder.alias(alias, script); | ||
}); | ||
if (main) { | ||
var alias = self.root | ||
? self.config.name + '/deps/' + name + '/index.js' | ||
: self.basename + '/deps/' + name + '/index.js'; | ||
aliases.push(builder.alias(alias, main)); | ||
} | ||
if (self.root) { | ||
aliases.push(builder.alias(name + '/index.js', main || 'index.js')); | ||
} | ||
aliases = aliases.join('\n'); | ||
builder.buildAliases(function(err, str){ | ||
if (err) return done(err); | ||
done(null, aliases + '\n' + str); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
batch.end(function(err, res){ | ||
if (err) return fn(err); | ||
var name = self.root | ||
? self.config.name | ||
: self.basename; | ||
if (self.config.main) { | ||
res.push(self.alias(name + '/index.js', self.config.main)); | ||
} | ||
fn(null, res.join('\n')); | ||
}); | ||
}; | ||
/** | ||
* Return an alias from script `a` to `b`. | ||
* | ||
* @param {String} a | ||
* @param {String} b | ||
* @return {String} | ||
* @api private | ||
*/ | ||
Builder.prototype.alias = function(a, b){ | ||
var name = this.root | ||
? this.config.name | ||
: this.basename; | ||
return 'require.alias("' + name + '/' + b + '", "' + a + '");'; | ||
}; | ||
/** | ||
* Build `type` and invoke `fn`. | ||
@@ -954,2 +828,9 @@ * | ||
js = requires(js, function(require){ | ||
var deps = builder.config.dependencies || {}; | ||
var path = require.path; | ||
var name = canonicalized(path, deps) || path; | ||
return 'require("' + name + '")'; | ||
}); | ||
if (builder.sourceUrls) { | ||
@@ -969,2 +850,20 @@ js = JSON.stringify(js + '//@ sourceURL=' + file); | ||
/** | ||
* Return canonical name of `dep` in `deps` | ||
* or undefined. | ||
* | ||
* @param {String} dep | ||
* @param {Object} deps | ||
* @return {String} | ||
* @api private | ||
*/ | ||
function canonicalized(dep, deps) { | ||
for (var name in deps) { | ||
if (dep == name.split('/')[1]) { | ||
return normalize(name); | ||
} | ||
} | ||
} | ||
/** | ||
* Return css with urls rewritten relative | ||
@@ -998,3 +897,6 @@ * to the `.assetDest` directory. This allows | ||
var name = normalize(builder.basename); | ||
url = [builder.urlPrefix, name, dirname(file), url].filter(empty).join('/'); | ||
// trailing `/` needed to distinguish the URL as a folder | ||
// for `url.resolve()` | ||
var folder = [builder.urlPrefix, name, dirname(file)].filter(empty).join('/') + '/'; | ||
url = resolveURL(folder, url); | ||
return 'url("' + url + '")'; | ||
@@ -1001,0 +903,0 @@ } |
{ | ||
"name": "component-builder", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "Component build tool", | ||
@@ -11,15 +11,16 @@ "keywords": [ | ||
"dependencies": { | ||
"component-require": "0.3.1", | ||
"component-require": "1.0.0", | ||
"batch": "0.2.1", | ||
"mkdirp": "0.3.4", | ||
"debug": "*", | ||
"better-assert": "~0.1.0", | ||
"cp": "~0.1.0", | ||
"string-to-js": "0.0.1" | ||
"string-to-js": "0.0.1", | ||
"requires": "~1.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*", | ||
"should": "1.x", | ||
"ejs": "~0.8.3", | ||
"styl": "0.2.2" | ||
"styl": "0.2.2", | ||
"better-assert": "~0.1.0" | ||
}, | ||
@@ -26,0 +27,0 @@ "repository": { |
@@ -76,2 +76,6 @@ # builder.js | ||
### Builder#use(fn) | ||
Give the builder a plugin to use. The `fn` args are `fn(builder [, done])`. If The plugin has async logic it should invoke the `done` callback as needed. Sync plugins should ignore this argument. | ||
## Examples | ||
@@ -78,0 +82,0 @@ |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
119
1
28048
5
816
+ Addedrequires@~1.0.0
+ Addedcomponent-require@1.0.0(transitive)
+ Addedrequires@1.0.2(transitive)
- Removedbetter-assert@~0.1.0
- Removedbetter-assert@0.1.0(transitive)
- Removedcallsite@1.0.0(transitive)
- Removedcomponent-require@0.3.1(transitive)
Updatedcomponent-require@1.0.0