{"version":3,"file":"process-helpers.cjs","sources":["../../src/process-helpers.ts"],"sourcesContent":["import treeKill from \"tree-kill\";\nimport { getConfig } from \"./config\";\nimport type { TestInstance } from \"./types\";\n\nexport const killProc = (instance: TestInstance, signal: string | undefined) =>\n  new Promise<void>((resolve, reject) => {\n    if (!instance.process.pid || (instance.process.pid && instance.hasExit())) {\n      resolve();\n      return;\n    }\n\n    treeKill(instance.process.pid, signal, async (err) => {\n      try {\n        if (err) {\n          if (\n            err.message.includes(\"The process\") &&\n            err.message.includes(\"not found.\")\n          ) {\n            resolve();\n            return;\n          }\n          if (\n            err.message.includes(\"could not be terminated\") &&\n            err.message.includes(\"There is no running instance of the task.\") &&\n            instance.hasExit()\n          ) {\n            resolve();\n            return;\n          }\n          const isOperationNotSupported = err.message.includes(\n            \"The operation attempted is not supported.\",\n          );\n          const isAccessDenied = err.message.includes(\"Access is denied.\");\n          if (\n            err.message.includes(\"could not be terminated\") &&\n            (isOperationNotSupported || isAccessDenied)\n          ) {\n            const sleep = (t: number) => new Promise((r) => setTimeout(r, t));\n            await sleep(getConfig().errorDebounceTimeout);\n            if (instance.hasExit()) {\n              resolve();\n              return;\n            }\n            console.warn(\"Ran into error while trying to kill process:\");\n            console.warn(err.toString());\n            console.warn(`This is likely due to Window's permissions.\n                Because this error is prevalent on CI Windows systems with the tree-kill package, we are attempting\n                 an alternative kill method.`);\n            console.warn();\n            console.warn(\n              \"Be aware that this alternative kill method is not guaranteed to work with subprocesses, and they may not exit properly as a result.\",\n            );\n\n            const didKill = instance.process.kill(signal as \"SIGKILL\");\n            if (didKill) {\n              resolve();\n            } else {\n              console.error(\n                \"Alternative kill method failed. Rejecting with original error.\",\n              );\n              reject(err);\n            }\n            return;\n          }\n          reject(err);\n        } else resolve();\n      } catch (e: unknown) {\n        reject(e);\n      }\n    });\n  });\n"],"names":["getConfig"],"mappings":";;;;AAIa,MAAA,WAAW,CAAC,UAAwB,WAC/C,IAAI,QAAc,CAAC,SAAS,WAAW;AACjC,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