Skip to content

Commit 3d4e50d

Browse files
pavelfeldmanaslushnikov
authored andcommitted
fix(env): respect =true/false as env values for boolean flags (#4228)
1 parent 1df6b92 commit 3d4e50d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/install/installer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import * as removeFolder from 'rimraf';
2222
import * as lockfile from 'proper-lockfile';
2323
import * as browserPaths from '../utils/browserPaths';
2424
import * as browserFetcher from './browserFetcher';
25-
import { getFromENV } from '../utils/utils';
25+
import { getAsBooleanFromENV } from '../utils/utils';
2626

2727
const fsMkdirAsync = util.promisify(fs.mkdir.bind(fs));
2828
const fsReaddirAsync = util.promisify(fs.readdir.bind(fs));
@@ -34,7 +34,7 @@ const removeFolderAsync = util.promisify(removeFolder);
3434

3535
export async function installBrowsersWithProgressBar(packagePath: string) {
3636
// PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD should have a value of 0 or 1
37-
if (!!Number(getFromENV('PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD'))) {
37+
if (getAsBooleanFromENV('PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD')) {
3838
browserFetcher.logPolitely('Skipping browsers download because `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` env variable is set');
3939
return false;
4040
}

src/utils/utils.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,18 @@ export function isUnderTest(): boolean {
9595
return _isUnderTest;
9696
}
9797

98-
export function getFromENV(name: string) {
98+
export function getFromENV(name: string): string | undefined {
9999
let value = process.env[name];
100-
value = typeof value === 'undefined' ? process.env[`npm_config_${name.toLowerCase()}`] : value;
101-
value = typeof value === 'undefined' ? process.env[`npm_package_config_${name.toLowerCase()}`] : value;
100+
value = value === undefined ? process.env[`npm_config_${name.toLowerCase()}`] : value;
101+
value = value === undefined ? process.env[`npm_package_config_${name.toLowerCase()}`] : value;
102102
return value;
103103
}
104104

105+
export function getAsBooleanFromENV(name: string): boolean {
106+
const value = getFromENV(name);
107+
return !!value && value !== 'false' && value !== '0';
108+
}
109+
105110
export async function mkdirIfNeeded(filePath: string) {
106111
// This will harmlessly throw on windows if the dirname is the root directory.
107112
await mkdirAsync(path.dirname(filePath), {recursive: true}).catch(() => {});

0 commit comments

Comments
 (0)