This commit is contained in:
@@ -28,12 +28,23 @@ function getRelativeImports(content) {
|
||||
const paths = []
|
||||
const fromRegex = /from\s+['"]([^'"]+)['"]/g
|
||||
const requireRegex = /require\s*\(\s*['"]([^'"]+)['"]\s*\)/g
|
||||
for (const re of [fromRegex, requireRegex]) {
|
||||
let m
|
||||
while ((m = re.exec(content)) !== null) {
|
||||
const p = m[1]
|
||||
if (p.startsWith('.')) paths.push(p)
|
||||
const extractMatches = (regex, text) => {
|
||||
const matches = []
|
||||
const execRegex = (r) => {
|
||||
const match = r.exec(text)
|
||||
if (match) {
|
||||
matches.push(match[1])
|
||||
return execRegex(r)
|
||||
}
|
||||
return matches
|
||||
}
|
||||
return execRegex(regex)
|
||||
}
|
||||
for (const re of [fromRegex, requireRegex]) {
|
||||
const matches = extractMatches(re, content)
|
||||
matches.forEach((p) => {
|
||||
if (p.startsWith('.')) paths.push(p)
|
||||
})
|
||||
}
|
||||
return paths
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user