- 
                Notifications
    You must be signed in to change notification settings 
- Fork 431
Description
Describe the bug
It seems like Deno's polyfill for Node's crypto.Hash considers .end() as a finalization of the object, and so a following call to .digest('hex') fails with ERR_CRYPTO_HASH_FINALIZED.
This happens in src/utils/deploy/hasher-segments.ts function hashFile():
const hashFile = async (filePath: string, algorithm: string) => {
  const hasher = createHash(algorithm)
  await pipeline([createReadStream(filePath), hasher])
  return hasher.digest('hex')
}pipeline() indirectly ends the hasher write stream after consuming the read stream. So the following call to hasher.digest('hex') results in an exception.
A solution that worked for me is providing { end: false } as a second parameter to pipeline(). (I also verified that this does not break running the command from node.js.)
See: Garciat/netlify-cli@main...garciat/fix-deno-digest-already-called
An alternative would be to use hasher.read().toString('hex') instead of hasher.digest('hex'), which only reads the hash result (assuming that .end() was called previously) instead of trying to finalize the hash object. However, I find this approach a bit too implicit/indirect.
Steps to reproduce
Given a project that has already been configured for deployment:
deno run -A npm:netlify-cli deployThe output was:
[...etc...]
❯ Context
✔ Finished uploading blobs to deploy store
✔ No cached functions were found
⠦ Hashing files... ›   Warning: 
{
  "code": "ERR_CRYPTO_HASH_FINALIZED",
  "name": "Error"
}
 ›   Error: Digest already called
Configuration
No response
Environment
  System:
    OS: macOS 15.3.1
    CPU: (8) arm64 Apple M1
    Memory: 96.05 MB / 8.00 GB
    Shell: 5.9 - /opt/homebrew/bin/zsh
  Binaries:
    Node: 23.7.0 - /opt/homebrew/bin/node
    npm: 11.1.0 - /opt/homebrew/bin/npm
  npmPackages:
    netlify-cli: ^18.1.0 => 18.1.0