olova 2.0.57 → 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.cjs +17 -21
- package/dist/olova.cjs.map +1 -1
- package/dist/olova.js +17 -21
- package/dist/olova.js.map +1 -1
- package/package.json +1 -1
- package/src/generator/index.ts +6 -6
- package/src/plugin/index.ts +6 -6
- package/src/scanner/index.ts +5 -7
- package/src/types/index.ts +0 -1
package/package.json
CHANGED
package/src/generator/index.ts
CHANGED
|
@@ -86,7 +86,7 @@ export function generateRouteTree(
|
|
|
86
86
|
const routeNames: { moduleName: string; lazyName: string; eager: boolean }[] = [];
|
|
87
87
|
|
|
88
88
|
const routeImports = routes.map((route) => {
|
|
89
|
-
const relativePath = stripImportExtension('./' + path.relative(srcDir, route.component).replace(/\\/g, '/'));
|
|
89
|
+
const relativePath = stripImportExtension('./app/' + path.relative(srcDir, route.component).replace(/\\/g, '/'));
|
|
90
90
|
// ALWAYS eager import for SSG - lazy() doesn't work with renderToString
|
|
91
91
|
const moduleName = getRouteName(route.component, 'RouteModule');
|
|
92
92
|
const lazyName = getRouteName(route.component, 'Route');
|
|
@@ -96,7 +96,7 @@ export function generateRouteTree(
|
|
|
96
96
|
|
|
97
97
|
const notFoundNames: string[] = [];
|
|
98
98
|
const notFoundImports = notFoundPages.map((nf) => {
|
|
99
|
-
const relativePath = stripImportExtension('./' + path.relative(srcDir, nf.filePath).replace(/\\/g, '/'));
|
|
99
|
+
const relativePath = stripImportExtension('./app/' + path.relative(srcDir, nf.filePath).replace(/\\/g, '/'));
|
|
100
100
|
if (nf.hasMetadata) {
|
|
101
101
|
const moduleName = getRouteName(nf.filePath, 'NotFoundModule');
|
|
102
102
|
notFoundNames.push(moduleName);
|
|
@@ -111,7 +111,7 @@ export function generateRouteTree(
|
|
|
111
111
|
|
|
112
112
|
const layoutNames: string[] = [];
|
|
113
113
|
const layoutImports = layouts.map((layout) => {
|
|
114
|
-
const relativePath = stripImportExtension('./' + path.relative(srcDir, layout.filePath).replace(/\\/g, '/'));
|
|
114
|
+
const relativePath = stripImportExtension('./app/' + path.relative(srcDir, layout.filePath).replace(/\\/g, '/'));
|
|
115
115
|
if (layout.hasMetadata) {
|
|
116
116
|
const moduleName = getRouteName(layout.filePath, 'LayoutModule');
|
|
117
117
|
layoutNames.push(moduleName);
|
|
@@ -126,7 +126,7 @@ export function generateRouteTree(
|
|
|
126
126
|
|
|
127
127
|
const loadingNames: string[] = [];
|
|
128
128
|
const loadingImports = loadingPages.map((lp) => {
|
|
129
|
-
const relativePath = stripImportExtension('./' + path.relative(srcDir, lp.filePath).replace(/\\/g, '/'));
|
|
129
|
+
const relativePath = stripImportExtension('./app/' + path.relative(srcDir, lp.filePath).replace(/\\/g, '/'));
|
|
130
130
|
const importName = getRouteName(lp.filePath, 'Loading');
|
|
131
131
|
loadingNames.push(importName);
|
|
132
132
|
if (lp.hasDefault) return `import ${importName} from '${relativePath}';`;
|
|
@@ -136,7 +136,7 @@ export function generateRouteTree(
|
|
|
136
136
|
|
|
137
137
|
const errorNames: string[] = [];
|
|
138
138
|
const errorImports = errorPages.map((ep) => {
|
|
139
|
-
const relativePath = stripImportExtension('./' + path.relative(srcDir, ep.filePath).replace(/\\/g, '/'));
|
|
139
|
+
const relativePath = stripImportExtension('./app/' + path.relative(srcDir, ep.filePath).replace(/\\/g, '/'));
|
|
140
140
|
const importName = getRouteName(ep.filePath, 'Error');
|
|
141
141
|
errorNames.push(importName);
|
|
142
142
|
if (ep.hasDefault) return `import ${importName} from '${relativePath}';`;
|
|
@@ -146,7 +146,7 @@ export function generateRouteTree(
|
|
|
146
146
|
|
|
147
147
|
const middlewareNames: string[] = [];
|
|
148
148
|
const middlewareImports = middlewares.map((mw) => {
|
|
149
|
-
const relativePath = stripImportExtension('./' + path.relative(srcDir, mw.filePath).replace(/\\/g, '/'));
|
|
149
|
+
const relativePath = stripImportExtension('./app/' + path.relative(srcDir, mw.filePath).replace(/\\/g, '/'));
|
|
150
150
|
const importName = getRouteName(mw.filePath, 'Middleware');
|
|
151
151
|
middlewareNames.push(importName);
|
|
152
152
|
if (mw.hasDefault) return `import ${importName} from '${relativePath}';`;
|
package/src/plugin/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { ErrorWithExport, LayoutWithExport, LoadingWithExport, MiddlewareWi
|
|
|
8
8
|
import { detectExportType, getRouteName } from '../utils';
|
|
9
9
|
|
|
10
10
|
export function olovaRouter(options: OlovaRouterOptions = {}): PluginOption[] {
|
|
11
|
-
const rootDir = options.rootDir || 'src';
|
|
11
|
+
const rootDir = options.rootDir || 'src/app';
|
|
12
12
|
const extensions = options.extensions || ['.tsx', '.ts', '.mdx'];
|
|
13
13
|
const packageName = options.packageName || 'olovastart';
|
|
14
14
|
|
|
@@ -98,7 +98,7 @@ export function olovaRouter(options: OlovaRouterOptions = {}): PluginOption[] {
|
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
const content = generateRouteTree(routeConfigs, notFoundConfigs, layoutConfigs, loadingConfigs, errorConfigs, middlewareConfigs, absoluteRootDir, packageName);
|
|
101
|
-
const treePath = path.resolve(
|
|
101
|
+
const treePath = path.resolve(config.root, 'src', 'route.tree.ts');
|
|
102
102
|
|
|
103
103
|
const existing = fs.existsSync(treePath) ? fs.readFileSync(treePath, 'utf-8') : '';
|
|
104
104
|
if (existing !== content) {
|
|
@@ -117,9 +117,9 @@ export function olovaRouter(options: OlovaRouterOptions = {}): PluginOption[] {
|
|
|
117
117
|
const ext = path.extname(filename);
|
|
118
118
|
const isConfiguredExtension = extensions.includes(ext);
|
|
119
119
|
|
|
120
|
-
const
|
|
121
|
-
const isAppFile = (filename.includes('App') && isConfiguredExtension);
|
|
120
|
+
const isPageFile = (filename.includes('page') && isConfiguredExtension);
|
|
122
121
|
const is404File = (filename.includes('404') && isConfiguredExtension);
|
|
122
|
+
const isNotFoundFile = (filename.includes('not-found') && isConfiguredExtension);
|
|
123
123
|
const isLayoutFile = (filename.includes('layout') && isConfiguredExtension);
|
|
124
124
|
const isLoadingFile = (filename.includes('loading') && isConfiguredExtension);
|
|
125
125
|
const isErrorFile = (filename.includes('error') && isConfiguredExtension);
|
|
@@ -128,8 +128,8 @@ export function olovaRouter(options: OlovaRouterOptions = {}): PluginOption[] {
|
|
|
128
128
|
const isDynamicSegment = filename.includes('[');
|
|
129
129
|
const isRenameEvent = eventType === 'rename';
|
|
130
130
|
|
|
131
|
-
if (
|
|
132
|
-
if (
|
|
131
|
+
if (isPageFile || is404File || isNotFoundFile || isLayoutFile || isLoadingFile || isErrorFile || isMiddlewareFile || isDirectory || isDynamicSegment || isRenameEvent) {
|
|
132
|
+
if (isPageFile && filename) {
|
|
133
133
|
const fullPath = path.join(absoluteRootDir, filename);
|
|
134
134
|
if (fs.existsSync(fullPath)) {
|
|
135
135
|
const stat = fs.statSync(fullPath);
|
package/src/scanner/index.ts
CHANGED
|
@@ -4,8 +4,8 @@ import type { ErrorEntry, LayoutEntry, LoadingEntry, MiddlewareEntry, NotFoundEn
|
|
|
4
4
|
import { isRouteGroup, pathToRoute } from '../utils';
|
|
5
5
|
|
|
6
6
|
const RESERVED_NAMES = new Set([
|
|
7
|
-
'
|
|
8
|
-
'
|
|
7
|
+
'page', 'layout', 'loading', 'error', 'not-found', 'middleware',
|
|
8
|
+
'route.tree',
|
|
9
9
|
]);
|
|
10
10
|
|
|
11
11
|
function scanDirectory(
|
|
@@ -66,15 +66,13 @@ function scanDirectory(
|
|
|
66
66
|
filePath: fullPath
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
-
else if (baseName === '404' && extensions.includes(ext)) {
|
|
69
|
+
else if ((baseName === 'not-found' || baseName === '404') && extensions.includes(ext)) {
|
|
70
70
|
const relativeParts = path.relative(rootDir, dir).split(path.sep).filter(Boolean);
|
|
71
71
|
const filteredParts = relativeParts.filter(p => !isRouteGroup(p));
|
|
72
72
|
const pathPrefix = isRoot ? '' : '/' + filteredParts.join('/');
|
|
73
73
|
notFoundPages.push({ pathPrefix: pathPrefix || '', filePath: fullPath });
|
|
74
|
-
} else if (
|
|
75
|
-
|
|
76
|
-
} else if (!isRoot && baseName === 'index' && extensions.includes(ext)) {
|
|
77
|
-
const relativePath = path.relative(rootDir, path.dirname(fullPath));
|
|
74
|
+
} else if (baseName === 'page' && extensions.includes(ext)) {
|
|
75
|
+
const relativePath = path.relative(rootDir, dir);
|
|
78
76
|
const { routePath, params } = pathToRoute(relativePath, path.sep);
|
|
79
77
|
routes.push({ path: routePath, filePath: fullPath, isDynamic: params.length > 0, params });
|
|
80
78
|
} else if (
|