install.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * This file is part of public API.
  18. *
  19. * By default, the `puppeteer` package runs this script during the installation
  20. * process unless one of the env flags is provided.
  21. * `puppeteer-core` package doesn't include this step at all. However, it's
  22. * still possible to install a supported browser using this script when
  23. * necessary.
  24. */
  25. const path = require('path');
  26. const fs = require('fs');
  27. const {execSync} = require('child_process');
  28. async function download() {
  29. if (!fs.existsSync(path.join(__dirname, 'lib'))) {
  30. console.log('It seems we are installing from the git repo.');
  31. console.log('Building install tools from scratch...');
  32. execSync('npm run build');
  33. }
  34. // need to ensure TS is compiled before loading the installer
  35. const {
  36. downloadBrowser,
  37. logPolitely,
  38. } = require('puppeteer/lib/cjs/puppeteer/node/install.js');
  39. if (process.env.PUPPETEER_SKIP_DOWNLOAD) {
  40. logPolitely(
  41. '**INFO** Skipping browser download. "PUPPETEER_SKIP_DOWNLOAD" environment variable was found.'
  42. );
  43. return;
  44. }
  45. if (
  46. process.env.NPM_CONFIG_PUPPETEER_SKIP_DOWNLOAD ||
  47. process.env.npm_config_puppeteer_skip_download
  48. ) {
  49. logPolitely(
  50. '**INFO** Skipping browser download. "PUPPETEER_SKIP_DOWNLOAD" was set in npm config.'
  51. );
  52. return;
  53. }
  54. if (
  55. process.env.NPM_PACKAGE_CONFIG_PUPPETEER_SKIP_DOWNLOAD ||
  56. process.env.npm_package_config_puppeteer_skip_download
  57. ) {
  58. logPolitely(
  59. '**INFO** Skipping browser download. "PUPPETEER_SKIP_DOWNLOAD" was set in project config.'
  60. );
  61. return;
  62. }
  63. if (process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD) {
  64. logPolitely(
  65. '**INFO** Skipping browser download. "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" environment variable was found.'
  66. );
  67. return;
  68. }
  69. if (
  70. process.env.NPM_CONFIG_PUPPETEER_SKIP_CHROMIUM_DOWNLOAD ||
  71. process.env.npm_config_puppeteer_skip_chromium_download
  72. ) {
  73. logPolitely(
  74. '**INFO** Skipping browser download. "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" was set in npm config.'
  75. );
  76. return;
  77. }
  78. if (
  79. process.env.NPM_PACKAGE_CONFIG_PUPPETEER_SKIP_CHROMIUM_DOWNLOAD ||
  80. process.env.npm_package_config_puppeteer_skip_chromium_download
  81. ) {
  82. logPolitely(
  83. '**INFO** Skipping browser download. "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD" was set in project config.'
  84. );
  85. return;
  86. }
  87. downloadBrowser();
  88. }
  89. download();