Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
source map extraction to only use // comments, node 6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed May 25, 2016
1 parent 0164594 commit 430e99a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
24 changes: 13 additions & 11 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var asp = require('bluebird').promisify;
var fs = require('fs');
var path = require('path');

var sourceMappingURL = require('source-map-url');
var dataUriToBuffer = require('data-uri-to-buffer');

var extend = require('./utils').extend;
Expand Down Expand Up @@ -192,23 +191,24 @@ Builder.prototype.reset = function(baseLoader) {
});
})
}))

// support picking up source URLs during fetch to set as metadata.sourceMap
.then(function (source) {
var metadata = load.metadata;
if (metadata.sourceMap)
if (load.metadata.sourceMap)
return source;
var sourceMap = sourceMappingURL.getFrom(source);
var sourceMap = source.match(/\s*\/\/\s*[#@] sourceMappingURL=([^\s'"]*)/m);
if (!sourceMap)
return source;
source = sourceMappingURL.removeFrom(source);
if (sourceMap.startsWith('data:')) {
if (sourceMap[1].startsWith('data:')) {
// inline source map
metadata.sourceMap = JSON.parse(dataUriToBuffer(sourceMap).toString('utf8'));
load.metadata.sourceMap = JSON.parse(dataUriToBuffer(sourceMap[1]).toString('utf8'));
return source;
} else {
}
else {
// relative path to the .map file
var sourceMapPath = path.join(path.dirname(fromFileURL(load.address)), sourceMap);
var sourceMapPath = path.join(path.dirname(fromFileURL(load.address)), sourceMap[1]);
return asp(fs.readFile)(sourceMapPath, 'utf8').then(function (sourceMap) {
metadata.sourceMap = JSON.parse(sourceMap);
load.metadata.sourceMap = JSON.parse(sourceMap);
return source;
});
}
Expand Down Expand Up @@ -306,7 +306,9 @@ function executeConfigFile(saveForReset, ignoreBaseURL, configPath, source) {
// and prevent that code from adding anything to the real global
var context = Object.create(global);
context.SystemJS = context.System = configLoader;
context.global = context.GLOBAL = context.root = context;
context.global = context;
if (process.versions.node && process.versions.node.split('.')[0] <= 6)
context.GLOBAL = context.root = context;
// make require available too, make it look as if config file was
// loaded like a module
var Module = require('module');
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"mkdirp": "^0.5.1",
"rollup": "^0.25.0",
"source-map": "^0.5.3",
"source-map-url": "^0.4.0",
"systemjs": "^0.19.28",
"traceur": "0.0.105",
"uglify-js": "^2.6.1"
Expand Down

0 comments on commit 430e99a

Please sign in to comment.