-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: preserve yaml anchor and alias when bump pnpm catalog
Co-authored-by: Kevin Deng 三咲智子 <sxzz@sxzz.moe>
- Loading branch information
1 parent
b43a167
commit 173c2f8
Showing
7 changed files
with
208 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { Alias, Document, Scalar } from 'yaml' | ||
import type { PnpmWorkspaceMeta } from '../types' | ||
import { writeFile } from 'node:fs/promises' | ||
import { visit } from 'yaml' | ||
|
||
export function writeYaml(pkg: PnpmWorkspaceMeta, document: Document) { | ||
return writeFile(pkg.filepath, document.toString(), 'utf-8') | ||
} | ||
|
||
export function findAnchor(doc: Document, alias: Alias): Scalar<string> | null { | ||
const { source } = alias | ||
let anchor: Scalar<string> | null = null | ||
|
||
visit(doc, { | ||
Scalar: (_key, scalar, _path) => { | ||
if ( | ||
scalar.anchor === source | ||
&& typeof scalar.value === 'string' | ||
) { | ||
anchor = scalar as Scalar<string> | ||
} | ||
}, | ||
}) | ||
|
||
return anchor | ||
} |
Oops, something went wrong.