UNPKG

2.79 kBJavaScriptView Raw
1/**
2 * Copyright 2017 Google Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * This file is part of public API.
19 *
20 * By default, the `puppeteer` package runs this script during the installation
21 * process unless one of the env flags is provided.
22 * `puppeteer-core` package doesn't include this step at all. However, it's
23 * still possible to install a supported browser using this script when
24 * necessary.
25 */
26
27const compileTypeScriptIfRequired = require('./typescript-if-required');
28
29async function download() {
30 await compileTypeScriptIfRequired();
31 // need to ensure TS is compiled before loading the installer
32 const {
33 downloadBrowser,
34 logPolitely,
35 } = require('./lib/cjs/puppeteer/install');
36
37 if (process.env.PUPPETEER_SKIP_DOWNLOAD) {
38 logPolitely(
39 '**INFO** Skipping browser download. "PUPPETEER_SKIP_DOWNLOAD" environment variable was found.'
40 );
41 return;
42 }
43 if (
44 process.env.NPM_CONFIG_PUPPETEER_SKIP_DOWNLOAD ||
45 process.env.npm_config_puppeteer_skip_download
46 ) {
47 logPolitely(
48 '**INFO** Skipping browser download. "PUPPETEER_SKIP_DOWNLOAD" was set in npm config.'
49 );
50 return;
51 }
52 if (
53 process.env.NPM_PACKAGE_CONFIG_PUPPETEER_SKIP_DOWNLOAD ||
54 process.env.npm_package_config_puppeteer_skip_download
55 ) {
56 logPolitely(
57 '**INFO** Skipping browser download. "PUPPETEER_SKIP_DOWNLOAD" was set in project config.'
58 );
59 return;
60 }
61 if (process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD) {
62 logPolitely(
63 '**INFO** Skipping browser download. "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" environment variable was found.'
64 );
65 return;
66 }
67 if (
68 process.env.NPM_CONFIG_PUPPETEER_SKIP_CHROMIUM_DOWNLOAD ||
69 process.env.npm_config_puppeteer_skip_chromium_download
70 ) {
71 logPolitely(
72 '**INFO** Skipping browser download. "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" was set in npm config.'
73 );
74 return;
75 }
76 if (
77 process.env.NPM_PACKAGE_CONFIG_PUPPETEER_SKIP_CHROMIUM_DOWNLOAD ||
78 process.env.npm_package_config_puppeteer_skip_chromium_download
79 ) {
80 logPolitely(
81 '**INFO** Skipping browser download. "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" was set in project config.'
82 );
83 return;
84 }
85
86 downloadBrowser();
87}
88
89download();