1
- import yaml from 'js- yaml' ;
1
+ import YAML from 'yaml' ;
2
2
import { getSerializationType } from './util.js' ;
3
3
import { KubernetesObject } from './types.js' ;
4
4
import { ObjectSerializer } from './serializer.js' ;
@@ -9,13 +9,12 @@ import { ObjectSerializer } from './serializer.js';
9
9
* @param opts - Optional YAML load options.
10
10
* @returns The deserialized Kubernetes object.
11
11
*/
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 ;
14
14
if ( ! yml ) {
15
15
throw new Error ( 'Failed to load YAML' ) ;
16
16
}
17
17
const type = getSerializationType ( yml . apiVersion , yml . kind ) ;
18
-
19
18
return ObjectSerializer . deserialize ( yml , type ) as T ;
20
19
}
21
20
@@ -25,12 +24,12 @@ export function loadYaml<T>(data: string, opts?: yaml.LoadOptions): T {
25
24
* @param opts - Optional YAML load options.
26
25
* @returns An array of deserialized Kubernetes objects.
27
26
*/
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 ;
32
31
const type = getSerializationType ( obj . apiVersion , obj . kind ) ;
33
- return ObjectSerializer . deserialize ( yml , type ) ;
32
+ return ObjectSerializer . deserialize ( obj , type ) ;
34
33
} ) ;
35
34
}
36
35
@@ -40,9 +39,9 @@ export function loadAllYaml(data: string, opts?: yaml.LoadOptions): any[] {
40
39
* @param opts - Optional YAML dump options.
41
40
* @returns The YAML string representation of the serialized Kubernetes object.
42
41
*/
43
- export function dumpYaml ( object : any , opts ?: yaml . DumpOptions ) : string {
42
+ export function dumpYaml ( object : any ) : string {
44
43
const kubeObject = object as KubernetesObject ;
45
44
const type = getSerializationType ( kubeObject . apiVersion , kubeObject . kind ) ;
46
45
const serialized = ObjectSerializer . serialize ( kubeObject , type ) ;
47
- return yaml . dump ( serialized , opts ) ;
46
+ return YAML . stringify ( serialized ) ;
48
47
}
0 commit comments