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";
2
2
3
3
let containerEnv : boolean | undefined ;
4
4
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 ;
8
8
}
9
9
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
+ }
13
14
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
+ }
24
18
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
+ ) ;
27
29
28
- export async function detectContainerEnv ( ) : Promise < boolean > {
29
- if ( containerEnv !== undefined ) {
30
- return containerEnv ;
31
- }
30
+ return exists . includes ( true ) ;
31
+ } ;
32
32
33
- containerEnv = await internalDetectContainerEnv ( ) ;
33
+ containerEnv = await detect ( ) ;
34
34
return containerEnv ;
35
35
}
You can’t perform that action at this time.
0 commit comments