fix(build): use mjs router script for Node 20 CI compatibility

This commit is contained in:
Arthur Bassi 2026-06-15 10:13:42 -03:00
parent 3b39b858c1
commit 96059ee53f
6 changed files with 70 additions and 63 deletions

View file

@ -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",

View file

@ -0,0 +1,3 @@
export const defaultRouterFile: string;
export function fixGeneroutedRouterPaths(routerFile?: string): void;

View file

@ -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);

View file

@ -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;

View file

@ -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"]
}

View file

@ -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(), "");