Skip to content

Commit

Permalink
Fix map file path creation (#286)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bcomnes authored and RyanZim committed Jul 8, 2019
1 parent f1c7352 commit 0de7ccf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const reporter = require('postcss-reporter/lib/formatter')()

const argv = require('./lib/args')
const depGraph = require('./lib/depGraph')
const getMapfile = require('./lib/getMapfile')

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

if (result.map) {
const mapfile = options.to.replace(
path.extname(options.to),
`${path.extname(options.to)}.map`
)
const mapfile = getMapfile(options.to)
tasks.push(fs.outputFile(mapfile, result.map))
}
} else process.stdout.write(result.css, 'utf8')
Expand Down
4 changes: 4 additions & 0 deletions lib/getMapfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict'
module.exports = function getMapfile(p) {
return `${p}.map`
}
23 changes: 23 additions & 0 deletions test/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import cli from './helpers/cli.js'
import tmp from './helpers/tmp.js'
import read from './helpers/read.js'

import getMapfile from '../lib/getMapfile'

test('inline maps are generated by default', async t => {
const output = tmp('output.css')

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

t.notRegex(await read(output), /\/*# sourceMappingURL=/)
})

test('mapFile path is property resolved', async t => {
const paths = [
{
input: '/foo/bar.css/baz/index.css',
want: '/foo/bar.css/baz/index.css.map'
},
{
input: '/foo/bar.sss/baz/index.sss',
want: '/foo/bar.sss/baz/index.sss.map'
},
{
input: '/foo/bar.css/baz/bar.css',
want: '/foo/bar.css/baz/bar.css.map'
}
]

for (const p of paths) {
t.is(getMapfile(p.input), p.want)
}
})

0 comments on commit 0de7ccf

Please sign in to comment.