File tree Expand file tree Collapse file tree 2 files changed +31
-32
lines changed Expand file tree Collapse file tree 2 files changed +31
-32
lines changed Original file line number Diff line number Diff line change 1- import fs from "node:fs" ;
2-
3- //! This code was taken from the package `is-docker` and modified to work here with esm
4- //! Original repository: https://github.com/sindresorhus/is-docker
5- let isDockerCached : boolean ;
6-
7- function hasDockerEnv ( ) {
8- try {
9- fs . statSync ( "/.dockerenv" ) ;
10- return true ;
11- } catch {
12- return false ;
13- }
14- }
15-
16- function hasDockerCGroup ( ) {
17- try {
18- return fs . readFileSync ( "/proc/self/cgroup" , "utf8" ) . includes ( "docker" ) ;
19- } catch {
20- return false ;
21- }
22- }
23-
24- export function isDocker ( ) {
25- // TODO: Use `??=` when targeting Node.js 16.
26- if ( isDockerCached === undefined ) {
27- isDockerCached = hasDockerEnv ( ) || hasDockerCGroup ( ) ;
28- }
29-
30- return isDockerCached ;
31- }
1+ import fs from "node:fs" ;
2+
3+ //! This code was taken from the package `is-docker` and modified to work here with esm
4+ //! Original repository: https://github.com/sindresorhus/is-docker
5+ let isDockerCached : boolean ;
6+
7+ function hasDockerEnv ( ) {
8+ try {
9+ fs . statSync ( "/.dockerenv" ) ;
10+ return true ;
11+ } catch {
12+ return false ;
13+ }
14+ }
15+
16+ function hasDockerCGroup ( ) {
17+ try {
18+ return fs . readFileSync ( "/proc/self/cgroup" , "utf8" ) . includes ( "docker" ) ;
19+ } catch {
20+ return false ;
21+ }
22+ }
23+
24+ export function isDocker ( ) {
25+ // TODO: Use `??=` when targeting Node.js 16.
26+ if ( isDockerCached === undefined ) {
27+ isDockerCached = hasDockerEnv ( ) || hasDockerCGroup ( ) ;
28+ }
29+
30+ return isDockerCached ;
31+ }
Original file line number Diff line number Diff line change @@ -4,4 +4,3 @@ export function sleep(ms: number) {
44 setTimeout ( resolve , ms )
55 ) ;
66}
7-
You can’t perform that action at this time.
0 commit comments