Upgrade js-yaml to 4.X (#3623)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-10-18 10:03:10 -04:00
1 parent fcb3010033
commit 5998b4ca84
17 files changed
+90 -57

No files matched your search

@@ -21,7 +21,7 @@
import "./pod-details-affinities.scss";
import React from "react";
import jsYaml from "js-yaml";
import yaml from "js-yaml";
import { DrawerParamToggler, DrawerItem } from "../drawer";
import type { Pod, Deployment, DaemonSet, StatefulSet, ReplicaSet, Job } from "../../../common/k8s-api/endpoints";
import MonacoEditor from "react-monaco-editor";
@@ -50,7 +50,7 @@ export class PodDetailsAffinities extends React.Component<Props> {
className={cssNames("MonacoEditor")}
theme={ThemeStore.getInstance().activeTheme.monacoTheme}
language="yaml"
value={jsYaml.dump(affinities)}
value={yaml.dump(affinities)}
/>
</div>
</DrawerParamToggler>
@@ -25,7 +25,7 @@ import React from "react";
import path from "path";
import fs from "fs-extra";
import {Select, GroupSelectOption, SelectOption} from "../select";
import jsYaml from "js-yaml";
import yaml from "js-yaml";
import { observable, makeObservable } from "mobx";
import { observer } from "mobx-react";
import { cssNames } from "../../utils";
@@ -101,15 +101,14 @@ export class CreateResource extends React.Component<Props> {
return null;
}
// skip empty documents if "---" pasted at the beginning or end
const resources = jsYaml.safeLoadAll(this.data).filter(Boolean);
// skip empty documents
const resources = yaml.loadAll(this.data).filter(Boolean);
const createdResources: string[] = [];
if (resources.length === 0) {
return void logger.info("Nothing to create");
}
const createdResources: string[] = [];
for (const result of await Promise.allSettled(resources.map(resourceApplierApi.update))) {
if (result.status === "fulfilled") {
createdResources.push(result.value.metadata.name);
@@ -72,13 +72,13 @@ export class EditResource extends React.Component<Props> {
return draft;
}
return yaml.safeDump(this.resource.toPlainObject()); // dump resource first time
return yaml.dump(this.resource.toPlainObject()); // dump resource first time
}
@action
saveDraft(draft: string | object) {
if (typeof draft === "object") {
draft = draft ? yaml.safeDump(draft) : undefined;
draft = draft ? yaml.dump(draft) : undefined;
}
editResourceStore.setData(this.tabId, {
@@ -99,8 +99,8 @@ export class EditResource extends React.Component<Props> {
}
const store = editResourceStore.getStore(this.tabId);
const currentVersion = yaml.safeLoad(this.draft);
const firstVersion = yaml.safeLoad(editResourceStore.getData(this.tabId).firstDraft ?? this.draft);
const currentVersion = yaml.load(this.draft);
const firstVersion = yaml.load(editResourceStore.getData(this.tabId).firstDraft ?? this.draft);
const patches = createPatch(firstVersion, currentVersion);
const updatedResource = await store.patch(this.resource, patches);
@@ -21,7 +21,7 @@
import MonacoEditor, {monaco} from "react-monaco-editor";
import React from "react";
import jsYaml from "js-yaml";
import yaml from "js-yaml";
import { observable, makeObservable } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react";
import { dockStore, TabId } from "./dock.store";
@@ -63,14 +63,14 @@ export class EditorPanel extends React.Component<Props> {
editorDidMount = (editor: monaco.editor.IStandaloneCodeEditor) => {
this.editor = editor;
const model = monacoModelsManager.getModel(this.props.tabId);
model.setValue(this.props.value ?? "");
this.editor.setModel(model);
};
validate(value: string) {
try {
jsYaml.safeLoadAll(value);
yaml.loadAll(value);
this.yamlError = "";
} catch (err) {
this.yamlError = err.toString();
@@ -24,7 +24,7 @@ import "./kubeconfig-dialog.scss";
import React from "react";
import { observable, makeObservable } from "mobx";
import { observer } from "mobx-react";
import jsYaml from "js-yaml";
import yaml from "js-yaml";
import type { ServiceAccount } from "../../../common/k8s-api/endpoints";
import { copyToClipboard, cssNames, saveFileDialog } from "../../utils";
import { Button } from "../button";
@@ -88,7 +88,7 @@ export class KubeConfigDialog extends React.Component<Props> {
this.close();
});
this.config = config ? jsYaml.dump(config) : "";
this.config = config ? yaml.dump(config) : "";
}
copyToClipboard = () => {