From 33ec7d0b53b9439b0a41dfab7d3fa49b3630da01 Mon Sep 17 00:00:00 2001 From: Jesse McCarthy Date: Thu, 5 Feb 2015 12:41:56 -0500 Subject: [PATCH] Make traceur runtime #1 entry file. --- index.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 59465b8..ebe677f 100644 --- a/index.js +++ b/index.js @@ -59,7 +59,15 @@ exports = module.exports = function es6ify(b, opts) { if (opts.basedir === undefined) opts.basedir = b._options.basedir; if (opts.includeRuntime === undefined) opts.includeRuntime = true; - if (opts.includeRuntime) b.add(runtime); + if (opts.includeRuntime) { + // Process records that have previously entered the pipeline. + b._recorded.forEach(function (rec) { + reorderEntry(rec); + }); + // Push a pipeline step to process records hereafter entering the pipeline. + b.pipeline.get('record').push(reorderEntries()); + b.add(runtime); + } transform = makeTransform(); @@ -105,6 +113,29 @@ exports = module.exports = function es6ify(b, opts) { // makeTransform } +// Reorder a pipeline record. +function reorderEntry(rec) { + if (rec.entry) rec.order++; + if (rec.id === runtime) rec.order = 1; + return rec; +} +// reorderEntry + +// Create a stream to insert in the browserify pipeline to reorder entry files +// so traceur runtime is number one. +function reorderEntries() { + var stream = through(write); + stream.label = 'es6ify-reorder-entries'; + + return stream; + + function write(rec) { + reorderEntry(rec); + this.queue(rec); + } +} +// reorderEntries + /** * The traceur runtime exposed here so it can be included in the bundle via: *