Skip to content

Commit

Permalink
feat: export compat types from /compat export (#2478)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato authored Jun 3, 2024
1 parent 2fb8606 commit aa19b39
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 139 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ vendor/
node_modules/
.docs/
.DS_Store
tmp-*
5 changes: 4 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"exports": {
".": "./src/mod.ts",
"./runtime": "./src/runtime/shared.ts",
"./dev": "./src/dev/mod.ts"
"./dev": "./src/dev/mod.ts",
"./compat": "./src/compat/mod.ts"
},
"lock": false,
"tasks": {
Expand Down Expand Up @@ -39,6 +40,7 @@
"@fresh/core": "./src/mod.ts",
"@fresh/core/dev": "./src/dev/mod.ts",
"@fresh/core/runtime": "./src/runtime/shared.ts",
"@fresh/core/compat": "./src/compat/mod.ts",
"@fresh/plugin-tailwind": "./plugin-tailwindcss/src/mod.ts",
"@luca/esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.10.3",
"@preact/signals": "npm:@preact/signals@^1.2.3",
Expand Down Expand Up @@ -71,6 +73,7 @@
"twind/": "https://esm.sh/[email protected]/"
},
"compilerOptions": {
"lib": ["dom", "dom.asynciterable", "deno.ns"],
"jsx": "precompile",
"jsxImportSource": "preact",
"jsxPrecompileSkipElements": ["a", "img", "source", "body", "html", "head"]
Expand Down
1 change: 1 addition & 0 deletions init/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ if (Deno.args.includes("build")) {
"@preact/signals": "npm:@preact/signals@^1.2.3",
} as Record<string, string>,
compilerOptions: {
lib: ["dom", "dom.asynciterable", "deno.ns"],
jsx: "react-jsx",
jsxImportSource: "preact",
},
Expand Down
13 changes: 13 additions & 0 deletions src/compat/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Compat with older Fresh versions
export {
type AppProps,
defineApp,
defineLayout,
defineRoute,
type ErrorPageProps,
type Handler,
type Handlers,
type LayoutProps,
type RouteContext,
type UnknownPageProps,
} from "./server.ts";
36 changes: 25 additions & 11 deletions src/compat/server.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
import type { VNode } from "preact";
import type { FreshContext } from "../context.ts";
import type { HandlerByMethod } from "../handlers.ts";
import type { HandlerFn, RouteHandler } from "../handlers.ts";

/**
* @deprecated Use {@link FreshContext} instead
* @deprecated Use {@link PageProps} instead.
*/
export type AppProps<_Data = unknown, T = unknown> = FreshContext<T>;
/**
* @deprecated Use {@link FreshContext} instead
* @deprecated Use {@link PageProps} instead.
*/
export type LayoutProps<_Data = unknown, T = unknown> = FreshContext<T>;
/**
* @deprecated Use {@link FreshContext} instead
* @deprecated Use {@link PageProps} instead.
*/
export type UnknownPageProps<_Data = unknown, T = unknown> = FreshContext<T>;
/**
* @deprecated Use {@link FreshContext} instead
* @deprecated Use {@link PageProps} instead.
*/
export type ErrorPageProps<_Data = unknown, T = unknown> = FreshContext<T>;

/**
* @deprecated Use {@link FreshContext} instead
* @deprecated Use {@link FreshContext} instead.
*/
export type RouteContext<_T = never, S = Record<string, unknown>> =
FreshContext<S>;

/**
* @deprecated Use {@link RouteHandler} instead.
*/
// deno-lint-ignore no-explicit-any
export type Handlers<T = any, State = Record<string, unknown>> = RouteHandler<
T,
State
>;

/**
* @deprecated Use {@link HandlerFn} instead.
*/
// deno-lint-ignore no-explicit-any
export type Handlers<T = any, State = Record<string, unknown>> =
HandlerByMethod<T, State>;
export type Handler<T = any, State = Record<string, unknown>> = HandlerFn<
T,
State
>;

function defineFn<State>(
fn: (
Expand All @@ -40,14 +54,14 @@ function defineFn<State>(
}

/**
* @deprecated Use {@link definePage} instead
* @deprecated Use {@link [../mod.ts].Define.page|define.page} instead.
*/
export const defineApp = defineFn;
/**
* @deprecated Use {@link definePage} instead
* @deprecated Use {@link [../mod.ts].Define.page|define.page} instead.
*/
export const defineRoute = defineFn;
/**
* @deprecated Use {@link definePage} instead
* @deprecated Use {@link [../mod.ts].Define.page|define.page} instead.
*/
export const defineLayout = defineFn;
14 changes: 0 additions & 14 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,3 @@ export type { FreshContext, Island, PageProps } from "./context.ts";
export { createDefine, type Define } from "./define.ts";
export type { Method } from "./router.ts";
export { HttpError } from "./error.ts";

// Compat with older Fresh versions
export {
type AppProps,
defineApp,
defineLayout,
defineRoute,
type ErrorPageProps,
type Handlers,
type Handlers as Handler,
type LayoutProps,
type RouteContext,
type UnknownPageProps,
} from "./compat/server.ts";
Loading

0 comments on commit aa19b39

Please sign in to comment.