Skip to content

Commit b45bca8

Browse files
committed
fix: fix importing mappings. closes #1454
1 parent 15ddc16 commit b45bca8

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

scripts/generate-mappings.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ const mappings = ast.program.body.reduce((acc, declaration, index, self) => {
6060
}, {});
6161

6262
fs.existsSync(path.dirname(output)) || fs.mkdirSync(path.dirname(output));
63-
fs.writeFileSync(output, JSON.stringify({ index, mappings }, null, 2));
63+
fs.writeFileSync(
64+
output,
65+
JSON.stringify({ name: packageJson.name, index, mappings }, null, 2)
66+
);

src/babel/__tests__/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ spawnSync('node', [
1010
]);
1111

1212
const { fixtures } = create({
13-
plugins: [require.resolve('../index')],
13+
plugins: [
14+
[
15+
require.resolve('../index'),
16+
{ mappings: require.resolve('../../../lib/mappings.json') },
17+
],
18+
],
1419
});
1520

1621
fixtures('generate mappings', path.join(__dirname, '..', '__fixtures__'));

src/babel/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const { index, mappings } = require('../../lib/mappings.json');
2-
const { name } = require('../../package.json');
3-
41
const SKIP = Symbol('SKIP');
52

6-
module.exports = function rewire(babel) {
3+
module.exports = function rewire(babel, options) {
74
const t = babel.types;
5+
6+
const { name, index, mappings } = require(options.mappings ||
7+
'../../mappings.json');
8+
89
return {
910
visitor: {
1011
ImportDeclaration(path) {

0 commit comments

Comments
 (0)