Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outputs syntax errors when bundling Browserify #113

Open
wants to merge 6 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
29 changes: 15 additions & 14 deletions lib/asset.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class exports.Asset extends EventEmitter
constructor: (options) ->
super()
options ?= {}

# Set the url
@url = options.url if options.url?

Expand Down Expand Up @@ -59,7 +59,7 @@ class exports.Asset extends EventEmitter
# Max age for HTTP cache control
@maxAge = options.maxAge if options.maxAge?

# Whether to allow caching of non-hashed urls
# Whether to allow caching of non-hashed urls
@allowNoHashCache = options.allowNoHashCache if options.allowNoHashCache?

# Fire callback if someone listens for a "complete" event
Expand Down Expand Up @@ -104,16 +104,17 @@ class exports.Asset extends EventEmitter
@emit 'complete'
else
@emit 'complete'

# Does the file watching
if @watch
@watcher = fs.watch @toWatch, (event, filename) =>
if event is 'change'
@watcher.close()
@completed = false
@assets = false
process.nextTick =>
@emit 'start'
@watcher = new gaze.Gaze(@toWatch + "/*")
@watcher.on 'all', (event, filepath) =>
@watcher.close()
@completed = false
@assets = false

process.nextTick =>
@emit 'start'

# Listen for errors and throw if no listeners
@on 'error', (error) =>
Expand Down Expand Up @@ -153,7 +154,7 @@ class exports.Asset extends EventEmitter
if @gzip
response.send @gzipContents
else response.send @contents

# Check if a given url "matches" this asset
checkUrl: (url) ->
url is @specificUrl or (not @hash? and url is @url)
Expand All @@ -172,10 +173,10 @@ class exports.Asset extends EventEmitter
handle()
else @on 'complete', ->
handle()
# Default create method, usually overwritten

# Default create method, usually overwritten
create: (options) ->

# At the end of a create method you always call
# the created event
@emit 'created'
Expand Down
27 changes: 20 additions & 7 deletions lib/modules/browserify.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,25 @@ class exports.BrowserifyAsset extends Asset
agent = browserify watch: false, debug: @debug
for handler in @extensionHandlers
agent.register(handler.ext, handler.handler)
agent.addEntry @filename
agent.on 'syntaxError', (err) ->
console.dir err

agent.add @filename
agent.require @require if @require
if @compress is true
uncompressed = agent.bundle()
@contents = uglify.minify(uncompressed, {fromString: true}).code
@emit 'created'
else
@emit 'created', contents: agent.bundle()

if options.transforms
options.transforms.forEach (transform) ->
agent.transform(transform.opts, transform.fn)

uncompressed = ""
browserifyStream = agent.bundle()

browserifyStream.on 'data', (chunk) =>
uncompressed += chunk

browserifyStream.on 'end', =>
if @compress is true
@contents = uglify.minify(uncompressed, {fromString: true}).code
@emit 'created'
else
@emit 'created', contents: uncompressed
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"author": "Brad Carleton <[email protected]>",
"repository": "https://github.com/techpines/asset-rack",
"dependencies": {
"browserify": "1.17.3",
"snockets": "~1.3.8",
"uglify-js": "~2.4.0",
"async": "~0.2.9",
Expand All @@ -14,11 +13,13 @@
"jade": "~0.35.0",
"mime": "1.2.11",
"nib": "~1.0.1",
"stylus": "~0.38.0",
"underscore": "~1.5.2",
"coffee-script": "~1.6.3",
"markdown": "~0.5.0",
"node-sassy": "~0.0.1"
"node-sassy": "~0.0.1",
"gaze": "~0.4.3",
"browserify": "3.33.1",
"stylus": "^0.42.3"
},
"devDependencies": {
"express.io": "1.1.8",
Expand Down