MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / resolveBindingPath

Function resolveBindingPath

node/opencc.js:44–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42}
43
44function 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
73const bindingPath = resolveBindingPath();
74const binding = require(bindingPath);

Callers 1

opencc.jsFile · 0.85

Calls 2

requireOptionalPackageFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected