Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = {
'fp/no-class': 0,
'fp/no-let': 0,
'fp/no-loops': 0,
'fp/no-mutating-methods': 0,
'fp/no-mutation': 0,
'fp/no-this': 0,
'promise/no-callback-in-promise': 0,
Expand Down
5 changes: 3 additions & 2 deletions src/deploy/hasher_segments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const objWriter = require('flush-write-stream').obj
const flushWriteStream = require('flush-write-stream')
const hasha = require('hasha')
const transform = require('parallel-transform')
const objFilterCtor = require('through2-filter').objCtor
Expand Down Expand Up @@ -28,13 +28,14 @@ const fileNormalizerCtor = ({ assetType = 'file' }) =>
// A writable stream segment ctor that normalizes file paths, and writes shaMap's
const manifestCollectorCtor = (filesObj, shaMap, { statusCb, assetType }) => {
if (!statusCb || !assetType) throw new Error('Missing required options')
return objWriter((fileObj, _, cb) => {
return flushWriteStream.obj((fileObj, _, cb) => {
filesObj[fileObj.normalizedPath] = fileObj.hash

// We map a hash to multiple fileObj's because the same file
// might live in two different locations

if (Array.isArray(shaMap[fileObj.hash])) {
// eslint-disable-next-line fp/no-mutating-methods
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code relies on streaming for performance reasons (hashing many files). Streaming relies on event handlers, which are hard to use in a purely functional way, which is why we need some mutation here.

There is a probably a way to do this in an incremental/performant way without mutation, but this could potentially break the logic.

shaMap[fileObj.hash].push(fileObj)
} else {
shaMap[fileObj.hash] = [fileObj]
Expand Down