chore: version preact explicitly in import map (#258)

This allows users to control the `preact` version independently of fresh
itself.
This commit is contained in:
Luca Casonato
2022-06-20 12:37:24 +02:00
committed by GitHub
parent 3e001fe242
commit cbbf616a74
55 changed files with 108 additions and 125 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ jobs:
run: deno lint
- name: Cache dependencies
run: deno cache --no-check src/dev/deps.ts src/runtime/deps.ts src/server/deps.ts
run: deno cache --no-check --import-map=./www/import_map.json src/dev/deps.ts src/server/deps.ts www/main.ts
- name: Cache Chrome (Linux)
if: startsWith(matrix.os, 'ubuntu')
+5 -1
View File
@@ -3,6 +3,10 @@
"imports": {
"$fresh/": "../",
"$twind": "https://esm.sh/twind@0.16.16",
"$twind/": "https://esm.sh/twind@0.16.16/"
"$twind/": "https://esm.sh/twind@0.16.16/",
"preact": "https://esm.sh/preact@10.6.6",
"preact/": "https://esm.sh/preact@10.6.6/",
"preact-render-to-string": "https://esm.sh/preact-render-to-string@5.1.20?deps=preact@10.6.6"
}
}
+4 -2
View File
@@ -43,7 +43,8 @@ Now, let's render some HTML using the route component. Another example:
// routes/html.tsx
/** @jsx h */
import { h, PageProps } from "$fresh/runtime.ts";
import { h } from "preact";
import { PageProps } from "$fresh/runtime.ts";
export default function Page(props: PageProps) {
return <div>You are on the page '{props.url.href}'.</div>;
@@ -65,7 +66,8 @@ response after rendering the page component.
// routes/html.tsx
/** @jsx h */
import { h, PageProps } from "$fresh/runtime.ts";
import { h } from "preact";
import { PageProps } from "$fresh/runtime.ts";
import { HandlerContext, Handlers } from "$fresh/server.ts";
export const handler: Handlers = {
+3 -2
View File
@@ -31,7 +31,8 @@ Here is an example of an island component that counts down to a specific time.
// islands/Countdown.tsx
/** @jsx h */
import { h, useEffect, useState } from "$fresh/runtime.ts";
import { h } from "preact";
import { useEffect, useState } from "preact/hooks";
const timeFmt = new Intl.RelativeTimeFormat("en-US");
@@ -73,7 +74,7 @@ client with the correct props:
// routes/countdown.tsx
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
import Countdown from "../islands/Countdown.tsx";
export default function Page() {
+1 -1
View File
@@ -38,7 +38,7 @@ This is done with JSX.
// routes/about.tsx
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
export default function AboutPage() {
return (
+1 -1
View File
@@ -31,7 +31,7 @@ then adds a custom header to the response before returning it:
// routes/about.tsx
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
import { Handlers } from "$fresh/server.ts";
export const handler: Handlers = {
+2 -1
View File
@@ -28,7 +28,8 @@ as arguments in it's `props` object though.
// routes/greet/[name].tsx
/** @jsx h */
import { h, PageProps } from "$fresh/runtime.ts";
import { h } from "preact";
import { PageProps } from "$fresh/runtime.ts";
export default function GreetPage(props: PageProps) {
const { name } = props.params;
+2 -1
View File
@@ -24,7 +24,8 @@ renders it in a page component.
// routes/github/[username].tsx
/** @jsx h */
import { h, PageProps } from "$fresh/runtime.ts";
import { h } from "preact";
import { PageProps } from "$fresh/runtime.ts";
import { Handlers } from "$fresh/server.ts";
interface User {
+2 -1
View File
@@ -33,7 +33,8 @@ server side:
// routes/search.tsx
/** @jsx h */
import { h, PageProps } from "$fresh/runtime.ts";
import { h } from "preact";
import { PageProps } from "$fresh/runtime.ts";
import { Handlers } from "$fresh/server.ts";
const NAMES = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Frank"];
+4 -1
View File
@@ -1,5 +1,8 @@
{
"imports": {
"$fresh/": "../../"
"$fresh/": "../../",
"preact": "https://esm.sh/preact@10.6.6",
"preact/": "https://esm.sh/preact@10.6.6/",
"preact-render-to-string": "https://esm.sh/preact-render-to-string@5.1.20?deps=preact@10.6.6"
}
}
+3 -1
View File
@@ -1,5 +1,7 @@
/** @jsx h */
import { h, IS_BROWSER, useState } from "$fresh/runtime.ts";
import { h } from "preact";
import { useState } from "preact/hooks";
import { IS_BROWSER } from "$fresh/runtime.ts";
interface CounterProps {
start: number;
+1 -1
View File
@@ -1,5 +1,5 @@
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
import Counter from "../islands/Counter.tsx";
export default function Home() {
+10 -3
View File
@@ -48,6 +48,10 @@ const IMPORT_MAP_JSON = JSON.stringify(
{
"imports": {
"$fresh/": new URL("./", import.meta.url).href,
"preact": "https://esm.sh/preact@10.6.6",
"preact/": "https://esm.sh/preact@10.6.6/",
"preact-render-to-string":
"https://esm.sh/preact-render-to-string@5.1.20?deps=preact@10.6.6",
},
},
null,
@@ -56,7 +60,7 @@ const IMPORT_MAP_JSON = JSON.stringify(
await Deno.writeTextFile(join(directory, "import_map.json"), IMPORT_MAP_JSON);
const ROUTES_INDEX_TSX = `/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
import Counter from "../islands/Counter.tsx";
export default function Home() {
@@ -78,7 +82,9 @@ await Deno.writeTextFile(
);
const ISLANDS_COUNTER_TSX = `/** @jsx h */
import { h, IS_BROWSER, useState } from "$fresh/runtime.ts";
import { h } from "preact";
import { useState } from "preact/hooks";
import { IS_BROWSER } from "$fresh/runtime.ts";
interface CounterProps {
start: number;
@@ -105,7 +111,8 @@ await Deno.writeTextFile(
);
const ROUTES_GREET_TSX = `/** @jsx h */
import { h, PageProps } from "$fresh/runtime.ts";
import { h } from "preact";
import { PageProps } from "$fresh/runtime.ts";
export default function Greet(props: PageProps) {
return <div>Hello {props.params.name}</div>;
-1
View File
@@ -1,4 +1,3 @@
export * from "./src/runtime/deps.ts";
export * from "./src/runtime/types.ts";
export * from "./src/runtime/utils.ts";
export * from "./src/runtime/head.ts";
+2 -1
View File
@@ -1,4 +1,5 @@
import { createContext, useContext } from "./deps.ts";
import { createContext } from "preact";
import { useContext } from "preact/hooks";
export const SELF = "'self'";
export const UNSAFE_INLINE = "'unsafe-inline'";
-24
View File
@@ -1,24 +0,0 @@
export * from "https://esm.sh/preact@10.6.6";
export { jsx, jsxDEV, jsxs } from "https://esm.sh/preact@10.6.6/jsx-runtime";
export {
useCallback,
useContext,
useDebugValue,
useEffect,
useErrorBoundary,
useImperativeHandle,
useLayoutEffect,
useMemo,
useReducer,
useRef,
useState,
} from "https://esm.sh/preact@10.6.6/hooks";
export type {
CreateHandle,
EffectCallback,
Inputs,
PropRef,
Reducer,
Ref,
StateUpdater,
} from "https://esm.sh/preact@10.6.6/hooks";
+2 -1
View File
@@ -1,4 +1,5 @@
import { ComponentChildren, createContext, useContext } from "./deps.ts";
import { ComponentChildren, createContext } from "preact";
import { useContext } from "preact/hooks";
export interface HeadProps {
children: ComponentChildren;
+1 -1
View File
@@ -1,4 +1,4 @@
import { ComponentType, h, options, render } from "./deps.ts";
import { ComponentType, h, options, render } from "preact";
import { assetHashingHook } from "./utils.ts";
function createRootFragment(
+1 -1
View File
@@ -1,4 +1,4 @@
import { ComponentType } from "./deps.ts";
import { ComponentType } from "preact";
// deno-lint-ignore no-explicit-any
export interface PageProps<T = any> {
+1 -1
View File
@@ -1,4 +1,4 @@
import { VNode } from "./deps.ts";
import { VNode } from "preact";
export const INTERNAL_PREFIX = "/_frsh";
export const ASSET_CACHE_BUST_KEY = "__frsh_c";
+1 -2
View File
@@ -8,10 +8,10 @@ import {
toFileUrl,
walk,
} from "./deps.ts";
import { h } from "preact";
import { Manifest } from "./mod.ts";
import { Bundler } from "./bundle.ts";
import { ALIVE_URL, BUILD_ID, JS_PREFIX, REFRESH_JS_URL } from "./constants.ts";
import DefaultErrorHandler from "./default_error_page.tsx";
import {
AppModule,
@@ -32,7 +32,6 @@ import {
} from "./types.ts";
import { render as internalRender } from "./render.tsx";
import { ContentSecurityPolicyDirectives, SELF } from "../runtime/csp.ts";
import { h } from "../runtime/deps.ts";
import { ASSET_CACHE_BUST_KEY, INTERNAL_PREFIX } from "../runtime/utils.ts";
interface StaticFile {
+1 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */
import { h } from "../runtime/deps.ts";
import { h } from "preact";
import { DEBUG } from "./constants.ts";
import type { ErrorPageProps } from "../runtime/types.ts";
-3
View File
@@ -1,6 +1,3 @@
// -- preact --
export { renderToString } from "https://esm.sh/preact-render-to-string@5.1.20?deps=preact@10.6.6";
// -- std --
export {
extname,
+2 -7
View File
@@ -1,11 +1,6 @@
/** @jsx h */
import { renderToString } from "./deps.ts";
import {
ComponentChildren,
ComponentType,
h,
options,
} from "../runtime/deps.ts";
import { renderToString } from "preact-render-to-string";
import { ComponentChildren, ComponentType, h, options } from "preact";
import {
AppModule,
ErrorPage,
+1 -1
View File
@@ -1,4 +1,4 @@
import { ComponentType } from "../runtime/deps.ts";
import { ComponentType } from "preact";
import { ConnInfo, router, ServeInit } from "./deps.ts";
import {
AppProps,
+4 -1
View File
@@ -1,5 +1,8 @@
{
"imports": {
"$fresh/": "../../"
"$fresh/": "../../",
"preact": "https://esm.sh/preact@10.6.6",
"preact/": "https://esm.sh/preact@10.6.6/",
"preact-render-to-string": "https://esm.sh/preact-render-to-string@5.1.20?deps=preact@10.6.6"
}
}
+3 -1
View File
@@ -1,5 +1,7 @@
/** @jsx h */
import { h, IS_BROWSER, useState } from "$fresh/runtime.ts";
import { h } from "preact";
import { useState } from "preact/hooks";
import { IS_BROWSER } from "$fresh/runtime.ts";
interface CounterProps {
start: number;
+1 -2
View File
@@ -1,6 +1,5 @@
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
export default function Test(props: { message: string }) {
return (
+1 -2
View File
@@ -1,6 +1,5 @@
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
interface Props {
params: Record<string, string | string[]>;
+2 -2
View File
@@ -1,6 +1,6 @@
/** @jsx h */
import { h, UnknownPageProps } from "$fresh/runtime.ts";
import { h } from "preact";
import { UnknownPageProps } from "$fresh/runtime.ts";
export default function NotFoundPage({ url }: UnknownPageProps) {
return <p>404 not found: {url.pathname}</p>;
+2 -2
View File
@@ -1,6 +1,6 @@
/** @jsx h */
import { ErrorPageProps, h } from "$fresh/runtime.ts";
import { h } from "preact";
import { ErrorPageProps } from "$fresh/runtime.ts";
export default function Error500Page({ error }: ErrorPageProps) {
return <p>500 internal error: {(error as Error).message}</p>;
+2 -2
View File
@@ -1,7 +1,7 @@
/** @jsx h */
/** @jsxFrag Fragment */
import { AppProps, Fragment, h, Head } from "$fresh/runtime.ts";
import { Fragment, h } from "preact";
import { AppProps, Head } from "$fresh/runtime.ts";
export default function App(props: AppProps) {
return (
+1 -2
View File
@@ -1,6 +1,5 @@
/** @jsx h */
import { asset, h } from "$fresh/runtime.ts";
import { h } from "preact";
import Test from "../../islands/Test.tsx";
export default function Home() {
+2 -2
View File
@@ -1,6 +1,6 @@
/** @jsx h */
import { h, PageProps, RouteConfig } from "$fresh/runtime.ts";
import { h } from "preact";
import { PageProps, RouteConfig } from "$fresh/runtime.ts";
export default function Page(props: PageProps) {
return <div>Book {props.params.id}</div>;
+2 -2
View File
@@ -1,6 +1,6 @@
/** @jsx h */
import { h, IS_BROWSER } from "$fresh/runtime.ts";
import { h } from "preact";
import { IS_BROWSER } from "$fresh/runtime.ts";
import Test from "../islands/Test.tsx";
export default function Home() {
+2 -3
View File
@@ -1,7 +1,6 @@
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { HandlerContext } from "../../../server.ts";
import { h } from "preact";
import { HandlerContext } from "$fresh/server.ts";
export default function Page() {
return <div>This is HTML</div>;
+3 -3
View File
@@ -1,7 +1,7 @@
/** @jsx h */
import { h, PageProps } from "$fresh/runtime.ts";
import { HandlerContext, Handlers } from "../../../server.ts";
import { h } from "preact";
import { PageProps } from "$fresh/runtime.ts";
import { Handlers } from "$fresh/server.ts";
interface Data extends Record<string, unknown> {
info: string;
+1 -2
View File
@@ -1,6 +1,5 @@
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
import Counter from "../../islands/Counter.tsx";
export default function Home() {
+2 -2
View File
@@ -1,6 +1,6 @@
/** @jsx h */
import { h, RouteConfig } from "$fresh/runtime.ts";
import { h } from "preact";
import { RouteConfig } from "$fresh/runtime.ts";
import { HandlerContext } from "../../../server.ts";
export const handler = {
+2 -2
View File
@@ -1,6 +1,6 @@
/** @jsx h */
import { h, PageProps } from "$fresh/runtime.ts";
import { h } from "preact";
import { PageProps } from "$fresh/runtime.ts";
export default function Home(props: PageProps) {
return <div>{JSON.stringify(props)}</div>;
+2 -2
View File
@@ -1,6 +1,6 @@
/** @jsx h */
import { asset, h } from "$fresh/runtime.ts";
import { h } from "preact";
import { asset } from "$fresh/runtime.ts";
export default function StaticPage() {
return (
+2 -2
View File
@@ -1,6 +1,6 @@
/** @jsx h */
import { h, PageProps, RouteConfig } from "$fresh/runtime.ts";
import { h } from "preact";
import { PageProps, RouteConfig } from "$fresh/runtime.ts";
export default function WildcardPage({ params }: PageProps) {
if (typeof params.path === "string") {
+4 -1
View File
@@ -1,5 +1,8 @@
{
"imports": {
"$fresh/": "../../"
"$fresh/": "../../",
"preact": "https://esm.sh/preact@10.6.6",
"preact/": "https://esm.sh/preact@10.6.6/",
"preact-render-to-string": "https://esm.sh/preact-render-to-string@5.1.20?deps=preact@10.6.6"
}
}
-3
View File
@@ -1,6 +1,3 @@
/** @jsx h */
import { h } from "$fresh/runtime.ts";
export default function Home(): null {
throw new Error("boom!");
}
+1 -2
View File
@@ -1,6 +1,5 @@
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
import { tw } from "../utils/twind.ts";
export function RoundedButton(props: h.JSX.HTMLAttributes<HTMLButtonElement>) {
+1 -2
View File
@@ -1,6 +1,5 @@
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
import { apply, tw } from "../utils/twind.ts";
import {
+1 -2
View File
@@ -1,6 +1,5 @@
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
import { tw } from "../utils/twind.ts";
const LINKS = [
+1 -2
View File
@@ -1,6 +1,5 @@
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
import { tw } from "../utils/twind.ts";
export function IconMinus() {
+1 -2
View File
@@ -1,6 +1,5 @@
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
import { tw } from "../utils/twind.ts";
export default function NavigationBar(props: { active: string }) {
+1 -2
View File
@@ -1,6 +1,5 @@
/** @jsx h */
import { h } from "$fresh/runtime.ts";
import { h } from "preact";
import { tw } from "../utils/twind.ts";
export default function WarningBanner() {
+4 -1
View File
@@ -2,6 +2,9 @@
"imports": {
"$fresh/": "../",
"$twind": "https://esm.sh/twind@0.16.16",
"$twind/": "https://esm.sh/twind@0.16.16/"
"$twind/": "https://esm.sh/twind@0.16.16/",
"preact": "https://esm.sh/preact@10.6.6",
"preact/": "https://esm.sh/preact@10.6.6/",
"preact-render-to-string": "https://esm.sh/preact-render-to-string@5.1.20?deps=preact@10.6.6"
}
}
+3 -1
View File
@@ -1,5 +1,7 @@
/** @jsx h */
import { h, IS_BROWSER, useState } from "$fresh/runtime.ts";
import { h } from "preact";
import { useState } from "preact/hooks";
import { IS_BROWSER } from "$fresh/runtime.ts";
import { tw } from "../utils/twind.ts";
import { RoundedButton } from "../components/Button.tsx";
import { IconMinus, IconPlus } from "../components/Icons.tsx";
+2 -1
View File
@@ -1,6 +1,7 @@
/** @jsx h */
/** @jsxFrag Fragment */
import { Fragment, h, useEffect, useRef, useState } from "$fresh/runtime.ts";
import { Fragment, h } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
import { tw } from "../utils/twind.ts";
import { Spring, WaveTank } from "../components/WaveTank.ts";
+2 -2
View File
@@ -1,7 +1,7 @@
/** @jsx h */
/** @jsxFrag Fragment */
import { Fragment, h, Head, PageProps } from "$fresh/runtime.ts";
import { Fragment, h } from "preact";
import { Head, PageProps } from "$fresh/runtime.ts";
import { Handlers } from "$fresh/server.ts";
import { apply, tw } from "../../utils/twind.ts";
import { frontMatter, gfm } from "../../utils/markdown.ts";
+2 -9
View File
@@ -1,14 +1,7 @@
/** @jsx h */
/** @jsxFrag Fragment */
import {
asset,
ComponentChildren,
Fragment,
h,
Head,
PageProps,
} from "$fresh/runtime.ts";
import { ComponentChildren, Fragment, h } from "preact";
import { asset, Head, PageProps } from "$fresh/runtime.ts";
import { tw } from "../utils/twind.ts";
import Counter from "../islands/Counter.tsx";
import LemonDrop from "../islands/LemonDrop.tsx";