Skip to content

Commit a3106e0

Browse files
committed
feat: support subpaths of supported dependencies (e.g. node:fs/promises)
1 parent 33f3c08 commit a3106e0

File tree

2 files changed

+18
-1
lines changed
  • packages/cli/src/services/check-parser

2 files changed

+18
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
import {} from 'node:path'
22
import {} from 'node:url'
3+
import {} from 'node:fs/promises'
34
import {} from 'crypto'
5+
import {} from 'timers/promises'

packages/cli/src/services/check-parser/parser.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class Parser {
100100
this.checkUnsupportedModules = options.checkUnsupportedModules ?? true
101101
}
102102

103-
supportsModule (importPath: string) {
103+
supportsModule (importPath: string): boolean {
104104
if (this.supportedModules.has(importPath)) {
105105
return true
106106
}
@@ -109,6 +109,21 @@ export class Parser {
109109
return true
110110
}
111111

112+
// Check namespaced modules and module subpaths.
113+
if (importPath.indexOf('/') !== -1) {
114+
if (importPath.startsWith('@')) {
115+
const [namespace, moduleName] = importPath.split('/', 3)
116+
if (this.supportedModules.has(namespace + '/' + moduleName)) {
117+
return true
118+
}
119+
} else {
120+
// Recurse to cover values with and without node: prefix.
121+
// This will not endlessly recurse because we remove the slash.
122+
const [moduleName] = importPath.split('/', 2)
123+
return this.supportsModule(moduleName)
124+
}
125+
}
126+
112127
return false
113128
}
114129

0 commit comments

Comments
 (0)