mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
- Turning on @typescript-eslint/recommended-requiring-type-checking - Turning off @typescript-eslint/no-unnecessary-type-assertion (due too many false positives) - Making @typescript-eslint/no-explicit-any an error (except in tests) Signed-off-by: Sebastian Malton <sebastian@malton.name>
72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
import { getInjectable } from "@ogre-tools/injectable";
|
|
import type { WriteFileOptions } from "fs";
|
|
import type { ReadOptions } from "fs-extra";
|
|
import fse from "fs-extra";
|
|
|
|
export type FileSystemFunctions = ReturnType<(typeof fsInjectable)["instantiate"]>;
|
|
|
|
/**
|
|
* NOTE: Add corresponding override of this injectable in `src/test-utils/override-fs-with-fakes.ts`
|
|
*/
|
|
const fsInjectable = getInjectable({
|
|
id: "fs",
|
|
instantiate: () => {
|
|
const {
|
|
promises: {
|
|
readFile,
|
|
writeFile,
|
|
readdir,
|
|
lstat,
|
|
rm,
|
|
access,
|
|
stat,
|
|
unlink,
|
|
rename,
|
|
},
|
|
ensureDir,
|
|
ensureDirSync,
|
|
readFileSync,
|
|
readJson,
|
|
writeJson,
|
|
readJsonSync,
|
|
writeFileSync,
|
|
writeJsonSync,
|
|
pathExistsSync,
|
|
pathExists,
|
|
copy,
|
|
createReadStream,
|
|
} = fse;
|
|
|
|
return {
|
|
readFile,
|
|
readJson: readJson as (file: string, options?: ReadOptions | BufferEncoding) => Promise<unknown>,
|
|
writeFile,
|
|
writeJson: writeJson as (file: string, value: unknown, options?: string | WriteFileOptions) => Promise<void>,
|
|
pathExists,
|
|
readdir,
|
|
readFileSync,
|
|
readJsonSync: readJsonSync as (file: string, options?: ReadOptions | BufferEncoding) => unknown,
|
|
writeFileSync,
|
|
writeJsonSync,
|
|
pathExistsSync,
|
|
lstat,
|
|
rm,
|
|
access,
|
|
copy: copy as (src: string, dest: string, options?: fse.CopyOptions) => Promise<void>,
|
|
ensureDir: ensureDir as (path: string, options?: number | fse.EnsureOptions ) => Promise<void>,
|
|
ensureDirSync,
|
|
createReadStream,
|
|
stat,
|
|
unlink,
|
|
rename,
|
|
};
|
|
},
|
|
causesSideEffects: true,
|
|
});
|
|
|
|
export default fsInjectable;
|