Skip to content

Commit

Permalink
fix(patch): the hash of the patch file should be the same on both Win…
Browse files Browse the repository at this point in the history
…dows and POSIX

close #4961
  • Loading branch information
zkochan committed Jul 2, 2022
1 parent e9946fc commit 9ec1519
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/soft-seals-shop.md
@@ -0,0 +1,6 @@
---
"@pnpm/crypto.base32-hash": patch
"pnpm": patch
---

The hash of the patch file should be the same on both Windows and POSIX [#4961](https://github.com/pnpm/pnpm/issues/4961).
3 changes: 2 additions & 1 deletion packages/crypto.base32-hash/package.json
Expand Up @@ -34,7 +34,8 @@
"rfc4648": "^1.5.1"
},
"devDependencies": {
"@pnpm/crypto.base32-hash": "workspace:*"
"@pnpm/crypto.base32-hash": "workspace:*",
"@pnpm/prepare": "workspace:*"
},
"funding": "https://opencollective.com/pnpm",
"exports": {
Expand Down
3 changes: 2 additions & 1 deletion packages/crypto.base32-hash/src/index.ts
Expand Up @@ -7,5 +7,6 @@ export function createBase32Hash (str: string): string {
}

export async function createBase32HashFromFile (file: string): Promise<string> {
return createBase32Hash(await fs.promises.readFile(file, 'utf8'))
const content = await fs.promises.readFile(file, 'utf8')
return createBase32Hash(content.replace('\r\n', '\n'))
}
11 changes: 10 additions & 1 deletion packages/crypto.base32-hash/test/index.ts
@@ -1,6 +1,15 @@
/// <reference path="../../../typings/index.d.ts"/>
import { createBase32Hash } from '@pnpm/crypto.base32-hash'
import fs from 'fs'
import { createBase32Hash, createBase32HashFromFile } from '@pnpm/crypto.base32-hash'
import { tempDir } from '@pnpm/prepare'

test('createBase32Hash()', () => {
expect(createBase32Hash('AAA')).toEqual('4h5p7m7gcttmf65hikljmi4gw4')
})

test('createBase32HashFromFile normalizes line endings before calculating the hash', async () => {
tempDir()
fs.writeFileSync('win-eol.txt', 'a\r\nb')
fs.writeFileSync('posix-eol.txt', 'a\nb')
expect(await createBase32HashFromFile('win-eol.txt')).toEqual(await createBase32HashFromFile('posix-eol.txt'))
})
6 changes: 5 additions & 1 deletion packages/crypto.base32-hash/tsconfig.json
Expand Up @@ -8,5 +8,9 @@
"src/**/*.ts",
"../../typings/**/*.d.ts"
],
"references": []
"references": [
{
"path": "../../privatePackages/prepare"
}
]
}
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9ec1519

Please sign in to comment.