fix(env): respect =true/false as env values for boolean flags (#4228)
This commit is contained in:
parent
ba7949359f
commit
0337928aa3
|
|
@ -22,7 +22,7 @@ import * as removeFolder from 'rimraf';
|
|||
import * as lockfile from 'proper-lockfile';
|
||||
import * as browserPaths from '../utils/browserPaths';
|
||||
import * as browserFetcher from './browserFetcher';
|
||||
import { getFromENV } from '../utils/utils';
|
||||
import { getAsBooleanFromENV } from '../utils/utils';
|
||||
|
||||
const fsMkdirAsync = util.promisify(fs.mkdir.bind(fs));
|
||||
const fsReaddirAsync = util.promisify(fs.readdir.bind(fs));
|
||||
|
|
@ -34,7 +34,7 @@ const removeFolderAsync = util.promisify(removeFolder);
|
|||
|
||||
export async function installBrowsersWithProgressBar(packagePath: string) {
|
||||
// PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD should have a value of 0 or 1
|
||||
if (!!Number(getFromENV('PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD'))) {
|
||||
if (getAsBooleanFromENV('PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD')) {
|
||||
browserFetcher.logPolitely('Skipping browsers download because `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` env variable is set');
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,13 +95,18 @@ export function isUnderTest(): boolean {
|
|||
return _isUnderTest;
|
||||
}
|
||||
|
||||
export function getFromENV(name: string) {
|
||||
export function getFromENV(name: string): string | undefined {
|
||||
let value = process.env[name];
|
||||
value = typeof value === 'undefined' ? process.env[`npm_config_${name.toLowerCase()}`] : value;
|
||||
value = typeof value === 'undefined' ? process.env[`npm_package_config_${name.toLowerCase()}`] : value;
|
||||
value = value === undefined ? process.env[`npm_config_${name.toLowerCase()}`] : value;
|
||||
value = value === undefined ? process.env[`npm_package_config_${name.toLowerCase()}`] : value;
|
||||
return value;
|
||||
}
|
||||
|
||||
export function getAsBooleanFromENV(name: string): boolean {
|
||||
const value = getFromENV(name);
|
||||
return !!value && value !== 'false' && value !== '0';
|
||||
}
|
||||
|
||||
export async function mkdirIfNeeded(filePath: string) {
|
||||
// This will harmlessly throw on windows if the dirname is the root directory.
|
||||
await mkdirAsync(path.dirname(filePath), {recursive: true}).catch(() => {});
|
||||
|
|
|
|||
Loading…
Reference in a new issue