Skip to content

Commit

Permalink
feat: support subpaths of supported dependencies (e.g. `node:fs/promi…
Browse files Browse the repository at this point in the history
…ses`)
  • Loading branch information
sorccu committed Jan 19, 2025
1 parent f2b5c4d commit 1a6865e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {} from 'node:path'
import {} from 'node:url'
import {} from 'node:fs/promises'
import {} from 'crypto'
import {} from 'timers/promises'
17 changes: 16 additions & 1 deletion packages/cli/src/services/check-parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class Parser {
this.checkUnsupportedModules = options.checkUnsupportedModules ?? true
}

supportsModule (importPath: string) {
supportsModule (importPath: string): boolean {
if (this.supportedModules.has(importPath)) {
return true
}
Expand All @@ -109,6 +109,21 @@ export class Parser {
return true
}

// Check namespaced modules and module subpaths.
if (importPath.indexOf('/') !== -1) {
if (importPath.startsWith('@')) {
const [namespace, moduleName] = importPath.split('/', 3)
if (this.supportedModules.has(namespace + '/' + moduleName)) {
return true
}
} else {
// Recurse to cover values with and without node: prefix.
// This will not endlessly recurse because we remove the slash.
const [moduleName] = importPath.split('/', 2)
return this.supportsModule(moduleName)
}
}

return false
}

Expand Down

0 comments on commit 1a6865e

Please sign in to comment.