From 51fae87baffdb3952869c8e35a88dd125f36d3a5 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 20 Feb 2023 19:42:08 +0700 Subject: [PATCH] Fix support for Podman Fixes sindresorhus/is-docker#14 --- index.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 72d1cdc..f66dc4c 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,25 @@ const localXdgOpenPath = path.join(__dirname, 'xdg-open'); const {platform, arch} = process; +// Podman detection +const hasContainerEnv = () => { + try { + fs.statSync('/run/.containerenv'); + return true; + } catch { + return false; + } +}; + +let cachedResult; +function isInsideContainer() { + if (cachedResult === undefined) { + cachedResult = hasContainerEnv() || isDocker(); + } + + return cachedResult; +} + /** Get the mount point for fixed drives in WSL. @@ -120,7 +139,7 @@ const baseOpen = async options => { if (app) { cliArguments.push('-a', app); } - } else if (platform === 'win32' || (isWsl && !isDocker() && !app)) { + } else if (platform === 'win32' || (isWsl && !isInsideContainer() && !app)) { const mountPoint = await getWslDrivesMountPoint(); command = isWsl ?