@gracile/engine 0.7.1 → 0.8.0-next.1
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/ambient.d.ts +16 -1
- package/dist/dev/{dev.d.ts → development.d.ts} +2 -2
- package/dist/dev/development.d.ts.map +1 -0
- package/dist/dev/{dev.js → development.js} +6 -6
- package/dist/dev/route-typings.d.ts.map +1 -1
- package/dist/dev/route-typings.js +3 -8
- package/dist/errors/create-vite-better-error.d.ts.map +1 -1
- package/dist/errors/create-vite-better-error.js +1 -3
- package/dist/errors/errors-data.d.ts +2 -2
- package/dist/errors/errors-data.d.ts.map +1 -1
- package/dist/errors/errors.d.ts +3 -3
- package/dist/errors/errors.d.ts.map +1 -1
- package/dist/errors/errors.js +7 -8
- package/dist/errors/pages.d.ts +2 -2
- package/dist/errors/pages.d.ts.map +1 -1
- package/dist/errors/pages.js +4 -4
- package/dist/plugin.d.ts +1 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +17 -16
- package/dist/render/route-template.d.ts.map +1 -1
- package/dist/render/route-template.js +54 -54
- package/dist/render/utils.d.ts +1 -1
- package/dist/render/utils.d.ts.map +1 -1
- package/dist/routes/collect.d.ts.map +1 -1
- package/dist/routes/collect.js +31 -34
- package/dist/routes/comparator.d.ts.map +1 -1
- package/dist/routes/comparator.js +5 -6
- package/dist/routes/load-module.d.ts.map +1 -1
- package/dist/routes/load-module.js +12 -12
- package/dist/routes/match.d.ts +2 -2
- package/dist/routes/match.d.ts.map +1 -1
- package/dist/routes/match.js +18 -21
- package/dist/{build/static.d.ts → routes/render.d.ts} +2 -2
- package/dist/routes/render.d.ts.map +1 -0
- package/dist/{build/static.js → routes/render.js} +34 -29
- package/dist/routes/route.d.ts +5 -5
- package/dist/routes/route.d.ts.map +1 -1
- package/dist/routes/route.js +1 -1
- package/dist/server/adapters/hono.d.ts +3 -3
- package/dist/server/adapters/hono.d.ts.map +1 -1
- package/dist/server/adapters/hono.js +3 -2
- package/dist/server/adapters/node.d.ts +5 -5
- package/dist/server/adapters/node.d.ts.map +1 -1
- package/dist/server/adapters/node.js +25 -21
- package/dist/server/request.d.ts.map +1 -1
- package/dist/server/request.js +25 -22
- package/dist/server/utils.d.ts +0 -1
- package/dist/server/utils.d.ts.map +1 -1
- package/dist/server/utils.js +14 -17
- package/dist/vite/{plugins/build-routes.d.ts → build-routes.d.ts} +3 -3
- package/dist/vite/build-routes.d.ts.map +1 -0
- package/dist/vite/{plugins/build-routes.js → build-routes.js} +24 -29
- package/dist/vite/html-routes.d.ts +10 -0
- package/dist/vite/html-routes.d.ts.map +1 -0
- package/dist/vite/html-routes.js +25 -0
- package/dist/vite/{plugins/virtual-routes.d.ts → virtual-routes.d.ts} +6 -3
- package/dist/vite/virtual-routes.d.ts.map +1 -0
- package/dist/vite/{plugins/virtual-routes.js → virtual-routes.js} +15 -17
- package/package.json +8 -9
- package/dist/build/static.d.ts.map +0 -1
- package/dist/dev/dev.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/vite/plugins/build-routes.d.ts.map +0 -1
- package/dist/vite/plugins/virtual-routes.d.ts.map +0 -1
package/dist/routes/collect.js
CHANGED
|
@@ -10,7 +10,7 @@ import { prepareSortableRoutes, routeComparator } from './comparator.js';
|
|
|
10
10
|
import { REGEXES } from './load-module.js';
|
|
11
11
|
const logger = getLogger();
|
|
12
12
|
function extractRoutePatterns(routeFilePath) {
|
|
13
|
-
const routePathname = routeFilePath.replace(/\.
|
|
13
|
+
const routePathname = routeFilePath.replace(/\.(js|ts|jsx|tsx|html)$/, '');
|
|
14
14
|
let pathParts = routePathname.split(paths.isWindows() ? paths.WINDOWS_PATH_SEPARATOR : '/');
|
|
15
15
|
const last = pathParts.at(-1);
|
|
16
16
|
if (last === undefined)
|
|
@@ -23,32 +23,31 @@ function extractRoutePatterns(routeFilePath) {
|
|
|
23
23
|
pathParts.pop();
|
|
24
24
|
if (pathParts.length === 1 && pathParts.at(0) === 'index')
|
|
25
25
|
pathParts = [];
|
|
26
|
-
let
|
|
27
|
-
const
|
|
26
|
+
let hasParameters = false;
|
|
27
|
+
const pathRelativeNormalized = pathParts.map((pathEntry) => {
|
|
28
28
|
let entry = pathEntry;
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
return pathEntry.replace(REGEXES.rest, (_s,
|
|
29
|
+
if (REGEXES.rest.test(entry)) {
|
|
30
|
+
hasParameters = true;
|
|
31
|
+
return pathEntry.replace(REGEXES.rest, (_s, parameter) => `:${parameter}*`);
|
|
32
32
|
}
|
|
33
33
|
while (REGEXES.param.test(entry)) {
|
|
34
|
-
|
|
35
|
-
entry = entry.replace(REGEXES.param, (_s,
|
|
36
|
-
return `{:${
|
|
34
|
+
hasParameters = true;
|
|
35
|
+
entry = entry.replace(REGEXES.param, (_s, parameter) => {
|
|
36
|
+
return `{:${parameter}}`;
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
return entry;
|
|
40
40
|
});
|
|
41
|
-
const trailingSlash =
|
|
42
|
-
const normalizedUrlPattern = `/${
|
|
41
|
+
const trailingSlash = pathRelativeNormalized.length > 0 ? '/' : '';
|
|
42
|
+
const normalizedUrlPattern = `/${pathRelativeNormalized.join('/')}${trailingSlash}`;
|
|
43
43
|
return {
|
|
44
44
|
patternString: normalizedUrlPattern,
|
|
45
45
|
pattern: new URLPattern(normalizedUrlPattern, 'http://gracile/'),
|
|
46
|
-
hasParams,
|
|
46
|
+
hasParams: hasParameters,
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
export const WATCHED_FILES_REGEX = /\/src\/routes\/(.*)\.(ts|
|
|
50
|
-
|
|
51
|
-
export async function collectRoutes(routes, root /* vite: ViteDevServer */, excludePatterns = []) {
|
|
49
|
+
export const WATCHED_FILES_REGEX = /\/src\/routes\/(.*)\.(js|ts|jsx|tsx|html|css|scss|sass|less|styl|stylus)$/;
|
|
50
|
+
export async function collectRoutes(routes, root, excludePatterns = []) {
|
|
52
51
|
routes.clear();
|
|
53
52
|
const routesFolder = 'src/routes';
|
|
54
53
|
const routesFolderAbsolute = join(root, routesFolder);
|
|
@@ -57,11 +56,10 @@ export async function collectRoutes(routes, root /* vite: ViteDevServer */, excl
|
|
|
57
56
|
.withRelativePaths()
|
|
58
57
|
.crawl(routesFolderAbsolute)
|
|
59
58
|
.withPromise();
|
|
60
|
-
|
|
61
|
-
const serverEntrypointsFilter = createFilter(['**/*.{js,ts}'], [
|
|
59
|
+
const serverEntrypointsFilter = createFilter(['**/*.{js,ts,jsx,tsx,html}'], [
|
|
62
60
|
//
|
|
63
|
-
'**/*.client.{js,ts}',
|
|
64
|
-
'**/*.document.{js,ts}',
|
|
61
|
+
'**/*.client.{js,ts,jsx,tsx}',
|
|
62
|
+
'**/*.document.{js,ts,jsx,tsx}',
|
|
65
63
|
'**/_*/**',
|
|
66
64
|
'**/_*',
|
|
67
65
|
'**/.*',
|
|
@@ -75,11 +73,11 @@ export async function collectRoutes(routes, root /* vite: ViteDevServer */, excl
|
|
|
75
73
|
return;
|
|
76
74
|
}
|
|
77
75
|
// MARK: Routes priority order
|
|
78
|
-
// TODO: `prepareSortableRoutes` and `routeComparator` in same function `sortRoutes
|
|
76
|
+
// TODO: `prepareSortableRoutes` and `routeComparator` in same function `sortRoutes`.
|
|
79
77
|
const serverEntrypointsSorted = prepareSortableRoutes(serverEntrypoints)
|
|
80
78
|
.sort((a, b) => routeComparator(a, b))
|
|
81
79
|
.map((r) => r.route);
|
|
82
|
-
const serverPageClientAssetsFilter = createFilter(['**/*.client.{js,ts}', '**/*.{css,scss,sass,less,styl,stylus}'], [...excludePatterns]);
|
|
80
|
+
const serverPageClientAssetsFilter = createFilter(['**/*.client.{js,ts,jsx,tsx}', '**/*.{css,scss,sass,less,styl,stylus}'], [...excludePatterns]);
|
|
83
81
|
const serverPageClientAssets = allFilesInRoutes.filter((f) => serverPageClientAssetsFilter(f));
|
|
84
82
|
logger.info(`\n${c.underline(`Found ${c.bold('routes')}`)}:\n` +
|
|
85
83
|
`${c.dim('- ')}${serverEntrypointsSorted
|
|
@@ -87,11 +85,11 @@ export async function collectRoutes(routes, root /* vite: ViteDevServer */, excl
|
|
|
87
85
|
const pathParts = f.split('/');
|
|
88
86
|
return pathParts
|
|
89
87
|
.map((part, index) => {
|
|
90
|
-
if (
|
|
88
|
+
if (/\[\./.test(part))
|
|
91
89
|
return c.cyan(c.italic(part));
|
|
92
|
-
if (
|
|
90
|
+
if (/\[/.test(part))
|
|
93
91
|
return c.cyan(part);
|
|
94
|
-
if (
|
|
92
|
+
if (/\(/.test(part))
|
|
95
93
|
return c.yellow(part);
|
|
96
94
|
if (index === pathParts.length - 1)
|
|
97
95
|
return c.green(part);
|
|
@@ -101,7 +99,7 @@ export async function collectRoutes(routes, root /* vite: ViteDevServer */, excl
|
|
|
101
99
|
})
|
|
102
100
|
.join(c.dim('\n- '))}\n`);
|
|
103
101
|
// MARK: Associate
|
|
104
|
-
|
|
102
|
+
for (const routePath of serverEntrypointsSorted) {
|
|
105
103
|
const filePath = join(routesFolder, routePath);
|
|
106
104
|
const routeWithPatterns = extractRoutePatterns(routePath);
|
|
107
105
|
routes.set(routeWithPatterns.patternString, {
|
|
@@ -112,14 +110,13 @@ export async function collectRoutes(routes, root /* vite: ViteDevServer */, excl
|
|
|
112
110
|
// NOTE: Not implemented here!
|
|
113
111
|
// prerender: null,
|
|
114
112
|
});
|
|
115
|
-
}
|
|
116
|
-
|
|
113
|
+
}
|
|
114
|
+
for (const routePath of serverPageClientAssets) {
|
|
117
115
|
// NOTE: Exact extension needed client side by Vite.
|
|
118
|
-
const
|
|
119
|
-
routes.
|
|
120
|
-
if (paths.
|
|
121
|
-
paths.
|
|
122
|
-
route.pageAssets.push(
|
|
123
|
-
|
|
124
|
-
});
|
|
116
|
+
const assetPathWithExtension = join(routesFolder, routePath);
|
|
117
|
+
for (const route of routes.values())
|
|
118
|
+
if (paths.removeAllExtension(route.filePath) ===
|
|
119
|
+
paths.removeAllExtension(assetPathWithExtension))
|
|
120
|
+
route.pageAssets.push(assetPathWithExtension);
|
|
121
|
+
}
|
|
125
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comparator.d.ts","sourceRoot":"","sources":["../../src/routes/comparator.ts"],"names":[],"mappings":"AAIA,UAAU,SAAS;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAEhB,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,EAAE,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,kBAAkB,UA2F3E;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"comparator.d.ts","sourceRoot":"","sources":["../../src/routes/comparator.ts"],"names":[],"mappings":"AAIA,UAAU,SAAS;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAEhB,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,EAAE,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,kBAAkB,UA2F3E;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,wBAqCrD"}
|
|
@@ -110,19 +110,18 @@ export function prepareSortableRoutes(routes) {
|
|
|
110
110
|
if (REGEXES.param.test(part)) {
|
|
111
111
|
segment.dynamic = true;
|
|
112
112
|
}
|
|
113
|
-
const
|
|
114
|
-
.replace(/\.(js|ts)$/, '')
|
|
113
|
+
const parameters = part
|
|
114
|
+
.replace(/\.(js|ts|jsx|tsx|html)$/, '')
|
|
115
115
|
.split(REGEXES.dynamicSplit)
|
|
116
|
-
.filter((
|
|
117
|
-
if (
|
|
116
|
+
.filter((parameter) => parameter !== '');
|
|
117
|
+
if (parameters.length > 1) {
|
|
118
118
|
segment.allDynamic = false;
|
|
119
119
|
}
|
|
120
|
-
else if (
|
|
120
|
+
else if (parameters.length === 1) {
|
|
121
121
|
segment.allDynamic = true;
|
|
122
122
|
}
|
|
123
123
|
return segment;
|
|
124
124
|
});
|
|
125
|
-
// console.log({ segments });
|
|
126
125
|
return {
|
|
127
126
|
route,
|
|
128
127
|
segments,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-module.d.ts","sourceRoot":"","sources":["../../src/routes/load-module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"load-module.d.ts","sourceRoot":"","sources":["../../src/routes/load-module.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;AAI1C,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAGhC,eAAO,MAAM,OAAO;;;;;;CASnB,CAAC;AAQF,wBAAsB,sBAAsB,CAAC,EAC5C,IAAI,EACJ,KAAK,EACL,YAAY,GACZ,EAAE;IACF,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACjC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC;IACf,YAAY,CAAC,EAAE,CAAC,CAAC,aAAa,GAAG,SAAS,CAAC;CAC3C,0BA8CA"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
1
3
|
import { collectErrorMetadata } from '@gracile-labs/better-errors/dev/utils';
|
|
2
4
|
import { enhanceViteSSRError } from '@gracile-labs/better-errors/dev/vite';
|
|
3
|
-
import { join } from 'path';
|
|
4
|
-
import { pathToFileURL } from 'url';
|
|
5
5
|
import {} from 'vite';
|
|
6
6
|
import { GracileError, GracileErrorData } from '../errors/errors.js';
|
|
7
7
|
import * as R from './route.js';
|
|
8
8
|
// const ROUTE_SPREAD = /^\.{3}.+$/;
|
|
9
9
|
export const REGEXES = {
|
|
10
10
|
//
|
|
11
|
-
param: /\[(.*?)
|
|
12
|
-
rest: /^\[
|
|
13
|
-
restWithExt: /^\[
|
|
14
|
-
dynamicSplit: /\[(.+?\(.+?\)|.+?)
|
|
11
|
+
param: /\[(.*?)]/,
|
|
12
|
+
rest: /^\[\.{3}(.*)]$/,
|
|
13
|
+
restWithExt: /^\[\.{3}(.*)]\.[jt|]s$/,
|
|
14
|
+
dynamicSplit: /\[(.+?\(.+?\)|.+?)]/,
|
|
15
15
|
// index: /^(index\.(js|ts)|\((.*)\)\.(js|ts))$/,
|
|
16
16
|
index: /\((.*)\)/,
|
|
17
17
|
};
|
|
@@ -21,20 +21,19 @@ const incorrectRouteModuleError = (p) => new GracileError({
|
|
|
21
21
|
});
|
|
22
22
|
export async function loadForeignRouteObject({ vite, route, routeImports, }) {
|
|
23
23
|
// NOTE: Check and assert unknown userland module to correct RouteModule instance (in the engine's realm)
|
|
24
|
-
let unknownRouteModule
|
|
24
|
+
let unknownRouteModule;
|
|
25
25
|
if (vite) {
|
|
26
26
|
try {
|
|
27
27
|
unknownRouteModule = await vite.ssrLoadModule(route.filePath /* + 's' */, {});
|
|
28
28
|
}
|
|
29
|
-
catch (
|
|
30
|
-
const
|
|
29
|
+
catch (error) {
|
|
30
|
+
const error_ = error;
|
|
31
31
|
const filePath = pathToFileURL(join(vite.config.root, route.filePath));
|
|
32
32
|
const rootFolder = pathToFileURL(vite.config.root);
|
|
33
33
|
// NOTE: Maybe it's not required here? But just upstream (safeError…)
|
|
34
34
|
const enhance = enhanceViteSSRError({
|
|
35
|
-
error:
|
|
35
|
+
error: error_,
|
|
36
36
|
filePath,
|
|
37
|
-
// @ts-expect-error Typings mismatches
|
|
38
37
|
vite,
|
|
39
38
|
});
|
|
40
39
|
const errorWithMetadata = collectErrorMetadata(enhance, rootFolder);
|
|
@@ -46,11 +45,12 @@ export async function loadForeignRouteObject({ vite, route, routeImports, }) {
|
|
|
46
45
|
if (ri)
|
|
47
46
|
unknownRouteModule = await Promise.resolve(ri());
|
|
48
47
|
}
|
|
49
|
-
if (unknownRouteModule ===
|
|
48
|
+
if (unknownRouteModule === undefined)
|
|
50
49
|
throw new Error('Cannot find route module.');
|
|
51
50
|
const routeModuleFactory = unknownRouteModule['default'];
|
|
52
51
|
if (typeof routeModuleFactory !== 'function')
|
|
53
52
|
throw incorrectRouteModuleError(route.filePath);
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
54
54
|
const routeModule = routeModuleFactory(R.RouteModule);
|
|
55
55
|
if (routeModule instanceof R.RouteModule === false)
|
|
56
56
|
throw incorrectRouteModuleError(route.filePath);
|
package/dist/routes/match.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ViteDevServer } from 'vite';
|
|
2
2
|
import type * as R from './route.js';
|
|
3
|
-
type
|
|
3
|
+
type Parameters_ = Record<string, string | undefined>;
|
|
4
4
|
export type RouteInfos = {
|
|
5
|
-
params:
|
|
5
|
+
params: Parameters_;
|
|
6
6
|
props: unknown;
|
|
7
7
|
routeModule: Readonly<R.RouteModule>;
|
|
8
8
|
foundRoute: R.Route;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../src/routes/match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,KAAK,KAAK,CAAC,MAAM,YAAY,CAAC;AAErC,KAAK,
|
|
1
|
+
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../src/routes/match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,KAAK,KAAK,CAAC,MAAM,YAAY,CAAC;AAErC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAoFtD,MAAM,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACrC,UAAU,EAAE,CAAC,CAAC,KAAK,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAsB,QAAQ,CAAC,OAAO,EAAE;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACjC,MAAM,EAAE,CAAC,CAAC,cAAc,CAAC;IACzB,YAAY,CAAC,EAAE,CAAC,CAAC,aAAa,GAAG,SAAS,CAAC;CAC3C,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CA6B7B"}
|
package/dist/routes/match.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { loadForeignRouteObject } from './load-module.js';
|
|
2
|
-
// FIXME: proper DI for routes
|
|
3
2
|
function matchRouteFromUrl(url, routes) {
|
|
4
3
|
let match;
|
|
5
4
|
let foundRoute;
|
|
6
5
|
const pathname = new URL(url).pathname;
|
|
7
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
8
6
|
for (const [, route] of routes) {
|
|
9
7
|
if (match)
|
|
10
8
|
break;
|
|
@@ -16,44 +14,43 @@ function matchRouteFromUrl(url, routes) {
|
|
|
16
14
|
}
|
|
17
15
|
if (!match || !foundRoute)
|
|
18
16
|
return null;
|
|
19
|
-
const
|
|
20
|
-
return { match, foundRoute, params, pathname };
|
|
17
|
+
const parameters = Object.freeze({ ...match.pathname.groups });
|
|
18
|
+
return { match, foundRoute, params: parameters, pathname };
|
|
21
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* @param options
|
|
22
|
+
* @param options.routeModule
|
|
23
|
+
* @param options.foundRoute
|
|
24
|
+
* @param options.params
|
|
25
|
+
* @param options.pathname
|
|
26
|
+
*/
|
|
22
27
|
async function extractStaticPaths(options) {
|
|
23
28
|
if (!options.foundRoute.hasParams)
|
|
24
29
|
return null;
|
|
25
30
|
if (!options.routeModule.staticPaths)
|
|
26
31
|
return null;
|
|
27
32
|
const routeStaticPaths = options.routeModule.staticPaths;
|
|
28
|
-
let
|
|
33
|
+
let properties;
|
|
29
34
|
const staticPaths = await Promise.resolve(routeStaticPaths());
|
|
30
|
-
let
|
|
31
|
-
|
|
35
|
+
let hasCorrectParameters = false;
|
|
36
|
+
for (const providedRouteOptions of staticPaths) {
|
|
32
37
|
const routeOptions = providedRouteOptions;
|
|
33
|
-
const matchingKeys = Object.entries(routeOptions.params).filter(([key,
|
|
38
|
+
const matchingKeys = Object.entries(routeOptions.params).filter(([key, value]) => options.params[key] === value);
|
|
34
39
|
if (matchingKeys.length === Object.keys(options.params).length) {
|
|
35
|
-
|
|
40
|
+
hasCorrectParameters = true;
|
|
36
41
|
if (routeOptions.props)
|
|
37
|
-
|
|
42
|
+
properties = routeOptions.props;
|
|
38
43
|
}
|
|
39
|
-
}
|
|
40
|
-
if (
|
|
41
|
-
// throw new Error(
|
|
42
|
-
// `Incorrect route parameters for \`${options.pathname}\`.\n` +
|
|
43
|
-
// `Check \`staticPaths\` for \`${options.foundRoute.filePath}\`.`,
|
|
44
|
-
// );
|
|
44
|
+
}
|
|
45
|
+
if (hasCorrectParameters === false)
|
|
45
46
|
return null;
|
|
46
|
-
return { staticPaths, props };
|
|
47
|
+
return { staticPaths, props: properties };
|
|
47
48
|
}
|
|
48
49
|
export async function getRoute(options) {
|
|
49
|
-
// throw new GracileError(new Error(`No route matching for ${url}`), {
|
|
50
|
-
// cause: 404,
|
|
51
|
-
// });
|
|
52
50
|
const matchedRoute = matchRouteFromUrl(options.url, options.routes);
|
|
53
51
|
if (!matchedRoute)
|
|
54
52
|
return matchedRoute;
|
|
55
53
|
const { foundRoute, pathname, params } = matchedRoute;
|
|
56
|
-
// TODO: Simplify all the routes things
|
|
57
54
|
const routeModule = await loadForeignRouteObject({
|
|
58
55
|
vite: options.vite,
|
|
59
56
|
route: foundRoute,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ViteDevServer } from 'vite';
|
|
2
|
-
import type { RoutesManifest } from '../routes/route.js';
|
|
3
2
|
import type { GracileConfig } from '../user-config.js';
|
|
3
|
+
import type { RoutesManifest } from './route.js';
|
|
4
4
|
export interface RenderedRouteDefinition {
|
|
5
5
|
absoluteId: string;
|
|
6
6
|
name: string;
|
|
@@ -22,4 +22,4 @@ export declare function renderRoutes({ routes, vite, serverMode, root, gracileCo
|
|
|
22
22
|
routes: RoutesManifest;
|
|
23
23
|
renderedRoutes: RenderedRouteDefinition[];
|
|
24
24
|
}>;
|
|
25
|
-
//# sourceMappingURL=
|
|
25
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/routes/render.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,WAAW,uBAAuB;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,MAAM,EAAE;QACP,KAAK,EAAE,OAAO,CAAC;QACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;KACxB,CAAC;IAEF,aAAa,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B;AAcD,wBAAsB,YAAY,CAAC,EAClC,MAAM,EACN,IAAI,EACJ,UAAU,EACV,IAAoB,EACpB,aAAa,GACb,EAAE;IACF,MAAM,EAAE,cAAc,CAAC;IACvB,IAAI,EAAE,aAAa,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,aAAa,CAAC;CAC7B;;;GAkKA"}
|
|
@@ -3,11 +3,10 @@ import path, { join } from 'node:path';
|
|
|
3
3
|
import { getLogger } from '@gracile/internal-utils/logger/helpers';
|
|
4
4
|
import c from 'picocolors';
|
|
5
5
|
import { renderRouteTemplate } from '../render/route-template.js';
|
|
6
|
-
import { collectRoutes } from '
|
|
7
|
-
import { loadForeignRouteObject } from '
|
|
6
|
+
import { collectRoutes } from './collect.js';
|
|
7
|
+
import { loadForeignRouteObject } from './load-module.js';
|
|
8
8
|
async function streamToString(stream) {
|
|
9
9
|
const chunks = [];
|
|
10
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
11
10
|
for await (const chunk of stream) {
|
|
12
11
|
if (typeof chunk === 'string') {
|
|
13
12
|
chunks.push(Buffer.from(chunk));
|
|
@@ -15,7 +14,7 @@ async function streamToString(stream) {
|
|
|
15
14
|
else
|
|
16
15
|
throw new TypeError('Wrong buffer');
|
|
17
16
|
}
|
|
18
|
-
return Buffer.concat(chunks).toString('
|
|
17
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
19
18
|
}
|
|
20
19
|
export async function renderRoutes({ routes, vite, serverMode, root = process.cwd(), gracileConfig, }) {
|
|
21
20
|
const logger = getLogger();
|
|
@@ -37,12 +36,12 @@ export async function renderRoutes({ routes, vite, serverMode, root = process.cw
|
|
|
37
36
|
await Promise.all(
|
|
38
37
|
/* Single route */
|
|
39
38
|
(routeStaticPaths ?? [patternString]).map(async (staticPathOptions) => {
|
|
40
|
-
let
|
|
41
|
-
let
|
|
42
|
-
let
|
|
39
|
+
let pathnameWithParameters = patternString;
|
|
40
|
+
let parameters = {};
|
|
41
|
+
let properties;
|
|
43
42
|
// MARK: Handler data (for single route only, NOT dynamic)
|
|
44
43
|
if (routeModule.handler) {
|
|
45
|
-
const url = new URL(
|
|
44
|
+
const url = new URL(pathnameWithParameters, 'http://gracile-static');
|
|
46
45
|
const context = {
|
|
47
46
|
url,
|
|
48
47
|
params: {},
|
|
@@ -53,10 +52,10 @@ export async function renderRoutes({ routes, vite, serverMode, root = process.cw
|
|
|
53
52
|
responseInit: {},
|
|
54
53
|
};
|
|
55
54
|
if (typeof routeModule.handler === 'function') {
|
|
56
|
-
|
|
55
|
+
properties = await Promise.resolve(routeModule.handler(context));
|
|
57
56
|
}
|
|
58
57
|
else if ('GET' in routeModule.handler) {
|
|
59
|
-
|
|
58
|
+
properties = {
|
|
60
59
|
GET: await Promise.resolve(routeModule.handler.GET(context)),
|
|
61
60
|
};
|
|
62
61
|
}
|
|
@@ -64,29 +63,29 @@ export async function renderRoutes({ routes, vite, serverMode, root = process.cw
|
|
|
64
63
|
// MARK: Convert pattern
|
|
65
64
|
// to real route with static parameters + get props. for after
|
|
66
65
|
else if (typeof staticPathOptions === 'object') {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Object.entries(staticPathOptions.params)
|
|
70
|
-
if (typeof value === 'string' ||
|
|
71
|
-
|
|
72
|
-
.replace(`:${
|
|
73
|
-
.replace(`{:${
|
|
74
|
-
}
|
|
66
|
+
parameters = staticPathOptions.params;
|
|
67
|
+
properties = staticPathOptions.props;
|
|
68
|
+
for (const [parameterName, value] of Object.entries(staticPathOptions.params)) {
|
|
69
|
+
if (typeof value === 'string' || value === undefined)
|
|
70
|
+
pathnameWithParameters = pathnameWithParameters
|
|
71
|
+
.replace(`:${parameterName}*`, value || '')
|
|
72
|
+
.replace(`{:${parameterName}}`, value || '');
|
|
73
|
+
}
|
|
75
74
|
}
|
|
76
75
|
// MARK: Prepare
|
|
77
76
|
// NOTE: Unused for now
|
|
78
|
-
const isErrorPage =
|
|
77
|
+
const isErrorPage = pathnameWithParameters.match(/\/__(.*)$/); /* Could add more (error, etc) */
|
|
79
78
|
const base = isErrorPage
|
|
80
|
-
? path.dirname(
|
|
81
|
-
:
|
|
79
|
+
? path.dirname(pathnameWithParameters.slice(1))
|
|
80
|
+
: pathnameWithParameters.slice(1);
|
|
82
81
|
let name = path.join(base, isErrorPage
|
|
83
|
-
? `${
|
|
82
|
+
? `${pathnameWithParameters.split('/').at(-2)?.replace('__', '')}.html`
|
|
84
83
|
: 'index.html');
|
|
85
84
|
if (name === '404/index.html')
|
|
86
85
|
name = '404.html';
|
|
87
|
-
if (name === '500/index.html')
|
|
86
|
+
else if (name === '500/index.html')
|
|
88
87
|
name = '500.html';
|
|
89
|
-
const url = new URL(
|
|
88
|
+
const url = new URL(pathnameWithParameters, 'http://gracile-static');
|
|
90
89
|
// MARK: Render
|
|
91
90
|
const { output, document } = await renderRouteTemplate({
|
|
92
91
|
//
|
|
@@ -96,15 +95,21 @@ export async function renderRoutes({ routes, vite, serverMode, root = process.cw
|
|
|
96
95
|
mode: 'build',
|
|
97
96
|
routeInfos: {
|
|
98
97
|
routeModule,
|
|
99
|
-
params,
|
|
98
|
+
params: parameters,
|
|
100
99
|
foundRoute: route,
|
|
101
|
-
pathname:
|
|
102
|
-
props,
|
|
100
|
+
pathname: pathnameWithParameters,
|
|
101
|
+
props: properties,
|
|
103
102
|
},
|
|
104
103
|
root,
|
|
105
104
|
serverMode,
|
|
106
105
|
});
|
|
107
|
-
const htmlString = output
|
|
106
|
+
const htmlString = output
|
|
107
|
+
? await streamToString(output).then((s) =>
|
|
108
|
+
// IMPORTANT: This is a hack for a behavior for which I'm not sure
|
|
109
|
+
// if Lit is taking advantage of. It looks like a fallback.
|
|
110
|
+
// TODO: Check if that breaks some hydration mechanism.
|
|
111
|
+
s.replaceAll('<?>', ''))
|
|
112
|
+
: null;
|
|
108
113
|
const existing = renderedRoutes.find((rendered) => rendered?.name === name);
|
|
109
114
|
// NOTE: IIRC, this happens when two or more routes has the
|
|
110
115
|
// same priority, that will output the same static path.
|
|
@@ -119,7 +124,7 @@ export async function renderRoutes({ routes, vite, serverMode, root = process.cw
|
|
|
119
124
|
name,
|
|
120
125
|
html: htmlString,
|
|
121
126
|
savePrerender,
|
|
122
|
-
static: { props, document },
|
|
127
|
+
static: { props: properties, document },
|
|
123
128
|
};
|
|
124
129
|
renderedRoutes.push(rendered);
|
|
125
130
|
}));
|
package/dist/routes/route.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare class RouteModule {
|
|
|
30
30
|
get template(): ((context: RouteContextGeneric) => RouteTemplateResult) | undefined;
|
|
31
31
|
constructor(options: ModuleOptions);
|
|
32
32
|
}
|
|
33
|
-
export type
|
|
33
|
+
export type Parameters = Record<string, string | undefined>;
|
|
34
34
|
export type Handler<Data extends HandlerData | HandlerDataHtml = never> = (context: {
|
|
35
35
|
url: URL;
|
|
36
36
|
/**
|
|
@@ -38,7 +38,7 @@ export type Handler<Data extends HandlerData | HandlerDataHtml = never> = (conte
|
|
|
38
38
|
*
|
|
39
39
|
* E.g. `src/routes/foo/[bar]/[baz].ts` -\> `{ bar: string; baz: string; }`
|
|
40
40
|
*/
|
|
41
|
-
params:
|
|
41
|
+
params: Parameters;
|
|
42
42
|
request: Request;
|
|
43
43
|
locals: Gracile.Locals;
|
|
44
44
|
/**
|
|
@@ -54,18 +54,18 @@ export type StaticPathsGeneric = () => MaybePromise<StaticPathOptionsGeneric[]>;
|
|
|
54
54
|
export type HandlerData = Response | undefined;
|
|
55
55
|
export type HandlerDataHtml = HandlerData | object;
|
|
56
56
|
export type StaticPathOptionsGeneric = {
|
|
57
|
-
params:
|
|
57
|
+
params: Parameters;
|
|
58
58
|
props: unknown;
|
|
59
59
|
};
|
|
60
60
|
export type MaybePromise<T> = Promise<T> | T;
|
|
61
61
|
export type StaticRequest = Pick<Request, 'url'>;
|
|
62
62
|
export type RouteContextGeneric = {
|
|
63
63
|
url: URL;
|
|
64
|
-
params:
|
|
64
|
+
params: Parameters;
|
|
65
65
|
props: unknown;
|
|
66
66
|
};
|
|
67
67
|
export type DocumentResult = MaybePromise<ServerRenderedTemplate>;
|
|
68
|
-
export type RouteTemplateResult = MaybePromise<TemplateResult
|
|
68
|
+
export type RouteTemplateResult = MaybePromise<TemplateResult>;
|
|
69
69
|
export type DocumentTemplate<RouteContext extends RouteContextGeneric = RouteContextGeneric> = (context: RouteContext) => DocumentResult;
|
|
70
70
|
export type BodyTemplate<RouteContext> = (context: RouteContext) => RouteTemplateResult;
|
|
71
71
|
export interface Route {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/routes/route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/routes/route.ts"],"names":[],"mappings":"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"}
|
package/dist/routes/route.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AdapterOptions, GracileHandler } from '../request.js';
|
|
2
|
-
export type { GracileHandler };
|
|
3
2
|
export type GracileHonoHandler = (context: {
|
|
4
3
|
req: {
|
|
5
4
|
raw: Request;
|
|
@@ -41,9 +40,10 @@ export declare const honoAdapter: (handler: GracileHandler, options?: HonoAdapte
|
|
|
41
40
|
*
|
|
42
41
|
* const app = new Hono();
|
|
43
42
|
*
|
|
44
|
-
* app.get('*', serveStatic({ root: gracile.
|
|
43
|
+
* app.get('*', serveStatic({ root: gracile.getClientBuildPath(import.meta.url) }));
|
|
45
44
|
* ```
|
|
46
45
|
*/
|
|
47
|
-
export declare function
|
|
46
|
+
export declare function getClientBuildPath(root: string): string;
|
|
48
47
|
export { printUrls } from '../utils.js';
|
|
48
|
+
export { type GracileHandler } from '../request.js';
|
|
49
49
|
//# sourceMappingURL=hono.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/hono.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpE,
|
|
1
|
+
{"version":3,"file":"hono.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/hono.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpE,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE;IAC1C,GAAG,EAAE;QAAE,GAAG,EAAE,OAAO,CAAA;KAAE,CAAC;IACtB,GAAG,EAAE,OAAO,CAAC;CACb,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAGxB,MAAM,WAAW,kBAAmB,SAAQ,cAAc;CAEzD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,WAAW,YACb,cAAc,YAAY,kBAAkB,KAAG,kBAmBxD,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,UAK9C;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -52,10 +52,11 @@ export const honoAdapter = (handler, options) => async (context) => {
|
|
|
52
52
|
*
|
|
53
53
|
* const app = new Hono();
|
|
54
54
|
*
|
|
55
|
-
* app.get('*', serveStatic({ root: gracile.
|
|
55
|
+
* app.get('*', serveStatic({ root: gracile.getClientBuildPath(import.meta.url) }));
|
|
56
56
|
* ```
|
|
57
57
|
*/
|
|
58
|
-
export function
|
|
58
|
+
export function getClientBuildPath(root) {
|
|
59
59
|
return relative(process.cwd(), fileURLToPath(new URL(constants.CLIENT_DIST_DIR, root)));
|
|
60
60
|
}
|
|
61
61
|
export { printUrls } from '../utils.js';
|
|
62
|
+
export {} from '../request.js';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { IncomingMessage, ServerResponse } from 'http';
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
2
|
import { type AdapterOptions, type GracileHandler } from '../request.js';
|
|
3
|
-
export type
|
|
4
|
-
export type GracileNodeHandler = (req: IncomingMessage, res: ServerResponse, locals?: unknown) => Promise<ServerResponse<IncomingMessage> | null | void>;
|
|
3
|
+
export type GracileNodeHandler = (request: IncomingMessage, response: ServerResponse, locals?: unknown) => Promise<ServerResponse<IncomingMessage> | null | void>;
|
|
5
4
|
export interface NodeAdapterOptions extends AdapterOptions {
|
|
6
5
|
}
|
|
7
6
|
/**
|
|
@@ -33,9 +32,10 @@ export declare function nodeAdapter(handler: GracileHandler, options?: NodeAdapt
|
|
|
33
32
|
*
|
|
34
33
|
* const app = express();
|
|
35
34
|
*
|
|
36
|
-
* app.use(express.static(gracile.
|
|
35
|
+
* app.use(express.static(gracile.getClientBuildPath(import.meta.url)));
|
|
37
36
|
* ```
|
|
38
37
|
*/
|
|
39
|
-
export declare function
|
|
38
|
+
export declare function getClientBuildPath(root: string): string;
|
|
40
39
|
export { printUrls } from '../utils.js';
|
|
40
|
+
export { type GracileHandler } from '../request.js';
|
|
41
41
|
//# sourceMappingURL=node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/server/adapters/node.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAQjE,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,cAAc,EAEnB,MAAM,eAAe,CAAC;AAqBvB,MAAM,MAAM,kBAAkB,GAAG,CAChC,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,cAAc,EACxB,MAAM,CAAC,EAAE,OAAO,KACZ,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;AAG5D,MAAM,WAAW,kBAAmB,SAAQ,cAAc;CAEzD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAC1B,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,kBAAkB,GAC1B,kBAAkB,CAqEpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,UAE9C;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC"}
|