UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

47 lines (46 loc) 1.79 kB
import micromatch from "micromatch"; import path from "path"; import { globDir } from "./globDir.native.js"; import { isPathInsideDirectory, isRouteFilePath } from "./routeFileWatch.native.js"; function getRoutePaths(routerRoot, ignoredRouteFiles) { var routePaths = globDir(routerRoot).filter(function (routePath) { return !routePath.endsWith(".d.ts"); }); if (!(ignoredRouteFiles === null || ignoredRouteFiles === void 0 ? void 0 : ignoredRouteFiles.length)) return routePaths; return micromatch.not(routePaths, ignoredRouteFiles, { matchBase: true }); } function createRouteIndex(param) { var { routerRoot, ignoredRouteFiles } = param; var absoluteRouterRoot = path.resolve(routerRoot); var routePaths = new Set(getRoutePaths(absoluteRouterRoot, ignoredRouteFiles)); return { getPaths() { return [...routePaths].sort(); }, update(event, filePath) { if (event !== "add" && event !== "delete" && event !== "unlink") return false; if (!isPathInsideDirectory(filePath, absoluteRouterRoot)) return false; if (!isRouteFilePath(filePath)) return false; var relativePath = path.relative(absoluteRouterRoot, path.resolve(filePath)).replaceAll("\\", "/"); var routePath = `./${relativePath}`; if ((ignoredRouteFiles === null || ignoredRouteFiles === void 0 ? void 0 : ignoredRouteFiles.length) && micromatch.isMatch(routePath, ignoredRouteFiles, { matchBase: true })) { return false; } if (event === "add") { var size = routePaths.size; routePaths.add(routePath); return routePaths.size !== size; } return routePaths.delete(routePath); } }; } export { createRouteIndex, getRoutePaths }; //# sourceMappingURL=routeIndex.native.js.map