feat(install): build node6 support when installing from github (#1562)

This patch starts building node6 support if puppeteer is installed from
github directly and is run under Node 6.
This commit is contained in:
Andrey Lushnikov 2017-12-08 16:53:12 -08:00 committed by GitHub
parent fc1f15e251
commit f19e2ade0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -13,6 +13,5 @@ install:
yarn run coverage &&
yarn run test-doclint
) else (
yarn run build &&
yarn run unit-node6
)

View File

@ -20,7 +20,6 @@ script:
- 'if [ "$NODE7" = "true" ]; then yarn run lint; fi'
- 'if [ "$NODE7" = "true" ]; then yarn run coverage; fi'
- 'if [ "$NODE7" = "true" ]; then yarn run test-doclint; fi'
- 'if [ "$NODE6" = "true" ]; then yarn run build; fi'
- 'if [ "$NODE6" = "true" ]; then yarn run unit-node6; fi'
jobs:
include:

View File

@ -14,6 +14,8 @@
* limitations under the License.
*/
buildNode6IfNecessary();
if (process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD) {
console.log('**INFO** Skipping Chromium download. "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" environment variable was found.');
return;
@ -92,3 +94,24 @@ function toMegabytes(bytes) {
return `${Math.round(mb * 10) / 10} Mb`;
}
function buildNode6IfNecessary() {
const fs = require('fs');
const path = require('path');
// if this package is installed from NPM, then it already has up-to-date node6
// folder.
if (!fs.existsSync(path.join('utils', 'node6-transform')))
return;
let asyncawait = true;
try {
new Function('async function test(){await 1}');
} catch (error) {
asyncawait = false;
}
// if async/await is supported, then node6 is not needed.
if (asyncawait)
return;
// Re-build node6/ folder.
console.log('Building Puppeteer for Node 6');
require(path.join(__dirname, 'utils', 'node6-transform'));
}