Comparing version 0.1.0-alpha.4 to 0.1.0-alpha.5
{ | ||
"name": "capsule-js", | ||
"version": "0.1.0-alpha.4", | ||
"version": "0.1.0-alpha.5", | ||
"homepage": "https://github.com/justinvdm/capsule", | ||
@@ -5,0 +5,0 @@ "authors": [ |
;(function() { | ||
var root = this; | ||
var pending = capsule.pending = {}; | ||
var pending = {}; | ||
var registry = capsule.registry = {}; | ||
var cglobal = capsule.global = {capsule: capsule}; | ||
capsule.alias = alias; | ||
capsule.exists = exists; | ||
capsule.chroot = chroot; | ||
capsule.exists = exists; | ||
capsule.alias = alias; | ||
@@ -14,7 +14,6 @@ | ||
var len = arguments.length; | ||
if (len < 1) throw new Error("No module name was given"); | ||
if (len < 2) return use(name); | ||
if (v === null) clear(name); | ||
else define(name, v); | ||
v ? define(name, v) | ||
: clear(name); | ||
@@ -33,3 +32,2 @@ return capsule; | ||
delete registry[name]; | ||
delete cglobal[name]; | ||
} | ||
@@ -41,5 +39,4 @@ | ||
if (name in registry) return registry[name]; | ||
if (name in cglobal) return cglobal[name]; | ||
if (name in root) return root[name]; | ||
throw new Error("Module '" + name + "' not found"); | ||
throw new Error(name + " not found"); | ||
} | ||
@@ -50,7 +47,10 @@ | ||
var fn = pending[name]; | ||
delete pending[name]; | ||
var exports; | ||
var module = {exports: {}}; | ||
fn(module.exports, module); | ||
registry[name] = module.exports; | ||
delete pending[name]; | ||
return module.exports; | ||
fn.call(root, module.exports, module); | ||
exports = registry[name] = module.exports; | ||
return exports; | ||
} | ||
@@ -62,6 +62,6 @@ | ||
|| name in registry | ||
|| name in cglobal | ||
|| name in root; | ||
} | ||
function alias(src, dest) { | ||
@@ -80,5 +80,5 @@ return capsule(dest, function(exports, module) { | ||
if (root.rainbows) | ||
root.capsule = capsule; | ||
else if (typeof module != 'undefined') | ||
if (root.c) | ||
root.c = capsule; | ||
if (typeof module != 'undefined') | ||
module.exports = capsule; | ||
@@ -85,0 +85,0 @@ else if (typeof define == 'function' && define.amd) |
@@ -1,1 +0,1 @@ | ||
(function(){function n(o,i){var u=arguments.length;if(1>u)throw new Error("No module name was given");return 2>u?r(o):(null===i?t(o):e(o,i),n)}function e(n,e){s[n]=e}function t(n){delete s[n],delete c[n],delete a[n]}function r(n){if(n in s)return o(n);if(n in c)return c[n];if(n in a)return a[n];if(n in l)return l[n];throw new Error("Module '"+n+"' not found")}function o(n){var e=s[n],t={exports:{}};return e(t.exports,t),c[n]=t.exports,delete s[n],t.exports}function i(n){return n in s||n in c||n in a||n in l}function u(e,t){return n(t,function(t,r){r.exports=n(e)})}function f(e){return l=e,n}var l=this,s=n.pending={},c=n.registry={},a=n.global={capsule:n};n.chroot=f,n.exists=i,n.alias=u,l.rainbows?l.capsule=n:"undefined"!=typeof module?module.exports=n:"function"==typeof e&&e.amd?e(function(){return n}):l.capsule=n}).call(this); | ||
(function(){function n(i,o){var u=arguments.length;return 2>u?r(i):(o?t(i,o):e(i),n)}function t(n,t){s[n]=t}function e(n){delete s[n],delete l[n]}function r(n){if(n in s)return i(n);if(n in l)return l[n];if(n in c)return c[n];throw new Error(n+" not found")}function i(n){var t=s[n];delete s[n];var e,r={exports:{}};return t.call(c,r.exports,r),e=l[n]=r.exports}function o(n){return n in s||n in l||n in c}function u(t,e){return n(e,function(e,r){r.exports=n(t)})}function f(t){return c=t,n}var c=this,s={},l=n.registry={};n.alias=u,n.exists=o,n.chroot=f,c.c&&(c.c=n),"undefined"!=typeof module?module.exports=n:"function"==typeof t&&t.amd?t(function(){return n}):c.capsule=n}).call(this); |
@@ -1,2 +0,3 @@ | ||
(function(n){function e(n,e){for(var r,i=-1,o=n.length,u=t.registry;++i<o;)r=n[i],u[r[0]]=e(r[1])}var t=function(){return function(){function n(i,o){var u=arguments.length;if(1>u)throw new Error("No module name was given");return 2>u?r(i):(null===o?t(i):e(i,o),n)}function e(n,e){l[n]=e}function t(n){delete l[n],delete a[n],delete s[n]}function r(n){if(n in l)return i(n);if(n in a)return a[n];if(n in s)return s[n];if(n in f)return f[n];throw new Error("Module '"+n+"' not found")}function i(n){var e=l[n],t={exports:{}};return e(t.exports,t),a[n]=t.exports,delete l[n],t.exports}function o(n){return n in l||n in a||n in s||n in f}function u(e,t){return n(t,function(t,r){r.exports=n(e)})}function c(e){return f=e,n}var f=this,l=n.pending={},a=n.registry={},s=n.global={capsule:n};n.chroot=c,n.exists=o,n.alias=u,f.rainbows?f.capsule=n:"undefined"!=typeof module?module.exports=n:"function"==typeof e&&e.amd?e(function(){return n}):f.capsule=n}.call(this),this.capsule}.call({rainbows:1}),r=this;t.chroot(r);var i=t.global;"undefined"!=typeof module?(e([["d3","d3"]],require),n.call(i,t),module.exports=t("basic")):"function"==typeof define&&define.amd?define(["require","d3"],function(r){return e([["d3","d3"]],r),n.call(i,t),t("basic")}):(e([["d3","d3"]],function(n){return r[n]}),n.call(i,t),r.basic=t("basic"))}).call(this,function(capsule){ | ||
(function(n){function t(n,t){for(var e,i=-1,o=n.length,u=r.registry;++i<o;)e=n[i],u[e[0]]=t(e[1])}var e,r,i=this;r={c:1},function(){(function(){function n(i,o){var u=arguments.length;return 2>u?r(i):(o?t(i,o):e(i),n)}function t(n,t){d[n]=t}function e(n){delete d[n],delete s[n]}function r(n){if(n in d)return i(n);if(n in s)return s[n];if(n in f)return f[n];throw Error(n+" not found")}function i(n){var t=d[n];delete d[n];var e,r={exports:{}};return t.call(f,r.exports,r),e=s[n]=r.exports}function o(n){return n in d||n in s||n in f}function u(t,e){return n(e,function(e,r){r.exports=n(t)})}function c(t){return f=t,n}var f=this,d={},s=n.registry={};n.alias=u,n.exists=o,n.chroot=c,f.c&&(f.c=n),"undefined"!=typeof module?module.exports=n:"function"==typeof t&&t.amd?t(function(){return n}):f.capsule=n}).call(this)}.call(r),r=r.c,r.chroot(i),n.bind(i),"undefined"!=typeof module?(t([["d3","d3"]],require),n(r),module.exports=r("basic")):"function"==typeof define&&(e=define).amd?e(["require","d3"],function(e){return t([["d3","d3"]],e),n(r),r("basic")}):(t([["d3","d3"]],function(n){return i[n]}),n(r),i.basic=r("basic"))}).call(this,function(capsule){ | ||
(function(n){capsule("chaingun",function(c,i){n.call(this,c,i)}),capsule("chaingun")}).call(this,function(exports, module){ | ||
(function() { | ||
@@ -49,2 +50,3 @@ function chaingun(obj) { | ||
}); | ||
capsule('basic.bar', function(exports, module) { | ||
@@ -51,0 +53,0 @@ var text = capsule('basic.text'); |
@@ -8,8 +8,6 @@ var gulp = require('gulp'); | ||
gulp.task('build', function () { | ||
return capsule([ | ||
'./bower_components/chaingun/chaingun.js', | ||
'./src/**/*.js', | ||
]) | ||
return capsule(['./src/**/*.js']) | ||
.main('basic') | ||
.externals(['d3']) | ||
.excludes(['d3']) | ||
.includes(['./bower_components/chaingun/chaingun.js']) | ||
.bundle() | ||
@@ -16,0 +14,0 @@ .pipe(source('basic.js')) |
{ | ||
"name": "capsule-js", | ||
"version": "0.1.0-alpha.4", | ||
"version": "0.1.0-alpha.5", | ||
"description": "Simple browser module system", | ||
@@ -5,0 +5,0 @@ "main": "bundler", |
@@ -10,4 +10,2 @@ # capsule | ||
capsule('foo', function(exports) { | ||
capsule('external-dep'); | ||
capsule('bundled-dep'); | ||
exports.bar = capsule('foo.bar'); | ||
@@ -24,3 +22,3 @@ }); | ||
```javascript | ||
$ capsule -m foo -e external-dep bundled-dep.js src/**/*.js > foo.js | ||
$ capsule -m foo src/**/*.js > foo.js | ||
``` | ||
@@ -70,5 +68,6 @@ | ||
Options: | ||
--help Show help | ||
-m, --main Name of the entry point module | ||
-e, --external Add an external dependency | ||
--help Show help | ||
-m, --main Name of the entry point module | ||
-i, --include Add a dependency to be included in the bundle | ||
-e, --exclude Add a dependency to be excluded from the bundle | ||
``` | ||
@@ -105,3 +104,3 @@ | ||
Creates a new bundler. `files` can be a string (eg. `'foo.js'`), an array (eg. `['foo.js', 'bar.js']`), a glob string or array, or a readable text stream. All files that should be bundled should be provided, including the dependencies that should be bundled. | ||
Creates a new bundler. `files` can be a string (eg. `'foo.js'`), an array (eg. `['foo.js', 'bar.js']`), a glob string or array, or a readable text stream. All source files that should be bundled should be provided. Dependencies that should be bundled should be given using [`.includes`](#includesdeps). | ||
@@ -121,7 +120,43 @@ ```javascript | ||
#### `.externals(names)` | ||
Configures the bundler to recognise the given `names` as external dependencies. When modules inside the bundle try import the named modules, the modules will be imported according to the environment the bundle is used in (amd, commonjs or browser global land). | ||
#### `.includes(deps)` | ||
Configures the bundler to include the given array of dependencies in the bundle. | ||
```javascript | ||
capsule('./src/**/*.js') | ||
.includes([{ | ||
name: 'jquery', | ||
file: './bower_components/jquery/dist/jquery.js' | ||
}]); | ||
``` | ||
`file` is the path to the dependency's source file, and is the only required option. `name` is the name to use when importing the module (for eg, `'foo'` if one wanted to import it with `capsule('foo')`). | ||
When a dependency is given as a string, the base name of `file` (`'jquery'` in the example below) will be used as the module's name. | ||
```javascript | ||
capsule('./src/**/*.js') | ||
.includes(['./bower_components/jquery/dist/jquery.js']); | ||
``` | ||
Each included dependency has its own `module` and `exports` available in the bundle, so if the dependency supports commonjs environments, capsule will use `module.exports` as the exported value. | ||
If a dependency's `global` name is given, capsule will use it to look up the module in the global namespace instead of providing `modules` and `exports` to it. | ||
```javascript | ||
capsule('./src/**/*.js') | ||
.includes([{ | ||
name: 'jquery', | ||
global: '$', | ||
file: './bower_components/jquery/dist/jquery.js' | ||
}]); | ||
``` | ||
#### `.excludes(deps)` | ||
Configures the bundler to recognise the given array of dependencies as external dependencies. When modules inside the bundle try import the named modules, the modules will be imported according to the environment the bundle is used in (amd, commonjs or browser global land). | ||
```javascript | ||
capsule('src/**/*.js') | ||
@@ -146,3 +181,2 @@ .externals(['d3']); | ||
#### `.bundle([fn])` | ||
@@ -213,2 +247,2 @@ | ||
Useful as a test setup step when a global module (eg. `$`) needs to be importable under a different name (eg. `jquery`) to match how the module's external dependencies are configured during bundling (see [`.externals`](#externalsnames)). | ||
Useful as a test setup step when a global module (eg. `$`) needs to be importable under a different name (eg. `jquery`) to match how the module's dependencies are configured during bundling (see[`.includes`](#includesdeps) and [`.excludes`](#excludesdeps)). |
@@ -13,4 +13,6 @@ #!/usr/bin/env node | ||
.describe('m', 'Name of the entry point module') | ||
.alias('e', 'external') | ||
.describe('e', 'Add an external dependency') | ||
.alias('i', 'include') | ||
.describe('i', 'Add a dependency to be included in the bundle') | ||
.alias('e', 'exclude') | ||
.describe('e', 'Add a dependency to be excluded from the bundle') | ||
.argv; | ||
@@ -21,3 +23,4 @@ | ||
.main(argv.main) | ||
.externals(array(argv.external).map(external)) | ||
.includes(array(argv.include).map(opts)) | ||
.excludes(array(argv.exclude).map(opts)) | ||
.bundle() | ||
@@ -27,7 +30,7 @@ .pipe(process.stdout); | ||
function external(m) { | ||
if (!/=/.test(m)) return m; | ||
function opts(s) { | ||
if (!/=/.test(s)) return s; | ||
var result = {}; | ||
m.split(',') | ||
s.split(',') | ||
.forEach(function(d) { | ||
@@ -34,0 +37,0 @@ var parts = d.split('='); |
@@ -9,2 +9,5 @@ var vm = require('vm'); | ||
describe("bundle", function() { | ||
function noop() {} | ||
function mksrc(sources) { | ||
@@ -25,6 +28,32 @@ var t = qs(); | ||
function noop() { | ||
function commonjs(ctx) { | ||
ctx = ctx || {}; | ||
ctx.require = ctx.require || noop; | ||
ctx.module = {exports: {}}; | ||
ctx.module.global = ctx; | ||
ctx.module.module = ctx.module; | ||
ctx.module.require = ctx.require; | ||
return ctx; | ||
} | ||
function amd(ctx) { | ||
ctx = ctx || {}; | ||
ctx.require = ctx.require || noop; | ||
ctx.define = ctx.define || define; | ||
ctx.define.amd = true; | ||
function define(deps, fn) { | ||
fn(ctx.require); | ||
} | ||
return ctx; | ||
} | ||
function fixture(parts) { | ||
return path.resolve.apply(path, [__dirname, 'fixtures'].concat(parts)); | ||
} | ||
it("should bundle the files", function() { | ||
@@ -50,5 +79,5 @@ return capsule(mksrc([ | ||
return capsule([ | ||
path.join(__dirname, 'fixtures', 'foo.js'), | ||
path.join(__dirname, 'fixtures', 'bar.js'), | ||
path.join(__dirname, 'fixtures', 'global.js') | ||
fixture('foo.js'), | ||
fixture('bar.js'), | ||
fixture('global.js') | ||
]) | ||
@@ -95,3 +124,3 @@ .bundle() | ||
it("should support defining standalone requirejs modules", function() { | ||
it("should support defining standalone amd modules", function() { | ||
return capsule(mksrc([ | ||
@@ -106,6 +135,5 @@ "capsule('foo', function(exports) { exports.bar = 3; });", | ||
.then(function(src) { | ||
define.amd = true; | ||
var defines = []; | ||
run(src, {define: define}); | ||
run(src, amd({define: define})); | ||
assert.deepEqual(defines, [{bar: 3}]); | ||
@@ -129,9 +157,3 @@ | ||
.then(function(src) { | ||
var ctx = {}; | ||
ctx.require = noop; | ||
ctx.module = {exports: {}}; | ||
ctx.module.global = ctx; | ||
ctx.module.module = ctx.module; | ||
ctx.module.require = ctx.require; | ||
var ctx = commonjs(); | ||
run(src, ctx.module); | ||
@@ -142,14 +164,8 @@ assert.deepEqual(ctx.module.exports, {bar: 3}); | ||
it("should support external dependencies when globals are used", function() { | ||
it("should support excluded global dependencies", function() { | ||
return capsule(mksrc([ | ||
"results.foo = capsule('foo');", | ||
"results.bar = capsule('bar');", | ||
"results.bazx = capsule('bazx');" | ||
"results.bar = capsule('bar');" | ||
])) | ||
.externals([ | ||
'foo', | ||
'bar', | ||
{name: 'bazx', | ||
global: 'baz'} | ||
]) | ||
.excludes(['foo', 'bar']) | ||
.bundle() | ||
@@ -162,3 +178,2 @@ .pipe(qs.concat()) | ||
bar: 3, | ||
baz: 4, | ||
results: {} | ||
@@ -169,4 +184,3 @@ }); | ||
foo: 2, | ||
bar: 3, | ||
bazx: 4 | ||
bar: 3 | ||
}); | ||
@@ -176,14 +190,29 @@ }); | ||
it("should support external dependencies when requirejs is used", function() { | ||
it("should support explicitly named excluded global dependencies", function() { | ||
return capsule(mksrc([ | ||
"results.bazx = capsule('bazx');" | ||
])) | ||
.excludes([{ | ||
name: 'bazx', | ||
global: 'baz' | ||
}]) | ||
.bundle() | ||
.pipe(qs.concat()) | ||
.promise() | ||
.then(function(src) { | ||
var ctx = run(src, { | ||
baz: 4, | ||
results: {} | ||
}); | ||
assert.deepEqual(ctx.results, {bazx: 4}); | ||
}); | ||
}); | ||
it("should support excluded amd dependencies", function() { | ||
return capsule(mksrc([ | ||
"results.foo = capsule('foo');", | ||
"results.bar = capsule('bar');", | ||
"results.bazx = capsule('bazx');" | ||
"results.bar = capsule('bar');" | ||
])) | ||
.externals([ | ||
'foo', | ||
'bar', | ||
{amd: 'baz', | ||
name: 'bazx'} | ||
]) | ||
.excludes(['foo', 'bar']) | ||
.bundle() | ||
@@ -193,13 +222,10 @@ .pipe(qs.concat()) | ||
.then(function(src) { | ||
define.amd = true; | ||
var ctx = { | ||
var ctx = amd({ | ||
registry: { | ||
foo: 2, | ||
bar: 3, | ||
baz: 4, | ||
bar: 3 | ||
}, | ||
results: {}, | ||
define: define | ||
}; | ||
require: require | ||
}); | ||
@@ -210,4 +236,3 @@ run(src, ctx); | ||
foo: 2, | ||
bar: 3, | ||
bazx: 4 | ||
bar: 3 | ||
}); | ||
@@ -218,5 +243,28 @@ | ||
} | ||
}); | ||
}); | ||
function define(deps, fn) { | ||
fn(require); | ||
it("should support explicitly named excluded amd dependencies", function() { | ||
return capsule(mksrc([ | ||
"results.bazx = capsule('bazx');" | ||
])) | ||
.excludes([{ | ||
amd: 'baz', | ||
name: 'bazx' | ||
}]) | ||
.bundle() | ||
.pipe(qs.concat()) | ||
.promise() | ||
.then(function(src) { | ||
var ctx = amd({ | ||
registry: {baz: 4}, | ||
results: {}, | ||
require: require | ||
}); | ||
run(src, ctx); | ||
assert.deepEqual(ctx.results, {bazx: 4}); | ||
function require(name) { | ||
return ctx.registry[name]; | ||
} | ||
@@ -226,14 +274,8 @@ }); | ||
it("should support external dependencies when commonjs is used", function() { | ||
it("should support excluded commonjs dependencies", function() { | ||
return capsule(mksrc([ | ||
"global.results.foo = capsule('foo');", | ||
"global.results.bar = capsule('bar');", | ||
"global.results.bazx = capsule('bazx');" | ||
"global.results.bar = capsule('bar');" | ||
])) | ||
.externals([ | ||
'foo', | ||
'bar', | ||
{name: 'bazx', | ||
commonjs: 'baz'} | ||
]) | ||
.excludes(['foo', 'bar']) | ||
.bundle() | ||
@@ -243,14 +285,10 @@ .pipe(qs.concat()) | ||
.then(function(src) { | ||
var ctx = {}; | ||
ctx.results = {}; | ||
ctx.registry = { | ||
foo: 2, | ||
bar: 3, | ||
baz: 4, | ||
}; | ||
ctx.require = require; | ||
ctx.module = {exports: {}}; | ||
ctx.module.global = ctx; | ||
ctx.module.module = ctx.module; | ||
ctx.module.require = ctx.require; | ||
var ctx = commonjs({ | ||
require: require, | ||
results: {}, | ||
registry: { | ||
foo: 2, | ||
bar: 3 | ||
} | ||
}); | ||
@@ -261,4 +299,3 @@ run(src, ctx.module); | ||
foo: 2, | ||
bar: 3, | ||
bazx: 4 | ||
bar: 3 | ||
}); | ||
@@ -272,2 +309,29 @@ | ||
it("should support explicitly named excluded commonjs dependencies", function() { | ||
return capsule(mksrc([ | ||
"global.results.bazx = capsule('bazx');" | ||
])) | ||
.excludes([{ | ||
name: 'bazx', | ||
commonjs: 'baz' | ||
}]) | ||
.bundle() | ||
.pipe(qs.concat()) | ||
.promise() | ||
.then(function(src) { | ||
var ctx = commonjs({ | ||
require: require, | ||
results: {}, | ||
registry: {baz: 4} | ||
}); | ||
run(src, ctx.module); | ||
assert.deepEqual(ctx.results, {bazx: 4}); | ||
function require(name) { | ||
return ctx.registry[name]; | ||
} | ||
}); | ||
}); | ||
it("should invoke the callback with the concatenated result", function(done) { | ||
@@ -298,2 +362,98 @@ capsule(mksrc(["capsule('foo', function() {});"])) | ||
}); | ||
it("should support included global dependencies", function() { | ||
return capsule(mksrc(["global.result = capsule('goo');"])) | ||
.includes([{ | ||
name: 'goo', | ||
global: 'gab', | ||
file: fixture('includes/global/global.js') | ||
}]) | ||
.bundle() | ||
.pipe(qs.concat()) | ||
.promise() | ||
.then(function(src) { | ||
var result = run(src, {global: {}}).global.result; | ||
assert.deepEqual(result, {foo: 2}); | ||
}); | ||
}); | ||
it("should support included module-based commonjs dependencies", function() { | ||
return capsule(mksrc(["global.result = capsule('goo');"])) | ||
.includes([{ | ||
name: 'goo', | ||
file: fixture('includes/commonjs/module.js') | ||
}]) | ||
.bundle() | ||
.pipe(qs.concat()) | ||
.promise() | ||
.then(function(src) { | ||
var result = run(src, {global: {}}).global.result; | ||
assert.deepEqual(result, {foo: 2}); | ||
}); | ||
}); | ||
it("should support included exports-based commonjs dependencies", function() { | ||
return capsule(mksrc(["global.result = capsule('goo');"])) | ||
.includes([{ | ||
name: 'goo', | ||
file: fixture('includes/commonjs/exports.js') | ||
}]) | ||
.bundle() | ||
.pipe(qs.concat()) | ||
.promise() | ||
.then(function(src) { | ||
var result = run(src, {global: {}}).global.result; | ||
assert.deepEqual(result, {foo: 2}); | ||
}); | ||
}); | ||
it("should not assume commonjs if a global is given for an include", function() { | ||
return capsule(mksrc(["global.result = capsule('goo');"])) | ||
.includes([{ | ||
name: 'goo', | ||
global: 'gab', | ||
file: fixture('includes/mixed.js') | ||
}]) | ||
.bundle() | ||
.pipe(qs.concat()) | ||
.promise() | ||
.then(function(src) { | ||
var result = run(src, {global: {}}).global.result; | ||
assert.deepEqual(result, {foo: 3}); | ||
}); | ||
}); | ||
it("should infer included dependency names from file names", function() { | ||
return capsule(mksrc([ | ||
"global.a = capsule('a');", | ||
"global.b = capsule('b');" | ||
])) | ||
.includes([ | ||
fixture('includes/a.min.js'), | ||
fixture('includes/b.js') | ||
]) | ||
.bundle() | ||
.pipe(qs.concat()) | ||
.promise() | ||
.then(function(src) { | ||
var result = run(src, {global: {}}).global; | ||
assert.deepEqual(result, { | ||
a: {foo: 2}, | ||
b: {bar: 3} | ||
}); | ||
}); | ||
}); | ||
it("should load included dependencies immediately", function() { | ||
return capsule(['']) | ||
.includes([fixture('inc.js')]) | ||
.bundle() | ||
.pipe(qs.concat()) | ||
.promise() | ||
.then(function(src) { | ||
var i = run(src, {global: {i: 0}}).global.i; | ||
assert.equal(i, 1); | ||
}); | ||
}); | ||
}); |
@@ -19,6 +19,2 @@ var fs = require('fs'); | ||
it("should throw an error if no module name is given", function() { | ||
assert.throws(function() { run("capsule();"); }, /No module name was given/); | ||
}); | ||
it("should define modules lazily", function() { | ||
@@ -70,12 +66,2 @@ var ctx = run("capsule('foo', function() { global.called = true; });"); | ||
it("should look up globals before environment globals", function() { | ||
var ctx = run([ | ||
"global.foo = 2;", | ||
"capsule.global.foo = 3;", | ||
"global.foo = capsule('foo');" | ||
].join('')); | ||
assert.equal(ctx.foo, 3); | ||
}); | ||
it("should look up environment globals", function() { | ||
@@ -91,3 +77,3 @@ var ctx = run([ | ||
it("should throw an error when it does not find a module", function() { | ||
assert.throws(function() { run("capsule('foo');"); }, /Module 'foo' not found/); | ||
assert.throws(function() { run("capsule('foo');"); }, /foo not found/); | ||
}); | ||
@@ -97,3 +83,2 @@ | ||
var ctx = run([ | ||
"capsule.global.foo = 2;", | ||
"capsule('foo', function(exports, module) { module.exports = 3; });", | ||
@@ -155,11 +140,2 @@ "capsule('foo');", | ||
it("should consider global modules as existing", function() { | ||
var ctx = run([ | ||
"capsule.global.foo = 3;", | ||
"global.exists = capsule.exists('foo');" | ||
].join('')); | ||
assert(ctx.exists); | ||
}); | ||
it("should consider environment globals as existing", function() { | ||
@@ -166,0 +142,0 @@ var ctx = run([ |
@@ -0,1 +1,2 @@ | ||
var util = require('util'); | ||
var qs = require('q-stream'); | ||
@@ -54,3 +55,3 @@ var sh = require('shelljs'); | ||
return capsule('foo.js') | ||
.externals(['baz']) | ||
.excludes(['baz']) | ||
.bundle() | ||
@@ -64,10 +65,7 @@ .pipe(qs.concat()) | ||
it("should allow external files to be given", function() { | ||
it("should allow excludes to be given", function() { | ||
return capsule('foo.js') | ||
.externals([ | ||
.excludes([ | ||
'baz', | ||
'quux', | ||
{name: 'corge', | ||
amd: 'corgex', | ||
global: 'corgey'} | ||
'quux' | ||
]) | ||
@@ -78,7 +76,57 @@ .bundle() | ||
.then(function(expected) { | ||
assert.equal(run( | ||
'-e baz -e quux -e name=corge,amd=corgex,global=corgey foo.js'), | ||
expected); | ||
assert.equal(run('-e baz -e quux foo.js'), expected); | ||
}); | ||
}); | ||
it("should allow complex excludes to be given", function() { | ||
return capsule('foo.js') | ||
.excludes([{ | ||
name: 'corge', | ||
amd: 'corgex', | ||
global: 'corgey' | ||
}]) | ||
.bundle() | ||
.pipe(qs.concat()) | ||
.promise() | ||
.then(function(expected) { | ||
assert.equal(run('-e name=corge,amd=corgex,global=corgey foo.js'), expected); | ||
}); | ||
}); | ||
it("should allow includes to be given", function() { | ||
return capsule('foo.js') | ||
.includes([ | ||
'a.min.js', | ||
'b.js', | ||
].map(fixture)) | ||
.bundle() | ||
.pipe(qs.concat()) | ||
.promise() | ||
.then(function(expected) { | ||
var cmd = util.format( | ||
'-i %s -i %s foo.js', | ||
fixture('a.min.js'), fixture('b.js')); | ||
assert.equal(run(cmd), expected); | ||
}); | ||
}); | ||
it("should allow complex includes to be given", function() { | ||
return capsule('foo.js') | ||
.includes([{ | ||
name: 'goo', | ||
global: 'gab', | ||
file: fixture('includes/global/global.js') | ||
}]) | ||
.bundle() | ||
.pipe(qs.concat()) | ||
.promise() | ||
.then(function(expected) { | ||
var cmd = util.format( | ||
'-i name=goo,global=gab,file=%s foo.js', | ||
fixture('includes/global/global.js')); | ||
assert.equal(run(cmd), expected); | ||
}); | ||
}); | ||
}); |
46898
46
1215
242
7