mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Update and fix WriteJson(Sync) to fix error in tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
c6c2bb920a
commit
618d0d83b5
@ -3,11 +3,10 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { JsonValue } from "type-fest";
|
||||
import getDirnameOfPathInjectable from "../path/get-dirname.injectable";
|
||||
import fsInjectable from "./fs.injectable";
|
||||
|
||||
export type WriteJson = (filePath: string, contents: JsonValue) => Promise<void>;
|
||||
export type WriteJson = (filePath: string, contents: unknown) => Promise<void>;
|
||||
|
||||
const writeJsonFileInjectable = getInjectable({
|
||||
id: "write-json-file",
|
||||
|
||||
@ -3,11 +3,29 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import getDirnameOfPathInjectable from "../path/get-dirname.injectable";
|
||||
import fsInjectable from "./fs.injectable";
|
||||
|
||||
export type WriteJsonSync = (filePath: string, contents: unknown) => void;
|
||||
|
||||
const writeJsonSyncInjectable = getInjectable({
|
||||
id: "write-json-sync",
|
||||
instantiate: (di) => di.inject(fsInjectable).writeJsonSync,
|
||||
instantiate: (di): WriteJsonSync => {
|
||||
const {
|
||||
writeJsonSync,
|
||||
ensureDirSync,
|
||||
} = di.inject(fsInjectable);
|
||||
const getDirnameOfPath = di.inject(getDirnameOfPathInjectable);
|
||||
|
||||
return (filePath, content) => {
|
||||
ensureDirSync(getDirnameOfPath(filePath), { mode: 0o755 });
|
||||
|
||||
writeJsonSync(filePath, content, {
|
||||
encoding: "utf-8",
|
||||
spaces: 2,
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default writeJsonSyncInjectable;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user