UNPKG

nexe

Version:

Create a single executable out of your Node.js application

21 lines 490 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const util_1 = require("../util"); function default_1(compiler, next) { return __awaiter(this, void 0, void 0, function* () { yield next(); compiler.shims.push((0, util_1.wrap)([ 'process.__nexe = {};', 'const fsPatcher = (function() {', 'const module = {exports: {}};', 'const exports = module.exports;', "var __node_require__ = require, __node_module__ = module;\n/******/ (() => { // webpackBootstrap\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 5:\n/***/ ((__unused_webpack_module, exports, __webpack_require__) => {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.AliasFS = void 0;\nconst ProxiedFS_1 = __webpack_require__(105);\nclass AliasFS extends ProxiedFS_1.ProxiedFS {\n constructor(target, { baseFs, pathUtils }) {\n super(pathUtils);\n this.target = target;\n this.baseFs = baseFs;\n }\n getRealPath() {\n return this.target;\n }\n getBaseFs() {\n return this.baseFs;\n }\n mapFromBase(p) {\n return p;\n }\n mapToBase(p) {\n return p;\n }\n}\nexports.AliasFS = AliasFS;\n\n\n/***/ }),\n\n/***/ 472:\n/***/ ((__unused_webpack_module, exports, __webpack_require__) => {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.CwdFS = void 0;\nconst NodeFS_1 = __webpack_require__(843);\nconst ProxiedFS_1 = __webpack_require__(105);\nconst path_1 = __webpack_require__(905);\nclass CwdFS extends ProxiedFS_1.ProxiedFS {\n constructor(target, { baseFs = new NodeFS_1.NodeFS() } = {}) {\n super(path_1.ppath);\n this.target = this.pathUtils.normalize(target);\n this.baseFs = baseFs;\n }\n getRealPath() {\n return this.pathUtils.resolve(this.baseFs.getRealPath(), this.target);\n }\n resolve(p) {\n if (this.pathUtils.isAbsolute(p)) {\n return path_1.ppath.normalize(p);\n }\n else {\n return this.baseFs.resolve(path_1.ppath.join(this.target, p));\n }\n }\n mapFromBase(path) {\n return path;\n }\n mapToBase(path) {\n if (this.pathUtils.isAbsolute(path)) {\n return path;\n }\n else {\n return this.pathUtils.join(this.target, path);\n }\n }\n}\nexports.CwdFS = CwdFS;\n\n\n/***/ }),\n\n/***/ 498:\n/***/ ((__unused_webpack_module, exports, __webpack_require__) => {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.normalizeLineEndings = exports.BasePortableFakeFS = exports.FakeFS = void 0;\nconst crypto_1 = __webpack_require__(113);\nconst os_1 = __webpack_require__(37);\nconst copyPromise_1 = __webpack_require__(142);\nconst path_1 = __webpack_require__(905);\nclass FakeFS {\n constructor(pathUtils) {\n this.pathUtils = pathUtils;\n }\n async *genTraversePromise(init, { stableSort = false } = {}) {\n const stack = [init];\n while (stack.length > 0) {\n const p = stack.shift();\n const entry = await this.lstatPromise(p);\n if (entry.isDirectory()) {\n const entries = await this.readdirPromise(p);\n if (stableSort) {\n for (const entry of entries.sort()) {\n stack.push(this.pathUtils.join(p, entry));\n }\n }\n else {\n throw new Error(`Not supported`);\n }\n }\n else {\n yield p;\n }\n }\n }\n async checksumFilePromise(path, { algorithm = `sha512` } = {}) {\n const fd = await this.openPromise(path, `r`);\n try {\n const CHUNK_SIZE = 65536;\n const chunk = Buffer.allocUnsafeSlow(CHUNK_SIZE);\n const hash = (0, crypto_1.createHash)(algorithm);\n let bytesRead = 0;\n while ((bytesRead = await this.readPromise(fd, chunk, 0, CHUNK_SIZE)) !== 0)\n hash.update(bytesRead === CHUNK_SIZE ? chunk : chunk.slice(0, bytesRead));\n return hash.digest(`hex`);\n }\n finally {\n await this.closePromise(fd);\n }\n }\n async removePromise(p, { recursive = true, maxRetries = 5 } = {}) {\n let stat;\n try {\n stat = await this.lstatPromise(p);\n }\n catch (error) {\n if (error.code === `ENOENT`) {\n return;\n }\n else {\n throw error;\n }\n }\n if (stat.isDirectory()) {\n if (recursive) {\n const entries = await this.readdirPromise(p);\n await Promise.all(entries.map(entry => {\n return this.removePromise(this.pathUtils.resolve(p, entry));\n }));\n }\n // 5 gives 1s worth of retries at worst\n for (let t = 0; t <= maxRetries; t++) {\n try {\n await this.rmdirPromise(p);\n break;\n }\n catch (error) {\n if (error.code !== `EBUSY` && error.code !== `ENOTEMPTY`) {\n throw error;\n }\n else if (t < maxRetries) {\n await new Promise(resolve => setTimeout(resolve, t * 100));\n }\n }\n }\n }\n else {\n await this.unlinkPromise(p);\n }\n }\n removeSync(p, { recursive = true } = {}) {\n let stat;\n try {\n stat = this.lstatSync(p);\n }\n catch (error) {\n if (error.code === `ENOENT`) {\n return;\n }\n else {\n throw error;\n }\n }\n if (stat.isDirectory()) {\n if (recursive)\n for (const entry of this.readdirSync(p))\n this.removeSync(this.pathUtils.resolve(p, entry));\n this.rmdirSync(p);\n }\n else {\n this.unlinkSync(p);\n }\n }\n async mkdirpPromise(p, { chmod, utimes } = {}) {\n p = this.resolve(p);\n if (p === this.pathUtils.dirname(p))\n return undefined;\n const parts = p.split(this.pathUtils.sep);\n let createdDirectory;\n for (let u = 2; u <= parts.length; ++u) {\n const subPath = parts.slice(0, u).join(this.pathUtils.sep);\n if (!this.existsSync(subPath)) {\n try {\n await this.mkdirPromise(subPath);\n }\n catch (error) {\n if (error.code === `EEXIST`) {\n continue;\n }\n else {\n throw error;\n }\n }\n createdDirectory !== null && createdDirectory !== void 0 ? createdDirectory : (createdDirectory = subPath);\n if (chmod != null)\n await this.chmodPromise(subPath, chmod);\n if (utimes != null) {\n await this.utimesPromise(subPath, utimes[0], utimes[1]);\n }\n else {\n const parentStat = await this.statPromise(this.pathUtils.dirname(subPath));\n await this.utimesPromise(subPath, parentStat.atime, parentStat.mtime);\n }\n }\n }\n return createdDirectory;\n }\n mkdirpSync(p, { chmod, utimes } = {}) {\n p = this.resolve(p);\n if (p === this.pathUtils.dirname(p))\n return undefined;\n const parts = p.split(this.pathUtils.sep);\n let createdDirectory;\n for (let u = 2; u <= parts.length; ++u) {\n const subPath = parts.slice(0, u).join(this.pathUtils.sep);\n if (!this.existsSync(subPath)) {\n try {\n this.mkdirSync(subPath);\n }\n catch (error) {\n if (error.code === `EEXIST`) {\n continue;\n }\n else {\n throw error;\n }\n }\n createdDirectory !== null && createdDirectory !== void 0 ? createdDirectory : (createdDirectory = subPath);\n if (chmod != null)\n this.chmodSync(subPath, chmod);\n if (utimes != null) {\n this.utimesSync(subPath, utimes[0], utimes[1]);\n }\n else {\n const parentStat = this.statSync(this.pathUtils.dirname(subPath));\n this.utimesSync(subPath, parentStat.atime, parentStat.mtime);\n }\n }\n }\n return createdDirectory;\n }\n async copyPromise(destination, source, { baseFs = this, overwrite = true, stableSort = false, stableTime = false, linkStrategy = null } = {}) {\n return await (0, copyPromise_1.copyPromise)(this, destination, baseFs, source, { overwrite, stableSort, stableTime, linkStrategy });\n }\n copySync(destination, source, { baseFs = this, overwrite = true } = {}) {\n const stat = baseFs.lstatSync(source);\n const exists = this.existsSync(destination);\n if (stat.isDirectory()) {\n this.mkdirpSync(destination);\n const directoryListing = baseFs.readdirSync(source);\n for (const entry of directoryListing) {\n this.copySync(this.pathUtils.join(destination, entry), baseFs.pathUtils.join(source, entry), { baseFs, overwrite });\n }\n }\n else if (stat.isFile()) {\n if (!exists || overwrite) {\n if (exists)\n this.removeSync(destination);\n const content = baseFs.readFileSync(source);\n this.writeFileSync(destination, content);\n }\n }\n else if (stat.isSymbolicLink()) {\n if (!exists || overwrite) {\n if (exists)\n this.removeSync(destination);\n const target = baseFs.readlinkSync(source);\n this.symlinkSync((0, path_1.convertPath)(this.pathUtils, target), destination);\n }\n }\n else {\n throw new Error(`Unsupported file type (file: ${source}, mode: 0o${stat.mode.toString(8).padStart(6, `0`)})`);\n }\n const mode = stat.mode & 0o777;\n this.chmodSync(destination, mode);\n }\n async changeFilePromise(p, content, opts = {}) {\n if (Buffer.isBuffer(content)) {\n return this.changeFileBufferPromise(p, content, opts);\n }\n else {\n return this.changeFileTextPromise(p, content, opts);\n }\n }\n async changeFileBufferPromise(p, content, { mode } = {}) {\n let current = Buffer.alloc(0);\n try {\n current = await this.readFilePromise(p);\n }\n catch (error) {\n // ignore errors, no big deal\n }\n if (Buffer.compare(current, content) === 0)\n return;\n await this.writeFilePromise(p, content, { mode });\n }\n async changeFileTextPromise(p, content, { automaticNewlines, mode } = {}) {\n let current = ``;\n try {\n current = await this.readFilePromise(p, `utf8`);\n }\n catch (error) {\n // ignore errors, no big deal\n }\n const normalizedContent = automaticNewlines\n ? normalizeLineEndings(current, content)\n : content;\n if (current === normalizedContent)\n return;\n await this.writeFilePromise(p, normalizedContent, { mode });\n }\n changeFileSync(p, content, opts = {}) {\n if (Buffer.isBuffer(content)) {\n return this.changeFileBufferSync(p, content, opts);\n }\n else {\n return this.changeFileTextSync(p, content, opts);\n }\n }\n changeFileBufferSync(p, content, { mode } = {}) {\n let current = Buffer.alloc(0);\n try {\n current = this.readFileSync(p);\n }\n catch (error) {\n // ignore errors, no big deal\n }\n if (Buffer.compare(current, content) === 0)\n return;\n this.writeFileSync(p, content, { mode });\n }\n changeFileTextSync(p, content, { automaticNewlines = false, mode } = {}) {\n let current = ``;\n try {\n current = this.readFileSync(p, `utf8`);\n }\n catch (error) {\n // ignore errors, no big deal\n }\n const normalizedContent = automaticNewlines\n ? normalizeLineEndings(current, content)\n : content;\n if (current === normalizedContent)\n return;\n this.writeFileSync(p, normalizedContent, { mode });\n }\n async movePromise(fromP, toP) {\n try {\n await this.renamePromise(fromP, toP);\n }\n catch (error) {\n if (error.code === `EXDEV`) {\n await this.copyPromise(toP, fromP);\n await this.removePromise(fromP);\n }\n else {\n throw error;\n }\n }\n }\n moveSync(fromP, toP) {\n try {\n this.renameSync(fromP, toP);\n }\n catch (error) {\n if (error.code === `EXDEV`) {\n this.copySync(toP, fromP);\n this.removeSync(fromP);\n }\n else {\n throw error;\n }\n }\n }\n async lockPromise(affectedPath, callback) {\n const lockPath = `${affectedPath}.flock`;\n const interval = 1000 / 60;\n const startTime = Date.now();\n let fd = null;\n // Even when we detect that a lock file exists, we still look inside to see\n // whether the pid that created it is still alive. It's not foolproof\n // (there are false positive), but there are no false negative and that's\n // all that matters in 99% of the cases.\n const isAlive = async () => {\n let pid;\n try {\n ([pid] = await this.readJsonPromise(lockPath));\n }\n catch (error) {\n // If we can't read the file repeatedly, we assume the process was\n // aborted before even writing finishing writing the payload.\n return Date.now() - startTime < 500;\n }\n try {\n // \"As a special case, a signal of 0 can be used to test for the\n // existence of a process\" - so we check whether it's alive.\n process.kill(pid, 0);\n return true;\n }\n catch (error) {\n return false;\n }\n };\n while (fd === null) {\n try {\n fd = await this.openPromise(lockPath, `wx`);\n }\n catch (error) {\n if (error.code === `EEXIST`) {\n if (!await isAlive()) {\n try {\n await this.unlinkPromise(lockPath);\n continue;\n }\n catch (error) {\n // No big deal if we can't remove it. Just fallback to wait for\n // it to be eventually released by its owner.\n }\n }\n if (Date.now() - startTime < 60 * 1000) {\n await new Promise(resolve => setTimeout(resolve, interval));\n }\n else {\n throw new Error(`Couldn't acquire a lock in a reasonable time (via ${lockPath})`);\n }\n }\n else {\n throw error;\n }\n }\n }\n await this.writePromise(fd, JSON.stringify([process.pid]));\n try {\n return await callback();\n }\n finally {\n try {\n // closePromise needs to come before unlinkPromise otherwise another process can attempt\n // to get the file handle after the unlink but before close resuling in\n // EPERM: operation not permitted, open\n await this.closePromise(fd);\n await this.unlinkPromise(lockPath);\n }\n catch (error) {\n // noop\n }\n }\n }\n async readJsonPromise(p) {\n const content = await this.readFilePromise(p, `utf8`);\n try {\n return JSON.parse(content);\n }\n catch (error) {\n error.message += ` (in ${p})`;\n throw error;\n }\n }\n readJsonSync(p) {\n const content = this.readFileSync(p, `utf8`);\n try {\n return JSON.parse(content);\n }\n catch (error) {\n error.message += ` (in ${p})`;\n throw error;\n }\n }\n async writeJsonPromise(p, data) {\n return await this.writeFilePromise(p, `${JSON.stringify(data, null, 2)}\\n`);\n }\n writeJsonSync(p, data) {\n return this.writeFileSync(p, `${JSON.stringify(data, null, 2)}\\n`);\n }\n async preserveTimePromise(p, cb) {\n const stat = await this.lstatPromise(p);\n const result = await cb();\n if (typeof result !== `undefined`)\n p = result;\n await this.lutimesPromise(p, stat.atime, stat.mtime);\n }\n async preserveTimeSync(p, cb) {\n const stat = this.lstatSync(p);\n const result = cb();\n if (typeof result !== `undefined`)\n p = result;\n this.lutimesSync(p, stat.atime, stat.mtime);\n }\n}\nexports.FakeFS = FakeFS;\nclass BasePortableFakeFS extends FakeFS {\n constructor() {\n super(path_1.ppath);\n }\n}\nexports.BasePortableFakeFS = BasePortableFakeFS;\nfunction getEndOfLine(content) {\n const matches = content.match(/\\r?\\n/g);\n if (matches === null)\n return os_1.EOL;\n const crlf = matches.filter(nl => nl === `\\r\\n`).length;\n const lf = matches.length - crlf;\n return crlf > lf ? `\\r\\n` : `\\n`;\n}\nfunction normalizeLineEndings(originalContent, newContent) {\n return newContent.replace(/\\r?\\n/g, getEndOfLine(originalContent));\n}\nexports.normalizeLineEndings = normalizeLineEndings;\n\n\n/***/ }),\n\n/***/ 238:\n/***/ ((__unused_webpack_module, exports, __webpack_require__) => {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.JailFS = void 0;\nconst NodeFS_1 = __webpack_require__(843);\nconst ProxiedFS_1 = __webpack_require__(105);\nconst path_1 = __webpack_require__(905);\nconst JAIL_ROOT = path_1.PortablePath.root;\nclass JailFS extends ProxiedFS_1.ProxiedFS {\n constructor(target, { baseFs = new NodeFS_1.NodeFS() } = {}) {\n super(path_1.ppath);\n this.target = this.pathUtils.resolve(path_1.PortablePath.root, target);\n this.baseFs = baseFs;\n }\n getRealPath() {\n return this.pathUtils.resolve(this.baseFs.getRealPath(), this.pathUtils.relative(path_1.PortablePath.root, this.target));\n }\n getTarget() {\n return this.target;\n }\n getBaseFs() {\n return this.baseFs;\n }\n mapToBase(p) {\n const normalized = this.pathUtils.normalize(p);\n if (this.pathUtils.isAbsolute(p))\n return this.pathUtils.resolve(this.target, this.pathUtils.relative(JAIL_ROOT, p));\n if (normalized.match(/^\\.\\.\\/?/))\n throw new Error(`Resolving this path (${p}) would escape the jail`);\n return this.pathUtils.resolve(this.target, p);\n }\n mapFromBase(p) {\n return this.pathUtils.resolve(JAIL_ROOT, this.pathUtils.relative(this.target, p));\n }\n}\nexports.JailFS = JailFS;\n\n\n/***/ }),\n\n/***/ 130:\n/***/ ((__unused_webpack_module, exports, __webpack_require__) => {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.LazyFS = void 0;\nconst ProxiedFS_1 = __webpack_require__(105);\nclass LazyFS extends ProxiedFS_1.ProxiedFS {\n constructor(factory, pathUtils) {\n super(pathUtils);\n this.instance = null;\n this.factory = factory;\n }\n get baseFs() {\n if (!this.instance)\n this.instance = this.factory();\n return this.instance;\n }\n set baseFs(value) {\n this.instance = value;\n }\n mapFromBase(p) {\n return p;\n }\n mapToBase(p) {\n return p;\n }\n}\nexports.LazyFS = LazyFS;\n\n\n/***/ }),\n\n/***/ 547:\n/***/ ((__unused_webpack_module, exports, __webpack_require__) => {\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.MountFS = void 0;\nconst tslib_1 = __webpack_require__(177);\nconst fs_1 = __webpack_require__(147);\nconst FakeFS_1 = __webpack_require__(498);\nconst NodeFS_1 = __webpack_require__(843);\nconst watchFile_1 = __webpack_require__(126);\nconst errors = tslib_1.__importStar(__webpack_require__(377));\nconst path_1 = __webpack_require__(905);\n// Only file descriptors prefixed by those values will be forwarded to the MountFS\n// instances. Note that the highest MOUNT_MAGIC bit MUST NOT be set, otherwise the\n// resulting fd becomes a negative integer, which isn't supposed to happen per\n// the unix rules (caused problems w/ Go).\n//\n// Those values must be synced with packages/yarnpkg-pnp/sources/esm-loader/fspatch.ts\n//\nconst MOUNT_MASK = 0xff000000;\nclass MountFS extends FakeFS_1.BasePortableFakeFS {\n constructor({ baseFs = new NodeFS_1.NodeFS(), filter = null, magicByte = 0x2a, maxOpenFiles = Infinity, useCache = true, maxAge = 5000, typeCheck = fs_1.constants.S_IFREG, getMountPoint, factoryPromise, factorySync }) {\n if (Math.floor(magicByte) !== magicByte || !(magicByte > 1 && magicByte <= 127))\n throw new Error(`The magic byte must be set to a round value between 1 and 127 included`);\n super();\n this.fdMap = new Map();\n this.nextFd = 3;\n this.isMount = new Set();\n this.notMount = new Set();\n this.realPaths = new Map();\n this.limitOpenFilesTimeout = null;\n this.baseFs = baseFs;\n this.mountInstances = useCache ? new Map() : null;\n this.factoryPromise = factoryPromise;\n this.factorySync = factorySync;\n this.filter = filter;\n this.getMountPoint = getMountPoint;\n this.magic = magicByte << 24;\n this.maxAge = maxAge;\n this.maxOpenFiles = maxOpenFiles;\n this.typeCheck = typeCheck;\n }\n getExtractHint(hints) {\n return this.baseFs.getExtractHint(hints);\n }\n getRealPath() {\n return this.baseFs.getRealPath();\n }\n saveAndClose() {\n var _a;\n (0, watchFile_1.unwatchAllFiles)(this);\n if (this.mountInstances) {\n for (const [path, { childFs }] of this.mountInstances.entries()) {\n (_a = childFs.saveAndClose) === null || _a === void 0 ? void 0 : _a.call(childFs);\n this.mountInstances.delete(path);\n }\n }\n }\n discardAndClose() {\n var _a;\n (0, watchFile_1.unwatchAllFiles)(this);\n if (this.mountInstances) {\n for (const [path, { childFs }] of this.mountInstances.entries()) {\n (_a = childFs.discardAndClose) === null || _a === void 0 ? void 0 : _a.call(childFs);\n this.mountInstances.delete(path);\n }\n }\n }\n resolve(p) {\n return this.baseFs.resolve(p);\n }\n remapFd(mountFs, fd) {\n const remappedFd = this.nextFd++ | this.magic;\n this.fdMap.set(remappedFd, [mountFs, fd]);\n return remappedFd;\n }\n async openPromise(p, flags, mode) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.openPromise(p, flags, mode);\n }, async (mountFs, { subPath }) => {\n return this.remapFd(mountFs, await mountFs.openPromise(subPath, flags, mode));\n });\n }\n openSync(p, flags, mode) {\n return this.makeCallSync(p, () => {\n return this.baseFs.openSync(p, flags, mode);\n }, (mountFs, { subPath }) => {\n return this.remapFd(mountFs, mountFs.openSync(subPath, flags, mode));\n });\n }\n async opendirPromise(p, opts) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.opendirPromise(p, opts);\n }, async (mountFs, { subPath }) => {\n return await mountFs.opendirPromise(subPath, opts);\n }, {\n requireSubpath: false,\n });\n }\n opendirSync(p, opts) {\n return this.makeCallSync(p, () => {\n return this.baseFs.opendirSync(p, opts);\n }, (mountFs, { subPath }) => {\n return mountFs.opendirSync(subPath, opts);\n }, {\n requireSubpath: false,\n });\n }\n async readPromise(fd, buffer, offset, length, position) {\n if ((fd & MOUNT_MASK) !== this.magic)\n return await this.baseFs.readPromise(fd, buffer, offset, length, position);\n const entry = this.fdMap.get(fd);\n if (typeof entry === `undefined`)\n throw errors.EBADF(`read`);\n const [mountFs, realFd] = entry;\n return await mountFs.readPromise(realFd, buffer, offset, length, position);\n }\n readSync(fd, buffer, offset, length, position) {\n if ((fd & MOUNT_MASK) !== this.magic)\n return this.baseFs.readSync(fd, buffer, offset, length, position);\n const entry = this.fdMap.get(fd);\n if (typeof entry === `undefined`)\n throw errors.EBADF(`readSync`);\n const [mountFs, realFd] = entry;\n return mountFs.readSync(realFd, buffer, offset, length, position);\n }\n async writePromise(fd, buffer, offset, length, position) {\n if ((fd & MOUNT_MASK) !== this.magic) {\n if (typeof buffer === `string`) {\n return await this.baseFs.writePromise(fd, buffer, offset);\n }\n else {\n return await this.baseFs.writePromise(fd, buffer, offset, length, position);\n }\n }\n const entry = this.fdMap.get(fd);\n if (typeof entry === `undefined`)\n throw errors.EBADF(`write`);\n const [mountFs, realFd] = entry;\n if (typeof buffer === `string`) {\n return await mountFs.writePromise(realFd, buffer, offset);\n }\n else {\n return await mountFs.writePromise(realFd, buffer, offset, length, position);\n }\n }\n writeSync(fd, buffer, offset, length, position) {\n if ((fd & MOUNT_MASK) !== this.magic) {\n if (typeof buffer === `string`) {\n return this.baseFs.writeSync(fd, buffer, offset);\n }\n else {\n return this.baseFs.writeSync(fd, buffer, offset, length, position);\n }\n }\n const entry = this.fdMap.get(fd);\n if (typeof entry === `undefined`)\n throw errors.EBADF(`writeSync`);\n const [mountFs, realFd] = entry;\n if (typeof buffer === `string`) {\n return mountFs.writeSync(realFd, buffer, offset);\n }\n else {\n return mountFs.writeSync(realFd, buffer, offset, length, position);\n }\n }\n async closePromise(fd) {\n if ((fd & MOUNT_MASK) !== this.magic)\n return await this.baseFs.closePromise(fd);\n const entry = this.fdMap.get(fd);\n if (typeof entry === `undefined`)\n throw errors.EBADF(`close`);\n this.fdMap.delete(fd);\n const [mountFs, realFd] = entry;\n return await mountFs.closePromise(realFd);\n }\n closeSync(fd) {\n if ((fd & MOUNT_MASK) !== this.magic)\n return this.baseFs.closeSync(fd);\n const entry = this.fdMap.get(fd);\n if (typeof entry === `undefined`)\n throw errors.EBADF(`closeSync`);\n this.fdMap.delete(fd);\n const [mountFs, realFd] = entry;\n return mountFs.closeSync(realFd);\n }\n createReadStream(p, opts) {\n if (p === null)\n return this.baseFs.createReadStream(p, opts);\n return this.makeCallSync(p, () => {\n return this.baseFs.createReadStream(p, opts);\n }, (mountFs, { archivePath, subPath }) => {\n const stream = mountFs.createReadStream(subPath, opts);\n // This is a very hacky workaround. `MountOpenFS` shouldn't have to work with `NativePath`s.\n // Ref: https://github.com/yarnpkg/berry/pull/3774\n // TODO: think of a better solution\n stream.path = path_1.npath.fromPortablePath(this.pathUtils.join(archivePath, subPath));\n return stream;\n });\n }\n createWriteStream(p, opts) {\n if (p === null)\n return this.baseFs.createWriteStream(p, opts);\n return this.makeCallSync(p, () => {\n return this.baseFs.createWriteStream(p, opts);\n }, (mountFs, { subPath }) => {\n return mountFs.createWriteStream(subPath, opts);\n });\n }\n async realpathPromise(p) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.realpathPromise(p);\n }, async (mountFs, { archivePath, subPath }) => {\n let realArchivePath = this.realPaths.get(archivePath);\n if (typeof realArchivePath === `undefined`) {\n realArchivePath = await this.baseFs.realpathPromise(archivePath);\n this.realPaths.set(archivePath, realArchivePath);\n }\n return this.pathUtils.join(realArchivePath, this.pathUtils.relative(path_1.PortablePath.root, await mountFs.realpathPromise(subPath)));\n });\n }\n realpathSync(p) {\n return this.makeCallSync(p, () => {\n return this.baseFs.realpathSync(p);\n }, (mountFs, { archivePath, subPath }) => {\n let realArchivePath = this.realPaths.get(archivePath);\n if (typeof realArchivePath === `undefined`) {\n realArchivePath = this.baseFs.realpathSync(archivePath);\n this.realPaths.set(archivePath, realArchivePath);\n }\n return this.pathUtils.join(realArchivePath, this.pathUtils.relative(path_1.PortablePath.root, mountFs.realpathSync(subPath)));\n });\n }\n async existsPromise(p) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.existsPromise(p);\n }, async (mountFs, { subPath }) => {\n return await mountFs.existsPromise(subPath);\n });\n }\n existsSync(p) {\n return this.makeCallSync(p, () => {\n return this.baseFs.existsSync(p);\n }, (mountFs, { subPath }) => {\n return mountFs.existsSync(subPath);\n });\n }\n async accessPromise(p, mode) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.accessPromise(p, mode);\n }, async (mountFs, { subPath }) => {\n return await mountFs.accessPromise(subPath, mode);\n });\n }\n accessSync(p, mode) {\n return this.makeCallSync(p, () => {\n return this.baseFs.accessSync(p, mode);\n }, (mountFs, { subPath }) => {\n return mountFs.accessSync(subPath, mode);\n });\n }\n async statPromise(p, opts) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.statPromise(p, opts);\n }, async (mountFs, { subPath }) => {\n return await mountFs.statPromise(subPath, opts);\n });\n }\n statSync(p, opts) {\n return this.makeCallSync(p, () => {\n return this.baseFs.statSync(p, opts);\n }, (mountFs, { subPath }) => {\n return mountFs.statSync(subPath, opts);\n });\n }\n async fstatPromise(fd, opts) {\n if ((fd & MOUNT_MASK) !== this.magic)\n return this.baseFs.fstatPromise(fd, opts);\n const entry = this.fdMap.get(fd);\n if (typeof entry === `undefined`)\n throw errors.EBADF(`fstat`);\n const [mountFs, realFd] = entry;\n return mountFs.fstatPromise(realFd, opts);\n }\n fstatSync(fd, opts) {\n if ((fd & MOUNT_MASK) !== this.magic)\n return this.baseFs.fstatSync(fd, opts);\n const entry = this.fdMap.get(fd);\n if (typeof entry === `undefined`)\n throw errors.EBADF(`fstatSync`);\n const [mountFs, realFd] = entry;\n return mountFs.fstatSync(realFd, opts);\n }\n async lstatPromise(p, opts) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.lstatPromise(p, opts);\n }, async (mountFs, { subPath }) => {\n return await mountFs.lstatPromise(subPath, opts);\n });\n }\n lstatSync(p, opts) {\n return this.makeCallSync(p, () => {\n return this.baseFs.lstatSync(p, opts);\n }, (mountFs, { subPath }) => {\n return mountFs.lstatSync(subPath, opts);\n });\n }\n async fchmodPromise(fd, mask) {\n if ((fd & MOUNT_MASK) !== this.magic)\n return this.baseFs.fchmodPromise(fd, mask);\n const entry = this.fdMap.get(fd);\n if (typeof entry === `undefined`)\n throw errors.EBADF(`fchmod`);\n const [mountFs, realFd] = entry;\n return mountFs.fchmodPromise(realFd, mask);\n }\n fchmodSync(fd, mask) {\n if ((fd & MOUNT_MASK) !== this.magic)\n return this.baseFs.fchmodSync(fd, mask);\n const entry = this.fdMap.get(fd);\n if (typeof entry === `undefined`)\n throw errors.EBADF(`fchmodSync`);\n const [mountFs, realFd] = entry;\n return mountFs.fchmodSync(realFd, mask);\n }\n async chmodPromise(p, mask) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.chmodPromise(p, mask);\n }, async (mountFs, { subPath }) => {\n return await mountFs.chmodPromise(subPath, mask);\n });\n }\n chmodSync(p, mask) {\n return this.makeCallSync(p, () => {\n return this.baseFs.chmodSync(p, mask);\n }, (mountFs, { subPath }) => {\n return mountFs.chmodSync(subPath, mask);\n });\n }\n async fchownPromise(fd, uid, gid) {\n if ((fd & MOUNT_MASK) !== this.magic)\n return this.baseFs.fchownPromise(fd, uid, gid);\n const entry = this.fdMap.get(fd);\n if (typeof entry === `undefined`)\n throw errors.EBADF(`fchown`);\n const [zipFs, realFd] = entry;\n return zipFs.fchownPromise(realFd, uid, gid);\n }\n fchownSync(fd, uid, gid) {\n if ((fd & MOUNT_MASK) !== this.magic)\n return this.baseFs.fchownSync(fd, uid, gid);\n const entry = this.fdMap.get(fd);\n if (typeof entry === `undefined`)\n throw errors.EBADF(`fchownSync`);\n const [zipFs, realFd] = entry;\n return zipFs.fchownSync(realFd, uid, gid);\n }\n async chownPromise(p, uid, gid) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.chownPromise(p, uid, gid);\n }, async (mountFs, { subPath }) => {\n return await mountFs.chownPromise(subPath, uid, gid);\n });\n }\n chownSync(p, uid, gid) {\n return this.makeCallSync(p, () => {\n return this.baseFs.chownSync(p, uid, gid);\n }, (mountFs, { subPath }) => {\n return mountFs.chownSync(subPath, uid, gid);\n });\n }\n async renamePromise(oldP, newP) {\n return await this.makeCallPromise(oldP, async () => {\n return await this.makeCallPromise(newP, async () => {\n return await this.baseFs.renamePromise(oldP, newP);\n }, async () => {\n throw Object.assign(new Error(`EEXDEV: cross-device link not permitted`), { code: `EEXDEV` });\n });\n }, async (mountFsO, { subPath: subPathO }) => {\n return await this.makeCallPromise(newP, async () => {\n throw Object.assign(new Error(`EEXDEV: cross-device link not permitted`), { code: `EEXDEV` });\n }, async (mountFsN, { subPath: subPathN }) => {\n if (mountFsO !== mountFsN) {\n throw Object.assign(new Error(`EEXDEV: cross-device link not permitted`), { code: `EEXDEV` });\n }\n else {\n return await mountFsO.renamePromise(subPathO, subPathN);\n }\n });\n });\n }\n renameSync(oldP, newP) {\n return this.makeCallSync(oldP, () => {\n return this.makeCallSync(newP, () => {\n return this.baseFs.renameSync(oldP, newP);\n }, () => {\n throw Object.assign(new Error(`EEXDEV: cross-device link not permitted`), { code: `EEXDEV` });\n });\n }, (mountFsO, { subPath: subPathO }) => {\n return this.makeCallSync(newP, () => {\n throw Object.assign(new Error(`EEXDEV: cross-device link not permitted`), { code: `EEXDEV` });\n }, (mountFsN, { subPath: subPathN }) => {\n if (mountFsO !== mountFsN) {\n throw Object.assign(new Error(`EEXDEV: cross-device link not permitted`), { code: `EEXDEV` });\n }\n else {\n return mountFsO.renameSync(subPathO, subPathN);\n }\n });\n });\n }\n async copyFilePromise(sourceP, destP, flags = 0) {\n const fallback = async (sourceFs, sourceP, destFs, destP) => {\n if ((flags & fs_1.constants.COPYFILE_FICLONE_FORCE) !== 0)\n throw Object.assign(new Error(`EXDEV: cross-device clone not permitted, copyfile '${sourceP}' -> ${destP}'`), { code: `EXDEV` });\n if ((flags & fs_1.constants.COPYFILE_EXCL) && await this.existsPromise(sourceP))\n throw Object.assign(new Error(`EEXIST: file already exists, copyfile '${sourceP}' -> '${destP}'`), { code: `EEXIST` });\n let content;\n try {\n content = await sourceFs.readFilePromise(sourceP);\n }\n catch (error) {\n throw Object.assign(new Error(`EINVAL: invalid argument, copyfile '${sourceP}' -> '${destP}'`), { code: `EINVAL` });\n }\n await destFs.writeFilePromise(destP, content);\n };\n return await this.makeCallPromise(sourceP, async () => {\n return await this.makeCallPromise(destP, async () => {\n return await this.baseFs.copyFilePromise(sourceP, destP, flags);\n }, async (mountFsD, { subPath: subPathD }) => {\n return await fallback(this.baseFs, sourceP, mountFsD, subPathD);\n });\n }, async (mountFsS, { subPath: subPathS }) => {\n return await this.makeCallPromise(destP, async () => {\n return await fallback(mountFsS, subPathS, this.baseFs, destP);\n }, async (mountFsD, { subPath: subPathD }) => {\n if (mountFsS !== mountFsD) {\n return await fallback(mountFsS, subPathS, mountFsD, subPathD);\n }\n else {\n return await mountFsS.copyFilePromise(subPathS, subPathD, flags);\n }\n });\n });\n }\n copyFileSync(sourceP, destP, flags = 0) {\n const fallback = (sourceFs, sourceP, destFs, destP) => {\n if ((flags & fs_1.constants.COPYFILE_FICLONE_FORCE) !== 0)\n throw Object.assign(new Error(`EXDEV: cross-device clone not permitted, copyfile '${sourceP}' -> ${destP}'`), { code: `EXDEV` });\n if ((flags & fs_1.constants.COPYFILE_EXCL) && this.existsSync(sourceP))\n throw Object.assign(new Error(`EEXIST: file already exists, copyfile '${sourceP}' -> '${destP}'`), { code: `EEXIST` });\n let content;\n try {\n content = sourceFs.readFileSync(sourceP);\n }\n catch (error) {\n throw Object.assign(new Error(`EINVAL: invalid argument, copyfile '${sourceP}' -> '${destP}'`), { code: `EINVAL` });\n }\n destFs.writeFileSync(destP, content);\n };\n return this.makeCallSync(sourceP, () => {\n return this.makeCallSync(destP, () => {\n return this.baseFs.copyFileSync(sourceP, destP, flags);\n }, (mountFsD, { subPath: subPathD }) => {\n return fallback(this.baseFs, sourceP, mountFsD, subPathD);\n });\n }, (mountFsS, { subPath: subPathS }) => {\n return this.makeCallSync(destP, () => {\n return fallback(mountFsS, subPathS, this.baseFs, destP);\n }, (mountFsD, { subPath: subPathD }) => {\n if (mountFsS !== mountFsD) {\n return fallback(mountFsS, subPathS, mountFsD, subPathD);\n }\n else {\n return mountFsS.copyFileSync(subPathS, subPathD, flags);\n }\n });\n });\n }\n async appendFilePromise(p, content, opts) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.appendFilePromise(p, content, opts);\n }, async (mountFs, { subPath }) => {\n return await mountFs.appendFilePromise(subPath, content, opts);\n });\n }\n appendFileSync(p, content, opts) {\n return this.makeCallSync(p, () => {\n return this.baseFs.appendFileSync(p, content, opts);\n }, (mountFs, { subPath }) => {\n return mountFs.appendFileSync(subPath, content, opts);\n });\n }\n async writeFilePromise(p, content, opts) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.writeFilePromise(p, content, opts);\n }, async (mountFs, { subPath }) => {\n return await mountFs.writeFilePromise(subPath, content, opts);\n });\n }\n writeFileSync(p, content, opts) {\n return this.makeCallSync(p, () => {\n return this.baseFs.writeFileSync(p, content, opts);\n }, (mountFs, { subPath }) => {\n return mountFs.writeFileSync(subPath, content, opts);\n });\n }\n async unlinkPromise(p) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.unlinkPromise(p);\n }, async (mountFs, { subPath }) => {\n return await mountFs.unlinkPromise(subPath);\n });\n }\n unlinkSync(p) {\n return this.makeCallSync(p, () => {\n return this.baseFs.unlinkSync(p);\n }, (mountFs, { subPath }) => {\n return mountFs.unlinkSync(subPath);\n });\n }\n async utimesPromise(p, atime, mtime) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.utimesPromise(p, atime, mtime);\n }, async (mountFs, { subPath }) => {\n return await mountFs.utimesPromise(subPath, atime, mtime);\n });\n }\n utimesSync(p, atime, mtime) {\n return this.makeCallSync(p, () => {\n return this.baseFs.utimesSync(p, atime, mtime);\n }, (mountFs, { subPath }) => {\n return mountFs.utimesSync(subPath, atime, mtime);\n });\n }\n async lutimesPromise(p, atime, mtime) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.lutimesPromise(p, atime, mtime);\n }, async (mountFs, { subPath }) => {\n return await mountFs.lutimesPromise(subPath, atime, mtime);\n });\n }\n lutimesSync(p, atime, mtime) {\n return this.makeCallSync(p, () => {\n return this.baseFs.lutimesSync(p, atime, mtime);\n }, (mountFs, { subPath }) => {\n return mountFs.lutimesSync(subPath, atime, mtime);\n });\n }\n async mkdirPromise(p, opts) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.mkdirPromise(p, opts);\n }, async (mountFs, { subPath }) => {\n return await mountFs.mkdirPromise(subPath, opts);\n });\n }\n mkdirSync(p, opts) {\n return this.makeCallSync(p, () => {\n return this.baseFs.mkdirSync(p, opts);\n }, (mountFs, { subPath }) => {\n return mountFs.mkdirSync(subPath, opts);\n });\n }\n async rmdirPromise(p, opts) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.rmdirPromise(p, opts);\n }, async (mountFs, { subPath }) => {\n return await mountFs.rmdirPromise(subPath, opts);\n });\n }\n rmdirSync(p, opts) {\n return this.makeCallSync(p, () => {\n return this.baseFs.rmdirSync(p, opts);\n }, (mountFs, { subPath }) => {\n return mountFs.rmdirSync(subPath, opts);\n });\n }\n async linkPromise(existingP, newP) {\n return await this.makeCallPromise(newP, async () => {\n return await this.baseFs.linkPromise(existingP, newP);\n }, async (mountFs, { subPath }) => {\n return await mountFs.linkPromise(existingP, subPath);\n });\n }\n linkSync(existingP, newP) {\n return this.makeCallSync(newP, () => {\n return this.baseFs.linkSync(existingP, newP);\n }, (mountFs, { subPath }) => {\n return mountFs.linkSync(existingP, subPath);\n });\n }\n async symlinkPromise(target, p, type) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.symlinkPromise(target, p, type);\n }, async (mountFs, { subPath }) => {\n return await mountFs.symlinkPromise(target, subPath);\n });\n }\n symlinkSync(target, p, type) {\n return this.makeCallSync(p, () => {\n return this.baseFs.symlinkSync(target, p, type);\n }, (mountFs, { subPath }) => {\n return mountFs.symlinkSync(target, subPath);\n });\n }\n async readFilePromise(p, encoding) {\n return this.makeCallPromise(p, async () => {\n return await this.baseFs.readFilePromise(p, encoding);\n }, async (mountFs, { subPath }) => {\n return await mountFs.readFilePromise(subPath, encoding);\n });\n }\n readFileSync(p, encoding) {\n return this.makeCallSync(p, () => {\n return this.baseFs.readFileSync(p, encoding);\n }, (mountFs, { subPath }) => {\n return mountFs.readFileSync(subPath, encoding);\n });\n }\n async readdirPromise(p, opts) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.readdirPromise(p, opts);\n }, async (mountFs, { subPath }) => {\n return await mountFs.readdirPromise(subPath, opts);\n }, {\n requireSubpath: false,\n });\n }\n readdirSync(p, opts) {\n return this.makeCallSync(p, () => {\n return this.baseFs.readdirSync(p, opts);\n }, (mountFs, { subPath }) => {\n return mountFs.readdirSync(subPath, opts);\n }, {\n requireSubpath: false,\n });\n }\n async readlinkPromise(p) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.readlinkPromise(p);\n }, async (mountFs, { subPath }) => {\n return await mountFs.readlinkPromise(subPath);\n });\n }\n readlinkSync(p) {\n return this.makeCallSync(p, () => {\n return this.baseFs.readlinkSync(p);\n }, (mountFs, { subPath }) => {\n return mountFs.readlinkSync(subPath);\n });\n }\n async truncatePromise(p, len) {\n return await this.makeCallPromise(p, async () => {\n return await this.baseFs.truncatePromise(p, len);\n }, async (mountFs, { subPath }) => {\n return await mountFs.truncatePromise(subPath, len);\n });\n }\n truncateSync(p, len) {\n return th