olova 2.0.59 → 2.0.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/olova.js CHANGED
@@ -190,7 +190,7 @@ function generateRouteTree(routes, notFoundPages, layouts, loadingPages, errorPa
190
190
  };
191
191
  const routeNames = [];
192
192
  const routeImports = routes.map((route) => {
193
- const relativePath = stripImportExtension("./" + path4.relative(srcDir, route.component).replace(/\\/g, "/"));
193
+ const relativePath = stripImportExtension("./app/" + path4.relative(srcDir, route.component).replace(/\\/g, "/"));
194
194
  const moduleName = getRouteName2(route.component, "RouteModule");
195
195
  const lazyName = getRouteName2(route.component, "Route");
196
196
  routeNames.push({ moduleName, lazyName, eager: true });
@@ -198,7 +198,7 @@ function generateRouteTree(routes, notFoundPages, layouts, loadingPages, errorPa
198
198
  }).join("\n");
199
199
  const notFoundNames = [];
200
200
  const notFoundImports = notFoundPages.map((nf) => {
201
- const relativePath = stripImportExtension("./" + path4.relative(srcDir, nf.filePath).replace(/\\/g, "/"));
201
+ const relativePath = stripImportExtension("./app/" + path4.relative(srcDir, nf.filePath).replace(/\\/g, "/"));
202
202
  if (nf.hasMetadata) {
203
203
  const moduleName = getRouteName2(nf.filePath, "NotFoundModule");
204
204
  notFoundNames.push(moduleName);
@@ -212,7 +212,7 @@ function generateRouteTree(routes, notFoundPages, layouts, loadingPages, errorPa
212
212
  }).join("\n");
213
213
  const layoutNames = [];
214
214
  const layoutImports = layouts.map((layout) => {
215
- const relativePath = stripImportExtension("./" + path4.relative(srcDir, layout.filePath).replace(/\\/g, "/"));
215
+ const relativePath = stripImportExtension("./app/" + path4.relative(srcDir, layout.filePath).replace(/\\/g, "/"));
216
216
  if (layout.hasMetadata) {
217
217
  const moduleName = getRouteName2(layout.filePath, "LayoutModule");
218
218
  layoutNames.push(moduleName);
@@ -226,7 +226,7 @@ function generateRouteTree(routes, notFoundPages, layouts, loadingPages, errorPa
226
226
  }).join("\n");
227
227
  const loadingNames = [];
228
228
  const loadingImports = loadingPages.map((lp) => {
229
- const relativePath = stripImportExtension("./" + path4.relative(srcDir, lp.filePath).replace(/\\/g, "/"));
229
+ const relativePath = stripImportExtension("./app/" + path4.relative(srcDir, lp.filePath).replace(/\\/g, "/"));
230
230
  const importName = getRouteName2(lp.filePath, "Loading");
231
231
  loadingNames.push(importName);
232
232
  if (lp.hasDefault) return `import ${importName} from '${relativePath}';`;
@@ -235,7 +235,7 @@ function generateRouteTree(routes, notFoundPages, layouts, loadingPages, errorPa
235
235
  }).join("\n");
236
236
  const errorNames = [];
237
237
  const errorImports = errorPages.map((ep) => {
238
- const relativePath = stripImportExtension("./" + path4.relative(srcDir, ep.filePath).replace(/\\/g, "/"));
238
+ const relativePath = stripImportExtension("./app/" + path4.relative(srcDir, ep.filePath).replace(/\\/g, "/"));
239
239
  const importName = getRouteName2(ep.filePath, "Error");
240
240
  errorNames.push(importName);
241
241
  if (ep.hasDefault) return `import ${importName} from '${relativePath}';`;
@@ -244,7 +244,7 @@ function generateRouteTree(routes, notFoundPages, layouts, loadingPages, errorPa
244
244
  }).join("\n");
245
245
  const middlewareNames = [];
246
246
  const middlewareImports = middlewares.map((mw) => {
247
- const relativePath = stripImportExtension("./" + path4.relative(srcDir, mw.filePath).replace(/\\/g, "/"));
247
+ const relativePath = stripImportExtension("./app/" + path4.relative(srcDir, mw.filePath).replace(/\\/g, "/"));
248
248
  const importName = getRouteName2(mw.filePath, "Middleware");
249
249
  middlewareNames.push(importName);
250
250
  if (mw.hasDefault) return `import ${importName} from '${relativePath}';`;
@@ -474,14 +474,12 @@ export type {
474
474
  `;
475
475
  }
476
476
  var RESERVED_NAMES = /* @__PURE__ */ new Set([
477
- "index",
477
+ "page",
478
478
  "layout",
479
479
  "loading",
480
480
  "error",
481
- "404",
481
+ "not-found",
482
482
  "middleware",
483
- "App",
484
- "main",
485
483
  "route.tree"
486
484
  ]);
487
485
  function scanDirectory(dir, rootDir, extensions, routes, notFoundPages, layouts, loadingPages, errorPages, middlewares, isRoot = false) {
@@ -523,15 +521,13 @@ function scanDirectory(dir, rootDir, extensions, routes, notFoundPages, layouts,
523
521
  path: isRoot ? "/" : routePath,
524
522
  filePath: fullPath
525
523
  });
526
- } else if (baseName === "404" && extensions.includes(ext)) {
524
+ } else if ((baseName === "not-found" || baseName === "404") && extensions.includes(ext)) {
527
525
  const relativeParts = path4.relative(rootDir, dir).split(path4.sep).filter(Boolean);
528
526
  const filteredParts = relativeParts.filter((p) => !isRouteGroup(p));
529
527
  const pathPrefix = isRoot ? "" : "/" + filteredParts.join("/");
530
528
  notFoundPages.push({ pathPrefix: pathPrefix || "", filePath: fullPath });
531
- } else if (isRoot && baseName === "App" && extensions.includes(ext)) {
532
- routes.push({ path: "/", filePath: fullPath, isDynamic: false, params: [] });
533
- } else if (!isRoot && baseName === "index" && extensions.includes(ext)) {
534
- const relativePath = path4.relative(rootDir, path4.dirname(fullPath));
529
+ } else if (baseName === "page" && extensions.includes(ext)) {
530
+ const relativePath = path4.relative(rootDir, dir);
535
531
  const { routePath, params } = pathToRoute(relativePath, path4.sep);
536
532
  routes.push({ path: routePath, filePath: fullPath, isDynamic: params.length > 0, params });
537
533
  } else if (!RESERVED_NAMES.has(baseName) && !baseName.endsWith(".d") && !baseName.startsWith("_") && extensions.includes(ext)) {
@@ -566,7 +562,7 @@ function scanRoutes(rootDir, extensions) {
566
562
 
567
563
  // src/plugin/index.ts
568
564
  function olovaRouter(options = {}) {
569
- const rootDir = options.rootDir || "src";
565
+ const rootDir = options.rootDir || "src/app";
570
566
  const extensions = options.extensions || [".tsx", ".ts", ".mdx"];
571
567
  const packageName = options.packageName || "olovastart";
572
568
  let config;
@@ -645,7 +641,7 @@ function olovaRouter(options = {}) {
645
641
  };
646
642
  });
647
643
  const content = generateRouteTree(routeConfigs, notFoundConfigs, layoutConfigs, loadingConfigs, errorConfigs, middlewareConfigs, absoluteRootDir, packageName);
648
- const treePath = path4.resolve(absoluteRootDir, "route.tree.ts");
644
+ const treePath = path4.resolve(config.root, "src", "route.tree.ts");
649
645
  const existing = fs3.existsSync(treePath) ? fs3.readFileSync(treePath, "utf-8") : "";
650
646
  if (existing !== content) {
651
647
  fs3.writeFileSync(treePath, content);
@@ -659,9 +655,9 @@ function olovaRouter(options = {}) {
659
655
  if (filename.includes("route.tree.ts")) return;
660
656
  const ext = path4.extname(filename);
661
657
  const isConfiguredExtension = extensions.includes(ext);
662
- const isIndexFile = filename.includes("index") && isConfiguredExtension;
663
- const isAppFile = filename.includes("App") && isConfiguredExtension;
658
+ const isPageFile = filename.includes("page") && isConfiguredExtension;
664
659
  const is404File = filename.includes("404") && isConfiguredExtension;
660
+ const isNotFoundFile = filename.includes("not-found") && isConfiguredExtension;
665
661
  const isLayoutFile = filename.includes("layout") && isConfiguredExtension;
666
662
  const isLoadingFile = filename.includes("loading") && isConfiguredExtension;
667
663
  const isErrorFile = filename.includes("error") && isConfiguredExtension;
@@ -669,8 +665,8 @@ function olovaRouter(options = {}) {
669
665
  const isDirectory = !filename.includes(".");
670
666
  const isDynamicSegment = filename.includes("[");
671
667
  const isRenameEvent = eventType === "rename";
672
- if (isIndexFile || isAppFile || is404File || isLayoutFile || isLoadingFile || isErrorFile || isMiddlewareFile || isDirectory || isDynamicSegment || isRenameEvent) {
673
- if (isIndexFile && filename) {
668
+ if (isPageFile || is404File || isNotFoundFile || isLayoutFile || isLoadingFile || isErrorFile || isMiddlewareFile || isDirectory || isDynamicSegment || isRenameEvent) {
669
+ if (isPageFile && filename) {
674
670
  const fullPath = path4.join(absoluteRootDir, filename);
675
671
  if (fs3.existsSync(fullPath)) {
676
672
  const stat = fs3.statSync(fullPath);