@solidjs/start 2.0.0-alpha.3 → 2.0.0-beta.1
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 +23 -0
- package/package.json +6 -5
- package/src/config/constants.ts +2 -2
- package/src/config/dev-server.ts +5 -1
- package/src/config/fs-routes/fs-watcher.ts +36 -40
- package/src/config/fs-routes/router.ts +27 -11
- package/src/config/fs-routes/tree-shake.ts +1 -48
- package/src/config/index.ts +12 -10
- package/src/config/lazy.ts +1 -0
- package/src/config/manifest.ts +8 -3
- package/src/directives/index.ts +1 -0
- package/src/directives/remove-unused-variables.ts +18 -3
- package/src/server/handler.ts +1 -1
- package/src/utils/debounce.ts +10 -0
- package/dist/client/StartClient.d.ts +0 -7
- package/dist/client/StartClient.jsx +0 -26
- package/dist/client/index.d.ts +0 -2
- package/dist/client/index.jsx +0 -2
- package/dist/client/mount.d.ts +0 -1
- package/dist/client/mount.js +0 -1
- package/dist/client/spa/index.d.ts +0 -4
- package/dist/client/spa/index.jsx +0 -5
- package/dist/config/constants.d.ts +0 -16
- package/dist/config/constants.js +0 -16
- package/dist/config/dev-server.d.ts +0 -2
- package/dist/config/dev-server.js +0 -126
- package/dist/config/env.d.ts +0 -19
- package/dist/config/env.js +0 -81
- package/dist/config/fs-router.d.ts +0 -37
- package/dist/config/fs-router.js +0 -141
- package/dist/config/fs-routes/fs-watcher.d.ts +0 -3
- package/dist/config/fs-routes/fs-watcher.js +0 -43
- package/dist/config/fs-routes/index.d.ts +0 -7
- package/dist/config/fs-routes/index.js +0 -107
- package/dist/config/fs-routes/router.d.ts +0 -37
- package/dist/config/fs-routes/router.js +0 -135
- package/dist/config/fs-routes/tree-shake.d.ts +0 -2
- package/dist/config/fs-routes/tree-shake.js +0 -348
- package/dist/config/index.d.ts +0 -25
- package/dist/config/index.js +0 -215
- package/dist/config/lazy.d.ts +0 -3
- package/dist/config/lazy.js +0 -112
- package/dist/config/manifest.d.ts +0 -3
- package/dist/config/manifest.js +0 -108
- package/dist/config/utils.d.ts +0 -4
- package/dist/config/utils.js +0 -6
- package/dist/config/vite-utils.d.ts +0 -21
- package/dist/config/vite-utils.js +0 -85
- package/dist/directives/bubble-function-declaration.d.ts +0 -3
- package/dist/directives/bubble-function-declaration.js +0 -23
- package/dist/directives/compile.d.ts +0 -9
- package/dist/directives/compile.js +0 -40
- package/dist/directives/generate-unique-name.d.ts +0 -3
- package/dist/directives/generate-unique-name.js +0 -16
- package/dist/directives/get-descriptive-name.d.ts +0 -2
- package/dist/directives/get-descriptive-name.js +0 -37
- package/dist/directives/get-import-identifier.d.ts +0 -4
- package/dist/directives/get-import-identifier.js +0 -19
- package/dist/directives/get-root-statement-path.d.ts +0 -2
- package/dist/directives/get-root-statement-path.js +0 -12
- package/dist/directives/index.d.ts +0 -14
- package/dist/directives/index.js +0 -169
- package/dist/directives/is-statement-top-level.d.ts +0 -3
- package/dist/directives/is-statement-top-level.js +0 -9
- package/dist/directives/paths.d.ts +0 -9
- package/dist/directives/paths.js +0 -36
- package/dist/directives/plugin.d.ts +0 -21
- package/dist/directives/plugin.js +0 -302
- package/dist/directives/remove-unused-variables.d.ts +0 -3
- package/dist/directives/remove-unused-variables.js +0 -53
- package/dist/directives/types.d.ts +0 -10
- package/dist/directives/types.js +0 -1
- package/dist/directives/xxhash32.d.ts +0 -6
- package/dist/directives/xxhash32.js +0 -193
- package/dist/fns/client.d.ts +0 -3
- package/dist/fns/client.js +0 -106
- package/dist/fns/handler.d.ts +0 -5
- package/dist/fns/handler.js +0 -269
- package/dist/fns/registration.d.ts +0 -2
- package/dist/fns/registration.js +0 -12
- package/dist/fns/serialization.d.ts +0 -6
- package/dist/fns/serialization.js +0 -208
- package/dist/fns/server.d.ts +0 -7
- package/dist/fns/server.js +0 -38
- package/dist/fns/shared.d.ts +0 -17
- package/dist/fns/shared.js +0 -105
- package/dist/http/index.d.ts +0 -81
- package/dist/http/index.js +0 -129
- package/dist/index.d.ts +0 -5
- package/dist/index.jsx +0 -6
- package/dist/middleware/index.d.ts +0 -38
- package/dist/middleware/index.js +0 -59
- package/dist/router.d.ts +0 -6
- package/dist/router.jsx +0 -29
- package/dist/server/StartServer.d.ts +0 -9
- package/dist/server/StartServer.jsx +0 -34
- package/dist/server/assets/PatchVirtualDevStyles.d.ts +0 -4
- package/dist/server/assets/PatchVirtualDevStyles.jsx +0 -28
- package/dist/server/assets/index.d.ts +0 -2
- package/dist/server/assets/index.js +0 -52
- package/dist/server/assets/render.d.ts +0 -19
- package/dist/server/assets/render.jsx +0 -14
- package/dist/server/collect-styles.d.ts +0 -3
- package/dist/server/collect-styles.js +0 -57
- package/dist/server/fetchEvent.d.ts +0 -7
- package/dist/server/fetchEvent.js +0 -26
- package/dist/server/handler.d.ts +0 -64
- package/dist/server/handler.js +0 -222
- package/dist/server/index.d.ts +0 -9
- package/dist/server/index.jsx +0 -14
- package/dist/server/manifest/client-manifest.d.ts +0 -9
- package/dist/server/manifest/client-manifest.js +0 -6
- package/dist/server/manifest/dev-client-manifest.d.ts +0 -4
- package/dist/server/manifest/dev-client-manifest.js +0 -24
- package/dist/server/manifest/dev-ssr-manifest.d.ts +0 -5
- package/dist/server/manifest/dev-ssr-manifest.js +0 -23
- package/dist/server/manifest/prod-client-manifest.d.ts +0 -5
- package/dist/server/manifest/prod-client-manifest.js +0 -26
- package/dist/server/manifest/prod-ssr-manifest.d.ts +0 -6
- package/dist/server/manifest/prod-ssr-manifest.js +0 -85
- package/dist/server/manifest/ssr-manifest.d.ts +0 -4
- package/dist/server/manifest/ssr-manifest.js +0 -6
- package/dist/server/routes.d.ts +0 -23
- package/dist/server/routes.js +0 -74
- package/dist/server/spa/StartServer.d.ts +0 -9
- package/dist/server/spa/StartServer.jsx +0 -25
- package/dist/server/spa/handler.d.ts +0 -36
- package/dist/server/spa/handler.js +0 -20
- package/dist/server/spa/index.d.ts +0 -4
- package/dist/server/spa/index.jsx +0 -5
- package/dist/server/types.d.ts +0 -75
- package/dist/server/types.js +0 -1
- package/dist/server/util.d.ts +0 -2
- package/dist/server/util.js +0 -8
- package/dist/shared/ErrorBoundary.d.ts +0 -3
- package/dist/shared/ErrorBoundary.jsx +0 -36
- package/dist/shared/GET.d.ts +0 -5
- package/dist/shared/GET.js +0 -8
- package/dist/shared/HttpHeader.d.ts +0 -10
- package/dist/shared/HttpHeader.jsx +0 -38
- package/dist/shared/HttpStatusCode.d.ts +0 -9
- package/dist/shared/HttpStatusCode.js +0 -18
- package/dist/shared/clientOnly.d.ts +0 -12
- package/dist/shared/clientOnly.js +0 -27
- package/dist/shared/dev-overlay/CodeView.d.ts +0 -7
- package/dist/shared/dev-overlay/CodeView.jsx +0 -62
- package/dist/shared/dev-overlay/DevOverlayDialog.d.ts +0 -9
- package/dist/shared/dev-overlay/DevOverlayDialog.jsx +0 -226
- package/dist/shared/dev-overlay/createStackFrame.d.ts +0 -9
- package/dist/shared/dev-overlay/createStackFrame.js +0 -56
- package/dist/shared/dev-overlay/download.d.ts +0 -1
- package/dist/shared/dev-overlay/download.js +0 -6
- package/dist/shared/dev-overlay/get-source-map.d.ts +0 -2
- package/dist/shared/dev-overlay/get-source-map.js +0 -25
- package/dist/shared/dev-overlay/icons.d.ts +0 -28
- package/dist/shared/dev-overlay/icons.jsx +0 -150
- package/dist/shared/dev-overlay/index.d.ts +0 -5
- package/dist/shared/dev-overlay/index.jsx +0 -39
- package/dist/shared/dev-overlay/styles.css +0 -292
- package/dist/shared/lazy.d.ts +0 -3
- package/dist/shared/lazy.js +0 -42
- package/dist/shared/serverFunction.d.ts +0 -6
- package/dist/shared/serverFunction.js +0 -8
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
-
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
-
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
-
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
return path;
|
|
8
|
-
};
|
|
9
|
-
import { NodeRequest, sendNodeResponse } from "srvx/node";
|
|
10
|
-
import { isRunnableDevEnvironment, } from "vite";
|
|
11
|
-
import { VITE_ENVIRONMENTS } from "./constants.js";
|
|
12
|
-
export function devServer() {
|
|
13
|
-
return [
|
|
14
|
-
{
|
|
15
|
-
name: "solid-start-dev-server",
|
|
16
|
-
configurePreviewServer(server) {
|
|
17
|
-
return () => {
|
|
18
|
-
server.middlewares.use(async (req, res) => {
|
|
19
|
-
res.setHeader("content-encoding", "identity");
|
|
20
|
-
const webReq = new NodeRequest({ req, res });
|
|
21
|
-
const def = await import(__rewriteRelativeImportExtension(process.cwd() + "/dist/server/entry-server.js", true));
|
|
22
|
-
sendNodeResponse(res, await def.default.fetch(webReq));
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
configureServer(viteDevServer) {
|
|
27
|
-
globalThis.VITE_DEV_SERVER = viteDevServer;
|
|
28
|
-
return async () => {
|
|
29
|
-
if (viteDevServer.config.server.middlewareMode)
|
|
30
|
-
return;
|
|
31
|
-
const serverEnv = viteDevServer.environments[VITE_ENVIRONMENTS.server];
|
|
32
|
-
if (!serverEnv)
|
|
33
|
-
throw new Error("Server environment not found");
|
|
34
|
-
if (
|
|
35
|
-
// do not check via `isFetchableDevEnvironment` since nitro does implement the `FetchableDevEnvironment` interface but not via inheritance (which this helper checks)
|
|
36
|
-
"dispatchFetch" in serverEnv)
|
|
37
|
-
return;
|
|
38
|
-
// another plugin is controlling the dev server
|
|
39
|
-
if (!isRunnableDevEnvironment(serverEnv)) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
globalThis.USING_SOLID_START_DEV_SERVER = true;
|
|
43
|
-
removeHtmlMiddlewares(viteDevServer);
|
|
44
|
-
viteDevServer.middlewares.use(async (req, res) => {
|
|
45
|
-
if (req.originalUrl) {
|
|
46
|
-
req.url = req.originalUrl;
|
|
47
|
-
}
|
|
48
|
-
const webReq = new NodeRequest({ req, res });
|
|
49
|
-
try {
|
|
50
|
-
const serverEntry = await serverEnv.runner.import("./src/entry-server.tsx");
|
|
51
|
-
const webRes = await serverEntry.default.fetch(webReq);
|
|
52
|
-
return sendNodeResponse(res, webRes);
|
|
53
|
-
}
|
|
54
|
-
catch (e) {
|
|
55
|
-
console.error(e);
|
|
56
|
-
viteDevServer.ssrFixStacktrace(e);
|
|
57
|
-
if (webReq.headers.get("content-type")?.includes("application/json")) {
|
|
58
|
-
return sendNodeResponse(res, Response.json({
|
|
59
|
-
status: 500,
|
|
60
|
-
error: "Internal Server Error",
|
|
61
|
-
message: "An unexpected error occurred. Please try again later.",
|
|
62
|
-
timestamp: new Date().toISOString(),
|
|
63
|
-
}, {
|
|
64
|
-
status: 500,
|
|
65
|
-
headers: {
|
|
66
|
-
"Content-Type": "application/json",
|
|
67
|
-
},
|
|
68
|
-
}));
|
|
69
|
-
}
|
|
70
|
-
return sendNodeResponse(res, new Response(`
|
|
71
|
-
<!DOCTYPE html>
|
|
72
|
-
<html lang="en">
|
|
73
|
-
<head>
|
|
74
|
-
<meta charset="UTF-8" />
|
|
75
|
-
<title>Error</title>
|
|
76
|
-
<script type="module">
|
|
77
|
-
import { ErrorOverlay } from '/@vite/client'
|
|
78
|
-
document.body.appendChild(new ErrorOverlay(${JSON.stringify(prepareError(req, e)).replace(/</g, "\\u003c")}))
|
|
79
|
-
</script>
|
|
80
|
-
</head>
|
|
81
|
-
<body>
|
|
82
|
-
</body>
|
|
83
|
-
</html>
|
|
84
|
-
`, {
|
|
85
|
-
status: 500,
|
|
86
|
-
headers: { "Content-Type": "text/html" },
|
|
87
|
-
}));
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Removes Vite internal middleware
|
|
97
|
-
*
|
|
98
|
-
* @param server
|
|
99
|
-
*/
|
|
100
|
-
function removeHtmlMiddlewares(server) {
|
|
101
|
-
const html_middlewares = [
|
|
102
|
-
"viteIndexHtmlMiddleware",
|
|
103
|
-
"vite404Middleware",
|
|
104
|
-
"viteSpaFallbackMiddleware",
|
|
105
|
-
];
|
|
106
|
-
for (let i = server.middlewares.stack.length - 1; i > 0; i--) {
|
|
107
|
-
if (html_middlewares.includes(
|
|
108
|
-
// @ts-expect-error
|
|
109
|
-
server.middlewares.stack[i].handle.name)) {
|
|
110
|
-
server.middlewares.stack.splice(i, 1);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Formats error for SSR message in error overlay
|
|
116
|
-
* @param req
|
|
117
|
-
* @param error
|
|
118
|
-
* @returns
|
|
119
|
-
*/
|
|
120
|
-
function prepareError(req, error) {
|
|
121
|
-
const e = error;
|
|
122
|
-
return {
|
|
123
|
-
message: `An error occured while server rendering ${req.url}:\n\n\t${typeof e === "string" ? e : e.message} `,
|
|
124
|
-
stack: typeof e === "string" ? "" : e.stack,
|
|
125
|
-
};
|
|
126
|
-
}
|
package/dist/config/env.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type Plugin } from "vite";
|
|
2
|
-
declare const LOADERS: {
|
|
3
|
-
node: string;
|
|
4
|
-
"cloudflare-workers": string;
|
|
5
|
-
"netlify-edge": string;
|
|
6
|
-
};
|
|
7
|
-
export interface EnvPluginOptions {
|
|
8
|
-
server?: {
|
|
9
|
-
runtime?: keyof typeof LOADERS | (string & {});
|
|
10
|
-
load?: (mode: string) => Record<string, string>;
|
|
11
|
-
prefix?: string;
|
|
12
|
-
};
|
|
13
|
-
client?: {
|
|
14
|
-
load?: (mode: string) => Record<string, string>;
|
|
15
|
-
prefix?: string;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
export declare function envPlugin(options?: EnvPluginOptions): Plugin;
|
|
19
|
-
export {};
|
package/dist/config/env.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { loadEnv } from "vite";
|
|
2
|
-
const LOADERS = {
|
|
3
|
-
node: `export default key => process.env[key];`,
|
|
4
|
-
"cloudflare-workers": `import { env } from 'cloudflare:workers';export default key => env[key];`,
|
|
5
|
-
"netlify-edge": `export default key => Netlify.env.get(key);`,
|
|
6
|
-
};
|
|
7
|
-
const SERVER_ENV = "env:server";
|
|
8
|
-
const CLIENT_ENV = "env:client";
|
|
9
|
-
const SERVER_RUNTIME_ENV = `${SERVER_ENV}/runtime`;
|
|
10
|
-
const SERVER_RUNTIME_LOADER = `${SERVER_RUNTIME_ENV}/loader`;
|
|
11
|
-
const DEFAULT_SERVER_PREFIX = "SERVER_";
|
|
12
|
-
const DEFAULT_CLIENT_PREFIX = "CLIENT_";
|
|
13
|
-
const SERVER_ONLY_MODULE = `throw new Error('Attempt to load server-only environment variables in client runtime.');`;
|
|
14
|
-
const SERVER_RUNTIME_CODE = `import load from '${SERVER_RUNTIME_LOADER}';
|
|
15
|
-
|
|
16
|
-
export default new Proxy({}, {
|
|
17
|
-
get(_, key) {
|
|
18
|
-
return load(key);
|
|
19
|
-
},
|
|
20
|
-
})`;
|
|
21
|
-
function convertObjectToModule(object) {
|
|
22
|
-
let result = "";
|
|
23
|
-
for (const key in object) {
|
|
24
|
-
result += `export const ${key} = ${JSON.stringify(object[key])};`;
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
export function envPlugin(options) {
|
|
29
|
-
const currentOptions = options ?? {};
|
|
30
|
-
let env;
|
|
31
|
-
const serverPrefix = currentOptions.server?.prefix ?? DEFAULT_SERVER_PREFIX;
|
|
32
|
-
const clientPrefix = currentOptions.client?.prefix ?? DEFAULT_CLIENT_PREFIX;
|
|
33
|
-
const runtime = options?.server?.runtime ?? "node";
|
|
34
|
-
const runtimeCode = runtime in LOADERS ? LOADERS[runtime] : runtime;
|
|
35
|
-
return {
|
|
36
|
-
name: "solid-start:env",
|
|
37
|
-
enforce: "pre",
|
|
38
|
-
configResolved(config) {
|
|
39
|
-
env = config.mode !== "production" ? "development" : "production";
|
|
40
|
-
},
|
|
41
|
-
resolveId(id) {
|
|
42
|
-
if (id === SERVER_ENV ||
|
|
43
|
-
id === CLIENT_ENV ||
|
|
44
|
-
id === SERVER_RUNTIME_ENV ||
|
|
45
|
-
id === SERVER_RUNTIME_LOADER) {
|
|
46
|
-
return id;
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
49
|
-
},
|
|
50
|
-
load(id, opts) {
|
|
51
|
-
if (id === SERVER_ENV) {
|
|
52
|
-
if (!opts?.ssr) {
|
|
53
|
-
return SERVER_ONLY_MODULE;
|
|
54
|
-
}
|
|
55
|
-
const vars = currentOptions.server?.load
|
|
56
|
-
? currentOptions.server.load(env)
|
|
57
|
-
: loadEnv(env, '.', serverPrefix);
|
|
58
|
-
return convertObjectToModule(vars);
|
|
59
|
-
}
|
|
60
|
-
if (id === CLIENT_ENV) {
|
|
61
|
-
const vars = currentOptions.client?.load
|
|
62
|
-
? currentOptions.client.load(env)
|
|
63
|
-
: loadEnv(env, '.', clientPrefix);
|
|
64
|
-
return convertObjectToModule(vars);
|
|
65
|
-
}
|
|
66
|
-
if (id === SERVER_RUNTIME_LOADER) {
|
|
67
|
-
if (!opts?.ssr) {
|
|
68
|
-
return SERVER_ONLY_MODULE;
|
|
69
|
-
}
|
|
70
|
-
return runtimeCode;
|
|
71
|
-
}
|
|
72
|
-
if (id === SERVER_RUNTIME_ENV) {
|
|
73
|
-
if (!opts?.ssr) {
|
|
74
|
-
return SERVER_ONLY_MODULE;
|
|
75
|
-
}
|
|
76
|
-
return SERVER_RUNTIME_CODE;
|
|
77
|
-
}
|
|
78
|
-
return undefined;
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { BaseFileSystemRouter, type FileSystemRouterConfig } from "./fs-routes/router.ts";
|
|
2
|
-
export declare class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
3
|
-
toPath(src: string): string;
|
|
4
|
-
toRoute(src: string): {
|
|
5
|
-
page: boolean;
|
|
6
|
-
$component: {
|
|
7
|
-
src: string;
|
|
8
|
-
pick: string[];
|
|
9
|
-
};
|
|
10
|
-
$$route: {
|
|
11
|
-
src: string;
|
|
12
|
-
pick: string[];
|
|
13
|
-
} | undefined;
|
|
14
|
-
path: string;
|
|
15
|
-
} | undefined;
|
|
16
|
-
}
|
|
17
|
-
export declare class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
18
|
-
config: FileSystemRouterConfig & {
|
|
19
|
-
dataOnly?: boolean;
|
|
20
|
-
};
|
|
21
|
-
constructor(config: FileSystemRouterConfig & {
|
|
22
|
-
dataOnly?: boolean;
|
|
23
|
-
});
|
|
24
|
-
toPath(src: string): string;
|
|
25
|
-
toRoute(src: string): {
|
|
26
|
-
path: string;
|
|
27
|
-
page: boolean;
|
|
28
|
-
$component: {
|
|
29
|
-
src: string;
|
|
30
|
-
pick: string[];
|
|
31
|
-
} | undefined;
|
|
32
|
-
$$route: {
|
|
33
|
-
src: string;
|
|
34
|
-
pick: string[];
|
|
35
|
-
} | undefined;
|
|
36
|
-
} | undefined;
|
|
37
|
-
}
|
package/dist/config/fs-router.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { analyzeModule, BaseFileSystemRouter, cleanPath, } from "./fs-routes/router.js";
|
|
2
|
-
export class SolidStartClientFileRouter extends BaseFileSystemRouter {
|
|
3
|
-
toPath(src) {
|
|
4
|
-
const routePath = cleanPath(src, this.config)
|
|
5
|
-
// remove the initial slash
|
|
6
|
-
.slice(1)
|
|
7
|
-
.replace(/index$/, "")
|
|
8
|
-
.replace(/\[([^/]+)\]/g, (_, m) => {
|
|
9
|
-
if (m.length > 3 && m.startsWith("...")) {
|
|
10
|
-
return `*${m.slice(3)}`;
|
|
11
|
-
}
|
|
12
|
-
if (m.length > 2 && m.startsWith("[") && m.endsWith("]")) {
|
|
13
|
-
return `:${m.slice(1, -1)}?`;
|
|
14
|
-
}
|
|
15
|
-
return `:${m}`;
|
|
16
|
-
});
|
|
17
|
-
return routePath?.length > 0 ? `/${routePath}` : "/";
|
|
18
|
-
}
|
|
19
|
-
toRoute(src) {
|
|
20
|
-
const path = this.toPath(src);
|
|
21
|
-
if (src.endsWith(".md") || src.endsWith(".mdx")) {
|
|
22
|
-
return {
|
|
23
|
-
page: true,
|
|
24
|
-
$component: {
|
|
25
|
-
src: src,
|
|
26
|
-
pick: ["$css"],
|
|
27
|
-
},
|
|
28
|
-
$$route: undefined,
|
|
29
|
-
path,
|
|
30
|
-
// filePath: src
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
const [_, exports] = analyzeModule(src);
|
|
34
|
-
const hasDefault = !!exports.find(e => e.n === "default");
|
|
35
|
-
const hasRouteConfig = !!exports.find(e => e.n === "route");
|
|
36
|
-
if (hasDefault) {
|
|
37
|
-
return {
|
|
38
|
-
page: true,
|
|
39
|
-
$component: {
|
|
40
|
-
src: src,
|
|
41
|
-
pick: [
|
|
42
|
-
...exports.filter(e => e.n === e.ln && e.n !== "route").map(e => e.n),
|
|
43
|
-
"default",
|
|
44
|
-
"$css",
|
|
45
|
-
],
|
|
46
|
-
},
|
|
47
|
-
$$route: hasRouteConfig
|
|
48
|
-
? {
|
|
49
|
-
src: src,
|
|
50
|
-
pick: ["route"],
|
|
51
|
-
}
|
|
52
|
-
: undefined,
|
|
53
|
-
path,
|
|
54
|
-
// filePath: src
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const HTTP_METHODS = ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"];
|
|
60
|
-
function createHTTPHandlers(src, exports) {
|
|
61
|
-
const handlers = {};
|
|
62
|
-
for (const exp of exports) {
|
|
63
|
-
if (HTTP_METHODS.includes(exp.n)) {
|
|
64
|
-
handlers[`$${exp.n}`] = {
|
|
65
|
-
src: src,
|
|
66
|
-
pick: [exp.n],
|
|
67
|
-
};
|
|
68
|
-
if (exp.n === "GET" && !exports.find(exp => exp.n === "HEAD")) {
|
|
69
|
-
handlers.$HEAD = {
|
|
70
|
-
src: src,
|
|
71
|
-
pick: [exp.n],
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return handlers;
|
|
77
|
-
}
|
|
78
|
-
export class SolidStartServerFileRouter extends BaseFileSystemRouter {
|
|
79
|
-
constructor(config) {
|
|
80
|
-
super(config);
|
|
81
|
-
}
|
|
82
|
-
toPath(src) {
|
|
83
|
-
const routePath = cleanPath(src, this.config)
|
|
84
|
-
// remove the initial slash
|
|
85
|
-
.slice(1)
|
|
86
|
-
.replace(/index$/, "")
|
|
87
|
-
.replace(/\[([^/]+)\]/g, (_, m) => {
|
|
88
|
-
if (m.length > 3 && m.startsWith("...")) {
|
|
89
|
-
return `*${m.slice(3)}`;
|
|
90
|
-
}
|
|
91
|
-
if (m.length > 2 && m.startsWith("[") && m.endsWith("]")) {
|
|
92
|
-
return `:${m.slice(1, -1)}?`;
|
|
93
|
-
}
|
|
94
|
-
return `:${m}`;
|
|
95
|
-
});
|
|
96
|
-
return routePath?.length > 0 ? `/${routePath}` : "/";
|
|
97
|
-
}
|
|
98
|
-
toRoute(src) {
|
|
99
|
-
const path = this.toPath(src);
|
|
100
|
-
if (src.endsWith(".md") || src.endsWith(".mdx")) {
|
|
101
|
-
return {
|
|
102
|
-
page: true,
|
|
103
|
-
$component: {
|
|
104
|
-
src: src,
|
|
105
|
-
pick: ["$css"],
|
|
106
|
-
},
|
|
107
|
-
$$route: undefined,
|
|
108
|
-
path,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
const [_, exports] = analyzeModule(src);
|
|
112
|
-
const hasRouteConfig = exports.find(e => e.n === "route");
|
|
113
|
-
const hasDefault = !!exports.find(e => e.n === "default");
|
|
114
|
-
const hasAPIRoutes = !!exports.find(exp => HTTP_METHODS.includes(exp.n));
|
|
115
|
-
if (hasDefault || hasAPIRoutes) {
|
|
116
|
-
return {
|
|
117
|
-
page: hasDefault,
|
|
118
|
-
$component: !this.config.dataOnly && hasDefault
|
|
119
|
-
? {
|
|
120
|
-
src: src,
|
|
121
|
-
pick: [
|
|
122
|
-
...exports
|
|
123
|
-
.filter(e => e.n === e.ln && e.n !== "route" && !HTTP_METHODS.includes(e.n))
|
|
124
|
-
.map(e => e.n),
|
|
125
|
-
"default",
|
|
126
|
-
"$css",
|
|
127
|
-
],
|
|
128
|
-
}
|
|
129
|
-
: undefined,
|
|
130
|
-
$$route: hasRouteConfig
|
|
131
|
-
? {
|
|
132
|
-
src: src,
|
|
133
|
-
pick: ["route"],
|
|
134
|
-
}
|
|
135
|
-
: undefined,
|
|
136
|
-
...createHTTPHandlers(src, exports),
|
|
137
|
-
path,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { VITE_ENVIRONMENTS } from "../constants.js";
|
|
2
|
-
import { moduleId } from "./index.js";
|
|
3
|
-
function setupWatcher(watcher, routes) {
|
|
4
|
-
watcher.on("unlink", path => routes.removeRoute(path));
|
|
5
|
-
watcher.on("add", path => routes.addRoute(path));
|
|
6
|
-
watcher.on("change", path => routes.updateRoute(path));
|
|
7
|
-
}
|
|
8
|
-
function createRoutesReloader(server, routes, environment) {
|
|
9
|
-
routes.addEventListener("reload", handleRoutesReload);
|
|
10
|
-
return () => routes.removeEventListener("reload", handleRoutesReload);
|
|
11
|
-
function handleRoutesReload() {
|
|
12
|
-
const envName = environment === "ssr" ? VITE_ENVIRONMENTS.server : VITE_ENVIRONMENTS.client;
|
|
13
|
-
const devEnv = server.environments[envName];
|
|
14
|
-
if (!devEnv?.moduleGraph)
|
|
15
|
-
return;
|
|
16
|
-
const mod = devEnv.moduleGraph.getModuleById(moduleId);
|
|
17
|
-
if (mod) {
|
|
18
|
-
const seen = new Set();
|
|
19
|
-
devEnv.moduleGraph.invalidateModule(mod, seen);
|
|
20
|
-
}
|
|
21
|
-
if (environment !== "ssr") {
|
|
22
|
-
if (mod) {
|
|
23
|
-
devEnv.reloadModule(mod);
|
|
24
|
-
}
|
|
25
|
-
else if (devEnv.hot) {
|
|
26
|
-
devEnv.hot.send({ type: "full-reload" });
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export const fileSystemWatcher = (routers) => {
|
|
32
|
-
const plugin = {
|
|
33
|
-
name: "fs-watcher",
|
|
34
|
-
async configureServer(server) {
|
|
35
|
-
Object.keys(routers).forEach(environment => {
|
|
36
|
-
const router = globalThis.ROUTERS[environment];
|
|
37
|
-
setupWatcher(server.watcher, router);
|
|
38
|
-
createRoutesReloader(server, router, environment);
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
return plugin;
|
|
43
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type PluginOption } from "vite";
|
|
2
|
-
import type { BaseFileSystemRouter } from "./router.ts";
|
|
3
|
-
export declare const moduleId = "solid-start:routes";
|
|
4
|
-
export interface FsRoutesArgs {
|
|
5
|
-
routers: Record<"client" | "ssr", BaseFileSystemRouter>;
|
|
6
|
-
}
|
|
7
|
-
export declare function fsRoutes({ routers }: FsRoutesArgs): Array<PluginOption>;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { relative } from "node:path";
|
|
2
|
-
import { fileSystemWatcher } from "./fs-watcher.js";
|
|
3
|
-
import { treeShake } from "./tree-shake.js";
|
|
4
|
-
export const moduleId = "solid-start:routes";
|
|
5
|
-
export function fsRoutes({ routers }) {
|
|
6
|
-
globalThis.ROUTERS = routers;
|
|
7
|
-
return [
|
|
8
|
-
{
|
|
9
|
-
name: "solid-start-fs-routes",
|
|
10
|
-
enforce: "pre",
|
|
11
|
-
resolveId(id) {
|
|
12
|
-
if (id === moduleId)
|
|
13
|
-
return id;
|
|
14
|
-
},
|
|
15
|
-
async load(id) {
|
|
16
|
-
const root = this.environment.config.root;
|
|
17
|
-
const isBuild = this.environment.mode === "build";
|
|
18
|
-
if (id !== moduleId)
|
|
19
|
-
return;
|
|
20
|
-
const js = jsCode();
|
|
21
|
-
const router = globalThis.ROUTERS[this.environment.name];
|
|
22
|
-
const routes = await router.getRoutes();
|
|
23
|
-
let routesCode = JSON.stringify(routes ?? [], (k, v) => {
|
|
24
|
-
if (v === undefined)
|
|
25
|
-
return undefined;
|
|
26
|
-
if (k.startsWith("$$")) {
|
|
27
|
-
const buildId = `${v.src}?${v.pick.map((p) => `pick=${p}`).join("&")}`;
|
|
28
|
-
/**
|
|
29
|
-
* @type {{ [key: string]: string }}
|
|
30
|
-
*/
|
|
31
|
-
const refs = {};
|
|
32
|
-
for (var pick of v.pick) {
|
|
33
|
-
refs[pick] = js.addNamedImport(pick, buildId);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
require: `_$() => ({ ${Object.entries(refs)
|
|
37
|
-
.map(([pick, namedImport]) => `'${pick}': ${namedImport}`)
|
|
38
|
-
.join(", ")} })$_`,
|
|
39
|
-
// src: isBuild ? relative(root, buildId) : buildId
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
else if (k.startsWith("$")) {
|
|
43
|
-
const buildId = `${v.src}?${v.pick.map((p) => `pick=${p}`).join("&")}`;
|
|
44
|
-
return {
|
|
45
|
-
src: relative(root, buildId),
|
|
46
|
-
build: isBuild ? `_$() => import('${buildId}')$_` : undefined,
|
|
47
|
-
import: `_$() => import('${buildId}')$_`,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return v;
|
|
51
|
-
});
|
|
52
|
-
routesCode = routesCode.replaceAll('"_$(', "(").replaceAll(')$_"', ")");
|
|
53
|
-
const code = `
|
|
54
|
-
${js.getImportStatements()}
|
|
55
|
-
export default ${routesCode}`;
|
|
56
|
-
return code;
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
treeShake(),
|
|
60
|
-
fileSystemWatcher(routers),
|
|
61
|
-
];
|
|
62
|
-
}
|
|
63
|
-
function jsCode() {
|
|
64
|
-
const imports = new Map();
|
|
65
|
-
let vars = 0;
|
|
66
|
-
function addImport(p) {
|
|
67
|
-
let id = imports.get(p);
|
|
68
|
-
if (!id) {
|
|
69
|
-
id = {};
|
|
70
|
-
imports.set(p, id);
|
|
71
|
-
}
|
|
72
|
-
const d = "routeData" + vars++;
|
|
73
|
-
id["default"] = d;
|
|
74
|
-
return d;
|
|
75
|
-
}
|
|
76
|
-
function addNamedImport(name, p) {
|
|
77
|
-
let id = imports.get(p);
|
|
78
|
-
if (!id) {
|
|
79
|
-
id = {};
|
|
80
|
-
imports.set(p, id);
|
|
81
|
-
}
|
|
82
|
-
const d = "routeData" + vars++;
|
|
83
|
-
id[name] = d;
|
|
84
|
-
return d;
|
|
85
|
-
}
|
|
86
|
-
const getNamedExport = (p) => {
|
|
87
|
-
const id = imports.get(p);
|
|
88
|
-
delete id["default"];
|
|
89
|
-
return Object.keys(id).length > 0
|
|
90
|
-
? `{ ${Object.keys(id)
|
|
91
|
-
.map(k => `${k} as ${id[k]}`)
|
|
92
|
-
.join(", ")} }`
|
|
93
|
-
: "";
|
|
94
|
-
};
|
|
95
|
-
const getImportStatements = () => {
|
|
96
|
-
return `${[...imports.keys()]
|
|
97
|
-
.map(i => `import ${imports.get(i).default
|
|
98
|
-
? `${imports.get(i).default}${Object.keys(imports.get(i)).length > 1 ? ", " : ""}`
|
|
99
|
-
: ""} ${getNamedExport(i)} from '${i}';`)
|
|
100
|
-
.join("\n")}`;
|
|
101
|
-
};
|
|
102
|
-
return {
|
|
103
|
-
addImport,
|
|
104
|
-
addNamedImport,
|
|
105
|
-
getImportStatements,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { pathToRegexp } from "path-to-regexp";
|
|
2
|
-
export { pathToRegexp };
|
|
3
|
-
export declare const glob: (path: string) => string[];
|
|
4
|
-
export type FileSystemRouterConfig = {
|
|
5
|
-
dir: string;
|
|
6
|
-
extensions: string[];
|
|
7
|
-
};
|
|
8
|
-
type Route = {
|
|
9
|
-
path: string;
|
|
10
|
-
} & Record<string, any>;
|
|
11
|
-
export declare function cleanPath(src: string, config: FileSystemRouterConfig): string;
|
|
12
|
-
export declare function analyzeModule(src: string): readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean, hasModuleSyntax: boolean];
|
|
13
|
-
export declare class BaseFileSystemRouter extends EventTarget {
|
|
14
|
-
routes: Route[];
|
|
15
|
-
config: FileSystemRouterConfig;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {} config
|
|
19
|
-
*/
|
|
20
|
-
constructor(config: FileSystemRouterConfig);
|
|
21
|
-
glob(): string;
|
|
22
|
-
buildRoutes(): Promise<any[]>;
|
|
23
|
-
isRoute(src: string): boolean;
|
|
24
|
-
toPath(src: string): void;
|
|
25
|
-
toRoute(src: string): Route | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* To be attached by vite plugin to the vite dev server
|
|
28
|
-
*/
|
|
29
|
-
update: undefined;
|
|
30
|
-
_addRoute(route: Route): void;
|
|
31
|
-
addRoute(src: string): Promise<void>;
|
|
32
|
-
reload(route: string): void;
|
|
33
|
-
updateRoute(src: string): Promise<void>;
|
|
34
|
-
removeRoute(src: string): void;
|
|
35
|
-
buildRoutesPromise?: Promise<any[]>;
|
|
36
|
-
getRoutes(): Promise<Route[]>;
|
|
37
|
-
}
|