Skip to content

Commit

Permalink
add actual sourcemap support and tests for any compiler that supports…
Browse files Browse the repository at this point in the history
… them
  • Loading branch information
Jeff Escalante committed Dec 17, 2014
1 parent 5ce9469 commit a013c89
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/coco.md
Expand Up @@ -4,6 +4,10 @@ Coco is a fork of CoffeeScript that tries to eliminate some pain points. It has
## Supported Methods
- render

## Source Maps

Coco does not support source maps, unfortunately. If they do add support we would be happy to add it to accord.

## Additional Options
### Bare
- key: `bare`
Expand Down
4 changes: 4 additions & 0 deletions docs/coffeescript.md
Expand Up @@ -4,6 +4,10 @@ The CoffeeScript adapter API is almost exactly the same as the CoffeeScript JS A
## Supported Methods
- render

## Source Maps

Source maps are supported by the coffeescript adapter. Just pass in `sourceMap: true` as an option and you will get back both `sourcemap` and `v3sourcemap` (this is what coffeescript passes back by default), on the response object.

## Additional Options
### Bare
- key: `bare`
Expand Down
4 changes: 4 additions & 0 deletions docs/csso.md
Expand Up @@ -4,6 +4,10 @@ CSSO is a great tool for optimizing CSS. It's public API is very simple, sometim
## Supported Methods
- render

## Source Maps

