diff --git a/index.js b/index.js index e54247d..0e4bef8 100644 --- a/index.js +++ b/index.js @@ -222,7 +222,7 @@ function css(css, file) { tasks.push(fs.outputFile(options.to, result.css)) if (result.map) { - const mapfile = getMapfile(options.to) + const mapfile = getMapfile(options) tasks.push(fs.outputFile(mapfile, result.map)) } } else process.stdout.write(result.css, 'utf8') diff --git a/lib/getMapfile.js b/lib/getMapfile.js index b9dd441..346fea7 100644 --- a/lib/getMapfile.js +++ b/lib/getMapfile.js @@ -1,4 +1,8 @@ 'use strict' -module.exports = function getMapfile(p) { - return `${p}.map` +const path = require('path') +module.exports = function getMapfile(options) { + if (options.map && typeof options.map.annotation === 'string') { + return `${path.dirname(options.to)}/${options.map.annotation}` + } + return `${options.to}.map` } diff --git a/test/map.js b/test/map.js index b944cd5..7c3c2ba 100644 --- a/test/map.js +++ b/test/map.js @@ -59,16 +59,20 @@ test('--no-map disables internal sourcemaps', async t => { test('mapFile path is property resolved', async t => { const paths = [ { - input: '/foo/bar.css/baz/index.css', + input: { to: '/foo/bar.css/baz/index.css' }, want: '/foo/bar.css/baz/index.css.map' }, { - input: '/foo/bar.sss/baz/index.sss', + input: { to: '/foo/bar.sss/baz/index.sss' }, want: '/foo/bar.sss/baz/index.sss.map' }, { - input: '/foo/bar.css/baz/bar.css', + input: { to: '/foo/bar.css/baz/bar.css' }, want: '/foo/bar.css/baz/bar.css.map' + }, + { + input: { map: { annotation: 'foo.map' }, to: '/foo/bar.css/baz/bar.css' }, + want: '/foo/bar.css/baz/foo.map' } ]