@gracile/engine 0.7.1 → 0.8.0-next.0

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.
Files changed (64) hide show
  1. package/ambient.d.ts +16 -0
  2. package/dist/dev/{dev.d.ts → development.d.ts} +2 -2
  3. package/dist/dev/development.d.ts.map +1 -0
  4. package/dist/dev/{dev.js → development.js} +6 -6
  5. package/dist/dev/route-typings.d.ts.map +1 -1
  6. package/dist/dev/route-typings.js +3 -8
  7. package/dist/errors/create-vite-better-error.d.ts.map +1 -1
  8. package/dist/errors/create-vite-better-error.js +1 -3
  9. package/dist/errors/errors-data.d.ts +2 -2
  10. package/dist/errors/errors-data.d.ts.map +1 -1
  11. package/dist/errors/errors.d.ts +3 -3
  12. package/dist/errors/errors.d.ts.map +1 -1
  13. package/dist/errors/errors.js +7 -8
  14. package/dist/errors/pages.d.ts +2 -2
  15. package/dist/errors/pages.d.ts.map +1 -1
  16. package/dist/errors/pages.js +4 -4
  17. package/dist/plugin.d.ts +1 -2
  18. package/dist/plugin.d.ts.map +1 -1
  19. package/dist/plugin.js +17 -16
  20. package/dist/render/route-template.d.ts.map +1 -1
  21. package/dist/render/route-template.js +54 -54
  22. package/dist/render/utils.d.ts +1 -1
  23. package/dist/render/utils.d.ts.map +1 -1
  24. package/dist/routes/collect.d.ts.map +1 -1
  25. package/dist/routes/collect.js +31 -34
  26. package/dist/routes/comparator.d.ts.map +1 -1
  27. package/dist/routes/comparator.js +5 -6
  28. package/dist/routes/load-module.d.ts.map +1 -1
  29. package/dist/routes/load-module.js +12 -12
  30. package/dist/routes/match.d.ts +2 -2
  31. package/dist/routes/match.d.ts.map +1 -1
  32. package/dist/routes/match.js +18 -21
  33. package/dist/{build/static.d.ts → routes/render.d.ts} +2 -2
  34. package/dist/routes/render.d.ts.map +1 -0
  35. package/dist/{build/static.js → routes/render.js} +34 -29
  36. package/dist/routes/route.d.ts +5 -5
  37. package/dist/routes/route.d.ts.map +1 -1
  38. package/dist/routes/route.js +1 -1
  39. package/dist/server/adapters/hono.d.ts +3 -3
  40. package/dist/server/adapters/hono.d.ts.map +1 -1
  41. package/dist/server/adapters/hono.js +3 -2
  42. package/dist/server/adapters/node.d.ts +5 -5
  43. package/dist/server/adapters/node.d.ts.map +1 -1
  44. package/dist/server/adapters/node.js +25 -21
  45. package/dist/server/request.d.ts.map +1 -1
  46. package/dist/server/request.js +9 -11
  47. package/dist/server/utils.d.ts +0 -1
  48. package/dist/server/utils.d.ts.map +1 -1
  49. package/dist/server/utils.js +14 -17
  50. package/dist/vite/{plugins/build-routes.d.ts → build-routes.d.ts} +3 -3
  51. package/dist/vite/build-routes.d.ts.map +1 -0
  52. package/dist/vite/{plugins/build-routes.js → build-routes.js} +24 -29
  53. package/dist/vite/html-routes.d.ts +10 -0
  54. package/dist/vite/html-routes.d.ts.map +1 -0
  55. package/dist/vite/html-routes.js +25 -0
  56. package/dist/vite/{plugins/virtual-routes.d.ts → virtual-routes.d.ts} +6 -3
  57. package/dist/vite/virtual-routes.d.ts.map +1 -0
  58. package/dist/vite/{plugins/virtual-routes.js → virtual-routes.js} +15 -17
  59. package/package.json +8 -9
  60. package/dist/build/static.d.ts.map +0 -1
  61. package/dist/dev/dev.d.ts.map +0 -1
  62. package/dist/tsconfig.tsbuildinfo +0 -1
  63. package/dist/vite/plugins/build-routes.d.ts.map +0 -1
  64. package/dist/vite/plugins/virtual-routes.d.ts.map +0 -1
package/ambient.d.ts CHANGED
@@ -8,5 +8,21 @@
8
8
  // }
9
9
 
10
10
  declare namespace Gracile {
11
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
11
12
  interface Locals {}
12
13
  }
14
+
15
+ declare module 'gracile:client:routes' {
16
+ export const enabled: boolean;
17
+
18
+ export const mode: 'static' | 'server';
19
+
20
+ export const routeImports: Map<
21
+ string,
22
+ () => Promise<{
23
+ default: (
24
+ routeModule: typeof import('@gracile/engine/routes/route').RouteModule,
25
+ ) => import('@gracile/engine/routes/route').RouteModule;
26
+ }>
27
+ >;
28
+ }
@@ -2,7 +2,7 @@ import { type ViteDevServer } from 'vite';
2
2
  import type { RoutesManifest } from '../routes/route.js';
3
3
  import { type GracileHandler } from '../server/request.js';
4
4
  import type { GracileConfig } from '../user-config.js';
