Parse Prettier config with yaml (#17410)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
fisker Cheungandautofix-ci[bot] authored and GitHub committed 2025-05-06 08:18:50 +08:00
1 parent 8860046468
commit 38dc5dee18
8 files changed
+46 -29

No files matched your search

+1 -1
View File
@@ -70,7 +70,6 @@
"import-meta-resolve": "4.1.0",
"is-es5-identifier-name": "1.0.0",
"jest-docblock": "30.0.0-alpha.7",
"js-yaml": "4.1.0",
"json5": "2.2.3",
"leven": "4.0.0",
"linguist-languages": "7.29.0",
@@ -104,6 +103,7 @@
"url-or-path": "2.6.1",
"vnopts": "2.0.2",
"wcwidth.js": "2.0.0",
"yaml": "1.10.2",
"yaml-unist-parser": "2.0.5"
},
"devDependencies": {
+10
View File
@@ -202,6 +202,16 @@ function getEsbuildOptions({ packageConfig, file, cliOptions }) {
);
}
// Current version of `yaml` is not tree-shakable,
// but when we update it, we may reduce size,
// since the UMD version don't need expose `__parsePrettierYamlConfig`
if (file.output.format === "umd" && file.output.file === "plugins/yaml.js") {
replaceModule.push({
module: path.join(PROJECT_ROOT, file.input),
text: 'export * from "../language-yaml/index.js";',
});
}
const { buildOptions } = file;
const shouldMinify =
cliOptions.minify ?? buildOptions.minify ?? file.platform === "universal";
-5
View File
@@ -761,11 +761,6 @@ const nodejsFiles = [
find: "const readBuffer = new Buffer(this.options.readChunk);",
replacement: "const readBuffer = Buffer.alloc(this.options.readChunk);",
},
{
module: getPackageFile("js-yaml/dist/js-yaml.mjs"),
find: "var dump = dumper.dump;",
replacement: "var dump;",
},
// `parse-json` use another copy of `@babel/code-frame`
{
module: require.resolve("@babel/code-frame", {
+8 -1
View File
@@ -1,5 +1,4 @@
import { pathToFileURL } from "node:url";
import { load as parseYaml } from "js-yaml";
import json5 from "json5";
import parseJson from "parse-json";
import { parse as parseToml } from "smol-toml";
@@ -53,8 +52,16 @@ async function loadConfigFromPackageYaml(file) {
return prettier;
}
let parseYaml;
async function loadYaml(file) {
const content = await readFile(file);
if (!parseYaml) {
({ __parsePrettierYamlConfig: parseYaml } = await import(
"../../plugins/yaml.js"
));
}
try {
return parseYaml(content);
} catch (/** @type {any} */ error) {
+10
View File
@@ -1 +1,11 @@
/*
Be careful when changing this file,
when bundle UMD version
build script will change the file content
to remove the `__parsePrettierYamlConfig` export.
*/
export * from "../language-yaml/index.js";
// Exposed to parser prettier yaml config
import YAML from "yaml";
export const __parsePrettierYamlConfig = YAML.parse;
@@ -149,18 +149,13 @@ describe("Invalid yaml file", () => {
stdout: "",
write: [],
stderr: expect.stringContaining(
/* cSpell:disable */
// Keep the outdent, since error message changes between versions
outdent`
end of the stream or a document separator is expected (2:1)
1 | a
2 | -b
-----^
Map keys must be unique; "a" is repeated
`
.split("\n")
.map((line) => `[error] ${line}`)
.join("\n"),
/* cSpell:enable */
),
});
});
@@ -1,2 +1,2 @@
a
-b
a:
a:
+13 -13
View File
@@ -5905,17 +5905,6 @@ __metadata:
languageName: node
linkType: hard
"js-yaml@npm:4.1.0, js-yaml@npm:^4.1.0":
version: 4.1.0
resolution: "js-yaml@npm:4.1.0"
dependencies:
argparse: "npm:^2.0.1"
bin:
js-yaml: bin/js-yaml.js
checksum: 10/c138a34a3fd0d08ebaf71273ad4465569a483b8a639e0b118ff65698d257c2791d3199e3f303631f2cb98213fa7b5f5d6a4621fd0fff819421b990d30d967140
languageName: node
linkType: hard
"js-yaml@npm:^3.13.1":
version: 3.14.1
resolution: "js-yaml@npm:3.14.1"
@@ -5928,6 +5917,17 @@ __metadata:
languageName: node
linkType: hard
"js-yaml@npm:^4.1.0":
version: 4.1.0
resolution: "js-yaml@npm:4.1.0"
dependencies:
argparse: "npm:^2.0.1"
bin:
js-yaml: bin/js-yaml.js
checksum: 10/c138a34a3fd0d08ebaf71273ad4465569a483b8a639e0b118ff65698d257c2791d3199e3f303631f2cb98213fa7b5f5d6a4621fd0fff819421b990d30d967140
languageName: node
linkType: hard
"jsbn@npm:1.1.0":
version: 1.1.0
resolution: "jsbn@npm:1.1.0"
@@ -7050,7 +7050,6 @@ __metadata:
jest-snapshot-serializer-ansi: "npm:2.2.1"
jest-snapshot-serializer-raw: "npm:2.0.0"
jest-watch-typeahead: "npm:2.2.2"
js-yaml: "npm:4.1.0"
json5: "npm:2.2.3"
knip: "npm:5.50.5"
leven: "npm:4.0.0"
@@ -7098,6 +7097,7 @@ __metadata:
url-or-path: "npm:2.6.1"
vnopts: "npm:2.0.2"
wcwidth.js: "npm:2.0.0"
yaml: "npm:1.10.2"
yaml-unist-parser: "npm:2.0.5"
bin:
prettier: ./bin/prettier.cjs
@@ -8755,7 +8755,7 @@ __metadata:
languageName: node
linkType: hard
"yaml@npm:^1.10.2":
"yaml@npm:1.10.2, yaml@npm:^1.10.2":
version: 1.10.2
resolution: "yaml@npm:1.10.2"
checksum: 10/e088b37b4d4885b70b50c9fa1b7e54bd2e27f5c87205f9deaffd1fb293ab263d9c964feadb9817a7b129a5bf30a06582cb08750f810568ecc14f3cdbabb79cb3