diff --git a/install.js b/install.js index ade7ce1d5960c..114bc7dc1144b 100644 --- a/install.js +++ b/install.js @@ -19,28 +19,23 @@ const path = require('path'); const child_process = require('child_process'); const {promisify} = require('util'); -const LIB_PATH = path.join(__dirname, 'lib'); - const fsAccess = promisify(fs.access); - const exec = promisify(child_process.exec); const fileExists = async filePath => fsAccess(filePath).then(() => true).catch(() => false); -/** - * This file is part of public API. +/* + * Now Puppeteer is built with TypeScript, we need to ensure that + * locally we have the generated output before trying to install. * - * By default, the `puppeteer` package runs this script during the installation - * process unless one of the env flags is provided. - * `puppeteer-core` package doesn't include this step at all. However, it's - * still possible to install a supported browser using this script when - * necessary. + * For users installing puppeteer this is fine, they will have the + * generated lib/ directory as we ship it when we publish to npm. + * + * However, if you're cloning the repo to contribute, you won't have the + * generated lib/ directory so this script checks if we need to run + * TypeScript first to ensure the output exists and is in the right + * place. */ -const supportedProducts = { - 'chrome': 'Chromium', - 'firefox': 'Firefox Nightly' -}; - async function compileTypeScript() { return exec('npm run tsc').catch(err => { console.error('Error running TypeScript', err); @@ -49,14 +44,29 @@ async function compileTypeScript() { } async function ensureLibDirectoryExists() { - const libExists = await fileExists(LIB_PATH); - + const libPath = path.join(__dirname, 'lib'); + const libExists = await fileExists(libPath); if (libExists) return; logPolitely('Compiling TypeScript before install...'); await compileTypeScript(); } + +/** + * This file is part of public API. + * + * By default, the `puppeteer` package runs this script during the installation + * process unless one of the env flags is provided. + * `puppeteer-core` package doesn't include this step at all. However, it's + * still possible to install a supported browser using this script when + * necessary. + */ +const supportedProducts = { + 'chrome': 'Chromium', + 'firefox': 'Firefox Nightly' +}; + async function download() { await ensureLibDirectoryExists();