From 926ec2e2f97000deefb8471b3987501857a8bb4a Mon Sep 17 00:00:00 2001 From: rush Date: Thu, 11 Jul 2024 03:45:50 +0300 Subject: [PATCH] chore: add warn message for new plugin namings --- src/index.ts | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/index.ts b/src/index.ts index 59951f7..2e0c1ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,17 @@ import { buildRoutesMap } from './utils/build-route-maps' let server: ViteDevServer +const routesCode = (imports: string | undefined, routesObject: string) => ` +${imports} + +function moduleFactory(module) { + const { default: Component, clientLoader: loader, actionLoader: action, loader: _loader, action: _action, Component: _Component, ...rest } = module; + return { Component, loader, action, ...rest }; +} + +export const routes = ${routesObject} +` + export function invalidateVirtualModule(server: ViteDevServer): void { const { moduleGraph, ws } = server const module = moduleGraph.getModuleById('virtual:routes') @@ -60,17 +71,13 @@ export const unpluginFactory: UnpluginFactory = options => .replace(/SpreadEnd"/g, ')') // console.log(JSON.stringify(routesObject, null, 2)) - const routesCode = ` -${imports} - -function moduleFactory(module) { - const { default: Component, clientLoader: loader, actionLoader: action, loader: _loader, action: _action, Component: _Component, ...rest } = module; - return { Component, loader, action, ...rest }; -} + console.log(` + [Warn] You are using unplugin-remix-router v2. + you should export Component as default, loader as clientLoader and action as clientAction. + see example in https://github.com/ws-rush/unplugin-remix-router#readme + `) -export const routes = ${routesObject} -` - return routesCode + return routesCode(imports, routesObject) } }, vite: {