Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix map file path creation #286

Merged
merged 4 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions lib/getMapfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict'
const path = require('path')

module.exports = function getMapfile(p) {
const ext = path.extname(p)
const base = path.basename(p)
return p.replace(base, base.replace(ext, `${ext}.map`))
bcomnes marked this conversation as resolved.
Show resolved Hide resolved
}
19 changes: 19 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,20 @@ 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'
}
]

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