Skip to content

Commit 0f74b0d

Browse files
committed
fix: OPTIONS_FILE could be unavailable
1 parent 87b2347 commit 0f74b0d

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

packages/doom/src/remark-lint/check-dead-links.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'node:fs/promises'
2+
import path from 'node:path'
23

34
import {
45
PluginDriver,
@@ -21,8 +22,16 @@ export const checkDeadLinks = lintRule<Root>(
2122
'doom-lint:check-dead-links',
2223
async (tree, vfile) => {
2324
if (!config || !configFilePath) {
24-
const { root, globalOptions } = JSON.parse(
25-
await fs.readFile(OPTIONS_FILE, 'utf8'),
25+
let optionsText: string | undefined
26+
27+
try {
28+
optionsText = await fs.readFile(OPTIONS_FILE, 'utf8')
29+
} catch {
30+
//
31+
}
32+
33+
const { root, globalOptions } = (
34+
optionsText ? JSON.parse(optionsText) : {}
2635
) as {
2736
root?: string
2837
globalOptions: GlobalCliOptions
@@ -31,6 +40,13 @@ export const checkDeadLinks = lintRule<Root>(
3140
;({ config, configFilePath } = await loadConfig(root, globalOptions))
3241
}
3342

43+
const relativePath = path.relative(config.root!, vfile.path)
44+
45+
// Ignore files outside the root directory
46+
if (relativePath.startsWith('..')) {
47+
return
48+
}
49+
3450
let routeService = RouteService.getInstance()
3551

3652
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition

0 commit comments

Comments
 (0)