()
| 42 | } |
| 43 | |
| 44 | function resolveBindingPath() { |
| 45 | // The addon is always named opencc.node and ships either as a local build |
| 46 | // (build/Release, also used by the node-gyp source build and the Bazel |
| 47 | // sandbox), as a prebuild under prebuilds/<platform>-<arch>/, or via an |
| 48 | // @opencc/opencc-<platform>-<arch> scoped package. A direct filesystem lookup |
| 49 | // replaces node-gyp-build (OpenCC ships a single N-API build per platform). |
| 50 | const candidates = [ |
| 51 | path.join(packageRoot, 'build', 'Release', 'opencc.node'), |
| 52 | path.join( |
| 53 | packageRoot, 'prebuilds', `${process.platform}-${process.arch}`, 'opencc.node' |
| 54 | ), |
| 55 | ]; |
| 56 | for (const candidate of candidates) { |
| 57 | if (fs.existsSync(candidate)) { |
| 58 | return candidate; |
| 59 | } |
| 60 | } |
| 61 | const scopedBinaryPackage = requireOptionalPackage( |
| 62 | `@opencc/opencc-${process.platform}-${process.arch}` |
| 63 | ); |
| 64 | if (scopedBinaryPackage && scopedBinaryPackage.binaryPath) { |
| 65 | return scopedBinaryPackage.binaryPath; |
| 66 | } |
| 67 | throw new Error( |
| 68 | 'Could not locate the opencc native addon (looked in build/Release, ' + |
| 69 | 'prebuilds/, and @opencc/opencc-* scoped packages)' |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | const bindingPath = resolveBindingPath(); |
| 74 | const binding = require(bindingPath); |
no test coverage detected