Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit f936c76

Browse files
committed
add source maps support!
1 parent 1efc227 commit f936c76

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"devDependencies": {
1616
"es-module-loader": "^1.2.0",
1717
"rollup": "^0.34.7",
18-
"rollup-plugin-node-resolve": "^2.0.0"
18+
"rollup-plugin-node-resolve": "^2.0.0",
19+
"source-map-support": "^0.4.4"
1920
},
2021
"scripts": {
2122
"build": "rollup -c",

src/node-es-module-loader.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ var path = require('path');
99
var Module = require('module');
1010
var fs = require('fs');
1111

12+
var sourceMapSources = global.nodeEsModuleLoaderSourceMapSources = global.nodeEsModuleLoaderSourceMapSources || {};
13+
14+
require('source-map-support').install({
15+
retrieveSourceMap: function(source) {
16+
if (!sourceMapSources[source])
17+
return null;
18+
19+
return {
20+
url: source.replace('!transpiled', ''),
21+
map: sourceMapSources[source]
22+
};
23+
}
24+
});
25+
1226
function NodeESModuleLoader(baseKey, rcPath) {
1327
if (!isNode)
1428
throw new Error('Node module loader can only be used in Node');
@@ -50,7 +64,7 @@ NodeESModuleLoader.prototype[RegisterLoader.normalize] = function(key, parent, m
5064
});
5165
};
5266

53-
var PROCESS_REGISTER_CONTEXT = RegisterLoader.processRegisterContext;
67+
var PROCESS_REGISTER_CONTEXT = RegisterLoader.processRegisterContext || 'processRegisterContext';
5468

5569
// instantiate just needs to run System.register
5670
// so we fetch the source, convert into the Babel System module format, then evaluate it
@@ -77,13 +91,15 @@ NodeESModuleLoader.prototype[RegisterLoader.instantiate] = function(key, metadat
7791
filename: key + '!transpiled',
7892
sourceFileName: key,
7993
moduleIds: false,
80-
sourceMaps: 'inline',
94+
sourceMaps: true,
8195
plugins: [require('babel-plugin-transform-es2015-modules-systemjs')],
8296
extends: loader.rcPath
8397
});
8498

8599
// evaluate without require, exports and module variables
86-
(0,eval)(output.code + '\n//# sourceURL=' + fileUrlToPath(key) + '!transpiled');
100+
var path = fileUrlToPath(key) + '!transpiled';
101+
sourceMapSources[path] = output.map;
102+
(0,eval)(output.code + '\n//# sourceURL=' + path);
87103
loader[PROCESS_REGISTER_CONTEXT](key);
88104

89105
resolve();

0 commit comments

Comments
 (0)