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AACpB,CAAC;AAED,SAAS,cAAc,CAAC,UAAsB,EAAE,IAAwC,EAAE,MAAc,EAAE,WAAmB,EAAE,KAAY;IACzI,IAAI,IAAI,IAAI,IAAI,EAAE;QAChB,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAA;KACnD;SAAM;QACL,OAAO,IAAA,oBAAS,EAAC,WAAW,EAAE,IAAI,CAAC,CAAA;KACpC;AACH,CAAC","sourcesContent":["import { AsyncTaskManager, log } from \"builder-util\"\nimport { FileCopier, Filter, MAX_FILE_REQUESTS } from \"builder-util/out/fs\"\nimport { symlink, createReadStream, createWriteStream, Stats } from \"fs\"\nimport { writeFile, readFile, mkdir } from \"fs/promises\"\nimport * as path from \"path\"\nimport { AsarOptions } from \"../options/PlatformSpecificBuildOptions\"\nimport { Packager } from \"../packager\"\nimport { PlatformPackager } from \"../platformPackager\"\nimport { getDestinationPath, ResolvedFileSet } from \"../util/appFileCopier\"\nimport { AsarFilesystem, Node } from \"./asar\"\nimport { hashFile, hashFileContents } from \"./integrity\"\nimport { detectUnpackedDirs } from \"./unpackDetector\"\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\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, packager: PlatformPackager) {\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 mkdir(path.dirname(this.outFile), { recursive: true })\n const unpackedFileIndexMap = new Map>()\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()\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(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 mkdir(path.join(this.unpackedDest, filePathInArchive), { recursive: true })\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()\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 } else {\n await correctDirNodeUnpackedFlag(fileParent, currentDirNode)\n }\n }\n }\n\n const dirNode = currentDirNode!\n const newData = transformedFiles == null ? undefined : transformedFiles.get(i)\n const isUnpacked = dirNode.unpacked || (this.unpackPattern != null && this.unpackPattern(file, stat))\n const integrity = newData === undefined ? await hashFile(file) : hashFileContents(newData)\n this.fs.addFileNode(file, dirNode, newData == undefined ? stat.size : Buffer.byteLength(newData), isUnpacked, stat, integrity)\n if (isUnpacked) {\n if (!dirNode.unpacked && !dirToCreateForUnpackedFiles.has(fileParent)) {\n dirToCreateForUnpackedFiles.add(fileParent)\n await mkdir(path.join(this.unpackedDest, fileParent), { recursive: true })\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, unpackedFileIndexMap: Map>): Promise {\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 } 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 } 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: any) => reject(`Cannot read file ${file}: ${e.stack || e}`))\n } else {\n const readStream = createReadStream(file)\n readStream.on(\"error\", reject)\n readStream.once(\"end\", () => w(index + 1))\n readStream.on(\"open\", () => {\n readStream.pipe(writeStream, {\n end: false,\n })\n })\n }\n }\n\n writeStream.write(headerBuf, () => w(0))\n })\n }\n}\n\nasync function order(filenames: Array, 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 = []\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 = []\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 } else {\n return writeFile(destination, data)\n }\n}\n"]}