diff --git a/lib/compiler.coffee b/lib/compiler.coffee index 300da52e..b70c1647 100644 --- a/lib/compiler.coffee +++ b/lib/compiler.coffee @@ -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) @@ -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) ###* @@ -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: @@ -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) @@ -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, @@ -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 @@ -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) diff --git a/package.json b/package.json index bfba009c..bfb0a966 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/compile.coffee b/test/compile.coffee index 66f00f5f..4dcedda0 100644 --- a/test/compile.coffee +++ b/test/compile.coffee @@ -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() diff --git a/test/fixtures/compile/sourcemaps/app.coffee b/test/fixtures/compile/sourcemaps/app.coffee new file mode 100644 index 00000000..d0d0e043 --- /dev/null +++ b/test/fixtures/compile/sourcemaps/app.coffee @@ -0,0 +1,5 @@ +stylus: + sourcemap: { comment: false } + +'coffee-script': + sourceMap: true diff --git a/test/fixtures/compile/sourcemaps/package.json b/test/fixtures/compile/sourcemaps/package.json new file mode 100644 index 00000000..8e37ef64 --- /dev/null +++ b/test/fixtures/compile/sourcemaps/package.json @@ -0,0 +1,7 @@ +{ + "name": "test", + "dependencies": { + "coffee-script": "*", + "stylus": "*" + } +} diff --git a/test/fixtures/compile/sourcemaps/test.coffee b/test/fixtures/compile/sourcemaps/test.coffee new file mode 100644 index 00000000..56f6dcde --- /dev/null +++ b/test/fixtures/compile/sourcemaps/test.coffee @@ -0,0 +1 @@ +console.log 'wow' diff --git a/test/fixtures/compile/sourcemaps/test.styl b/test/fixtures/compile/sourcemaps/test.styl new file mode 100644 index 00000000..9dcb4c8d --- /dev/null +++ b/test/fixtures/compile/sourcemaps/test.styl @@ -0,0 +1,2 @@ +p + color: red