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 6fb1e46
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 237 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ jobs:
" >> $GITHUB_OUTPUT
- name: Install dependencies
run: |
yarn add @swc/wasm -D
yarn config set --json supportedArchitectures.cpu '["current", "arm64", "arm", "ppc64le", "s390x", "x64"]'
yarn config set --json supportedArchitectures.libc '["glibc", "musl"]'
yarn install
- name: Download artifacts
uses: actions/download-artifact@v4
with:
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": []
}
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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 +62,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 +89,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 6fb1e46

Please sign in to comment.