@gracile/engine 0.6.0 → 0.7.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/dist/build/static.d.ts +8 -2
- package/dist/build/static.d.ts.map +1 -1
- package/dist/build/static.js +38 -8
- package/dist/dev/dev.d.ts +4 -1
- package/dist/dev/dev.d.ts.map +1 -1
- package/dist/dev/dev.js +32 -19
- package/dist/dev/vite-logger.d.ts +2 -0
- package/dist/dev/vite-logger.d.ts.map +1 -0
- package/dist/dev/vite-logger.js +2 -0
- package/dist/errors/create-vite-better-error.d.ts +6 -0
- package/dist/errors/create-vite-better-error.d.ts.map +1 -0
- package/dist/errors/create-vite-better-error.js +27 -0
- package/dist/errors/errors-data.d.ts +81 -0
- package/dist/errors/errors-data.d.ts.map +1 -0
- package/dist/errors/errors-data.js +98 -0
- package/dist/errors/errors.d.ts +22 -0
- package/dist/errors/errors.d.ts.map +1 -0
- package/dist/errors/errors.js +122 -0
- package/dist/errors/pages.d.ts +4 -0
- package/dist/errors/pages.d.ts.map +1 -0
- package/dist/errors/pages.js +135 -0
- package/dist/logging/messages.d.ts +2 -0
- package/dist/logging/messages.d.ts.map +1 -0
- package/dist/logging/messages.js +6 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +82 -43
- package/dist/render/markers.d.ts +3 -0
- package/dist/render/markers.d.ts.map +1 -0
- package/dist/render/markers.js +4 -0
- package/dist/render/route-template.d.ts +5 -10
- package/dist/render/route-template.d.ts.map +1 -1
- package/dist/render/route-template.js +68 -48
- package/dist/render/utils.d.ts +24 -1
- package/dist/render/utils.d.ts.map +1 -1
- package/dist/render/utils.js +23 -1
- package/dist/routes/collect.d.ts +2 -1
- package/dist/routes/collect.d.ts.map +1 -1
- package/dist/routes/collect.js +15 -11
- package/dist/routes/load-module.d.ts +1 -1
- package/dist/routes/load-module.d.ts.map +1 -1
- package/dist/routes/load-module.js +31 -5
- package/dist/routes/match.d.ts +1 -1
- package/dist/routes/match.d.ts.map +1 -1
- package/dist/routes/match.js +26 -12
- package/dist/routes/route.d.ts +2 -2
- package/dist/routes/route.d.ts.map +1 -1
- package/dist/routes/route.js +14 -12
- package/dist/server/adapters/hono.d.ts +5 -2
- package/dist/server/adapters/hono.d.ts.map +1 -1
- package/dist/server/adapters/hono.js +12 -6
- package/dist/server/adapters/node.d.ts +4 -2
- package/dist/server/adapters/node.d.ts.map +1 -1
- package/dist/server/adapters/node.js +27 -12
- package/dist/server/constants.d.ts +1 -1
- package/dist/server/constants.d.ts.map +1 -1
- package/dist/server/constants.js +1 -1
- package/dist/server/request.d.ts +7 -2
- package/dist/server/request.d.ts.map +1 -1
- package/dist/server/request.js +95 -69
- package/dist/server/utils.d.ts.map +1 -1
- package/dist/server/utils.js +5 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/user-config.d.ts +35 -1
- package/dist/user-config.d.ts.map +1 -1
- package/dist/vite/plugins/build-routes.d.ts +6 -2
- package/dist/vite/plugins/build-routes.d.ts.map +1 -1
- package/dist/vite/plugins/build-routes.js +69 -35
- package/dist/vite/plugins/virtual-routes.d.ts +10 -0
- package/dist/vite/plugins/virtual-routes.d.ts.map +1 -1
- package/dist/vite/plugins/virtual-routes.js +56 -4
- package/package.json +10 -11
- package/dist/assertions.d.ts +0 -13
- package/dist/assertions.d.ts.map +0 -1
- package/dist/assertions.js +0 -45
- package/dist/errors/templates.d.ts +0 -3
- package/dist/errors/templates.d.ts.map +0 -1
- package/dist/errors/templates.js +0 -69
package/dist/user-config.d.ts
CHANGED
|
@@ -60,12 +60,46 @@ export interface GracileConfig {
|
|
|
60
60
|
*/
|
|
61
61
|
exclude?: string[];
|
|
62
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* Settings for pages in `/src/routes`.
|
|
65
|
+
*/
|
|
66
|
+
pages?: {
|
|
67
|
+
/**
|
|
68
|
+
* Premises are the document and the properties necessary for page template
|
|
69
|
+
* rendering.
|
|
70
|
+
*
|
|
71
|
+
* You can access them via:
|
|
72
|
+
*
|
|
73
|
+
* - `.../_my-route/__index.props.json`
|
|
74
|
+
* - `.../_my-route/__index.doc.html`
|
|
75
|
+
*
|
|
76
|
+
* They are accessible with the dev/server handler and are outputted as
|
|
77
|
+
* static files for the static output or for server pre-rendered pages.
|
|
78
|
+
*
|
|
79
|
+
* They can be use for implementing client-side routing.
|
|
80
|
+
*/
|
|
81
|
+
premises?: {
|
|
82
|
+
/**
|
|
83
|
+
* @defaultValue false
|
|
84
|
+
*/
|
|
85
|
+
expose?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Include routes with a glob filter array.
|
|
88
|
+
*/
|
|
89
|
+
include?: string[];
|
|
90
|
+
/**
|
|
91
|
+
* Exclude routes with a glob filter array.
|
|
92
|
+
*/
|
|
93
|
+
exclude?: string[];
|
|
94
|
+
};
|
|
95
|
+
};
|
|
63
96
|
/**
|
|
64
97
|
* Future, unstable features flags.
|
|
65
98
|
*/
|
|
66
99
|
experimental?: {
|
|
67
100
|
/**
|
|
68
|
-
*
|
|
101
|
+
* Automatically typed route paths.
|
|
102
|
+
* @experimental
|
|
69
103
|
*/
|
|
70
104
|
generateRoutesTypings?: boolean;
|
|
71
105
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-config.d.ts","sourceRoot":"","sources":["../src/user-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAE7B;;OAEG;IACH,GAAG,CAAC,EAAE;QACL;;;;;WAKG;QACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE;YAAE,WAAW,EAAE,OAAO,CAAC,eAAe,CAAA;SAAE,KAAK,OAAO,CAAC;KACxE,CAAC;IAEF;;OAEG;IACH,MAAM,CAAC,EAAE;QACR;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;IAEF;;OAEG;IACH,YAAY,CAAC,EAAE;QACd
|
|
1
|
+
{"version":3,"file":"user-config.d.ts","sourceRoot":"","sources":["../src/user-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAE7B;;OAEG;IACH,GAAG,CAAC,EAAE;QACL;;;;;WAKG;QACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE;YAAE,WAAW,EAAE,OAAO,CAAC,eAAe,CAAA;SAAE,KAAK,OAAO,CAAC;KACxE,CAAC;IAEF;;OAEG;IACH,MAAM,CAAC,EAAE;QACR;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;IAEF;;OAEG;IACH,KAAK,CAAC,EAAE;QACP;;;;;;;;;;;;;WAaG;QACH,QAAQ,CAAC,EAAE;YACV;;eAEG;YACH,MAAM,CAAC,EAAE,OAAO,CAAC;YAGjB;;eAEG;YACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;YAEnB;;eAEG;YACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;SACnB,CAAC;KACF,CAAC;IAEF;;OAEG;IACH,YAAY,CAAC,EAAE;QACd;;;WAGG;QACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;KAOhC,CAAC;CACF"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { type ViteDevServer } from 'vite';
|
|
2
|
+
import type { RoutesManifest } from '../../routes/route.js';
|
|
2
3
|
import type { GracileConfig } from '../../user-config.js';
|
|
3
|
-
export declare const buildRoutes: ({ viteServerForBuild, root, gracileConfig, serverMode, }: {
|
|
4
|
+
export declare const buildRoutes: ({ routes, viteServerForBuild, root, gracileConfig, serverMode, }: {
|
|
5
|
+
routes: RoutesManifest;
|
|
4
6
|
viteServerForBuild: ViteDevServer;
|
|
5
7
|
root: string;
|
|
6
8
|
gracileConfig: GracileConfig;
|
|
7
9
|
serverMode?: boolean;
|
|
8
10
|
}) => Promise<{
|
|
9
|
-
routes:
|
|
11
|
+
routes: RoutesManifest;
|
|
10
12
|
renderedRoutes: import("../../build/static.js").RenderedRouteDefinition[];
|
|
11
13
|
inputList: string[];
|
|
12
14
|
plugin: ({
|
|
@@ -15,10 +17,12 @@ export declare const buildRoutes: ({ viteServerForBuild, root, gracileConfig, se
|
|
|
15
17
|
enforce: "pre";
|
|
16
18
|
resolveId(this: import("rollup").PluginContext, id: string): string | null;
|
|
17
19
|
load(this: import("rollup").PluginContext, id: string): string | null;
|
|
20
|
+
buildStart?: never;
|
|
18
21
|
generateBundle?: never;
|
|
19
22
|
} | {
|
|
20
23
|
name: string;
|
|
21
24
|
enforce: "post";
|
|
25
|
+
buildStart(this: import("rollup").PluginContext): void;
|
|
22
26
|
generateBundle(this: import("rollup").PluginContext, _: import("rollup").NormalizedOutputOptions, bundle: import("rollup").OutputBundle): void;
|
|
23
27
|
apply?: never;
|
|
24
28
|
resolveId?: never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-routes.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/build-routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build-routes.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/build-routes.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;AAOrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,eAAO,MAAM,WAAW,qEAMrB;IACF,MAAM,EAAE,cAAc,CAAC;IACvB,kBAAkB,EAAE,aAAa,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;;;;;;;;;;;;;;;;;;;;;EA4KA,CAAC"}
|
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
import {} from '
|
|
1
|
+
import { basename, extname, join } from 'node:path';
|
|
2
|
+
import { createFilter } from 'vite';
|
|
2
3
|
import { renderRoutes } from '../../build/static.js';
|
|
3
4
|
import { REGEX_TAG_LINK, REGEX_TAG_SCRIPT, } from '../../render/route-template.js';
|
|
4
|
-
export const buildRoutes = async ({ viteServerForBuild, root, gracileConfig, serverMode = false, }) => {
|
|
5
|
+
export const buildRoutes = async ({ routes, viteServerForBuild, root, gracileConfig, serverMode = false, }) => {
|
|
5
6
|
// TODO: extract upstream, return just the plugins
|
|
6
|
-
const { renderedRoutes
|
|
7
|
+
const { renderedRoutes } = await renderRoutes({
|
|
7
8
|
vite: viteServerForBuild,
|
|
8
9
|
serverMode,
|
|
9
10
|
root,
|
|
10
11
|
gracileConfig,
|
|
12
|
+
routes,
|
|
11
13
|
});
|
|
12
14
|
const inputList = renderedRoutes
|
|
13
15
|
.filter((i) => i.html)
|
|
14
16
|
.map((input) => input.name);
|
|
17
|
+
const premisesFilter = gracileConfig.pages?.premises?.expose
|
|
18
|
+
? createFilter(gracileConfig.pages.premises.include, gracileConfig.pages.premises.exclude)
|
|
19
|
+
: null;
|
|
20
|
+
if (gracileConfig.pages?.premises?.expose && premisesFilter) {
|
|
21
|
+
inputList.forEach((input) => {
|
|
22
|
+
if (premisesFilter(input) === false)
|
|
23
|
+
return;
|
|
24
|
+
inputList.push(input
|
|
25
|
+
.replace(/index\.html$/, '__index.doc.html')
|
|
26
|
+
.replace(/404\.html$/, '__404.doc.html')
|
|
27
|
+
.replace(/500\.html$/, '__500.doc.html'));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
15
30
|
return {
|
|
16
31
|
routes,
|
|
17
32
|
renderedRoutes,
|
|
@@ -21,43 +36,36 @@ export const buildRoutes = async ({ viteServerForBuild, root, gracileConfig, ser
|
|
|
21
36
|
name: 'gracile-html-routes',
|
|
22
37
|
apply: 'build',
|
|
23
38
|
enforce: 'pre',
|
|
24
|
-
// config() {
|
|
25
|
-
// return {
|
|
26
|
-
// build: { rollupOptions: { input: inputList } },
|
|
27
|
-
// };
|
|
28
|
-
// },
|
|
29
|
-
// NOTE: NOT WORKING. Must be done in the config, before.
|
|
30
|
-
// config: {
|
|
31
|
-
// order: 'pre',
|
|
32
|
-
// handler(config) {
|
|
33
|
-
// if (config.build?.rollupOptions) {
|
|
34
|
-
// // eslint-disable-next-line no-param-reassign
|
|
35
|
-
// }
|
|
36
|
-
// // eslint-disable-next-line no-param-reassign
|
|
37
|
-
// config.build ||= {};
|
|
38
|
-
// // eslint-disable-next-line no-param-reassign
|
|
39
|
-
// config.build.rollupOptions ||= {};
|
|
40
|
-
// // eslint-disable-next-line no-param-reassign
|
|
41
|
-
// config.build.rollupOptions.input = inputList;
|
|
42
|
-
// return {
|
|
43
|
-
// build: { rollupOptions: { input: inputList } },
|
|
44
|
-
// };
|
|
45
|
-
// // return
|
|
46
|
-
// },
|
|
47
|
-
// },
|
|
48
39
|
resolveId(id) {
|
|
49
|
-
if (id
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return input.absoluteId;
|
|
40
|
+
if (extname(id) === '.html') {
|
|
41
|
+
if (inputList.find((i) => i === id))
|
|
42
|
+
return join(root, id);
|
|
53
43
|
}
|
|
54
44
|
return null;
|
|
55
45
|
},
|
|
56
46
|
load(id) {
|
|
57
|
-
if (id
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
47
|
+
if (extname(id) === '.html') {
|
|
48
|
+
if (['index.html', '404.html', '500.html'].includes(basename(id))) {
|
|
49
|
+
const content = renderedRoutes.find((i) => i.absoluteId === id)?.html;
|
|
50
|
+
if (content)
|
|
51
|
+
return content;
|
|
52
|
+
}
|
|
53
|
+
if (gracileConfig.pages?.premises?.expose) {
|
|
54
|
+
if (basename(id).endsWith('doc.html')) {
|
|
55
|
+
const content = renderedRoutes.find((i) => {
|
|
56
|
+
return (i.absoluteId
|
|
57
|
+
.replace(/index\.html$/, '__index.doc.html')
|
|
58
|
+
.replace(/404\.html$/, '__404.doc.html')
|
|
59
|
+
.replace(/500\.html$/, '__500.doc.html') === id);
|
|
60
|
+
})?.static.document;
|
|
61
|
+
if (content)
|
|
62
|
+
return content;
|
|
63
|
+
}
|
|
64
|
+
const content = renderedRoutes.find((i) => i.name === basename(id))?.html;
|
|
65
|
+
if (content)
|
|
66
|
+
return content;
|
|
67
|
+
// return '';}
|
|
68
|
+
}
|
|
61
69
|
}
|
|
62
70
|
return null;
|
|
63
71
|
},
|
|
@@ -65,6 +73,28 @@ export const buildRoutes = async ({ viteServerForBuild, root, gracileConfig, ser
|
|
|
65
73
|
{
|
|
66
74
|
name: 'gracile-collect-handler-assets',
|
|
67
75
|
enforce: 'post',
|
|
76
|
+
buildStart() {
|
|
77
|
+
if (!gracileConfig.pages?.premises?.expose || !premisesFilter)
|
|
78
|
+
return;
|
|
79
|
+
renderedRoutes.forEach((route) => {
|
|
80
|
+
if (premisesFilter(route.name) === false)
|
|
81
|
+
return;
|
|
82
|
+
if (serverMode && route.savePrerender !== true)
|
|
83
|
+
return;
|
|
84
|
+
const fileNameParts = route.name.split('/');
|
|
85
|
+
const last = fileNameParts.pop();
|
|
86
|
+
const newName = last?.replace(/(.*)\.html$/, (_, r) => `__${r}.props.json`);
|
|
87
|
+
if (!newName)
|
|
88
|
+
throw new Error();
|
|
89
|
+
fileNameParts.push(newName);
|
|
90
|
+
const fileName = fileNameParts.join('/');
|
|
91
|
+
this.emitFile({
|
|
92
|
+
fileName,
|
|
93
|
+
type: 'asset',
|
|
94
|
+
source: JSON.stringify(route.static.props ?? {}),
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
},
|
|
68
98
|
generateBundle(_, bundle) {
|
|
69
99
|
if (serverMode === false)
|
|
70
100
|
return;
|
|
@@ -86,6 +116,9 @@ export const buildRoutes = async ({ viteServerForBuild, root, gracileConfig, ser
|
|
|
86
116
|
// NOTE: Not used (for now?)
|
|
87
117
|
// file.source = alteredContent;
|
|
88
118
|
const route = renderedRoutes.find((r) => {
|
|
119
|
+
if (gracileConfig.pages?.premises?.expose)
|
|
120
|
+
return (`/${r.name}` ===
|
|
121
|
+
`/${fileKey}`.replace(/(.*?)\/__(.*?)\.doc\.html$/, (a, b, c) => `${b}/${c}.html`));
|
|
89
122
|
return r.name === fileKey;
|
|
90
123
|
});
|
|
91
124
|
if (route)
|
|
@@ -93,6 +126,7 @@ export const buildRoutes = async ({ viteServerForBuild, root, gracileConfig, ser
|
|
|
93
126
|
if (route?.savePrerender !== true) {
|
|
94
127
|
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-dynamic-delete
|
|
95
128
|
delete bundle[fileKey];
|
|
129
|
+
// NOTE: Not sure if it's useful
|
|
96
130
|
if (route?.html)
|
|
97
131
|
route.html = null;
|
|
98
132
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RenderedRouteDefinition } from '../../build/static.js';
|
|
2
2
|
import type { RoutesManifest } from '../../routes/route.js';
|
|
3
|
+
import type { GracileConfig } from '../../user-config.js';
|
|
3
4
|
export declare function virtualRoutes({ routes, renderedRoutes, }: {
|
|
4
5
|
routes: RoutesManifest;
|
|
5
6
|
renderedRoutes: RenderedRouteDefinition[];
|
|
@@ -8,4 +9,13 @@ export declare function virtualRoutes({ routes, renderedRoutes, }: {
|
|
|
8
9
|
resolveId(this: import("rollup").PluginContext, id: string): "\0gracile:routes" | null;
|
|
9
10
|
load(this: import("rollup").PluginContext, id: string): string | null;
|
|
10
11
|
}[];
|
|
12
|
+
export declare function virtualRoutesClient({ routes: routesMap, mode, gracileConfig, }: {
|
|
13
|
+
routes: RoutesManifest;
|
|
14
|
+
mode: 'static' | 'server';
|
|
15
|
+
gracileConfig: GracileConfig;
|
|
16
|
+
}): {
|
|
17
|
+
name: string;
|
|
18
|
+
resolveId(this: import("rollup").PluginContext, id: string): "\0gracile:client:routes" | null;
|
|
19
|
+
load(this: import("rollup").PluginContext, id: string): string | null;
|
|
20
|
+
}[];
|
|
11
21
|
//# sourceMappingURL=virtual-routes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-routes.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/virtual-routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"virtual-routes.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/virtual-routes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,wBAAgB,aAAa,CAAC,EAE7B,MAAM,EACN,cAAc,GACd,EAAE;IAEF,MAAM,EAAE,cAAc,CAAC;IACvB,cAAc,EAAE,uBAAuB,EAAE,CAAC;CAC1C;;;;IA2EA;AAKD,wBAAgB,mBAAmB,CAAC,EACnC,MAAM,EAAE,SAAS,EACjB,IAAe,EACf,aAAa,GACb,EAAE;IACF,MAAM,EAAE,cAAc,CAAC;IACvB,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,aAAa,EAAE,aAAa,CAAC;CAC7B;;;;IA4DA"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { normalizeToPosix } from '@gracile/internal-utils/paths';
|
|
2
|
+
import { createFilter } from 'vite';
|
|
1
3
|
export function virtualRoutes({
|
|
2
4
|
// root,
|
|
3
5
|
routes, renderedRoutes, }) {
|
|
@@ -26,16 +28,20 @@ routes, renderedRoutes, }) {
|
|
|
26
28
|
return `
|
|
27
29
|
import { URLPattern } from '@gracile/gracile/url-pattern';
|
|
28
30
|
|
|
29
|
-
const routes = new Map(${
|
|
31
|
+
const routes = new Map(${
|
|
32
|
+
//
|
|
33
|
+
JSON.stringify(routesWithoutPrerender, null, 2).replaceAll(
|
|
34
|
+
// NOTE: Not strictly necessary, but just in case.
|
|
35
|
+
'"pattern": {}', '"pattern": null')})
|
|
30
36
|
routes.forEach((route, pattern) => {
|
|
31
37
|
route.pattern = new URLPattern(pattern, 'http://gracile');
|
|
32
38
|
});
|
|
33
39
|
|
|
34
40
|
const routeImports = new Map(
|
|
35
41
|
[
|
|
36
|
-
|
|
37
|
-
.map(([pattern, route]) => `['${pattern}', () => import('/${route.filePath}')],`)
|
|
38
|
-
.join('\n')}
|
|
42
|
+
${routesWithoutPrerender
|
|
43
|
+
.map(([pattern, route]) => `['${pattern}', () => import('/${normalizeToPosix(route.filePath)}')],`)
|
|
44
|
+
.join('\n ')}
|
|
39
45
|
]
|
|
40
46
|
);
|
|
41
47
|
|
|
@@ -57,3 +63,49 @@ export { routes, routeImports, routeAssets };
|
|
|
57
63
|
},
|
|
58
64
|
];
|
|
59
65
|
}
|
|
66
|
+
// TODO: move to CSR package?
|
|
67
|
+
// It's very tiny and can act as a stub.
|
|
68
|
+
// Could be documented for user, too? For allowing custom implementations.
|
|
69
|
+
export function virtualRoutesClient({ routes: routesMap, mode = 'server', gracileConfig, }) {
|
|
70
|
+
const virtualModuleId = 'gracile:client:routes';
|
|
71
|
+
const resolvedVirtualModuleId = `\0${virtualModuleId}`;
|
|
72
|
+
const enabled = gracileConfig.pages?.premises?.expose;
|
|
73
|
+
const premisesFilter = createFilter(gracileConfig.pages?.premises?.include, gracileConfig.pages?.premises?.exclude);
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
name: 'gracile-client-routes',
|
|
77
|
+
// TODO: Proper invalidation!
|
|
78
|
+
resolveId(id) {
|
|
79
|
+
if (id === virtualModuleId) {
|
|
80
|
+
return resolvedVirtualModuleId;
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
},
|
|
84
|
+
load(id) {
|
|
85
|
+
if (id === resolvedVirtualModuleId) {
|
|
86
|
+
if (!routesMap || routesMap.size < 1)
|
|
87
|
+
return '';
|
|
88
|
+
const routes = [...routesMap].filter((r) => premisesFilter(r[1].filePath));
|
|
89
|
+
return `
|
|
90
|
+
const routeImports = new Map(
|
|
91
|
+
[
|
|
92
|
+
${enabled
|
|
93
|
+
? routes
|
|
94
|
+
.map(([pattern, route]) => `['${pattern}', () => import('/${normalizeToPosix(route.filePath)}')],`)
|
|
95
|
+
.join('\n ')
|
|
96
|
+
: '/* DISABLED */'}
|
|
97
|
+
]
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
export const enabled = ${enabled};
|
|
101
|
+
|
|
102
|
+
export const mode = '${mode}';
|
|
103
|
+
|
|
104
|
+
export { routeImports };
|
|
105
|
+
`;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gracile/engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-next.1",
|
|
4
4
|
"description": "A thin, full-stack, web framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"custom-elements",
|
|
@@ -29,13 +29,11 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": "./dist/index.js",
|
|
31
31
|
"./*": "./dist/*.js",
|
|
32
|
-
"./ambient":
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"development": "./dist/dev/server.js",
|
|
38
|
-
"default": "./dist/server/server.js"
|
|
32
|
+
"./ambient": "./ambient.d.ts",
|
|
33
|
+
"./server/*": {
|
|
34
|
+
"types": "./dist/server/*.js",
|
|
35
|
+
"development": "./dist/server/*.js",
|
|
36
|
+
"default": "./dist/server/*.js"
|
|
39
37
|
}
|
|
40
38
|
},
|
|
41
39
|
"files": [
|
|
@@ -45,11 +43,12 @@
|
|
|
45
43
|
"!/dist/typedoc-entrypoint.*"
|
|
46
44
|
],
|
|
47
45
|
"dependencies": {
|
|
46
|
+
"@gracile-labs/better-errors": "^0.1.0-next.0",
|
|
48
47
|
"@gracile/client": "^0.3.1",
|
|
49
|
-
"@gracile/internal-utils": "^0.
|
|
48
|
+
"@gracile/internal-utils": "^0.4.0-next.0",
|
|
50
49
|
"@whatwg-node/server": "^0.9.25",
|
|
51
50
|
"fdir": "^6.2.0",
|
|
52
|
-
"picocolors": "^1.0.
|
|
51
|
+
"picocolors": "^1.0.1",
|
|
53
52
|
"urlpattern-polyfill": "^10.0.0",
|
|
54
53
|
"vite": "^5.3.5"
|
|
55
54
|
},
|
|
@@ -75,5 +74,5 @@
|
|
|
75
74
|
"vite-plugin-standard-css-modules": "^0.0.10",
|
|
76
75
|
"vite-plugin-web-components-hmr-local": "link:../../../../../__forks/vite-plugin-web-components-hmr/packages/dev-server-hmr"
|
|
77
76
|
},
|
|
78
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "eb666d5de119a919c30846412cf3c5301200f9bd"
|
|
79
78
|
}
|
package/dist/assertions.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type ServerRenderedTemplate } from '@lit-labs/ssr';
|
|
2
|
-
import type { TemplateResult } from 'lit';
|
|
3
|
-
export type UnknownObject = Record<string, unknown>;
|
|
4
|
-
/**
|
|
5
|
-
* Used for user provided modules with unknown/possibly malformed shapes.
|
|
6
|
-
* Avoid this for well typed sources.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isUnknownObject(input: unknown): input is UnknownObject;
|
|
9
|
-
export declare function isLitTemplate(input: unknown): input is TemplateResult<1> | ServerRenderedTemplate;
|
|
10
|
-
export declare function isLitNormalTemplate(input: unknown): input is TemplateResult<1>;
|
|
11
|
-
export declare function isLitServerTemplate(input: unknown): input is ServerRenderedTemplate;
|
|
12
|
-
export declare function isResponseOrPatchedResponse(input: unknown): input is Response;
|
|
13
|
-
//# sourceMappingURL=assertions.d.ts.map
|
package/dist/assertions.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../src/assertions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAE1C,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED,wBAAgB,aAAa,CAC5B,KAAK,EAAE,OAAO,GACZ,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,sBAAsB,CAWrD;AAED,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,OAAO,GACZ,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC,CAE5B;AAED,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,OAAO,GACZ,KAAK,IAAI,sBAAsB,CAOjC;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAoB7E"}
|
package/dist/assertions.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {} from '@lit-labs/ssr';
|
|
2
|
-
/**
|
|
3
|
-
* Used for user provided modules with unknown/possibly malformed shapes.
|
|
4
|
-
* Avoid this for well typed sources.
|
|
5
|
-
*/
|
|
6
|
-
export function isUnknownObject(input) {
|
|
7
|
-
return typeof input === 'object' && input !== null && !Array.isArray(input);
|
|
8
|
-
}
|
|
9
|
-
export function isLitTemplate(input) {
|
|
10
|
-
return ((typeof input === 'object' &&
|
|
11
|
-
input &&
|
|
12
|
-
'_$litType$' in input &&
|
|
13
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
14
|
-
input._$litType$ === 1 &&
|
|
15
|
-
'strings' in input &&
|
|
16
|
-
Array.isArray(input.strings)) ||
|
|
17
|
-
false);
|
|
18
|
-
}
|
|
19
|
-
export function isLitNormalTemplate(input) {
|
|
20
|
-
return isLitTemplate(input) && '_$litServerRenderMode' in input === false;
|
|
21
|
-
}
|
|
22
|
-
export function isLitServerTemplate(input) {
|
|
23
|
-
return (isLitTemplate(input) &&
|
|
24
|
-
'_$litServerRenderMode' in input &&
|
|
25
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
26
|
-
input._$litServerRenderMode === 1);
|
|
27
|
-
}
|
|
28
|
-
export function isResponseOrPatchedResponse(input) {
|
|
29
|
-
if (input instanceof Response)
|
|
30
|
-
return true;
|
|
31
|
-
// NOTE: We have to use that because Hono breaks with `Response.json`
|
|
32
|
-
// (IDK why, maybe some global patching somewhere,
|
|
33
|
-
// not found in the Hono codebase).
|
|
34
|
-
if (input &&
|
|
35
|
-
typeof input === 'object' &&
|
|
36
|
-
input.constructor.name === 'Response' &&
|
|
37
|
-
'url' in input &&
|
|
38
|
-
'body' in input &&
|
|
39
|
-
'bodyUsed' in input &&
|
|
40
|
-
'headers' in input &&
|
|
41
|
-
'status' in input &&
|
|
42
|
-
'statusText' in input)
|
|
43
|
-
return true;
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/errors/templates.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,kDASvC;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,kDAyDrC"}
|
package/dist/errors/templates.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { html } from '@lit-labs/ssr';
|
|
2
|
-
export function errorInline(error) {
|
|
3
|
-
return html `<!-- --></a>
|
|
4
|
-
<div data-ssr-error>
|
|
5
|
-
<strong style="color: red">SSR Template error!</strong>
|
|
6
|
-
<details>
|
|
7
|
-
<summary style="user-select: none; cursor: pointer">Stack trace</summary>
|
|
8
|
-
<pre style="overflow: auto">${error.stack}</pre>
|
|
9
|
-
</details>
|
|
10
|
-
</div>`;
|
|
11
|
-
}
|
|
12
|
-
export function errorPage(error) {
|
|
13
|
-
return html `
|
|
14
|
-
<!-- -->
|
|
15
|
-
|
|
16
|
-
<!doctype html>
|
|
17
|
-
<html lang="en">
|
|
18
|
-
<head>
|
|
19
|
-
<meta charset="UTF-8" />
|
|
20
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
21
|
-
|
|
22
|
-
<title>Error</title>
|
|
23
|
-
</head>
|
|
24
|
-
<body>
|
|
25
|
-
<style>
|
|
26
|
-
html {
|
|
27
|
-
color-scheme: dark;
|
|
28
|
-
font-size: 16px;
|
|
29
|
-
line-height: 1.23rem;
|
|
30
|
-
font-family: system-ui;
|
|
31
|
-
}
|
|
32
|
-
body {
|
|
33
|
-
padding: 1rem;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
pre {
|
|
37
|
-
padding: 1rem;
|
|
38
|
-
|
|
39
|
-
overflow-y: auto;
|
|
40
|
-
}
|
|
41
|
-
button {
|
|
42
|
-
font-size: 2rem;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
h1 {
|
|
46
|
-
color: tomato;
|
|
47
|
-
}
|
|
48
|
-
</style>
|
|
49
|
-
|
|
50
|
-
<main>
|
|
51
|
-
<h1>😵 An error has occurred!</h1>
|
|
52
|
-
<button id="reload">Reload</button>
|
|
53
|
-
<!-- -->
|
|
54
|
-
<hr />
|
|
55
|
-
|
|
56
|
-
<pre>${error.stack}</pre>
|
|
57
|
-
<!-- <pre>$ {e.name}</pre> -->
|
|
58
|
-
<!-- <pre>$ {e.message}</pre> -->
|
|
59
|
-
<!-- <pre>$ {e.cause}</pre> -->
|
|
60
|
-
<hr />
|
|
61
|
-
</main>
|
|
62
|
-
|
|
63
|
-
<script>
|
|
64
|
-
reload.addEventListener('click', () => document.location.reload());
|
|
65
|
-
</script>
|
|
66
|
-
</body>
|
|
67
|
-
</html>
|
|
68
|
-
`;
|
|
69
|
-
}
|