-
Notifications
You must be signed in to change notification settings - Fork 31
/
env.js
129 lines (110 loc) · 3.33 KB
/
env.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* eslint-disable no-undef */
/* eslint-disable no-useless-escape */
/**
* Taken from https://github.com/browserless/chrome/blob/master/env.js
*
* By @joelgriffith
*/
import os from 'os'
import playwright from 'playwright-core'
import puppeteer from 'puppeteer'
const IS_DOCKER = process.env.IS_DOCKER === 'true';
const USE_CHROME_STABLE = process.env.USE_CHROME_STABLE && process.env.USE_CHROME_STABLE === 'true';
const MAC = 'MAC';
const WINDOWS = 'WINDOWS';
const LINUX = 'LINUX';
const LINUX_ARM64 = 'LINUX_ARM64';
const CHROME_BINARY_PATHS = {
LINUX: '/usr/bin/google-chrome',
MAC: '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome',
WIN: 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',
};
const PLATFORM = os.platform() === 'win32' ?
WINDOWS :
os.platform() === 'darwin' ?
MAC :
os.arch() === 'arm64' ?
LINUX_ARM64 :
LINUX;
/*
* Assess which chromium revision to install.
* Note that in docker we do our own install, and
* ignore puppeteer's install.js file.
*/
const PUPPETEER_CHROMIUM_REVISION = (() => {
return puppeteer._preferredRevision;
})();
/*
* Sometimes we don't use puppeteer's built-in chromium
* for compatibility reasons
*/
const PUPPETEER_BINARY_LOCATION = (() => {
if (PLATFORM === LINUX_ARM64) {
return playwright.chromium.executablePath();
}
const browserFetcher = puppeteer.createBrowserFetcher();
return browserFetcher.revisionInfo(PUPPETEER_CHROMIUM_REVISION).executablePath;
})();
/*
* Tells puppeteer, in its install script, what revision to download.
* This is set in our deploy.js file in our docker build. If
* PUPPETEER_SKIP_CHROMIUM_DOWNLOAD is true, then this is ignored
*/
const CHROME_BINARY_LOCATION = (() => {
if (process.env.CHROME_BINARY_LOCATION) {
return process.env.CHROME_BINARY_LOCATION;
}
// In docker we symlink any chrome installs to the default install location
// so that chromedriver can do its thing
if (IS_DOCKER) {
return CHROME_BINARY_PATHS.LINUX;
}
// If using chrome-stable, default to it's natural habitat
if (USE_CHROME_STABLE) {
return CHROME_BINARY_PATHS[PLATFORM];
}
// All else uses pptr's bin
return PUPPETEER_BINARY_LOCATION;
})();
/*
* Tells the chromedriver library to download the appropriate chromedriver binary.
* The only time this should be false is when building chrome stable in docker.
*/
const CHROMEDRIVER_SKIP_DOWNLOAD = (() => {
if (process.env.CHROMEDRIVER_SKIP_DOWNLOAD) {
return process.env.CHROMEDRIVER_SKIP_DOWNLOAD;
}
if (IS_DOCKER) {
return !USE_CHROME_STABLE;
}
return true;
})();
/*
* Tells puppeteer to skip downloading the appropriate chrome revision. This is generally
* not the case, however when installing chrome-stable in docker we want to skip it as
* we'll download google-chrome-stable from a deb package instead.
*/
const PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = (() => {
if (process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD) {
return process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD;
}
if (IS_DOCKER) {
return USE_CHROME_STABLE;
}
return false;
})();
const e = {
IS_DOCKER,
USE_CHROME_STABLE,
PUPPETEER_CHROMIUM_REVISION,
CHROME_BINARY_LOCATION,
CHROMEDRIVER_SKIP_DOWNLOAD,
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD,
PUPPETEER_BINARY_LOCATION,
PLATFORM,
WINDOWS,
MAC,
LINUX,
LINUX_ARM64,
};
export default e