Skip to content

Commit

Permalink
refactor: DRYing out code
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedAlchemy committed Jun 12, 2018
1 parent 9bd3e37 commit 19c606e
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/flushChunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,17 @@ const flushWebpack = (ids: Files, stats: Stats): Files => {
}

/** CREATE FILES MAP */

const createFilesByPath = ({ chunks, modules }: Stats): FilesMap => {
const filesByChunk = chunks.reduce((chunks, chunk) => {
const filesByChunk = chunks =>
chunks.reduce((chunks, chunk) => {
chunks[chunk.id] = chunk.files
return chunks
}, {})

const createFilesByPath = ({ chunks, modules }: Stats): FilesMap => {
const chunkedFiles = filesByChunk(chunks)
return modules.reduce((filesByPath, module) => {
const filePath = module.name
const files = concatFilesAtKeys(filesByChunk, module.chunks)
const files = concatFilesAtKeys(chunkedFiles, module.chunks)

filesByPath[filePath] = files.filter(isUnique)
return filesByPath
Expand All @@ -179,11 +180,7 @@ const findChunkById = ({ chunks }) => {
if (!chunks) {
return {}
}
const filesByChunk = chunks.reduce((chunks, chunk) => {
chunks[chunk.id] = chunk.files
return chunks
}, {})
return filesByChunk
return filesByChunk(chunks)
}

/** HELPERS */
Expand Down

0 comments on commit 19c606e

Please sign in to comment.