next-rsc-error-handler
Advanced tools
Comparing version
{ | ||
"name": "next-rsc-error-handler", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Webpack plugin that allow to handle RSC errors on the server side", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -29,2 +29,4 @@ import parser from "@babel/parser"; | ||
const options = this.getOptions(); | ||
const noExtRelativePath = dropExtension(relativePath); | ||
@@ -34,6 +36,2 @@ const isTrulyClientComponent = isClientComponent(source); | ||
if (isTrulyClientComponent || clientComponents.has(noExtRelativePath)) { | ||
if (!isTrulyClientComponent && serverComponents.has(noExtRelativePath)) { | ||
throw new Error(`${relativePath} is used on both client and server`); | ||
} | ||
const ast = parser.parse(source, { | ||
@@ -44,2 +42,4 @@ sourceType: "module", | ||
let hasComponents = false; | ||
traverse.default(ast, { | ||
@@ -49,9 +49,28 @@ ImportDeclaration(p) { | ||
}, | ||
// TODO add FunctionExpression | ||
FunctionDeclaration(p) { | ||
const functionName = p.node.id?.name ?? ""; | ||
if (options.componentName.test(functionName)) { | ||
hasComponents = true; | ||
} | ||
}, | ||
ArrowFunctionExpression(p) { | ||
const functionName = getArrowFunctionName(p); | ||
if (options.componentName.test(functionName)) { | ||
hasComponents = true; | ||
} | ||
}, | ||
}); | ||
if ( | ||
hasComponents && | ||
!isTrulyClientComponent && | ||
serverComponents.has(noExtRelativePath) | ||
) { | ||
throw new Error(`${relativePath} is used on both client and server`); | ||
} | ||
return source; | ||
} | ||
const options = this.getOptions(); | ||
const ast = parser.parse(source, { | ||
@@ -58,0 +77,0 @@ sourceType: "module", |
10272
5.07%284
6.77%