From 714c1dccb1ff4d1cfe131e3ab4644d4c609e9df6 Mon Sep 17 00:00:00 2001 From: Vladimir Vagaytsev Date: Fri, 17 Nov 2023 17:12:51 +0100 Subject: [PATCH] chore: move yaml helper to serialization module (#5438) --- core/src/util/serialization.ts | 10 ++++++++-- core/src/util/util.ts | 8 -------- core/test/unit/src/resolve-module.ts | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/core/src/util/serialization.ts b/core/src/util/serialization.ts index 4febdc1c47..d06cd5c98a 100644 --- a/core/src/util/serialization.ts +++ b/core/src/util/serialization.ts @@ -8,11 +8,12 @@ import { mapValues } from "lodash-es" import fsExtra from "fs-extra" -const { writeFile } = fsExtra import type { DumpOptions } from "js-yaml" -import { dump } from "js-yaml" +import { dump, load } from "js-yaml" import highlightModule from "cli-highlight" import { styles } from "../logger/styles.js" + +const { readFile, writeFile } = fsExtra const highlight = highlightModule.default export async function dumpYaml(yamlPath: string, data: any) { @@ -51,6 +52,11 @@ export async function dumpYamlMulti(yamlPath: string, objects: object[]) { return writeFile(yamlPath, encodeYamlMulti(objects)) } +export async function loadYamlFile(path: string): Promise { + const fileData = await readFile(path) + return load(fileData.toString()) +} + export function serializeObject(o: any): string { return Buffer.from(JSON.stringify(o)).toString("base64") } diff --git a/core/src/util/util.ts b/core/src/util/util.ts index 2633a80bfc..b689b7b5d9 100644 --- a/core/src/util/util.ts +++ b/core/src/util/util.ts @@ -9,9 +9,6 @@ import { asyncExitHook, gracefulExit } from "@scg82/exit-hook" import _spawn from "cross-spawn" import { createHash } from "node:crypto" -import fsExtra from "fs-extra" -const { readFile } = fsExtra -import { load } from "js-yaml" import { difference, find, @@ -441,11 +438,6 @@ export function getEnumKeys(Enum) { return Object.values(Enum).filter((k) => typeof k === "string") as string[] } -export async function loadYamlFile(path: string): Promise { - const fileData = await readFile(path) - return load(fileData.toString()) -} - export interface ObjectWithName { name: string diff --git a/core/test/unit/src/resolve-module.ts b/core/test/unit/src/resolve-module.ts index 90802e8556..cee85d6981 100644 --- a/core/test/unit/src/resolve-module.ts +++ b/core/test/unit/src/resolve-module.ts @@ -12,7 +12,7 @@ import type { TestGarden } from "../../helpers.js" import { getDataDir, makeTestGarden, makeTestGardenA } from "../../helpers.js" import { DEFAULT_BUILD_TIMEOUT_SEC } from "../../../src/constants.js" import type { ConfigGraph } from "../../../src/graph/config-graph.js" -import { loadYamlFile } from "../../../src/util/util.js" +import { loadYamlFile } from "../../../src/util/serialization.js" describe("ModuleResolver", () => { // Note: We test the ModuleResolver via the TestGarden.resolveModule method, for convenience.