Yongzeng Liu
Committed by GitHub

docs(nodejs-addon-examples): add guide for pnpm user (#1401)

@@ -12,19 +12,31 @@ Note: [../nodejs-examples](../nodejs-examples) uses WebAssembly to wrap @@ -12,19 +12,31 @@ Note: [../nodejs-examples](../nodejs-examples) uses WebAssembly to wrap
12 Before you continue, please first run 12 Before you continue, please first run
13 13
14 ```bash 14 ```bash
15 -npm install 15 +npm install # or pnpm install
16 16
17 # For macOS x64 17 # For macOS x64
  18 +## With npm
18 export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-x64:$DYLD_LIBRARY_PATH 19 export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-x64:$DYLD_LIBRARY_PATH
  20 +## With pnpm
  21 +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
19 22
20 # For macOS arm64 23 # For macOS arm64
  24 +## With npm
21 export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-arm64:$DYLD_LIBRARY_PATH 25 export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-arm64:$DYLD_LIBRARY_PATH
  26 +## With pnpm
  27 +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
22 28
23 # For Linux x64 29 # For Linux x64
  30 +## With npm
24 export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-x64:$LD_LIBRARY_PATH 31 export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-x64:$LD_LIBRARY_PATH
  32 +## With pnpm
  33 +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
25 34
26 # For Linux arm64, e.g., Raspberry Pi 4 35 # For Linux arm64, e.g., Raspberry Pi 4
  36 +## With npm
27 export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-arm64:$LD_LIBRARY_PATH 37 export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-arm64:$LD_LIBRARY_PATH
  38 +## With pnpm
  39 +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
28 ``` 40 ```
29 41
30 # Examples 42 # Examples
1 const os = require('os'); 1 const os = require('os');
  2 +const path = require('path');
2 3
3 // Package name triggered spam for sherpa-onnx-win32-x64 4 // Package name triggered spam for sherpa-onnx-win32-x64
4 // so we have renamed it to sherpa-onnx-win-x64 5 // so we have renamed it to sherpa-onnx-win-x64
@@ -25,6 +26,14 @@ for (const p of possible_paths) { @@ -25,6 +26,14 @@ for (const p of possible_paths) {
25 } 26 }
26 27
27 if (!found) { 28 if (!found) {
  29 + let addon_path = `${process.env.PWD}/node_modules/sherpa-onnx-${platform_arch}`;
  30 + const pnpmIndex = __dirname.indexOf(`node_modules${path.sep}.pnpm`);
  31 + if (pnpmIndex !== -1) {
  32 + const parts = __dirname.slice(pnpmIndex).split(path.sep);
  33 + parts.pop();
  34 + addon_path = `${process.env.PWD}/${parts.join('/')}/sherpa-onnx-${platform_arch}`;
  35 + }
  36 +
28 let msg = `Could not find sherpa-onnx-node. Tried\n\n ${ 37 let msg = `Could not find sherpa-onnx-node. Tried\n\n ${
29 possible_paths.join('\n ')}\n` 38 possible_paths.join('\n ')}\n`
30 if (os.platform() == 'darwin' && 39 if (os.platform() == 'darwin' &&
@@ -34,8 +43,7 @@ if (!found) { @@ -34,8 +43,7 @@ if (!found) {
34 msg += 43 msg +=
35 'Please remeber to set the following environment variable and try again:\n'; 44 'Please remeber to set the following environment variable and try again:\n';
36 45
37 - msg += `export DYLD_LIBRARY_PATH=${  
38 - process.env.PWD}/node_modules/sherpa-onnx-${platform_arch}`; 46 + msg += `export DYLD_LIBRARY_PATH=${addon_path}`;
39 47
40 msg += ':$DYLD_LIBRARY_PATH\n'; 48 msg += ':$DYLD_LIBRARY_PATH\n';
41 } 49 }
@@ -47,8 +55,7 @@ if (!found) { @@ -47,8 +55,7 @@ if (!found) {
47 msg += 55 msg +=
48 'Please remeber to set the following environment variable and try again:\n'; 56 'Please remeber to set the following environment variable and try again:\n';
49 57
50 - msg += `export LD_LIBRARY_PATH=${  
51 - process.env.PWD}/node_modules/sherpa-onnx-${platform_arch}`; 58 + msg += `export LD_LIBRARY_PATH=${addon_path}`;
52 59
53 msg += ':$LD_LIBRARY_PATH\n'; 60 msg += ':$LD_LIBRARY_PATH\n';
54 } 61 }