Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support subpaths of supported dependencies (e.g. node:fs/promises) [sc-22943] #1010

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading