This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

24
node_modules/fs-monkey/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>

45
node_modules/fs-monkey/README.md generated vendored Normal file
View File

@@ -0,0 +1,45 @@
# fs-monkey
[![][npm-img]][npm-url] [![][travis-badge]][travis-url]
Monkey-patches for filesystem related things.
- Rewrite `require` function to load Node's modules from memory.
- Or rewrite the whole `fs` filesystem module.
## Install
```shell
npm install --save fs-monkey
```
## Terms
An *fs-like* object is an object that implements methods of Node's
[filesystem API](https://nodejs.org/api/fs.html).
It is denoted as `vol`:
```js
let vol = {
readFile: () => { /* ... */ },
readFileSync: () => { /* ... */ },
// etc...
}
```
## Reference
- [`patchFs`](./docs/api/patchFs.md) - rewrites Node's filesystem module `fs` with *fs-like* object `vol`
- [`patchRequire`](./docs/api/patchRequire.md) - rewrites `require` function, patches Node's `module` module to use a given *fs-like* object for module loading
[npm-img]: https://img.shields.io/npm/v/fs-monkey.svg
[npm-url]: https://www.npmjs.com/package/fs-monkey
[travis-url]: https://travis-ci.org/streamich/fs-monkey
[travis-badge]: https://travis-ci.org/streamich/fs-monkey.svg?branch=master
## License
[Unlicense](./LICENSE) - public domain.

40
node_modules/fs-monkey/docs/api/patchFs.md generated vendored Normal file
View File

@@ -0,0 +1,40 @@
# `patchFs(vol[, fs])`
Rewrites Node's filesystem module `fs` with *fs-like* object.
- `vol` - fs-like object
- `fs` *(optional)* - a filesystem to patch, defaults to `require('fs')`
```js
import {patchFs} from 'fs-monkey';
const myfs = {
readFileSync: () => 'hello world',
};
patchFs(myfs);
console.log(require('fs').readFileSync('/foo/bar')); // hello world
```
You don't need to create *fs-like* objects yourself, use [`memfs`](https://github.com/streamich/memfs)
to create a virtual filesystem for you:
```js
import {vol} from 'memfs';
import {patchFs} from 'fs-monkey';
vol.fromJSON({'/dir/foo': 'bar'});
patchFs(vol);
console.log(require('fs').readdirSync('/')); // [ 'dir' ]
```
Promises API is supported as well:
```js
import {vol} from 'memfs';
import {patchFs} from 'fs-monkey';
vol.fromJSON({'/dir/foo': 'bar'});
patchFs(vol);
require('fs').promises.readFile('/dir/foo', 'UTF-8').then(console.log); // bar
```

55
node_modules/fs-monkey/docs/api/patchRequire.md generated vendored Normal file
View File

@@ -0,0 +1,55 @@
# `patchRequire(vol[, unixifyPaths[, Module]])`
Patches Node's `module` module to use a given *fs-like* object `vol` for module loading.
- `vol` - fs-like object
- `unixifyPaths` *(optional)* - whether to convert Windows paths to unix style paths, defaults to `false`.
- `Module` *(optional)* - a module to patch, defaults to `require('module')`
Monkey-patches the `require` function in Node, this way you can make
Node.js to *require* modules from your custom filesystem.
It expects an object with three filesystem methods implemented that are
needed for the `require` function to work.
```js
let vol = {
readFileSync: () => {},
realpathSync: () => {},
statSync: () => {},
};
```
If you want to make Node.js to *require* your files from memory, you
don't need to implement those functions yourself, just use the
[`memfs`](https://github.com/streamich/memfs) package:
```js
import {vol} from 'memfs';
import {patchRequire} from 'fs-monkey';
vol.fromJSON({'/foo/bar.js': 'console.log("obi trice");'});
patchRequire(vol);
require('/foo/bar'); // obi trice
```
Now the `require` function will only load the files from the `vol` file
system, but not from the actual filesystem on the disk.
If you want the `require` function to load modules from both file
systems, use the [`unionfs`](https://github.com/streamich/unionfs) package
to combine both filesystems into a union:
```js
import {vol} from 'memfs';
import {patchRequire} from 'fs-monkey';
import {ufs} from 'unionfs';
import * as fs from 'fs';
vol.fromJSON({'/foo/bar.js': 'console.log("obi trice");'});
ufs
.use(vol)
.use(fs);
patchRequire(ufs);
require('/foo/bar.js'); // obi trice
```

43
node_modules/fs-monkey/lib/correctPath.js generated vendored Normal file
View File

@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.correctPath = correctPath;
exports.unixify = unixify;
var isWin = process.platform === 'win32';
function removeTrailingSeparator(str) {
var i = str.length - 1;
if (i < 2) {
return str;
}
while (isSeparator(str, i)) {
i--;
}
return str.substr(0, i + 1);
}
function isSeparator(str, i) {
var _char = str[i];
return i > 0 && (_char === '/' || isWin && _char === '\\');
}
function normalizePath(str, stripTrailing) {
if (typeof str !== 'string') {
throw new TypeError('expected a string');
}
str = str.replace(/[\\\/]+/g, '/');
if (stripTrailing !== false) {
str = removeTrailingSeparator(str);
}
return str;
}
function unixify(filepath) {
var stripTrailing = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (isWin) {
filepath = normalizePath(filepath, stripTrailing);
return filepath.replace(/^([a-zA-Z]+:|\.\/)/, '');
}
return filepath;
}
function correctPath(filepath) {
return unixify(filepath.replace(/^\\\\\?\\.:\\/, '\\'));
}

32
node_modules/fs-monkey/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,32 @@
"use strict";
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "patchFs", {
enumerable: true,
get: function get() {
return _patchFs["default"];
}
});
Object.defineProperty(exports, "patchRequire", {
enumerable: true,
get: function get() {
return _patchRequire["default"];
}
});
Object.defineProperty(exports, "unixify", {
enumerable: true,
get: function get() {
return _correctPath.unixify;
}
});
exports.util = void 0;
var _patchFs = _interopRequireDefault(require("./patchFs"));
var _patchRequire = _interopRequireDefault(require("./patchRequire"));
var _correctPath = require("./correctPath");
var util = _interopRequireWildcard(require("./util/lists"));
exports.util = util;
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }

92
node_modules/fs-monkey/lib/patchFs.js generated vendored Normal file
View File

@@ -0,0 +1,92 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = patchFs;
var _lists = require("./util/lists");
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function patchFs(vol) {
var fs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : require('fs');
var bkp = {};
var patch = function patch(key, newValue) {
bkp[key] = fs[key];
fs[key] = newValue;
};
var patchMethod = function patchMethod(key) {
return patch(key, vol[key].bind(vol));
};
var _iterator = _createForOfIteratorHelper(_lists.fsProps),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var prop = _step.value;
if (typeof vol[prop] !== 'undefined') patch(prop, vol[prop]);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
if (typeof vol.StatWatcher === 'function') {
patch('StatWatcher', vol.FSWatcher.bind(null, vol));
}
if (typeof vol.FSWatcher === 'function') {
patch('FSWatcher', vol.StatWatcher.bind(null, vol));
}
if (typeof vol.ReadStream === 'function') {
patch('ReadStream', vol.ReadStream.bind(null, vol));
}
if (typeof vol.WriteStream === 'function') {
patch('WriteStream', vol.WriteStream.bind(null, vol));
}
if (typeof vol._toUnixTimestamp === 'function') patchMethod('_toUnixTimestamp');
var _iterator2 = _createForOfIteratorHelper(_lists.fsAsyncMethods),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var method = _step2.value;
if (typeof vol[method] === 'function') patchMethod(method);
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
var _iterator3 = _createForOfIteratorHelper(_lists.fsSyncMethods),
_step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var _method = _step3.value;
if (typeof vol[_method] === 'function') patchMethod(_method);
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
var promisesBackup;
try {
promisesBackup = fs.promises;
Object.defineProperty(fs, 'promises', {
get: function get() {
return vol.promises;
}
});
} catch (_unused) {
undefined;
}
return function unpatch() {
for (var key in bkp) fs[key] = bkp[key];
if (promisesBackup) {
Object.defineProperty(fs, 'promises', {
get: function get() {
return promisesBackup;
}
});
}
};
}
;

175
node_modules/fs-monkey/lib/patchRequire.js generated vendored Normal file
View File

@@ -0,0 +1,175 @@
"use strict";
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = patchRequire;
var path = _interopRequireWildcard(require("path"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var isWin32 = process.platform === 'win32';
var correctPath = isWin32 ? require('./correctPath').correctPath : function (p) {
return p;
};
function stripBOM(content) {
if (content.charCodeAt(0) === 0xFEFF) {
content = content.slice(1);
}
return content;
}
function patchRequire(vol) {
var unixifyPaths = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var Module = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : require('module');
if (isWin32 && unixifyPaths) {
var original = vol;
vol = {
readFileSync: function readFileSync(path, options) {
return original.readFileSync(correctPath(path), options);
},
realpathSync: function realpathSync(path) {
return original.realpathSync(correctPath(path));
},
statSync: function statSync(path) {
return original.statSync(correctPath(path));
}
};
}
function internalModuleReadFile(path) {
try {
return vol.readFileSync(path, 'utf8');
} catch (err) {}
}
function internalModuleStat(filename) {
try {
return vol.statSync(filename).isDirectory() ? 1 : 0;
} catch (err) {
return -2;
}
}
function stat(filename) {
filename = path._makeLong(filename);
var cache = stat.cache;
if (cache !== null) {
var _result = cache.get(filename);
if (_result !== undefined) return _result;
}
var result = internalModuleStat(filename);
if (cache !== null) cache.set(filename, result);
return result;
}
stat.cache = null;
var preserveSymlinks = false;
function toRealPath(requestPath) {
return vol.realpathSync(requestPath);
}
var packageMainCache = Object.create(null);
function readPackage(requestPath) {
var entry = packageMainCache[requestPath];
if (entry) return entry;
var jsonPath = path.resolve(requestPath, 'package.json');
var json = internalModuleReadFile(path._makeLong(jsonPath));
if (json === undefined) {
return false;
}
var pkg;
try {
var pkgJson = JSON.parse(json);
pkg = packageMainCache[requestPath] = pkgJson.exports && pkgJson.exports.require || pkgJson.main;
} catch (e) {
e.path = jsonPath;
e.message = 'Error parsing ' + jsonPath + ': ' + e.message;
throw e;
}
return pkg;
}
function tryFile(requestPath, isMain) {
var rc = stat(requestPath);
if (preserveSymlinks && !isMain) {
return rc === 0 && path.resolve(requestPath);
}
return rc === 0 && toRealPath(requestPath);
}
function tryExtensions(p, exts, isMain) {
for (var i = 0; i < exts.length; i++) {
var filename = tryFile(p + exts[i], isMain);
if (filename) {
return filename;
}
}
return false;
}
function tryPackage(requestPath, exts, isMain) {
var pkg = readPackage(requestPath);
if (!pkg) return false;
var filename = path.resolve(requestPath, pkg);
return tryFile(filename, isMain) || tryExtensions(filename, exts, isMain) || tryExtensions(path.resolve(filename, 'index'), exts, isMain);
}
Module._extensions['.js'] = function (module, filename) {
var content = vol.readFileSync(filename, 'utf8');
module._compile(stripBOM(content), filename);
};
Module._extensions['.json'] = function (module, filename) {
var content = vol.readFileSync(filename, 'utf8');
try {
module.exports = JSON.parse(stripBOM(content));
} catch (err) {
err.message = filename + ': ' + err.message;
throw err;
}
};
var warned = true;
Module._findPath = function (request, paths, isMain) {
if (path.isAbsolute(request)) {
paths = [''];
} else if (!paths || paths.length === 0) {
return false;
}
var cacheKey = request + '\x00' + (paths.length === 1 ? paths[0] : paths.join('\x00'));
var entry = Module._pathCache[cacheKey];
if (entry) return entry;
var exts;
var trailingSlash = request.length > 0 && request.charCodeAt(request.length - 1) === 47;
for (var i = 0; i < paths.length; i++) {
var curPath = paths[i];
if (curPath && stat(curPath) < 1) continue;
var basePath = correctPath(path.resolve(curPath, request));
var filename;
var rc = stat(basePath);
if (!trailingSlash) {
if (rc === 0) {
if (preserveSymlinks && !isMain) {
filename = path.resolve(basePath);
} else {
filename = toRealPath(basePath);
}
} else if (rc === 1) {
if (exts === undefined) exts = Object.keys(Module._extensions);
filename = tryPackage(basePath, exts, isMain);
}
if (!filename) {
if (exts === undefined) exts = Object.keys(Module._extensions);
filename = tryExtensions(basePath, exts, isMain);
}
}
if (!filename && rc === 1) {
if (exts === undefined) exts = Object.keys(Module._extensions);
filename = tryPackage(basePath, exts, isMain);
}
if (!filename && rc === 1) {
if (exts === undefined) exts = Object.keys(Module._extensions);
filename = tryExtensions(path.resolve(basePath, 'index'), exts, isMain);
}
if (filename) {
if (request === '.' && i > 0) {
if (!warned) {
warned = true;
process.emitWarning('warning: require(\'.\') resolved outside the package ' + 'directory. This functionality is deprecated and will be removed ' + 'soon.', 'DeprecationWarning', 'DEP0019');
}
}
Module._pathCache[cacheKey] = filename;
return filename;
}
}
return false;
};
}

9
node_modules/fs-monkey/lib/util/lists.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fsSyncMethods = exports.fsProps = exports.fsAsyncMethods = void 0;
var fsProps = exports.fsProps = ['constants', 'F_OK', 'R_OK', 'W_OK', 'X_OK', 'Stats'];
var fsSyncMethods = exports.fsSyncMethods = ['renameSync', 'ftruncateSync', 'truncateSync', 'chownSync', 'fchownSync', 'lchownSync', 'chmodSync', 'fchmodSync', 'lchmodSync', 'statSync', 'lstatSync', 'fstatSync', 'linkSync', 'symlinkSync', 'readlinkSync', 'realpathSync', 'unlinkSync', 'rmdirSync', 'mkdirSync', 'mkdirpSync', 'readdirSync', 'closeSync', 'openSync', 'utimesSync', 'futimesSync', 'fsyncSync', 'writeSync', 'readSync', 'readFileSync', 'writeFileSync', 'appendFileSync', 'existsSync', 'accessSync', 'fdatasyncSync', 'mkdtempSync', 'copyFileSync', 'rmSync', 'createReadStream', 'createWriteStream'];
var fsAsyncMethods = exports.fsAsyncMethods = ['rename', 'ftruncate', 'truncate', 'chown', 'fchown', 'lchown', 'chmod', 'fchmod', 'lchmod', 'stat', 'lstat', 'fstat', 'link', 'symlink', 'readlink', 'realpath', 'unlink', 'rmdir', 'mkdir', 'mkdirp', 'readdir', 'close', 'open', 'utimes', 'futimes', 'fsync', 'write', 'read', 'readFile', 'writeFile', 'appendFile', 'exists', 'access', 'fdatasync', 'mkdtemp', 'copyFile', 'rm', 'watchFile', 'unwatchFile', 'watch'];

69
node_modules/fs-monkey/package.json generated vendored Normal file
View File

@@ -0,0 +1,69 @@
{
"name": "fs-monkey",
"version": "1.1.0",
"description": "Monkey patches for file system related things.",
"main": "lib/index.js",
"license": "Unlicense",
"keywords": [
"fs",
"file",
"file system",
"monkey",
"fsmonkey",
"monkeyfs",
"monkeypatch",
"patch"
],
"files": [
"lib",
"!lib/__tests__",
"docs"
],
"directories": {
"doc": "docs"
},
"repository": {
"type": "git",
"url": "https://github.com/streamich/fs-monkey.git"
},
"scripts": {
"build": "babel src --out-dir lib",
"test": "jest"
},
"dependencies": {},
"devDependencies": {
"@babel/cli": "^7.18.6",
"@babel/core": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^9.0.1",
"@types/jest": "^29.0.0",
"@types/node": "^8.10.66",
"babel-jest": "^29.0.0",
"jest": "^29.0.0",
"semantic-release": "^19.0.3",
"source-map-support": "^0.5.21"
},
"release": {
"verifyConditions": [
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git"
],
"prepare": [
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git"
]
},
"jest": {
"collectCoverageFrom": [
"src/**/*.js"
],
"transform": {
"^.+\\.jsx?$": "babel-jest"
},
"testRegex": ".*(__tests__/|/test/unit/).*(test|spec)\\.(t|j)sx?$"
}
}