@solidjs/start 0.4.0-alpha.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.
- package/LICENSE +21 -0
- package/client/StartClient.tsx +17 -0
- package/client/index.tsx +3 -0
- package/client/islands.tsx +5 -0
- package/client/mount.ts +98 -0
- package/client/spa/index.tsx +8 -0
- package/config/fs-router.js +137 -0
- package/config/index.js +178 -0
- package/config/server-components.js +106 -0
- package/config/server-runtime.jsx +44 -0
- package/package.json +52 -0
- package/server/StartServer.tsx +42 -0
- package/server/handler.tsx +72 -0
- package/server/index.tsx +4 -0
- package/server/islands/index.tsx +102 -0
- package/server/islands/utils.tsx +87 -0
- package/server/middleware.ts +129 -0
- package/server/renderAsset.tsx +16 -0
- package/server/spa/StartServer.tsx +30 -0
- package/server/spa/handler.tsx +24 -0
- package/server/spa/index.tsx +4 -0
- package/server/types.ts +58 -0
- package/shared/ErrorBoundary.tsx +48 -0
- package/shared/FileRoutes.tsx +28 -0
- package/shared/HttpHeader.tsx +30 -0
- package/shared/HttpStatusCode.tsx +13 -0
- package/shared/clientOnly.tsx +28 -0
- package/shared/index.tsx +6 -0
- package/shared/lazyRoute.tsx +59 -0
- package/shared/routes.ts +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Ryan Carniato
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/client/index.tsx
ADDED
package/client/mount.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createStore } from "solid-js/store";
|
|
2
|
+
import { createComponent, getHydrationKey, getOwner, hydrate } from "solid-js/web";
|
|
3
|
+
|
|
4
|
+
export function mount(fn, el) {
|
|
5
|
+
if (import.meta.env.START_ISLANDS) {
|
|
6
|
+
const map = new WeakMap();
|
|
7
|
+
async function mountIsland(el: HTMLElement) {
|
|
8
|
+
if (el.dataset.css) {
|
|
9
|
+
let css = JSON.parse(el.dataset.css);
|
|
10
|
+
for (let href of css) {
|
|
11
|
+
if (!document.querySelector(`link[href="${href}"]`)) {
|
|
12
|
+
let link = document.createElement("link");
|
|
13
|
+
link.rel = "stylesheet";
|
|
14
|
+
link.href = href;
|
|
15
|
+
document.head.appendChild(link);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let mod = await import(
|
|
21
|
+
/* @vite-ignore */
|
|
22
|
+
import.meta.env.MANIFEST["client"].chunks[el.dataset.id.split("#")[0]].output.path
|
|
23
|
+
);
|
|
24
|
+
if (!mod || !el.dataset.hk) return;
|
|
25
|
+
|
|
26
|
+
let Component = mod[el.dataset.id.split("#")[1]];
|
|
27
|
+
let hk = el.dataset.hk;
|
|
28
|
+
// _$DEBUG("hydrating island", el.dataset.island, hk.slice(0, hk.length - 1) + `1-`, el);
|
|
29
|
+
|
|
30
|
+
let props = createStore({
|
|
31
|
+
...JSON.parse(el.dataset.props!),
|
|
32
|
+
get children() {
|
|
33
|
+
const p = el.getElementsByTagName("solid-children");
|
|
34
|
+
getHydrationKey();
|
|
35
|
+
[...p].forEach(a => {
|
|
36
|
+
(a as any).__$owner = getOwner();
|
|
37
|
+
});
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
map.set(el, props);
|
|
43
|
+
|
|
44
|
+
hydrate(() => createComponent(Component, props[0]), el, {
|
|
45
|
+
renderId: hk.slice(0, hk.length - 1) + `${1 + Number(el.dataset.offset)}-`,
|
|
46
|
+
owner: lookupOwner(el)
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
delete el.dataset.hk;
|
|
50
|
+
el.dataset.hkk = hk;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let queue: HTMLElement[] = [];
|
|
54
|
+
let queued = false;
|
|
55
|
+
function runTaskQueue(info: any) {
|
|
56
|
+
while (info.timeRemaining() > 0 && queue.length) {
|
|
57
|
+
mountIsland(queue.shift()!);
|
|
58
|
+
}
|
|
59
|
+
if (queue.length) {
|
|
60
|
+
requestIdleCallback(runTaskQueue);
|
|
61
|
+
} else queued = false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const hydrateIslands = () => {
|
|
65
|
+
const islands: NodeListOf<HTMLElement> = document.querySelectorAll("solid-island[data-hk]");
|
|
66
|
+
const assets = new Set<string>();
|
|
67
|
+
islands.forEach((el: HTMLElement) => el.dataset.id && assets.add(el.dataset.id));
|
|
68
|
+
Promise.all(
|
|
69
|
+
[...assets].map(
|
|
70
|
+
asset =>
|
|
71
|
+
import(/* @vite-ignore */import.meta.env.MANIFEST["client"].chunks[asset.split("#")[0]].output.path)
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
.then(() => {
|
|
75
|
+
islands.forEach((el: HTMLElement) => {
|
|
76
|
+
if (el.dataset.when === "idle" && "requestIdleCallback" in window) {
|
|
77
|
+
if (!queued) {
|
|
78
|
+
queued = true;
|
|
79
|
+
requestIdleCallback(runTaskQueue);
|
|
80
|
+
}
|
|
81
|
+
queue.push(el);
|
|
82
|
+
} else mountIsland(el as HTMLElement);
|
|
83
|
+
});
|
|
84
|
+
})
|
|
85
|
+
.catch(e => console.error(e));
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
function lookupOwner(el: HTMLElement) {
|
|
89
|
+
const parent = el.closest("solid-children");
|
|
90
|
+
return parent && (parent as any).__$owner;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
hydrateIslands();
|
|
94
|
+
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
return hydrate(fn, el);
|
|
98
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { analyzeModule, BaseFileSystemRouter, cleanPath } from "vinxi/fs-router";
|
|
2
|
+
|
|
3
|
+
export class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
4
|
+
toPath(src) {
|
|
5
|
+
const routePath = cleanPath(src, this.config)
|
|
6
|
+
// remove the initial slash
|
|
7
|
+
.slice(1)
|
|
8
|
+
.replace(/index$/, "")
|
|
9
|
+
.replace(/\[([^\/]+)\]/g, (_, m) => {
|
|
10
|
+
if (m.length > 3 && m.startsWith("...")) {
|
|
11
|
+
return `*${m.slice(3)}`;
|
|
12
|
+
}
|
|
13
|
+
if (m.length > 2 && m.startsWith("[") && m.endsWith("]")) {
|
|
14
|
+
return `:${m.slice(1, -1)}?`;
|
|
15
|
+
}
|
|
16
|
+
return `:${m}`;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return routePath?.length > 0 ? `/${routePath}` : "/";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
toRoute(src) {
|
|
23
|
+
let path = this.toPath(src);
|
|
24
|
+
|
|
25
|
+
if (src.endsWith(".md") || src.endsWith(".mdx")) {
|
|
26
|
+
return {
|
|
27
|
+
type: "page",
|
|
28
|
+
$component: {
|
|
29
|
+
src: src,
|
|
30
|
+
pick: ["$css"]
|
|
31
|
+
},
|
|
32
|
+
$$route: undefined,
|
|
33
|
+
path,
|
|
34
|
+
filePath: src
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const [_, exports] = analyzeModule(src);
|
|
39
|
+
const hasDefault = exports.find(e => e.n === "default");
|
|
40
|
+
const hasRouteConfig = exports.find(e => e.n === "route");
|
|
41
|
+
if (hasDefault) {
|
|
42
|
+
return {
|
|
43
|
+
type: "page",
|
|
44
|
+
$component: {
|
|
45
|
+
src: src,
|
|
46
|
+
pick: ["default", "$css"]
|
|
47
|
+
},
|
|
48
|
+
$$route: hasRouteConfig
|
|
49
|
+
? {
|
|
50
|
+
src: src,
|
|
51
|
+
pick: ["route"]
|
|
52
|
+
}
|
|
53
|
+
: undefined,
|
|
54
|
+
path,
|
|
55
|
+
filePath: src
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
61
|
+
toPath(src) {
|
|
62
|
+
const routePath = cleanPath(src, this.config)
|
|
63
|
+
// remove the initial slash
|
|
64
|
+
.slice(1)
|
|
65
|
+
.replace(/index$/, "")
|
|
66
|
+
.replace(/\[([^\/]+)\]/g, (_, m) => {
|
|
67
|
+
if (m.length > 3 && m.startsWith("...")) {
|
|
68
|
+
return `*${m.slice(3)}`;
|
|
69
|
+
}
|
|
70
|
+
if (m.length > 2 && m.startsWith("[") && m.endsWith("]")) {
|
|
71
|
+
return `:${m.slice(1, -1)}?`;
|
|
72
|
+
}
|
|
73
|
+
return `:${m}`;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return routePath?.length > 0 ? `/${routePath}` : "/";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
toRoute(src) {
|
|
80
|
+
let path = this.toPath(src);
|
|
81
|
+
|
|
82
|
+
if (src.endsWith(".md") || src.endsWith(".mdx")) {
|
|
83
|
+
return {
|
|
84
|
+
type: "page",
|
|
85
|
+
$component: {
|
|
86
|
+
src: src,
|
|
87
|
+
pick: ["$css"]
|
|
88
|
+
},
|
|
89
|
+
$$route: undefined,
|
|
90
|
+
path,
|
|
91
|
+
filePath: src
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const [_, exports] = analyzeModule(src);
|
|
96
|
+
const hasRouteConfig = exports.find(e => e.n === "route");
|
|
97
|
+
if (exports.find(exp => exp.n === "default")) {
|
|
98
|
+
return {
|
|
99
|
+
type: "page",
|
|
100
|
+
$component: {
|
|
101
|
+
src: src,
|
|
102
|
+
pick: ["default", "$css"]
|
|
103
|
+
},
|
|
104
|
+
$$route: hasRouteConfig
|
|
105
|
+
? {
|
|
106
|
+
src: src,
|
|
107
|
+
pick: ["route"]
|
|
108
|
+
}
|
|
109
|
+
: undefined,
|
|
110
|
+
path,
|
|
111
|
+
filePath: src
|
|
112
|
+
};
|
|
113
|
+
} else if (
|
|
114
|
+
exports.find(
|
|
115
|
+
exp => exp.n === "GET" || exp.n === "POST" || exp.n === "PUT" || exp.n === "DELETE"
|
|
116
|
+
)
|
|
117
|
+
) {
|
|
118
|
+
return {
|
|
119
|
+
type: "api",
|
|
120
|
+
$GET: exports.find(exp => exp.n === "GET")
|
|
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,
|
|
132
|
+
path,
|
|
133
|
+
filePath: src
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
package/config/index.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { serverFunctions } from "@vinxi/server-functions/plugin";
|
|
2
|
+
import defu from "defu";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { createApp, resolve } from "vinxi";
|
|
6
|
+
import { normalize } from "vinxi/lib/path";
|
|
7
|
+
import { config } from "vinxi/plugins/config";
|
|
8
|
+
import solid from "vite-plugin-solid";
|
|
9
|
+
import { SolidStartClientFileRouter, SolidStartServerFileRouter } from "./fs-router.js";
|
|
10
|
+
import { serverComponents } from "./server-components.js";
|
|
11
|
+
|
|
12
|
+
const DEFAULT_EXTENSIONS = ["js", "jsx", "ts", "tsx"];
|
|
13
|
+
|
|
14
|
+
function solidStartClientFsRouter(config) {
|
|
15
|
+
return (router, app) =>
|
|
16
|
+
new SolidStartClientFileRouter(
|
|
17
|
+
{
|
|
18
|
+
dir: resolve.absolute(config.dir, router.root),
|
|
19
|
+
extensions: config.extensions ?? ["js", "jsx", "ts", "tsx"]
|
|
20
|
+
},
|
|
21
|
+
router,
|
|
22
|
+
app
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function solidStartServerFsRouter(config) {
|
|
27
|
+
return (router, app) =>
|
|
28
|
+
new SolidStartServerFileRouter(
|
|
29
|
+
{
|
|
30
|
+
dir: resolve.absolute(config.dir, router.root),
|
|
31
|
+
extensions: config.extensions ?? ["js", "jsx", "ts", "tsx"]
|
|
32
|
+
},
|
|
33
|
+
router,
|
|
34
|
+
app
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function defineConfig(baseConfig = {}) {
|
|
39
|
+
let { plugins = [], start = {}, ...userConfig } = baseConfig;
|
|
40
|
+
const extensions = [...DEFAULT_EXTENSIONS, ...(start.extensions || [])];
|
|
41
|
+
start = defu(start, {
|
|
42
|
+
appRoot: "./src",
|
|
43
|
+
ssr: true,
|
|
44
|
+
islands: false,
|
|
45
|
+
serverPlugins: []
|
|
46
|
+
});
|
|
47
|
+
return createApp({
|
|
48
|
+
server: {
|
|
49
|
+
compressPublicAssets: {
|
|
50
|
+
brotli: true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
routers: [
|
|
54
|
+
{
|
|
55
|
+
name: "public",
|
|
56
|
+
mode: "static",
|
|
57
|
+
dir: "./public",
|
|
58
|
+
base: "/"
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
{
|
|
62
|
+
name: "ssr",
|
|
63
|
+
mode: "handler",
|
|
64
|
+
handler: `${start.appRoot}/entry-server.tsx`,
|
|
65
|
+
middleware: start.middleware,
|
|
66
|
+
...(start.ssr
|
|
67
|
+
? { routes: solidStartServerFsRouter({ dir: `${start.appRoot}/routes`, extensions }) }
|
|
68
|
+
: {}),
|
|
69
|
+
extensions,
|
|
70
|
+
target: "server",
|
|
71
|
+
plugins: () => [
|
|
72
|
+
config("user", userConfig),
|
|
73
|
+
...plugins,
|
|
74
|
+
start.islands ? serverComponents.server() : null,
|
|
75
|
+
solid({ ssr: true, extensions: extensions.map(ext => `.${ext}`) }),
|
|
76
|
+
config("app-server", {
|
|
77
|
+
resolve: {
|
|
78
|
+
alias: {
|
|
79
|
+
"#start/app": join(process.cwd(), start.appRoot, "app.tsx"),
|
|
80
|
+
"~": join(process.cwd(), start.appRoot),
|
|
81
|
+
...(!start.ssr
|
|
82
|
+
? {
|
|
83
|
+
"@solidjs/start/server": "@solidjs/start/server/spa"
|
|
84
|
+
}
|
|
85
|
+
: {})
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
define: {
|
|
89
|
+
"import.meta.env.START_ISLANDS": JSON.stringify(start.islands),
|
|
90
|
+
"import.meta.env.SSR": JSON.stringify(true),
|
|
91
|
+
"import.meta.env.START_SSR": JSON.stringify(start.ssr)
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "client",
|
|
98
|
+
mode: "build",
|
|
99
|
+
handler: `${start.appRoot}/entry-client.tsx`,
|
|
100
|
+
...(start.islands
|
|
101
|
+
? {}
|
|
102
|
+
: {
|
|
103
|
+
routes: solidStartClientFsRouter({ dir: `${start.appRoot}/routes`, extensions })
|
|
104
|
+
}),
|
|
105
|
+
extensions,
|
|
106
|
+
target: "browser",
|
|
107
|
+
plugins: () => [
|
|
108
|
+
config("user", userConfig),
|
|
109
|
+
...plugins,
|
|
110
|
+
serverFunctions.client({
|
|
111
|
+
runtime: normalize(fileURLToPath(new URL("./server-runtime.jsx", import.meta.url)))
|
|
112
|
+
}),
|
|
113
|
+
start.islands ? serverComponents.client() : null,
|
|
114
|
+
solid({ ssr: start.ssr, extensions: extensions.map(ext => `.${ext}`) }),
|
|
115
|
+
config("app-client", {
|
|
116
|
+
resolve: {
|
|
117
|
+
alias: {
|
|
118
|
+
"#start/app": join(process.cwd(), start.appRoot, "app.tsx"),
|
|
119
|
+
"~": join(process.cwd(), start.appRoot),
|
|
120
|
+
...(start.islands
|
|
121
|
+
? {
|
|
122
|
+
"@solidjs/start/client": "@solidjs/start/client/islands"
|
|
123
|
+
}
|
|
124
|
+
: {}),
|
|
125
|
+
...(!start.ssr
|
|
126
|
+
? {
|
|
127
|
+
"@solidjs/start/client": "@solidjs/start/client/spa"
|
|
128
|
+
}
|
|
129
|
+
: {})
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
define: {
|
|
133
|
+
"import.meta.env.START_ISLANDS": JSON.stringify(start.islands),
|
|
134
|
+
"import.meta.env.SSR": JSON.stringify(false),
|
|
135
|
+
"import.meta.env.START_SSR": JSON.stringify(start.ssr)
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
],
|
|
139
|
+
base: "/_build"
|
|
140
|
+
},
|
|
141
|
+
// {
|
|
142
|
+
// name: "server",
|
|
143
|
+
// mode: "handler",
|
|
144
|
+
// base: "/_server",
|
|
145
|
+
// handler: serverFunctions.handler,
|
|
146
|
+
// target: "server",
|
|
147
|
+
// ...(overrides ?? {}),
|
|
148
|
+
// plugins: () => [serverserver(), ...(overrides?.plugins?.() ?? [])],
|
|
149
|
+
// },
|
|
150
|
+
serverFunctions.router({
|
|
151
|
+
plugins: () => [
|
|
152
|
+
config("user", userConfig),
|
|
153
|
+
...plugins,
|
|
154
|
+
solid({ ssr: true, extensions: extensions.map(ext => `.${ext}`) }),
|
|
155
|
+
config("app-server", {
|
|
156
|
+
resolve: {
|
|
157
|
+
alias: {
|
|
158
|
+
"#start/app": join(process.cwd(), start.appRoot, "app.tsx"),
|
|
159
|
+
"~": join(process.cwd(), start.appRoot),
|
|
160
|
+
...(!start.ssr
|
|
161
|
+
? {
|
|
162
|
+
"@solidjs/start/server": "@solidjs/start/server/spa"
|
|
163
|
+
}
|
|
164
|
+
: {})
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
define: {
|
|
168
|
+
"import.meta.env.START_ISLANDS": JSON.stringify(start.islands),
|
|
169
|
+
"import.meta.env.SSR": JSON.stringify(true),
|
|
170
|
+
"import.meta.env.START_SSR": JSON.stringify(start.ssr)
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
],
|
|
174
|
+
middleware: start.middleware
|
|
175
|
+
})
|
|
176
|
+
]
|
|
177
|
+
});
|
|
178
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decorateExportsPlugin,
|
|
3
|
+
directives,
|
|
4
|
+
shimExportsPlugin,
|
|
5
|
+
wrapExportsPlugin
|
|
6
|
+
} from "@vinxi/plugin-directives";
|
|
7
|
+
import { client as clientComponents } from "@vinxi/server-components/client";
|
|
8
|
+
import { SERVER_REFERENCES_MANIFEST } from "@vinxi/server-components/constants";
|
|
9
|
+
import { buildServerComponents } from "@vinxi/server-components/server";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { chunkify } from "vinxi/lib/chunks";
|
|
12
|
+
import { normalize } from "vinxi/lib/path";
|
|
13
|
+
|
|
14
|
+
function client() {
|
|
15
|
+
return clientComponents({
|
|
16
|
+
server: "ssr",
|
|
17
|
+
transpileDeps: [],
|
|
18
|
+
manifest: SERVER_REFERENCES_MANIFEST
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function server() {
|
|
23
|
+
const runtime = normalize(fileURLToPath(new URL("./server-runtime.jsx", import.meta.url)));
|
|
24
|
+
// export function serverComponents({
|
|
25
|
+
// resolve = {
|
|
26
|
+
// conditions: ["react-server"],
|
|
27
|
+
// },
|
|
28
|
+
// runtime = "@vinxi/react-server-dom-vite/runtime",
|
|
29
|
+
// transpileDeps = ["react", "react-dom", "@vinxi/react-server-dom-vite"],
|
|
30
|
+
// manifest = SERVER_REFERENCES_MANIFEST,
|
|
31
|
+
// transforms = undefined,
|
|
32
|
+
// } = {}) {
|
|
33
|
+
const serverModules = new Set();
|
|
34
|
+
const clientModules = new Set();
|
|
35
|
+
|
|
36
|
+
function onReference(type, reference) {
|
|
37
|
+
if (type === "server") {
|
|
38
|
+
serverModules.add(reference);
|
|
39
|
+
} else {
|
|
40
|
+
clientModules.add(reference);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return [
|
|
45
|
+
directives({
|
|
46
|
+
hash: chunkify,
|
|
47
|
+
runtime,
|
|
48
|
+
onReference: onReference,
|
|
49
|
+
transforms: [
|
|
50
|
+
shimExportsPlugin({
|
|
51
|
+
runtime: {
|
|
52
|
+
module: runtime,
|
|
53
|
+
function: "createServerReference"
|
|
54
|
+
},
|
|
55
|
+
onModuleFound: mod => onReference("server", mod),
|
|
56
|
+
hash: chunkify,
|
|
57
|
+
apply: (code, id, options) => {
|
|
58
|
+
return !options.ssr;
|
|
59
|
+
},
|
|
60
|
+
pragma: "use server"
|
|
61
|
+
}),
|
|
62
|
+
decorateExportsPlugin({
|
|
63
|
+
runtime: {
|
|
64
|
+
module: runtime,
|
|
65
|
+
function: "createServerReference"
|
|
66
|
+
},
|
|
67
|
+
onModuleFound: mod => onReference("server", mod),
|
|
68
|
+
hash: chunkify,
|
|
69
|
+
apply: (code, id, options) => {
|
|
70
|
+
return options.ssr;
|
|
71
|
+
},
|
|
72
|
+
pragma: "use server"
|
|
73
|
+
}),
|
|
74
|
+
wrapExportsPlugin({
|
|
75
|
+
runtime: {
|
|
76
|
+
module: runtime,
|
|
77
|
+
function: "createClientReference"
|
|
78
|
+
},
|
|
79
|
+
onModuleFound: mod => onReference("client", mod),
|
|
80
|
+
hash: chunkify,
|
|
81
|
+
apply: (code, id, options) => {
|
|
82
|
+
return options.ssr;
|
|
83
|
+
},
|
|
84
|
+
pragma: "use client"
|
|
85
|
+
})
|
|
86
|
+
]
|
|
87
|
+
}),
|
|
88
|
+
buildServerComponents({
|
|
89
|
+
resolve: {
|
|
90
|
+
conditions: ["solid"]
|
|
91
|
+
},
|
|
92
|
+
transpileDeps: [],
|
|
93
|
+
manifest: SERVER_REFERENCES_MANIFEST,
|
|
94
|
+
modules: {
|
|
95
|
+
server: serverModules,
|
|
96
|
+
client: clientModules
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
];
|
|
100
|
+
// }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const serverComponents = {
|
|
104
|
+
client,
|
|
105
|
+
server
|
|
106
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createIslandReference } from "../server/islands";
|
|
2
|
+
|
|
3
|
+
async function fetchServerAction(base, id, args) {
|
|
4
|
+
console.log("fetching serevr action");
|
|
5
|
+
const response = await fetch(base, {
|
|
6
|
+
method: "POST",
|
|
7
|
+
headers: {
|
|
8
|
+
Accept: "application/json",
|
|
9
|
+
"Content-Type": "application/json",
|
|
10
|
+
"server-action": id
|
|
11
|
+
},
|
|
12
|
+
body: JSON.stringify(args)
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const json = await response.json();
|
|
16
|
+
|
|
17
|
+
if (response.status === 200) {
|
|
18
|
+
return json;
|
|
19
|
+
} else {
|
|
20
|
+
console.log(json);
|
|
21
|
+
throw { message: json.error };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createServerReference(fn, id, name) {
|
|
26
|
+
return new Proxy(fn, {
|
|
27
|
+
get(target, prop, receiver) {
|
|
28
|
+
if (prop === "url") {
|
|
29
|
+
return `/_server?id=${encodeURIComponent(id)}&name=${encodeURIComponent(name)}`;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
apply(target, thisArg, args) {
|
|
33
|
+
return fetchServerAction("/_server", `${id}#${name}`, args);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function createClientReference(Component, id, name) {
|
|
39
|
+
if (typeof Component === "function") {
|
|
40
|
+
return createIslandReference(Component, id, name);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return Component;
|
|
44
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solidjs/start",
|
|
3
|
+
"version": "0.4.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"author": "Ryan Carniato",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"client",
|
|
11
|
+
"config",
|
|
12
|
+
"server",
|
|
13
|
+
"shared",
|
|
14
|
+
"*.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"types": "./index.tsx",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./shared/index.tsx",
|
|
19
|
+
"./config": "./config/index.js",
|
|
20
|
+
"./server": "./server/index.tsx",
|
|
21
|
+
"./server/spa": "./server/spa/index.tsx",
|
|
22
|
+
"./client": "./client/index.tsx",
|
|
23
|
+
"./client/islands": "./client/islands.tsx",
|
|
24
|
+
"./middleware": "./server/middleware.ts",
|
|
25
|
+
"./client/spa": "./client/spa/index.tsx"
|
|
26
|
+
},
|
|
27
|
+
"typesVersions": {
|
|
28
|
+
"*": {
|
|
29
|
+
".": [
|
|
30
|
+
"./shared/index.tsx"
|
|
31
|
+
],
|
|
32
|
+
"./server": [
|
|
33
|
+
"./server/index.tsx"
|
|
34
|
+
],
|
|
35
|
+
"./client": [
|
|
36
|
+
"./client/index.tsx"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"solid-js": "^1.8.4",
|
|
42
|
+
"vinxi": "0.0.47"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@vinxi/plugin-directives": "0.0.39",
|
|
46
|
+
"@vinxi/server-functions": "0.0.39",
|
|
47
|
+
"@vinxi/server-components": "0.0.39",
|
|
48
|
+
"defu": "^6.1.2",
|
|
49
|
+
"vite-plugin-inspect": "^0.7.33",
|
|
50
|
+
"vite-plugin-solid": "^2.7.0"
|
|
51
|
+
}
|
|
52
|
+
}
|