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EAAE,CAAC,IAAX,EAAiB,EAAE,CAAC,IAApB,CAAjC,EAA4D,WAA5D,CApBP,CAAP;AAqBD;;AAEM,MAAM,qBAAqB,GAAI,IAAD,IAAkB,KAAhD;;;;AACA,MAAM,cAAc,GAAI,IAAD,IAAkB,IAAzC,C","sourcesContent":["import BluebirdPromise from \"bluebird-lst\"\nimport { access, chmod, copyFile as _nodeCopyFile, ensureDir, link, lstat, readdir, readlink, stat, Stats, symlink, unlink, writeFile } from \"fs-extra\"\nimport * as path from \"path\"\nimport Mode from \"stat-mode\"\nimport { log } from \"./log\"\nimport { orIfFileNotExist, orNullIfFileNotExist } from \"./promise\"\n\nexport const MAX_FILE_REQUESTS = 8\nexport const CONCURRENCY = {concurrency: MAX_FILE_REQUESTS}\n\nexport type AfterCopyFileTransformer = (file: string) => Promise\n\nexport class CopyFileTransformer {\n constructor(public readonly afterCopyTransformer: AfterCopyFileTransformer) {\n }\n}\n\nexport type FileTransformer = (file: string) => Promise | null | string | Buffer | CopyFileTransformer\nexport type Filter = (file: string, stat: Stats) => boolean\n\nexport function unlinkIfExists(file: string) {\n return unlink(file)\n .catch(() => {/* ignore */})\n}\n\nexport async function statOrNull(file: string): Promise {\n return orNullIfFileNotExist(stat(file))\n}\n\nexport async function exists(file: string): Promise {\n try {\n await access(file)\n return true\n }\n catch (e) {\n return false\n }\n}\n\nexport interface FileConsumer {\n consume(file: string, fileStat: Stats, parent: string, siblingNames: Array): any\n\n /**\n * @default false\n */\n isIncludeDir?: boolean\n}\n\n/**\n * Returns list of file paths (system-dependent file separator)\n */\nexport async function walk(initialDirPath: string, filter?: Filter | null, consumer?: FileConsumer): Promise> {\n let result: Array = []\n const queue: Array = [initialDirPath]\n let addDirToResult = false\n const isIncludeDir = consumer == null ? false : consumer.isIncludeDir === true\n while (queue.length > 0) {\n const dirPath = queue.pop()!\n if (isIncludeDir) {\n if (addDirToResult) {\n result.push(dirPath)\n }\n else {\n addDirToResult = true\n }\n }\n\n const childNames = await orIfFileNotExist(readdir(dirPath), [])\n childNames.sort()\n\n let nodeModuleContent: Array | null = null\n\n const dirs: Array = []\n // our handler is async, but we should add sorted files, so, we add file to result not in the mapper, but after map\n const sortedFilePaths = await BluebirdPromise.map(childNames, name => {\n if (name === \".DS_Store\" || name === \".gitkeep\") {\n return null\n }\n\n const filePath = dirPath + path.sep + name\n return lstat(filePath)\n .then(stat => {\n if (filter != null && !filter(filePath, stat)) {\n return null\n }\n\n const consumerResult = consumer == null ? null : consumer.consume(filePath, stat, dirPath, childNames)\n if (consumerResult === false) {\n return null\n }\n else if (consumerResult == null || !(\"then\" in consumerResult)) {\n if (stat.isDirectory()) {\n dirs.push(name)\n return null\n }\n else {\n return filePath\n }\n }\n else {\n return (consumerResult as Promise)\n .then((it): any => {\n if (it != null && Array.isArray(it)) {\n nodeModuleContent = it\n return null\n }\n\n // asarUtil can return modified stat (symlink handling)\n if ((it != null && \"isDirectory\" in it ? (it as Stats) : stat).isDirectory()) {\n dirs.push(name)\n return null\n }\n else {\n return filePath\n }\n })\n }\n })\n }, CONCURRENCY)\n\n for (const child of sortedFilePaths) {\n if (child != null) {\n result.push(child)\n }\n }\n\n dirs.sort()\n for (const child of dirs) {\n queue.push(dirPath + path.sep + child)\n }\n\n if (nodeModuleContent != null) {\n result = result.concat(nodeModuleContent)\n }\n }\n\n return result\n}\n\nconst _isUseHardLink = process.platform !== \"win32\" && process.env.USE_HARD_LINKS !== \"false\" && (require(\"is-ci\") || process.env.USE_HARD_LINKS === \"true\")\n\nexport function copyFile(src: string, dest: string, isEnsureDir = true) {\n return (isEnsureDir ? ensureDir(path.dirname(dest)) : Promise.resolve())\n .then(() => copyOrLinkFile(src, dest, null, false))\n}\n\n/**\n * Hard links is used if supported and allowed.\n * File permission is fixed — allow execute for all if owner can, allow read for all if owner can.\n *\n * ensureDir is not called, dest parent dir must exists\n */\nexport function copyOrLinkFile(src: string, dest: string, stats?: Stats | null, isUseHardLink?: boolean, exDevErrorHandler?: (() => boolean) | null): Promise {\n if (isUseHardLink === undefined) {\n isUseHardLink = _isUseHardLink\n }\n\n if (stats != null) {\n const originalModeNumber = stats.mode\n const mode = new Mode(stats)\n if (mode.owner.execute) {\n mode.group.execute = true\n mode.others.execute = true\n }\n\n mode.group.read = true\n mode.others.read = true\n\n mode.setuid = false\n mode.setgid = false\n\n if (originalModeNumber !== stats.mode) {\n if (log.isDebugEnabled) {\n const oldMode = new Mode({mode: originalModeNumber})\n log.debug({file: dest, oldMode, mode}, \"permissions fixed from\")\n }\n\n // https://helgeklein.com/blog/2009/05/hard-links-and-permissions-acls/\n // Permissions on all hard links to the same data on disk are always identical. The same applies to attributes.\n // That means if you change the permissions/owner/attributes on one hard link, you will immediately see the changes on all other hard links.\n if (isUseHardLink) {\n isUseHardLink = false\n log.debug({dest}, \"copied, but not linked, because file permissions need to be fixed\")\n }\n }\n }\n\n if (isUseHardLink) {\n return link(src, dest)\n .catch(e => {\n if (e.code === \"EXDEV\") {\n const isLog = exDevErrorHandler == null ? true : exDevErrorHandler()\n if (isLog && log.isDebugEnabled) {\n log.debug({error: e.message}, \"cannot copy using hard link\")\n }\n return doCopyFile(src, dest, stats)\n }\n else {\n throw e\n }\n })\n }\n return doCopyFile(src, dest, stats)\n}\n\nfunction doCopyFile(src: string, dest: string, stats: Stats | null | undefined): Promise {\n const promise = _nodeCopyFile(src, dest)\n if (stats == null) {\n return promise\n }\n\n return promise\n .then(() => chmod(dest, stats.mode))\n}\n\nexport class FileCopier {\n isUseHardLink: boolean\n\n constructor(private readonly isUseHardLinkFunction?: ((file: string) => boolean) | null, private readonly transformer?: FileTransformer | null) {\n if (isUseHardLinkFunction === USE_HARD_LINKS) {\n this.isUseHardLink = true\n }\n else {\n this.isUseHardLink = _isUseHardLink && isUseHardLinkFunction !== DO_NOT_USE_HARD_LINKS\n }\n }\n\n async copy(src: string, dest: string, stat: Stats | undefined) {\n let afterCopyTransformer: AfterCopyFileTransformer | null = null\n if (this.transformer != null && stat != null && stat.isFile()) {\n let data = this.transformer(src)\n if (data != null) {\n if (typeof data === \"object\" && \"then\" in data) {\n data = await data\n }\n\n if (data != null) {\n if (data instanceof CopyFileTransformer) {\n afterCopyTransformer = data.afterCopyTransformer\n }\n else {\n await writeFile(dest, data)\n return\n }\n }\n }\n }\n\n const isUseHardLink = afterCopyTransformer == null && ((!this.isUseHardLink || this.isUseHardLinkFunction == null) ? this.isUseHardLink : this.isUseHardLinkFunction(dest))\n await copyOrLinkFile(src, dest, stat, isUseHardLink, isUseHardLink ? () => {\n // files are copied concurrently, so, we must not check here currentIsUseHardLink — our code can be executed after that other handler will set currentIsUseHardLink to false\n if (this.isUseHardLink) {\n this.isUseHardLink = false\n return true\n }\n else {\n return false\n }\n } : null)\n\n if (afterCopyTransformer != null) {\n await afterCopyTransformer(dest)\n }\n }\n}\n\nexport interface CopyDirOptions {\n filter?: Filter | null\n transformer?: FileTransformer | null\n isUseHardLink?: ((file: string) => boolean) | null\n}\n\n/**\n * Empty directories is never created.\n * Hard links is used if supported and allowed.\n */\nexport function copyDir(src: string, destination: string, options: CopyDirOptions = {}): Promise {\n const fileCopier = new FileCopier(options.isUseHardLink, options.transformer)\n\n if (log.isDebugEnabled) {\n log.debug({src, destination}, `copying${fileCopier.isUseHardLink ? \" using hard links\" : \"\"}`)\n }\n\n const createdSourceDirs = new Set()\n const links: Array = []\n return walk(src, options.filter, {\n consume: async (file, stat, parent) => {\n if (!stat.isFile() && !stat.isSymbolicLink()) {\n return\n }\n\n if (!createdSourceDirs.has(parent)) {\n await ensureDir(parent.replace(src, destination))\n createdSourceDirs.add(parent)\n }\n\n const destFile = file.replace(src, destination)\n if (stat.isFile()) {\n await fileCopier.copy(file, destFile, stat)\n }\n else {\n links.push({file: destFile, link: await readlink(file)})\n }\n }\n })\n .then(() => BluebirdPromise.map(links, it => symlink(it.link, it.file), CONCURRENCY))\n}\n\nexport const DO_NOT_USE_HARD_LINKS = (file: string) => false\nexport const USE_HARD_LINKS = (file: string) => true\n\nexport interface Link {\n readonly link: string,\n readonly file: string\n}"],"sourceRoot":""}