@u4/opencv4nodejs
Advanced tools
Comparing version 6.0.7 to 6.0.8
@@ -61,4 +61,10 @@ "use strict"; | ||
.concat('-Wl,-rpath,' + libDir); | ||
npmlog_1.default.info('libs', `${os_1.EOL}Setting the following libs:`); | ||
libs.forEach(lib => npmlog_1.default.info('libs', '' + lib)); | ||
if (libs.length > 0) { | ||
const dir = path_1.default.dirname(libs[0]); | ||
const names = libs.map(lib => path_1.default.basename(lib)); | ||
npmlog_1.default.info('libs', `${os_1.EOL}Setting lib from ${picocolors_1.default.green(dir)} : ${names.map(picocolors_1.default.yellow).join(', ')}`); | ||
} | ||
else { | ||
npmlog_1.default.info('libs', `${os_1.EOL}no Libs available`); | ||
} | ||
return libs; | ||
@@ -82,6 +88,31 @@ } | ||
: [(0, commons_1.resolvePath)(env.opencvInclude), (0, commons_1.resolvePath)(env.opencv4Include)]; | ||
npmlog_1.default.info('install', '${EOL}setting the following includes:'); | ||
npmlog_1.default.info('install', `${os_1.EOL}setting the following includes:`); | ||
includes.forEach(inc => npmlog_1.default.info('includes', picocolors_1.default.green(inc))); | ||
return includes; | ||
} | ||
function getExistingNodeModulesBin(dir, name) { | ||
const binPath = path_1.default.join(dir, 'node_modules', '.bin', name); | ||
if (fs_1.default.existsSync(binPath)) { | ||
return binPath; | ||
} | ||
return ''; | ||
} | ||
function getExistingBin(dir, name) { | ||
const binPath = path_1.default.join(dir, name); | ||
if (fs_1.default.existsSync(binPath)) { | ||
return binPath; | ||
} | ||
return ''; | ||
} | ||
function getParents(dir) { | ||
const out = [dir]; | ||
while (true) { | ||
const next = path_1.default.resolve(dir, '..'); | ||
if (next === dir) | ||
break; | ||
dir = next; | ||
out.push(dir); | ||
} | ||
return out; | ||
} | ||
async function compileLib(args) { | ||
@@ -91,3 +122,3 @@ let dryRun = false; | ||
if (args.includes('--help') || args.includes('-h') || !args.includes('build')) { | ||
console.log('Usage: install [--version=<version>] [--dry-run] [--flags=<flags>] [--cuda] [--nocontrib] [--nobuild] build'); | ||
console.log('Usage: install [--version=<version>] [--electron] [--dry-run] [--flags=<flags>] [--cuda] [--nocontrib] [--nobuild] build'); | ||
console.log((0, opencv_build_1.genHelp)()); | ||
@@ -112,3 +143,2 @@ return; | ||
*/ | ||
// builder.env.applyEnvsFromPackageJson() | ||
const libDir = getLibDir(builder.env); | ||
@@ -140,4 +170,2 @@ npmlog_1.default.info('install', 'Using lib dir: ' + libDir); | ||
flags += ` --jobs ${JOBS}`; | ||
// const arch = 'x86_64' | ||
// const arch = 'x64' | ||
const cwd = path_1.default.join(__dirname, '..'); | ||
@@ -149,6 +177,38 @@ const hidenGyp = path_1.default.join(cwd, '_binding.gyp'); | ||
} | ||
// const nodegypCmd = `node-gyp rebuild --arch=${arch} --target_arch=${arch} ` + flags | ||
// const nodegypCmd = `node-gyp --help`; | ||
const nodegypCmd = `node-gyp rebuild ` + flags; | ||
npmlog_1.default.info('install', `Spawning in ${cwd} node gyp process: ${nodegypCmd}`); | ||
// const arch = 'x86_64' / 'x64' | ||
// flags += --arch=${arch} --target_arch=${arch} | ||
let nodegypCmd = ''; | ||
const nodegyp = options.extra.electron ? 'electron-rebuild' : 'node-gyp'; | ||
for (const dir of process.env.PATH.split(path_1.default.delimiter)) { | ||
nodegypCmd = getExistingBin(dir, nodegyp); | ||
if (nodegypCmd) { | ||
// no need to use full path | ||
nodegypCmd = nodegyp; | ||
break; | ||
} | ||
} | ||
if (!nodegypCmd) { | ||
for (const startDir in [__dirname, process.cwd()]) { | ||
let dir = startDir; | ||
while (dir) { | ||
nodegypCmd = getExistingNodeModulesBin(dir, nodegyp); | ||
if (nodegypCmd) | ||
break; | ||
const next = path_1.default.resolve(dir, '..'); | ||
if (next === dir) { | ||
break; | ||
} | ||
dir = next; | ||
} | ||
if (nodegypCmd) | ||
break; | ||
} | ||
} | ||
if (!nodegypCmd) { | ||
const msg = `Please install "${nodegyp}" to build openCV bindings${os_1.EOL}npm install --save-dev ${nodegyp}`; | ||
throw Error(msg); | ||
} | ||
// flags starts with ' ' | ||
nodegypCmd += ` rebuild${flags}`; | ||
npmlog_1.default.info('install', `Spawning in directory:${cwd} node-gyp process: ${nodegypCmd}`); | ||
if (dryRun) { | ||
@@ -166,8 +226,9 @@ console.log(''); | ||
fs_1.default.unlinkSync(realGyp); | ||
const bin = options.extra.electron ? 'electron-rebuild' : 'node-gyp'; | ||
if (error) { | ||
console.log(`error: `, error); | ||
npmlog_1.default.error('install', `install.ts failed and return ${error.name} ${error.message} return code: ${error.code}`); | ||
npmlog_1.default.error('install', `${bin} failed and return ${error.name} ${error.message} return code: ${error.code}`); | ||
} | ||
else { | ||
npmlog_1.default.info('install', 'install.ts complet with no error'); | ||
npmlog_1.default.info('install', `${bin} complete successfully`); | ||
} | ||
@@ -174,0 +235,0 @@ }); |
@@ -59,4 +59,10 @@ import { OpencvModule, OpenCVBuilder, OpenCVBuildEnv, OpenCVBuildEnvParams, args2Option, genHelp } from '@u4/opencv-build' | ||
.concat('-Wl,-rpath,' + libDir) | ||
log.info('libs', `${EOL}Setting the following libs:`) | ||
libs.forEach(lib => log.info('libs', '' + lib)) | ||
if (libs.length > 0) { | ||
const dir = path.dirname(libs[0]); | ||
const names = libs.map(lib => path.basename(lib)) | ||
log.info('libs', `${EOL}Setting lib from ${pc.green(dir)} : ${names.map(pc.yellow).join(', ')}`) | ||
} else { | ||
log.info('libs', `${EOL}no Libs available`) | ||
} | ||
return libs; | ||
@@ -82,3 +88,3 @@ } | ||
: [resolvePath(env.opencvInclude), resolvePath(env.opencv4Include)] | ||
log.info('install', '${EOL}setting the following includes:') | ||
log.info('install', `${EOL}setting the following includes:`) | ||
includes.forEach(inc => log.info('includes', pc.green(inc))) | ||
@@ -88,2 +94,31 @@ return includes; | ||
function getExistingNodeModulesBin(dir: string, name: string): string { | ||
const binPath = path.join(dir, 'node_modules', '.bin', name); | ||
if (fs.existsSync(binPath)) { | ||
return binPath; | ||
} | ||
return ''; | ||
} | ||
function getExistingBin(dir: string, name: string): string { | ||
const binPath = path.join(dir, name); | ||
if (fs.existsSync(binPath)) { | ||
return binPath; | ||
} | ||
return ''; | ||
} | ||
function getParents(dir: string) { | ||
const out = [dir]; | ||
while (true) { | ||
const next = path.resolve(dir, '..'); | ||
if (next === dir) | ||
break; | ||
dir = next; | ||
out.push(dir); | ||
} | ||
return out; | ||
} | ||
export async function compileLib(args: string[]) { | ||
@@ -94,3 +129,3 @@ let dryRun = false; | ||
if (args.includes('--help') || args.includes('-h') || !args.includes('build')) { | ||
console.log('Usage: install [--version=<version>] [--dry-run] [--flags=<flags>] [--cuda] [--nocontrib] [--nobuild] build'); | ||
console.log('Usage: install [--version=<version>] [--electron] [--dry-run] [--flags=<flags>] [--cuda] [--nocontrib] [--nobuild] build'); | ||
console.log(genHelp()); | ||
@@ -100,2 +135,3 @@ return; | ||
const options: OpenCVBuildEnvParams = args2Option(args) | ||
dryRun = (args.includes('--dry-run') || args.includes('--dryrun')); | ||
@@ -107,3 +143,3 @@ let njobs = args.indexOf('--jobs') | ||
JOBS = args[njobs + 1]; | ||
for (const K in ['autoBuildFlags']) { | ||
@@ -117,3 +153,2 @@ if (options[K]) console.log(`using ${K}:`, options[K]); | ||
*/ | ||
// builder.env.applyEnvsFromPackageJson() | ||
const libDir: string = getLibDir(builder.env); | ||
@@ -147,4 +182,2 @@ log.info('install', 'Using lib dir: ' + libDir) | ||
// const arch = 'x86_64' | ||
// const arch = 'x64' | ||
const cwd = path.join(__dirname, '..'); | ||
@@ -157,8 +190,43 @@ const hidenGyp = path.join(cwd, '_binding.gyp'); | ||
// const arch = 'x86_64' / 'x64' | ||
// flags += --arch=${arch} --target_arch=${arch} | ||
let nodegypCmd = '' | ||
// const nodegypCmd = `node-gyp rebuild --arch=${arch} --target_arch=${arch} ` + flags | ||
// const nodegypCmd = `node-gyp --help`; | ||
const nodegypCmd = `node-gyp rebuild ` + flags | ||
log.info('install', `Spawning in ${cwd} node gyp process: ${nodegypCmd}`) | ||
const nodegyp = options.extra.electron ? 'electron-rebuild' : 'node-gyp'; | ||
for (const dir of process.env.PATH.split(path.delimiter)) { | ||
nodegypCmd = getExistingBin(dir, nodegyp); | ||
if (nodegypCmd) { | ||
// no need to use full path | ||
nodegypCmd = nodegyp; | ||
break; | ||
} | ||
} | ||
if (!nodegypCmd) { | ||
for (const startDir in [__dirname, process.cwd()]) { | ||
let dir = startDir; | ||
while (dir) { | ||
nodegypCmd = getExistingNodeModulesBin(dir, nodegyp); | ||
if (nodegypCmd) | ||
break; | ||
const next = path.resolve(dir, '..'); | ||
if (next === dir) { | ||
break; | ||
} | ||
dir = next; | ||
} | ||
if (nodegypCmd) | ||
break; | ||
} | ||
} | ||
if (!nodegypCmd) { | ||
const msg = `Please install "${nodegyp}" to build openCV bindings${EOL}npm install --save-dev ${nodegyp}`; | ||
throw Error(msg) | ||
} | ||
// flags starts with ' ' | ||
nodegypCmd += ` rebuild${flags}`; | ||
log.info('install', `Spawning in directory:${cwd} node-gyp process: ${nodegypCmd}`) | ||
if (dryRun) { | ||
@@ -175,7 +243,8 @@ console.log(''); | ||
fs.unlinkSync(realGyp); | ||
const bin = options.extra.electron ? 'electron-rebuild' : 'node-gyp'; | ||
if (error) { | ||
console.log(`error: `, error); | ||
log.error('install', `install.ts failed and return ${error.name} ${error.message} return code: ${error.code}`); | ||
log.error('install', `${bin} failed and return ${error.name} ${error.message} return code: ${error.code}`); | ||
} else { | ||
log.info('install', 'install.ts complet with no error'); | ||
log.info('install', `${bin} complete successfully`); | ||
} | ||
@@ -182,0 +251,0 @@ }) |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolvePath = void 0; | ||
exports.isElectronWebpack = exports.resolvePath = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
@@ -16,1 +16,11 @@ function resolvePath(filePath, file) { | ||
exports.resolvePath = resolvePath; | ||
/** | ||
* detect if electron https://github.com/electron/electron/issues/2288 | ||
*/ | ||
function isElectronWebpack() { | ||
// assume module required by webpack if no system path inv envs | ||
return !process.env.path | ||
&& global.window && global.window.process && global.window.process.type | ||
&& global.navigator && ((global.navigator.userAgent || '').toLowerCase().indexOf(' electron/') > -1); | ||
} | ||
exports.isElectronWebpack = isElectronWebpack; |
@@ -9,1 +9,11 @@ import path from 'path' | ||
} | ||
/** | ||
* detect if electron https://github.com/electron/electron/issues/2288 | ||
*/ | ||
export function isElectronWebpack() { | ||
// assume module required by webpack if no system path inv envs | ||
return !process.env.path | ||
&& global.window && global.window.process && (global.window.process as any).type | ||
&& global.navigator && ((global.navigator.userAgent || '').toLowerCase().indexOf(' electron/') > -1) | ||
} |
@@ -42,3 +42,9 @@ "use strict"; | ||
let opencvBuild = null; | ||
const requirePath = path_1.default.join(__dirname, process.env.BINDINGS_DEBUG ? '../build/Debug/opencv4nodejs' : '../build/Release/opencv4nodejs'); | ||
let requirePath = ''; | ||
if ((0, commons_1.isElectronWebpack)()) { | ||
requirePath = '../build/Release/opencv4nodejs.node'; | ||
} | ||
else { | ||
requirePath = path_1.default.join(__dirname, process.env.BINDINGS_DEBUG ? '../build/Debug/opencv4nodejs' : '../build/Release/opencv4nodejs'); | ||
} | ||
try { | ||
@@ -45,0 +51,0 @@ logDebug('require', `require path is ${picocolors_1.default.yellow(requirePath)}`); |
@@ -5,3 +5,3 @@ import { OpenCVBuilder } from '@u4/opencv-build'; | ||
import path from 'path'; | ||
import { resolvePath } from './commons'; | ||
import { isElectronWebpack, resolvePath } from './commons'; | ||
import pc from 'picocolors' | ||
@@ -48,3 +48,8 @@ import { info } from 'npmlog'; | ||
let opencvBuild = null | ||
const requirePath = path.join(__dirname, process.env.BINDINGS_DEBUG ? '../build/Debug/opencv4nodejs' : '../build/Release/opencv4nodejs') | ||
let requirePath = ''; | ||
if (isElectronWebpack()) { | ||
requirePath = '../build/Release/opencv4nodejs.node'; | ||
} else { | ||
requirePath = path.join(__dirname, process.env.BINDINGS_DEBUG ? '../build/Debug/opencv4nodejs' : '../build/Release/opencv4nodejs') | ||
} | ||
try { | ||
@@ -51,0 +56,0 @@ logDebug('require', `require path is ${pc.yellow(requirePath)}`) |
@@ -9,9 +9,2 @@ "use strict"; | ||
function loadOpenCV(opt) { | ||
//const isElectronWebpack = | ||
// // assume module required by webpack if no system path inv envs | ||
// !process.env.path | ||
// // detect if electron https://github.com/electron/electron/issues/2288 | ||
// && global.window && global.window.process && (global.window.process as any).type | ||
// && global.navigator && ((global.navigator.userAgent || '').toLowerCase().indexOf(' electron/') > -1) | ||
// let cvBase = isElectronWebpack ? require('../build/Release/opencv4nodejs.node') : require('./cvloader') | ||
const cvBase = (0, cvloader_1.default)(opt); | ||
@@ -34,3 +27,3 @@ if (!cvBase.accumulate) { | ||
const defExport = { cv }; | ||
// duplucate all export for retrocompatibility | ||
// duplicate all export for retro-compatibility | ||
for (const key in cv) { | ||
@@ -37,0 +30,0 @@ defExport[key] = cv[key]; |
@@ -8,9 +8,2 @@ import { OpenCVBuildEnvParams } from '@u4/opencv-build'; | ||
function loadOpenCV(opt?: OpenCVBuildEnvParams): typeof openCV { | ||
//const isElectronWebpack = | ||
// // assume module required by webpack if no system path inv envs | ||
// !process.env.path | ||
// // detect if electron https://github.com/electron/electron/issues/2288 | ||
// && global.window && global.window.process && (global.window.process as any).type | ||
// && global.navigator && ((global.navigator.userAgent || '').toLowerCase().indexOf(' electron/') > -1) | ||
// let cvBase = isElectronWebpack ? require('../build/Release/opencv4nodejs.node') : require('./cvloader') | ||
const cvBase = raw(opt); | ||
@@ -35,3 +28,3 @@ if (!cvBase.accumulate) { | ||
const defExport = { cv }; | ||
// duplucate all export for retrocompatibility | ||
// duplicate all export for retro-compatibility | ||
for (const key in cv) { | ||
@@ -38,0 +31,0 @@ defExport[key] = cv[key]; |
{ | ||
"name": "@u4/opencv4nodejs", | ||
"version": "6.0.7", | ||
"description": "Asynchronous OpenCV 3.x nodejs bindings with JavaScript and TypeScript API.", | ||
"version": "6.0.8", | ||
"description": "Asynchronous OpenCV 3.x / 4.x nodejs bindings with JavaScript and TypeScript API.", | ||
"keywords": [ | ||
@@ -53,3 +53,3 @@ "opencv", | ||
"dependencies": { | ||
"@u4/opencv-build": "^0.4.1", | ||
"@u4/opencv-build": "^0.4.2", | ||
"nan": "^2.15.0", | ||
@@ -56,0 +56,0 @@ "native-node-utils": "^0.2.7", |
@@ -7,8 +7,8 @@ # @u4/opencv4nodejs | ||
- Node-gyp is not run at setup time, It must be launch from the project that includ the lib. | ||
- `build-opencv` binary must be call to build the project before usage. | ||
- I recomand you to only define an global OPENCV_BUILD_ROOT=~/opencv to boost you develepoment speed and reduce you hard disk usage. | ||
- `node-gyp` is not run during `npm install`, It must be launch from the project with `build-opencv`. (if you forgot to do so some help message will assis you :wink:) | ||
- All javascript code had been converted to Typesscript. | ||
- This version depend on [@u4/opencv-build](https://www.npmjs.com/package/@u4/opencv-build). | ||
- This version had been test under windows environnement. | ||
- This version do not work with electron. | ||
- This version had been test under windows / MacOs X / Debian environnement. | ||
- This version **Works** with new elecron. | ||
@@ -120,3 +120,3 @@ ![opencv4nodejs](https://user-images.githubusercontent.com/31125521/37272906-67187fdc-25d8-11e8-9704-40e9e94c1e80.jpg) | ||
``` bash | ||
npm install --save opencv4nodejs | ||
npm install --save @u4/opencv4nodejs | ||
``` | ||
@@ -211,3 +211,3 @@ | ||
"dependencies": { | ||
"opencv4nodejs": "^X.X.X" | ||
"@u4/opencv4nodejs": "^X.X.X" | ||
}, | ||
@@ -254,8 +254,8 @@ "opencv4nodejs": { | ||
### [opencv-electron](https://github.com/justadudewhohacks/opencv-electron) - example for opencv4nodejs with electron | ||
### [opencv-electron](https://github.com/urielch/opencv-electron) - example for opencv4nodejs with electron | ||
Add the following script to your package.json: | ||
``` python | ||
"electron-rebuild": "electron-rebuild -w opencv4nodejs" | ||
```python | ||
"electron-rebuild": "build-opencv --electron --version 4.5.4 build" | ||
``` | ||
@@ -265,3 +265,3 @@ | ||
``` bash | ||
```bash | ||
npm run electron-rebuild | ||
@@ -273,3 +273,3 @@ ``` | ||
``` javascript | ||
const cv = require('opencv4nodejs'); | ||
const cv = require('@u4/opencv4nodejs'); | ||
``` | ||
@@ -286,3 +286,3 @@ | ||
``` javascript | ||
const cv = require('opencv4nodejs'); | ||
const cv = require('@u4/opencv4nodejs'); | ||
``` | ||
@@ -295,3 +295,3 @@ | ||
``` javascript | ||
const cv = require('opencv4nodejs'); | ||
const cv = require('@u4/opencv4nodejs'); | ||
``` | ||
@@ -574,3 +574,3 @@ | ||
``` javascript | ||
import * as cv from 'opencv4nodejs' | ||
import * as cv from '@u4/opencv4nodejs' | ||
``` | ||
@@ -597,3 +597,3 @@ | ||
process.env.OPENCV4NODEJS_DISABLE_EXTERNAL_MEM_TRACKING = 1 | ||
const cv = require('opencv4nodejs') | ||
const cv = require('@u4/opencv4nodejs') | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13849281
356
3179
23
Updated@u4/opencv-build@^0.4.2