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

Commit

Permalink
outputESM as a trace option, translate hook to take trace options
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jun 3, 2016
1 parent dae0f18 commit 27af669
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
7 changes: 6 additions & 1 deletion lib/builder.js
Expand Up @@ -329,6 +329,10 @@ Builder.prototype.config = function(config, saveForReset, ignoreBaseURL) {
*/
function processTraceOpts(options, defaults) {
var opts = {
// indicate to plugins to output ES modules instead of System.register for Rollup support
outputESM: true,
sourceMaps: false,

// conditional tracing options
browser: undefined,
node: undefined,
Expand Down Expand Up @@ -511,7 +515,8 @@ Builder.prototype.compile = function(moduleNameOrLoad, outFile, opts) {
.then(function(moduleName) {
if (!opts || opts.cache !== true)
self.invalidate(moduleName);
return self.tracer.getLoadRecord(getCanonicalName(self.loader, moduleName), true);
return self.tracer.getLoadRecord(getCanonicalName(self.loader, moduleName),
processTraceOpts(opts, { tracePackageConfig: false, browser: true, node: false, production: true, dev: false, outputESM: false }));
});
})
.then(function(load) {
Expand Down
16 changes: 5 additions & 11 deletions lib/trace.js
Expand Up @@ -109,7 +109,7 @@ function isLoadFresh(load, loader, loads) {
* Low-level functions
*/
// runs the pipeline hooks, returning the load record for a module
Trace.prototype.getLoadRecord = function(canonical, excludeURLs, parentStack, sourceMaps) {
Trace.prototype.getLoadRecord = function(canonical, traceOpts, parentStack) {

var loader = this.loader;
var loads = this.loads;
Expand Down Expand Up @@ -430,20 +430,14 @@ Trace.prototype.getLoadRecord = function(canonical, excludeURLs, parentStack, so

// Parse source map definitions inside of the source and apply it to the metadata if present.
.then(function (source) {
// Once the sourceMaps option is set to false, we will not parse any source map definitions.
// Just returning the plain source is required.
if (sourceMaps === false) {
if (!traceOpts.sourceMaps || load.metadata.sourceMap)
return source;
}

if (load.metadata.sourceMap) return source;

// Search for the specified sourceMap definition in the files source.
var sourceMap = source.match(/^\s*\/\/\s*[#@] sourceMappingURL=([^\s'"]*)/m);

if (!sourceMap) {
if (!sourceMap)
return source;
}

// Once the sourceMappingURL starts with `data:`, we have to parse it as an inline source map.
if (sourceMap[1].startsWith('data:')) {
Expand Down Expand Up @@ -473,7 +467,7 @@ Trace.prototype.getLoadRecord = function(canonical, excludeURLs, parentStack, so
load.metadata.timestamp = undefined;
}

return loader.translate({ name: normalized, metadata: load.metadata, address: address, source: source });
return loader.translate({ name: normalized, metadata: load.metadata, address: address, source: source }, traceOpts);
})
.then(function(source) {
load.source = source;
Expand Down Expand Up @@ -509,7 +503,7 @@ Trace.prototype.getLoadRecord = function(canonical, excludeURLs, parentStack, so
load.depMap[dep] = getCanonicalName(loader, normalized);
}
catch(e) {
if (!excludeURLs || normalized.substr(0, 7) == 'file://')
if (!traceOpts.excludeURLs || normalized.substr(0, 7) == 'file://')
throw e;
(loader.meta[normalized] = loader.meta[normalized] || {}).build = false;
load.depMap[dep] = normalized;
Expand Down

0 comments on commit 27af669

Please sign in to comment.