diff --git a/internal/benchmark/lib/ConfigurationLoader.js b/internal/benchmark/lib/ConfigurationLoader.js index 609245b483d..c41ba0c228a 100644 --- a/internal/benchmark/lib/ConfigurationLoader.js +++ b/internal/benchmark/lib/ConfigurationLoader.js @@ -1,4 +1,4 @@ -import yaml from "js-yaml"; +import {load as yamlLoad} from "js-yaml"; import Configuration from "./benchmark/Configuration.js"; /** @@ -37,7 +37,7 @@ export default class ConfigurationLoader { let parsedYaml; try { - parsedYaml = yaml.load(fileContents); + parsedYaml = yamlLoad(fileContents); } catch (error) { throw new Error(`Failed to parse YAML configuration: ${error.message}`); } diff --git a/internal/benchmark/package.json b/internal/benchmark/package.json index 50943e1da16..3ed476f44c5 100644 --- a/internal/benchmark/package.json +++ b/internal/benchmark/package.json @@ -19,6 +19,6 @@ }, "devDependencies": { "eslint": "^10.9.1", - "js-yaml": "^4.3.1" + "js-yaml": "^5.4.1" } } diff --git a/package-lock.json b/package-lock.json index b74d417affa..8cd423b17c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,13 +40,36 @@ }, "devDependencies": { "eslint": "^10.9.1", - "js-yaml": "^4.3.1" + "js-yaml": "^5.4.1" }, "engines": { "node": "^22.22.2 || ^24.15.0 || >=26.0.0", "npm": ">= 8" } }, + "internal/benchmark/node_modules/js-yaml": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-5.4.1.tgz", + "integrity": "sha512-28R/k+NAjeuf7+CKlTxWZVExJGwVVLwY06DgEnOMz2gEpfNkDcD7QvyiVPT0xy0XXhU8vHsd4Ot42OOPdJG7dQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/nodeca" + } + ], + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.mjs" + } + }, "internal/documentation": { "name": "@ui5/documentation", "version": "0.0.1", @@ -11991,6 +12014,7 @@ "version": "4.3.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.1.tgz", "integrity": "sha512-CY6crGq313MX8GkwvB7tzgp99vjQxY1++5y10/BKN/GUfHqWaOGQMNZkBvqSzsZKWk/ijwHlWzzkLulsGHhjWQ==", + "dev": true, "funding": [ { "type": "github", @@ -19054,7 +19078,7 @@ "chalk": "^6.0.0", "data-with-position": "^0.5.0", "import-local": "^3.2.0", - "js-yaml": "^4.3.1", + "js-yaml": "^5.4.1", "open": "^11.0.1", "pretty-hrtime": "^1.0.3", "semver": "^7.8.5", @@ -19109,6 +19133,28 @@ "node": ">=20" } }, + "packages/cli/node_modules/js-yaml": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-5.4.1.tgz", + "integrity": "sha512-28R/k+NAjeuf7+CKlTxWZVExJGwVVLwY06DgEnOMz2gEpfNkDcD7QvyiVPT0xy0XXhU8vHsd4Ot42OOPdJG7dQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/nodeca" + } + ], + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.mjs" + } + }, "packages/cli/node_modules/yargs": { "version": "18.1.0", "resolved": "https://registry.npmjs.org/yargs/-/yargs-18.1.0.tgz", @@ -19263,7 +19309,7 @@ "escape-string-regexp": "^5.0.0", "globby": "^14.1.0", "graceful-fs": "^4.2.11", - "js-yaml": "^4.3.1", + "js-yaml": "^5.4.1", "lockfile": "^1.0.4", "make-fetch-happen": "^15.0.6", "micromatch": "^4.0.8", @@ -19370,6 +19416,28 @@ "node": ">= 4" } }, + "packages/project/node_modules/js-yaml": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-5.4.1.tgz", + "integrity": "sha512-28R/k+NAjeuf7+CKlTxWZVExJGwVVLwY06DgEnOMz2gEpfNkDcD7QvyiVPT0xy0XXhU8vHsd4Ot42OOPdJG7dQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/nodeca" + } + ], + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.mjs" + } + }, "packages/server": { "name": "@ui5/server", "version": "5.0.0-alpha.8", diff --git a/packages/cli/lib/cli/commands/init.js b/packages/cli/lib/cli/commands/init.js index 5985c4f07c0..b4e88219268 100644 --- a/packages/cli/lib/cli/commands/init.js +++ b/packages/cli/lib/cli/commands/init.js @@ -12,7 +12,7 @@ initCommand.handler = async function() { const {default: init} = await import("../../init/init.js"); const {default: path} = await import("node:path"); const {writeFile} = await import("node:fs/promises"); - const {default: jsYaml} = await import("js-yaml"); + const {dump: jsYamlDump} = await import("js-yaml"); const yamlPath = path.resolve("./ui5.yaml"); if (await exists(yamlPath)) { @@ -20,7 +20,7 @@ initCommand.handler = async function() { } const projectConfig = await init(); - const yaml = jsYaml.dump(projectConfig, {quotingType: `"`}); + const yaml = jsYamlDump(projectConfig, {quoteStyle: "double"}); await writeFile(yamlPath, yaml); process.stdout.write(`Wrote ui5.yaml to ${yamlPath}:`); diff --git a/packages/cli/lib/framework/updateYaml.js b/packages/cli/lib/framework/updateYaml.js index 12063245f91..edce87f0342 100644 --- a/packages/cli/lib/framework/updateYaml.js +++ b/packages/cli/lib/framework/updateYaml.js @@ -1,6 +1,6 @@ import path from "node:path"; import {readFile, writeFile} from "node:fs/promises"; -import {loadAll, dump} from "js-yaml"; +import {loadAll, dump, CORE_SCHEMA} from "js-yaml"; import {fromYaml, getPosition, getValue, getKind} from "data-with-position"; import {getLogger} from "@ui5/logger"; @@ -149,7 +149,7 @@ function formatValue(value, indent) { return string; } else if (Array.isArray(value)) { const indentString = " ".repeat(indent); - const string = dump(value); + const string = dump(value, {schema: CORE_SCHEMA}); const arr = string.split("\n"); arr.pop(); return "\n" + indentString + arr.join("\n" + indentString) + "\n"; diff --git a/packages/cli/package.json b/packages/cli/package.json index 0853363d4b0..214e4473340 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -59,7 +59,7 @@ "chalk": "^6.0.0", "data-with-position": "^0.5.0", "import-local": "^3.2.0", - "js-yaml": "^4.3.1", + "js-yaml": "^5.4.1", "open": "^11.0.1", "pretty-hrtime": "^1.0.3", "semver": "^7.8.5", diff --git a/packages/cli/test/lib/cli/commands/init.js b/packages/cli/test/lib/cli/commands/init.js index 33785f14367..24554ea6e7e 100644 --- a/packages/cli/test/lib/cli/commands/init.js +++ b/packages/cli/test/lib/cli/commands/init.js @@ -38,7 +38,8 @@ test.serial("Writes ui5.yaml to fs", async (t) => { t.is(fsWriteFileStub.getCall(0).args[0], ui5YamlPath, "Passes yaml path to write the yaml file to"); t.is(fsWriteFileStub.getCall(0).args[1], ui5Yaml, "Passes yaml content to write to fs"); - t.deepEqual(jsyamlDumpStub.getCall(0).args[1], {quotingType: `"`}, "Enforce usage of double quotes in yaml files"); + t.deepEqual(jsyamlDumpStub.getCall(0).args[1], + {quoteStyle: "double"}, "Enforce usage of double quotes in yaml files"); }); test.serial("Error: throws if ui5.yaml already exists", async (t) => { diff --git a/packages/project/lib/graph/Module.js b/packages/project/lib/graph/Module.js index 9609a49d456..a5d28ef34be 100644 --- a/packages/project/lib/graph/Module.js +++ b/packages/project/lib/graph/Module.js @@ -2,7 +2,7 @@ import fs from "graceful-fs"; import path from "node:path"; import {promisify} from "node:util"; const readFile = promisify(fs.readFile); -import jsyaml from "js-yaml"; +import {loadAll as jsyamlLoadAll, CORE_SCHEMA as jsyamlCoreSchema} from "js-yaml"; import {createReader} from "@ui5/fs/resourceFactory"; import Specification from "../specifications/Specification.js"; import {validate} from "../validation/validator.js"; @@ -318,12 +318,10 @@ class Module { let configs; try { - // 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 - configs = jsyaml.loadAll(configFile, undefined, { + // Using loadAll with CORE_SCHEMA (equivalent of v4's DEFAULT_SAFE_SCHEMA) to pass "filename". + configs = jsyamlLoadAll(configFile, undefined, { filename: configPath, - schema: jsyaml.DEFAULT_SAFE_SCHEMA + schema: jsyamlCoreSchema }); } catch (err) { if (err.name === "YAMLException") { diff --git a/packages/project/lib/graph/helpers/createWorkspace.js b/packages/project/lib/graph/helpers/createWorkspace.js index 4b8a41d39dc..6052491f4b4 100644 --- a/packages/project/lib/graph/helpers/createWorkspace.js +++ b/packages/project/lib/graph/helpers/createWorkspace.js @@ -74,7 +74,7 @@ async function readWorkspaceConfigFile(filePath) { } = await import("graceful-fs"); const {promisify} = await import("node:util"); const readFile = promisify(fs.readFile); - const jsyaml = await import("js-yaml"); + const {loadAll: jsyamlLoadAll} = await import("js-yaml"); let fileContent; try { @@ -87,7 +87,7 @@ async function readWorkspaceConfigFile(filePath) { } let configs; try { - configs = jsyaml.loadAll(fileContent, undefined, { + configs = jsyamlLoadAll(fileContent, undefined, { filename: filePath, }); } catch (err) { diff --git a/packages/project/package.json b/packages/project/package.json index ab68570c637..513c35af347 100644 --- a/packages/project/package.json +++ b/packages/project/package.json @@ -70,7 +70,7 @@ "escape-string-regexp": "^5.0.0", "globby": "^14.1.0", "graceful-fs": "^4.2.11", - "js-yaml": "^4.3.1", + "js-yaml": "^5.4.1", "lockfile": "^1.0.4", "make-fetch-happen": "^15.0.6", "micromatch": "^4.0.8",