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/entry-worker.cjs.map +1 -1
- package/dist/entry-worker.js.map +1 -1
- package/dist/main.cjs +5 -30
- package/dist/main.cjs.map +1 -1
- package/dist/main.js +4 -29
- package/dist/main.js.map +1 -1
- package/dist/olova.cjs +18 -22
- package/dist/olova.cjs.map +1 -1
- package/dist/olova.js +17 -21
- package/dist/olova.js.map +1 -1
- package/main.tsx +76 -0
- package/olova.ts +619 -0
- package/package.json +18 -34
- package/src/entry-server.tsx +165 -0
- package/src/entry-worker.tsx +201 -0
- package/src/generator/index.ts +409 -0
- package/src/hydration/flight.ts +320 -0
- package/src/hydration/index.ts +12 -0
- package/src/hydration/types.ts +225 -0
- package/src/logger.ts +182 -0
- package/src/main.tsx +24 -0
- package/src/performance.ts +488 -0
- package/src/plugin/index.ts +204 -0
- package/src/router/ErrorBoundary.tsx +145 -0
- package/src/router/Link.tsx +117 -0
- package/src/router/OlovaRouter.tsx +354 -0
- package/src/router/Outlet.tsx +8 -0
- package/src/router/context.ts +117 -0
- package/src/router/index.ts +29 -0
- package/src/router/matching.ts +63 -0
- package/src/router/router.tsx +23 -0
- package/src/router/search-params.ts +29 -0
- package/src/scanner/index.ts +114 -0
- package/src/types/index.ts +190 -0
- package/src/utils/export.ts +85 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/naming.ts +54 -0
- package/src/utils/path.ts +45 -0
- package/tsup.config.ts +35 -0
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
|
-
"
|
|
477
|
+
"page",
|
|
478
478
|
"layout",
|
|
479
479
|
"loading",
|
|
480
480
|
"error",
|
|
481
|
-
"
|
|
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 (
|
|
532
|
-
|
|
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(
|
|
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
|
|
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 (
|
|
673
|
-
if (
|
|
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);
|