|
1 | 1 | const path = require('path'); |
2 | | -const opencvBuild = require(`@nut-tree/opencv-build-${process.platform}`) |
3 | 2 | const { resolvePath } = require('./commons'); |
4 | 3 |
|
5 | 4 | const requirePath = path.join(__dirname, process.env.BINDINGS_DEBUG ? '../build/Debug/opencv4nodejs' : '../build/Release/opencv4nodejs') |
6 | 5 |
|
7 | 6 | const logDebug = process.env.OPENCV4NODES_DEBUG_REQUIRE ? require('npmlog').info : () => {} |
8 | 7 |
|
9 | | -function tryGetOpencvBinDir() { |
10 | | - if (process.env.OPENCV_BIN_DIR) { |
11 | | - logDebug('tryGetOpencvBinDir', 'OPENCV_BIN_DIR environment variable is set') |
12 | | - return process.env.OPENCV_BIN_DIR |
13 | | - } |
14 | | - // if the auto build is not disabled via environment do not even attempt |
15 | | - // to read package.json |
16 | | - if (!opencvBuild.isAutoBuildDisabled()) { |
17 | | - logDebug('tryGetOpencvBinDir', 'auto build has not been disabled via environment variable, using opencv bin dir of opencv-build') |
18 | | - return opencvBuild.opencvBinDir |
19 | | - } |
20 | | - |
21 | | - logDebug('tryGetOpencvBinDir', 'auto build has not been explicitly disabled via environment variable, attempting to read envs from package.json...') |
22 | | - const envs = opencvBuild.readEnvsFromPackageJson() |
23 | | - |
24 | | - if (!envs.disableAutoBuild) { |
25 | | - logDebug('tryGetOpencvBinDir', 'auto build has not been disabled via package.json, using opencv bin dir of opencv-build') |
26 | | - return opencvBuild.opencvBinDir |
27 | | - } |
28 | | - |
29 | | - if (envs.opencvBinDir) { |
30 | | - logDebug('tryGetOpencvBinDir', 'found opencv binary environment variable in package.json') |
31 | | - return envs.opencvBinDir |
32 | | - } |
33 | | - logDebug('tryGetOpencvBinDir', 'failed to find opencv binary environment variable in package.json') |
34 | | - return null |
35 | | -} |
36 | | - |
37 | 8 | let cv = null |
38 | 9 | try { |
39 | 10 | logDebug('require', 'require path is ' + requirePath) |
40 | 11 | cv = require(requirePath); |
41 | 12 | } catch (err) { |
42 | 13 | logDebug('require', 'failed to require cv with exception: ' + err.toString()) |
43 | | - logDebug('require', 'attempting to add opencv binaries to path') |
44 | | - |
45 | | - if (!process.env.path) { |
46 | | - logDebug('require', 'there is no path environment variable, skipping...') |
47 | | - throw err |
48 | | - } |
49 | | - |
50 | | - const opencvBinDir = tryGetOpencvBinDir() |
51 | | - logDebug('require', 'adding opencv binary dir to path: ' + opencvBinDir) |
52 | | - |
53 | | - // ensure binaries are added to path on windows |
54 | | - if (!process.env.path.includes(opencvBinDir)) { |
55 | | - process.env.path = `${process.env.path};${opencvBinDir};` |
56 | | - } |
57 | | - logDebug('require', 'process.env.path: ' + process.env.path) |
58 | | - cv = require(requirePath); |
| 14 | + throw err |
59 | 15 | } |
60 | 16 |
|
61 | 17 | // resolve haarcascade files |
|
0 commit comments