Skip to content

Commit

Permalink
abstract environment updated for better support of vendors injecting (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jifeon authored and maZahaca committed Oct 7, 2017
1 parent 82293b5 commit aaf5866
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
28 changes: 7 additions & 21 deletions lib/PhantomEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class PhantomEnvironment extends AbstractEnvironment {
.then(this._rotateProxy, this)
.then(this._navigateTo.bind(this, this._url))
.then(this._validateProxy, this)
.then(this._inject, this);
.then(this._injectVendors, this);
}

setProxy(proxy) {
Expand Down Expand Up @@ -239,7 +239,7 @@ class PhantomEnvironment extends AbstractEnvironment {
});
debug('Added page load callback');

return deferred.promise().then(this._inject, this);
return deferred.promise().then(this._injectVendors, this);
}

waitForQuery(uri, timeout) {
Expand Down Expand Up @@ -670,24 +670,10 @@ class PhantomEnvironment extends AbstractEnvironment {
return Array.isArray(proxy) ? proxy.pop() : null;
}

/**
* Inject libs which are required for parse process
*
* @private
*/
_inject() {
debug('.inject()-ing parser libs');
const files = [
require.resolve('goose-abstract-environment/vendor/sizzle.min.js'),
require.resolve('goose-abstract-environment/vendor/xhr.sniffer.js'),
];
return this._injectFiles(files);
}

_injectFiles(files) {
files.forEach((file) => {
debug('injecting file %s', file);
this._page.injectJs(path.join(__dirname, '..', file));
_injectFiles(filePaths) {
filePaths.forEach((filePath) => {
debug('injecting file %s', filePath);
this._page.injectJs(filePath);
});
return vow.resolve();
}
Expand All @@ -699,7 +685,7 @@ class PhantomEnvironment extends AbstractEnvironment {

debug('.inject()-ing browser env libs');
return this._injectFiles([
'build/browser.bundle.js',
path.join(__dirname, '../build/browser.bundle.js'),
]);
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"version": "1.0.5",
"version": "1.0.8",
"name": "goose-phantom-environment",
"main": "lib/PhantomEnvironment.js",
"repository": "redco/goose-phantom-environment",
Expand All @@ -9,7 +9,7 @@
"dependencies": {
"babel-polyfill": "^6.23.0",
"debug": "^3.0.1",
"goose-abstract-environment": "1.0.6",
"goose-abstract-environment": "1.0.8",
"lodash": "^4.17.4",
"mkdir-p": "^0.0.7",
"phantom": "^0.8.4",
Expand Down

0 comments on commit aaf5866

Please sign in to comment.