Skip to content

Commit 568528d

Browse files
keithamusRyanZim
authored andcommitted
Respect map.annotation string (#307)
* fix: respect map.annotation string * test: fix unit tests for getMapFile * fix: always use posix paths in getMapFile * style: prettier lib/getMapFile
1 parent 745ad2c commit 568528d

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function css(css, file) {
222222
tasks.push(fs.outputFile(options.to, result.css))
223223

224224
if (result.map) {
225-
const mapfile = getMapfile(options.to)
225+
const mapfile = getMapfile(options)
226226
tasks.push(fs.outputFile(mapfile, result.map))
227227
}
228228
} else process.stdout.write(result.css, 'utf8')

lib/getMapfile.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
'use strict'
2-
module.exports = function getMapfile(p) {
3-
return `${p}.map`
2+
const path = require('path')
3+
module.exports = function getMapfile(options) {
4+
if (options.map && typeof options.map.annotation === 'string') {
5+
return `${path.dirname(options.to)}/${options.map.annotation}`
6+
}
7+
return `${options.to}.map`
48
}

test/map.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,20 @@ test('--no-map disables internal sourcemaps', async t => {
5959
test('mapFile path is property resolved', async t => {
6060
const paths = [
6161
{
62-
input: '/foo/bar.css/baz/index.css',
62+
input: { to: '/foo/bar.css/baz/index.css' },
6363
want: '/foo/bar.css/baz/index.css.map'
6464
},
6565
{
66-
input: '/foo/bar.sss/baz/index.sss',
66+
input: { to: '/foo/bar.sss/baz/index.sss' },
6767
want: '/foo/bar.sss/baz/index.sss.map'
6868
},
6969
{
70-
input: '/foo/bar.css/baz/bar.css',
70+
input: { to: '/foo/bar.css/baz/bar.css' },
7171
want: '/foo/bar.css/baz/bar.css.map'
72+
},
73+
{
74+
input: { map: { annotation: 'foo.map' }, to: '/foo/bar.css/baz/bar.css' },
75+
want: '/foo/bar.css/baz/foo.map'
7276
}
7377
]
7478

0 commit comments

Comments
 (0)