-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: generate hash of final bundle file (netlify/edge-bundler#4)
* fix: generate hash of final bundle file * refactor: use -pre suffix on pre-bundle * refactor: rename variables
- Loading branch information
1 parent
cd3eb3b
commit afff58b
Showing
6 changed files
with
110 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
import crypto from 'crypto' | ||
import fs from 'fs' | ||
|
||
const getStringHash = (input: string) => { | ||
const shasum = crypto.createHash('sha256') | ||
const getFileHash = (path: string): Promise<string> => { | ||
const hash = crypto.createHash('sha256') | ||
|
||
shasum.update(input) | ||
hash.setEncoding('hex') | ||
|
||
const hash = shasum.digest('hex') | ||
return new Promise((resolve, reject) => { | ||
const file = fs.createReadStream(path) | ||
|
||
return hash | ||
file.on('end', () => { | ||
hash.end() | ||
|
||
resolve(hash.read()) | ||
}) | ||
file.on('error', reject) | ||
|
||
file.pipe(hash) | ||
}) | ||
} | ||
|
||
export { getStringHash } | ||
export { getFileHash } |