fix(support): allow in addition to the old one, and promote it in doctor instead
MODIFY
packages/doctor/lib/general.js
packages/doctor/lib/general.js
@@ -50,7 +50,7 @@ checks.push(new NodeVersionCheck());
class OptionalOpencv4nodejsCommandCheck extends DoctorCheck {
async diagnose () {
- const packageName = 'opencv4nodejs';
+ const packageName = '@u4/opencv4nodejs';
const packageInfo = await getNpmPackageInfo(packageName);
if (packageInfo) {

MODIFY
packages/doctor/test/general-specs.js
packages/doctor/test/general-specs.js
@@ -88,10 +88,10 @@ describe('general', function () {
mocks.tp.expects('exec').once().returns({stdout: `
{
"dependencies": {
- "opencv4nodejs": {
+ "@u4/opencv4nodejs": {
"version": "4.13.0",
- "from": "opencv4nodejs",
- "resolved": "https://registry.npmjs.org/opencv4nodejs/-/opencv4nodejs-4.14.1.tgz"
+ "from": "@u4/opencv4nodejs",
+ "resolved": "https://registry.npmjs.org/@u4/opencv4nodejs/-/opencv4nodejs-4.14.1.tgz"
}
},
"path": "/path/to/node/node/v11.4.0/lib"
@@ -100,7 +100,7 @@ describe('general', function () {
(await check.diagnose()).should.deep.equal({
ok: true,
optional: true,
- message: 'opencv4nodejs is installed at: /path/to/node/node/v11.4.0/lib. Installed version is: 4.13.0'
+ message: '@u4/opencv4nodejs is installed at: /path/to/node/node/v11.4.0/lib. Installed version is: 4.13.0'
});
mocks.verify();
});
@@ -109,7 +109,7 @@ describe('general', function () {
(await check.diagnose()).should.deep.equal({
ok: false,
optional: true,
- message: 'opencv4nodejs cannot be found.'
+ message: '@u4/opencv4nodejs cannot be found.'
});
mocks.verify();
});

MODIFY
packages/support/lib/image-util.js
packages/support/lib/image-util.js
@@ -8,6 +8,10 @@ import log from './logger';
import { requirePackage } from './node';
+const OCV_OLD = 'opencv4nodejs';
+const OCV_NEW = '@u4/opencv4nodejs';
+
+
const { MIME_JPEG, MIME_PNG, MIME_BMP } = Jimp;
let cv = null;
@@ -127,16 +131,20 @@ async function initOpenCV () {
}
log.debug(`Initializing opencv`);
+ for (const ocvPackage of [OCV_OLD, OCV_NEW]) {
try {
- cv = await requirePackage('opencv4nodejs');
+ log.debug(`Attempting to load '${ocvPackage}'`);
+ cv = await requirePackage(ocvPackage);
+ break;
} catch (err) {
- log.warn(`Unable to load 'opencv4nodejs': ${err.message}`);
+ log.warn(`Unable to load '${ocvPackage}': ${err.message}`);
+ }
}
if (!cv) {
- throw new Error(`'opencv4nodejs' module is required to use OpenCV features. ` +
- `Please install it first ('npm i -g opencv4nodejs') and restart Appium. ` +
- 'Read https://github.com/justadudewhohacks/opencv4nodejs#how-to-install for more details on this topic.');
+ throw new Error(`An opencv node module is required to use OpenCV features. ` +
+ `Please install one first (e.g., 'npm i -g ${OCV_NEW}') and restart Appium. ` +
+ 'Read https://github.com/UrielCh/opencv4nodejs#how-to-install for more details on this topic.');
}
}

fix(support): allow @u4/opencv4nodejs in addition to the old one, and promote it in doctor instead