fix: create @pnpm/crypto.base32-hash

This commit is contained in:
Zoltan Kochan
2022-06-18 22:58:16 +03:00
parent 0abfe17182
commit 725636a907
13 changed files with 122 additions and 9 deletions

View File

@@ -0,0 +1,5 @@
---
"dependency-path": patch
---
Use @pnpm/crypto.base32-hash.

View File

@@ -0,0 +1,5 @@
---
"@pnpm/crypto.base32-hash": major
---
Initial release.

View File

@@ -0,0 +1,13 @@
# @pnpm/crypto.base32-hash
> Create a base32 hash
## Installation
```sh
pnpm add @pnpm/crypto.base32-hash
```
## License
MIT

View File

@@ -0,0 +1,3 @@
const config = require('../../jest.config.js');
module.exports = Object.assign({}, config, {});

View File

@@ -0,0 +1,43 @@
{
"name": "@pnpm/crypto.base32-hash",
"version": "0.0.0",
"description": "Create a base32 hash",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib",
"!*.map"
],
"scripts": {
"lint": "eslint src/**/*.ts test/**/*.ts",
"_test": "jest",
"test": "pnpm run compile && pnpm run _test",
"prepublishOnly": "pnpm run compile",
"compile": "tsc --build && pnpm run lint --fix"
},
"repository": "https://github.com/pnpm/pnpm/blob/main/packages/crypto.base32-hash",
"keywords": [
"pnpm7",
"hash",
"crypto",
"base32"
],
"engines": {
"node": ">=14.6"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/pnpm/pnpm/issues"
},
"homepage": "https://github.com/pnpm/pnpm/blob/main/packages/crypto.base32-hash#readme",
"dependencies": {
"rfc4648": "^1.5.1"
},
"devDependencies": {
"@pnpm/crypto.base32-hash": "workspace:0.0.0"
},
"funding": "https://opencollective.com/pnpm",
"exports": {
".": "./lib/index.js"
}
}

View File

@@ -0,0 +1,11 @@
import crypto from 'crypto'
import fs from 'fs'
import { base32 } from 'rfc4648'
export function createBase32Hash (str: string): string {
return base32.stringify(crypto.createHash('md5').update(str).digest()).replace(/(=+)$/, '').toLowerCase()
}
export async function createBase32HashFromFile (file: string): Promise<string> {
return createBase32Hash(await fs.promises.readFile(file, 'utf8'))
}

View File

@@ -0,0 +1,6 @@
/// <reference path="../../../typings/index.d.ts"/>
import { createBase32Hash } from '@pnpm/crypto.base32-hash'
test('createBase32Hash()', () => {
expect(createBase32Hash('AAA')).toEqual('4h5p7m7gcttmf65hikljmi4gw4')
})

View File

@@ -0,0 +1,12 @@
{
"extends": "@pnpm/tsconfig",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
},
"include": [
"src/**/*.ts",
"../../typings/**/*.d.ts"
],
"references": []
}

View File

@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*.ts",
"test/**/*.ts",
"../../typings/**/*.d.ts"
]
}

View File

@@ -31,9 +31,9 @@
},
"homepage": "https://github.com/pnpm/pnpm/blob/main/packages/dependency-path#readme",
"dependencies": {
"@pnpm/crypto.base32-hash": "workspace:0.0.0",
"@pnpm/types": "workspace:8.1.0",
"encode-registry": "^3.0.0",
"rfc4648": "^1.5.1",
"semver": "^7.3.4"
},
"devDependencies": {

View File

@@ -1,7 +1,6 @@
import crypto from 'crypto'
import { createBase32Hash } from '@pnpm/crypto.base32-hash'
import { Registries } from '@pnpm/types'
import encodeRegistry from 'encode-registry'
import { base32 } from 'rfc4648'
import semver from 'semver'
export function isAbsolute (dependencyPath: string) {
@@ -163,7 +162,3 @@ export function createPeersFolderSuffix (peers: Array<{name: string, version: st
}
return `_${folderName}`
}
function createBase32Hash (str: string): string {
return base32.stringify(crypto.createHash('md5').update(str).digest()).replace(/(=+)$/, '').toLowerCase()
}

View File

@@ -9,6 +9,9 @@
"../../typings/**/*.d.ts"
],
"references": [
{
"path": "../crypto.base32-hash"
},
{
"path": "../types"
}

13
pnpm-lock.yaml generated
View File

@@ -610,6 +610,15 @@ importers:
'@pnpm/logger': 4.0.0
'@pnpm/prepare': link:../../privatePackages/prepare
packages/crypto.base32-hash:
specifiers:
'@pnpm/crypto.base32-hash': workspace:0.0.0
rfc4648: ^1.5.1
dependencies:
rfc4648: 1.5.2
devDependencies:
'@pnpm/crypto.base32-hash': 'link:'
packages/default-reporter:
specifiers:
'@pnpm/config': workspace:15.2.1
@@ -729,16 +738,16 @@ importers:
packages/dependency-path:
specifiers:
'@pnpm/crypto.base32-hash': workspace:0.0.0
'@pnpm/types': workspace:8.1.0
'@types/semver': ^7.3.4
dependency-path: workspace:9.1.3
encode-registry: ^3.0.0
rfc4648: ^1.5.1
semver: ^7.3.4
dependencies:
'@pnpm/crypto.base32-hash': link:../crypto.base32-hash
'@pnpm/types': link:../types
encode-registry: 3.0.0
rfc4648: 1.5.2
semver: 7.3.7
devDependencies:
'@types/semver': 7.3.9