From 96059ee53f9e029be65897bf814b855caa20e2f6 Mon Sep 17 00:00:00 2001 From: Arthur Bassi Date: Mon, 15 Jun 2026 10:13:42 -0300 Subject: [PATCH] fix(build): use mjs router script for Node 20 CI compatibility --- package.json | 2 +- scripts/fix-router-paths.d.mts | 3 + ...x-router-paths.ts => fix-router-paths.mjs} | 6 +- src/router.ts | 118 +++++++++--------- tsconfig.node.json | 2 +- vite.config.ts | 2 +- 6 files changed, 70 insertions(+), 63 deletions(-) create mode 100644 scripts/fix-router-paths.d.mts rename scripts/{fix-router-paths.ts => fix-router-paths.mjs} (80%) diff --git a/package.json b/package.json index 65e5d096..272ebcde 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "vite", - "build": "node --experimental-strip-types scripts/fix-router-paths.ts && tsc -b && vite build", + "build": "node scripts/fix-router-paths.mjs && tsc -b && vite build", "preview": "vite preview", "test": "vitest run", "test:watch": "vitest", diff --git a/scripts/fix-router-paths.d.mts b/scripts/fix-router-paths.d.mts new file mode 100644 index 00000000..b2a88c1b --- /dev/null +++ b/scripts/fix-router-paths.d.mts @@ -0,0 +1,3 @@ +export const defaultRouterFile: string; + +export function fixGeneroutedRouterPaths(routerFile?: string): void; diff --git a/scripts/fix-router-paths.ts b/scripts/fix-router-paths.mjs similarity index 80% rename from scripts/fix-router-paths.ts rename to scripts/fix-router-paths.mjs index 92c47598..c9783610 100644 --- a/scripts/fix-router-paths.ts +++ b/scripts/fix-router-paths.mjs @@ -8,7 +8,11 @@ export const defaultRouterFile = path.resolve(scriptDir, "../src/router.ts"); /** Strip `/src/app` prefix from generouted Path types — views live under src/app/, not src/pages/. */ export function fixGeneroutedRouterPaths(routerFile = defaultRouterFile) { const content = fs.readFileSync(routerFile, "utf8"); - const fixed = content.replace(/`\/+src\/app/g, "`").replace(/"\/+src\/app/g, '"/'); + const fixed = content + .replace(/`\/+src\/app\//g, "`/") + .replace(/`\/+src\/app`/g, "`/`") + .replace(/"\/+src\/app\//g, '"/') + .replace(/"\/+src\/app"/g, '"/"'); if (fixed !== content) { fs.writeFileSync(routerFile, fixed); diff --git a/src/router.ts b/src/router.ts index 60236af4..ac6af18e 100644 --- a/src/router.ts +++ b/src/router.ts @@ -4,67 +4,67 @@ import { components, hooks, utils } from "@generouted/react-router/client"; export type Path = - | `///src/app` - | `///src/app/accounts` - | `///src/app/accounts/edit/:id` - | `///src/app/accounts/new` - | `///src/app/assets` - | `///src/app/assets/edit/:id` - | `///src/app/assets/new` - | `///src/app/calendar` - | `///src/app/calendar/edit/:id` - | `///src/app/calendar/new` - | `///src/app/contacts` - | `///src/app/contacts/edit/:id` - | `///src/app/contacts/new` - | `///src/app/dashboard` - | `///src/app/employees` - | `///src/app/employees/edit/:id` - | `///src/app/employees/new` - | `///src/app/followups` - | `///src/app/followups/edit/:id` - | `///src/app/followups/new` - | `///src/app/locations` - | `///src/app/locations/edit/:id` - | `///src/app/locations/new` - | `///src/app/login` - | `///src/app/pmschedules` - | `///src/app/pmschedules/edit/:id` - | `///src/app/pmschedules/new` - | `///src/app/settings/dropdowns` - | `///src/app/settings/task-templates` - | `///src/app/uplifts` - | `///src/app/v/:token` - | `///src/app/v/:token/dashboard` - | `///src/app/v/:token/dispatch/:id` - | `///src/app/v/:token/pos` - | `///src/app/vendor-pos` - | `///src/app/vendor-pos/:id` - | `///src/app/vendors` - | `///src/app/vendors/edit/:id` - | `///src/app/vendors/new` - | `///src/app/workorders` - | `///src/app/workorders/:id` - | `///src/app/workorders/edit/:id` - | `///src/app/workorders/new`; + | `/` + | `/accounts` + | `/accounts/edit/:id` + | `/accounts/new` + | `/assets` + | `/assets/edit/:id` + | `/assets/new` + | `/calendar` + | `/calendar/edit/:id` + | `/calendar/new` + | `/contacts` + | `/contacts/edit/:id` + | `/contacts/new` + | `/dashboard` + | `/employees` + | `/employees/edit/:id` + | `/employees/new` + | `/followups` + | `/followups/edit/:id` + | `/followups/new` + | `/locations` + | `/locations/edit/:id` + | `/locations/new` + | `/login` + | `/pmschedules` + | `/pmschedules/edit/:id` + | `/pmschedules/new` + | `/settings/dropdowns` + | `/settings/task-templates` + | `/uplifts` + | `/v/:token` + | `/v/:token/dashboard` + | `/v/:token/dispatch/:id` + | `/v/:token/pos` + | `/vendor-pos` + | `/vendor-pos/:id` + | `/vendors` + | `/vendors/edit/:id` + | `/vendors/new` + | `/workorders` + | `/workorders/:id` + | `/workorders/edit/:id` + | `/workorders/new`; export type Params = { - "///src/app/accounts/edit/:id": { id: string }; - "///src/app/assets/edit/:id": { id: string }; - "///src/app/calendar/edit/:id": { id: string }; - "///src/app/contacts/edit/:id": { id: string }; - "///src/app/employees/edit/:id": { id: string }; - "///src/app/followups/edit/:id": { id: string }; - "///src/app/locations/edit/:id": { id: string }; - "///src/app/pmschedules/edit/:id": { id: string }; - "///src/app/v/:token": { token: string }; - "///src/app/v/:token/dashboard": { token: string }; - "///src/app/v/:token/dispatch/:id": { token: string; id: string }; - "///src/app/v/:token/pos": { token: string }; - "///src/app/vendor-pos/:id": { id: string }; - "///src/app/vendors/edit/:id": { id: string }; - "///src/app/workorders/:id": { id: string }; - "///src/app/workorders/edit/:id": { id: string }; + "/accounts/edit/:id": { id: string }; + "/assets/edit/:id": { id: string }; + "/calendar/edit/:id": { id: string }; + "/contacts/edit/:id": { id: string }; + "/employees/edit/:id": { id: string }; + "/followups/edit/:id": { id: string }; + "/locations/edit/:id": { id: string }; + "/pmschedules/edit/:id": { id: string }; + "/v/:token": { token: string }; + "/v/:token/dashboard": { token: string }; + "/v/:token/dispatch/:id": { token: string; id: string }; + "/v/:token/pos": { token: string }; + "/vendor-pos/:id": { id: string }; + "/vendors/edit/:id": { id: string }; + "/workorders/:id": { id: string }; + "/workorders/edit/:id": { id: string }; }; export type ModalPath = never; diff --git a/tsconfig.node.json b/tsconfig.node.json index 11907bfb..a02b1983 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -16,5 +16,5 @@ "outDir": "./node_modules/.tmp/tsconfig.node", "types": ["node"] }, - "include": ["vite.config.ts", "vitest.config.ts", "scripts/fix-router-paths.ts"] + "include": ["vite.config.ts", "vitest.config.ts"] } diff --git a/vite.config.ts b/vite.config.ts index 4b833d1b..af49ba81 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,7 +3,7 @@ import react from "@vitejs/plugin-react"; import tailwindcss from "@tailwindcss/vite"; import path from "node:path"; import { defineConfig, loadEnv, transformWithEsbuild } from "vite"; -import { defaultRouterFile, fixGeneroutedRouterPaths } from "./scripts/fix-router-paths.ts"; +import { defaultRouterFile, fixGeneroutedRouterPaths } from "./scripts/fix-router-paths.mjs"; export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), "");