Skip to content

Commit 6f20d1b

Browse files
dependabot[bot]stevesCopilotCopilot
authored
Bump js-yaml from 4.2.0 to 5.1.0 (#61999)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Steve S <steves@users.noreply.github.com> Co-authored-by: steves <steves@github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent c062f1a commit 6f20d1b

8 files changed

Lines changed: 100 additions & 15 deletions

File tree

package-lock.json

Lines changed: 50 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
"is-svg": "6.0.0",
229229
"javascript-stringify": "^2.1.0",
230230
"js-cookie": "^3.0.7",
231-
"js-yaml": "^4.2.0",
231+
"js-yaml": "^5.1.0",
232232
"liquidjs": "^10.27.0",
233233
"lodash": "^4.18.0",
234234
"lodash-es": "^4.18.0",

src/data-directory/lib/data-directory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import assert from 'assert'
22
import fs from 'fs'
33
import path from 'path'
44
import walk from 'walk-sync'
5-
import { load } from 'js-yaml'
5+
import { loadYaml } from '@/frame/lib/load-yaml'
66
import { isRegExp, setWith } from 'lodash-es'
77
import filenameToKey from './filename-to-key'
88
import matter from '@gr2m/gray-matter'
@@ -74,7 +74,7 @@ export default function dataDirectory(
7474
setWith(data, key, JSON.parse(processedContent), Object)
7575
break
7676
case '.yml':
77-
setWith(data, key, load(processedContent, { filename }), Object)
77+
setWith(data, key, loadYaml(processedContent, { filename }), Object)
7878
break
7979
case '.md':
8080
case '.markdown':

src/data-directory/lib/get-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs'
22
import path from 'path'
33

4-
import { load } from 'js-yaml'
4+
import { loadYaml } from '@/frame/lib/load-yaml'
55
import matter from '@gr2m/gray-matter'
66
import { merge, get } from 'lodash-es'
77

@@ -331,7 +331,7 @@ const getYamlContent = memoize(
331331
root = englishRoot
332332
}
333333
const fileContent = getFileContent(root, relPath, englishRoot)
334-
return load(fileContent, { filename: relPath })
334+
return loadYaml(fileContent, { filename: relPath })
335335
},
336336
)
337337

src/frame/lib/load-yaml.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { load, loadAll, type LoadOptions } from 'js-yaml'
2+
3+
// js-yaml v5's `load()` throws a `YAMLException` ("expected a document, but
4+
// the input is empty") when the input contains no YAML document — i.e. when
5+
// it is empty, whitespace-only, or comments-only. js-yaml v4 returned
6+
// `undefined` in those cases. This wrapper restores the v4 behavior so callers
7+
// that read arbitrary (possibly empty) YAML files keep working across the
8+
// major version bump.
9+
//
10+
// For any input that does contain a document, this behaves exactly like
11+
// `load()` — including throwing on genuinely malformed YAML.
12+
export function loadYaml(content: string, options?: LoadOptions): unknown {
13+
// `loadAll` invokes the iterator once per document and, unlike `load`, does
14+
// not throw when there are zero documents. Collect the documents so we can
15+
// reproduce `load`'s single-document semantics without parsing twice.
16+
const documents: unknown[] = []
17+
loadAll(content, (doc) => documents.push(doc), options)
18+
// No document (empty / whitespace-only / comments-only): v4 returned
19+
// `undefined`.
20+
if (documents.length === 0) return undefined
21+
// Multiple documents: defer to `load` so it throws the same "expected a
22+
// single document" error that v4 did.
23+
if (documents.length > 1) return load(content, options)
24+
return documents[0]
25+
}

src/frame/tests/load-yaml.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { describe, expect, test } from 'vitest'
2+
3+
import { loadYaml } from '@/frame/lib/load-yaml'
4+
5+
describe('loadYaml', () => {
6+
test('returns undefined for empty or document-less content', () => {
7+
expect(loadYaml('')).toBeUndefined()
8+
expect(loadYaml(' \n\t')).toBeUndefined()
9+
expect(loadYaml('# comment only\n# another comment')).toBeUndefined()
10+
})
11+
12+
test('throws on multiple YAML documents', () => {
13+
expect(() => loadYaml('a: 1\n---\nb: 2\n')).toThrow()
14+
})
15+
})

src/links/lib/update-internal-links.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from 'fs'
33
import { visit, Test } from 'unist-util-visit'
44
import { fromMarkdown } from 'mdast-util-from-markdown'
55
import { toMarkdown } from 'mdast-util-to-markdown'
6-
import { load } from 'js-yaml'
6+
import { loadYaml } from '@/frame/lib/load-yaml'
77
import { type Node, type Nodes, type Definition, type Link } from 'mdast'
88

99
import type { Context, Page } from '@/types'
@@ -101,7 +101,7 @@ async function updateFile(file: string, context: LinkContext, opts: typeof Optio
101101
// And since the Yaml file might contain arrays of internal linked
102102
// pathnames, we have to re-read it fully.
103103
if (file.endsWith('.yml')) {
104-
Object.assign(data, load(content))
104+
Object.assign(data, loadYaml(content))
105105
}
106106

107107
let newContent = content

src/workflows/generate-llms-txt.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import fs from 'fs'
1515

16-
import { load } from 'js-yaml'
16+
import { loadYaml } from '@/frame/lib/load-yaml'
1717

1818
import { loadPageMap } from '@/frame/lib/page-data'
1919
import { renderContent } from '@/content-render/index'
@@ -44,11 +44,11 @@ export const ROLLUP_URL =
4444
const BASE_URL = 'https://docs.github.com'
4545

4646
export function loadConfig(overridePath?: string): LlmsTxtConfig {
47-
const defaults = load(fs.readFileSync(DEFAULT_CONFIG_PATH, 'utf8')) as Partial<LlmsTxtConfig>
47+
const defaults = loadYaml(fs.readFileSync(DEFAULT_CONFIG_PATH, 'utf8')) as Partial<LlmsTxtConfig>
4848
if (!overridePath || overridePath === DEFAULT_CONFIG_PATH) {
4949
return defaults as LlmsTxtConfig
5050
}
51-
const overrides = load(fs.readFileSync(overridePath, 'utf8')) as Partial<LlmsTxtConfig> | null
51+
const overrides = loadYaml(fs.readFileSync(overridePath, 'utf8')) as Partial<LlmsTxtConfig> | null
5252
return { ...(defaults as LlmsTxtConfig), ...(overrides || {}) }
5353
}
5454

0 commit comments

Comments
 (0)