1- import yaml from 'js- yaml' ;
1+ import YAML from 'yaml' ;
22import { getSerializationType } from './util.js' ;
33import { KubernetesObject } from './types.js' ;
44import { ObjectSerializer } from './serializer.js' ;
@@ -9,13 +9,12 @@ import { ObjectSerializer } from './serializer.js';
99 * @param opts - Optional YAML load options.
1010 * @returns The deserialized Kubernetes object.
1111 */
12- export function loadYaml < T > ( data : string , opts ?: yaml . LoadOptions ) : T {
13- const yml = yaml . load ( data , opts ) as any as KubernetesObject ;
12+ export function loadYaml < T > ( data : string ) : T {
13+ const yml = YAML . parse ( data , { version : '1.1' } ) as any as KubernetesObject ;
1414 if ( ! yml ) {
1515 throw new Error ( 'Failed to load YAML' ) ;
1616 }
1717 const type = getSerializationType ( yml . apiVersion , yml . kind ) ;
18-
1918 return ObjectSerializer . deserialize ( yml , type ) as T ;
2019}
2120
@@ -25,12 +24,12 @@ export function loadYaml<T>(data: string, opts?: yaml.LoadOptions): T {
2524 * @param opts - Optional YAML load options.
2625 * @returns An array of deserialized Kubernetes objects.
2726 */
28- export function loadAllYaml ( data : string , opts ?: yaml . LoadOptions ) : any [ ] {
29- const ymls = yaml . loadAll ( data , undefined , opts ) ;
30- return ymls . map ( ( yml ) => {
31- const obj = yml as KubernetesObject ;
27+ export function loadAllYaml ( data : string ) : any [ ] {
28+ const ymls = YAML . parseAllDocuments ( data , { version : '1.1' } ) ;
29+ return ymls . map ( ( doc ) => {
30+ const obj = doc . toJS ( ) as KubernetesObject ;
3231 const type = getSerializationType ( obj . apiVersion , obj . kind ) ;
33- return ObjectSerializer . deserialize ( yml , type ) ;
32+ return ObjectSerializer . deserialize ( obj , type ) ;
3433 } ) ;
3534}
3635
@@ -40,9 +39,9 @@ export function loadAllYaml(data: string, opts?: yaml.LoadOptions): any[] {
4039 * @param opts - Optional YAML dump options.
4140 * @returns The YAML string representation of the serialized Kubernetes object.
4241 */
43- export function dumpYaml ( object : any , opts ?: yaml . DumpOptions ) : string {
42+ export function dumpYaml ( object : any ) : string {
4443 const kubeObject = object as KubernetesObject ;
4544 const type = getSerializationType ( kubeObject . apiVersion , kubeObject . kind ) ;
4645 const serialized = ObjectSerializer . serialize ( kubeObject , type ) ;
47- return yaml . dump ( serialized , opts ) ;
46+ return YAML . stringify ( serialized ) ;
4847}
0 commit comments