Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from yarn to bun #14

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@ jobs:
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Set up Node.js

- name: Set up Node.js 🍞
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Enable Corepack
run: corepack enable

- name: Set Yarn version to Berry
run: corepack prepare [email protected] --activate

- name: Install Bun (via Bun action) 🍞
uses: oven-sh/setup-bun@v1

- name: Install dependencies
run: yarn install
run: bun install

- name: Build auto-utils package 🔧
run: yarn workspace @autonomys/auto-utils build
run: bun run --filter '@autonomys/auto-utils' build

- name: Build all packages 🔧
run: yarn build
run: bun run build

- name: Run tests 🧪
run: yarn test
run: bun test
1 change: 0 additions & 1 deletion .yarnrc.yml

This file was deleted.

16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The repository is organized as follows:
## Requirements

- Node.js
- Yarn 2 (Berry) or later
- [Bun 1.0.0 or higher](https://bun.sh/docs/installation#installing)

## Setup

Expand All @@ -25,27 +25,23 @@ The repository is organized as follows:

`cd auto-sdk`

3. **Set Yarn to use the Berry version:**
3. **Install dependencies:**

`yarn set version berry`

4. **Install dependencies:**

`yarn install`
`bun install`

## Scripts

### Build

To build all packages:

`yarn build`
`bun build`

### Test

To run tests for all packages:

`yarn test`
`bun test`

### Localhost testing

Expand Down Expand Up @@ -79,7 +75,7 @@ To test the packages against a local node, you can use the script at `scripts/lo

## Workspaces

This project uses Yarn workspaces. Packages are located in the `packages` directory. Each package can have its own dependencies and build scripts.
This project uses workspaces. Packages are located in the `packages` directory. Each package can have its own dependencies and build scripts.

## License

Expand Down
Binary file added bun.lockb
Binary file not shown.
28 changes: 23 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,31 @@
"packages/*"
],
"scripts": {
"build": "yarn workspaces foreach --all run build",
"test": "yarn workspaces foreach --all run test"
"build": "bun run --filter '@autonomys/auto-utils' build && bun run --filter '*' build",
"clean": "bun run --filter '*' clean",
"format": "bun run --filter '*' format",
"test": "bun run --filter '*' test"
},
"packageManager": "[email protected]",
"engines": {
"node": ">=18.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/subspace/auto-sdk"
},
"author": {
"name": "Autonomys",
"url": "https://www.autonomys.net"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
"eslint": "^8.57.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"typescript": "^5.4.5"
},
"packageManager": "[email protected]"
"typescript": "^5.4.5",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2"
}
}
20 changes: 12 additions & 8 deletions packages/auto-consensus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
"version": "0.1.0",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"test": "jest"
"build": "bun build ./src/index.ts --outdir ./dist --target node",
"clean": "rm -rf dist",
"format": "prettier --write \"src/**/*.ts\"",
"test": "bun test"
},
"files": [
"dist",
"README.md"
],
"repository": {
"type": "git",
"url": "https://github.com/subspace/auto-sdk"
},
"author": {
"name": "Autonomys",
"url": "https://www.autonomys.net"
},
"dependencies": {
"@autonomys/auto-utils": "workspace:*"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"ts-jest": "^29.1.4",
"typescript": "^5.4.5"
}
}
24 changes: 12 additions & 12 deletions packages/auto-id/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
"version": "0.1.0",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"build": "bun build ./src/index.ts --outdir ./dist --target node",
"clean": "rm -rf dist",
"format": "prettier --write \"src/**/*.ts\"",
"test": "jest"
},
"dependencies": {
"@autonomys/auto-utils": "workspace:*",
"@types/node": "^20.12.12"
"test": "bun test"
},
"files": [
"dist",
"README.md"
],
"devDependencies": {
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
"dependencies": {
"@autonomys/auto-utils": "workspace:*"
},
"repository": {
"type": "git",
"url": "https://github.com/subspace/auto-sdk"
},
"author": {
"name": "Autonomys",
"url": "https://www.autonomys.net"
}
}
6 changes: 3 additions & 3 deletions packages/auto-id/src/keyManagement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { read, save } from '@autonomys/auto-utils'
import { KeyObject, createPrivateKey, createPublicKey, generateKeyPairSync } from 'crypto'
import { KeyObject, createPrivateKey, createPublicKey, generateKeyPairSync } from 'node:crypto'

/**
* Generates an RSA key pair.
Expand Down Expand Up @@ -113,7 +113,7 @@
const pem = keyToPem(key, password)
await save(filePath, pem)
} catch (e: any) {
throw new Error(`Failed to save key: ${e.message}`)

Check failure on line 116 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to save key: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:116:11

Check failure on line 116 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to save key: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:116:11

Check failure on line 116 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to save key: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:116:11

Check failure on line 116 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to save key: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:116:11
}
}

Expand Down Expand Up @@ -167,9 +167,9 @@
try {
const keyData = await read(filePath)
const privateKey = pemToPrivateKey(keyData, password)
return privateKey;
return privateKey
} catch (error: any) {
throw new Error(`Failed to load private key: ${error.message}`)

Check failure on line 172 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to load private key: Failed to read or parse file: ENOENT: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:172:11

Check failure on line 172 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to load private key: Failed to read or parse file: ENOENT: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:172:11

Check failure on line 172 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to load private key: Failed to read or parse file: ENOENT: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:172:11

Check failure on line 172 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to load private key: Failed to read or parse file: ENOENT: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:172:11

Check failure on line 172 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to load private key: Failed to read or parse file: ENOENT: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:172:11

Check failure on line 172 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to load private key: Failed to read or parse file: ENOENT: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:172:11

Check failure on line 172 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to load private key: Failed to read or parse file: ENOENT: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:172:11

Check failure on line 172 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to load private key: Failed to read or parse file: ENOENT: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:172:11
}
}

Expand Down Expand Up @@ -215,7 +215,7 @@
const publicKey = pemToPublicKey(keyData)
return publicKey
} catch (error: any) {
throw new Error(`Failed to load public key: ${error.message}`)

Check failure on line 218 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to load public key: Failed to read or parse file: ENOENT: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:218:11

Check failure on line 218 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to load public key: Failed to read or parse file: ENOENT: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:218:11

Check failure on line 218 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to load public key: Failed to read or parse file: ENOENT: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:218:11

Check failure on line 218 in packages/auto-id/src/keyManagement.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: Failed to load public key: Failed to read or parse file: ENOENT: No such file or directory

at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/src/keyManagement.ts:218:11
}
}

Expand Down Expand Up @@ -286,4 +286,4 @@

// Compare the serialized public key data
return publicKey1Der.equals(publicKey2Der)
}
}
7 changes: 3 additions & 4 deletions packages/auto-id/tests/keyManagement.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect, test } from '@jest/globals'
import { KeyObject, createPrivateKey, createPublicKey } from 'crypto'
import { promises as fs } from 'fs'
import * as path from 'path'
import { KeyObject, createPrivateKey, createPublicKey } from 'node:crypto'
import { promises as fs } from 'node:fs'
import * as path from 'node:path'
import {
doPublicKeysMatch,
generateEd25519KeyPair,
Expand Down Expand Up @@ -49,7 +48,7 @@

expect(keyToPem(privateKeyObject)).toStrictEqual(privateKey)
expect(keyToPem(privateKeyObject, 'subspace')).not.toEqual(privateKey) // unequal because of password encryption
expect(keyToPem(publicKeyObject)).toStrictEqual(publicKey)

Check failure on line 51 in packages/auto-id/tests/keyManagement.test.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: expect(received).toStrictEqual(expected)

Expected: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAWY84xKhBY/bHWa4swWBHoE+bcAxzR1my7777H87UOec=\n-----END PUBLIC KEY-----\n" Received: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n-----END PUBLIC KEY-----\n" at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/tests/keyManagement.test.ts:51:5

Check failure on line 51 in packages/auto-id/tests/keyManagement.test.ts

View workflow job for this annotation

GitHub Actions / Build all packages and run tests

error: expect(received).toStrictEqual(expected)

Expected: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAol26MU46xpSuqqvFvDI0PaOEBt+FzzfodWWHE8G66Kg=\n-----END PUBLIC KEY-----\n" Received: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAAgAAAAEAAAAQAAAAAQAAABAAAAAAAAAAAAAAAAAAAAA=\n-----END PUBLIC KEY-----\n" at /home/runner/work/auto-sdk/auto-sdk/packages/auto-id/tests/keyManagement.test.ts:51:5
})
})

Expand Down
18 changes: 11 additions & 7 deletions packages/auto-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"version": "0.1.0",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"test": "jest"
"build": "bun build ./src/index.ts --outdir ./dist --target node",
"clean": "rm -rf dist",
"format": "prettier --write \"src/**/*.ts\"",
"test": "bun test"
},
"files": [
"dist",
Expand All @@ -14,11 +16,13 @@
"@polkadot/api": "^11.2.1",
"fs": "^0.0.1-security"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"ts-jest": "^29.1.4",
"typescript": "^5.4.5"
"repository": {
"type": "git",
"url": "https://github.com/subspace/auto-sdk"
},
"author": {
"name": "Autonomys",
"url": "https://www.autonomys.net"
},
"browser": {
"fs": false
Expand Down
6 changes: 3 additions & 3 deletions packages/auto-utils/src/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export const readFromLocalStorage = async (key: string) => {
export const readFromFileSystem = async (key: string) => {
if (typeof window === 'undefined') {
// read from file system
const fs = await import('fs/promises')
const fs = await import('node:fs/promises')
try {
const data = await fs.readFile(key, { encoding: 'utf-8' })
return JSON.parse(data);
return JSON.parse(data)
} catch (error) {
throw new Error('Failed to read or parse file: ' + error)
}
} else throw new Error('This function can only be used in node')
}
}
6 changes: 3 additions & 3 deletions packages/auto-utils/src/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export const saveOnLocalStorage = async (key: string, value: any) => {
export const saveOnFileSystem = async (key: string, value: any) => {
if (typeof window === 'undefined') {
// save on file system
const fs = await import('fs/promises')
const fs = await import('node:fs/promises')
// Check if value is already a string to avoid unnecessary JSON string conversion
const data = typeof value === 'string' ? value : JSON.stringify(value);
const data = typeof value === 'string' ? value : JSON.stringify(value)
await fs.writeFile(key, JSON.stringify(data))
} else throw new Error('This function can only be used in node')
}
}
2 changes: 1 addition & 1 deletion scripts/localhost-run-test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LOCALHOST="true"
export LOCALHOST

yarn test
bun test
Loading
Loading