Skip to content

Commit ee6c4dd

Browse files
committed
fix ts
1 parent 3cf86c5 commit ee6c4dd

11 files changed

Lines changed: 705 additions & 856 deletions

File tree

packages/start/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
}
2525
},
2626
"dependencies": {
27-
"@babel/core": "^7.28.0",
27+
"@babel/core": "^7.28.3",
28+
"@babel/traverse": "^7.28.3",
2829
"@solidjs/meta": "^0.29.4",
2930
"@tanstack/server-functions-plugin": "^1.115.0",
31+
"@types/babel__traverse": "^7.28.0",
3032
"@types/micromatch": "^4.0.9",
3133
"defu": "^6.1.4",
3234
"error-stack-parser": "^2.1.4",
@@ -40,7 +42,7 @@
4042
"path-to-regexp": "^8.2.0",
4143
"pathe": "^2.0.3",
4244
"radix3": "^1.1.2",
43-
"seroval": "^1.2.1",
45+
"seroval": "^1.3.2",
4446
"seroval-plugins": "^1.2.1",
4547
"shiki": "^1.26.1",
4648
"solid-js": "^1.9.5",

packages/start/src/config/fs-routes/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import { PluginOption, ResolvedConfig } from "vite";
21
import { relative } from "node:path";
3-
4-
import { BaseFileSystemRouter } from "./router.js";
2+
import type { PluginOption, ResolvedConfig } from "vite";
53
import { manifest } from "./manifest.js";
4+
import type { BaseFileSystemRouter } from "./router.js";
65

76
export const moduleId = "solid-start:routes";
87

98
export type RouterBuilder = (config: ResolvedConfig) => BaseFileSystemRouter;
109

10+
export interface FsRoutesArgs {
11+
routers: Record<"client" | "server", RouterBuilder>;
12+
handlers: Record<"client" | "server", string>;
13+
}
14+
1115
export function fsRoutes({
1216
routers,
1317
handlers
14-
}: {
15-
routers: Record<"client" | "server", RouterBuilder>;
16-
handlers: Record<"client" | "server", string>;
17-
}): Array<PluginOption> {
18+
}: FsRoutesArgs): Array<PluginOption> {
1819
(globalThis as any).ROUTERS = {};
1920

2021
return [

packages/start/src/config/fs-routes/tree-shake.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
// https://github.com/vercel/next.js/blob/canary/packages/next/build/babel/plugins/next-ssg-transform.ts
33
// This is adapted to work with routeData functions. It can be run in two modes, one which preserves the routeData and the Component in the same file, and one which creates a
44

5+
import type { NodePath, PluginObj, PluginPass } from "@babel/core";
6+
import type * as Babel from '@babel/core';
7+
import { Binding } from "@babel/traverse";
58
import { basename } from "pathe";
6-
import { Plugin, ViteDevServer } from "vite";
9+
import type { Plugin, ResolvedConfig, ViteDevServer } from "vite";
710

8-
function treeShakeTransform({ types: t }) {
9-
function getIdentifier(path) {
11+
type State = Omit<PluginPass, "opts"> & { opts: { pick: string[] }, refs: Set<any>, done: boolean }
12+
13+
function treeShakeTransform({ types: t }: typeof Babel): PluginObj<State> {
14+
function getIdentifier(path: any) {
1015
const parentPath = path.parentPath;
1116
if (parentPath.type === "VariableDeclarator") {
1217
const pp = parentPath;
@@ -24,9 +29,9 @@ function treeShakeTransform({ types: t }) {
2429
return path.node.id && path.node.id.type === "Identifier" ? path.get("id") : null;
2530
}
2631

27-
function isIdentifierReferenced(ident) {
28-
const b = ident.scope.getBinding(ident.node.name);
29-
if (b && b.referenced) {
32+
function isIdentifierReferenced(ident: any) {
33+
const b: Binding | undefined = ident.scope.getBinding(ident.node.name);
34+
if (b?.referenced) {
3035
if (b.path.type === "FunctionDeclaration") {
3136
return !b.constantViolations
3237
.concat(b.referencePaths)
@@ -36,13 +41,13 @@ function treeShakeTransform({ types: t }) {
3641
}
3742
return false;
3843
}
39-
function markFunction(path, state) {
44+
function markFunction(path: any, state: any) {
4045
const ident = getIdentifier(path);
4146
if (ident && ident.node && isIdentifierReferenced(ident)) {
4247
state.refs.add(ident);
4348
}
4449
}
45-
function markImport(path, state) {
50+
function markImport(path: any, state: any) {
4651
const local = path.get("local");
4752
if (isIdentifierReferenced(local)) {
4853
state.refs.add(local);
@@ -57,34 +62,34 @@ function treeShakeTransform({ types: t }) {
5762
state.done = false;
5863
path.traverse(
5964
{
60-
VariableDeclarator(variablePath, variableState) {
65+
VariableDeclarator(variablePath, variableState: any) {
6166
if (variablePath.node.id.type === "Identifier") {
6267
const local = variablePath.get("id");
6368
if (isIdentifierReferenced(local)) {
6469
variableState.refs.add(local);
6570
}
6671
} else if (variablePath.node.id.type === "ObjectPattern") {
6772
const pattern = variablePath.get("id");
68-
const properties = pattern.get("properties");
73+
const properties = pattern.get("properties") as Array<NodePath>;
6974
properties.forEach(p => {
7075
const local = p.get(
7176
p.node.type === "ObjectProperty"
7277
? "value"
7378
: p.node.type === "RestElement"
7479
? "argument"
7580
: (function () {
76-
throw new Error("invariant");
77-
})()
81+
throw new Error("invariant");
82+
})()
7883
);
7984
if (isIdentifierReferenced(local)) {
8085
variableState.refs.add(local);
8186
}
8287
});
8388
} else if (variablePath.node.id.type === "ArrayPattern") {
8489
const pattern = variablePath.get("id");
85-
const elements = pattern.get("elements");
90+
const elements = pattern.get("elements") as Array<NodePath>;
8691
elements.forEach(e => {
87-
let local;
92+
let local: NodePath<any>;
8893
if (e.node && e.node.type === "Identifier") {
8994
local = e;
9095
} else if (e.node && e.node.type === "RestElement") {
@@ -131,14 +136,14 @@ function treeShakeTransform({ types: t }) {
131136
}
132137
switch (decl.node.type) {
133138
case "FunctionDeclaration": {
134-
const name = decl.node.id.name;
135-
if (state.opts.pick && !state.opts.pick.includes(name)) {
139+
const name = decl.node.id?.name;
140+
if (name && state.opts.pick && !state.opts.pick.includes(name)) {
136141
exportNamedPath.remove();
137142
}
138143
break;
139144
}
140145
case "VariableDeclaration": {
141-
const inner = decl.get("declarations");
146+
const inner = decl.get("declarations") as Array<NodePath<any>>;
142147
inner.forEach(d => {
143148
if (d.node.id.type !== "Identifier") {
144149
return;
@@ -175,8 +180,8 @@ function treeShakeTransform({ types: t }) {
175180
);
176181

177182
const refs = state.refs;
178-
let count;
179-
function sweepFunction(sweepPath) {
183+
let count = 0;
184+
const sweepFunction = (sweepPath: any) => {
180185
const ident = getIdentifier(sweepPath);
181186
if (ident && ident.node && refs.has(ident) && !isIdentifierReferenced(ident)) {
182187
++count;
@@ -190,7 +195,7 @@ function treeShakeTransform({ types: t }) {
190195
}
191196
}
192197
}
193-
function sweepImport(sweepPath) {
198+
function sweepImport(sweepPath: any) {
194199
const local = sweepPath.get("local");
195200
if (refs.has(local) && !isIdentifierReferenced(local)) {
196201
++count;
@@ -222,8 +227,8 @@ function treeShakeTransform({ types: t }) {
222227
: p.node.type === "RestElement"
223228
? "argument"
224229
: (function () {
225-
throw new Error("invariant");
226-
})()
230+
throw new Error("invariant");
231+
})()
227232
);
228233
if (refs.has(local) && !isIdentifierReferenced(local)) {
229234
++count;
@@ -238,7 +243,7 @@ function treeShakeTransform({ types: t }) {
238243
const beforeCount = count;
239244
const elements = pattern.get("elements");
240245
elements.forEach(e => {
241-
let local;
246+
let local: NodePath<any> | undefined;
242247
if (e.node && e.node.type === "Identifier") {
243248
local = e;
244249
} else if (e.node && e.node.type === "RestElement") {
@@ -271,8 +276,7 @@ function treeShakeTransform({ types: t }) {
271276
}
272277

273278
export function treeShake(): Plugin {
274-
/** @type {import('../vite-dev.d.ts').ViteConfig} */
275-
let config;
279+
let config: ResolvedConfig;
276280
let cache: Record<string, any> = {};
277281
let server: ViteDevServer;
278282

@@ -348,7 +352,7 @@ export function treeShake(): Plugin {
348352
if (!ext) return;
349353
if (query.has("pick") && ["js", "jsx", "ts", "tsx"].includes(ext)) {
350354
const transformed = await transform(id, code);
351-
if (!transformed) return;
355+
if (!transformed?.code) return;
352356

353357
cache[path] ??= {};
354358
cache[path][id] = transformed.code;

packages/start/src/config/index.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,6 @@ function solidStartVitePlugin(options: SolidStartOptions): Array<PluginOption> {
9595
server: `${start.appRoot}/entry-server${entryExtension}`
9696
};
9797

98-
const routers = {
99-
handlers,
100-
routers: {
101-
client: config =>
102-
new SolidStartClientFileRouter({
103-
dir: absolute(routeDir, config.root),
104-
extensions
105-
}),
106-
server: config =>
107-
new SolidStartServerFileRouter({
108-
dir: absolute(routeDir, config.root),
109-
extensions,
110-
dataOnly: !start.ssr
111-
})
112-
}
113-
};
114-
11598
return [
11699
{
117100
name: "solid-start-vite-config-client",
@@ -190,7 +173,22 @@ function solidStartVitePlugin(options: SolidStartOptions): Array<PluginOption> {
190173
return SolidStartServerFnsPlugin.client;
191174
}
192175
},
193-
fsRoutes(routers),
176+
fsRoutes({
177+
handlers,
178+
routers: {
179+
client: config =>
180+
new SolidStartClientFileRouter({
181+
dir: absolute(routeDir, config.root),
182+
extensions
183+
}),
184+
server: config =>
185+
new SolidStartServerFileRouter({
186+
dir: absolute(routeDir, config.root),
187+
extensions,
188+
dataOnly: !start.ssr
189+
})
190+
}
191+
}),
194192
{
195193
name: "solid-start:manifest-plugin",
196194
enforce: "pre",

packages/start/src/server/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ async function createPageEvent(ctx: FetchEvent) {
4141
// router: {
4242
// // submission: initFromFlash(ctx) as any
4343
// },
44-
routes: createRoutes()
44+
routes: createRoutes(),
4545
// // prevUrl: prevPath || "",
4646
// // mutation: mutation,
4747
// // $type: FETCH_EVENT,
48-
// complete: false,
49-
// $islands: new Set<string>()
48+
complete: false,
49+
$islands: new Set<string>()
5050
});
5151

5252
return pageEvent;
@@ -70,7 +70,9 @@ export function createHandler(fn: (context: PageEvent) => JSX.Element) {
7070

7171
if (serverFnResponse instanceof Response) return serverFnResponse;
7272

73-
const resp = new Response(serverFnResponse, { headers: getResponseHeaders(e) });
73+
const resp = new Response(serverFnResponse as any, {
74+
headers: getResponseHeaders(e) as any
75+
});
7476

7577
return resp;
7678
}

packages/start/src/server/server-functions-handler.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ export async function handleServerFunction(h3Event: H3Event) {
147147
]
148148
}) as any)
149149
: json
150-
).forEach((arg: any) => parsed.push(arg));
150+
).forEach((arg: any) => {
151+
parsed.push(arg)
152+
});
151153
}
152154
}
153155
if (h3Event.method === "POST") {
@@ -261,7 +263,7 @@ export async function handleServerFunction(h3Event: H3Event) {
261263
setResponseStatus(h3Event, (x as any).status);
262264
if ((x as any).customBody) {
263265
x = (x as any).customBody();
264-
} else if ((x as any).body == undefined) x = null;
266+
} else if ((x as any).body === undefined) x = null;
265267
setHeader(h3Event, "X-Error", "true");
266268
} else if (instance) {
267269
const error = x instanceof Error ? x.message : typeof x === "string" ? x : "true";
@@ -281,7 +283,7 @@ function handleNoJS(result: any, request: Request, parsed: any[], thrown?: boole
281283
const url = new URL(request.url);
282284
const isError = result instanceof Error;
283285
let statusCode = 302;
284-
let headers;
286+
let headers: Headers;
285287
if (result instanceof Response) {
286288
headers = new Headers(result.headers);
287289
if (result.headers.has("Location")) {

packages/start/src/server/server-manifest.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1+
import path from "node:path";
12
import { manifest } from "solid-start:server-manifest";
2-
import path, { isAbsolute, join, normalize } from "node:path";
3-
import { fileURLToPath } from "node:url";
4-
import { existsSync } from "node:fs";
53
import { normalizePath } from "vite";
64

75
export const CLIENT_BASE_PATH = "_build";

packages/start/src/server/types.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ export type DocumentComponentProps = {
1212

1313
export type Asset =
1414
| {
15-
tag: "style";
16-
attrs: JSX.StyleHTMLAttributes<HTMLStyleElement> & { key?: string };
17-
children?: JSX.Element;
18-
}
15+
tag: "style";
16+
attrs: JSX.StyleHTMLAttributes<HTMLStyleElement> & { key?: string };
17+
children?: JSX.Element;
18+
}
1919
| {
20-
tag: "script";
21-
attrs: JSX.ScriptHTMLAttributes<HTMLScriptElement> & { key?: string };
22-
}
20+
tag: "script";
21+
attrs: JSX.ScriptHTMLAttributes<HTMLScriptElement> & { key?: string };
22+
}
2323
| {
24-
tag: "link";
25-
attrs: JSX.LinkHTMLAttributes<HTMLLinkElement> & { key?: string };
26-
};
24+
tag: "link";
25+
attrs: JSX.LinkHTMLAttributes<HTMLLinkElement> & { key?: string };
26+
};
2727

2828
export type HandlerOptions = {
2929
mode?: "sync" | "async" | "stream";

packages/start/src/virtual.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
declare module "solid-start:server-manifest" {
22
interface StartServerManifest {
33
clientEntryId: string;
4-
clientViteManifest: Record<string, any>;
4+
clientViteManifest: Record<string, { css?: Array<string>, file?: string, [key: string]: unknown }>;
55
routes: Record<string, { output: string }>;
66
}
77

@@ -13,3 +13,7 @@ declare module "solid-start:client-prod-manifest" {
1313

1414
export default {} as Manifest;
1515
}
16+
17+
declare module "#start/app" {
18+
export default App as import("solid-js").Component;
19+
}

packages/start/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"compilerOptions": {
33
"target": "ESNext",
4-
"module": "node16",
5-
"moduleResolution": "node16",
4+
"module": "ESNext",
5+
"moduleResolution": "node",
66
"strict": true,
77
"noUncheckedIndexedAccess": true,
88
"allowSyntheticDefaultImports": true,

0 commit comments

Comments
 (0)