Skip to content

Commit

Permalink
support pass string to node-sass sourceMap option (#269)
Browse files Browse the repository at this point in the history
* support pass string to node-sass sourceMap option
* add test case: set sass sourcemap option to string
* update scss adapter doc
  • Loading branch information
creeperyang authored and jescalan committed Dec 24, 2016
1 parent ecc580b commit b35b60a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
7 changes: 6 additions & 1 deletion docs/scss.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ This adapter uses [node-sass](https://github.com/andrew/node-sass), an incredibl

## 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.
`node-sass` (include its dependency `libsass`) currently supports sourcemap. And you can use `sourcemap` option to enable this feature.

1. When passing `Boolean` value to `sourcemap`, it means enable/disable the sourcemap. And the `sources` property of generated sourcemap is array of absolute paths.
2. When passing `String` value to `sourcemap`, the `sources` property of generated sourcemap is array of relative paths (relative to the scss file).

See [node-sass Options.sourceMap](https://github.com/sass/node-sass#sourcemap) for more details.

## 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
7 changes: 5 additions & 2 deletions lib/adapters/scss/2.x.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ class SCSS extends Adapter
_render: (str, options) ->
deferred = W.defer()

if options.sourcemap is true
options.sourceMap = true
if options.sourcemap
if typeof options.sourcemap is 'string'
options.sourceMap = options.sourcemap
else
options.sourceMap = true
options.outFile = path.basename(options.filename).replace('.scss', '.css')
options.omitSourceMapUrl = true
options.sourceMapContents = true
Expand Down
14 changes: 9 additions & 5 deletions lib/adapters/scss/3.x - 4.x.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ class SCSS extends Adapter
_render: (str, options) ->
deferred = W.defer()

if options.sourcemap is true
options.sourceMap = true
if options.sourcemap
if typeof options.sourcemap is 'string'
options.sourceMap = options.sourcemap
else
options.sourceMap = true
options.outFile = options.filename.replace('.scss', '.css')
options.omitSourceMapUrl = true
options.sourceMapContents = true
Expand All @@ -35,9 +38,10 @@ class SCSS extends Adapter
if res.map
data.sourcemap = JSON.parse(res.map.toString('utf8'))
basePath = path.dirname(options.filename)
data.sourcemap.sources =
data.sourcemap.sources.map (relativePath) ->
path.join(basePath, relativePath)
if typeof options.sourceMap isnt 'string'
data.sourcemap.sources =
data.sourcemap.sources.map (relativePath) ->
path.join(basePath, relativePath)

deferred.resolve(data)

Expand Down
13 changes: 13 additions & 0 deletions test/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,19 @@ describe 'scss', ->
res.sourcemap.sourcesContent.length.should.equal(2)
.then((res) => should.match_expected(@scss, res.result, lpath))

it 'should generate a sourcemap with correct relative sources', ->
lpath = path.join(@path, 'external.scss')
mixinpath = path.join(@path, '_mixin_lib.scss')
@scss.renderFile(lpath, { sourcemap: lpath })
.tap (res) ->
res.sourcemap.version.should.equal(3)
res.sourcemap.mappings.length.should.be.above(1)
res.sourcemap.sources.length.should.equal(2)
res.sourcemap.sources[0].should.equal('external.scss')
res.sourcemap.sources[1].should.equal('_mixin_lib.scss')
res.sourcemap.sourcesContent.length.should.equal(2)
.then((res) => should.match_expected(@scss, res.result, lpath))

describe 'less', ->

before ->
Expand Down

0 comments on commit b35b60a

Please sign in to comment.