Permalink
Browse files

Add support for non-CommonJS dependencies

  • Loading branch information...
1 parent 078c491 commit b045f5d91c345e25e970349072d99c1bd67a367e @sstephenson sstephenson committed Mar 23, 2011
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -26,15 +26,29 @@ catch err
exports.Package = class Package
constructor: (config) ->
- @identifier = config.identifier ? 'require'
- @paths = config.paths ? ['lib']
- @compilers = _.extend {}, compilers, config.compilers
+ @identifier = config.identifier ? 'require'
+ @paths = config.paths ? ['lib']
+ @dependencies = config.dependencies ? []
+ @compilers = _.extend {}, compilers, config.compilers
@cache = config.cache ? true
@mtimeCache = {}
@compileCache = {}
compile: (callback) ->
+ async.parallel [
+ @compileDependencies
+ @compileSources
+ ], (err, parts) ->
+ if err then callback err
+ else callback null, parts.join("\n")
+
+ compileDependencies: (callback) =>
+ async.map @dependencies, fs.readFile, (err, dependencySources) =>
+ if err then callback err
+ else callback null, dependencySources.join("\n")
+
+ compileSources: (callback) =>
async.reduce @paths, {}, _.bind(@gatherSourcesFromPath, @), (err, sources) =>
return callback err if err
@@ -0,0 +1 @@
+// Backbone
@@ -0,0 +1 @@
+// Underscore
@@ -0,0 +1 @@
+// Zepto
View
@@ -28,6 +28,17 @@ ecoOptions =
paths: [ecoFixtures]
ecoPackage = stitch.createPackage ecoOptions
+dependencyOptions =
+ identifier: "testRequire"
+ paths: [fixtures]
+ dependencies: [
+ fixtureRoot + "/dependencies/zepto.js"
+ fixtureRoot + "/dependencies/underscore.js"
+ fixtureRoot + "/dependencies/backbone.js"
+ ]
+dependencyPackage = stitch.createPackage dependencyOptions
+
+
load = (source, callback) ->
(-> eval source).call module = {}
callback? (source) -> (-> eval source).call module
@@ -41,6 +52,7 @@ rescue = (callback) ->
rescued = true
rescued
+
module.exports =
"walk tree": (test) ->
test.expect fixtureCount
@@ -261,6 +273,20 @@ module.exports =
test.ok rescue -> testRequire("circular/error")
test.done()
+ "dependencies option concatenates files in order": (test) ->
+ test.expect 5
+ dependencyPackage.compile (err, sources) ->
+ test.ok !err
+ lines = sources.split("\n").slice(0, 5)
+
+ test.same "// Zepto", lines[0]
+ test.same "// Underscore", lines[2]
+ test.same "// Backbone", lines[4]
+
+ testRequire = load sources
+ test.ok testRequire("foo/bar/baz")
+ test.done()
+
if stitch.compilers.eco
module.exports["eco compiler"] = (test) ->
test.expect 2

0 comments on commit b045f5d

Please sign in to comment.