From d7ac29d846d8c170d8df1d27dfa4d33e26b7aff6 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Wed, 8 Jan 2020 18:20:16 +0000 Subject: [PATCH 1/4] fix: respect map.annotation string --- index.js | 2 +- lib/getMapfile.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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..a0f665a 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.join(path.dirname(options.to), options.map.annotation) + } + return `${options.to}.map` } From 3b09732d511c921d798f4303f4cb7fa042a53f15 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Thu, 9 Jan 2020 10:47:07 +0000 Subject: [PATCH 2/4] test: fix unit tests for getMapFile --- test/map.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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' } ] From 9ebb843bd22325f48a11b4a331dddab8e0751f59 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Thu, 9 Jan 2020 11:01:52 +0000 Subject: [PATCH 3/4] fix: always use posix paths in getMapFile --- lib/getMapfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/getMapfile.js b/lib/getMapfile.js index a0f665a..687e466 100644 --- a/lib/getMapfile.js +++ b/lib/getMapfile.js @@ -2,7 +2,7 @@ const path = require('path') module.exports = function getMapfile(options) { if (options.map && typeof options.map.annotation === 'string') { - return path.join(path.dirname(options.to), options.map.annotation) + return `${ path.dirname(options.to) }/${ options.map.annotation }` } return `${options.to}.map` } From 9a5e383c3d6de84a4ebfacb12c33cd61b9d5feea Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Thu, 9 Jan 2020 11:27:19 +0000 Subject: [PATCH 4/4] style: prettier lib/getMapFile --- lib/getMapfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/getMapfile.js b/lib/getMapfile.js index 687e466..346fea7 100644 --- a/lib/getMapfile.js +++ b/lib/getMapfile.js @@ -2,7 +2,7 @@ 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 `${path.dirname(options.to)}/${options.map.annotation}` } return `${options.to}.map` }