UrielCh/opencv4nodejs

Requires rebuild after every package install with yarn, multiple bugs in getOpenCV function

Opened this issue · 0 comments

Hi Uriel,

Great work with the library!

I am using yarn and I noticed that whenever I add or remove a package, yarn resets the node_modules package states. This results in the loss of release files and opencv4nodejs requires rebuilding everytime a package install takes place.

Even if I manually copy over the opencv4nodejs.node file to OPENCV_BIN_DIR (as this is the directory the getOpenCV function checks for), it does not work because the function does not look for the correct file path.

From what I could decipher, the getOpenCV function uses the below logic:

  1. Looks for Debug/opencv4nodejs.node inside node_modules/@u4/opencv4nodejs/build/, then looks for Release/opencv4nodejs.node inside the same folder

  2. In case the Release build is not found, it checks for process.env.path - this would work only on windows, I think this should be process.env.PATH:

    if (!process.env.path) {
    logDebug('require', 'there is no path environment variable, skipping...')
    throw err
    }
    On my linux machine, this is the exact block the execution ends up in, and does not proceed.

  3. Next. it tries to add OPENCV_BIN_DIR to process.env.path, I think path should be contactenated with the colon operator on linux and semicolon on windows (unless this part is meant only for windows):

    process.env.path = `${process.env.path};${opencvBinDir};`

  4. After path modification, it tries to require the exact same release build path it did in Step 1, without any modification to the path - This is guaranteed to fail, are we trying to look for OPENCV_BIN_DIR/opencv4nodejs.node instead of node_modules/@u4/opencv4nodejs/build/Release/opencv4nodejs.node at this point?

I am not sure if the above logic is written as it was meant to be. Also, I would highly recommend making the output directory for node-gyp used within the package configurable via an environment variable and using the same environment variable to check for the build files existence in getOpenCV.

Kindly look into this.