Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensures factor bundle correctly matches entries to output streams #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,20 @@ ctor = module.exports = function atomifyJs (opts, cb) {
}

// for each entry, we're going to create a stream-able buffer to put the factored bundle into
outputs = {}
outputs = []
opts.entries.forEach(function createOutputs (entry) {
outputs[path.basename(entry).replace(path.extname(entry), '')] = new streamBuffer.WritableStreamBuffer({
outputs.push(new streamBuffer.WritableStreamBuffer({
// these values are arbitrary, but we don't want to require huge buffers
// start as 1 kilobytes.
initialSize: 1 * 1024
// grow by 1 kilobytes each time buffer overflows.
, incrementAmount: 1 * 1024
})
}))
})

// setup factor bundle, pass in our streamable-buffers as the output source
b.plugin(factorBundle, {
o: _.values(outputs)
o: outputs
})

// we need to wrap the callback to output an object with all the bundles
Expand All @@ -232,15 +232,18 @@ ctor = module.exports = function atomifyJs (opts, cb) {
if (err && hasCallback) return void cb(err)

// turn the stream-able buffers into plain buffers
out = _.mapValues(outputs, function convertStreamToBuffer (stream, entryName) {
out = opts.entries.reduce(function(acc, entry, ix) {
var stream = outputs[ix]
var entryBuffer = stream.getContents()
var entryName = path.basename(entry).replace(path.extname(entry), '')

// for those using the streaming interface, emit an event with the entry
// do this here so that we don't have to itterate through the outputs twice
emitter.emit('entry', entryBuffer, entryName)

return entryBuffer
})
acc[entryName] = entryBuffer
return acc
}, {})

// add in the common bundle
out.common = common
Expand Down