Skip to content

Commit

Permalink
tidy up install script
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfranklin committed Apr 2, 2020
1 parent c2b0302 commit f9ad309
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions install.js
Expand Up @@ -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);
Expand All @@ -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();

Expand Down

0 comments on commit f9ad309

Please sign in to comment.