Skip to content

Commit

Permalink
RSC: vite auto-loader: Spell out 'path' and other chores (redwoodjs#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed May 21, 2024
1 parent d611d7c commit ddfea30
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/vite/src/plugins/vite-plugin-rsc-routes-auto-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,29 @@ export function rscRoutesAutoLoader(): Plugin {
// We have to filter out any pages which the user has already explicitly imported
// in the routes file otherwise there would be conflicts.
const importedNames = new Set<string>()

traverse(ast, {
ImportDeclaration(p) {
const importPath = p.node.source.value
ImportDeclaration(path) {
const importPath = path.node.source.value

if (importPath === null) {
return
}

const userImportRelativePath = getPathRelativeToSrc(
importStatementPath(p.node.source?.value),
importStatementPath(importPath),
)

const defaultSpecifier = p.node.specifiers.filter((specifiers) =>
t.isImportDefaultSpecifier(specifiers),
const defaultSpecifier = path.node.specifiers.filter((specifier) =>
t.isImportDefaultSpecifier(specifier),
)[0]

if (userImportRelativePath && defaultSpecifier) {
importedNames.add(defaultSpecifier.local.name)
}
},
})

const nonImportedPages = pages.filter(
(page) => !importedNames.has(page.importName),
)
Expand Down

0 comments on commit ddfea30

Please sign in to comment.