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