Skip to content

Commit

Permalink
Merge 92d4764 into 7b25a89
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Escalante committed Dec 19, 2014
2 parents 7b25a89 + 92d4764 commit 802d076
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
41 changes: 34 additions & 7 deletions lib/compiler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ class CompileFile
.then((o) => @content = o)
.then(=> sequence(hooks('compile_hooks.before_file'), @))
.then(each_pass)
.tap((o) => @content = o)
.tap (o) =>
@content = o.result
@sourcemap = o.sourcemap
.tap(=> @roots.emit('compile', @file))
.then(=> sequence(hooks('compile_hooks.after_file'), @))
.then(write_file)
Expand Down Expand Up @@ -129,6 +131,7 @@ class CompileFile
write_file = ->
sequence(@extensions.hooks('compile_hooks.write', @category), @)
.then(process_write_hook_results.bind(@))
.then(write_sourcemaps_if_present.bind(@))
.then(W.all)

###*
Expand Down Expand Up @@ -172,6 +175,20 @@ class CompileFile

return W.resolve(write_tasks)

write_sourcemaps_if_present = (tasks) ->
if not @sourcemap then return tasks

f = new File
base: @roots.root
path: @file.path + '.map'

tasks.push write_task.call @,
path: f
content: @sourcemap
sourcemap: true

return W.resolve(tasks)

###*
* Single task to write a file. Accepts an optional object with the following
* keys:
Expand Down Expand Up @@ -199,6 +216,9 @@ class CompileFile
if not obj.extension? and @is_compiled
obj.extension = @out_ext

if obj.sourcemap?
obj.extension += '.map'

if not (obj.path instanceof File)
obj.path = new File(base: @roots.root, path: obj.path)

Expand Down Expand Up @@ -243,7 +263,7 @@ class CompileFile

each_pass = ->
pass = new CompilePass(@)
pipeline(@adapters.map((a,i) -> pass.run.bind(pass, a, i + 1)), @content)
pipeline(@adapters.map((a,i) -> pass.run.bind(pass, a, i + 1)), { result: @content })

###*
* Returns the absolute path to the file as requested through the browser,
Expand Down Expand Up @@ -292,16 +312,23 @@ class CompilePass
* @todo is there a way to yield(@content)?
###

run: (@adapter, @index, @content) ->
run: (@adapter, @index, @input) ->
hooks = (cat) => @file.extensions.hooks(cat, @file.category)

@content = @input.result

sequence(hooks('compile_hooks.before_pass'), @)
.with(@)
.tap(=> @opts = configure_options.call(@))
.then(compile_or_pass)
.then((o) => @content = o)
.then(=> sequence(hooks('compile_hooks.after_pass'), @))
.then(=> @content)
.then (o) =>
@content = o.result
res = { result: @content }
if o.sourcemap
@sourcemap = o.sourcemap
res.sourcemap = @sourcemap
return res
.tap(=> sequence(hooks('compile_hooks.after_pass'), @))

###*
* This function is responsible for getting all the options together for the
Expand Down Expand Up @@ -345,5 +372,5 @@ class CompilePass
###

compile_or_pass = ->
if not @adapter.name then return @content
if not @adapter.name then return @input
@adapter.render(@content, @opts)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"doc": "doc"
},
"dependencies": {
"accord": "0.12.x",
"accord": "0.13.x",
"argparse": "0.1.x",
"charge": "0.0.3",
"chokidar": "0.9.x",
Expand Down
15 changes: 15 additions & 0 deletions test/compile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,18 @@ describe 'compile', ->
path.join(output, 'dev_file.html').should.not.be.a.path()
done()
, done

it 'should output sourcemaps when specified', (done) ->
p = path.join(test_path, 'sourcemaps')
output = path.join(p, 'public')

compile_fixture p, done, ->
p = path.join(output, 'test.css')
p.should.be.a.file()
p2 = path.join(output, 'test.css.map')
p2.should.be.a.file()
p3 = path.join(output, 'test.js')
p3.should.be.a.file()
p4 = path.join(output, 'test.js.map')
p4.should.be.a.file()
done()
5 changes: 5 additions & 0 deletions test/fixtures/compile/sourcemaps/app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
stylus:
sourcemap: { comment: false }

'coffee-script':
sourceMap: true
7 changes: 7 additions & 0 deletions test/fixtures/compile/sourcemaps/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "test",
"dependencies": {
"coffee-script": "*",
"stylus": "*"
}
}
1 change: 1 addition & 0 deletions test/fixtures/compile/sourcemaps/test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log 'wow'
2 changes: 2 additions & 0 deletions test/fixtures/compile/sourcemaps/test.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
p
color: red

0 comments on commit 802d076

Please sign in to comment.