File tree Expand file tree Collapse file tree 1 file changed +23
-23
lines changed
Expand file tree Collapse file tree 1 file changed +23
-23
lines changed Original file line number Diff line number Diff line change @@ -2,34 +2,34 @@ import fs from "fs/promises";
22
33let containerEnv : boolean | undefined ;
44
5- async function internalDetectContainerEnv ( ) : Promise < boolean > {
6- if ( process . platform !== "linux" ) {
7- return false ; // we only support linux containers for now
5+ export async function detectContainerEnv ( ) : Promise < boolean > {
6+ if ( containerEnv !== undefined ) {
7+ return containerEnv ;
88 }
99
10- if ( process . env . container ) {
11- return true ;
12- }
10+ const detect = async function ( ) : Promise < boolean > {
11+ if ( process . platform !== "linux" ) {
12+ return false ; // we only support linux containers for now
13+ }
1314
14- const exists = await Promise . all (
15- [ "/.dockerenv" , "/run/.containerenv" , "/var/run/.containerenv" ] . map ( async ( file ) => {
16- try {
17- await fs . access ( file ) ;
18- return true ;
19- } catch {
20- return false ;
21- }
22- } )
23- ) ;
15+ if ( process . env . container ) {
16+ return true ;
17+ }
2418
25- return exists . includes ( true ) ;
26- }
19+ const exists = await Promise . all (
20+ [ "/.dockerenv" , "/run/.containerenv" , "/var/run/.containerenv" ] . map ( async ( file ) => {
21+ try {
22+ await fs . access ( file ) ;
23+ return true ;
24+ } catch {
25+ return false ;
26+ }
27+ } )
28+ ) ;
2729
28- export async function detectContainerEnv ( ) : Promise < boolean > {
29- if ( containerEnv !== undefined ) {
30- return containerEnv ;
31- }
30+ return exists . includes ( true ) ;
31+ } ;
3232
33- containerEnv = await internalDetectContainerEnv ( ) ;
33+ containerEnv = await detect ( ) ;
3434 return containerEnv ;
3535}
You can’t perform that action at this time.
0 commit comments