From a218eccc22a52a216dd1836560fe8a6b8a5a4d8c Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Wed, 17 Dec 2014 17:01:01 -0500 Subject: [PATCH 1/4] upgrade to accord 0.13 --- lib/compiler.coffee | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/compiler.coffee b/lib/compiler.coffee index 300da52e..a4d92414 100644 --- a/lib/compiler.coffee +++ b/lib/compiler.coffee @@ -346,4 +346,4 @@ class CompilePass compile_or_pass = -> if not @adapter.name then return @content - @adapter.render(@content, @opts) + @adapter.render(@content, @opts).then((r) -> r.result) 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", From 1343ce9e229731a58d321a20ecbf82be43b5397c Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Wed, 17 Dec 2014 17:12:29 -0500 Subject: [PATCH 2/4] let's get that sourcemap on our file object --- lib/compiler.coffee | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/compiler.coffee b/lib/compiler.coffee index a4d92414..46b330f6 100644 --- a/lib/compiler.coffee +++ b/lib/compiler.coffee @@ -299,9 +299,11 @@ class CompilePass .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 + @sourcemap = o.sourcemap + return @content + .tap(=> sequence(hooks('compile_hooks.after_pass'), @)) ###* * This function is responsible for getting all the options together for the @@ -345,5 +347,5 @@ class CompilePass ### compile_or_pass = -> - if not @adapter.name then return @content - @adapter.render(@content, @opts).then((r) -> r.result) + if not @adapter.name then return { result: @content } + @adapter.render(@content, @opts) From 6b89761e665ff006b9f3e43c154bc9e9566b6993 Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Fri, 19 Dec 2014 11:57:33 -0500 Subject: [PATCH 3/4] better sourcemap integration internally --- lib/compiler.coffee | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/compiler.coffee b/lib/compiler.coffee index 46b330f6..9dd08e6e 100644 --- a/lib/compiler.coffee +++ b/lib/compiler.coffee @@ -90,7 +90,7 @@ 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) .tap(=> @roots.emit('compile', @file)) .then(=> sequence(hooks('compile_hooks.after_file'), @)) .then(write_file) @@ -243,7 +243,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,17 +292,22 @@ 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.result - @sourcemap = o.sourcemap - return @content + res = { result: @content } + if o.sourcemap + @sourcemap = o.sourcemap + res.sourcemap = @sourcemap + return res .tap(=> sequence(hooks('compile_hooks.after_pass'), @)) ###* @@ -347,5 +352,5 @@ class CompilePass ### compile_or_pass = -> - if not @adapter.name then return { result: @content } + if not @adapter.name then return @input @adapter.render(@content, @opts) From 92d47644580a3fd6ea296e067e78d7e920761136 Mon Sep 17 00:00:00 2001 From: Jeff Escalante Date: Fri, 19 Dec 2014 15:12:24 -0500 Subject: [PATCH 4/4] sourcemaps being written and test in place ...but their formatting needs to be normalized for sure --- lib/compiler.coffee | 22 ++++++++++++++++++- test/compile.coffee | 15 +++++++++++++ test/fixtures/compile/sourcemaps/app.coffee | 5 +++++ test/fixtures/compile/sourcemaps/package.json | 7 ++++++ test/fixtures/compile/sourcemaps/test.coffee | 1 + test/fixtures/compile/sourcemaps/test.styl | 2 ++ 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/compile/sourcemaps/app.coffee create mode 100644 test/fixtures/compile/sourcemaps/package.json create mode 100644 test/fixtures/compile/sourcemaps/test.coffee create mode 100644 test/fixtures/compile/sourcemaps/test.styl diff --git a/lib/compiler.coffee b/lib/compiler.coffee index 9dd08e6e..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.result) + .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) 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