fix(patch): the hash of the patch file should be the same on both Windows and POSIX (#4969)

close #4961
This commit is contained in:
Zoltan Kochan
2022-07-02 16:04:42 +03:00
committed by GitHub
parent e9946fcfa7
commit 2bca856e00
6 changed files with 27 additions and 4 deletions

View File

@@ -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).

View File

@@ -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": {

View File

@@ -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.split('\r\n').join('\n'))
}

View File

@@ -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\r\nc')
fs.writeFileSync('posix-eol.txt', 'a\nb\r\nc')
expect(await createBase32HashFromFile('win-eol.txt')).toEqual(await createBase32HashFromFile('posix-eol.txt'))
})

View File

@@ -8,5 +8,9 @@
"src/**/*.ts",
"../../typings/**/*.d.ts"
],
"references": []
"references": [
{
"path": "../../privatePackages/prepare"
}
]
}

2
pnpm-lock.yaml generated
View File

@@ -613,11 +613,13 @@ importers:
packages/crypto.base32-hash:
specifiers:
'@pnpm/crypto.base32-hash': workspace:*
'@pnpm/prepare': workspace:*
rfc4648: ^1.5.1
dependencies:
rfc4648: 1.5.2
devDependencies:
'@pnpm/crypto.base32-hash': 'link:'
'@pnpm/prepare': link:../../privatePackages/prepare
packages/default-reporter:
specifiers: