Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Add ability to include the file extension when requiring modules. #46

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/stitch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[ "Josh Peek"
, "Sam Stephenson"
]
, "version": "0.3.3"
, "version": "0.3.4"
, "licenses": [
{ "type": "MIT"
, "url": "http://github.com/sstephenson/stitch/raw/master/LICENSE"
Expand Down
9 changes: 6 additions & 3 deletions src/stitch.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ exports.Package = class Package
return require(name, '');
}
this.#{@identifier}.define = function(bundle) {
for (var key in bundle)
for (var key in bundle) {
modules[key] = bundle[key];
var ext = key.split('.').pop();
if (ext.indexOf('/') === -1 && ext.length < key.length)
modules[key.slice(0,-ext.length - 1)] = bundle[key];
}
};
}
return this.#{@identifier}.define;
Expand Down Expand Up @@ -154,8 +158,7 @@ exports.Package = class Package
@compileFile path, (err, source) ->
if err then callback err
else
extension = extname relativePath
key = relativePath.slice(0, -extension.length)
key = relativePath
sources[key] =
filename: relativePath
source: source
Expand Down
9 changes: 9 additions & 0 deletions test/test_stitch.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ module.exports =
test.ok testRequire("foo/bar/baz")
test.done()

"require with .js extension": (test) ->
test.expect 3
additionalPackage.compile (err, sources) ->
test.ok !err
testRequire = load sources
test.ok testRequire("foo/bar.js")
test.ok testRequire("hello.js")
test.done()

if stitch.compilers.eco
module.exports["eco compiler"] = (test) ->
test.expect 2
Expand Down