@solidjs/start 2.0.0-beta.1 → 2.0.0-beta.2
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/CHANGELOG.md +7 -0
- package/dist/client/StartClient.d.ts +7 -0
- package/{src/client/StartClient.tsx → dist/client/StartClient.jsx} +7 -15
- package/dist/client/index.jsx +2 -0
- package/dist/client/mount.d.ts +1 -0
- package/dist/client/mount.js +1 -0
- package/dist/client/spa/index.d.ts +4 -0
- package/dist/client/spa/index.jsx +5 -0
- package/dist/config/constants.d.ts +16 -0
- package/dist/config/constants.js +16 -0
- package/dist/config/dev-server.d.ts +2 -0
- package/dist/config/dev-server.js +128 -0
- package/dist/config/env.d.ts +19 -0
- package/dist/config/env.js +81 -0
- package/dist/config/fs-router.d.ts +37 -0
- package/dist/config/fs-router.js +141 -0
- package/dist/config/fs-routes/fs-watcher.d.ts +3 -0
- package/dist/config/fs-routes/fs-watcher.js +53 -0
- package/dist/config/fs-routes/index.d.ts +7 -0
- package/dist/config/fs-routes/index.js +107 -0
- package/dist/config/fs-routes/router.d.ts +42 -0
- package/dist/config/fs-routes/router.js +148 -0
- package/dist/config/fs-routes/tree-shake.d.ts +2 -0
- package/dist/config/fs-routes/tree-shake.js +305 -0
- package/dist/config/index.d.ts +25 -0
- package/dist/config/index.js +217 -0
- package/dist/config/lazy.d.ts +3 -0
- package/dist/config/lazy.js +114 -0
- package/dist/config/manifest.d.ts +3 -0
- package/dist/config/manifest.js +109 -0
- package/dist/config/utils.d.ts +4 -0
- package/dist/config/utils.js +6 -0
- package/dist/config/vite-utils.d.ts +21 -0
- package/dist/config/vite-utils.js +85 -0
- package/dist/directives/bubble-function-declaration.d.ts +3 -0
- package/dist/directives/bubble-function-declaration.js +23 -0
- package/dist/directives/compile.d.ts +9 -0
- package/dist/directives/compile.js +40 -0
- package/dist/directives/generate-unique-name.d.ts +3 -0
- package/dist/directives/generate-unique-name.js +16 -0
- package/dist/directives/get-descriptive-name.d.ts +2 -0
- package/dist/directives/get-descriptive-name.js +37 -0
- package/dist/directives/get-import-identifier.d.ts +4 -0
- package/dist/directives/get-import-identifier.js +19 -0
- package/dist/directives/get-root-statement-path.d.ts +2 -0
- package/dist/directives/get-root-statement-path.js +12 -0
- package/dist/directives/index.d.ts +14 -0
- package/dist/directives/index.js +170 -0
- package/dist/directives/is-statement-top-level.d.ts +3 -0
- package/dist/directives/is-statement-top-level.js +9 -0
- package/dist/directives/paths.d.ts +9 -0
- package/dist/directives/paths.js +36 -0
- package/dist/directives/plugin.d.ts +21 -0
- package/dist/directives/plugin.js +302 -0
- package/dist/directives/remove-unused-variables.d.ts +3 -0
- package/dist/directives/remove-unused-variables.js +66 -0
- package/{src/directives/types.ts → dist/directives/types.d.ts} +5 -7
- package/dist/directives/types.js +1 -0
- package/dist/directives/xxhash32.d.ts +6 -0
- package/dist/directives/xxhash32.js +193 -0
- package/dist/fns/client.d.ts +3 -0
- package/dist/fns/client.js +106 -0
- package/dist/fns/handler.d.ts +5 -0
- package/dist/fns/handler.js +269 -0
- package/dist/fns/registration.d.ts +2 -0
- package/dist/fns/registration.js +12 -0
- package/dist/fns/serialization.d.ts +6 -0
- package/dist/fns/serialization.js +208 -0
- package/dist/fns/server.d.ts +7 -0
- package/dist/fns/server.js +38 -0
- package/dist/fns/shared.d.ts +17 -0
- package/dist/fns/shared.js +105 -0
- package/dist/http/index.d.ts +81 -0
- package/dist/http/index.js +129 -0
- package/{src/index.tsx → dist/index.d.ts} +0 -2
- package/dist/index.jsx +6 -0
- package/dist/middleware/index.d.ts +38 -0
- package/dist/middleware/index.js +59 -0
- package/dist/router.d.ts +6 -0
- package/dist/router.jsx +29 -0
- package/dist/server/StartServer.d.ts +9 -0
- package/dist/server/StartServer.jsx +34 -0
- package/dist/server/assets/PatchVirtualDevStyles.d.ts +4 -0
- package/{src/server/assets/PatchVirtualDevStyles.tsx → dist/server/assets/PatchVirtualDevStyles.jsx} +7 -10
- package/dist/server/assets/index.d.ts +2 -0
- package/dist/server/assets/index.js +52 -0
- package/dist/server/assets/render.d.ts +19 -0
- package/dist/server/assets/render.jsx +14 -0
- package/dist/server/collect-styles.d.ts +3 -0
- package/dist/server/collect-styles.js +57 -0
- package/dist/server/fetchEvent.d.ts +7 -0
- package/dist/server/fetchEvent.js +26 -0
- package/dist/server/handler.d.ts +64 -0
- package/dist/server/handler.js +222 -0
- package/dist/server/index.d.ts +9 -0
- package/{src/server/index.tsx → dist/server/index.jsx} +4 -19
- package/dist/server/manifest/client-manifest.d.ts +9 -0
- package/dist/server/manifest/client-manifest.js +6 -0
- package/dist/server/manifest/dev-client-manifest.d.ts +4 -0
- package/dist/server/manifest/dev-client-manifest.js +24 -0
- package/dist/server/manifest/dev-ssr-manifest.d.ts +5 -0
- package/dist/server/manifest/dev-ssr-manifest.js +23 -0
- package/dist/server/manifest/prod-client-manifest.d.ts +5 -0
- package/dist/server/manifest/prod-client-manifest.js +26 -0
- package/dist/server/manifest/prod-ssr-manifest.d.ts +6 -0
- package/dist/server/manifest/prod-ssr-manifest.js +85 -0
- package/dist/server/manifest/ssr-manifest.d.ts +4 -0
- package/dist/server/manifest/ssr-manifest.js +6 -0
- package/dist/server/routes.d.ts +23 -0
- package/dist/server/routes.js +74 -0
- package/dist/server/spa/StartServer.d.ts +9 -0
- package/dist/server/spa/StartServer.jsx +25 -0
- package/dist/server/spa/handler.d.ts +36 -0
- package/dist/server/spa/handler.js +20 -0
- package/{src/server/spa/index.tsx → dist/server/spa/index.d.ts} +0 -1
- package/dist/server/spa/index.jsx +5 -0
- package/dist/server/types.d.ts +75 -0
- package/dist/server/types.js +1 -0
- package/dist/server/util.d.ts +2 -0
- package/dist/server/util.js +8 -0
- package/dist/shared/ErrorBoundary.d.ts +3 -0
- package/dist/shared/ErrorBoundary.jsx +36 -0
- package/dist/shared/GET.d.ts +5 -0
- package/dist/shared/GET.js +8 -0
- package/dist/shared/HttpHeader.d.ts +10 -0
- package/dist/shared/HttpHeader.jsx +38 -0
- package/dist/shared/HttpStatusCode.d.ts +9 -0
- package/dist/shared/HttpStatusCode.js +18 -0
- package/dist/shared/clientOnly.d.ts +12 -0
- package/dist/shared/clientOnly.js +27 -0
- package/dist/shared/dev-overlay/CodeView.d.ts +7 -0
- package/dist/shared/dev-overlay/CodeView.jsx +62 -0
- package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +9 -0
- package/dist/shared/dev-overlay/DevOverlayDialog.jsx +226 -0
- package/dist/shared/dev-overlay/createStackFrame.d.ts +9 -0
- package/dist/shared/dev-overlay/createStackFrame.js +56 -0
- package/dist/shared/dev-overlay/download.d.ts +1 -0
- package/dist/shared/dev-overlay/download.js +6 -0
- package/dist/shared/dev-overlay/get-source-map.d.ts +2 -0
- package/dist/shared/dev-overlay/get-source-map.js +25 -0
- package/dist/shared/dev-overlay/icons.d.ts +28 -0
- package/dist/shared/dev-overlay/icons.jsx +150 -0
- package/dist/shared/dev-overlay/index.d.ts +5 -0
- package/dist/shared/dev-overlay/index.jsx +39 -0
- package/dist/shared/lazy.d.ts +3 -0
- package/dist/shared/lazy.js +42 -0
- package/dist/shared/serverFunction.d.ts +6 -0
- package/dist/shared/serverFunction.js +8 -0
- package/dist/utils/debounce.d.ts +4 -0
- package/dist/utils/debounce.js +10 -0
- package/package.json +7 -2
- package/scripts/build.js +0 -15
- package/scripts/validate-imports.js +0 -316
- package/src/client/mount.ts +0 -1
- package/src/client/spa/index.tsx +0 -9
- package/src/config/constants.ts +0 -19
- package/src/config/dev-server.ts +0 -161
- package/src/config/env.ts +0 -105
- package/src/config/fs-router.ts +0 -162
- package/src/config/fs-routes/fs-watcher.ts +0 -66
- package/src/config/fs-routes/index.ts +0 -136
- package/src/config/fs-routes/router.ts +0 -184
- package/src/config/fs-routes/tree-shake.ts +0 -324
- package/src/config/index.ts +0 -239
- package/src/config/lazy.ts +0 -132
- package/src/config/manifest.ts +0 -120
- package/src/config/utils.ts +0 -5
- package/src/config/vite-utils.ts +0 -113
- package/src/directives/bubble-function-declaration.ts +0 -33
- package/src/directives/compile.ts +0 -54
- package/src/directives/generate-unique-name.ts +0 -22
- package/src/directives/get-descriptive-name.ts +0 -39
- package/src/directives/get-import-identifier.ts +0 -34
- package/src/directives/get-root-statement-path.ts +0 -14
- package/src/directives/index.ts +0 -233
- package/src/directives/is-statement-top-level.ts +0 -13
- package/src/directives/paths.ts +0 -63
- package/src/directives/plugin.ts +0 -389
- package/src/directives/remove-unused-variables.ts +0 -70
- package/src/directives/xxhash32.ts +0 -214
- package/src/env.d.ts +0 -17
- package/src/fns/client.ts +0 -141
- package/src/fns/handler.spec.ts +0 -85
- package/src/fns/handler.ts +0 -287
- package/src/fns/registration.ts +0 -19
- package/src/fns/serialization.ts +0 -250
- package/src/fns/server.ts +0 -46
- package/src/fns/shared.ts +0 -116
- package/src/http/index.ts +0 -216
- package/src/internal.d.ts +0 -14
- package/src/middleware/index.ts +0 -92
- package/src/router.tsx +0 -37
- package/src/server/StartServer.tsx +0 -58
- package/src/server/assets/index.ts +0 -70
- package/src/server/assets/render.tsx +0 -46
- package/src/server/collect-styles.ts +0 -70
- package/src/server/fetchEvent.spec.ts +0 -85
- package/src/server/fetchEvent.ts +0 -36
- package/src/server/handler.ts +0 -261
- package/src/server/manifest/client-manifest.ts +0 -8
- package/src/server/manifest/dev-client-manifest.ts +0 -21
- package/src/server/manifest/dev-ssr-manifest.ts +0 -23
- package/src/server/manifest/prod-client-manifest.ts +0 -21
- package/src/server/manifest/prod-ssr-manifest.ts +0 -109
- package/src/server/manifest/ssr-manifest.ts +0 -10
- package/src/server/routes.ts +0 -126
- package/src/server/spa/StartServer.tsx +0 -42
- package/src/server/spa/handler.ts +0 -29
- package/src/server/types.ts +0 -82
- package/src/server/util.ts +0 -12
- package/src/shared/ErrorBoundary.tsx +0 -52
- package/src/shared/GET.ts +0 -8
- package/src/shared/HttpHeader.tsx +0 -42
- package/src/shared/HttpStatusCode.ts +0 -27
- package/src/shared/clientOnly.ts +0 -44
- package/src/shared/dev-overlay/CodeView.tsx +0 -90
- package/src/shared/dev-overlay/DevOverlayDialog.tsx +0 -316
- package/src/shared/dev-overlay/createStackFrame.ts +0 -74
- package/src/shared/dev-overlay/download.ts +0 -6
- package/src/shared/dev-overlay/env.d.ts +0 -4
- package/src/shared/dev-overlay/get-source-map.ts +0 -33
- package/src/shared/dev-overlay/icons.tsx +0 -456
- package/src/shared/dev-overlay/index.tsx +0 -63
- package/src/shared/lazy.ts +0 -52
- package/src/shared/serverFunction.ts +0 -10
- package/src/utils/debounce.ts +0 -10
- package/src/virtual.d.ts +0 -27
- package/tsconfig.json +0 -24
- package/vitest.config.ts +0 -9
- /package/{src/client/index.tsx → dist/client/index.d.ts} +0 -0
- /package/{src → dist}/shared/dev-overlay/styles.css +0 -0
package/src/middleware/index.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// @refresh skip
|
|
2
|
-
|
|
3
|
-
import type { H3Event, Middleware } from "h3";
|
|
4
|
-
import { getFetchEvent } from "../server/fetchEvent.ts";
|
|
5
|
-
import type { FetchEvent } from "../server/types.ts";
|
|
6
|
-
|
|
7
|
-
/** Function responsible for receiving an observable [operation]{@link Operation} and returning a [result]{@link OperationResult}. */
|
|
8
|
-
|
|
9
|
-
export type MiddlewareFn = (event: FetchEvent) => Promise<unknown> | unknown;
|
|
10
|
-
/** This composes an array of Exchanges into a single ExchangeIO function */
|
|
11
|
-
|
|
12
|
-
export type RequestMiddleware = (
|
|
13
|
-
event: FetchEvent,
|
|
14
|
-
) => Response | Promise<Response> | void | Promise<void> | Promise<void | Response>;
|
|
15
|
-
|
|
16
|
-
// copy-pasted from h3/dist/index.d.ts
|
|
17
|
-
type EventHandlerResponse<T = any> = T | Promise<T>;
|
|
18
|
-
type ResponseMiddlewareResponseParam = { body?: Awaited<EventHandlerResponse> };
|
|
19
|
-
|
|
20
|
-
export type ResponseMiddleware = (
|
|
21
|
-
event: FetchEvent,
|
|
22
|
-
response: ResponseMiddlewareResponseParam,
|
|
23
|
-
) => Response | Promise<Response> | void | Promise<void>;
|
|
24
|
-
|
|
25
|
-
function wrapRequestMiddleware(onRequest: RequestMiddleware) {
|
|
26
|
-
return async (h3Event: H3Event) => {
|
|
27
|
-
const fetchEvent = getFetchEvent(h3Event);
|
|
28
|
-
const response = await onRequest(fetchEvent);
|
|
29
|
-
if (response) return response;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function wrapResponseMiddleware(onBeforeResponse: ResponseMiddleware): Middleware {
|
|
34
|
-
return async (h3Event, next) => {
|
|
35
|
-
const resp = await next();
|
|
36
|
-
|
|
37
|
-
const fetchEvent = getFetchEvent(h3Event);
|
|
38
|
-
const mwResponse = await onBeforeResponse(fetchEvent, {
|
|
39
|
-
body: resp,
|
|
40
|
-
});
|
|
41
|
-
if (mwResponse) return mwResponse;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Creates middleware for handling requests and responses.
|
|
47
|
-
*
|
|
48
|
-
* @see https://docs.solidjs.com/solid-start/reference/server/create-middleware
|
|
49
|
-
/**
|
|
50
|
-
* Creates request/response middlewares via H3.
|
|
51
|
-
*
|
|
52
|
-
* Accepts an array of H3 {@link Middleware}
|
|
53
|
-
*
|
|
54
|
-
* @tip To run your middleware before response, `await next()` in your function block.
|
|
55
|
-
*@example
|
|
56
|
-
* const middleware = createMiddleware([
|
|
57
|
-
* async (event, next) => {
|
|
58
|
-
* const resp = await next();
|
|
59
|
-
* if (resp instanceof Response) return resp;
|
|
60
|
-
* return new Response("Not found", { status: 404 });
|
|
61
|
-
* },
|
|
62
|
-
* ]);
|
|
63
|
-
*
|
|
64
|
-
*/
|
|
65
|
-
export function createMiddleware(
|
|
66
|
-
args:
|
|
67
|
-
| {
|
|
68
|
-
/** @deprecated Use H3 `Middleware` */
|
|
69
|
-
onRequest?: RequestMiddleware | RequestMiddleware[] | undefined;
|
|
70
|
-
/** @deprecated Use H3 `Middleware` */
|
|
71
|
-
onBeforeResponse?: ResponseMiddleware | ResponseMiddleware[] | undefined;
|
|
72
|
-
}
|
|
73
|
-
| Middleware[],
|
|
74
|
-
): Middleware[] {
|
|
75
|
-
if (Array.isArray(args)) return args;
|
|
76
|
-
|
|
77
|
-
const mw: Middleware[] = [];
|
|
78
|
-
|
|
79
|
-
if (typeof args.onRequest === "function") {
|
|
80
|
-
mw.push(wrapRequestMiddleware(args.onRequest));
|
|
81
|
-
} else if (Array.isArray(args.onRequest)) {
|
|
82
|
-
mw.push(...args.onRequest.map(wrapRequestMiddleware));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (typeof args.onBeforeResponse === "function") {
|
|
86
|
-
mw.push(wrapResponseMiddleware(args.onBeforeResponse));
|
|
87
|
-
} else if (Array.isArray(args.onBeforeResponse)) {
|
|
88
|
-
mw.push(...args.onBeforeResponse.map(wrapResponseMiddleware));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return mw;
|
|
92
|
-
}
|
package/src/router.tsx
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { lazy, type Component } from "solid-js";
|
|
2
|
-
import { getRequestEvent, isServer } from "solid-js/web";
|
|
3
|
-
|
|
4
|
-
import { pageRoutes as routeConfigs } from "./server/routes.ts";
|
|
5
|
-
import type { PageEvent } from "./server/types.ts";
|
|
6
|
-
|
|
7
|
-
const components: Record<string, Component> = {};
|
|
8
|
-
|
|
9
|
-
export function createRoutes() {
|
|
10
|
-
function createRoute(route: any) {
|
|
11
|
-
const component =
|
|
12
|
-
route.$component && (components[route.$component.src] ??= lazy(route.$component.import));
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
...route,
|
|
16
|
-
...(route.$$route ? route.$$route.require().route : undefined),
|
|
17
|
-
info: {
|
|
18
|
-
...(route.$$route ? route.$$route.require().route.info : {}),
|
|
19
|
-
filesystem: true,
|
|
20
|
-
},
|
|
21
|
-
component,
|
|
22
|
-
children: route.children ? route.children.map(createRoute) : undefined,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
const routes = routeConfigs.map(createRoute);
|
|
26
|
-
return routes;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let routes: any[];
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* Read more: https://docs.solidjs.com/solid-start/reference/routing/file-routes
|
|
34
|
-
*/
|
|
35
|
-
export const FileRoutes = isServer
|
|
36
|
-
? () => (getRequestEvent() as PageEvent).routes
|
|
37
|
-
: () => routes || (routes = createRoutes());
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// @refresh skip
|
|
2
|
-
import type { Component } from "solid-js";
|
|
3
|
-
import { Hydration, HydrationScript, NoHydration, getRequestEvent, ssr } from "solid-js/web";
|
|
4
|
-
import App from "solid-start:app";
|
|
5
|
-
|
|
6
|
-
import { ErrorBoundary, TopErrorBoundary } from "../shared/ErrorBoundary.tsx";
|
|
7
|
-
import { useAssets } from "./assets/index.ts";
|
|
8
|
-
import PatchVirtualDevStyles from "./assets/PatchVirtualDevStyles.tsx";
|
|
9
|
-
import { getSsrManifest } from "./manifest/ssr-manifest.ts";
|
|
10
|
-
import type { DocumentComponentProps, PageEvent } from "./types.ts";
|
|
11
|
-
|
|
12
|
-
const docType = ssr("<!DOCTYPE html>");
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* Read more: https://docs.solidjs.com/solid-start/reference/server/start-server
|
|
17
|
-
*/
|
|
18
|
-
export function StartServer(props: { document: Component<DocumentComponentProps> }) {
|
|
19
|
-
const context = getRequestEvent() as PageEvent;
|
|
20
|
-
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
const nonce = context.nonce;
|
|
23
|
-
useAssets(context.assets, nonce);
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<NoHydration>
|
|
27
|
-
{docType as unknown as any}
|
|
28
|
-
<TopErrorBoundary>
|
|
29
|
-
<props.document
|
|
30
|
-
assets={<HydrationScript />}
|
|
31
|
-
scripts={
|
|
32
|
-
<>
|
|
33
|
-
<PatchVirtualDevStyles nonce={nonce} />
|
|
34
|
-
<script
|
|
35
|
-
type="module"
|
|
36
|
-
nonce={nonce}
|
|
37
|
-
async
|
|
38
|
-
src={getSsrManifest("client").path(import.meta.env.START_CLIENT_ENTRY)}
|
|
39
|
-
/>
|
|
40
|
-
</>
|
|
41
|
-
}
|
|
42
|
-
>
|
|
43
|
-
{!import.meta.env.START_ISLANDS ? (
|
|
44
|
-
<Hydration>
|
|
45
|
-
<ErrorBoundary>
|
|
46
|
-
<App />
|
|
47
|
-
</ErrorBoundary>
|
|
48
|
-
</Hydration>
|
|
49
|
-
) : (
|
|
50
|
-
<ErrorBoundary>
|
|
51
|
-
<App />
|
|
52
|
-
</ErrorBoundary>
|
|
53
|
-
)}
|
|
54
|
-
</props.document>
|
|
55
|
-
</TopErrorBoundary>
|
|
56
|
-
</NoHydration>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { onCleanup, sharedConfig } from "solid-js";
|
|
2
|
-
import { getRequestEvent, useAssets as useAssets_ } from "solid-js/web";
|
|
3
|
-
import { renderAsset, type Asset } from "./render.tsx";
|
|
4
|
-
|
|
5
|
-
const REGISTRY = Symbol("assetRegistry");
|
|
6
|
-
const NOOP = () => "";
|
|
7
|
-
|
|
8
|
-
type AssetEntity = {
|
|
9
|
-
key: string;
|
|
10
|
-
consumers: number;
|
|
11
|
-
preloadEl?: HTMLLinkElement;
|
|
12
|
-
ssrIdx?: number;
|
|
13
|
-
};
|
|
14
|
-
type Registry = Record<string, AssetEntity>;
|
|
15
|
-
|
|
16
|
-
const keyAttrs = ["href", "rel", "data-vite-dev-id"] as const;
|
|
17
|
-
|
|
18
|
-
const getEntity = (registry: Registry, asset: Asset) => {
|
|
19
|
-
let key = asset.tag;
|
|
20
|
-
for (const k of keyAttrs) {
|
|
21
|
-
if (!(k in asset.attrs)) continue;
|
|
22
|
-
key += `[${k}='${asset.attrs[k as keyof Asset["attrs"]]}']`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const entity = (registry[key] ??= {
|
|
26
|
-
key,
|
|
27
|
-
consumers: 0,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return entity;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const useAssets = (assets: Asset[], nonce?: string) => {
|
|
34
|
-
if (!assets.length) return;
|
|
35
|
-
|
|
36
|
-
const registry: Registry = (getRequestEvent()!.locals[REGISTRY] ??= {});
|
|
37
|
-
const ssrRequestAssets: Function[] = (sharedConfig.context as any)?.assets;
|
|
38
|
-
const cssKeys: string[] = [];
|
|
39
|
-
|
|
40
|
-
for (const asset of assets) {
|
|
41
|
-
const entity = getEntity(registry, asset);
|
|
42
|
-
const isCSSLink = asset.tag === "link" && asset.attrs.rel === "stylesheet";
|
|
43
|
-
const isCSS = isCSSLink || asset.tag === "style";
|
|
44
|
-
if (isCSS) {
|
|
45
|
-
cssKeys.push(entity.key);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
entity.consumers++;
|
|
49
|
-
if (entity.consumers > 1) continue;
|
|
50
|
-
|
|
51
|
-
// Mounting logic
|
|
52
|
-
useAssets_(() => renderAsset(asset, nonce));
|
|
53
|
-
entity.ssrIdx = ssrRequestAssets.length - 1;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
onCleanup(() => {
|
|
57
|
-
for (const key of cssKeys) {
|
|
58
|
-
const entity = registry[key]!;
|
|
59
|
-
entity.consumers--;
|
|
60
|
-
if (entity.consumers != 0) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Ideally this logic should be implemented directly in dom-expressions
|
|
65
|
-
ssrRequestAssets.splice(entity.ssrIdx!, 1, NOOP);
|
|
66
|
-
|
|
67
|
-
delete registry[key];
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// @refresh skip
|
|
2
|
-
import type { JSX } from "solid-js";
|
|
3
|
-
|
|
4
|
-
const assetMap = {
|
|
5
|
-
style: (props: { attrs: JSX.StyleHTMLAttributes<HTMLStyleElement>; children?: JSX.Element }) => (
|
|
6
|
-
<style {...props.attrs}>{props.children}</style>
|
|
7
|
-
),
|
|
8
|
-
link: (props: { attrs: JSX.LinkHTMLAttributes<HTMLLinkElement> }) => <link {...props.attrs} />,
|
|
9
|
-
script: (props: {
|
|
10
|
-
attrs: JSX.ScriptHTMLAttributes<HTMLScriptElement>;
|
|
11
|
-
key: string | undefined;
|
|
12
|
-
}) => {
|
|
13
|
-
return props.attrs.src ? (
|
|
14
|
-
<script {...props.attrs} id={props.key}>
|
|
15
|
-
{" "}
|
|
16
|
-
</script>
|
|
17
|
-
) : null;
|
|
18
|
-
},
|
|
19
|
-
noscript: (props: { attrs: JSX.HTMLAttributes<HTMLElement>; children: JSX.Element }) => (
|
|
20
|
-
<noscript {...props.attrs}>{props.children}</noscript>
|
|
21
|
-
),
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export function renderAsset(asset: Asset, nonce?: string) {
|
|
25
|
-
let {
|
|
26
|
-
tag,
|
|
27
|
-
attrs: { key, ...attrs } = { key: undefined },
|
|
28
|
-
children,
|
|
29
|
-
} = asset as any;
|
|
30
|
-
return (assetMap as any)[tag]({ attrs: { ...attrs, nonce }, key, children });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type Asset =
|
|
34
|
-
| {
|
|
35
|
-
tag: "style";
|
|
36
|
-
attrs: JSX.StyleHTMLAttributes<HTMLStyleElement> & { key?: string };
|
|
37
|
-
children?: JSX.Element;
|
|
38
|
-
}
|
|
39
|
-
| {
|
|
40
|
-
tag: "script";
|
|
41
|
-
attrs: JSX.ScriptHTMLAttributes<HTMLScriptElement> & { key?: string };
|
|
42
|
-
}
|
|
43
|
-
| {
|
|
44
|
-
tag: "link";
|
|
45
|
-
attrs: JSX.LinkHTMLAttributes<HTMLLinkElement> & { key?: string };
|
|
46
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import type { DevEnvironment, EnvironmentModuleNode } from "vite";
|
|
3
|
-
|
|
4
|
-
async function getViteModuleNode(vite: DevEnvironment, file: string, importer?: string) {
|
|
5
|
-
try {
|
|
6
|
-
const res = await vite.fetchModule(file, importer);
|
|
7
|
-
if (!("id" in res)) return;
|
|
8
|
-
return vite.moduleGraph.getModuleById(res.id);
|
|
9
|
-
} catch (err) {}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async function findModuleDependencies(
|
|
13
|
-
vite: DevEnvironment,
|
|
14
|
-
file: string,
|
|
15
|
-
deps: Set<EnvironmentModuleNode>,
|
|
16
|
-
crawledFiles = new Set<string>(),
|
|
17
|
-
importer?: string,
|
|
18
|
-
) {
|
|
19
|
-
crawledFiles.add(file);
|
|
20
|
-
const module = await getViteModuleNode(vite, file, importer);
|
|
21
|
-
if (!module?.id || deps.has(module)) return;
|
|
22
|
-
|
|
23
|
-
deps.add(module);
|
|
24
|
-
|
|
25
|
-
if (module.url.endsWith(".css") || module.url.includes("node_modules")) return;
|
|
26
|
-
|
|
27
|
-
if (!module.transformResult) {
|
|
28
|
-
await vite.transformRequest(module.id).catch(() => {});
|
|
29
|
-
}
|
|
30
|
-
if (!module.transformResult?.deps) return;
|
|
31
|
-
|
|
32
|
-
// Relying on module.transformResult.deps instead of module.importedModules because:
|
|
33
|
-
// transformResult properly separates imports into deps and dynamicDeps, importedModules doesn't
|
|
34
|
-
// Style crawling has to skip dynamic imports as such modules load their styles themselves
|
|
35
|
-
for (const dep of module.transformResult.deps) {
|
|
36
|
-
if (crawledFiles.has(dep)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
await findModuleDependencies(vite, dep, deps, crawledFiles, module.id);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Vite doesn't expose these so we just copy the list for now
|
|
44
|
-
// https://github.com/vitejs/vite/blob/d6bde8b03d433778aaed62afc2be0630c8131908/packages/vite/src/node/constants.ts#L49C23-L50
|
|
45
|
-
const cssFileRegExp = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)$/;
|
|
46
|
-
// https://github.com/vitejs/vite/blob/d6bde8b03d433778aaed62afc2be0630c8131908/packages/vite/src/node/plugins/css.ts#L160
|
|
47
|
-
const cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
|
|
48
|
-
|
|
49
|
-
const isCssFile = (file: string) => cssFileRegExp.test(file);
|
|
50
|
-
export const isCssModulesFile = (file: string) => cssModulesRegExp.test(file);
|
|
51
|
-
|
|
52
|
-
export async function findStylesInModuleGraph(vite: DevEnvironment, id: string) {
|
|
53
|
-
const absolute = path.resolve(process.cwd(), id);
|
|
54
|
-
const dependencies = new Set<EnvironmentModuleNode>();
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
await findModuleDependencies(vite, absolute, dependencies);
|
|
58
|
-
} catch (e) {
|
|
59
|
-
console.error(e);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const styles: Record<string, any> = {};
|
|
63
|
-
for (const dep of dependencies) {
|
|
64
|
-
if (dep.id && isCssFile(dep.url)) {
|
|
65
|
-
styles[dep.id] = dep.url;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return styles;
|
|
70
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import * as h3 from "h3";
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { createFetchEvent, getFetchEvent, mergeResponseHeaders } from "./fetchEvent.ts";
|
|
5
|
-
|
|
6
|
-
vi.mock(import("h3"), async mod => {
|
|
7
|
-
return {
|
|
8
|
-
...(await mod()),
|
|
9
|
-
getRequestIP: vi.fn(),
|
|
10
|
-
};
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const mockedH3 = vi.mocked(h3);
|
|
14
|
-
|
|
15
|
-
const createMockH3Event = (): h3.H3Event => {
|
|
16
|
-
const event = new h3.H3Event(new Request("http://localhost/test"));
|
|
17
|
-
|
|
18
|
-
event.res.status = 200;
|
|
19
|
-
event.res.statusText = "OK";
|
|
20
|
-
|
|
21
|
-
return event;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
describe("fetchEvent", () => {
|
|
25
|
-
let mockH3Event: h3.H3Event;
|
|
26
|
-
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
mockH3Event = createMockH3Event();
|
|
29
|
-
vi.clearAllMocks();
|
|
30
|
-
|
|
31
|
-
mockedH3.getRequestIP.mockReturnValue("127.0.0.1");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe("createFetchEvent", () => {
|
|
35
|
-
it("should create a FetchEvent from H3Event", () => {
|
|
36
|
-
const fetchEvent = createFetchEvent(mockH3Event);
|
|
37
|
-
|
|
38
|
-
expect(fetchEvent).toEqual({
|
|
39
|
-
request: mockH3Event.req,
|
|
40
|
-
response: expect.any(Object),
|
|
41
|
-
clientAddress: "127.0.0.1",
|
|
42
|
-
locals: {},
|
|
43
|
-
nativeEvent: mockH3Event,
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("should create response stub with correct properties", () => {
|
|
48
|
-
const fetchEvent = createFetchEvent(mockH3Event);
|
|
49
|
-
|
|
50
|
-
expect(fetchEvent.response).toHaveProperty("status");
|
|
51
|
-
expect(fetchEvent.response).toHaveProperty("statusText");
|
|
52
|
-
expect(fetchEvent.response).toHaveProperty("headers");
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe("getFetchEvent", () => {
|
|
57
|
-
it("should create and cache FetchEvent on first call", () => {
|
|
58
|
-
const fetchEvent = getFetchEvent(mockH3Event);
|
|
59
|
-
|
|
60
|
-
expect(mockH3Event.context.solidFetchEvent).toBe(fetchEvent);
|
|
61
|
-
expect(fetchEvent.nativeEvent).toBe(mockH3Event);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("should return cached FetchEvent on subsequent calls", () => {
|
|
65
|
-
const firstCall = getFetchEvent(mockH3Event);
|
|
66
|
-
const secondCall = getFetchEvent(mockH3Event);
|
|
67
|
-
|
|
68
|
-
expect(firstCall).toBe(secondCall);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("mergeResponseHeaders", () => {
|
|
73
|
-
it("should merge headers from Headers object to H3Event", () => {
|
|
74
|
-
const headers = new Headers({
|
|
75
|
-
"content-type": "application/json",
|
|
76
|
-
"x-custom": "value",
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
mergeResponseHeaders(mockH3Event, headers);
|
|
80
|
-
|
|
81
|
-
expect(headers.get("content-type")).toBe("application/json");
|
|
82
|
-
expect(headers.get("x-custom")).toBe("value");
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
});
|
package/src/server/fetchEvent.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { type EventHandler, getRequestIP, type H3Event, type Middleware } from "h3";
|
|
2
|
-
import { provideRequestEvent } from "solid-js/web/storage";
|
|
3
|
-
import type { FetchEvent } from "./types.ts";
|
|
4
|
-
|
|
5
|
-
const FETCH_EVENT_CONTEXT = "solidFetchEvent";
|
|
6
|
-
|
|
7
|
-
export function createFetchEvent(event: H3Event): FetchEvent {
|
|
8
|
-
return {
|
|
9
|
-
request: event.req,
|
|
10
|
-
response: event.res,
|
|
11
|
-
clientAddress: getRequestIP(event),
|
|
12
|
-
locals: {},
|
|
13
|
-
nativeEvent: event,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function getFetchEvent(h3Event: H3Event): FetchEvent {
|
|
18
|
-
if (!h3Event.context[FETCH_EVENT_CONTEXT]) {
|
|
19
|
-
const fetchEvent = createFetchEvent(h3Event);
|
|
20
|
-
h3Event.context[FETCH_EVENT_CONTEXT] = fetchEvent;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return h3Event.context[FETCH_EVENT_CONTEXT] as any;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function mergeResponseHeaders(h3Event: H3Event, headers: Headers) {
|
|
27
|
-
for (const [key, value] of headers.entries()) {
|
|
28
|
-
h3Event.res.headers.append(key, value);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const decorateHandler = <T extends EventHandler>(fn: T) =>
|
|
33
|
-
(event => provideRequestEvent(getFetchEvent(event), () => fn(event))) as T;
|
|
34
|
-
|
|
35
|
-
export const decorateMiddleware = <T extends Middleware>(fn: T) =>
|
|
36
|
-
((event, next) => provideRequestEvent(getFetchEvent(event), () => fn(event, next))) as T;
|