diff --git a/lib/builder.js b/lib/builder.js index 727e477..ad4e4eb 100644 --- a/lib/builder.js +++ b/lib/builder.js @@ -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, @@ -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) { diff --git a/lib/trace.js b/lib/trace.js index 15b1cd1..40cfe5c 100644 --- a/lib/trace.js +++ b/lib/trace.js @@ -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; @@ -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:')) { @@ -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; @@ -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;