rebuild hrm

This commit is contained in:
2026-04-13 09:30:59 +08:00
parent 44a98495ab
commit cd31c74da8
12034 changed files with 548007 additions and 451275 deletions

View File

@@ -6,10 +6,14 @@
"use strict";
/** @typedef {import("./Resolver").FileSystem} FileSystem */
/** @typedef {import("./Resolver").ReaddirStringCallback} ReaddirStringCallback */
/** @typedef {import("./Resolver").StringCallback} StringCallback */
/** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */
// eslint-disable-next-line jsdoc/reject-function-type
/** @typedef {Function} SyncOrAsyncFunction */
// eslint-disable-next-line jsdoc/reject-any-type
/** @typedef {any} ResultOfSyncOrAsyncFunction */
/**
* @param {SyncFileSystem} fs file system implementation
* @constructor
@@ -19,7 +23,7 @@ function SyncAsyncFileSystemDecorator(fs) {
this.lstat = undefined;
this.lstatSync = undefined;
const lstatSync = fs.lstatSync;
const { lstatSync } = fs;
if (lstatSync) {
this.lstat =
/** @type {FileSystem["lstat"]} */
@@ -27,16 +31,21 @@ function SyncAsyncFileSystemDecorator(fs) {
(arg, options, callback) => {
let result;
try {
result = /** @type {Function | undefined} */ (callback)
result = /** @type {SyncOrAsyncFunction | undefined} */ (callback)
? lstatSync.call(fs, arg, options)
: lstatSync.call(fs, arg);
} catch (e) {
} catch (err) {
return (callback || options)(
/** @type {NodeJS.ErrnoException | null} */ (e)
/** @type {NodeJS.ErrnoException | null} */
(err),
);
}
(callback || options)(null, /** @type {any} */ (result));
(callback || options)(
null,
/** @type {ResultOfSyncOrAsyncFunction} */
(result),
);
}
);
this.lstatSync =
@@ -50,16 +59,21 @@ function SyncAsyncFileSystemDecorator(fs) {
(arg, options, callback) => {
let result;
try {
result = /** @type {Function | undefined} */ (callback)
result = /** @type {SyncOrAsyncFunction | undefined} */ (callback)
? fs.statSync(arg, options)
: fs.statSync(arg);
} catch (e) {
} catch (err) {
return (callback || options)(
/** @type {NodeJS.ErrnoException | null} */ (e)
/** @type {NodeJS.ErrnoException | null} */
(err),
);
}
(callback || options)(null, /** @type {any} */ (result));
(callback || options)(
null,
/** @type {ResultOfSyncOrAsyncFunction} */
(result),
);
}
);
this.statSync =
@@ -72,20 +86,26 @@ function SyncAsyncFileSystemDecorator(fs) {
(arg, options, callback) => {
let result;
try {
result = /** @type {Function | undefined} */ (callback)
result = /** @type {SyncOrAsyncFunction | undefined} */ (callback)
? fs.readdirSync(
arg,
/** @type {Exclude<Parameters<FileSystem["readdir"]>[1], ReaddirStringCallback>} */
(options)
)
/** @type {Exclude<Parameters<FileSystem["readdir"]>[1], (err: NodeJS.ErrnoException | null, files: string[]) => void>} */
(options),
)
: fs.readdirSync(arg);
} catch (e) {
} catch (err) {
return (callback || options)(
/** @type {NodeJS.ErrnoException | null} */ (e)
/** @type {NodeJS.ErrnoException | null} */
(err),
[],
);
}
(callback || options)(null, /** @type {any} */ (result));
(callback || options)(
null,
/** @type {ResultOfSyncOrAsyncFunction} */
(result),
);
}
);
this.readdirSync =
@@ -94,7 +114,7 @@ function SyncAsyncFileSystemDecorator(fs) {
(arg, options) =>
fs.readdirSync(
arg,
/** @type {Parameters<SyncFileSystem["readdirSync"]>[1]} */ (options)
/** @type {Parameters<SyncFileSystem["readdirSync"]>[1]} */ (options),
)
);
@@ -104,16 +124,21 @@ function SyncAsyncFileSystemDecorator(fs) {
(arg, options, callback) => {
let result;
try {
result = /** @type {Function | undefined} */ (callback)
result = /** @type {SyncOrAsyncFunction | undefined} */ (callback)
? fs.readFileSync(arg, options)
: fs.readFileSync(arg);
} catch (e) {
} catch (err) {
return (callback || options)(
/** @type {NodeJS.ErrnoException | null} */ (e)
/** @type {NodeJS.ErrnoException | null} */
(err),
);
}
(callback || options)(null, /** @type {any} */ (result));
(callback || options)(
null,
/** @type {ResultOfSyncOrAsyncFunction} */
(result),
);
}
);
this.readFileSync =
@@ -126,20 +151,25 @@ function SyncAsyncFileSystemDecorator(fs) {
(arg, options, callback) => {
let result;
try {
result = /** @type {Function | undefined} */ (callback)
result = /** @type {SyncOrAsyncFunction | undefined} */ (callback)
? fs.readlinkSync(
arg,
/** @type {Exclude<Parameters<FileSystem["readlink"]>[1], StringCallback>} */
(options)
)
(options),
)
: fs.readlinkSync(arg);
} catch (e) {
} catch (err) {
return (callback || options)(
/** @type {NodeJS.ErrnoException | null} */ (e)
/** @type {NodeJS.ErrnoException | null} */
(err),
);
}
(callback || options)(null, /** @type {any} */ (result));
(callback || options)(
null,
/** @type {ResultOfSyncOrAsyncFunction} */
(result),
);
}
);
this.readlinkSync =
@@ -148,13 +178,15 @@ function SyncAsyncFileSystemDecorator(fs) {
(arg, options) =>
fs.readlinkSync(
arg,
/** @type {Parameters<SyncFileSystem["readlinkSync"]>[1]} */ (options)
/** @type {Parameters<SyncFileSystem["readlinkSync"]>[1]} */ (
options
),
)
);
this.readJson = undefined;
this.readJsonSync = undefined;
const readJsonSync = fs.readJsonSync;
const { readJsonSync } = fs;
if (readJsonSync) {
this.readJson =
/** @type {FileSystem["readJson"]} */
@@ -163,9 +195,9 @@ function SyncAsyncFileSystemDecorator(fs) {
let result;
try {
result = readJsonSync.call(fs, arg);
} catch (e) {
} catch (err) {
return callback(
/** @type {NodeJS.ErrnoException | Error | null} */ (e)
/** @type {NodeJS.ErrnoException | Error | null} */ (err),
);
}
@@ -174,12 +206,12 @@ function SyncAsyncFileSystemDecorator(fs) {
);
this.readJsonSync =
/** @type {SyncFileSystem["readJsonSync"]} */
(arg => readJsonSync.call(fs, arg));
((arg) => readJsonSync.call(fs, arg));
}
this.realpath = undefined;
this.realpathSync = undefined;
const realpathSync = fs.realpathSync;
const { realpathSync } = fs;
if (realpathSync) {
this.realpath =
/** @type {FileSystem["realpath"]} */
@@ -187,21 +219,26 @@ function SyncAsyncFileSystemDecorator(fs) {
(arg, options, callback) => {
let result;
try {
result = /** @type {Function | undefined} */ (callback)
result = /** @type {SyncOrAsyncFunction | undefined} */ (callback)
? realpathSync.call(
fs,
arg,
/** @type {Exclude<Parameters<NonNullable<FileSystem["realpath"]>>[1], StringCallback>} */
(options)
)
(options),
)
: realpathSync.call(fs, arg);
} catch (e) {
} catch (err) {
return (callback || options)(
/** @type {NodeJS.ErrnoException | null} */ (e)
/** @type {NodeJS.ErrnoException | null} */
(err),
);
}
(callback || options)(null, /** @type {any} */ (result));
(callback || options)(
null,
/** @type {ResultOfSyncOrAsyncFunction} */
(result),
);
}
);
this.realpathSync =
@@ -212,9 +249,10 @@ function SyncAsyncFileSystemDecorator(fs) {
fs,
arg,
/** @type {Parameters<NonNullable<SyncFileSystem["realpathSync"]>>[1]} */
(options)
(options),
)
);
}
}
module.exports = SyncAsyncFileSystemDecorator;