CSSO does not have support for source maps, unfortunately. There is an open issue for it [here](https://github.com/css/csso/issues/173). If they do add support we'd be happy to integrate it with accord.

## Additional Options
### No Restructure
- key: `no_restructure`
Expand Down
4 changes: 4 additions & 0 deletions docs/dogescript.md
Expand Up @@ -10,3 +10,7 @@ dogescript.render('wow', { beauty: true, trueDoge: true })

## Supported Methods
- render

## Source Maps

Dogescript does not support sourcemaps. Honestly, I doubt it ever will. If you are writing dogescript, you probably don't need sourcemaps anyway because you are too boss for that kind of stuff.
4 changes: 4 additions & 0 deletions docs/handlebars.md
Expand Up @@ -18,3 +18,7 @@ hbs.render("hello there {{ name }}", {
- compile
- compileClient
- clientHelpers

## Source Maps

Handlebars [does support source maps](https://github.com/wycats/handlebars.js/pull/902), but the functionality is brand new (at the time of writing), and is still undocumented. We will add this feature to accord once it's documented in handlebars if there's any demand for it.
4 changes: 4 additions & 0 deletions docs/jade.md
Expand Up @@ -6,3 +6,7 @@ The jade adapter is used in just about the exact same as the jade public api, ma
- compile
- compileClient
- clientHelpers

## Source Maps

Jade does not support source maps and has no plans of doing so in the near future. See [this issue](https://github.com/jadejs/jade/issues/941) for discussion.
4 changes: 4 additions & 0 deletions docs/less.md
Expand Up @@ -11,3 +11,7 @@ less.render('some less code', {

## Supported Methods
- render

## Source Maps

The less adapter does have support for sourcemaps. You can pass in `sourceMap: true` as an option and receive a map back on the response object as `sourcemap`.
4 changes: 4 additions & 0 deletions docs/livescript.md
Expand Up @@ -4,6 +4,10 @@ LiveScript is a fork of Coco, which is a fork of CoffeeScript. More info on chan
## Supported Methods
- render

## Source Maps

Livescript does not yet have support for source maps. You can see an open issue for this feature [here](https://github.com/gkz/LiveScript/issues/452).

## Additional Options
Its compiler is unsurprisingly very similar to both CoffeeScript and Coco, and has only 2 unique options, explained below.

Expand Down
4 changes: 4 additions & 0 deletions docs/minify-css.md
Expand Up @@ -3,3 +3,7 @@ CSS is minified with the fantastic [clean-css](https://github.com/GoalSmashers/c

## Supported Methods
- render

## Source Maps

Clean CSS does not yet have support for source maps, but it is [in the works](https://github.com/jakubpawlowicz/clean-css/issues/125) at the time of writing. We will re-examine if/when this feature is fully implemented.
4 changes: 4 additions & 0 deletions docs/minify-js.md
Expand Up @@ -3,3 +3,7 @@ Uses [uglifyjs2](https://github.com/mishoo/UglifyJS2) to minify javascript code.

## Supported Methods
- render

## Source Maps

Although UglifyJS has sourcemap support, unfortunately it forces you to write them to a specific file rather than simply returning the map so you can do with it what you want. Since accord does not write files and simply executes transforms then returns the text, we do not support this in any special way. You can pass `sourceMap` as an option with the path to a file and presumably it will be written. This is not tested or officially supported and will not be until UglifyJS allows us to return the sourcemap as a string or object.
4 changes: 4 additions & 0 deletions docs/myth.md
Expand Up @@ -3,3 +3,7 @@ Essentially a polyfill for the css future spec. Check the [features](https://git

## Supported Methods
- render

## Source Maps

Myth does support sourcemaps, but automatically inlines them. If call the adapter with `sourcemap: true` as an option, it will return a compiled result with an inline sourcemap.
4 changes: 4 additions & 0 deletions docs/scss.md
Expand Up @@ -4,6 +4,10 @@ This adapter uses [node-sass](https://github.com/andrew/node-sass), an incredibl
## Supported Methods
- render

## Source Maps

Libsass does not yet support source maps, although at the time of writing there is [an open pull request](https://github.com/sass/libsass/pull/591) to work on this.

## Additional Options
It has a pretty standard API, and uses the [options documented here](https://github.com/andrew/node-sass#options). Do not pass through `data` or `file`, as this will be overridden by accord's wrapper - everything else is fair game.

Expand Down
4 changes: 4 additions & 0 deletions docs/stylus.md
Expand Up @@ -4,6 +4,10 @@ The Stylus compiler interface is one of the most abnormal and has gone through h
## Supported Methods
- render

## Source Maps

Source maps are supported by the stylus adapter. Just pass in a `sourcemap` option [as described in the docs](http://learnboost.github.io/stylus/docs/sourcemaps.html), and it will come back as `sourcemap` on the response object.

## Additional Options
### [Define](http://learnboost.github.io/stylus/docs/js.html#definename-node)

Expand Down
5 changes: 4 additions & 1 deletion lib/adapters/coffee-script.coffee
Expand Up @@ -15,6 +15,9 @@ class CoffeeScript extends Adapter
compile = (fn) ->
try res = fn()
catch err then return W.reject(err)
W.resolve(compiled: res)
if res.sourceMap
W.resolve(compiled: res.js, sourcemap: res.sourceMap, v3sourcemap: res.v3SourceMap)
else
W.resolve(compiled: res)

module.exports = CoffeeScript
4 changes: 3 additions & 1 deletion lib/adapters/less.coffee
Expand Up @@ -16,7 +16,9 @@ class Less extends Adapter

@engine.render str, options, (err, res) ->
if err then return deferred.reject(err)
deferred.resolve(compiled: res.css)
obj = { compiled: res.css }
if options.sourceMap then obj.sourcemap = res.map
deferred.resolve(obj)

return deferred.promise

Expand Down
10 changes: 7 additions & 3 deletions lib/adapters/minify-js.coffee
Expand Up @@ -10,13 +10,17 @@ class MinifyJS extends Adapter
isolated: true

_render: (str, options) ->
compile => @engine.minify(str, _.extend(options, fromString: true)).code
compile =>
res = @engine.minify(str, _.extend(options, fromString: true))
obj = { compiled: res.code }
if options.sourceMap then obj.sourcemap = res.map
obj

# private

compile = (fn) ->
compile = (fn, map) ->
try res = fn()
catch err then return W.reject(err)
W.resolve(compiled: res)
W.resolve(res)

module.exports = MinifyJS
4 changes: 3 additions & 1 deletion lib/adapters/myth.coffee
Expand Up @@ -7,7 +7,9 @@ class Myth extends Adapter
output: 'css'

_render: (str, options) ->
compile => @engine(str)
options.source = options.filename
delete options.filename
compile => @engine(str, options)

# private

Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/myth/expected/import.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions test/fixtures/myth/import.myth
@@ -0,0 +1,5 @@
@import "imported.myth";

body {
color: red
}
3 changes: 3 additions & 0 deletions test/fixtures/myth/imported.myth
@@ -0,0 +1,3 @@
html {
background: blue;
}
25 changes: 25 additions & 0 deletions test/test.coffee
Expand Up @@ -174,6 +174,13 @@ describe 'coffeescript', ->
@coffee.render("! ---@#$$@%#$")
.done(should.not.exist, (-> done()))

it 'should generate sourcemaps', (done) ->
lpath = path.join(@path, 'basic.coffee')
@coffee.renderFile(lpath, sourceMap: true ).done (res) =>
res.sourcemap.should.exist
res.v3sourcemap.should.exist
should.match_expected(@coffee, res.compiled, lpath, done)

describe 'stylus', ->

before ->
Expand Down Expand Up @@ -426,6 +433,13 @@ describe 'minify-js', ->
@minifyjs.render("@#$%#I$$N%NI#$%I$PQ")
.done(should.not.exist, (-> done()))

it.skip 'should generate sourcemaps', (done) ->
lpath = path.join(@path, 'basic.js')
@minifyjs.renderFile(lpath, sourceMap: true).done (res) =>
res.sourcemap.should.exist
res.sourcemap.should.not.equal('null')
should.match_expected(@minifyjs, res.compiled, lpath, done)

describe 'minify-css', ->

before ->
Expand Down Expand Up @@ -736,6 +750,12 @@ describe 'less', ->
''')
.done(should.not.exist, (-> done()))

it 'should generate sourcemaps', (done) ->
lpath = path.join(@path, 'basic.less')
@less.renderFile(lpath, sourceMap: true).done (res) =>
res.sourcemap.should.exist
should.match_expected(@less, res.compiled, lpath, done)

describe 'coco', ->

before ->
Expand Down Expand Up @@ -823,6 +843,11 @@ describe 'myth', ->
@myth.render("!! --- )I%$_(I(YRTO")
.done(should.not.exist, (-> done()))

it 'should generate sourcemaps', (done) ->
lpath = path.join(@path, 'import.myth')
@myth.renderFile(lpath, sourcemap: true).done (res) =>
should.match_expected(@myth, res.compiled, lpath, done)

describe 'haml', ->

before ->
Expand Down

0 comments on commit a013c89

Please sign in to comment.