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IAAI,CAAC,GAApB,GAA0B,cAApC,CAAN,CADwB,CAExB;;AACA,UAAM,uBAAgB,GAAhB,CAAoB,WAAW,CAAC,IAAZ,EAApB,EAAwC,MAAM,SAAN,IAAkB;AAC9D,YAAM,IAAI,GAAG,YAAY,GAAG,IAAI,CAAC,GAApB,GAA0B,SAAvC;AACA,YAAM,0BAAU,IAAV,CAAN;AACA,YAAM,uBAAgB,IAAhB,CAAqB,WAAW,CAAC,GAAZ,CAAgB,SAAhB,CAArB,EAAmD,EAAD,IAAY;AAClE,YAAI,WAAW,CAAC,GAAZ,CAAgB,SAAS,GAAG,IAAI,CAAC,GAAjB,GAAuB,EAAvC,CAAJ,EAAgD;AAC9C;AACA,iBAAO,IAAP;AACD,SAHD,MAIK;AACH,iBAAO,0BAAU,IAAI,GAAG,IAAI,CAAC,GAAZ,GAAkB,EAA5B,CAAP;AACD;AACF,OARK,CAAN;AASD,KAZK,EAYH,iBAZG,CAAN;AAaD;AACF,C","sourcesContent":["import BluebirdPromise from \"bluebird-lst\"\nimport { log } from \"builder-util\"\nimport { CONCURRENCY } from \"builder-util/out/fs\"\nimport { ensureDir } from \"fs-extra\"\nimport { isBinaryFile } from \"isbinaryfile\"\nimport * as path from \"path\"\nimport { NODE_MODULES_PATTERN } from \"../fileTransformer\"\nimport { getDestinationPath, ResolvedFileSet } from \"../util/appFileCopier\"\n\nfunction addValue(map: Map>, key: string, value: string) {\n let list = map.get(key)\n if (list == null) {\n list = [value]\n map.set(key, list)\n }\n else {\n list.push(value)\n }\n}\n\nexport function isLibOrExe(file: string): boolean {\n return file.endsWith(\".dll\") || file.endsWith(\".exe\") || file.endsWith(\".dylib\") || file.endsWith(\".so\")\n}\n\n/** @internal */\nexport async function detectUnpackedDirs(fileSet: ResolvedFileSet, autoUnpackDirs: Set, unpackedDest: string, rootForAppFilesWithoutAsar: string) {\n const dirToCreate = new Map>()\n const metadata = fileSet.metadata\n\n function addParents(child: string, root: string) {\n child = path.dirname(child)\n if (autoUnpackDirs.has(child)) {\n return\n }\n\n do {\n autoUnpackDirs.add(child)\n const p = path.dirname(child)\n // create parent dir to be able to copy file later without directory existence check\n addValue(dirToCreate, p, path.basename(child))\n\n if (child === root || p === root || autoUnpackDirs.has(p)) {\n break\n }\n child = p\n }\n while (true)\n\n autoUnpackDirs.add(root)\n }\n\n for (let i = 0, n = fileSet.files.length; i < n; i++) {\n const file = fileSet.files[i]\n const index = file.lastIndexOf(NODE_MODULES_PATTERN)\n if (index < 0) {\n continue\n }\n\n let nextSlashIndex = file.indexOf(path.sep, index + NODE_MODULES_PATTERN.length + 1)\n if (nextSlashIndex < 0) {\n continue\n }\n\n if (file[index + NODE_MODULES_PATTERN.length] === \"@\") {\n nextSlashIndex = file.indexOf(path.sep, nextSlashIndex + 1)\n }\n\n if (!metadata.get(file)!.isFile()) {\n continue\n }\n\n const packageDir = file.substring(0, nextSlashIndex)\n const packageDirPathInArchive = path.relative(rootForAppFilesWithoutAsar, getDestinationPath(packageDir, fileSet))\n const pathInArchive = path.relative(rootForAppFilesWithoutAsar, getDestinationPath(file, fileSet))\n if (autoUnpackDirs.has(packageDirPathInArchive)) {\n // if package dir is unpacked, any file also unpacked\n addParents(pathInArchive, packageDirPathInArchive)\n continue\n }\n\n // https://github.com/electron-userland/electron-builder/issues/2679\n let shouldUnpack = false\n // ffprobe-static and ffmpeg-static are known packages to always unpack\n const moduleName = path.basename(packageDir)\n if (moduleName === \"ffprobe-static\" || moduleName === \"ffmpeg-static\" || isLibOrExe(file)) {\n shouldUnpack = true\n }\n else if (!file.includes(\".\", nextSlashIndex) && path.extname(file) === \"\") {\n shouldUnpack = await isBinaryFile(file)\n }\n\n if (!shouldUnpack) {\n continue\n }\n\n if (log.isDebugEnabled) {\n log.debug({file: pathInArchive, reason: \"contains executable code\"}, \"not packed into asar archive\")\n }\n\n addParents(pathInArchive, packageDirPathInArchive)\n }\n\n if (dirToCreate.size > 0) {\n await ensureDir(unpackedDest + path.sep + \"node_modules\")\n // child directories should be not created asynchronously - parent directories should be created first\n await BluebirdPromise.map(dirToCreate.keys(), async parentDir => {\n const base = unpackedDest + path.sep + parentDir\n await ensureDir(base)\n await BluebirdPromise.each(dirToCreate.get(parentDir)!, (it): any => {\n if (dirToCreate.has(parentDir + path.sep + it)) {\n // already created\n return null\n }\n else {\n return ensureDir(base + path.sep + it)\n }\n })\n }, CONCURRENCY)\n }\n}"],"sourceRoot":""}