From c1577ff1e8fe2cbf995a6eba38bcf50d73f9e7ee Mon Sep 17 00:00:00 2001 From: Kevin Heis Date: Mon, 11 Aug 2025 06:41:17 -0700 Subject: [PATCH] Replace gray-matter with @gr2m/gray-matter to control quotes in frontmatter (#57049) --- next.config.js | 2 +- package-lock.json | 63 +++++-------------- package.json | 2 +- .../lib/update-markdown.ts | 2 +- .../tests/update-markdown.ts | 2 +- src/codeql-cli/scripts/sync.js | 2 +- src/content-linter/lib/helpers/utils.js | 2 +- src/data-directory/lib/data-directory.ts | 2 +- src/data-directory/lib/get-data.js | 2 +- src/frame/lib/read-frontmatter.js | 5 +- src/frame/tests/read-frontmatter.js | 2 +- .../scripts/create-enterprise-issue.ts | 2 +- src/workflows/fm-utils.ts | 2 +- 13 files changed, 30 insertions(+), 60 deletions(-) diff --git a/next.config.js b/next.config.js index b05ccea811..62978f55f9 100644 --- a/next.config.js +++ b/next.config.js @@ -1,7 +1,7 @@ import fs from 'fs' import path from 'path' -import frontmatter from 'gray-matter' +import frontmatter from '@gr2m/gray-matter' import { getLogLevelNumber } from '#src/observability/logger/lib/log-levels.js' // Replace imports with hardcoded values diff --git a/package-lock.json b/package-lock.json index 45db695bf7..c94f46bd52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@elastic/elasticsearch": "8.13.1", "@github/failbot": "0.8.3", + "@gr2m/gray-matter": "4.0.3-with-pr-137", "@horizon-rs/language-guesser": "0.1.1", "@octokit/plugin-retry": "8.0.1", "@octokit/request-error": "7.0.0", @@ -43,7 +44,6 @@ "github-slugger": "^2.0.0", "glob": "11.0.2", "got": "^14.4.7", - "gray-matter": "^4.0.3", "hast-util-from-parse5": "^8.0.3", "hast-util-to-string": "^3.0.1", "hastscript": "^9.0.1", @@ -1614,6 +1614,21 @@ "integrity": "sha512-Yx70pO8A0p7Stnm9knKkUNX8i4bjuwDYZarRkM8JH0Z+ffhpe++oNAPbzGI9GEcGugRHvKuSC6p4YOdoHtTniQ==", "license": "MIT" }, + "node_modules/@gr2m/gray-matter": { + "version": "4.0.3-with-pr-137", + "resolved": "https://registry.npmjs.org/@gr2m/gray-matter/-/gray-matter-4.0.3-with-pr-137.tgz", + "integrity": "sha512-6prHnKL+WQzCFe64DtUKki7MacXZARwNH3jlocGrOMgGw8AJASl405f/ULz6vjIU9uTDnxwP2N7ZlHEqOX1T6w==", + "license": "MIT", + "dependencies": { + "js-yaml": "^4.1.0", + "kind-of": "^6.0.2", + "section-matter": "^1.0.0", + "strip-bom-string": "^1.0.0" + }, + "engines": { + "node": ">=6.0" + } + }, "node_modules/@graphql-inspector/core": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/@graphql-inspector/core/-/core-6.1.0.tgz", @@ -8445,17 +8460,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/esprima": { - "version": "4.0.1", - "license": "BSD-2-Clause", - "bin": { - "esparse": "bin/esparse.js", - "esvalidate": "bin/esvalidate.js" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/esquery": { "version": "1.5.0", "dev": true, @@ -9388,37 +9392,6 @@ "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" } }, - "node_modules/gray-matter": { - "version": "4.0.3", - "license": "MIT", - "dependencies": { - "js-yaml": "^3.13.1", - "kind-of": "^6.0.2", - "section-matter": "^1.0.0", - "strip-bom-string": "^1.0.0" - }, - "engines": { - "node": ">=6.0" - } - }, - "node_modules/gray-matter/node_modules/argparse": { - "version": "1.0.10", - "license": "MIT", - "dependencies": { - "sprintf-js": "~1.0.2" - } - }, - "node_modules/gray-matter/node_modules/js-yaml": { - "version": "3.14.1", - "license": "MIT", - "dependencies": { - "argparse": "^1.0.7", - "esprima": "^4.0.0" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" - } - }, "node_modules/has-bigints": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", @@ -15013,10 +14986,6 @@ "node": "*" } }, - "node_modules/sprintf-js": { - "version": "1.0.3", - "license": "BSD-3-Clause" - }, "node_modules/srcset": { "version": "5.0.0", "dev": true, diff --git a/package.json b/package.json index a1e24880f3..bf066c142c 100644 --- a/package.json +++ b/package.json @@ -282,7 +282,7 @@ "github-slugger": "^2.0.0", "glob": "11.0.2", "got": "^14.4.7", - "gray-matter": "^4.0.3", + "@gr2m/gray-matter": "4.0.3-with-pr-137", "hast-util-from-parse5": "^8.0.3", "hast-util-to-string": "^3.0.1", "hastscript": "^9.0.1", diff --git a/src/automated-pipelines/lib/update-markdown.ts b/src/automated-pipelines/lib/update-markdown.ts index 6375c99adc..5face8f32f 100644 --- a/src/automated-pipelines/lib/update-markdown.ts +++ b/src/automated-pipelines/lib/update-markdown.ts @@ -2,7 +2,7 @@ import walk from 'walk-sync' import { existsSync, lstatSync, unlinkSync } from 'fs' import path from 'path' import { readFile, writeFile, readdir } from 'fs/promises' -import matter from 'gray-matter' +import matter from '@gr2m/gray-matter' import { rimraf } from 'rimraf' import { mkdirp } from 'mkdirp' import { difference, isEqual } from 'lodash-es' diff --git a/src/automated-pipelines/tests/update-markdown.ts b/src/automated-pipelines/tests/update-markdown.ts index 6bd3205248..6ab6a03ca7 100644 --- a/src/automated-pipelines/tests/update-markdown.ts +++ b/src/automated-pipelines/tests/update-markdown.ts @@ -5,7 +5,7 @@ import path from 'path' import { afterAll, beforeAll, describe, expect, test } from 'vitest' import { mkdirp } from 'mkdirp' -import matter from 'gray-matter' +import matter from '@gr2m/gray-matter' import type { FrontmatterVersions } from '@/types' import { updateContentDirectory } from '../lib/update-markdown' diff --git a/src/codeql-cli/scripts/sync.js b/src/codeql-cli/scripts/sync.js index 488ae9e3fa..93ed6a4d62 100755 --- a/src/codeql-cli/scripts/sync.js +++ b/src/codeql-cli/scripts/sync.js @@ -4,7 +4,7 @@ import walk from 'walk-sync' import { mkdirp } from 'mkdirp' import { execFileSync, execSync } from 'child_process' import path from 'path' -import matter from 'gray-matter' +import matter from '@gr2m/gray-matter' import { rimraf } from 'rimraf' import { updateContentDirectory } from '../../automated-pipelines/lib/update-markdown' diff --git a/src/content-linter/lib/helpers/utils.js b/src/content-linter/lib/helpers/utils.js index c186ef1a2e..f994deac22 100644 --- a/src/content-linter/lib/helpers/utils.js +++ b/src/content-linter/lib/helpers/utils.js @@ -1,5 +1,5 @@ import { addError, filterTokens } from 'markdownlint-rule-helpers' -import matter from 'gray-matter' +import matter from '@gr2m/gray-matter' // Adds an error object with details conditionally via the onError callback export function addFixErrorDetail(onError, lineNumber, expected, actual, range, fixInfo) { diff --git a/src/data-directory/lib/data-directory.ts b/src/data-directory/lib/data-directory.ts index f9739b4f72..dc87f873c2 100644 --- a/src/data-directory/lib/data-directory.ts +++ b/src/data-directory/lib/data-directory.ts @@ -5,7 +5,7 @@ import walk from 'walk-sync' import yaml from 'js-yaml' import { isRegExp, setWith } from 'lodash-es' import filenameToKey from './filename-to-key' -import matter from 'gray-matter' +import matter from '@gr2m/gray-matter' interface DataDirectoryOptions { preprocess?: (content: string) => string diff --git a/src/data-directory/lib/get-data.js b/src/data-directory/lib/get-data.js index aa3246de03..4ea6f90099 100644 --- a/src/data-directory/lib/get-data.js +++ b/src/data-directory/lib/get-data.js @@ -2,7 +2,7 @@ import fs from 'fs' import path from 'path' import yaml from 'js-yaml' -import matter from 'gray-matter' +import matter from '@gr2m/gray-matter' import { merge, get } from 'lodash-es' import languages from '@/languages/lib/languages' diff --git a/src/frame/lib/read-frontmatter.js b/src/frame/lib/read-frontmatter.js index 25a153d178..fbf59ca98d 100644 --- a/src/frame/lib/read-frontmatter.js +++ b/src/frame/lib/read-frontmatter.js @@ -1,4 +1,4 @@ -import matter from 'gray-matter' +import matter from '@gr2m/gray-matter' import { validateJson } from '@/tests/lib/validate-json-schema' @@ -15,7 +15,8 @@ function readFrontmatter(markdown, opts = {}) { const reason = e.reason ? // make this common error message a little easier to understand - e.reason.startsWith('can not read a block mapping entry;') + e.reason.startsWith('can not read a block mapping entry;') || + e.reason === 'bad indentation of a mapping entry' ? defaultReason : e.reason : defaultReason diff --git a/src/frame/tests/read-frontmatter.js b/src/frame/tests/read-frontmatter.js index a4d3a03d31..da0d0adb95 100644 --- a/src/frame/tests/read-frontmatter.js +++ b/src/frame/tests/read-frontmatter.js @@ -65,7 +65,7 @@ I am content. const expectedError = { filepath: 'path/to/file.md', message: 'YML parsing error!', - reason: 'bad indentation of a mapping entry', + reason: 'invalid frontmatter entry', } expect(errors[0]).toEqual(expectedError) }) diff --git a/src/ghes-releases/scripts/create-enterprise-issue.ts b/src/ghes-releases/scripts/create-enterprise-issue.ts index 19663a370b..cabba508e9 100644 --- a/src/ghes-releases/scripts/create-enterprise-issue.ts +++ b/src/ghes-releases/scripts/create-enterprise-issue.ts @@ -2,7 +2,7 @@ import { readFileSync } from 'fs' import { basename } from 'path' import { Liquid } from 'liquidjs' import walk from 'walk-sync' -import matter from 'gray-matter' +import matter from '@gr2m/gray-matter' import { latest, oldestSupported } from '@/versions/lib/enterprise-server-releases' import { getContents } from '@/workflows/git-utils' diff --git a/src/workflows/fm-utils.ts b/src/workflows/fm-utils.ts index b6d39e53ce..1ec0aa8a72 100644 --- a/src/workflows/fm-utils.ts +++ b/src/workflows/fm-utils.ts @@ -1,5 +1,5 @@ import { readFileSync } from 'fs' -import matter from 'gray-matter' +import matter from '@gr2m/gray-matter' // Filters out files from a list of filePaths // that have a type property in their frontmatter