-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow anchor being defined in separated field
- Loading branch information
1 parent
ee30ac7
commit d102f66
Showing
4 changed files
with
125 additions
and
67 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
This file was deleted.
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
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 | ||
} |
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