diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 42069129..f411625c 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -74,13 +74,17 @@ jobs:
run: deno check --remote cli.ts
- name: Type check website
- run: deno check --remote www/main.ts
+ run: deno check --remote main.ts
+ working-directory: www/
- name: Type check examples/counter
- run: deno check --remote examples/counter/main.ts
+ run: deno check --remote main.ts
+ working-directory: examples/counter
- name: Type check tests/fixture
- run: deno check tests/fixture/main.ts
+ run: deno check main.ts
+ working-directory: tests/fixture/
- name: Type check tests/fixture_error
- run: deno check tests/fixture_error/main.ts
+ run: deno check main.ts
+ working-directory: tests/fixture_error/
diff --git a/.vscode/import_map.json b/.vscode/import_map.json
new file mode 100644
index 00000000..a4b4ed22
--- /dev/null
+++ b/.vscode/import_map.json
@@ -0,0 +1,8 @@
+{
+ ".": "THIS FILE EXISTS ONLY FOR VSCODE! IT IS NOT USED AT RUNTIME.",
+ "imports": {
+ "$fresh/": "../",
+ "$twind": "https://esm.sh/twind@0.16.16",
+ "$twind/": "https://esm.sh/twind@0.16.16/"
+ }
+}
diff --git a/.vscode/settings.json b/.vscode/settings.json
index e1533c2b..61e6398e 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,4 +1,5 @@
{
"deno.enable": true,
- "deno.lint": true
+ "deno.lint": true,
+ "deno.importMap": "./.vscode/import_map.json"
}
diff --git a/deno.jsonc b/deno.jsonc
index 3f12b288..046c60a4 100644
--- a/deno.jsonc
+++ b/deno.jsonc
@@ -1,7 +1,8 @@
{
"tasks": {
- "test": "deno test -A --no-check=remote && deno check www/main.ts && deno check cli.ts",
+ "test": "deno test -A --no-check=remote && deno check --config=www/deno.json www/main.ts && deno check cli.ts",
"fixture": "deno run -A --watch ./tests/fixture/main.ts & deno run -A ./cli.ts manifest --watch ./tests/fixture",
"www": "deno run -A --watch=www/static,docs/ ./www/main.ts & deno run -A ./cli.ts manifest --watch ./www"
- }
+ },
+ "importMap": "./tests/fixture/import_map.json"
}
diff --git a/docs/concepts/middleware.md b/docs/concepts/middleware.md
index 196d64e3..3aa74ce5 100644
--- a/docs/concepts/middleware.md
+++ b/docs/concepts/middleware.md
@@ -15,7 +15,7 @@ used to pass arbituary data to downstream (or upstream) handlers.
```ts
// routes/_middleware.ts
-import { MiddlewareHandlerContext } from "../deps.server.ts";
+import { MiddlewareHandlerContext } from "$fresh/server.ts";
interface State {
data: string;
diff --git a/docs/concepts/routes.md b/docs/concepts/routes.md
index fb54c0bf..addec3c4 100644
--- a/docs/concepts/routes.md
+++ b/docs/concepts/routes.md
@@ -22,7 +22,7 @@ Let's look at a basic route that returns a plain text string:
```tsx
// routes/plain.tsx
-import { HandlerContext, Handlers } from "../deps.server.ts";
+import { HandlerContext, Handlers } from "$fresh/server.ts";
export const handler: Handlers = {
GET(ctx: HandlerContext) {
@@ -43,7 +43,7 @@ Now, let's render some HTML using the route component. Another example:
// routes/html.tsx
/** @jsx h */
-import { h, PageProps } from "../deps.client.ts";
+import { h, PageProps } from "$fresh/runtime.ts";
export default function Page(props: PageProps) {
return
You are on the page '{props.url.href}'.
;
@@ -65,8 +65,8 @@ response after rendering the page component.
// routes/html.tsx
/** @jsx h */
-import { h, PageProps } from "../deps.client.ts";
-import { HandlerContext, Handlers } from "../deps.server.ts";
+import { h, PageProps } from "$fresh/runtime.ts";
+import { HandlerContext, Handlers } from "$fresh/server.ts";
export const handler: Handlers = {
GET(ctx: HandlerContext) {
diff --git a/docs/getting-started/adding-interactivity.md b/docs/getting-started/adding-interactivity.md
index ac07edbc..3c6b5bba 100644
--- a/docs/getting-started/adding-interactivity.md
+++ b/docs/getting-started/adding-interactivity.md
@@ -31,7 +31,7 @@ Here is an example of an island component that counts down to a specific time.
// islands/Countdown.tsx
/** @jsx h */
-import { h, useEffect, useMemo, useState } from "../deps.client.ts";
+import { h, useEffect, useMemo, useState } from "$fresh/runtime.ts";
const timeFmt = new Intl.RelativeTimeFormat("en-US");
@@ -73,7 +73,7 @@ client with the correct props:
// routes/countdown.tsx
/** @jsx h */
-import { h } from "../deps.client.ts";
+import { h } from "$fresh/runtime.ts";
import { Countdown } from "../islands/Countdown.tsx";
export default function Page() {
diff --git a/docs/getting-started/create-a-project.md b/docs/getting-started/create-a-project.md
index e0a401e3..b438e046 100644
--- a/docs/getting-started/create-a-project.md
+++ b/docs/getting-started/create-a-project.md
@@ -14,8 +14,8 @@ $ fresh init my-project
Manifest generated and written to ./my-project/fresh.gen.ts
```
-This will create a directory containing a bunch of files. Out of all of the
-files, only two are strictly necessary for a fresh project:
+This will create a directory containing some files and directories. There are 3
+files that are strictly necessary to run a fresh project:
- **`main.ts`**: This is the entrypoint for your project. It is the file that
will you run to start your fresh application. This file doesn't actually need
@@ -25,19 +25,17 @@ files, only two are strictly necessary for a fresh project:
your routes and islands. This file is automatically generated based on your
`routes/` and `islands/` folder by the `fresh` CLI when running the
`fresh manifest` command.
+- **`import_map.json`**: This is an [import map][import-map] that is used to
+ manage dependencies for the project. This allows for easy importing and
+ updating of dependencies.
-In addition to these two files, two other files are created that manage
-dependencies:
+A **`deno.json`** file is also created in the project directory. This file does
+two things:
-- **`deps.client.ts`**: This file contains dependencies that you need on the
- client, and possibly also on the server. It should be assumed that all of the
- dependencies referenced by this file will be shipped to the client. By
- default, it just re-exports the `fresh` runtime.
-- **`deps.server.ts`**: This file contains dependencies that are only used on
- the server. These are often things like database drivers, API clients, or
- other code that should only be executed on the server. This file should never
- be referenced by modules that might be shipped to the client. By default this
- just re-exports the `fresh` server libraries.
+- It tells Deno about the location of the import map, so that it can be loaded
+ automatically.
+- It registers a "start" [task][task-runner] to run the project without having
+ to type a long `deno run` command.
Two important folders are also created that contain your routes and islands
respectively:
@@ -54,4 +52,6 @@ respectively:
Finally a **`static/`** folder is created that contains static files that are
automatically served "as is". [Learn more about static files][static-files].
+[import-map]: https://deno.land/manual/linking_to_external_code/import_maps
+[task-runner]: https://deno.land/manual/tools/task_runner
[static-files]: ../concepts/static-files
diff --git a/docs/getting-started/create-a-route.md b/docs/getting-started/create-a-route.md
index 809c09f6..d0db8e47 100644
--- a/docs/getting-started/create-a-route.md
+++ b/docs/getting-started/create-a-route.md
@@ -38,7 +38,7 @@ This is done with JSX.
// routes/about.tsx
/** @jsx h */
-import { h } from "../deps.client.ts";
+import { h } from "$fresh/runtime.ts";
export default function AboutPage() {
return (
diff --git a/docs/getting-started/custom-handlers.md b/docs/getting-started/custom-handlers.md
index fc946bb7..86ba81a4 100644
--- a/docs/getting-started/custom-handlers.md
+++ b/docs/getting-started/custom-handlers.md
@@ -31,7 +31,7 @@ then adds a custom header to the response before returning it:
// routes/about.tsx
/** @jsx h */
-import { h, Handlers } from "../deps.client.ts";
+import { h, Handlers } from "$fresh/runtime.ts";
export const handler: Handlers = {
GET(req, ctx) {
@@ -58,7 +58,7 @@ response:
```ts
// routes/api/random-uuid.ts
-import { Handlers } from "../deps.client.ts";
+import { Handlers } from "$fresh/runtime.ts";
export const handler: Handlers = {
GET(req) {
diff --git a/docs/getting-started/dynamic-routes.md b/docs/getting-started/dynamic-routes.md
index 97293021..d93391dc 100644
--- a/docs/getting-started/dynamic-routes.md
+++ b/docs/getting-started/dynamic-routes.md
@@ -28,7 +28,7 @@ as arguments in it's `props` object though.
// routes/greet/[name].tsx
/** @jsx h */
-import { h, PageProps } from "../../deps.client.ts";
+import { h, PageProps } from "$fresh/runtime.ts";
export default function AboutPage(props: PageProps) {
const { name } = props.params;
diff --git a/docs/getting-started/fetching-data.md b/docs/getting-started/fetching-data.md
index cda87c7e..71d0cc82 100644
--- a/docs/getting-started/fetching-data.md
+++ b/docs/getting-started/fetching-data.md
@@ -24,8 +24,8 @@ renders it in a page component.
// routes/github/[username].tsx
/** @jsx h */
-import { h, PageProps } from "../../deps.client.ts";
-import { Handlers } from "../../deps.server.ts";
+import { h, PageProps } from "$fresh/runtime.ts";
+import { Handlers } from "$fresh/server.ts";
interface User {
login: string;
diff --git a/docs/getting-started/form-submissions.md b/docs/getting-started/form-submissions.md
index 7b05b94b..9deec3da 100644
--- a/docs/getting-started/form-submissions.md
+++ b/docs/getting-started/form-submissions.md
@@ -33,8 +33,8 @@ server side:
// routes/search.tsx
/** @jsx h */
-import { h, PageProps } from "../../deps.client.ts";
-import { Handlers } from "../../deps.server.ts";
+import { h, PageProps } from "$fresh/runtime.ts";
+import { Handlers } from "$fresh/server.ts";
const NAMES = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Frank"];
diff --git a/examples/counter/deno.json b/examples/counter/deno.json
index abc9a70f..88b96c5b 100644
--- a/examples/counter/deno.json
+++ b/examples/counter/deno.json
@@ -1,5 +1,6 @@
{
"tasks": {
"start": "deno run -A --watch main.ts & deno run -A ../../cli.ts manifest --watch"
- }
+ },
+ "importMap": "./import_map.json"
}
diff --git a/examples/counter/deps.client.ts b/examples/counter/deps.client.ts
deleted file mode 100644
index 3ccecce5..00000000
--- a/examples/counter/deps.client.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "../../runtime.ts";
diff --git a/examples/counter/deps.server.ts b/examples/counter/deps.server.ts
deleted file mode 100644
index 0318a0be..00000000
--- a/examples/counter/deps.server.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "../../server.ts";
diff --git a/examples/counter/import_map.json b/examples/counter/import_map.json
new file mode 100644
index 00000000..7bdcd08d
--- /dev/null
+++ b/examples/counter/import_map.json
@@ -0,0 +1,5 @@
+{
+ "imports": {
+ "$fresh/": "../../"
+ }
+}
diff --git a/examples/counter/islands/Counter.tsx b/examples/counter/islands/Counter.tsx
index 41f19e26..ce4e644e 100644
--- a/examples/counter/islands/Counter.tsx
+++ b/examples/counter/islands/Counter.tsx
@@ -1,5 +1,5 @@
/** @jsx h */
-import { h, IS_BROWSER, useState } from "../deps.client.ts";
+import { h, IS_BROWSER, useState } from "$fresh/runtime.ts";
interface CounterProps {
start: number;
diff --git a/examples/counter/main.ts b/examples/counter/main.ts
index 7652910e..0f15e8de 100644
--- a/examples/counter/main.ts
+++ b/examples/counter/main.ts
@@ -4,7 +4,7 @@
///
///
-import { start } from "./deps.server.ts";
+import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";
await start(manifest);
diff --git a/examples/counter/routes/index.tsx b/examples/counter/routes/index.tsx
index 43a8cd2b..37050b81 100644
--- a/examples/counter/routes/index.tsx
+++ b/examples/counter/routes/index.tsx
@@ -1,5 +1,5 @@
/** @jsx h */
-import { h } from "../deps.client.ts";
+import { h } from "$fresh/runtime.ts";
import Counter from "../islands/Counter.tsx";
export default function Home() {
diff --git a/src/cli/init.ts b/src/cli/init.ts
index e00c8dc5..633a4e0f 100644
--- a/src/cli/init.ts
+++ b/src/cli/init.ts
@@ -66,19 +66,19 @@ async function init(directory: string) {
await Deno.mkdir(join(directory, "islands"), { recursive: true });
await Deno.mkdir(join(directory, "static"), { recursive: true });
- const DEPS_CLIENT_TS = `export * from "${new URL(
- "../../runtime.ts",
- import.meta.url,
- )}";\n`;
- await Deno.writeTextFile(join(directory, "deps.client.ts"), DEPS_CLIENT_TS);
- const DEPS_SERVER_TS = `export * from "${new URL(
- "../../server.ts",
- import.meta.url,
- )}";\n`;
- await Deno.writeTextFile(join(directory, "deps.server.ts"), DEPS_SERVER_TS);
+ const IMPORT_MAP_JSON = JSON.stringify(
+ {
+ "imports": {
+ "$fresh/": new URL("../../", import.meta.url).href,
+ },
+ },
+ null,
+ 2,
+ );
+ await Deno.writeTextFile(join(directory, "import_map.json"), IMPORT_MAP_JSON);
const ROUTES_INDEX_TSX = `/** @jsx h */
-import { h } from "../deps.client.ts";
+import { h } from "$fresh/runtime.ts";
import Counter from "../islands/Counter.tsx";
export default function Home() {
@@ -100,7 +100,7 @@ export default function Home() {
);
const ISLANDS_COUNTER_TSX = `/** @jsx h */
-import { h, IS_BROWSER, useState } from "../deps.client.ts";
+import { h, IS_BROWSER, useState } from "$fresh/runtime.ts";
interface CounterProps {
start: number;
@@ -127,7 +127,7 @@ export default function Counter(props: CounterProps) {
);
const ROUTES_GREET_TSX = `/** @jsx h */
-import { h, PageProps } from "../deps.client.ts";
+import { h, PageProps } from "$fresh/runtime.ts";
export default function Greet(props: PageProps) {
return