Skip to content

Commit 07ae0c0

Browse files
committed
feat: 📖 add basic test file for ls function
1 parent cba3742 commit 07ae0c0

File tree

10 files changed

+3271
-3325
lines changed

10 files changed

+3271
-3325
lines changed

‎.husky/pre-commit‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
yarn lint-staged
4+
pnpm lint-staged

‎__test__/index.spec.ts‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎__test__/ls.spec.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import test from 'ava'
2+
import { ls } from '../index.js'
3+
4+
test('ls should list files in current directory', (t) => {
5+
const files = ls('.')
6+
7+
// asserts
8+
t.true(Array.isArray(files))
9+
t.true(files.length > 0)
10+
t.true(
11+
files.some((f: string) => f.includes('package.json')),
12+
'Result should contain package.json',
13+
)
14+
})

‎__test__/package.json‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎index.js‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
// @ts-nocheck
44
/* auto-generated by NAPI-RS */
55

6-
const { createRequire } = require('node:module')
7-
require = createRequire(__filename)
8-
96
const { readFileSync } = require('node:fs')
107
let nativeBinding = null
118
const loadErrors = []
@@ -108,7 +105,24 @@ function requireNative() {
108105
}
109106
} else if (process.platform === 'win32') {
110107
if (process.arch === 'x64') {
108+
if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
109+
try {
110+
return require('./hyper-fs.win32-x64-gnu.node')
111+
} catch (e) {
112+
loadErrors.push(e)
113+
}
111114
try {
115+
const binding = require('hyper-fs-win32-x64-gnu')
116+
const bindingPackageVersion = require('hyper-fs-win32-x64-gnu/package.json').version
117+
if (bindingPackageVersion !== '1.0.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118+
throw new Error(`Native binding package version mismatch, expected 1.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
119+
}
120+
return binding
121+
} catch (e) {
122+
loadErrors.push(e)
123+
}
124+
} else {
125+
try {
112126
return require('./hyper-fs.win32-x64-msvc.node')
113127
} catch (e) {
114128
loadErrors.push(e)
@@ -123,6 +137,7 @@ function requireNative() {
123137
} catch (e) {
124138
loadErrors.push(e)
125139
}
140+
}
126141
} else if (process.arch === 'ia32') {
127142
try {
128143
return require('./hyper-fs.win32-ia32-msvc.node')

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@oxc-node/core": "^0.0.34",
6262
"@taplo/cli": "^0.7.0",
6363
"@tybys/wasm-util": "^0.10.0",
64+
"@types/node": "^20.0.0",
6465
"ava": "^6.4.1",
6566
"chalk": "^5.6.2",
6667
"husky": "^9.1.7",
@@ -103,5 +104,5 @@
103104
"singleQuote": true,
104105
"arrowParens": "always"
105106
},
106-
"packageManager": "yarn@4.12.0"
107+
"packageManager": "pnpm@9.15.0"
107108
}

0 commit comments

Comments
 (0)