Bump js-yaml (#9245)

This commit is contained in:
Bram Kragten 2021-05-26 00:13:58 +02:00 committed by GitHub
parent de09e31815
commit fdcbb5b432
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 68 additions and 61 deletions

View File

@ -52,11 +52,7 @@ const createRollupConfig = ({
browser: true,
rootDir: paths.polymer_dir,
}),
commonjs({
namedExports: {
"js-yaml": ["safeDump", "safeLoad"],
},
}),
commonjs(),
json(),
babel({
...bundle.babelOptions({ latestBuild }),

View File

@ -1,7 +1,7 @@
import { html } from "@polymer/polymer/lib/utils/html-tag";
/* eslint-plugin-disable lit */
import { PolymerElement } from "@polymer/polymer/polymer-element";
import { safeLoad } from "js-yaml";
import { load } from "js-yaml";
import { createCardElement } from "../../../src/panels/lovelace/create-element/create-card-element";
class DemoCard extends PolymerElement {
@ -80,7 +80,7 @@ class DemoCard extends PolymerElement {
card.removeChild(card.lastChild);
}
const el = this._createCardElement(safeLoad(config.config)[0]);
const el = this._createCardElement(load(config.config)[0]);
card.appendChild(el);
this._getSize(el);
}

View File

@ -1,4 +1,4 @@
import { safeDump } from "js-yaml";
import { dump } from "js-yaml";
import { html, css, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import "../../../src/components/ha-card";
@ -56,7 +56,7 @@ export class DemoAutomationDescribeAction extends LitElement {
(conf) => html`
<div class="action">
<span>${describeAction(this.hass, conf as any)}</span>
<pre>${safeDump(conf)}</pre>
<pre>${dump(conf)}</pre>
</div>
`
)}

View File

@ -1,4 +1,4 @@
import { safeDump } from "js-yaml";
import { dump } from "js-yaml";
import { html, css, LitElement, TemplateResult } from "lit";
import { customElement } from "lit/decorators";
import "../../../src/components/ha-card";
@ -26,7 +26,7 @@ export class DemoAutomationDescribeCondition extends LitElement {
(conf) => html`
<div class="condition">
<span>${describeCondition(conf as any)}</span>
<pre>${safeDump(conf)}</pre>
<pre>${dump(conf)}</pre>
</div>
`
)}

View File

@ -1,4 +1,4 @@
import { safeDump } from "js-yaml";
import { dump } from "js-yaml";
import { html, css, LitElement, TemplateResult } from "lit";
import { customElement } from "lit/decorators";
import "../../../src/components/ha-card";
@ -29,7 +29,7 @@ export class DemoAutomationDescribeTrigger extends LitElement {
(conf) => html`
<div class="trigger">
<span>${describeTrigger(conf as any)}</span>
<pre>${safeDump(conf)}</pre>
<pre>${dump(conf)}</pre>
</div>
`
)}

View File

@ -2,7 +2,7 @@ import "@material/mwc-button";
import { ActionDetail } from "@material/mwc-list/mwc-list-foundation";
import "@material/mwc-list/mwc-list-item";
import { mdiDotsVertical } from "@mdi/js";
import { safeDump } from "js-yaml";
import { dump } from "js-yaml";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import memoizeOne from "memoize-one";
@ -233,7 +233,7 @@ class HassioHostInfo extends LitElement {
const content = await fetchHassioHardwareInfo(this.hass);
showHassioMarkdownDialog(this, {
title: this.supervisor.localize("system.host.hardware"),
content: `<pre>${safeDump(content, { indent: 2 })}</pre>`,
content: `<pre>${dump(content, { indent: 2 })}</pre>`,
});
} catch (err) {
showAlertDialog(this, {

View File

@ -113,7 +113,7 @@
"home-assistant-js-websocket": "^5.10.0",
"idb-keyval": "^3.2.0",
"intl-messageformat": "^9.6.13",
"js-yaml": "^3.13.1",
"js-yaml": "^4.1.0",
"leaflet": "^1.7.1",
"leaflet-draw": "^1.0.4",
"lit": "^2.0.0-rc.2",
@ -168,7 +168,7 @@
"@types/chai": "^4.1.7",
"@types/chromecast-caf-receiver": "^5.0.11",
"@types/chromecast-caf-sender": "^1.0.3",
"@types/js-yaml": "^3.12.1",
"@types/js-yaml": "^4.0.1",
"@types/leaflet": "^1.7.0",
"@types/leaflet-draw": "^1.0.3",
"@types/marked": "^1.2.2",

View File

@ -1,4 +1,4 @@
import { safeDump, safeLoad } from "js-yaml";
import { dump, load } from "js-yaml";
import { html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event";
@ -30,7 +30,7 @@ export class HaYamlEditor extends LitElement {
public setValue(value): void {
try {
this._yaml = value && !isEmpty(value) ? safeDump(value) : "";
this._yaml = value && !isEmpty(value) ? dump(value) : "";
} catch (err) {
// eslint-disable-next-line no-console
console.error(err, value);
@ -67,7 +67,7 @@ export class HaYamlEditor extends LitElement {
if (this._yaml) {
try {
parsed = safeLoad(this._yaml);
parsed = load(this._yaml);
} catch (err) {
// Invalid YAML
isValid = false;

View File

@ -1,4 +1,4 @@
import { safeDump } from "js-yaml";
import { dump } from "js-yaml";
import { html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import "../../../../components/ha-code-editor";
@ -15,7 +15,7 @@ export class HaAutomationTraceBlueprintConfig extends LitElement {
protected render(): TemplateResult {
return html`
<ha-code-editor
.value=${safeDump(this.trace.blueprint_inputs || "").trimRight()}
.value=${dump(this.trace.blueprint_inputs || "").trimRight()}
readOnly
></ha-code-editor>
`;

View File

@ -1,4 +1,4 @@
import { safeDump } from "js-yaml";
import { dump } from "js-yaml";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property } from "lit/decorators";
import "../../../../components/ha-code-editor";
@ -15,7 +15,7 @@ export class HaAutomationTraceConfig extends LitElement {
protected render(): TemplateResult {
return html`
<ha-code-editor
.value=${safeDump(this.trace.config).trimRight()}
.value=${dump(this.trace.config).trimRight()}
readOnly
></ha-code-editor>
`;

View File

@ -1,4 +1,4 @@
import { safeDump } from "js-yaml";
import { dump } from "js-yaml";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
@ -132,13 +132,13 @@ export class HaAutomationTracePathDetails extends LitElement {
)}<br />
${result
? html`Result:
<pre>${safeDump(result)}</pre>`
<pre>${dump(result)}</pre>`
: error
? html`<div class="error">Error: ${error}</div>`
: ""}
${Object.keys(rest).length === 0
? ""
: html`<pre>${safeDump(rest)}</pre>`}
: html`<pre>${dump(rest)}</pre>`}
`;
})
);
@ -154,7 +154,7 @@ export class HaAutomationTracePathDetails extends LitElement {
const config = getDataFromPath(this.trace!.config, this.selected.path);
return config
? html`<ha-code-editor
.value=${safeDump(config).trimRight()}
.value=${dump(config).trimRight()}
readOnly
></ha-code-editor>`
: "Unable to find config";
@ -171,9 +171,7 @@ export class HaAutomationTracePathDetails extends LitElement {
${idx > 0 ? html`<p>Iteration ${idx + 1}</p>` : ""}
${Object.keys(trace.changed_variables || {}).length === 0
? "No variables changed"
: html`<pre>
${safeDump(trace.changed_variables).trimRight()}</pre
>`}
: html`<pre>${dump(trace.changed_variables).trimRight()}</pre>`}
`
)}
</div>

View File

@ -1,4 +1,4 @@
import { safeDump } from "js-yaml";
import { dump } from "js-yaml";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
@ -31,7 +31,7 @@ class MQTTDiscoveryPayload extends LitElement {
const payload = this.payload;
return html`
${this.showAsYaml
? html` <pre>${safeDump(payload)}</pre> `
? html` <pre>${dump(payload)}</pre> `
: html` <pre>${JSON.stringify(payload, null, 2)}</pre> `}
`;
}

View File

@ -1,4 +1,4 @@
import { safeDump } from "js-yaml";
import { dump } from "js-yaml";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { classMap } from "lit/directives/class-map";
@ -92,7 +92,7 @@ class MQTTMessages extends LitElement {
return json
? html`
${this.showAsYaml
? html` <pre>${safeDump(json)}</pre> `
? html` <pre>${dump(json)}</pre> `
: html` <pre>${JSON.stringify(json, null, 2)}</pre> `}
`
: html` <code>${message.payload}</code> `;

View File

@ -4,7 +4,7 @@ import "@polymer/paper-input/paper-input";
import { html } from "@polymer/polymer/lib/utils/html-tag";
/* eslint-plugin-disable lit */
import { PolymerElement } from "@polymer/polymer/polymer-element";
import { safeLoad } from "js-yaml";
import { load } from "js-yaml";
import "../../../components/ha-code-editor";
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
import { EventsMixin } from "../../../mixins/events-mixin";
@ -151,7 +151,7 @@ class HaPanelDevEvent extends EventsMixin(LocalizeMixin(PolymerElement)) {
_computeParsedEventData(eventData) {
try {
return eventData.trim() ? safeLoad(eventData) : {};
return eventData.trim() ? load(eventData) : {};
} catch (err) {
return ERROR_SENTINEL;
}

View File

@ -1,6 +1,6 @@
import { mdiHelpCircle } from "@mdi/js";
import { ERR_CONNECTION_LOST } from "home-assistant-js-websocket";
import { safeLoad } from "js-yaml";
import { load } from "js-yaml";
import { css, CSSResultGroup, html, LitElement } from "lit";
import { property, query, state } from "lit/decorators";
import memoizeOne from "memoize-one";
@ -361,9 +361,9 @@ class HaPanelDevService extends LitElement {
const example = {};
fields.forEach((field) => {
if (field.example) {
let value = "";
let value: any = "";
try {
value = safeLoad(field.example);
value = load(field.example);
} catch (err) {
value = field.example;
}

View File

@ -9,7 +9,7 @@ import "@polymer/paper-input/paper-input";
import { html } from "@polymer/polymer/lib/utils/html-tag";
/* eslint-plugin-disable lit */
import { PolymerElement } from "@polymer/polymer/polymer-element";
import { safeDump, safeLoad } from "js-yaml";
import { dump, load } from "js-yaml";
import { formatDateTimeWithSeconds } from "../../../common/datetime/format_date_time";
import { computeRTL } from "../../../common/util/compute_rtl";
import { copyToClipboard } from "../../../common/util/copy-clipboard";
@ -332,7 +332,7 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
this._entityId = state.entity_id;
this._entity = state;
this._state = state.state;
this._stateAttributes = safeDump(state.attributes);
this._stateAttributes = dump(state.attributes);
ev.preventDefault();
}
@ -349,7 +349,7 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
}
this._entity = state;
this._state = state.state;
this._stateAttributes = safeDump(state.attributes);
this._stateAttributes = dump(state.attributes);
}
entityMoreInfo(ev) {
@ -493,7 +493,7 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
(Array.isArray(value) && value.some((val) => val instanceof Object)) ||
(!Array.isArray(value) && value instanceof Object)
) {
return `\n${safeDump(value)}`;
return `\n${dump(value)}`;
}
return Array.isArray(value) ? value.join(", ") : value;
}
@ -508,7 +508,7 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
_computeParsedStateAttributes(stateAttributes) {
try {
return stateAttributes.trim() ? safeLoad(stateAttributes) : {};
return stateAttributes.trim() ? load(stateAttributes) : {};
} catch (err) {
return ERROR_SENTINEL;
}

View File

@ -1,4 +1,4 @@
import { safeDump } from "js-yaml";
import { dump } from "js-yaml";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, state } from "lit/decorators";
import { HomeAssistant } from "../../../types";
@ -28,7 +28,7 @@ export class HuiErrorCard extends LitElement implements LovelaceCard {
if (this._config.origConfig) {
try {
dumped = safeDump(this._config.origConfig);
dumped = dump(this._config.origConfig);
} catch (err) {
dumped = `[Error dumping ${this._config.origConfig}]`;
}

View File

@ -1,5 +1,5 @@
import "@material/mwc-button";
import { safeDump, safeLoad } from "js-yaml";
import { dump, load } from "js-yaml";
import {
css,
CSSResultGroup,
@ -77,7 +77,7 @@ export abstract class HuiElementEditor<T> extends LitElement {
public get yaml(): string {
if (!this._yaml) {
this._yaml = safeDump(this._config);
this._yaml = dump(this._config);
}
return this._yaml || "";
}
@ -85,7 +85,7 @@ export abstract class HuiElementEditor<T> extends LitElement {
public set yaml(_yaml: string) {
this._yaml = _yaml;
try {
this._config = safeLoad(this.yaml);
this._config = load(this.yaml) as any;
this._errors = undefined;
} catch (err) {
this._errors = [err.message];

View File

@ -2,7 +2,7 @@ import { undoDepth } from "@codemirror/history";
import "@material/mwc-button";
import "@polymer/app-layout/app-header/app-header";
import "@polymer/app-layout/app-toolbar/app-toolbar";
import { safeDump, safeLoad } from "js-yaml";
import { dump, load } from "js-yaml";
import {
css,
CSSResultGroup,
@ -104,7 +104,7 @@ class LovelaceFullConfigEditor extends LitElement {
protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
this.yamlEditor.value = safeDump(this.lovelace!.rawConfig);
this.yamlEditor.value = dump(this.lovelace!.rawConfig);
}
protected updated(changedProps: PropertyValues) {
@ -122,7 +122,7 @@ class LovelaceFullConfigEditor extends LitElement {
),
action: {
action: () => {
this.yamlEditor.value = safeDump(this.lovelace!.rawConfig);
this.yamlEditor.value = dump(this.lovelace!.rawConfig);
},
text: this.hass!.localize(
"ui.panel.lovelace.editor.raw_editor.reload"
@ -258,7 +258,7 @@ class LovelaceFullConfigEditor extends LitElement {
let config: LovelaceConfig;
try {
config = safeLoad(value);
config = load(value) as LovelaceConfig;
} catch (err) {
showAlertDialog(this, {
text: this.hass.localize(

View File

@ -0,0 +1 @@
export { dump } from "js-yaml";

View File

@ -7,7 +7,7 @@ import { isDate } from "../common/string/is_date";
import { isTimestamp } from "../common/string/is_timestamp";
import { HomeAssistant } from "../types";
let jsYamlPromise: Promise<typeof import("js-yaml")>;
let jsYamlPromise: Promise<typeof import("../resources/js-yaml-dump")>;
const hassAttributeUtil = {
DOMAIN_DEVICE_CLASS: {
@ -156,9 +156,9 @@ export function formatAttributeValue(
(!Array.isArray(value) && value instanceof Object)
) {
if (!jsYamlPromise) {
jsYamlPromise = import("js-yaml");
jsYamlPromise = import("../resources/js-yaml-dump");
}
const yaml = jsYamlPromise.then((jsYaml) => jsYaml.safeDump(value));
const yaml = jsYamlPromise.then((jsYaml) => jsYaml.dump(value));
return html`<pre>${until(yaml, "")}</pre>`;
}

View File

@ -2762,10 +2762,10 @@
resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-1.8.0.tgz#682477dbbbd07cd032731cb3b0e7eaee3d026b69"
integrity sha512-2aoSC4UUbHDj2uCsCxcG/vRMXey/m17bC7UwitVm5hn22nI8O8Y9iDpA76Orc+DWkQ4zZrOKEshCqR/jSuXAHA==
"@types/js-yaml@^3.12.1":
version "3.12.1"
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.12.1.tgz#5c6f4a1eabca84792fbd916f0cb40847f123c656"
integrity sha512-SGGAhXLHDx+PK4YLNcNGa6goPf9XRWQNAUUbffkwVGGXIxmDKWyGGL4inzq2sPmExu431Ekb9aEMn9BkPqEYFA==
"@types/js-yaml@^4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.1.tgz#5544730b65a480b18ace6b6ce914e519cec2d43b"
integrity sha512-xdOvNmXmrZqqPy3kuCQ+fz6wA0xU5pji9cd1nDrflWaAWtYLLGk5ykW0H6yg5TVyehHP1pfmuuSaZkhP+kspVA==
"@types/json-schema@*":
version "7.0.5"
@ -3831,6 +3831,11 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"
argparse@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==
arr-diff@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-2.0.0.tgz#8f3b827f955a8bd669697e4a4256ac3ceae356cf"
@ -8365,6 +8370,13 @@ js-yaml@3.13.1, js-yaml@^3.13.0, js-yaml@^3.13.1:
argparse "^1.0.7"
esprima "^4.0.0"
js-yaml@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
dependencies:
argparse "^2.0.1"
jsesc@^2.5.1:
version "2.5.2"
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4"