From 24d4f1439edd4d851de1e883e43373decab1e2b9 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 25 Apr 2024 19:35:23 +0200 Subject: [PATCH] fix(react): improve option for react-refresh, aware Remix and Next.js (#461) Co-authored-by: Stephen Zhou --- src/configs/react.ts | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/configs/react.ts b/src/configs/react.ts index 55d5c3f829..9091ceaea7 100644 --- a/src/configs/react.ts +++ b/src/configs/react.ts @@ -7,6 +7,15 @@ import { GLOB_TS, GLOB_TSX } from '../globs' const ReactRefreshAllowConstantExportPackages = [ 'vite', ] +const RemixPackages = [ + '@remix-run/node', + '@remix-run/react', + '@remix-run/serve', + '@remix-run/dev', +] +const NextJsPackages = [ + 'next', +] export async function react( options: OptionsTypeScriptWithTypes & OptionsOverrides & OptionsFiles = {}, @@ -39,9 +48,9 @@ export async function react( interopDefault(import('@typescript-eslint/parser')), ] as const) - const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some( - i => isPackageExists(i), - ) + const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(i => isPackageExists(i)) + const isUsingRemix = RemixPackages.some(i => isPackageExists(i)) + const isUsingNext = NextJsPackages.some(i => isPackageExists(i)) const plugins = pluginReact.configs.all.plugins @@ -91,7 +100,30 @@ export async function react( // react refresh 'react-refresh/only-export-components': [ 'warn', - { allowConstantExport: isAllowConstantExport }, + { + allowConstantExport: isAllowConstantExport, + allowExportNames: [ + ...(isUsingNext + ? [ + 'config', + 'generateStaticParams', + 'metadata', + 'generateMetadata', + 'viewport', + 'generateViewport', + ] + : []), + ...(isUsingRemix + ? [ + 'meta', + 'links', + 'headers', + 'loader', + 'action', + ] + : []), + ], + }, ], // recommended rules from @eslint-react