diff --git a/index.js b/index.js index f96c07f..8d79228 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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') diff --git a/lib/getMapfile.js b/lib/getMapfile.js new file mode 100644 index 0000000..b9dd441 --- /dev/null +++ b/lib/getMapfile.js @@ -0,0 +1,4 @@ +'use strict' +module.exports = function getMapfile(p) { + return `${p}.map` +} diff --git a/test/map.js b/test/map.js index 53880d8..b944cd5 100644 --- a/test/map.js +++ b/test/map.js @@ -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') @@ -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) + } +})