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,WAAW,GAAG,IAAd;AACA,MAAA,cAAc,GAAG,IAAjB;AACA,aAAO,uBAAO,GAAP,CAAP;AACD;;AAED,WAAO,OAAO,CAAC,GAAR,CAAY,SAAS,CAAC,GAAV,CAAc,EAAE,IAAG;AACpC,UAAI,EAAE,CAAC,QAAH,IAAe,IAAnB,EAAyB;AACvB,eAAO,EAAE,CAAC,QAAH,CAAY,EAAE,CAAC,IAAf,CAAP;AACD;;AAED,aAAO,CAAC,EAAE,CAAC,KAAH,GAAW,uBAAO,EAAE,CAAC,IAAV,CAAX,GAA6B,uBAAO,EAAE,CAAC,IAAV,CAA9B,EACJ,KADI,CACE,CAAC,IAAG;AACT,QAAA,WAAW,CAAC,CAAD,EAAI,EAAE,CAAC,IAAP,CAAX;AACD,OAHI,CAAP;AAID,KATkB,CAAZ,CAAP;AAUD;;AAED,EAAA,QAAQ,GAAA;AACN,WAAO,KAAK,SAAZ;AACD;;AA7GgB;;;;AAgHnB,SAAS,OAAT,CAAiB,CAAjB,EAAkC;AAChC,SAAO,CAAC,IAAI,IAAL,IAAa,CAAC,CAAC,MAAF,KAAa,CAA1B,GAA8B,IAA9B,GAAqC,CAA5C;AACD,C","sourcesContent":["import {ensureDir, mkdtemp, realpath, remove, removeSync, unlink, unlinkSync} from \"fs-extra\"\nimport {tmpdir} from \"os\"\nimport * as path from \"path\"\n\nlet tmpFileCounter = 0\nconst tmpDirManagers = new Set()\n\n// add date to avoid use stale temp dir\nconst tempDirPrefix = `${process.pid.toString(36)}-${Date.now().toString(36)}`\n\nexport function getTempName(prefix?: string | null | undefined): string {\n return `${prefix == null ? \"\" : `${prefix}-`}${tempDirPrefix}-${(tmpFileCounter++).toString(36)}`\n}\n\nlet tempDirPromise: Promise | null\nlet tempBaseDir: string | null\n\nfunction getBaseTempDir(): Promise {\n if (tempDirPromise != null) {\n return tempDirPromise\n }\n\n if (tempBaseDir != null) {\n return Promise.resolve(tempBaseDir)\n }\n\n const systemTmpDir = process.env.APP_BUILDER_TMP_DIR || tmpdir()\n const isEnsureRemovedOnExit = process.env.TMP_DIR_MANAGER_ENSURE_REMOVED_ON_EXIT !== \"false\"\n tempDirPromise = mkdtemp(path.join(systemTmpDir, \"t-\"))\n .then(it => realpath(it))\n .then(dir => {\n if (isEnsureRemovedOnExit) {\n addExitHook(dir)\n }\n tempBaseDir = dir\n return dir\n })\n return tempDirPromise\n}\n\nfunction addExitHook(dir: string) {\n require(\"async-exit-hook\")((callback: (() => void) | null) => {\n const managers = Array.from(tmpDirManagers)\n tmpDirManagers.clear()\n\n if (callback == null) {\n for (const manager of managers) {\n manager.cleanupSync()\n }\n\n try {\n removeSync(dir)\n }\n catch (e) {\n handleError(e, dir)\n }\n return\n }\n\n Promise.all(managers.map(it => it.cleanup()))\n .then(() => remove(dir))\n .then(() => callback())\n .catch(e => {\n try {\n handleError(e, dir)\n }\n finally {\n callback()\n }\n })\n })\n}\n\nfunction handleError(e: any, file: string) {\n if (e.code !== \"EPERM\" && e.code !== \"ENOENT\") {\n // use only console.* instead of our warn on exit (otherwise nodeEmoji can be required on request)\n console.warn(`Cannot delete temporary \"${file}\": ${(e.stack || e).toString()}`)\n }\n}\n\ninterface TempFileInfo {\n isDir: boolean\n path: string\n disposer?: ((file: string) => Promise) | null\n}\n\nexport interface GetTempFileOptions {\n prefix?: string | null\n suffix?: string | null\n\n disposer?: ((file: string) => Promise) | null\n}\n\nexport class TmpDir {\n private tempFiles: Array = []\n private registered = false\n\n constructor(private readonly debugName: string = \"\") {\n }\n\n // noinspection JSMethodCanBeStatic,JSUnusedGlobalSymbols\n get rootTempDir(): Promise {\n return getBaseTempDir()\n }\n\n getTempDir(options?: GetTempFileOptions): Promise {\n return this.getTempFile(options, true)\n }\n\n createTempDir(options?: GetTempFileOptions): Promise {\n return this.getTempFile(options, true)\n .then(it => ensureDir(it).then(() => it))\n }\n\n getTempFile(options?: GetTempFileOptions, isDir = false): Promise {\n return getBaseTempDir()\n .then(baseTempDir => {\n if (!this.registered) {\n this.registered = true\n tmpDirManagers.add(this)\n }\n\n const prefix = nullize(options == null ? null : options.prefix)\n const suffix = nullize(options == null ? null : options.suffix)\n const namePrefix = prefix == null ? \"\" : `${prefix}-`\n const nameSuffix = suffix == null ? \"\" : (suffix.startsWith(\".\") ? suffix : `-${suffix}`)\n const result = `${baseTempDir}${path.sep}${namePrefix}${(tmpFileCounter++).toString(36)}${nameSuffix}`\n this.tempFiles.push({\n path: result,\n isDir,\n disposer: options == null ? null : options.disposer,\n })\n return result\n })\n }\n\n cleanupSync() {\n const tempFiles = this.tempFiles\n tmpDirManagers.delete(this)\n this.registered = false\n if (tempFiles.length === 0) {\n return\n }\n\n this.tempFiles = []\n\n for (const file of tempFiles) {\n if (file.disposer != null) {\n // noinspection JSIgnoredPromiseFromCall\n file.disposer(file.path)\n continue\n }\n\n try {\n if (file.isDir) {\n removeSync(file.path)\n }\n else {\n unlinkSync(file.path)\n }\n }\n catch (e) {\n handleError(e, file.path)\n }\n }\n }\n\n cleanup(): Promise {\n const tempFiles = this.tempFiles\n tmpDirManagers.delete(this)\n\n this.registered = false\n if (tempFiles.length === 0) {\n return Promise.resolve()\n }\n this.tempFiles = []\n\n if (tmpDirManagers.size === 0) {\n const dir = tempBaseDir\n if (dir == null) {\n return Promise.resolve()\n }\n\n tempBaseDir = null\n tempDirPromise = null\n return remove(dir)\n }\n\n return Promise.all(tempFiles.map(it => {\n if (it.disposer != null) {\n return it.disposer(it.path)\n }\n\n return (it.isDir ? remove(it.path) : unlink(it.path))\n .catch(e => {\n handleError(e, it.path)\n })\n }))\n }\n\n toString() {\n return this.debugName\n }\n}\n\nfunction nullize(s?: string | null) {\n return s == null || s.length === 0 ? null : s\n}"],"sourceRoot":""}