5
- export declare function createDevHandler({ routes, vite, gracileConfig, }: {
5
+ export declare function createDevelopmentHandler({ routes, vite, gracileConfig, }: {
6
6
  routes: RoutesManifest;
7
7
  vite: ViteDevServer;
8
8
  gracileConfig: GracileConfig;
@@ -10,4 +10,4 @@ export declare function createDevHandler({ routes, vite, gracileConfig, }: {
10
10
  handler: GracileHandler;
11
11
  routes: RoutesManifest;
12
12
  }>;
13
- //# sourceMappingURL=dev.d.ts.map
13
+ //# sourceMappingURL=development.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"development.d.ts","sourceRoot":"","sources":["../../src/dev/development.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAEN,KAAK,cAAc,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIvD,wBAAsB,wBAAwB,CAAC,EAC9C,MAAM,EACN,IAAI,EACJ,aAAa,GACb,EAAE;IACF,MAAM,EAAE,cAAc,CAAC;IACvB,IAAI,EAAE,aAAa,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;CAC7B,GAAG,OAAO,CAAC;IACX,OAAO,EAAE,cAAc,CAAC;IACxB,MAAM,EAAE,cAAc,CAAC;CACvB,CAAC,CAgDD"}
@@ -4,32 +4,32 @@ import {} from 'vite';
4
4
  import { collectRoutes, WATCHED_FILES_REGEX } from '../routes/collect.js';
5
5
  import { createGracileHandler, } from '../server/request.js';
6
6
  import { generateRoutesTypings } from './route-typings.js';
7
- export async function createDevHandler({ routes, vite, gracileConfig, }) {
7
+ export async function createDevelopmentHandler({ routes, vite, gracileConfig, }) {
8
8
  const logger = getLogger();
9
9
  const root = vite.config.root;
10
10
  logger.info('');
11
11
  logger.info(c.dim('Creating the request handler…'), { timestamp: true });
12
- const collect = async () => {
12
+ const collectAndCodegen = async () => {
13
13
  await collectRoutes(routes, root, gracileConfig.routes?.exclude);
14
14
  if (gracileConfig.experimental?.generateRoutesTypings)
15
15
  await generateRoutesTypings(root, routes).catch((error) => logger.error(String(error)));
16
16
  };
17
- await collect();
17
+ await collectAndCodegen();
18
18
  let wait;
19
19
  vite.watcher.on('all', (event, file) => {
20
- if (file.match(WATCHED_FILES_REGEX) &&
20
+ if (WATCHED_FILES_REGEX.test(file) &&
21
21
  ['add', 'unlink'].includes(event)
22
22
  //
23
23
  ) {
24
24
  clearTimeout(wait);
25
25
  wait = setTimeout(() => {
26
- collect()
26
+ collectAndCodegen()
27
27
  .then(() => vite.hot.send('vite:invalidate'))
28
28
  .catch((error) => logger.error(String(error)));
29
29
  }, 100);
30
30
  }
31
31
  });
32
- //
32
+ // ---
33
33
  // NOTE: Wrong place?
34
34
  const serverMode = false;
35
35
  const gracile = createGracileHandler({
@@ -1 +1 @@
1
- {"version":3,"file":"route-typings.d.ts","sourceRoot":"","sources":["../../src/dev/route-typings.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,wBAAsB,qBAAqB,CAC1C,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,cAAc,iBAiCtB"}
1
+ {"version":3,"file":"route-typings.d.ts","sourceRoot":"","sources":["../../src/dev/route-typings.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,wBAAsB,qBAAqB,CAC1C,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,cAAc,iBAiCtB"}
@@ -1,6 +1,5 @@
1
- import { mkdir } from 'node:fs/promises';
1
+ import { mkdir, writeFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
- import { writeFile } from 'fs/promises';
4
3
  export async function generateRoutesTypings(root, routes) {
5
4
  // NOTE: For future, we'll provide parameters like:
6
5
  // `route('/blog/:id', { id: 'foo' })`.
@@ -14,12 +13,8 @@ export async function generateRoutesTypings(root, routes) {
14
13
  export type Route =
15
14
  | ${[...routes]
16
15
  .map(([v]) => `\`${v
17
- .replace(/\{:(.*)\}/,
18
- // eslint-disable-next-line no-template-curly-in-string
19
- '${string}')
20
- .replace(/:(.*?)\*\//,
21
- // eslint-disable-next-line no-template-curly-in-string
22
- '${string}')}\``)
16
+ .replace(/{:(.*)}/, '${string}')
17
+ .replace(/:(.*?)\*\//, '${string}')}\``)
23
18
  .join('\n | ')};
24
19
  `;
25
20
  await mkdir(join(root, '.gracile')).catch(() => null);
@@ -1 +1 @@
1
- {"version":3,"file":"create-vite-better-error.d.ts","sourceRoot":"","sources":["../../src/errors/create-vite-better-error.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,MAAM,CAAC;AAQxD,wBAAsB,mBAAmB,CAAC,EACzC,KAAK,EACL,IAAI,GACJ,EAAE;IACF,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;CACpB,mBA6BA"}
1
+ {"version":3,"file":"create-vite-better-error.d.ts","sourceRoot":"","sources":["../../src/errors/create-vite-better-error.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,MAAM,CAAC;AASxD,wBAAsB,mBAAmB,CAAC,EACzC,KAAK,EACL,IAAI,GACJ,EAAE;IACF,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,aAAa,CAAC;CACpB,mBA2BA"}
@@ -9,9 +9,7 @@ import { builtInErrorPage } from './pages.js';
9
9
  const logger = getLogger();
10
10
  export async function emitViteBetterError({ error, vite, }) {
11
11
  const errorWithMetadata = collectErrorMetadata(error, pathToFileURL(vite.config.root));
12
- logger.error(formatErrorMessage(errorWithMetadata, false, GracileErrorData, GRACILE_JS_ERRORS_DOCS_BASE), {
13
- timestamp: true,
14
- });
12
+ logger.error(formatErrorMessage(errorWithMetadata, false, GracileErrorData, GRACILE_JS_ERRORS_DOCS_BASE), { timestamp: true });
15
13
  const payload = await getViteErrorPayload({
16
14
  docsBaseUrl: GRACILE_JS_ERRORS_DOCS_BASE,
17
15
  errorsData: GracileErrorData,
@@ -1,8 +1,8 @@
1
1
  export interface ErrorData {
2
2
  name: string;
3
3
  title: string;
4
- message?: string | ((...params: any) => string) | undefined;
5
- hint?: string | ((...params: any) => string) | undefined;
4
+ message?: string | ((...parameters: any) => string) | undefined;
5
+ hint?: string | ((...parameters: any) => string) | undefined;
6
6
  }
7
7
  /**
8
8
  * @docs
@@ -1 +1 @@
1
- {"version":3,"file":"errors-data.d.ts","sourceRoot":"","sources":["../../src/errors/errors-data.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;IAC5D,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;CACzD;AAED;;;;GAIG;AAGH;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;mCAGX,MAAM;;CAEC,CAAC;AAC/B;;GAEG;AAgBH;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;oCAGZ,MAAM;;CAGA,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;oCAGb,MAAM;;CAGA,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;kCAGX,MAAM;;CAGE,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;kCAGjB,MAAM;;CAGE,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;kCAGT,MAAM;;CAEE,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;kCAGlB,MAAM;;CAGE,CAAC;AAC/B;;GAEG"}
1
+ {"version":3,"file":"errors-data.d.ts","sourceRoot":"","sources":["../../src/errors/errors-data.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,UAAU,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;IAChE,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,UAAU,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;CAC7D;AAED;;;;GAIG;AAGH;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;mCAGX,MAAM;;CAEC,CAAC;AAC/B;;GAEG;AAgBH;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;oCAGZ,MAAM;;CAGA,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;oCAGb,MAAM;;CAGA,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;kCAGX,MAAM;;CAGE,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;kCAGjB,MAAM;;CAGE,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;kCAGT,MAAM;;CAEE,CAAC;AAC/B;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;kCAGlB,MAAM;;CAGE,CAAC;AAC/B;;GAEG"}
@@ -4,15 +4,15 @@ export declare const GRACILE_JS_ERRORS_DOCS_BASE = "https://gracile.js.org/docs/
4
4
  type ErrorTypes = BuiltinErrorTypes | 'GracileError' | 'TemplateError' | 'InternalError' | 'TypeGuardError' | 'AggregateError';
5
5
  export declare class GracileError extends BetterError<ErrorTypes> {
6
6
  type: ErrorTypes;
7
- static is(err: unknown): err is GracileError;
7
+ static is(error: unknown): error is GracileError;
8
8
  }
9
9
  export declare class TemplateError extends GracileError {
10
10
  type: ErrorTypes;
11
- static is(err: unknown): err is TemplateError;
11
+ static is(error: unknown): error is TemplateError;
12
12
  }
13
13
  export declare class InternalError extends GracileError {
14
14
  type: ErrorTypes;
15
- static is(err: unknown): err is InternalError;
15
+ static is(error: unknown): error is InternalError;
16
16
  }
17
17
  /**
18
18
  * An error util. that should never be called in theory.
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAIA,OAAO,EACN,WAAW,EACX,KAAK,iBAAiB,EACtB,MAAM,oCAAoC,CAAC;AAI5C,OAAO,KAAK,gBAAgB,MAAM,kBAAkB,CAAC;AAErD,eAAO,MAAM,2BAA2B,kDACQ,CAAC;AAEjD,KAAK,UAAU,GACZ,iBAAiB,GACjB,cAAc,GACd,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,gBAAgB,CAAC;AAQpB,qBAAa,YAAa,SAAQ,WAAW,CAAC,UAAU,CAAC;IACxD,IAAI,EAAE,UAAU,CAAkB;IAElC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,YAAY;CAG5C;AAED,qBAAa,aAAc,SAAQ,YAAY;IAC9C,IAAI,EAAE,UAAU,CAAmB;IAEnC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,aAAa;CAG7C;AAED,qBAAa,aAAc,SAAQ,YAAY;IAC9C,IAAI,EAAE,UAAU,CAAmB;IAEnC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,aAAa;CAG7C;AAuGD;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;CAAG"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors/errors.ts"],"names":[],"mappings":"AAIA,OAAO,EACN,WAAW,EACX,KAAK,iBAAiB,EACtB,MAAM,oCAAoC,CAAC;AAI5C,OAAO,KAAK,gBAAgB,MAAM,kBAAkB,CAAC;AAErD,eAAO,MAAM,2BAA2B,kDACQ,CAAC;AAEjD,KAAK,UAAU,GACZ,iBAAiB,GACjB,cAAc,GACd,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,gBAAgB,CAAC;AAQpB,qBAAa,YAAa,SAAQ,WAAW,CAAC,UAAU,CAAC;IACxD,IAAI,EAAE,UAAU,CAAkB;IAElC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY;CAGhD;AAED,qBAAa,aAAc,SAAQ,YAAY;IAC9C,IAAI,EAAE,UAAU,CAAmB;IAEnC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa;CAGjD;AAED,qBAAa,aAAc,SAAQ,YAAY;IAC9C,IAAI,EAAE,UAAU,CAAmB;IAEnC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa;CAGjD;AAuGD;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;CAAG"}
@@ -1,5 +1,4 @@
1
- /* eslint-disable max-classes-per-file */
2
- /* eslint-disable @typescript-eslint/lines-between-class-members */
1
+ /* eslint-disable unicorn/custom-error-definition */
3
2
  // NOTE: Taken and adapted from https://github.com/withGracile/Gracile/blob/cf65476b27053333cf5a36f6f9f46b794c98dfa2/packages/Gracile/src/core/errors/errors.ts
4
3
  import { BetterError, } from '@gracile-labs/better-errors/errors';
5
4
  // import { codeFrame } from '@gracile-labs/better-errors/printer';
@@ -12,20 +11,20 @@ export const GRACILE_JS_ERRORS_DOCS_BASE = 'https://gracile.js.org/docs/referenc
12
11
  // | 'MarkdownError'
13
12
  export class GracileError extends BetterError {
14
13
  type = 'GracileError';
15
- static is(err) {
16
- return err.type === 'GracileError';
14
+ static is(error) {
15
+ return error.type === 'GracileError';
17
16
  }
18
17
  }
19
18
  export class TemplateError extends GracileError {
20
19
  type = 'TemplateError';
21
- static is(err) {
22
- return err.type === 'TemplateError';
20
+ static is(error) {
21
+ return error.type === 'TemplateError';
23
22
  }
24
23
  }
25
24
  export class InternalError extends GracileError {
26
25
  type = 'InternalError';
27
- static is(err) {
28
- return err.type === 'InternalError';
26
+ static is(error) {
27
+ return error.type === 'InternalError';
29
28
  }
30
29
  }
31
30
  //
@@ -1,4 +1,4 @@
1
1
  export declare function errorInline(error: Error): import("@lit-labs/ssr").ServerRenderedTemplate;
2
- export declare function builtIn404Page(path: string, dev?: boolean): import("@lit-labs/ssr").ServerRenderedTemplate;
3
- export declare function builtInErrorPage(name?: string, dev?: boolean): import("@lit-labs/ssr").ServerRenderedTemplate;
2
+ export declare function builtIn404Page(path: string, development?: boolean): import("@lit-labs/ssr").ServerRenderedTemplate;
3
+ export declare function builtInErrorPage(name?: string, development?: boolean): import("@lit-labs/ssr").ServerRenderedTemplate;
4
4
  //# sourceMappingURL=pages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../../src/errors/pages.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,kDASvC;AAgBD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAQ,kDAwFvD;AAOD,wBAAgB,gBAAgB,CAAC,IAAI,SAAU,EAAE,GAAG,UAAQ,kDAoB3D"}
1
+ {"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../../src/errors/pages.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,kDASvC;AAgBD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,UAAQ,kDAwF/D;AAOD,wBAAgB,gBAAgB,CAAC,IAAI,SAAU,EAAE,WAAW,UAAQ,kDAoBnE"}
@@ -20,7 +20,7 @@ const minimalStyles = () => html `<style>
20
20
  const logo = () =>
21
21
  /* prettier-ignore */
22
22
  html `<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2" viewBox="0 0 630 630"><g transform="matrix(.877 .23499 -.25635 .95673 119.498 -60.39)"><circle cx="315" cy="315" r="315" style="fill:url(#a)"/><path d="M315 0c173.853 0 315 141.147 315 315S488.853 630 315 630 0 488.853 0 315 141.147 0 315 0Zm0 13.125c166.309 0 300.682 135.566 300.682 301.875S481.309 616.875 315 616.875C148.691 616.875 14.318 481.309 14.318 315S148.691 13.125 315 13.125Z" style="fill:#1a1a1e"/></g><path d="M.238.087A.195.195 0 0 1 .135.058.215.215 0 0 1 .06-.029a.293.293 0 0 1-.028-.135c0-.051.008-.103.024-.156a.699.699 0 0 1 .162-.278.475.475 0 0 1 .115-.089.258.258 0 0 1 .121-.032.14.14 0 0 1 .07.016c.017.011.03.026.038.044a.158.158 0 0 1 .011.058.215.215 0 0 1-.012.07.181.181 0 0 1-.034.058C.512-.458.496-.45.479-.45a.036.036 0 0 1-.022-.007.073.073 0 0 1-.02-.026.162.162 0 0 0 .034-.035.303.303 0 0 0 .032-.056.135.135 0 0 0 .014-.054.05.05 0 0 0-.012-.034C.496-.671.482-.675.463-.675a.16.16 0 0 0-.092.033.447.447 0 0 0-.091.089.764.764 0 0 0-.152.4c0 .061.013.108.04.141.026.034.057.051.094.051A.127.127 0 0 0 .338.013a.243.243 0 0 0 .061-.069.454.454 0 0 0 .062-.19.9.9 0 0 0-.051-.008 1.011 1.011 0 0 0-.056-.002H.322l-.034.002a.1.1 0 0 1 .029-.052.076.076 0 0 1 .051-.016c.02 0 .04.003.061.009a4.452 4.452 0 0 0 .123.039l-.01.031-.029.091a.854.854 0 0 0-.026.108l-.002.043.001.042.002.052C.468.09.453.085.444.076A.063.063 0 0 1 .425.044.148.148 0 0 1 .42.009v-.01l.001-.01a.317.317 0 0 1-.08.071.2.2 0 0 1-.103.027Z" style="fill-rule:nonzero" transform="translate(115.745 497.368) scale(589.0308)"/><path d="M6516.9 5139.28c-23.64 24.86-49.83 45.96-78.54 63.32-38.12 23.04-81.04 34.61-128.8 34.61-46.96 0-90.14-12.37-129.56-37.11-39.27-24.65-70.68-60.51-94.08-107.72-23.09-46.59-34.76-102.43-34.76-167.57 0-62.67 9.75-126.16 29.28-190.46 19.46-64.05 46.21-125.05 80.26-183.02 34.06-57.99 73-109.68 116.79-155.1 44.07-45.7 90.8-81.78 140.17-108.29 50.15-26.95 100.53-40.34 151.1-40.34 37.75 0 67.7 7.39 90.01 21.55 22.8 14.47 39.21 33.58 49.3 57.27 9.78 22.96 14.7 47.62 14.7 73.99 0 29.25-5.21 58.51-15.66 87.77-10.56 29.57-24.99 54.04-43.16 73.48-19.63 20.99-41.46 31.15-65.19 31.15-11.93 0-22.88-3.46-32.82-10.42-9.08-6.35-18.42-17.93-27.5-35.16-2.67-5.08-1.07-11.36 3.71-14.55 11.2-7.47 23.58-20.66 37.4-39.34 14.36-19.4 26.96-40.94 37.83-64.61 10.4-22.67 15.78-42.88 15.78-60.72 0-12.95-3.93-23.85-12.02-32.59-8.3-8.96-22.33-12.61-41.58-12.61-33.94 0-68.72 12.89-104.54 38.15-37.17 26.22-72.55 61.08-106.2 104.51-33.98 43.85-64.59 92.85-91.85 146.98-27.27 54.14-48.81 109.46-64.62 165.98-15.7 56.14-23.58 109.33-23.58 159.58 0 69.79 14.72 124.16 45.02 162.89 29.19 37.32 63.93 56.3 104.57 56.3 30.37 0 58.3-9.68 83.86-28.94 26.57-20.03 50.02-46.45 70.43-79.18 20.72-33.23 37.33-69.39 49.84-108.49 11.42-35.68 18.94-70.7 22.56-105.08-16.51-3-33.42-5.31-50.74-6.95-20.87-1.97-42.72-2.95-65.55-2.95-12.68 0-25.37.2-38.05.6-12.71.39-26.22.99-40.53 1.78a11.194 11.194 0 0 1-11.47-13.97c7.89-30.7 20.71-53.1 37.81-67.57 17.46-14.76 40.4-22.45 69.04-22.45 25.1 0 50.41 3.96 75.93 11.91 24.52 7.64 49.44 15.88 74.77 24.72 24.8 8.66 49.02 15.75 72.65 21.27 3.05.71 5.66 2.66 7.2 5.39 1.55 2.73 1.88 5.98.92 8.96 0 0-12 37.2-12.02 37.24-14.39 43.95-26.17 80.52-35.36 109.68-9.1 28.89-16.03 53.42-20.78 73.6-4.67 19.86-7.8 37.76-9.36 53.72-1.56 16.06-2.34 32.69-2.34 49.92 0 15.83.39 32.26 1.18 49.28.81 17.24 1.61 38.29 2.41 63.16.11 3.29-1.24 6.46-3.68 8.67a11.2 11.2 0 0 1-9 2.79c-26.84-3.58-46.58-11.82-59.55-23.9-13.28-12.36-21.92-26.81-26.04-43.29-3.23-12.91-5.09-25.52-5.59-37.84Zm-207.34 86.73c-44.8 0-86-11.8-123.6-35.4-37.6-23.6-67.6-58-90-103.2-22.4-45.2-33.6-99.4-33.6-162.6 0-61.6 9.6-124 28.8-187.2 19.2-63.2 45.6-123.4 79.2-180.6 33.6-57.2 72-108.2 115.2-153s89-80.2 137.4-106.2c48.4-26 97-39 145.8-39 35.2 0 63.2 6.6 84 19.8 20.8 13.2 35.8 30.6 45 52.2 9.2 21.6 13.8 44.8 13.8 69.6 0 28-5 56-15 84s-23.6 51.2-40.8 69.6c-17.2 18.4-36.2 27.6-57 27.6-9.6 0-18.4-2.8-26.4-8.4-8-5.6-16-16-24-31.2 12-8 25.4-22 40.2-42 14.8-20 27.8-42.2 39-66.6 11.2-24.4 16.8-46.2 16.8-65.4 0-16-5-29.4-15-40.2-10-10.8-26.6-16.2-49.8-16.2-36 0-73 13.4-111 40.2-38 26.8-74.2 62.4-108.6 106.8-34.4 44.4-65.4 94-93 148.8-27.6 54.8-49.4 110.8-65.4 168-16 57.2-24 111.4-24 162.6 0 72.8 15.8 129.4 47.4 169.8 31.6 40.4 69.4 60.6 113.4 60.6 32.8 0 63-10.4 90.6-31.2 27.6-20.8 52-48.2 73.2-82.2 21.2-34 38.2-71 51-111 12.8-40 20.8-79.2 24-117.6-20-4-40.6-7-61.8-9-21.2-2-43.4-3-66.6-3-12.8 0-25.6.2-38.4.6-12.8.4-26.4 1-40.8 1.8 7.2-28 18.6-48.6 34.2-61.8 15.6-13.2 36.2-19.8 61.8-19.8 24 0 48.2 3.8 72.6 11.4 24.4 7.6 49.2 15.8 74.4 24.6 25.2 8.8 49.8 16 73.8 21.6l-12 37.2c-14.4 44-26.2 80.6-35.4 109.8-9.2 29.2-16.2 54-21 74.4-4.8 20.4-8 38.8-9.6 55.2-1.6 16.4-2.4 33.4-2.4 51 0 16 .4 32.6 1.2 49.8.8 17.2 1.6 38.2 2.4 63-24-3.2-41.8-10.2-53.4-21-11.6-10.8-19.2-23.4-22.8-37.8-3.6-14.4-5.4-28.4-5.4-42v-12c0-4 .4-8 1.2-12-28 34.4-60.2 62.6-96.6 84.6-36.4 22-77.4 33-123 33Z" style="fill:#fff" transform="matrix(.49086 0 0 .49086 -2841.17 -2016.62)"/><defs><radialGradient id="a" cx="0" cy="0" r="1" gradientTransform="matrix(315 0 0 315 315 315)" gradientUnits="userSpaceOnUse"><stop offset="0" style="stop-color:white;stop-opacity:1"/><stop offset="1" style="stop-color:#57d5a3;stop-opacity:1"/></radialGradient></defs></svg>`;
23
- export function builtIn404Page(path, dev = false) {
23
+ export function builtIn404Page(path, development = false) {
24
24
  return html `
25
25
  <!doctype html>
26
26
  <html lang="en">
@@ -89,7 +89,7 @@ export function builtIn404Page(path, dev = false) {
89
89
  <pre>${path}</pre>
90
90
  </section>
91
91
 
92
- ${dev
92
+ ${development
93
93
  ? html ` <section>
94
94
  <p>The page or route may be not configured properly.</p>
95
95
 
@@ -113,7 +113,7 @@ export function builtIn404Page(path, dev = false) {
113
113
  // const ESCAPE_SEQUENCE_CHARACTER =
114
114
  // // eslint-disable-next-line no-control-regex
115
115
  // /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
116
- export function builtInErrorPage(name = 'Error', dev = false) {
116
+ export function builtInErrorPage(name = 'Error', development = false) {
117
117
  const title = `500: ${name ? `${name} | ` : ''}Internal Server Error`;
118
118
  return html `
119
119
  <!doctype html>
@@ -123,7 +123,7 @@ export function builtInErrorPage(name = 'Error', dev = false) {
123
123
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
124
124
  <title>${title}</title>
125
125
  ${minimalStyles()}
126
- ${dev
126
+ ${development
127
127
  ? html `<script type="module" src="/@vite/client"></script>`
128
128
  : null}
129
129
  </head>
package/dist/plugin.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import type { GracileConfig } from './user-config.js';
2
- export type { GracileConfig };
3
2
  /**
4
3
  * The main Vite plugin for loading the Gracile framework.
5
- *
6
4
  * @param config - Gracile configuration.
7
5
  * @returns Vite plugins. `any` is used to prevent Vite typings version mismatches for the plugin API.
8
6
  * @example
@@ -19,4 +17,5 @@ export type { GracileConfig };
19
17
  * ```
20
18
  */
21
19
  export declare const gracile: (config?: GracileConfig) => any[];
20
+ export type { GracileConfig } from './user-config.js';
22
21
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAOtD,YAAY,EAAE,aAAa,EAAE,CAAC;AAI9B;;;;;;;;;;;;;;;;;GAiBG;AAIH,eAAO,MAAM,OAAO,YAAa,aAAa,KAAG,GAAG,EAyTnD,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAOtD;;;;;;;;;;;;;;;;GAgBG;AAIH,eAAO,MAAM,OAAO,YAAa,aAAa,KAAG,GAAG,EA2TnD,CAAC;AAEF,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/plugin.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import { join } from 'node:path';
2
+ import { rename, rm } from 'node:fs/promises';
2
3
  import { createLogger } from '@gracile/internal-utils/logger/helpers';
3
4
  import { getVersion } from '@gracile/internal-utils/version';
4
5
  // import { betterErrors } from '@gracile-labs/better-errors/plugin';
5
- import { rename, rm } from 'fs/promises';
6
6
  import c from 'picocolors';
7
7
  import { build, createServer } from 'vite';
8
- import {} from './build/static.js';
9
- import { createDevHandler } from './dev/dev.js';
8
+ import {} from './routes/render.js';
9
+ import { createDevelopmentHandler } from './dev/development.js';
10
10
  import { nodeAdapter } from './server/adapters/node.js';
11
- import { buildRoutes } from './vite/plugins/build-routes.js';
12
- import { virtualRoutes, virtualRoutesClient, } from './vite/plugins/virtual-routes.js';
11
+ import { buildRoutes } from './vite/build-routes.js';
12
+ import { htmlRoutesLoader } from './vite/html-routes.js';
13
+ import { virtualRoutes, virtualRoutesClient } from './vite/virtual-routes.js';
13
14
  let isClientBuilt = false;
14
15
  /**
15
16
  * The main Vite plugin for loading the Gracile framework.
16
- *
17
17
  * @param config - Gracile configuration.
18
18
  * @returns Vite plugins. `any` is used to prevent Vite typings version mismatches for the plugin API.
19
19
  * @example
@@ -40,6 +40,7 @@ export const gracile = (config) => {
40
40
  let renderedRoutes = null;
41
41
  let root = null;
42
42
  const gracileConfig = config || {};
43
+ // NOTE: Prevent duplicate client build for the SSR build step in server mode.
43
44
  if (isClientBuilt)
44
45
  return [];
45
46
  isClientBuilt = true;
@@ -83,8 +84,8 @@ export const gracile = (config) => {
83
84
  {
84
85
  name: 'vite-plugin-gracile-serve-middleware',
85
86
  apply: 'serve',
86
- config(_, env) {
87
- if (env.isPreview)
87
+ config(_, environment) {
88
+ if (environment.isPreview)
88
89
  return null;
89
90
  return {
90
91
  // NOTE: Supresses message: `Could not auto-determine entry point from rollupOptions or html files…`
@@ -117,7 +118,7 @@ export const gracile = (config) => {
117
118
  logger.info(`${c.cyan(c.italic(c.underline('🧚 Gracile')))}` +
118
119
  ` ${c.dim(`~`)} ${c.green(`v${version ?? 'X'}`)}`);
119
120
  // ---
120
- const { handler } = await createDevHandler({
121
+ const { handler } = await createDevelopmentHandler({
121
122
  routes,
122
123
  vite: server,
123
124
  gracileConfig,
@@ -132,18 +133,19 @@ export const gracile = (config) => {
132
133
  timestamp: true,
133
134
  });
134
135
  logger.info('');
136
+ // NOTE: We want it to show after the Vite intro stuff
135
137
  }, 100);
136
- // s
137
138
  });
138
139
  return () => {
139
- server.middlewares.use((req, res, next) => {
140
- const locals = config?.dev?.locals?.({ nodeRequest: req });
141
- Promise.resolve(nodeAdapter(handler, { logger })(req, res, locals)).catch((error) => next(error));
140
+ server.middlewares.use((request, response, next) => {
141
+ const locals = config?.dev?.locals?.({ nodeRequest: request });
142
+ Promise.resolve(nodeAdapter(handler, { logger })(request, response, locals)).catch((error) => next(error));
142
143
  });
143
144
  };
144
145
  },
145
146
  },
146
147
  virtualRoutesForClient,
148
+ htmlRoutesLoader(),
147
149
  {
148
150
  name: 'vite-plugin-gracile-build',
149
151
  apply: 'build',
@@ -182,10 +184,9 @@ export const gracile = (config) => {
182
184
  writeBundle(_, bundle) {
183
185
  if (outputMode === 'static')
184
186
  return;
185
- Object.entries(bundle).forEach(([, file]) => {
187
+ for (const file of Object.values(bundle))
186
188
  if (file.type === 'asset' && file.name)
187
189
  clientAssets[file.name] = file.fileName;
188
- });
189
190
  },
190
191
  },
191
192
  {
@@ -226,7 +227,7 @@ export const gracile = (config) => {
226
227
  // NOTE: When not imported at all from client
227
228
  return `assets/${chunkInfo.name.replace(/\.(.*)$/, '')}-[hash].[ext]`;
228
229
  }
229
- // throw new Error(`Not client asset`);
230
+ // throw new Error(`Not a client asset`);
230
231
  return 'assets/[name]-[hash].[ext]';
231
232
  },
232
233
  chunkFileNames: 'chunk/[name].js',
@@ -1 +1 @@
1
- {"version":3,"file":"route-template.d.ts","sourceRoot":"","sources":["../../src/render/route-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAOvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAO1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,KAAK,CAAC,MAAM,oBAAoB,CAAC;AAa7C,eAAO,MAAM,gBAAgB,QACkC,CAAC;AAEhE,eAAO,MAAM,cAAc,QAA2B,CAAC;AAEvD,wBAAsB,mBAAmB,CAAC,EACzC,GAAG,EACH,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,WAAW,EACX,UAAU,EACV,OAAO,GACP,EAAE;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;IACtB,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,CAAC,CAAC,YAAY,GAAG,SAAS,CAAC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,IAAI,GAAG,QAAQ,CAAC;IAAC,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAA;CAAE,CAAC,CAqNhE"}
1
+ {"version":3,"file":"route-template.d.ts","sourceRoot":"","sources":["../../src/render/route-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAOvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAO1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,KAAK,CAAC,MAAM,oBAAoB,CAAC;AAY7C,eAAO,MAAM,gBAAgB,QACkC,CAAC;AAEhE,eAAO,MAAM,cAAc,QAA2B,CAAC;AAEvD,wBAAsB,mBAAmB,CAAC,EACzC,GAAG,EACH,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,WAAW,EACX,UAAU,EACV,OAAO,GACP,EAAE;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;IACtB,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,CAAC,CAAC,YAAY,GAAG,SAAS,CAAC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,IAAI,GAAG,QAAQ,CAAC;IAAC,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAA;CAAE,CAAC,CA8NhE"}
@@ -6,9 +6,7 @@ import { collectResult } from '@lit-labs/ssr/lib/render-result.js';
6
6
  import { GracileError, GracileErrorData, TemplateError, } from '../errors/errors.js';
7
7
  import { PAGE_ASSETS_MARKER, SSR_OUTLET_MARKER } from './markers.js';
8
8
  async function* concatStreams(...readables) {
9
- // eslint-disable-next-line no-restricted-syntax
10
9
  for (const readable of readables) {
11
- // eslint-disable-next-line no-restricted-syntax, no-await-in-loop
12
10
  for await (const chunk of readable) {
13
11
  yield chunk;
14
12
  }
@@ -49,54 +47,56 @@ export async function renderRouteTemplate({ url, vite, mode, routeInfos, routeAs
49
47
  message: GracileErrorData.InvalidRouteDocument.message(location.file),
50
48
  location,
51
49
  });
52
- const baseDocTemplateResult = await Promise.resolve(routeInfos.routeModule.document?.(context));
53
- if (assert.isLitServerTemplate(baseDocTemplateResult) === false)
50
+ const baseDocumentTemplateResult = await Promise.resolve(routeInfos.routeModule.document?.(context));
51
+ if (assert.isLitServerTemplate(baseDocumentTemplateResult) === false)
54
52
  throw new GracileError({
55
53
  ...GracileErrorData.InvalidRouteDocumentResult,
56
54
  message: GracileErrorData.InvalidRouteDocumentResult.message(location.file),
57
55
  location,
58
56
  });
59
- let baseDocRendered;
60
- // console.log({ ddd: baseDocTemplateResult });
57
+ let baseDocumentRendered;
61
58
  try {
62
- baseDocRendered = await collectResult(renderLitSsr(baseDocTemplateResult));
59
+ baseDocumentRendered = await collectResult(renderLitSsr(baseDocumentTemplateResult));
63
60
  }
64
- catch (e) {
61
+ catch (error) {
65
62
  throw new TemplateError({
66
63
  ...GracileErrorData.CouldNotRenderRouteDocument,
67
64
  message: GracileErrorData.CouldNotRenderRouteDocument.message(location.file),
68
65
  location,
69
- }, { cause: String(e) });
66
+ }, { cause: String(error) });
70
67
  }
71
68
  // MARK: Sibling assets
72
- let baseDocRenderedWithAssets = baseDocRendered;
73
- // If the user doesnt use `pageAssetCustomLocation`, we put this as a fallback
74
- baseDocRenderedWithAssets = baseDocRenderedWithAssets
69
+ // NOTE: If the user doesn't use `pageAssetCustomLocation`,
70
+ // we put this as a fallback.
71
+ baseDocumentRendered = baseDocumentRendered
75
72
  .replace('</head>', `\n${PAGE_ASSETS_MARKER}</head>`)
76
- .replace(PAGE_ASSETS_MARKER,
77
- // eslint-disable-next-line prefer-template
78
- routeInfos.foundRoute.pageAssets.length
79
- ? // eslint-disable-next-line prefer-template
80
- html `<!-- PAGE ASSETS -->` +
81
- `${routeInfos.foundRoute.pageAssets
82
- .map((path) => {
83
- //
84
- if (/\.(js|ts)$/.test(path)) {
85
- // prettier-ignore
86
- return html ` <script type="module" src="/${path}"></script>`;
87
- }
88
- if (/\.(css|scss|sass|less|styl|stylus)$/.test(path)) {
89
- // prettier-ignore
90
- return html ` <link rel="stylesheet" href="/${path}" />`;
91
- }
92
- // NOTE: Never called (filtered upstream in `collectRoutes`)
93
- return null;
94
- })
95
- .join('\n')}` +
96
- `<!-- /PAGE ASSETS -->\n `
73
+ .replace(PAGE_ASSETS_MARKER, routeInfos.foundRoute.pageAssets.length > 0
74
+ ? html `<!-- PAGE ASSETS -->` +
75
+ `${routeInfos.foundRoute.pageAssets
76
+ .map((path) => {
77
+ //
78
+ if (/\.(js|ts|jsx|tsx)$/.test(path)) {
79
+ // prettier-ignore
80
+ return html ` <script type="module" src="/${path}"></script>`;
81
+ }
82
+ if (/\.(css|scss|sass|less|styl|stylus)$/.test(path)) {
83
+ // prettier-ignore
84
+ return html ` <link rel="stylesheet" href="/${path}" />`;
85
+ }
86
+ // NOTE: Never called (filtered upstream in `collectRoutes`)
87
+ return null;
88
+ })
89
+ .join('\n')}` +
90
+ `<!-- /PAGE ASSETS -->\n `
97
91
  : '');
98
- // MARK: Dev. overlay
99
- // TODO: Need more testing and refinement (refreshes kills its usefulness)
92
+ // MARK: Add doctype if missing.
93
+ if (baseDocumentRendered
94
+ .trimStart()
95
+ .toLocaleLowerCase()
96
+ .startsWith('<!doctype') === false)
97
+ baseDocumentRendered = `<!doctype html>\n${baseDocumentRendered}`;
98
+ // MARK: Dev. overlay.
99
+ // TODO: Need more testing and refinement (refreshes kills its usefulness).
100
100
  const overlay = () => html `
101
101
  <script type="module">
102
102
  if (import.meta.hot) {
@@ -110,39 +110,39 @@ export async function renderRouteTemplate({ url, vite, mode, routeInfos, routeAs
110
110
  </script>
111
111
  `;
112
112
  if (mode === 'dev')
113
- baseDocRenderedWithAssets = baseDocRenderedWithAssets.replace('<head>', `<head>\n${overlay()}`);
114
- // // MARK: Inject assets for server output runtime only
113
+ baseDocumentRendered = baseDocumentRendered.replace('<head>', `<head>\n${overlay()}`);
114
+ // MARK: Inject assets for server output runtime only.
115
115
  const routeAssetsString = routeAssets?.get?.(routeInfos.foundRoute.pattern.pathname);
116
116
  if (routeAssetsString)
117
- baseDocRenderedWithAssets = baseDocRenderedWithAssets
118
- .replace(REGEX_TAG_SCRIPT, (s) => {
117
+ baseDocumentRendered = baseDocumentRendered
118
+ .replaceAll(REGEX_TAG_SCRIPT, (s) => {
119
119
  if (s.includes(`type="module"`))
120
120
  return '';
121
121
  return s;
122
122
  })
123
- .replace(REGEX_TAG_LINK, (s) => {
123
+ .replaceAll(REGEX_TAG_LINK, (s) => {
124
124
  if (s.includes(`rel="stylesheet"`))
125
125
  return '';
126
126
  return s;
127
127
  })
128
128
  .replace('</head>', `${routeAssetsString}\n</head>`);
129
129
  // MARK: Base document
130
- const baseDocHtml = vite && mode === 'dev'
130
+ const baseDocumentHtml = vite && mode === 'dev'
131
131
  ? await vite.transformIndexHtml(
132
132
  // HACK: Sometimes, we need to invalidate for server asset url
133
133
  // imports to work. So we keep this hack around just in case.
134
134
  // Maybe it's linked to the way hashed assets are invalidating
135
135
  // the html proxy module…
136
136
  // `${routeInfos.pathname}?r=${Math.random()}`,
137
- routeInfos.pathname, baseDocRenderedWithAssets)
138
- : baseDocRenderedWithAssets;
137
+ routeInfos.pathname, baseDocumentRendered)
138
+ : baseDocumentRendered;
139
139
  if (docOnly)
140
- return { document: baseDocHtml, output: null };
141
- const index = baseDocHtml.indexOf(SSR_OUTLET_MARKER);
142
- const baseDocRenderStreamPre = Readable.from(baseDocHtml.substring(0, index));
143
- const baseDocRenderStreamPost = Readable.from(baseDocHtml.substring(index + SSR_OUTLET_MARKER.length + 1));
140
+ return { document: baseDocumentHtml, output: null };
141
+ const index = baseDocumentHtml.indexOf(SSR_OUTLET_MARKER);
142
+ const baseDocumentRenderStreamPre = Readable.from(baseDocumentHtml.slice(0, Math.max(0, index)));
143
+ const baseDocumentRenderStreamPost = Readable.from(baseDocumentHtml.slice(Math.max(0, index + SSR_OUTLET_MARKER.length)));
144
144
  // MARK: Page
145
- // Skipped with server mode in production build
145
+ // Skipped with server mode in production build.
146
146
  if (routeInfos.routeModule.template &&
147
147
  (serverMode === false ||
148
148
  //
@@ -157,12 +157,12 @@ export async function renderRouteTemplate({ url, vite, mode, routeInfos, routeAs
157
157
  // return { output, document: null };
158
158
  // }
159
159
  if (assert.isLitTemplate(routeOutput) === false)
160
- throw Error(`Wrong template result for page template ${routeInfos.foundRoute.filePath}.`);
160
+ throw new Error(`Wrong template result for page template ${routeInfos.foundRoute.filePath}.`);
161
161
  const renderStream = Readable.from(renderLitSsr(routeOutput));
162
- const output = Readable.from(concatStreams(baseDocRenderStreamPre, renderStream, baseDocRenderStreamPost));
163
- return { output, document: baseDocHtml };
162
+ const output = Readable.from(concatStreams(baseDocumentRenderStreamPre, renderStream, baseDocumentRenderStreamPost));
163
+ return { output, document: baseDocumentHtml };
164
164
  }
165
- // MARK: Just the document
166
- const output = Readable.from(baseDocHtml);
167
- return { output, document: baseDocHtml };
165
+ // MARK: Just the document.
166
+ const output = Readable.from(baseDocumentHtml);
167
+ return { output, document: baseDocumentHtml };
168
168
  }
@@ -22,5 +22,5 @@ import type { TemplateResult } from 'lit';
22
22
  * assert.match(result, /Hello/);
23
23
  * ```
24
24
  */
25
- export declare function renderLitTemplate(template: ServerRenderedTemplate | TemplateResult<1>): Promise<string>;
25
+ export declare function renderLitTemplate(template: ServerRenderedTemplate | TemplateResult): Promise<string>;
26
26
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/render/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,sBAAsB,EAC3B,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,iBAAiB,CACtC,QAAQ,EAAE,sBAAsB,GAAG,cAAc,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,MAAM,CAAC,CAEjB"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/render/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,sBAAsB,EAC3B,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,iBAAiB,CACtC,QAAQ,EAAE,sBAAsB,GAAG,cAAc,GAC/C,OAAO,CAAC,MAAM,CAAC,CAEjB"}
@@ -1 +1 @@
1
- {"version":3,"file":"collect.d.ts","sourceRoot":"","sources":["../../src/routes/collect.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,KAAK,CAAC,MAAM,YAAY,CAAC;AAuDrC,eAAO,MAAM,mBAAmB,QAC+B,CAAC;AAGhE,wBAAsB,aAAa,CAClC,MAAM,EAAE,CAAC,CAAC,cAAc,EACxB,IAAI,EAAE,MAAM,EACZ,eAAe,GAAE,MAAM,EAAO,GAE5B,OAAO,CAAC,IAAI,CAAC,CAoGf"}
1
+ {"version":3,"file":"collect.d.ts","sourceRoot":"","sources":["../../src/routes/collect.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,KAAK,CAAC,MAAM,YAAY,CAAC;AA0DrC,eAAO,MAAM,mBAAmB,QAC4C,CAAC;AAE7E,wBAAsB,aAAa,CAClC,MAAM,EAAE,CAAC,CAAC,cAAc,EACxB,IAAI,EAAE,MAAM,EACZ,eAAe,GAAE,MAAM,EAAO,GAC5B,OAAO,CAAC,IAAI,CAAC,CAiGf"}