11import { execFile } from "node:child_process" ;
22import { promisify } from "node:util" ;
33import { type PortablePath , npath , ppath , xfs } from "@yarnpkg/fslib" ;
4- import { dump as yamlDump , load as yamlLoad } from "js- yaml" ;
4+ import { parse as yamlParse , stringify as yamlStringify } from "yaml" ;
55import { dir as tmpDir } from "tmp-promise" ;
66
77const execFileAsync = promisify ( execFile ) ;
@@ -12,7 +12,9 @@ export interface TestWorkspace {
1212 writeJson : ( path : string , content : unknown ) => Promise < void > ;
1313 readPackageJson : ( ) => Promise < any > ;
1414 readYarnrc : ( ) => Promise < any > ;
15+ readYarnrcRaw : ( ) => Promise < string > ;
1516 writeYarnrc : ( content : unknown ) => Promise < void > ;
17+ writeYarnrcRaw : ( content : string ) => Promise < void > ;
1618 writeCatalogsYml : ( content : unknown ) => Promise < void > ;
1719 yarn : {
1820 ( args : string [ ] ) : Promise < { stdout : string ; stderr : string } > ;
@@ -76,7 +78,7 @@ export async function createTestWorkspace(): Promise<TestWorkspace> {
7678 . catch ( ( ) => "" ) ;
7779 await xfs . writeFilePromise (
7880 yarnrcPath ,
79- `${ existingContent } \n${ yamlDump ( content ) } ` ,
81+ `${ existingContent } \n${ yamlStringify ( content ) } ` ,
8082 ) ;
8183 } ;
8284
@@ -85,7 +87,7 @@ export async function createTestWorkspace(): Promise<TestWorkspace> {
8587 portablePath ,
8688 "catalogs.yml" as PortablePath ,
8789 ) ;
88- await xfs . writeFilePromise ( catalogsYmlPath , yamlDump ( content ) ) ;
90+ await xfs . writeFilePromise ( catalogsYmlPath , yamlStringify ( content ) ) ;
8991 } ;
9092
9193 const readPackageJson = async ( ) => {
@@ -97,7 +99,17 @@ export async function createTestWorkspace(): Promise<TestWorkspace> {
9799 const readYarnrc = async ( ) => {
98100 const yarnrcPath = ppath . join ( portablePath , ".yarnrc.yml" as PortablePath ) ;
99101 const content = await xfs . readFilePromise ( yarnrcPath , "utf8" ) ;
100- return yamlLoad ( content ) ;
102+ return yamlParse ( content ) ;
103+ } ;
104+
105+ const readYarnrcRaw = async ( ) => {
106+ const yarnrcPath = ppath . join ( portablePath , ".yarnrc.yml" as PortablePath ) ;
107+ return await xfs . readFilePromise ( yarnrcPath , "utf8" ) ;
108+ } ;
109+
110+ const writeYarnrcRaw = async ( content : string ) => {
111+ const yarnrcPath = ppath . join ( portablePath , ".yarnrc.yml" as PortablePath ) ;
112+ await xfs . writeFilePromise ( yarnrcPath , content ) ;
101113 } ;
102114
103115 return {
@@ -106,7 +118,9 @@ export async function createTestWorkspace(): Promise<TestWorkspace> {
106118 writeJson,
107119 readPackageJson,
108120 readYarnrc,
121+ readYarnrcRaw,
109122 writeYarnrc : writeYaml ,
123+ writeYarnrcRaw,
110124 writeCatalogsYml,
111125 yarn,
112126 } ;
0 commit comments