@gracile/engine 0.9.0-next.4 β†’ 0.9.0-next.6

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 (42) hide show
  1. package/dist/dev/development.d.ts.map +1 -1
  2. package/dist/dev/development.js +1 -1
  3. package/dist/plugin.d.ts.map +1 -1
  4. package/dist/plugin.js +37 -262
  5. package/dist/render/route-template-pipeline.d.ts +64 -0
  6. package/dist/render/route-template-pipeline.d.ts.map +1 -0
  7. package/dist/render/route-template-pipeline.js +144 -0
  8. package/dist/render/route-template.d.ts +1 -2
  9. package/dist/render/route-template.d.ts.map +1 -1
  10. package/dist/render/route-template.js +17 -93
  11. package/dist/routes/collect.d.ts +5 -1
  12. package/dist/routes/collect.d.ts.map +1 -1
  13. package/dist/routes/collect.js +8 -6
  14. package/dist/routes/match.d.ts +31 -1
  15. package/dist/routes/match.d.ts.map +1 -1
  16. package/dist/routes/match.js +22 -4
  17. package/dist/routes/render.d.ts.map +1 -1
  18. package/dist/routes/render.js +9 -2
  19. package/dist/server/request-pipeline.d.ts +109 -0
  20. package/dist/server/request-pipeline.d.ts.map +1 -0
  21. package/dist/server/request-pipeline.js +198 -0
  22. package/dist/server/request.d.ts +3 -16
  23. package/dist/server/request.d.ts.map +1 -1
  24. package/dist/server/request.js +74 -171
  25. package/dist/test/init.d.ts +2 -0
  26. package/dist/test/init.d.ts.map +1 -0
  27. package/dist/test/init.js +7 -0
  28. package/dist/user-config.d.ts +13 -0
  29. package/dist/user-config.d.ts.map +1 -1
  30. package/dist/vite/plugin-client-build.d.ts +16 -0
  31. package/dist/vite/plugin-client-build.d.ts.map +1 -0
  32. package/dist/vite/plugin-client-build.js +49 -0
  33. package/dist/vite/plugin-serve.d.ts +18 -0
  34. package/dist/vite/plugin-serve.d.ts.map +1 -0
  35. package/dist/vite/plugin-serve.js +62 -0
  36. package/dist/vite/plugin-server-build.d.ts +33 -0
  37. package/dist/vite/plugin-server-build.d.ts.map +1 -0
  38. package/dist/vite/plugin-server-build.js +157 -0
  39. package/dist/vite/plugin-shared-state.d.ts +31 -0
  40. package/dist/vite/plugin-shared-state.d.ts.map +1 -0
  41. package/dist/vite/plugin-shared-state.js +22 -0
  42. package/package.json +4 -4
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Vite plugin: development server middleware.
3
+ *
4
+ * Sets up the Gracile request handler, route watcher, and dev-time
5
+ * logging for `vite dev`.
6
+ *
7
+ * @internal
8
+ */
9
+ import type { Logger, PluginOption } from 'vite';
10
+ import type { GracileConfig } from '../user-config.js';
11
+ import type { PluginSharedState } from './plugin-shared-state.js';
12
+ export declare function gracileServePlugin({ state, config, logger, resetClientBuiltFlag, }: {
13
+ state: PluginSharedState;
14
+ config: GracileConfig | undefined;
15
+ logger: Logger;
16
+ resetClientBuiltFlag: () => void;
17
+ }): PluginOption;
18
+ //# sourceMappingURL=plugin-serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-serve.d.ts","sourceRoot":"","sources":["../../src/vite/plugin-serve.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAIjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,wBAAgB,kBAAkB,CAAC,EAClC,KAAK,EACL,MAAM,EACN,MAAM,EACN,oBAAoB,GACpB,EAAE;IACF,KAAK,EAAE,iBAAiB,CAAC;IACzB,MAAM,EAAE,aAAa,GAAG,SAAS,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,EAAE,MAAM,IAAI,CAAC;CACjC,GAAG,YAAY,CA6Df"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Vite plugin: development server middleware.
3
+ *
4
+ * Sets up the Gracile request handler, route watcher, and dev-time
5
+ * logging for `vite dev`.
6
+ *
7
+ * @internal
8
+ */
9
+ import { getVersion } from '@gracile/internal-utils/version';
10
+ import c from 'picocolors';
11
+ import { createDevelopmentHandler } from '../dev/development.js';
12
+ import { nodeAdapter } from '../server/adapters/node.js';
13
+ export function gracileServePlugin({ state, config, logger, resetClientBuiltFlag, }) {
14
+ return {
15
+ name: 'vite-plugin-gracile-serve-middleware',
16
+ apply: 'serve',
17
+ config(_, environment) {
18
+ if (environment.isPreview)
19
+ return null;
20
+ return {
21
+ // NOTE: Supresses message: `Could not auto-determine entry point from rollupOptions or html files…`
22
+ // FIXME: It's not working when reloading the Vite config.
23
+ // Is user config, putting `optimizeDeps: { include: [] }` solve this.
24
+ optimizeDeps: { include: [] },
25
+ // NOTE: Useful? It breaks preview (expected)
26
+ appType: 'custom',
27
+ };
28
+ },
29
+ async configureServer(server) {
30
+ // HACK: We know we are in dev here, this will prevent incorrect
31
+ // vite.config hot reloading. Will be removed when adopting env. API.
32
+ resetClientBuiltFlag();
33
+ const version = getVersion();
34
+ logger.info(`${c.cyan(c.italic(c.underline('🧚 Gracile')))}` +
35
+ ` ${c.dim(`~`)} ${c.green(`v${version ?? 'X'}`)}`);
36
+ const { handler } = await createDevelopmentHandler({
37
+ routes: state.routes,
38
+ vite: server,
39
+ gracileConfig: state.gracileConfig,
40
+ });
41
+ logger.info(c.dim('Vite development server is starting…'), {
42
+ timestamp: true,
43
+ });
44
+ server.watcher.on('ready', () => {
45
+ setTimeout(() => {
46
+ logger.info('');
47
+ logger.info(c.green('Watching for file changes…'), {
48
+ timestamp: true,
49
+ });
50
+ logger.info('');
51
+ // NOTE: We want it to show after the Vite intro stuff
52
+ }, 100);
53
+ });
54
+ return () => {
55
+ server.middlewares.use((request, response, next) => {
56
+ const locals = config?.dev?.locals?.({ nodeRequest: request });
57
+ Promise.resolve(nodeAdapter(handler, { logger })(request, response, locals)).catch((error) => next(error));
58
+ });
59
+ };
60
+ },
61
+ };
62
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Vite plugins: server-side build pipeline.
3
+ *
4
+ * After the client build completes, these plugins run a nested
5
+ * `vite build` in SSR mode to produce the server entrypoint.
6
+ *
7
+ * Includes:
8
+ * - Client asset filename collector (from the client writeBundle)
9
+ * - Server build trigger (closeBundle)
10
+ * - Virtual entrypoint codegen
11
+ * - Server-to-client asset mover
12
+ *
13
+ * @internal
14
+ */
15
+ import { type PluginOption } from 'vite';
16
+ import type { PluginSharedState } from './plugin-shared-state.js';
17
+ /**
18
+ * Tracks client bundle assets so the server build can reference them
19
+ * with their hashed filenames.
20
+ */
21
+ export declare function gracileCollectClientAssetsPlugin({ state, }: {
22
+ state: PluginSharedState;
23
+ }): PluginOption;
24
+ /**
25
+ * After the client build finishes (`closeBundle`), run a nested SSR
26
+ * build that produces the server entrypoint and moves assets back into
27
+ * the client output directory.
28
+ */
29
+ export declare function gracileServerBuildPlugin({ state, virtualRoutesForClient, }: {
30
+ state: PluginSharedState;
31
+ virtualRoutesForClient: PluginOption;
32
+ }): PluginOption;
33
+ //# sourceMappingURL=plugin-server-build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-server-build.d.ts","sourceRoot":"","sources":["../../src/vite/plugin-server-build.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AAGhD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAIlE;;;GAGG;AACH,wBAAgB,gCAAgC,CAAC,EAChD,KAAK,GACL,EAAE;IACF,KAAK,EAAE,iBAAiB,CAAC;CACzB,GAAG,YAAY,CAYf;AAID;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,EACxC,KAAK,EACL,sBAAsB,GACtB,EAAE;IACF,KAAK,EAAE,iBAAiB,CAAC;IACzB,sBAAsB,EAAE,YAAY,CAAC;CACrC,GAAG,YAAY,CAqEf"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Vite plugins: server-side build pipeline.
3
+ *
4
+ * After the client build completes, these plugins run a nested
5
+ * `vite build` in SSR mode to produce the server entrypoint.
6
+ *
7
+ * Includes:
8
+ * - Client asset filename collector (from the client writeBundle)
9
+ * - Server build trigger (closeBundle)
10
+ * - Virtual entrypoint codegen
11
+ * - Server-to-client asset mover
12
+ *
13
+ * @internal
14
+ */
15
+ import { join } from 'node:path';
16
+ import { rename, rm } from 'node:fs/promises';
17
+ import { build } from 'vite';
18
+ import { virtualRoutes } from './virtual-routes.js';
19
+ // ── Client asset collector ───────────────────────────────────────────
20
+ /**
21
+ * Tracks client bundle assets so the server build can reference them
22
+ * with their hashed filenames.
23
+ */
24
+ export function gracileCollectClientAssetsPlugin({ state, }) {
25
+ return {
26
+ name: 'vite-plugin-gracile-collect-client-assets-for-server',
27
+ writeBundle(_, bundle) {
28
+ if (state.outputMode === 'static')
29
+ return;
30
+ for (const file of Object.values(bundle))
31
+ if (file.type === 'asset' && file.name)
32
+ state.clientAssets[file.name] = file.fileName;
33
+ },
34
+ };
35
+ }
36
+ // ── Server build trigger ─────────────────────────────────────────────
37
+ /**
38
+ * After the client build finishes (`closeBundle`), run a nested SSR
39
+ * build that produces the server entrypoint and moves assets back into
40
+ * the client output directory.
41
+ */
42
+ export function gracileServerBuildPlugin({ state, virtualRoutesForClient, }) {
43
+ return {
44
+ name: 'vite-plugin-gracile-server-build',
45
+ apply: 'build',
46
+ config(viteConfig) {
47
+ state.root = viteConfig.root || null;
48
+ },
49
+ async closeBundle() {
50
+ if (state.outputMode === 'static' ||
51
+ !state.routes ||
52
+ !state.renderedRoutes)
53
+ return;
54
+ const root = state.root || process.cwd();
55
+ await build({
56
+ root,
57
+ ssr: { external: ['@gracile/gracile'] },
58
+ build: {
59
+ target: 'esnext',
60
+ ssr: true,
61
+ copyPublicDir: false,
62
+ outDir: 'dist/server',
63
+ ssrEmitAssets: true,
64
+ cssMinify: true,
65
+ cssCodeSplit: true,
66
+ rollupOptions: {
67
+ input: 'entrypoint.js',
68
+ output: {
69
+ entryFileNames: '[name].js',
70
+ assetFileNames: (chunkInfo) => {
71
+ if (chunkInfo.name) {
72
+ const fileName = state.clientAssets[chunkInfo.name];
73
+ if (fileName)
74
+ return fileName;
75
+ // NOTE: When not imported at all from client
76
+ return `assets/${chunkInfo.name.replace(/\.(.*)$/, '')}-[hash].[ext]`;
77
+ }
78
+ return 'assets/[name]-[hash].[ext]';
79
+ },
80
+ chunkFileNames: 'chunk/[name].js',
81
+ },
82
+ },
83
+ },
84
+ plugins: [
85
+ virtualRoutesForClient,
86
+ virtualRoutes({
87
+ routes: state.routes,
88
+ renderedRoutes: state.renderedRoutes,
89
+ }),
90
+ gracileEntrypointPlugin(state),
91
+ gracileMoveServerAssetsPlugin(state),
92
+ ],
93
+ });
94
+ },
95
+ };
96
+ }
97
+ // ── Virtual entrypoint ───────────────────────────────────────────────
98
+ /**
99
+ * Generates the virtual `entrypoint.js` module for the server build.
100
+ * This is the server's main entry: it imports routes and creates the
101
+ * Gracile handler.
102
+ */
103
+ function gracileEntrypointPlugin(state) {
104
+ return {
105
+ name: 'vite-plugin-gracile-entry',
106
+ resolveId(id) {
107
+ if (id === 'entrypoint.js') {
108
+ return id;
109
+ }
110
+ return null;
111
+ },
112
+ load(id) {
113
+ if (id === 'entrypoint.js' && state.routes && state.renderedRoutes) {
114
+ return `
115
+ import { routeAssets, routeImports, routes } from 'gracile:routes';
116
+ import { createGracileHandler } from '@gracile/gracile/_internals/server-runtime';
117
+ import { createLogger } from '@gracile/gracile/_internals/logger';
118
+
119
+ createLogger();
120
+
121
+ export const handler = createGracileHandler({
122
+ root: process.cwd(),
123
+ routes,
124
+ routeImports,
125
+ routeAssets,
126
+ serverMode: true,
127
+ gracileConfig: ${JSON.stringify(state.gracileConfig, null, 2)}
128
+ });
129
+ `;
130
+ }
131
+ return null;
132
+ },
133
+ };
134
+ }
135
+ // ── Server asset mover ───────────────────────────────────────────────
136
+ /**
137
+ * After the server build writes its bundle, move any assets from
138
+ * `dist/server/assets/` into `dist/client/assets/` so the client
139
+ * can serve them.
140
+ */
141
+ function gracileMoveServerAssetsPlugin(state) {
142
+ return {
143
+ name: 'gracile-move-server-assets',
144
+ async writeBundle(_, bundle) {
145
+ const cwd = state.root || process.cwd();
146
+ await Promise.all(Object.entries(bundle).map(async ([file]) => {
147
+ if (file.startsWith('assets/') === false)
148
+ return;
149
+ await rename(join(cwd, `/dist/server/${file}`), join(cwd, `/dist/client/${file}`));
150
+ }));
151
+ // NOTE: Disabled for now, because it conflict with test's folder comparer
152
+ await rm(join(cwd, `/dist/server/assets`), {
153
+ recursive: true,
154
+ }).catch(() => null);
155
+ },
156
+ };
157
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Shared mutable state passed between the Gracile Vite plugin phases.
3
+ *
4
+ * This exists because Vite plugins in the same array share data through
5
+ * closures. Making the shared state explicit (instead of ad-hoc `let`
6
+ * variables) makes the data flow between plugins visible and auditable.
7
+ *
8
+ * @internal
9
+ */
10
+ import type { RenderedRouteDefinition } from '../routes/render.js';
11
+ import type { RoutesManifest } from '../routes/route.js';
12
+ import type { GracileConfig } from '../user-config.js';
13
+ export interface PluginSharedState {
14
+ /** Collected file-system routes (populated during dev and build). */
15
+ routes: RoutesManifest;
16
+ /** Rendered route definitions from the client build phase. */
17
+ renderedRoutes: RenderedRouteDefinition[] | null;
18
+ /** Maps original asset names β†’ hashed filenames from the client bundle. */
19
+ clientAssets: Record<string, string>;
20
+ /** Vite `root` captured during build config. */
21
+ root: string | null;
22
+ /** The resolved Gracile configuration. */
23
+ gracileConfig: GracileConfig;
24
+ /** The output mode: 'static' or 'server'. */
25
+ outputMode: 'static' | 'server';
26
+ }
27
+ /**
28
+ * Create a fresh shared state object.
29
+ */
30
+ export declare function createPluginSharedState(config: GracileConfig | undefined): PluginSharedState;
31
+ //# sourceMappingURL=plugin-shared-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-shared-state.d.ts","sourceRoot":"","sources":["../../src/vite/plugin-shared-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,WAAW,iBAAiB;IACjC,qEAAqE;IACrE,MAAM,EAAE,cAAc,CAAC;IAEvB,8DAA8D;IAC9D,cAAc,EAAE,uBAAuB,EAAE,GAAG,IAAI,CAAC;IAEjD,2EAA2E;IAC3E,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAErC,gDAAgD;IAChD,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpB,0CAA0C;IAC1C,aAAa,EAAE,aAAa,CAAC;IAE7B,6CAA6C;IAC7C,UAAU,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAChC;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,aAAa,GAAG,SAAS,GAC/B,iBAAiB,CASnB"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Shared mutable state passed between the Gracile Vite plugin phases.
3
+ *
4
+ * This exists because Vite plugins in the same array share data through
5
+ * closures. Making the shared state explicit (instead of ad-hoc `let`
6
+ * variables) makes the data flow between plugins visible and auditable.
7
+ *
8
+ * @internal
9
+ */
10
+ /**
11
+ * Create a fresh shared state object.
12
+ */
13
+ export function createPluginSharedState(config) {
14
+ return {
15
+ routes: new Map(),
16
+ renderedRoutes: null,
17
+ clientAssets: {},
18
+ root: null,
19
+ gracileConfig: config || {},
20
+ outputMode: config?.output || 'static',
21
+ };
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gracile/engine",
3
- "version": "0.9.0-next.4",
3
+ "version": "0.9.0-next.6",
4
4
  "description": "A thin, full-stack, web framework",
5
5
  "keywords": [
6
6
  "custom-elements",
@@ -43,8 +43,8 @@
43
43
  "!/dist/typedoc-entrypoint.*"
44
44
  ],
45
45
  "dependencies": {
46
- "@gracile-labs/better-errors": "^0.2.0-next.4",
47
- "@gracile/internal-utils": "^0.6.0-next.3",
46
+ "@gracile-labs/better-errors": "^0.2.1-next.0",
47
+ "@gracile/internal-utils": "^0.6.1-next.0",
48
48
  "@whatwg-node/server": "^0.10.18",
49
49
  "fdir": "^6.5.0",
50
50
  "picocolors": "^1.1.1",
@@ -60,5 +60,5 @@
60
60
  "access": "public",
61
61
  "provenance": true
62
62
  },
63
- "gitHead": "a7441bf4d5c390521a9789077568619ca90ae623"
63
+ "gitHead": "a83e253566cdeb19aa75c7d0a686e3e52e921eed"
64
64
  }