Skip to content

Commit c9361cb

Browse files
authored
Ensure source maps contain relative paths
Fixes #1882.
1 parent 6fb0964 commit c9361cb

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

lib/babel-pipeline.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ function build(projectDir, cacheDir, userOptions, compileEnhancements) {
145145
cwd: projectDir,
146146
envName,
147147
inputSourceMap,
148-
filename
148+
filename,
149+
sourceFileName: path.relative(projectDir, filename),
150+
sourceRoot: projectDir
149151
}));
150152

151153
// TODO: Check for `partialTestConfig.config` and include a hash of the file
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import test from '../../../../../..';
2+
3+
test('ok', t => t.pass());

test/integration/babel.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
'use strict';
2+
const fs = require('fs');
3+
const path = require('path');
4+
const globby = require('globby');
25
const test = require('tap').test;
36
const figures = require('figures');
47
const pkg = require('../../package.json');
@@ -30,3 +33,16 @@ for (const which of [
3033
});
3134
});
3235
}
36+
37+
test('includes relative paths in source map', t => {
38+
execCli([], {dirname: 'fixture/correct-sources-in-source-map'}, () => {
39+
const [file] = globby.sync(['*.js.map'], {
40+
absolute: true,
41+
cwd: path.resolve(__dirname, '../fixture/correct-sources-in-source-map/node_modules/.cache/ava')
42+
});
43+
const map = JSON.parse(fs.readFileSync(file, 'utf8'));
44+
t.same(map.sources, [path.normalize('test/path-to/the/test-file.js')]);
45+
t.is(map.sourceRoot, path.resolve(__dirname, '../fixture/correct-sources-in-source-map'));
46+
t.end();
47+
});
48+
});

0 commit comments

Comments
 (0)