Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Jul 21, 2024
1 parent 1b67218 commit 9e11ff3
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 241 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,21 @@ jobs:
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.cargo
~/.napi-rs
target/
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
- uses: goto-bus-stop/setup-zig@v2
if: ${{ contains(matrix.settings.target, 'musl') }}
with:
version: 0.13.0
- name: Install cargo-zigbuild
uses: taiki-e/install-action@v2
if: ${{ contains(matrix.settings.target, 'musl') }}
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tool: cargo-zigbuild
- name: Setup toolchain
run: ${{ matrix.settings.setup }}
if: ${{ matrix.settings.setup }}
Expand Down Expand Up @@ -253,6 +258,8 @@ jobs:
# too slow
- target: aarch64-unknown-linux-gnu
node: '18'
- target: s390x-unknown-linux-gnu
node: '18'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -286,12 +293,15 @@ jobs:
" >> $GITHUB_OUTPUT
- name: Install dependencies
run: |
yarn add @swc/wasm -D
yarn config set --json supportedArchitectures.os '["current", "linux"]'
yarn config set --json supportedArchitectures.cpu '["current", "arm64", "arm", "ppc64", "s390x", "x64"]'
yarn config set --json supportedArchitectures.libc '["current", "glibc", "musl"]'
yarn install
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bindings-${{ matrix.target }}
path: ./packages/core
path: .
- name: List packages
run: ls -R .
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { join } from 'node:path'
import test from 'ava'

import { Archive } from '../index'
import { fileURLToPath } from 'node:url'

const __dirname = join(fileURLToPath(import.meta.url), '..')

test('should be able to read archive', (t) => {
const archive = new Archive(join(__dirname, 'src.tar'))
Expand Down
3 changes: 3 additions & 0 deletions __test__/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
10 changes: 10 additions & 0 deletions __test__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
"outDir": "./dist"
},
"include": ["."],
"exclude": []
}
54 changes: 25 additions & 29 deletions benchmark/bench.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { readFileSync } from 'node:fs'
import { join } from 'node:path'

import b from 'benny'
import { Bench } from 'tinybench'
import { list } from 'tar'

import { Archive } from '../index'
import { fileURLToPath } from 'node:url'

const __dirname = join(fileURLToPath(import.meta.url), '..')

const ARCHIVE_PATH = join(__dirname, '..', '__test__', 'src.tar.gz')

Expand All @@ -22,33 +25,26 @@ for (const entry of archive.entries()) {
console.info('list from @napi-rs/tar', entry.path())
}

async function run() {
await b.suite(
'Read all entries',

b.add('@napi-rs/tar', () => {
const archiveBuffer = readFileSync(ARCHIVE_PATH)
const archive = new Archive(archiveBuffer)
for (const entry of archive.entries()) {
entry.path()
}
}),

b.add('node-tar', () => {
list({
file: join(__dirname, '..', '__test__', 'src.tar.gz'),
onentry: (entry) => {
entry.path
},
sync: true,
})
}),

b.cycle(),
b.complete(),
)
}
const b = new Bench()

b.add('@napi-rs/tar', () => {
const archiveBuffer = readFileSync(ARCHIVE_PATH)
const archive = new Archive(archiveBuffer)
for (const entry of archive.entries()) {
entry.path()
}
})

run().catch((e) => {
console.error(e)
b.add('node-tar', () => {
list({
file: join(__dirname, '..', '__test__', 'src.tar.gz'),
onentry: (entry) => {
entry.path
},
sync: true,
})
})

await b.run()

console.table(b.table())
3 changes: 3 additions & 0 deletions benchmark/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
5 changes: 5 additions & 0 deletions benchmark/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../__test__/tsconfig.json",
"include": ["."],
"exclude": []
}
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"aarch64-unknown-linux-musl",
"aarch64-pc-windows-msvc",
"armv7-linux-androideabi",
"powerpc64le-unknown-linux-gnu",
"s390x-unknown-linux-gnu",
"wasm32-wasip1-threads"
]
},
Expand All @@ -47,7 +49,7 @@
},
"scripts": {
"artifacts": "napi artifacts",
"bench": "node -r @swc-node/register benchmark/bench.ts",
"bench": "node --import @oxc-node/core/register benchmark/bench.ts",
"build": "napi build --platform --release",
"build:debug": "napi build --platform",
"format": "run-p format:prettier format:rs format:toml",
Expand All @@ -62,8 +64,7 @@
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.62",
"@napi-rs/lzma": "^1.3.0",
"@swc-node/register": "^1.9.0",
"@swc/core": "^1.4.17",
"@oxc-node/core": "^0.0.10",
"@taplo/cli": "^0.7.0",
"@types/node": "^20.12.7",
"@types/tar": "^6",
Expand All @@ -90,14 +91,15 @@
]
},
"ava": {
"require": [
"@swc-node/register"
],
"extensions": [
"ts"
],
"extensions": {
"ts": "module"
},
"timeout": "2m",
"workerThreads": false,
"nodeArguments": [
"--import",
"@oxc-node/core/register"
],
"environmentVariables": {
"TS_NODE_PROJECT": "./tsconfig.json"
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"allowSyntheticDefaultImports": true
},
"include": ["."],
"exclude": ["node_modules"]
"exclude": ["node_modules", "__test__", "benchmark"]
}
Loading

0 comments on commit 9e11ff3

Please sign in to comment.