55import * as cp from 'child_process' ;
66import * as fse from 'fs-extra' ;
77import * as fs from 'fs/promises' ;
8- import * as JSYAML from 'js-yaml' ;
98import * as path from 'path' ;
109import * as semver from 'semver' ;
1110import * as tmp from 'tmp' ;
1211import { promisify } from 'util' ;
1312import * as vscode from 'vscode' ;
1413import { extensions , Uri , ViewColumn , WebviewPanel , window } from 'vscode' ;
14+ import { parse , stringify } from 'yaml' ;
1515import { Alizer } from '../../alizer/alizerWrapper' ;
1616import { AlizerDevfileResponse , Version } from '../../alizer/types' ;
1717import { DevfileInfo , DevfileInfoExt , DevfileVersionInfo } from '../../devfile-registry/devfileInfo' ;
@@ -23,6 +23,7 @@ import sendTelemetry from '../../telemetry';
2323import { ExtensionID } from '../../util/constants' ;
2424import { DevfileConverter } from '../../util/devfileConverter' ;
2525import { DevfileV1 } from '../../util/devfileV1Type' ;
26+ import { YAML_STRINGIFY_OPTIONS } from '../../util/utils' ;
2627import { getInitialWorkspaceFolder , selectWorkspaceFolder } from '../../util/workspace' ;
2728import {
2829 isValidProjectFolder ,
@@ -474,11 +475,11 @@ export default class CreateComponentLoader {
474475 static async updateDevfileWithComponentName ( ucomponentFolderUri : vscode . Uri , componentName : string ) : Promise < void > {
475476 const devFilePath = path . join ( ucomponentFolderUri . fsPath , 'devfile.yaml' ) ;
476477 const file = await fs . readFile ( devFilePath , 'utf8' ) ;
477- const devfile = JSYAML . load ( file . toString ( ) ) as any ;
478+ const devfile = parse ( file . toString ( ) ) ;
478479 if ( devfile ?. metadata ?. name !== componentName ) {
479480 devfile . metadata . name = componentName ;
480481 await fs . unlink ( devFilePath ) ;
481- const yaml = JSYAML . dump ( devfile , { sortKeys : true } ) ;
482+ const yaml = stringify ( devfile , YAML_STRINGIFY_OPTIONS ) ;
482483 await fs . writeFile ( devFilePath , yaml . toString ( ) , 'utf-8' ) ;
483484 }
484485 }
@@ -504,7 +505,7 @@ export default class CreateComponentLoader {
504505 //Try reading the raw devfile
505506 const devFileYamlPath = path . join ( tmpFolder . fsPath , 'devfile.yaml' ) ;
506507 const file = await fs . readFile ( devFileYamlPath , 'utf8' ) ;
507- rawDevfile = JSYAML . load ( file . toString ( ) ) ;
508+ rawDevfile = parse ( file . toString ( ) ) ;
508509 }
509510
510511 void CreateComponentLoader . panel . webview . postMessage ( {
@@ -517,7 +518,7 @@ export default class CreateComponentLoader {
517518 id : rawDevfile . metadata . name ,
518519 starterProjects : rawDevfile . starterProjects ,
519520 tags : [ ] ,
520- yaml : JSYAML . dump ( rawDevfile ) ,
521+ yaml : stringify ( rawDevfile , YAML_STRINGIFY_OPTIONS ) ,
521522 supportsDebug,
522523 supportsDeploy,
523524 } as Devfile ;
@@ -551,7 +552,7 @@ export default class CreateComponentLoader {
551552 try {
552553 const devFileV1Path = path . join ( uri . fsPath , 'devfile.yaml' ) ;
553554 const file = await fs . readFile ( devFileV1Path , 'utf8' ) ;
554- const devfileV1 = JSYAML . load ( file . toString ( ) ) as DevfileV1 ;
555+ const devfileV1 = parse ( file . toString ( ) ) as DevfileV1 ;
555556 await fs . unlink ( devFileV1Path ) ;
556557 analyzeRes = await Alizer . Instance . alizerDevfile ( uri ) ;
557558 compDescriptions = await getCompDescriptionsAfterAnalizer ( analyzeRes ) ;
@@ -560,7 +561,7 @@ export default class CreateComponentLoader {
560561 devfileV1 ,
561562 endPoints ,
562563 ) ;
563- const yaml = JSYAML . dump ( devfileV2 , { sortKeys : true } ) ;
564+ const yaml = stringify ( devfileV2 , YAML_STRINGIFY_OPTIONS ) ;
564565 await fs . writeFile ( devFileV1Path , yaml . toString ( ) , 'utf-8' ) ;
565566 await CreateComponentLoader . panel ?. webview . postMessage ( {
566567 action : 'devfileRegenerated' ,
0 commit comments