@solidjs/start 0.4.0 → 0.4.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/config/fs-router.js +15 -17
- package/config/index.d.ts +4 -3
- package/config/index.js +3 -1
- package/config/server-handler.js +38 -1
- package/config/server-runtime.jsx +27 -2
- package/package.json +7 -6
- package/server/StartServer.tsx +15 -8
- package/server/page-event.tsx +3 -1
- package/server/spa/StartServer.tsx +6 -2
package/config/fs-router.js
CHANGED
|
@@ -57,6 +57,19 @@ export class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
+
const HTTP_METHODS = ["GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
61
|
+
function createHTTPHandlers(src, exports) {
|
|
62
|
+
const handlers = {};
|
|
63
|
+
for (const exp of exports) {
|
|
64
|
+
if (HTTP_METHODS.includes(exp.n)) {
|
|
65
|
+
handlers[`$${exp.n}`] = {
|
|
66
|
+
src: src,
|
|
67
|
+
pick: [exp.n]
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return handlers;
|
|
72
|
+
}
|
|
60
73
|
export class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
61
74
|
toPath(src) {
|
|
62
75
|
const routePath = cleanPath(src, this.config)
|
|
@@ -110,25 +123,10 @@ export class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
|
110
123
|
path,
|
|
111
124
|
filePath: src
|
|
112
125
|
};
|
|
113
|
-
} else if (
|
|
114
|
-
exports.find(
|
|
115
|
-
exp => exp.n === "GET" || exp.n === "POST" || exp.n === "PUT" || exp.n === "DELETE"
|
|
116
|
-
)
|
|
117
|
-
) {
|
|
126
|
+
} else if (exports.find(exp => HTTP_METHODS.includes(exp.n))) {
|
|
118
127
|
return {
|
|
119
128
|
type: "api",
|
|
120
|
-
|
|
121
|
-
? {
|
|
122
|
-
src: src,
|
|
123
|
-
pick: ["GET"]
|
|
124
|
-
}
|
|
125
|
-
: undefined,
|
|
126
|
-
$POST: exports.find(exp => exp.n === "POST")
|
|
127
|
-
? {
|
|
128
|
-
src: src,
|
|
129
|
-
pick: ["POST"]
|
|
130
|
-
}
|
|
131
|
-
: undefined,
|
|
129
|
+
...createHTTPHandlers(src, exports),
|
|
132
130
|
path,
|
|
133
131
|
filePath: src
|
|
134
132
|
};
|
package/config/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { AppOptions } from "vinxi";
|
|
1
2
|
import { InlineConfig } from "vite";
|
|
2
3
|
|
|
3
4
|
type SolidStartInlineConfig = Omit<InlineConfig, "router"> & {
|
|
4
5
|
start?: {
|
|
5
6
|
ssr?: boolean | "async",
|
|
6
7
|
extensions?: string[],
|
|
7
|
-
server?:
|
|
8
|
+
server?: AppOptions['server'],
|
|
8
9
|
appRoot?: string,
|
|
9
10
|
middleware?: string,
|
|
10
|
-
|
|
11
|
+
islands?: boolean
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
export declare function defineConfig(baseConfig
|
|
15
|
+
export declare function defineConfig(baseConfig?: SolidStartInlineConfig)
|
package/config/index.js
CHANGED
|
@@ -38,18 +38,20 @@ function solidStartServerFsRouter(config) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export function defineConfig(baseConfig = {}) {
|
|
41
|
-
let { plugins = [], start = {}, ...userConfig } = baseConfig;
|
|
41
|
+
let { plugins = [], start = {}, base, ...userConfig } = baseConfig;
|
|
42
42
|
const extensions = [...DEFAULT_EXTENSIONS, ...(start.extensions || [])];
|
|
43
43
|
start = defu(start, {
|
|
44
44
|
appRoot: "./src",
|
|
45
45
|
ssr: true,
|
|
46
46
|
islands: false,
|
|
47
|
+
server: { base },
|
|
47
48
|
solid: {}
|
|
48
49
|
});
|
|
49
50
|
let server = start.server;
|
|
50
51
|
if (!start.ssr) {
|
|
51
52
|
server = { ...server, prerender: { routes: ["/"] } };
|
|
52
53
|
}
|
|
54
|
+
console.log("start", start)
|
|
53
55
|
let entryExtension = ".tsx"
|
|
54
56
|
if (existsSync(join(process.cwd(), start.appRoot, "app.jsx"))) {
|
|
55
57
|
entryExtension = ".jsx"
|
package/config/server-handler.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
/// <reference types="vinxi/types/server" />
|
|
2
2
|
import { crossSerializeStream, fromJSON } from "seroval";
|
|
3
|
+
import {
|
|
4
|
+
CustomEventPlugin,
|
|
5
|
+
DOMExceptionPlugin,
|
|
6
|
+
EventPlugin,
|
|
7
|
+
FormDataPlugin,
|
|
8
|
+
HeadersPlugin,
|
|
9
|
+
ReadableStreamPlugin,
|
|
10
|
+
RequestPlugin,
|
|
11
|
+
ResponsePlugin,
|
|
12
|
+
URLPlugin,
|
|
13
|
+
URLSearchParamsPlugin,
|
|
14
|
+
} from 'seroval-plugins/web';
|
|
3
15
|
import { provideRequestEvent } from "solid-js/web/storage";
|
|
4
16
|
import invariant from "vinxi/lib/invariant";
|
|
5
17
|
import {
|
|
@@ -17,6 +29,18 @@ function serializeToStream(id, value) {
|
|
|
17
29
|
start(controller) {
|
|
18
30
|
crossSerializeStream(value, {
|
|
19
31
|
scopeId: id,
|
|
32
|
+
plugins: [
|
|
33
|
+
CustomEventPlugin,
|
|
34
|
+
DOMExceptionPlugin,
|
|
35
|
+
EventPlugin,
|
|
36
|
+
FormDataPlugin,
|
|
37
|
+
HeadersPlugin,
|
|
38
|
+
ReadableStreamPlugin,
|
|
39
|
+
RequestPlugin,
|
|
40
|
+
ResponsePlugin,
|
|
41
|
+
URLSearchParamsPlugin,
|
|
42
|
+
URLPlugin,
|
|
43
|
+
],
|
|
20
44
|
onSerialize(data, initial) {
|
|
21
45
|
const result = initial ? `($R["${id}"]=[],${data})` : data;
|
|
22
46
|
controller.enqueue(new TextEncoder().encode(`${result};\n`));
|
|
@@ -67,7 +91,20 @@ async function handleServerFunction(event) {
|
|
|
67
91
|
) {
|
|
68
92
|
parsed.push(await readFormData(event));
|
|
69
93
|
} else {
|
|
70
|
-
parsed = fromJSON(await readBody(event)
|
|
94
|
+
parsed = fromJSON(await readBody(event), {
|
|
95
|
+
plugins: [
|
|
96
|
+
CustomEventPlugin,
|
|
97
|
+
DOMExceptionPlugin,
|
|
98
|
+
EventPlugin,
|
|
99
|
+
FormDataPlugin,
|
|
100
|
+
HeadersPlugin,
|
|
101
|
+
ReadableStreamPlugin,
|
|
102
|
+
RequestPlugin,
|
|
103
|
+
ResponsePlugin,
|
|
104
|
+
URLSearchParamsPlugin,
|
|
105
|
+
URLPlugin,
|
|
106
|
+
],
|
|
107
|
+
});
|
|
71
108
|
}
|
|
72
109
|
try {
|
|
73
110
|
const result = await provideRequestEvent(getFetchEvent(event), () => action(...parsed));
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { deserialize, toJSONAsync } from "seroval";
|
|
2
|
+
import {
|
|
3
|
+
CustomEventPlugin,
|
|
4
|
+
DOMExceptionPlugin,
|
|
5
|
+
EventPlugin,
|
|
6
|
+
FormDataPlugin,
|
|
7
|
+
HeadersPlugin,
|
|
8
|
+
ReadableStreamPlugin,
|
|
9
|
+
RequestPlugin,
|
|
10
|
+
ResponsePlugin,
|
|
11
|
+
URLPlugin,
|
|
12
|
+
URLSearchParamsPlugin,
|
|
13
|
+
} from 'seroval-plugins/web';
|
|
2
14
|
import { createIslandReference } from "../server/islands";
|
|
3
15
|
|
|
4
16
|
async function deserializeStream(id, response) {
|
|
@@ -41,7 +53,7 @@ async function deserializeStream(id, response) {
|
|
|
41
53
|
|
|
42
54
|
pop().then(
|
|
43
55
|
() => {
|
|
44
|
-
delete
|
|
56
|
+
delete $R[id];
|
|
45
57
|
},
|
|
46
58
|
() => {
|
|
47
59
|
// no-op
|
|
@@ -69,7 +81,20 @@ async function fetchServerFunction(base, id, args) {
|
|
|
69
81
|
const instance = `server-fn:${INSTANCE++}`;
|
|
70
82
|
const response = await (args.length === 1 && args[0] instanceof FormData
|
|
71
83
|
? createRequest(base, id, instance, args[0])
|
|
72
|
-
: createRequest(base, id, instance, JSON.stringify(await Promise.resolve(toJSONAsync(args
|
|
84
|
+
: createRequest(base, id, instance, JSON.stringify(await Promise.resolve(toJSONAsync(args, {
|
|
85
|
+
plugins: [
|
|
86
|
+
CustomEventPlugin,
|
|
87
|
+
DOMExceptionPlugin,
|
|
88
|
+
EventPlugin,
|
|
89
|
+
FormDataPlugin,
|
|
90
|
+
HeadersPlugin,
|
|
91
|
+
ReadableStreamPlugin,
|
|
92
|
+
RequestPlugin,
|
|
93
|
+
ResponsePlugin,
|
|
94
|
+
URLSearchParamsPlugin,
|
|
95
|
+
URLPlugin,
|
|
96
|
+
],
|
|
97
|
+
}))), "application/json"));
|
|
73
98
|
|
|
74
99
|
if (response.headers.get("Location")) throw response;
|
|
75
100
|
if (response.headers.get("X-Revalidate")) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/start",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"publishConfig": {
|
|
@@ -39,14 +39,15 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"solid-js": "^1.8.7",
|
|
42
|
-
"vinxi": "0.0.
|
|
42
|
+
"vinxi": "0.0.54"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@vinxi/plugin-directives": "0.0.
|
|
46
|
-
"@vinxi/server-components": "0.0.
|
|
47
|
-
"@vinxi/server-functions": "0.0.
|
|
45
|
+
"@vinxi/plugin-directives": "0.0.50",
|
|
46
|
+
"@vinxi/server-components": "0.0.50",
|
|
47
|
+
"@vinxi/server-functions": "0.0.51",
|
|
48
48
|
"defu": "^6.1.2",
|
|
49
|
-
"seroval": "^0.
|
|
49
|
+
"seroval": "^1.0.0",
|
|
50
|
+
"seroval-plugins": "^1.0.1",
|
|
50
51
|
"vite-plugin-inspect": "^0.7.33",
|
|
51
52
|
"vite-plugin-solid": "^2.8.0"
|
|
52
53
|
},
|
package/server/StartServer.tsx
CHANGED
|
@@ -26,7 +26,8 @@ export function StartServer(props: { document: Component<DocumentComponentProps>
|
|
|
26
26
|
const match = context.routerMatches[0][i];
|
|
27
27
|
if (match.metadata && match.metadata.filesystem) {
|
|
28
28
|
const segment = current.find(r => r.path === match.path);
|
|
29
|
-
const part = import.meta.env.MANIFEST["
|
|
29
|
+
const part = import.meta.env.MANIFEST[import.meta.env.START_ISLANDS ? "ssr" : "client"]
|
|
30
|
+
.inputs[segment["$component"].src];
|
|
30
31
|
const asset = await part.assets();
|
|
31
32
|
assets.push.apply(assets, asset);
|
|
32
33
|
current = segment.children;
|
|
@@ -34,26 +35,32 @@ export function StartServer(props: { document: Component<DocumentComponentProps>
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
// dedupe assets
|
|
37
|
-
assets = [...new Map(assets.map(item => [item.attrs.key, item])).values()].filter(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
assets = [...new Map(assets.map(item => [item.attrs.key, item])).values()].filter(asset =>
|
|
39
|
+
import.meta.env.START_ISLANDS
|
|
40
|
+
? false
|
|
41
|
+
: asset.attrs.rel === "modulepreload" &&
|
|
42
|
+
!context.assets.find(a => a.attrs.key === asset.attrs.key)
|
|
41
43
|
);
|
|
42
44
|
});
|
|
43
45
|
|
|
44
|
-
useAssets(() => assets.length ? assets.map(m => renderAsset(m)) : undefined);
|
|
46
|
+
useAssets(() => (assets.length ? assets.map(m => renderAsset(m)) : undefined));
|
|
45
47
|
|
|
46
48
|
return (
|
|
47
49
|
<NoHydration>
|
|
48
50
|
{docType as unknown as any}
|
|
49
51
|
<props.document
|
|
50
|
-
assets={
|
|
51
|
-
scripts={
|
|
52
|
+
assets={
|
|
52
53
|
<>
|
|
53
54
|
<HydrationScript />
|
|
55
|
+
{context.assets.map(m => renderAsset(m))}
|
|
56
|
+
</>
|
|
57
|
+
}
|
|
58
|
+
scripts={
|
|
59
|
+
<>
|
|
54
60
|
<script innerHTML={`window.manifest = ${JSON.stringify(context.manifest)}`} />
|
|
55
61
|
<script
|
|
56
62
|
type="module"
|
|
63
|
+
async
|
|
57
64
|
src={
|
|
58
65
|
import.meta.env.MANIFEST["client"].inputs[
|
|
59
66
|
import.meta.env.MANIFEST["client"].handler
|
package/server/page-event.tsx
CHANGED
|
@@ -35,7 +35,9 @@ export async function createPageEvent(ctx: FetchEvent) {
|
|
|
35
35
|
assets: [
|
|
36
36
|
...(await clientManifest.inputs[clientManifest.handler].assets()),
|
|
37
37
|
...(import.meta.env.START_ISLANDS
|
|
38
|
-
? await serverManifest.inputs[serverManifest.handler].assets()
|
|
38
|
+
? (await serverManifest.inputs[serverManifest.handler].assets()).filter(
|
|
39
|
+
s => (s as any).attrs.rel !== "modulepreload"
|
|
40
|
+
)
|
|
39
41
|
: [])
|
|
40
42
|
],
|
|
41
43
|
initialSubmission: initFromFlash(ctx),
|
|
@@ -10,11 +10,15 @@ export function StartServer(props) {
|
|
|
10
10
|
<NoHydration>
|
|
11
11
|
{docType as unknown as any}
|
|
12
12
|
<props.document
|
|
13
|
-
assets={
|
|
13
|
+
assets={
|
|
14
|
+
<>
|
|
15
|
+
<script>$R = [];</script>
|
|
16
|
+
{context.assets.map(m => renderAsset(m))}
|
|
17
|
+
</>
|
|
18
|
+
}
|
|
14
19
|
scripts={
|
|
15
20
|
<>
|
|
16
21
|
<script innerHTML={`window.manifest = ${JSON.stringify(context.manifest)}`} />
|
|
17
|
-
<script>$R = [];</script>
|
|
18
22
|
<script
|
|
19
23
|
type="module"
|
|
20
24
|
src={
|