This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 30
Require from global if opencv4nodejs is not found locally #105
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2215448
Require from global if opencv4nodejs is not found locally
imurchie 937289e
Add windows to travis build
imurchie b44a72d
Experiment with Windows on Travis
imurchie 5676cdb
See what the path is
imurchie 176b9c5
switch to linking package
imurchie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { isWindows } from './system'; | ||
import log from './logger'; | ||
import { exec } from 'teen_process'; | ||
|
||
|
||
/** | ||
* Internal utility to link global package to local context | ||
* | ||
* @returns {string} - name of the package to link | ||
* @throws {Error} If the command fails | ||
*/ | ||
async function linkGlobalPackage (packageName) { | ||
try { | ||
log.debug(`Linking package '${packageName}'`); | ||
const cmd = isWindows() ? 'npm.cmd' : 'npm'; | ||
await exec(cmd, ['link', packageName], {timeout: 20000}); | ||
} catch (err) { | ||
const msg = `Unable to load package '${packageName}', linking failed: ${err.message}`; | ||
log.debug(msg); | ||
if (err.stderr) { | ||
// log the stderr if there, but do not add to thrown error as it is | ||
// _very_ verbose | ||
log.debug(err.stderr); | ||
} | ||
throw new Error(msg); | ||
} | ||
} | ||
|
||
/** | ||
* Utility function to extend node functionality, allowing us to require | ||
* modules that are installed globally. If the package cannot be required, | ||
* this will attempt to link the package and then re-require it | ||
* | ||
* @param {string} packageName - the name of the package to be required | ||
* @returns {object} - the package object | ||
* @throws {Error} If the package is not found locally or globally | ||
*/ | ||
async function requirePackage (packageName) { | ||
try { | ||
log.debug(`Loading local package '${packageName}'`); | ||
return require(packageName); | ||
} catch (err) { | ||
log.debug(`Failed to load package '${packageName}': ${err.message}`); | ||
await linkGlobalPackage(packageName); | ||
} | ||
try { | ||
log.debug(`Retrying load of local package '${packageName}'`); | ||
return require(packageName); | ||
} catch (err) { | ||
log.errorAndThrow(`Unable to load package '${packageName}': ${err.message}`); | ||
} | ||
} | ||
|
||
export { requirePackage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"func-names": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import chai from 'chai'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import { node } from '..'; | ||
|
||
|
||
chai.should(); | ||
chai.use(chaiAsPromised); | ||
|
||
describe('node utilities', function () { | ||
describe('requirePackage', function () { | ||
it('should be able to require a local package', async function () { | ||
await node.requirePackage('chai').should.not.be.rejected; | ||
}); | ||
it('should be able to require a global package', async function () { | ||
await node.requirePackage('npm').should.not.be.rejected; | ||
}); | ||
it('should fail to find uninstalled package', async function () { | ||
await node.requirePackage('appium-foo-driver').should.eventually.be.rejectedWith(/Unable to load package/); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this
only
intentional?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Trying to get Windows working on Travis.