From effa0ec35482ef62c6dacc1fe1fcb0f8097fe4bd Mon Sep 17 00:00:00 2001 From: Kevin Deng Date: Fri, 14 Nov 2025 03:09:53 +0800 Subject: [PATCH] refactor: migrate `js-yaml` to `yaml` --- package.json | 5 ++--- pnpm-lock.yaml | 14 +++----------- src/config.ts | 6 +++--- src/from.ts | 4 ++-- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index d0e4955..13e5da8 100644 --- a/package.json +++ b/package.json @@ -50,15 +50,14 @@ "empathic": "^2.0.0", "escape-string-regexp": "^5.0.0", "giget": "^2.0.0", - "js-yaml": "^4.1.1", "tinyexec": "^1.0.2", - "unconfig": "^7.4.1" + "unconfig": "^7.4.1", + "yaml": "^2.8.1" }, "devDependencies": { "@antfu/utils": "^9.3.0", "@sxzz/eslint-config": "^7.2.10", "@sxzz/prettier-config": "^2.2.4", - "@types/js-yaml": "^4.0.9", "@types/node": "^24.10.1", "bumpp": "^10.3.1", "eslint": "^9.39.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index db9ea83..a571967 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,15 +32,15 @@ importers: giget: specifier: ^2.0.0 version: 2.0.0 - js-yaml: - specifier: ^4.1.1 - version: 4.1.1 tinyexec: specifier: ^1.0.2 version: 1.0.2 unconfig: specifier: ^7.4.1 version: 7.4.1 + yaml: + specifier: ^2.8.1 + version: 2.8.1 devDependencies: '@antfu/utils': specifier: ^9.3.0 @@ -51,9 +51,6 @@ importers: '@sxzz/prettier-config': specifier: ^2.2.4 version: 2.2.4 - '@types/js-yaml': - specifier: ^4.0.9 - version: 4.0.9 '@types/node': specifier: ^24.10.1 version: 24.10.1 @@ -643,9 +640,6 @@ packages: '@types/estree@1.0.8': resolution: {integrity: sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==} - '@types/js-yaml@4.0.9': - resolution: {integrity: sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==} - '@types/json-schema@7.0.15': resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} @@ -2701,8 +2695,6 @@ snapshots: '@types/estree@1.0.8': {} - '@types/js-yaml@4.0.9': {} - '@types/json-schema@7.0.15': {} '@types/mdast@4.0.4': diff --git a/src/config.ts b/src/config.ts index 91644b0..99cb44e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -6,9 +6,9 @@ import { objectPick, toArray } from '@antfu/utils' import { confirm, isCancel, select } from '@clack/prompts' import ansis from 'ansis' import consola from 'consola' -import { dump, load } from 'js-yaml' import { x } from 'tinyexec' import { loadConfig } from 'unconfig' +import { parse, stringify } from 'yaml' import { CliError, cmdExists, findConfigTypePath } from './utils' import type { Config, ConfigReplace, ConfigTemplate } from './types' @@ -76,7 +76,7 @@ export async function getConfig({ files: configPath, extensions: ['yaml', 'yml'], async parser(filePath) { - return load(await readFile(filePath, 'utf8')) as Config + return parse(await readFile(filePath, 'utf8')) as Config }, }, ], @@ -156,7 +156,7 @@ export default config } case 'YAML': filePath += '.yml' - contents = dump(demoConfig) + contents = stringify(demoConfig) break } await writeFile(filePath, contents) diff --git a/src/from.ts b/src/from.ts index 8f4bc40..583ffa3 100644 --- a/src/from.ts +++ b/src/from.ts @@ -1,8 +1,8 @@ import { mkdtemp, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import path from 'node:path' -import { load } from 'js-yaml' import { loadConfig } from 'unconfig' +import { parse } from 'yaml' import { normalizeConfig } from './config' import { CliError } from './utils' import type { Config } from './types' @@ -21,7 +21,7 @@ export async function fromTemplate(template: string): Promise { let config: Config if (filename.endsWith('.yaml') || filename.endsWith('.yml')) { - config = load(contents) as Config + config = parse(contents) as Config } else if (filename.endsWith('.json')) { config = JSON.parse(contents) as Config } else { -- knotmirror 0.0.1