Skip to content

Commit

Permalink
[DEPENDENCY] Bump js-yaml from 3.14.1 to 4.0.0 (#402)
Browse files Browse the repository at this point in the history
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Matthias Osswald <mat.osswald@sap.com>
  • Loading branch information
dependabot[bot] and matz3 committed Mar 4, 2021
1 parent 43967fa commit 0033c52
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ initCommand.handler = async function() {
}

const projectConfig = await init.init();
const yaml = jsYaml.safeDump(projectConfig);
const yaml = jsYaml.dump(projectConfig);

await writeFile(yamlPath, yaml);
console.log(`Wrote ui5.yaml to ${yamlPath}:\n`);
Expand Down
20 changes: 6 additions & 14 deletions lib/framework/updateYaml.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
const path = require("path");
const log = require("@ui5/logger").getLogger("cli:framework:updateYaml");
const {loadAll, safeDump, DEFAULT_SAFE_SCHEMA} = require("js-yaml");
const {loadAll, dump} = require("js-yaml");
const {fromYaml, getPosition, getValue} = require("data-with-position");

function safeLoadAll({configFile, configPath}) {
// Using loadAll with DEFAULT_SAFE_SCHEMA instead of safeLoadAll to pass "filename".
// safeLoadAll doesn't handle its parameters properly.
// See https://github.com/nodeca/js-yaml/issues/456 and https://github.com/nodeca/js-yaml/pull/381
return loadAll(configFile, undefined, {
filename: configPath,
schema: DEFAULT_SAFE_SCHEMA
});
}

function getProjectYamlDocument({project, configFile, configPath}) {
const configs = safeLoadAll({configFile, configPath});
const configs = loadAll(configFile, undefined, {
filename: configPath
});

const projectDocumentIndex = configs.findIndex((config) => {
return config.metadata && config.metadata.name === project.metadata.name;
Expand Down Expand Up @@ -138,7 +130,7 @@ function formatValue(value, indent) {
return string;
} else if (Array.isArray(value)) {
const indentString = " ".repeat(indent);
const string = safeDump(value);
const string = dump(value);
const arr = string.split("\n");
arr.pop();
return "\n" + indentString + arr.join("\n" + indentString) + "\n";
Expand Down Expand Up @@ -261,7 +253,7 @@ module.exports = async function({project, data}) {

// Validate content before writing
try {
safeLoadAll({configFile: adoptedYaml});
loadAll(adoptedYaml);
} catch (err) {
const error = new Error("Failed to update YAML file: " + err.message);
error.name = "FrameworkUpdateYamlFailed";
Expand Down
99 changes: 94 additions & 5 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"chalk": "^4.1.0",
"data-with-position": "^0.4.1",
"import-local": "^3.0.2",
"js-yaml": "^3.14.1",
"js-yaml": "^4.0.0",
"open": "^7.4.2",
"semver": "^7.3.4",
"treeify": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion test/lib/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test.serial("Writes ui5.yaml to fs", async (t) => {
mock("path", {resolve: () => ui5YamlPath});
sinon.stub(fsHelper, "exists").resolves(false);
sinon.stub(init, "init").resolves({});
sinon.stub(jsYaml, "safeDump").returns(ui5Yaml);
sinon.stub(jsYaml, "dump").returns(ui5Yaml);
const fsWriteFileStub = sinon.stub(fs, "writeFile").callsArgWith(2);

await initCommand.handler({});
Expand Down
10 changes: 7 additions & 3 deletions test/lib/framework/updateYaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,13 @@ framework: { name: "SAPUI5" }
}));

t.is(error.message,
"Failed to update YAML file: bad indentation of a mapping entry at line 5, column 14:\n" +
" version: \"1.76.0\"\n" +
" ^"
`Failed to update YAML file: bad indentation of a mapping entry (5:14)\n` +
`\n` +
` 2 | metadata:\n` +
` 3 | name: my-project\n` +
` 4 | framework: { name: "SAPUI5" }\n` +
` 5 | version: "1.76.0"\n` +
`------------------^`
);
t.is(t.context.fsWriteFileStub.callCount, 0, "fs.writeFile should not be called");
});
Expand Down

0 comments on commit 0033c52

Please sign in to comment.