Skip to content

Commit

Permalink
chore: move yaml helper to serialization module (#5438)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvagaytsev authored Nov 17, 2023
1 parent 4a71bb3 commit 714c1dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
10 changes: 8 additions & 2 deletions core/src/util/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -51,6 +52,11 @@ export async function dumpYamlMulti(yamlPath: string, objects: object[]) {
return writeFile(yamlPath, encodeYamlMulti(objects))
}

export async function loadYamlFile(path: string): Promise<any> {
const fileData = await readFile(path)
return load(fileData.toString())
}

export function serializeObject(o: any): string {
return Buffer.from(JSON.stringify(o)).toString("base64")
}
Expand Down
8 changes: 0 additions & 8 deletions core/src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<any> {
const fileData = await readFile(path)
return load(fileData.toString())
}

export interface ObjectWithName {
name: string

Expand Down
2 changes: 1 addition & 1 deletion core/test/unit/src/resolve-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 714c1dc

Please sign in to comment.