diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 377f78e34..c5fe6c749 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,6 +64,9 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile + - name: 🔨 Build + run: pnpm --filter solid-start build:entry-client + - name: Use Deno if: matrix.adapter == 'solid-start-deno' uses: denoland/setup-deno@v1 diff --git a/packages/start/entry-client/package.json b/packages/start/entry-client/package.json new file mode 100644 index 000000000..529efcc82 --- /dev/null +++ b/packages/start/entry-client/package.json @@ -0,0 +1,7 @@ +{ + "name": "solid-start/entry-client", + "module": "./dist/index.jsx", + "types": "./dist/index.d.ts", + "type": "module", + "sideEffects": false +} diff --git a/packages/start/entry-client/StartClient.tsx b/packages/start/entry-client/src/StartClient.tsx similarity index 95% rename from packages/start/entry-client/StartClient.tsx rename to packages/start/entry-client/src/StartClient.tsx index 10fb95790..99dd15646 100644 --- a/packages/start/entry-client/StartClient.tsx +++ b/packages/start/entry-client/src/StartClient.tsx @@ -2,8 +2,8 @@ import { MetaProvider } from "@solidjs/meta"; import { Router, RouterProps } from "@solidjs/router"; // @ts-ignore import Root from "~start/root"; -import { ServerContext } from "../server/ServerContext"; -import { FETCH_EVENT, PageEvent } from "../server/types"; +import { ServerContext } from "solid-start/server/ServerContext"; +import { FETCH_EVENT, PageEvent } from "solid-start/server/types"; const rootData: { default: () => Promise } = Object.values( import.meta.glob("/src/root.data.(js|ts)", { eager: true }) diff --git a/packages/start/entry-client/index.tsx b/packages/start/entry-client/src/index.tsx similarity index 100% rename from packages/start/entry-client/index.tsx rename to packages/start/entry-client/src/index.tsx diff --git a/packages/start/entry-client/mount.tsx b/packages/start/entry-client/src/mount.tsx similarity index 92% rename from packages/start/entry-client/mount.tsx rename to packages/start/entry-client/src/mount.tsx index 05bb2bad3..1d08029cb 100644 --- a/packages/start/entry-client/mount.tsx +++ b/packages/start/entry-client/src/mount.tsx @@ -1,8 +1,8 @@ import type { JSX } from "solid-js"; import { hydrate, render } from "solid-js/web"; -import { hydrateServerRouter } from "../islands/mount"; -import mountRouter from "../islands/router"; +import { hydrateServerRouter } from "solid-start/islands/mount"; +import mountRouter from "solid-start/islands/router"; declare global { interface Window { diff --git a/packages/start/entry-client/tsconfig.json b/packages/start/entry-client/tsconfig.json new file mode 100644 index 000000000..9339cfa28 --- /dev/null +++ b/packages/start/entry-client/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "noEmit": false, + "emitDeclarationOnly": false, + "outDir": "./dist", + "types": ["../env", "solid-start/vite/plugin", "solid-start/router"], + "paths": { + "solid-start/islands": ["../islands"], + "solid-start/server": ["../server"] + } + }, + "include": ["./src"], + "exclude": [] +} diff --git a/packages/start/islands/entry-client.ts b/packages/start/islands/entry-client.ts index f14b5737b..8d8f54cc5 100644 --- a/packages/start/islands/entry-client.ts +++ b/packages/start/islands/entry-client.ts @@ -1,3 +1,3 @@ -import StartClient from "../entry-client/StartClient"; +import StartClient from "../entry-client/src/StartClient"; StartClient(); diff --git a/packages/start/package.json b/packages/start/package.json index ad8c848d8..001c4c320 100644 --- a/packages/start/package.json +++ b/packages/start/package.json @@ -23,8 +23,11 @@ "./api": "./api/index.ts", "./api/*": "./api/*", "./durable-object": "./durable-object/index.ts", - "./entry-client": "./entry-client/index.tsx", - "./entry-client/*": "./entry-client/*", + "./entry-client": { + "types": "./entry-client/dist/index.d.ts", + "import": "./entry-client/dist/index.jsx" + }, + "./entry-client/dist/*": "./entry-client/dist/*", "./entry-server": "./entry-server/index.ts", "./entry-server/*": "./entry-server/*", "./error-boundary": "./error-boundary/index.tsx", @@ -62,7 +65,8 @@ "data", "dev", "durable-object", - "entry-client", + "entry-client/dist", + "entry-client/package.json", "entry-server", "error-boundary", "fs-router", @@ -82,7 +86,8 @@ "types.ts" ], "scripts": { - "typecheck": "tsc --noEmit --checkJs false --skipLibCheck" + "build:entry-client": "tsc --project ./entry-client/tsconfig.json", + "typecheck": "tsc --noEmit" }, "dependencies": { "@babel/core": "^7.22.9", diff --git a/packages/start/router.d.ts b/packages/start/router.d.ts new file mode 100644 index 000000000..747e6f82f --- /dev/null +++ b/packages/start/router.d.ts @@ -0,0 +1,39 @@ +import { A as BaseA, Location, NavigateOptions, Navigator, RouteDataFunc } from "@solidjs/router"; +import { JSX } from "solid-js"; +import { LocationEntry, useSearchParams as useIslandsSearchParams } from "./islands/router"; +export type RouteParams = Record; +export type RouteDataArgs = { + data: StartRoutes[T]["data"]; + params: RouteParams; + location: Location; + navigate: Navigator; +}; +declare const A: typeof BaseA; +declare const Routes: (props: import("@solidjs/router").RoutesProps) => JSX.Element; +declare const Outlet: () => JSX.Element; +declare const useNavigate: () => Navigator; +declare const useSearchParams: typeof useIslandsSearchParams | (() => [T, (params: import("@solidjs/router").SetParams, options?: Partial> | undefined) => void]); +declare global { + interface Window { + router: { + navigate: (to: string, options?: Partial) => Promise; + push: (to: string | URL, options: Partial) => void; + update: (body: string) => Promise; + router: EventTarget; + location: () => LocationEntry; + }; + } + interface StartRoutes { + $: { + params: any; + data: any; + }; + } + interface Route { + "/notes/[note]": "/notes/[note]"; + } +} +export declare function useRouteData(): ReturnType; +export declare function useRouteData any>(): T extends RouteDataFunc ? R : ReturnType; +export { useLocation } from "./islands/useLocation"; +export { A, Outlet, Routes, useNavigate, useSearchParams }; diff --git a/packages/start/tsconfig.json b/packages/start/tsconfig.json index 7e907a6a5..3d49ed586 100644 --- a/packages/start/tsconfig.json +++ b/packages/start/tsconfig.json @@ -5,13 +5,15 @@ "target": "ESNext", "allowJs": true, "noEmit": true, - "checkJs": true, + "declaration": true, + "checkJs": false, "module": "ESNext", "moduleResolution": "node", "jsxImportSource": "solid-js", "jsx": "preserve", "types": ["./env"], "strict": true, + "skipLibCheck": true, "lib": ["DOM", "DOM.Iterable", "ESNext"], "paths": { "vite": ["./node_modules/vite"] @@ -19,5 +21,5 @@ "baseUrl": "./" }, "include": ["./**/*.ts", "./**/*.tsx", "./**/*.js", "./**/*.jsx"], - "exclude": ["node_modules", "**/node_modules/*"] + "exclude": ["node_modules", "**/node_modules/*", "entry-client"] } diff --git a/packages/start/virtual/entry-client.tsx b/packages/start/virtual/entry-client.tsx index ba4824e2f..48d60ca2e 100644 --- a/packages/start/virtual/entry-client.tsx +++ b/packages/start/virtual/entry-client.tsx @@ -1,3 +1,3 @@ -import { mount, StartClient } from "../entry-client"; +import { mount, StartClient } from "../entry-client/src"; mount(() => , document); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bc54244aa..86c5d3167 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1223,6 +1223,8 @@ importers: specifier: ^4.4.6 version: 4.4.6(@types/node@18.16.19)(terser@5.19.0) + packages/start/entry-client: {} + test: dependencies: '@playwright/test':