Skip to content

Commit

Permalink
docs(nodejs-addon-examples): add guide for pnpm user (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
YogiLiu authored Oct 9, 2024
1 parent d468527 commit 9765412
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
14 changes: 13 additions & 1 deletion nodejs-addon-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,31 @@ Note: [../nodejs-examples](../nodejs-examples) uses WebAssembly to wrap
Before you continue, please first run

```bash
npm install
npm install # or pnpm install

# For macOS x64
## With npm
export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-x64:$DYLD_LIBRARY_PATH
## With pnpm
export DYLD_LIBRARY_PATH=$PWD/node_modules/.pnpm/sherpa-onnx-node@<REPLACE-THIS-WITH-THE-INSTALLED-VERSION>/node_modules/sherpa-onnx-darwin-x64:$DYLD_LIBRARY_PATH

# For macOS arm64
## With npm
export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-arm64:$DYLD_LIBRARY_PATH
## With pnpm
export DYLD_LIBRARY_PATH=$PWD/node_modules/.pnpm/sherpa-onnx-node@<REPLACE-THIS-WITH-THE-INSTALLED-VERSION>/node_modules/sherpa-onnx-darwin-arm64:$DYLD_LIBRARY_PATH

# For Linux x64
## With npm
export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-x64:$LD_LIBRARY_PATH
## With pnpm
export LD_LIBRARY_PATH=$PWD/node_modules/.pnpm/sherpa-onnx-node@<REPLACE-THIS-WITH-THE-INSTALLED-VERSION>/node_modules/sherpa-onnx-linux-x64:$LD_LIBRARY_PATH

# For Linux arm64, e.g., Raspberry Pi 4
## With npm
export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-arm64:$LD_LIBRARY_PATH
## With pnpm
export LD_LIBRARY_PATH=$PWD/node_modules/.pnpm/sherpa-onnx-node@<REPLACE-THIS-WITH-THE-INSTALLED-VERSION>/node_modules/sherpa-onnx-linux-arm64:$LD_LIBRARY_PATH
```

# Examples
Expand Down
15 changes: 11 additions & 4 deletions scripts/node-addon-api/lib/addon.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const os = require('os');
const path = require('path');

// Package name triggered spam for sherpa-onnx-win32-x64
// so we have renamed it to sherpa-onnx-win-x64
Expand All @@ -25,6 +26,14 @@ for (const p of possible_paths) {
}

if (!found) {
let addon_path = `${process.env.PWD}/node_modules/sherpa-onnx-${platform_arch}`;
const pnpmIndex = __dirname.indexOf(`node_modules${path.sep}.pnpm`);
if (pnpmIndex !== -1) {
const parts = __dirname.slice(pnpmIndex).split(path.sep);
parts.pop();
addon_path = `${process.env.PWD}/${parts.join('/')}/sherpa-onnx-${platform_arch}`;
}

let msg = `Could not find sherpa-onnx-node. Tried\n\n ${
possible_paths.join('\n ')}\n`
if (os.platform() == 'darwin' &&
Expand All @@ -34,8 +43,7 @@ if (!found) {
msg +=
'Please remeber to set the following environment variable and try again:\n';

msg += `export DYLD_LIBRARY_PATH=${
process.env.PWD}/node_modules/sherpa-onnx-${platform_arch}`;
msg += `export DYLD_LIBRARY_PATH=${addon_path}`;

msg += ':$DYLD_LIBRARY_PATH\n';
}
Expand All @@ -47,8 +55,7 @@ if (!found) {
msg +=
'Please remeber to set the following environment variable and try again:\n';

msg += `export LD_LIBRARY_PATH=${
process.env.PWD}/node_modules/sherpa-onnx-${platform_arch}`;
msg += `export LD_LIBRARY_PATH=${addon_path}`;

msg += ':$LD_LIBRARY_PATH\n';
}
Expand Down

0 comments on commit 9765412

Please sign in to comment.