mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Consolidate phantom shim code in the phantom-shim folder
This patch: - renames phantomjs folder into phantom_shim - moves bin/puppeteer into a phantom_shim/runner.js and merges the file with phantomjs/index.js - removes "bin" field from the package.json - it is confusing to have phantom shim installable
This commit is contained in:
parent
8a5b3d3e05
commit
79ceb0c439
@ -18,9 +18,6 @@
|
||||
"progress": "^2.0.0",
|
||||
"rimraf": "^2.6.1"
|
||||
},
|
||||
"bin": {
|
||||
"puppeteer": "./bin/puppeteer.js"
|
||||
},
|
||||
"puppeteer": {
|
||||
"chromium_revision": "478524"
|
||||
},
|
||||
|
@ -16,10 +16,15 @@
|
||||
*/
|
||||
|
||||
var vm = require('vm');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var Phantom = require('./Phantom');
|
||||
var FileSystem = require('./FileSystem');
|
||||
var System = require('./System');
|
||||
var WebPage = require('./WebPage');
|
||||
var WebServer = require('./WebServer');
|
||||
var child_process = require('child_process');
|
||||
var Browser = require('..').Browser;
|
||||
var PhatomJs = require('../phantomjs');
|
||||
var version = require('../package.json').version;
|
||||
var argv = require('minimist')(process.argv.slice(2), {
|
||||
alias: { v: 'version' },
|
||||
@ -40,7 +45,7 @@ if (argv['ssl-certificates-path']) {
|
||||
|
||||
var scriptArguments = argv._;
|
||||
if (!scriptArguments.length) {
|
||||
console.log('puppeteer [scriptfile]');
|
||||
console.log(__filename.split('/').pop() + ' [scriptfile]');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -56,6 +61,49 @@ var browser = new Browser({
|
||||
headless: argv.headless,
|
||||
});
|
||||
|
||||
var context = PhatomJs.createContext(browser, scriptPath, argv);
|
||||
var context = createPhantomContext(browser, scriptPath, argv);
|
||||
var scriptContent = fs.readFileSync(scriptPath, 'utf8');
|
||||
vm.runInContext(scriptContent, context);
|
||||
|
||||
/**
|
||||
* @param {!Browser} browser
|
||||
* @param {string} scriptPath
|
||||
* @param {!Array<string>} argv
|
||||
* @return {!Object}
|
||||
*/
|
||||
function createPhantomContext(browser, scriptPath, argv) {
|
||||
var context = {};
|
||||
context.setInterval = setInterval;
|
||||
context.setTimeout = setTimeout;
|
||||
context.clearInterval = clearInterval;
|
||||
context.clearTimeout = clearTimeout;
|
||||
|
||||
context.phantom = Phantom.create(context, scriptPath);
|
||||
context.console = console;
|
||||
context.window = context;
|
||||
context.WebPage = options => new WebPage(browser, scriptPath, options);
|
||||
|
||||
vm.createContext(context);
|
||||
|
||||
var nativeExports = {
|
||||
fs: new FileSystem(),
|
||||
system: new System(argv._),
|
||||
webpage: {
|
||||
create: context.WebPage,
|
||||
},
|
||||
webserver: {
|
||||
create: () => new WebServer(),
|
||||
},
|
||||
cookiejar: {
|
||||
create: () => {},
|
||||
},
|
||||
child_process: child_process
|
||||
};
|
||||
var bootstrapPath = path.join(__dirname, '..', 'third_party', 'phantomjs', 'bootstrap.js');
|
||||
var bootstrapCode = fs.readFileSync(bootstrapPath, 'utf8');
|
||||
vm.runInContext(bootstrapCode, context, {
|
||||
filename: 'bootstrap.js'
|
||||
})(nativeExports);
|
||||
return context;
|
||||
}
|
||||
|
@ -1,71 +0,0 @@
|
||||
/**
|
||||
* Copyright 2017 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var vm = require('vm');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var Phantom = require('./Phantom');
|
||||
var FileSystem = require('./FileSystem');
|
||||
var System = require('./System');
|
||||
var WebPage = require('./WebPage');
|
||||
var WebServer = require('./WebServer');
|
||||
var child_process = require('child_process');
|
||||
|
||||
var bootstrapPath = path.join(__dirname, '..', 'third_party', 'phantomjs', 'bootstrap.js');
|
||||
var bootstrapCode = fs.readFileSync(bootstrapPath, 'utf8');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* @param {!Browser} browser
|
||||
* @param {string} scriptPath
|
||||
* @param {!Array<string>} argv
|
||||
* @return {!Object}
|
||||
*/
|
||||
createContext(browser, scriptPath, argv) {
|
||||
var context = {};
|
||||
context.setInterval = setInterval;
|
||||
context.setTimeout = setTimeout;
|
||||
context.clearInterval = clearInterval;
|
||||
context.clearTimeout = clearTimeout;
|
||||
|
||||
context.phantom = Phantom.create(context, scriptPath);
|
||||
context.console = console;
|
||||
context.window = context;
|
||||
context.WebPage = options => new WebPage(browser, scriptPath, options);
|
||||
|
||||
vm.createContext(context);
|
||||
|
||||
var nativeExports = {
|
||||
fs: new FileSystem(),
|
||||
system: new System(argv._),
|
||||
webpage: {
|
||||
create: context.WebPage,
|
||||
},
|
||||
webserver: {
|
||||
create: () => new WebServer(),
|
||||
},
|
||||
cookiejar: {
|
||||
create: () => {},
|
||||
},
|
||||
child_process: child_process
|
||||
};
|
||||
vm.runInContext(bootstrapCode, context, {
|
||||
filename: 'bootstrap.js'
|
||||
})(nativeExports);
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
2
third_party/phantomjs/test/run-tests.py
vendored
2
third_party/phantomjs/test/run-tests.py
vendored
@ -977,7 +977,7 @@ class TestRunner(object):
|
||||
|
||||
def init():
|
||||
base_path = os.path.normpath(os.path.dirname(os.path.abspath(__file__)))
|
||||
phantomjs_exe = os.path.normpath(base_path + '/../../../bin/puppeteer.js')
|
||||
phantomjs_exe = os.path.normpath(base_path + '/../../../phantom_shim/runner.js')
|
||||
if not os.path.isfile(phantomjs_exe):
|
||||
sys.stdout.write("{} is unavailable, cannot run tests.\n"
|
||||
.format(phantomjs_exe))
|
||||
|
Loading…
Reference in New Issue
Block a user