Skip to content

Commit

Permalink
sourcemaps being written and test in place
Browse files Browse the repository at this point in the history
...but their formatting needs to be normalized for sure
  • Loading branch information
Jeff Escalante committed Dec 19, 2014
1 parent 6b89761 commit 92d4764
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
22 changes: 21 additions & 1 deletion 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.result)
.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
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 92d4764

Please sign in to comment.