From 23b60dc1975db38c280d8a123aff97544d1673e0 Mon Sep 17 00:00:00 2001 From: HelenHuang <LinHuang@pollex.com.tw> Date: 星期四, 09 六月 2022 15:34:21 +0800 Subject: [PATCH] TODO#139890 FAQ 常見問題 1-文案調整 --- PAMapp/node_modules/memfs/lib/volume.js | 118 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 86 insertions(+), 32 deletions(-) diff --git a/PAMapp/node_modules/memfs/lib/volume.js b/PAMapp/node_modules/memfs/lib/volume.js index 0229e4a..a615229 100644 --- a/PAMapp/node_modules/memfs/lib/volume.js +++ b/PAMapp/node_modules/memfs/lib/volume.js @@ -65,7 +65,7 @@ LENGTH: 'length must be an integer', POSITION: 'position must be an integer', }; -var ERRSTR_OPTS = function (tipeof) { return "Expected options to be either an object or a string, but got " + tipeof + " instead"; }; +var ERRSTR_OPTS = function (tipeof) { return "Expected options to be either an object or a string, but got ".concat(tipeof, " instead"); }; // const ERRSTR_FLAG = flag => `Unknown file open flag: ${flag}`; var ENOENT = 'ENOENT'; var EBADF = 'EBADF'; @@ -86,38 +86,38 @@ if (path2 === void 0) { path2 = ''; } var pathFormatted = ''; if (path) - pathFormatted = " '" + path + "'"; + pathFormatted = " '".concat(path, "'"); if (path2) - pathFormatted += " -> '" + path2 + "'"; + pathFormatted += " -> '".concat(path2, "'"); switch (errorCode) { case ENOENT: - return "ENOENT: no such file or directory, " + func + pathFormatted; + return "ENOENT: no such file or directory, ".concat(func).concat(pathFormatted); case EBADF: - return "EBADF: bad file descriptor, " + func + pathFormatted; + return "EBADF: bad file descriptor, ".concat(func).concat(pathFormatted); case EINVAL: - return "EINVAL: invalid argument, " + func + pathFormatted; + return "EINVAL: invalid argument, ".concat(func).concat(pathFormatted); case EPERM: - return "EPERM: operation not permitted, " + func + pathFormatted; + return "EPERM: operation not permitted, ".concat(func).concat(pathFormatted); case EPROTO: - return "EPROTO: protocol error, " + func + pathFormatted; + return "EPROTO: protocol error, ".concat(func).concat(pathFormatted); case EEXIST: - return "EEXIST: file already exists, " + func + pathFormatted; + return "EEXIST: file already exists, ".concat(func).concat(pathFormatted); case ENOTDIR: - return "ENOTDIR: not a directory, " + func + pathFormatted; + return "ENOTDIR: not a directory, ".concat(func).concat(pathFormatted); case EISDIR: - return "EISDIR: illegal operation on a directory, " + func + pathFormatted; + return "EISDIR: illegal operation on a directory, ".concat(func).concat(pathFormatted); case EACCES: - return "EACCES: permission denied, " + func + pathFormatted; + return "EACCES: permission denied, ".concat(func).concat(pathFormatted); case ENOTEMPTY: - return "ENOTEMPTY: directory not empty, " + func + pathFormatted; + return "ENOTEMPTY: directory not empty, ".concat(func).concat(pathFormatted); case EMFILE: - return "EMFILE: too many open files, " + func + pathFormatted; + return "EMFILE: too many open files, ".concat(func).concat(pathFormatted); case ENOSYS: - return "ENOSYS: function not implemented, " + func + pathFormatted; + return "ENOSYS: function not implemented, ".concat(func).concat(pathFormatted); case ERR_FS_EISDIR: - return "[ERR_FS_EISDIR]: Path is a directory: " + func + " returned EISDIR (is a directory) " + path; + return "[ERR_FS_EISDIR]: Path is a directory: ".concat(func, " returned EISDIR (is a directory) ").concat(path); default: - return errorCode + ": error occurred, " + func + pathFormatted; + return "".concat(errorCode, ": error occurred, ").concat(func).concat(pathFormatted); } } function createError(errorCode, func, path, path2, Constructor) { @@ -1252,33 +1252,49 @@ var pathFilename = pathToFilename(path); this.wrapAsync(this.realpathBase, [pathFilename, opts.encoding], callback); }; - Volume.prototype.lstatBase = function (filename, bigint) { + Volume.prototype.lstatBase = function (filename, bigint, throwIfNoEntry) { if (bigint === void 0) { bigint = false; } + if (throwIfNoEntry === void 0) { throwIfNoEntry = false; } var link = this.getLink(filenameToSteps(filename)); - if (!link) + if (link) { + return Stats_1.default.build(link.getNode(), bigint); + } + else if (!throwIfNoEntry) { + return undefined; + } + else { throw createError(ENOENT, 'lstat', filename); - return Stats_1.default.build(link.getNode(), bigint); + } }; Volume.prototype.lstatSync = function (path, options) { - return this.lstatBase(pathToFilename(path), getStatOptions(options).bigint); + var _a = getStatOptions(options), _b = _a.throwIfNoEntry, throwIfNoEntry = _b === void 0 ? true : _b, _c = _a.bigint, bigint = _c === void 0 ? false : _c; + return this.lstatBase(pathToFilename(path), bigint, throwIfNoEntry); }; Volume.prototype.lstat = function (path, a, b) { - var _a = getStatOptsAndCb(a, b), opts = _a[0], callback = _a[1]; - this.wrapAsync(this.lstatBase, [pathToFilename(path), opts.bigint], callback); + var _a = getStatOptsAndCb(a, b), _b = _a[0], _c = _b.throwIfNoEntry, throwIfNoEntry = _c === void 0 ? true : _c, _d = _b.bigint, bigint = _d === void 0 ? false : _d, callback = _a[1]; + this.wrapAsync(this.lstatBase, [pathToFilename(path), bigint, throwIfNoEntry], callback); }; - Volume.prototype.statBase = function (filename, bigint) { + Volume.prototype.statBase = function (filename, bigint, throwIfNoEntry) { if (bigint === void 0) { bigint = false; } + if (throwIfNoEntry === void 0) { throwIfNoEntry = true; } var link = this.getResolvedLink(filenameToSteps(filename)); - if (!link) + if (link) { + return Stats_1.default.build(link.getNode(), bigint); + } + else if (!throwIfNoEntry) { + return undefined; + } + else { throw createError(ENOENT, 'stat', filename); - return Stats_1.default.build(link.getNode(), bigint); + } }; Volume.prototype.statSync = function (path, options) { - return this.statBase(pathToFilename(path), getStatOptions(options).bigint); + var _a = getStatOptions(options), _b = _a.bigint, bigint = _b === void 0 ? true : _b, _c = _a.throwIfNoEntry, throwIfNoEntry = _c === void 0 ? true : _c; + return this.statBase(pathToFilename(path), bigint, throwIfNoEntry); }; Volume.prototype.stat = function (path, a, b) { - var _a = getStatOptsAndCb(a, b), opts = _a[0], callback = _a[1]; - this.wrapAsync(this.statBase, [pathToFilename(path), opts.bigint], callback); + var _a = getStatOptsAndCb(a, b), _b = _a[0], _c = _b.bigint, bigint = _c === void 0 ? false : _c, _d = _b.throwIfNoEntry, throwIfNoEntry = _d === void 0 ? true : _d, callback = _a[1]; + this.wrapAsync(this.statBase, [pathToFilename(path), bigint, throwIfNoEntry], callback); }; Volume.prototype.fstatBase = function (fd, bigint) { if (bigint === void 0) { bigint = false; } @@ -1313,6 +1329,7 @@ } // Rename should overwrite the new path, if that exists. var name = newPathSteps[newPathSteps.length - 1]; + link.name = name; link.steps = __spreadArray(__spreadArray([], newPathDirLink.steps, true), [name], false); newPathDirLink.setChild(link.getName(), link); }; @@ -2018,6 +2035,7 @@ }; FsReadStream.prototype.close = function (cb) { var _this = this; + var _a; if (cb) this.once('close', cb); if (this.closed || typeof this.fd !== 'number') { @@ -2027,7 +2045,15 @@ } return process_1.default.nextTick(function () { return _this.emit('close'); }); } - this.closed = true; + // Since Node 18, there is only a getter for '.closed'. + // The first branch mimics other setters from Readable. + // See https://github.com/nodejs/node/blob/v18.0.0/lib/internal/streams/readable.js#L1243 + if (typeof ((_a = this._readableState) === null || _a === void 0 ? void 0 : _a.closed) === 'boolean') { + this._readableState.closed = true; + } + else { + this.closed = true; + } this._vol.close(this.fd, function (er) { if (er) _this.emit('error', er); @@ -2140,8 +2166,36 @@ if (this.pos !== undefined) this.pos += size; }; +FsWriteStream.prototype.close = function (cb) { + var _this = this; + var _a; + if (cb) + this.once('close', cb); + if (this.closed || typeof this.fd !== 'number') { + if (typeof this.fd !== 'number') { + this.once('open', closeOnOpen); + return; + } + return process_1.default.nextTick(function () { return _this.emit('close'); }); + } + // Since Node 18, there is only a getter for '.closed'. + // The first branch mimics other setters from Writable. + // See https://github.com/nodejs/node/blob/v18.0.0/lib/internal/streams/writable.js#L766 + if (typeof ((_a = this._writableState) === null || _a === void 0 ? void 0 : _a.closed) === 'boolean') { + this._writableState.closed = true; + } + else { + this.closed = true; + } + this._vol.close(this.fd, function (er) { + if (er) + _this.emit('error', er); + else + _this.emit('close'); + }); + this.fd = null; +}; FsWriteStream.prototype._destroy = FsReadStream.prototype._destroy; -FsWriteStream.prototype.close = FsReadStream.prototype.close; // There is no shutdown() for files. FsWriteStream.prototype.destroySoon = FsWriteStream.prototype.end; // ---------------------------------------- FSWatcher @@ -2201,7 +2255,7 @@ this._link = this._vol.getLinkOrThrow(this._filename, 'FSWatcher'); } catch (err) { - var error = new Error("watch " + this._filename + " " + err.code); + var error = new Error("watch ".concat(this._filename, " ").concat(err.code)); error.code = err.code; error.errno = err.code; throw error; -- Gitblit v1.8.0