Skip to content

Commit a6ca5da

Browse files
fix: don't error when failing to load "ts-declaration-location"
1 parent 36c3fbf commit a6ca5da

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/rules/no-sync.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44
*/
55
"use strict"
66

7-
const typeMatchesSpecifier =
8-
/** @type {import('ts-declaration-location').default} */ (
9-
/** @type {unknown} */ (require("ts-declaration-location"))
10-
)
7+
let typeMatchesSpecifier =
8+
/** @type {import('ts-declaration-location').default | undefined} */
9+
(undefined)
10+
11+
try {
12+
typeMatchesSpecifier =
13+
/** @type {import('ts-declaration-location').default} */ (
14+
/** @type {unknown} */ (require("ts-declaration-location"))
15+
)
16+
17+
// eslint-disable-next-line no-empty -- Deliberately left empty.
18+
} catch {}
1119
const getTypeOfNode = require("../util/get-type-of-node")
1220
const getParserServices = require("../util/get-parser-services")
1321
const getFullTypeName = require("../util/get-full-type-name")
@@ -137,7 +145,8 @@ module.exports = {
137145

138146
if (
139147
parserServices === null ||
140-
parserServices.program === null
148+
parserServices.program === null ||
149+
typeMatchesSpecifier === undefined
141150
) {
142151
throw new Error(
143152
'TypeScript parser services not available. Rule "n/no-sync" is configured to use "ignores" option with a non-string value. This requires TypeScript parser services to be available.'

0 commit comments

Comments
 (0)