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", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "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", "preview": "vite preview",
"test": "vitest run", "test": "vitest run",
"test:watch": "vitest", "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/. */ /** Strip `/src/app` prefix from generouted Path types — views live under src/app/, not src/pages/. */
export function fixGeneroutedRouterPaths(routerFile = defaultRouterFile) { export function fixGeneroutedRouterPaths(routerFile = defaultRouterFile) {
const content = fs.readFileSync(routerFile, "utf8"); 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) { if (fixed !== content) {
fs.writeFileSync(routerFile, fixed); fs.writeFileSync(routerFile, fixed);

View file

@ -4,67 +4,67 @@
import { components, hooks, utils } from "@generouted/react-router/client"; import { components, hooks, utils } from "@generouted/react-router/client";
export type Path = export type Path =
| `///src/app` | `/`
| `///src/app/accounts` | `/accounts`
| `///src/app/accounts/edit/:id` | `/accounts/edit/:id`
| `///src/app/accounts/new` | `/accounts/new`
| `///src/app/assets` | `/assets`
| `///src/app/assets/edit/:id` | `/assets/edit/:id`
| `///src/app/assets/new` | `/assets/new`
| `///src/app/calendar` | `/calendar`
| `///src/app/calendar/edit/:id` | `/calendar/edit/:id`
| `///src/app/calendar/new` | `/calendar/new`
| `///src/app/contacts` | `/contacts`
| `///src/app/contacts/edit/:id` | `/contacts/edit/:id`
| `///src/app/contacts/new` | `/contacts/new`
| `///src/app/dashboard` | `/dashboard`
| `///src/app/employees` | `/employees`
| `///src/app/employees/edit/:id` | `/employees/edit/:id`
| `///src/app/employees/new` | `/employees/new`
| `///src/app/followups` | `/followups`
| `///src/app/followups/edit/:id` | `/followups/edit/:id`
| `///src/app/followups/new` | `/followups/new`
| `///src/app/locations` | `/locations`
| `///src/app/locations/edit/:id` | `/locations/edit/:id`
| `///src/app/locations/new` | `/locations/new`
| `///src/app/login` | `/login`
| `///src/app/pmschedules` | `/pmschedules`
| `///src/app/pmschedules/edit/:id` | `/pmschedules/edit/:id`
| `///src/app/pmschedules/new` | `/pmschedules/new`
| `///src/app/settings/dropdowns` | `/settings/dropdowns`
| `///src/app/settings/task-templates` | `/settings/task-templates`
| `///src/app/uplifts` | `/uplifts`
| `///src/app/v/:token` | `/v/:token`
| `///src/app/v/:token/dashboard` | `/v/:token/dashboard`
| `///src/app/v/:token/dispatch/:id` | `/v/:token/dispatch/:id`
| `///src/app/v/:token/pos` | `/v/:token/pos`
| `///src/app/vendor-pos` | `/vendor-pos`
| `///src/app/vendor-pos/:id` | `/vendor-pos/:id`
| `///src/app/vendors` | `/vendors`
| `///src/app/vendors/edit/:id` | `/vendors/edit/:id`
| `///src/app/vendors/new` | `/vendors/new`
| `///src/app/workorders` | `/workorders`
| `///src/app/workorders/:id` | `/workorders/:id`
| `///src/app/workorders/edit/:id` | `/workorders/edit/:id`
| `///src/app/workorders/new`; | `/workorders/new`;
export type Params = { export type Params = {
"///src/app/accounts/edit/:id": { id: string }; "/accounts/edit/:id": { id: string };
"///src/app/assets/edit/:id": { id: string }; "/assets/edit/:id": { id: string };
"///src/app/calendar/edit/:id": { id: string }; "/calendar/edit/:id": { id: string };
"///src/app/contacts/edit/:id": { id: string }; "/contacts/edit/:id": { id: string };
"///src/app/employees/edit/:id": { id: string }; "/employees/edit/:id": { id: string };
"///src/app/followups/edit/:id": { id: string }; "/followups/edit/:id": { id: string };
"///src/app/locations/edit/:id": { id: string }; "/locations/edit/:id": { id: string };
"///src/app/pmschedules/edit/:id": { id: string }; "/pmschedules/edit/:id": { id: string };
"///src/app/v/:token": { token: string }; "/v/:token": { token: string };
"///src/app/v/:token/dashboard": { token: string }; "/v/:token/dashboard": { token: string };
"///src/app/v/:token/dispatch/:id": { token: string; id: string }; "/v/:token/dispatch/:id": { token: string; id: string };
"///src/app/v/:token/pos": { token: string }; "/v/:token/pos": { token: string };
"///src/app/vendor-pos/:id": { id: string }; "/vendor-pos/:id": { id: string };
"///src/app/vendors/edit/:id": { id: string }; "/vendors/edit/:id": { id: string };
"///src/app/workorders/:id": { id: string }; "/workorders/:id": { id: string };
"///src/app/workorders/edit/:id": { id: string }; "/workorders/edit/:id": { id: string };
}; };
export type ModalPath = never; export type ModalPath = never;

View file

@ -16,5 +16,5 @@
"outDir": "./node_modules/.tmp/tsconfig.node", "outDir": "./node_modules/.tmp/tsconfig.node",
"types": ["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 tailwindcss from "@tailwindcss/vite";
import path from "node:path"; import path from "node:path";
import { defineConfig, loadEnv, transformWithEsbuild } from "vite"; 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 }) => { export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), ""); const env = loadEnv(mode, process.cwd(), "");