Skip to content
Merged
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
16 changes: 11 additions & 5 deletions packages/helper/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# `@node-rs/helper`

> Helper library for node-rs
[![install size](https://packagephobia.com/badge?p=@node-rs/helper)](https://packagephobia.com/result?p=@node-rs/helper)
[![Downloads](https://img.shields.io/npm/dm/@node-rs/helper.svg?sanitize=true)](https://npmcharts.com/compare/@node-rs/helper?minimal=true)

> Helper library for load native package.

## Usage

Expand All @@ -9,14 +12,17 @@
Load native binding file from `dirname`

```ts
locateBinding(dirname: string): string
loadBinding(dirname: string, filename?: string = 'index', packageName?: string): string
```

- `dirname`, dirname which the **.node** binding file located
- return the full path of the binding file, throw if file not existed or platform not supported
- `filename`, the `napi.name` filed in you `package.json`
- `packageName`, the `name` filed in your `package.json`, `@swc/core` for example.

- return native module

```ts
const { locateBinding } = require('@node-rs/helper')
const { loadBinding } = require('@node-rs/helper')

module.exports = require(locateBinding(__dirname))
module.exports = loadBinding(__dirname, 'swc', '@swc/core')
```
3 changes: 0 additions & 3 deletions packages/helper/npm/darwin-x64/README.md

This file was deleted.

24 changes: 0 additions & 24 deletions packages/helper/npm/darwin-x64/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/helper/npm/linux-x64-gnu/README.md

This file was deleted.

24 changes: 0 additions & 24 deletions packages/helper/npm/linux-x64-gnu/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/helper/npm/win32-x64-msvc/README.md

This file was deleted.

24 changes: 0 additions & 24 deletions packages/helper/npm/win32-x64-msvc/package.json

This file was deleted.

3 changes: 1 addition & 2 deletions packages/helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"build": "exit 0;"
},
"dependencies": {
"@napi-rs/triples": "^1.0.2",
"tslib": "^2.3.0"
"@napi-rs/triples": "^1.0.3"
}
}
6 changes: 5 additions & 1 deletion packages/helper/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export function loadBinding(dirname: string, filename = 'index', packageName?: s
}
const localFilePath = join(dirname, `${filename}.${triple.platformArchABI}.node`)
if (existsSync(localFilePath)) {
return require(localFilePath)
try {
return require(localFilePath)
} catch (e) {
additionalErrorMsg += `file: ${localFilePath} existed but error occurred while require it: ${e.message ?? e} \n`
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/helper/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"compilerOptions": {
"outDir": "lib",
"rootDir": "./src",
"composite": true
"composite": true,
"sourceMap": false,
"inlineSourceMap": false,
"noEmitHelpers": false,
"importHelpers": false
},
"include": ["./src"]
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -967,10 +967,10 @@
toml "^3.0.0"
tslib "^2.2.0"

"@napi-rs/triples@^1.0.2":
version "1.0.2"
resolved "https://registry.npmjs.org/@napi-rs/triples/-/triples-1.0.2.tgz#2ce4c6a78568358772008f564ee5009093d20a19"
integrity sha512-EL3SiX43m9poFSnhDx4d4fn9SSaqyO2rHsCNhETi9bWPmjXK3uPJ0QpPFtx39FEdHcz1vJmsiW41kqc0AgvtzQ==
"@napi-rs/triples@^1.0.3":
version "1.0.3"
resolved "https://registry.npmjs.org/@napi-rs/triples/-/triples-1.0.3.tgz#76d6d0c3f4d16013c61e45dfca5ff1e6c31ae53c"
integrity sha512-jDJTpta+P4p1NZTFVLHJ/TLFVYVcOqv6l8xwOeBKNPMgY/zDYH/YH7SJbvrr/h1RcS9GzbPcLKGzpuK9cV56UA==

"@nodelib/fs.scandir@2.1.5":
version "2.1.5"
Expand Down