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A,MAAA,OAAO,IAAI,CAAX;AACD;AACF;;AACD,qBAAI,IAAJ,CAAS;AAAC,IAAA,QAAQ,EAAG,CAAC,KAAK,GAAG,OAAT,IAAoB,KAApB,GAA4B;AAAxC,GAAT,EAAwD,gCAAxD;;AACA,SAAO,WAAP;AACD;;AAED,SAAS,cAAT,CAAwB,UAAxB,EAAgD,IAAhD,EAA0F,MAA1F,EAA0G,WAA1G,EAA+H,KAA/H,EAA2I;AACzI,MAAI,IAAI,IAAI,IAAZ,EAAkB;AAChB,WAAO,UAAU,CAAC,IAAX,CAAgB,MAAhB,EAAwB,WAAxB,EAAqC,KAArC,CAAP;AACD,GAFD,MAGK;AACH,WAAO,0BAAU,WAAV,EAAuB,IAAvB,CAAP;AACD;AACF,C","sourcesContent":["import { AsyncTaskManager, log } from \"builder-util\"\nimport { FileCopier, Filter, MAX_FILE_REQUESTS } from \"builder-util/out/fs\"\nimport { symlink } from \"fs\"\nimport { createReadStream, createWriteStream, ensureDir, readFile, Stats, writeFile } from \"fs-extra\"\nimport * as path from \"path\"\nimport { AsarOptions } from \"..\"\nimport { Packager } from \"../packager\"\nimport { PlatformPackager } from \"../platformPackager\"\nimport { getDestinationPath, ResolvedFileSet } from \"../util/appFileCopier\"\nimport { AsarFilesystem, Node } from \"./asar\"\nimport { detectUnpackedDirs } from \"./unpackDetector\"\n\nconst pickle = require(\"chromium-pickle-js\")\n\n/** @internal */\nexport class AsarPackager {\n private readonly fs = new AsarFilesystem(this.src)\n private readonly outFile: string\n private readonly unpackedDest: string\n\n constructor(private readonly src: string, private readonly destination: string, private readonly options: AsarOptions, private readonly unpackPattern: Filter | null) {\n this.outFile = path.join(destination, \"app.asar\")\n this.unpackedDest = `${this.outFile}.unpacked`\n }\n\n // sort files to minimize file change (i.e. asar file is not changed dramatically on small change)\n async pack(fileSets: Array<ResolvedFileSet>, packager: PlatformPackager<any>) {\n if (this.options.ordering != null) {\n // ordering doesn't support transformed files, but ordering is not used functionality - wait user report to fix it\n await order(fileSets[0].files, this.options.ordering, fileSets[0].src)\n }\n await ensureDir(path.dirname(this.outFile))\n const unpackedFileIndexMap = new Map<ResolvedFileSet, Set<number>>()\n for (const fileSet of fileSets) {\n unpackedFileIndexMap.set(fileSet, await this.createPackageFromFiles(fileSet, packager.info))\n }\n await this.writeAsarFile(fileSets, unpackedFileIndexMap)\n }\n\n private async createPackageFromFiles(fileSet: ResolvedFileSet, packager: Packager) {\n const metadata = fileSet.metadata\n // search auto unpacked dir\n const unpackedDirs = new Set<string>()\n const rootForAppFilesWithoutAsar = path.join(this.destination, \"app\")\n\n if (this.options.smartUnpack !== false) {\n await detectUnpackedDirs(fileSet, unpackedDirs, this.unpackedDest, rootForAppFilesWithoutAsar)\n }\n\n const dirToCreateForUnpackedFiles = new Set<string>(unpackedDirs)\n\n const correctDirNodeUnpackedFlag = async (filePathInArchive: string, dirNode: Node) => {\n for (const dir of unpackedDirs) {\n if (filePathInArchive.length > (dir.length + 2) && filePathInArchive[dir.length] === path.sep && filePathInArchive.startsWith(dir)) {\n dirNode.unpacked = true\n unpackedDirs.add(filePathInArchive)\n // not all dirs marked as unpacked after first iteration - because node module dir can be marked as unpacked after processing node module dir content\n // e.g. node-notifier/example/advanced.js processed, but only on process vendor/terminal-notifier.app module will be marked as unpacked\n await ensureDir(path.join(this.unpackedDest, filePathInArchive))\n break\n }\n }\n }\n\n const transformedFiles = fileSet.transformedFiles\n const taskManager = new AsyncTaskManager(packager.cancellationToken)\n const fileCopier = new FileCopier()\n\n let currentDirNode: Node | null = null\n let currentDirPath: string | null = null\n\n const unpackedFileIndexSet = new Set<number>()\n\n for (let i = 0, n = fileSet.files.length; i < n; i++) {\n const file = fileSet.files[i]\n const stat = metadata.get(file)\n if (stat == null) {\n continue\n }\n\n const pathInArchive = path.relative(rootForAppFilesWithoutAsar, getDestinationPath(file, fileSet))\n\n if (stat.isSymbolicLink()) {\n const s = (stat as any)\n this.fs.getOrCreateNode(pathInArchive).link = s.relativeLink\n s.pathInArchive = pathInArchive\n unpackedFileIndexSet.add(i)\n continue\n }\n\n let fileParent = path.dirname(pathInArchive)\n if (fileParent === \".\") {\n fileParent = \"\"\n }\n\n if (currentDirPath !== fileParent) {\n if (fileParent.startsWith(\"..\")) {\n throw new Error(`Internal error: path must not start with \"..\": ${fileParent}`)\n }\n\n currentDirPath = fileParent\n currentDirNode = this.fs.getOrCreateNode(fileParent)\n // do not check for root\n if (fileParent !== \"\" && !currentDirNode.unpacked) {\n if (unpackedDirs.has(fileParent)) {\n currentDirNode.unpacked = true\n }\n else {\n await correctDirNodeUnpackedFlag(fileParent, currentDirNode)\n }\n }\n }\n\n const dirNode = currentDirNode!\n const newData = transformedFiles == null ? null : transformedFiles.get(i)\n const isUnpacked = dirNode.unpacked || (this.unpackPattern != null && this.unpackPattern(file, stat))\n this.fs.addFileNode(file, dirNode, newData == null ? stat.size : Buffer.byteLength(newData), isUnpacked, stat)\n if (isUnpacked) {\n if (!dirNode.unpacked && !dirToCreateForUnpackedFiles.has(fileParent)) {\n dirToCreateForUnpackedFiles.add(fileParent)\n await ensureDir(path.join(this.unpackedDest, fileParent))\n }\n\n const unpackedFile = path.join(this.unpackedDest, pathInArchive)\n taskManager.addTask(copyFileOrData(fileCopier, newData, file, unpackedFile, stat))\n if (taskManager.tasks.length > MAX_FILE_REQUESTS) {\n await taskManager.awaitTasks()\n }\n\n unpackedFileIndexSet.add(i)\n }\n }\n\n if (taskManager.tasks.length > 0) {\n await taskManager.awaitTasks()\n }\n\n return unpackedFileIndexSet\n }\n\n private writeAsarFile(fileSets: Array<ResolvedFileSet>, unpackedFileIndexMap: Map<ResolvedFileSet, Set<number>>): Promise<any> {\n return new Promise((resolve, reject) => {\n const headerPickle = pickle.createEmpty()\n headerPickle.writeString(JSON.stringify(this.fs.header))\n const headerBuf = headerPickle.toBuffer()\n\n const sizePickle = pickle.createEmpty()\n sizePickle.writeUInt32(headerBuf.length)\n\n const sizeBuf = sizePickle.toBuffer()\n const writeStream = createWriteStream(this.outFile)\n writeStream.on(\"error\", reject)\n writeStream.on(\"close\", resolve)\n writeStream.write(sizeBuf)\n\n let fileSetIndex = 0\n\n let files = fileSets[0].files\n let metadata = fileSets[0].metadata\n let transformedFiles = fileSets[0].transformedFiles\n let unpackedFileIndexSet = unpackedFileIndexMap.get(fileSets[0])!!\n const w = (index: number) => {\n while (true) {\n if (index >= files.length) {\n if (++fileSetIndex >= fileSets.length) {\n writeStream.end()\n return\n }\n else {\n files = fileSets[fileSetIndex].files\n metadata = fileSets[fileSetIndex].metadata\n transformedFiles = fileSets[fileSetIndex].transformedFiles\n unpackedFileIndexSet = unpackedFileIndexMap.get(fileSets[fileSetIndex])!!\n index = 0\n }\n }\n\n if (!unpackedFileIndexSet.has(index)) {\n break\n }\n else {\n const stat = metadata.get(files[index])\n if (stat != null && stat.isSymbolicLink()) {\n symlink((stat as any).linkRelativeToFile, path.join(this.unpackedDest, (stat as any).pathInArchive), () => w(index + 1))\n return\n }\n }\n index++\n }\n\n const data = transformedFiles == null ? null : transformedFiles.get(index)\n const file = files[index]\n if (data !== null && data !== undefined) {\n writeStream.write(data, () => w(index + 1))\n return\n }\n\n // https://github.com/yarnpkg/yarn/pull/3539\n const stat = metadata.get(file)\n if (stat != null && stat.size < (2 * 1024 * 1024)) {\n readFile(file)\n .then(it => {\n writeStream.write(it, () => w(index + 1))\n })\n .catch(e => reject(`Cannot read file ${file}: ${e.stack || e}`))\n }\n else {\n const readStream = createReadStream(file)\n readStream.on(\"error\", reject)\n readStream.once(\"end\", () => w(index + 1))\n readStream.pipe(writeStream, {\n end: false\n })\n }\n }\n\n writeStream.write(headerBuf, () => w(0))\n })\n }\n}\n\nasync function order(filenames: Array<string>, orderingFile: string, src: string) {\n const orderingFiles = (await readFile(orderingFile, \"utf8\")).split(\"\\n\").map(line => {\n if (line.indexOf(\":\") !== -1) {\n line = line.split(\":\").pop()!\n }\n line = line.trim()\n if (line[0] === \"/\") {\n line = line.slice(1)\n }\n return line\n })\n\n const ordering: Array<string> = []\n for (const file of orderingFiles) {\n const pathComponents = file.split(path.sep)\n for (const pathComponent of pathComponents) {\n ordering.push(path.join(src, pathComponent))\n }\n }\n\n const sortedFiles: Array<string> = []\n let missing = 0\n const total = filenames.length\n for (const file of ordering) {\n if (!sortedFiles.includes(file) && filenames.includes(file)) {\n sortedFiles.push(file)\n }\n }\n for (const file of filenames) {\n if (!sortedFiles.includes(file)) {\n sortedFiles.push(file)\n missing += 1\n }\n }\n log.info({coverage: ((total - missing) / total * 100)}, \"ordering files in ASAR archive\")\n return sortedFiles\n}\n\nfunction copyFileOrData(fileCopier: FileCopier, data: string | Buffer | undefined | null, source: string, destination: string, stats: Stats) {\n if (data == null) {\n return fileCopier.copy(source, destination, stats)\n }\n else {\n return writeFile(destination, data)\n }\n}"],"sourceRoot":""}