Skip to content

Commit 0de7ccf

Browse files
bcomnesRyanZim
authored andcommitted
Fix map file path creation (#286)
* Add failing test for external map file path creation * Write passing map file implementation Can we just append + '.map'? * Add additional failing example * Simplify implementation
1 parent f1c7352 commit 0de7ccf

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const reporter = require('postcss-reporter/lib/formatter')()
1616

1717
const argv = require('./lib/args')
1818
const depGraph = require('./lib/depGraph')
19+
const getMapfile = require('./lib/getMapfile')
1920

2021
let input = argv._
2122
const { dir, output } = argv
@@ -221,10 +222,7 @@ function css(css, file) {
221222
tasks.push(fs.outputFile(options.to, result.css))
222223

223224
if (result.map) {
224-
const mapfile = options.to.replace(
225-
path.extname(options.to),
226-
`${path.extname(options.to)}.map`
227-
)
225+
const mapfile = getMapfile(options.to)
228226
tasks.push(fs.outputFile(mapfile, result.map))
229227
}
230228
} else process.stdout.write(result.css, 'utf8')

lib/getMapfile.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict'
2+
module.exports = function getMapfile(p) {
3+
return `${p}.map`
4+
}

test/map.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import cli from './helpers/cli.js'
55
import tmp from './helpers/tmp.js'
66
import read from './helpers/read.js'
77

8+
import getMapfile from '../lib/getMapfile'
9+
810
test('inline maps are generated by default', async t => {
911
const output = tmp('output.css')
1012

@@ -53,3 +55,24 @@ test('--no-map disables internal sourcemaps', async t => {
5355

5456
t.notRegex(await read(output), /\/*# sourceMappingURL=/)
5557
})
58+
59+
test('mapFile path is property resolved', async t => {
60+
const paths = [
61+
{
62+
input: '/foo/bar.css/baz/index.css',
63+
want: '/foo/bar.css/baz/index.css.map'
64+
},
65+
{
66+
input: '/foo/bar.sss/baz/index.sss',
67+
want: '/foo/bar.sss/baz/index.sss.map'
68+
},
69+
{
70+
input: '/foo/bar.css/baz/bar.css',
71+
want: '/foo/bar.css/baz/bar.css.map'
72+
}
73+
]
74+
75+
for (const p of paths) {
76+
t.is(getMapfile(p.input), p.want)
77+
}
78+
})

0 commit comments

Comments
 (0)