From 8e83a032d9142b6c6d1528044b64b6e8eab63058 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Sun, 8 Aug 2021 11:11:34 +0200 Subject: [PATCH] feat: --config is not needed anymore (#48) This commit removes the need for users to specify a --config file. TS libs are now configured via `/// ` directives, and the JSX transform is specified via the `/** @jsx h */` pragma. The future is configless! --- .github/workflows/ci.yml | 2 +- README.md | 2 +- docs/getting-started.md | 2 +- example/README.md | 2 +- example/components/Button.tsx | 2 ++ example/components/Icons.tsx | 2 ++ example/deps.ts | 5 +++++ example/pages/[name].tsx | 2 ++ example/pages/index.tsx | 2 ++ example/pages/x/[module].tsx | 2 ++ example/tsconfig.json | 7 ------- makefile | 4 ++-- src/cli/init.ts | 30 +++++++++++------------------- src/server/bundle.ts | 4 +--- src/server/render.tsx | 2 ++ tests/fixture/README.md | 2 +- tests/fixture/pages/[name].tsx | 2 ++ tests/fixture/pages/index.tsx | 2 ++ tests/fixture/pages/props/[id].tsx | 2 ++ tests/fixture/pages/static.tsx | 2 ++ tests/fixture/tsconfig.json | 6 ------ 21 files changed, 44 insertions(+), 42 deletions(-) delete mode 100644 example/tsconfig.json delete mode 100644 tests/fixture/tsconfig.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43183ad9..5c543e5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,4 +36,4 @@ jobs: run: deno cache --no-check src/*/deps.ts - name: Run tests - run: deno test -A --unstable --config ./tsconfig.json --no-check + run: deno test -A --unstable --no-check diff --git a/README.md b/README.md index cb981bd5..ae7f313c 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ fresh init myproject To now start the project, call `deno run`: ``` -deno run -A --unstable --config tsconfig.json --watch main.ts +deno run -A --unstable --watch main.ts ``` To deploy the script to [Deno Deploy](https://deno.com/deploy), push your diff --git a/docs/getting-started.md b/docs/getting-started.md index 3477d986..87ef3a83 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -45,7 +45,7 @@ To learn more about how projects are structured, take a look at the You can now run your new project locally using the `deno` CLI: ``` -deno run -A --unstable --config tsconfig.json --watch main.ts +deno run -A --unstable --watch main.ts ``` The `--watch` option will cause your script to be reloaded on any changes to the diff --git a/example/README.md b/example/README.md index e8d3e69a..850ee95d 100644 --- a/example/README.md +++ b/example/README.md @@ -5,7 +5,7 @@ Start the project: ``` -deno run -A --unstable --config tsconfig.json --watch main.ts +deno run -A --unstable --watch main.ts ``` After adding, removing, or moving a page in the `pages` directory, run: diff --git a/example/components/Button.tsx b/example/components/Button.tsx index 0fdabf13..6c8af28e 100644 --- a/example/components/Button.tsx +++ b/example/components/Button.tsx @@ -1,3 +1,5 @@ +/** @jsx h */ + import { h, tw } from "../deps.ts"; export function RoundedButton(props: h.JSX.HTMLAttributes) { diff --git a/example/components/Icons.tsx b/example/components/Icons.tsx index 7cf95500..62830a17 100644 --- a/example/components/Icons.tsx +++ b/example/components/Icons.tsx @@ -1,3 +1,5 @@ +/** @jsx h */ + import { h, tw } from "../deps.ts"; export function IconMinus() { diff --git a/example/deps.ts b/example/deps.ts index 327f69c8..d561d51f 100644 --- a/example/deps.ts +++ b/example/deps.ts @@ -1,3 +1,8 @@ +/// +/// +/// +/// + export * from "../runtime.ts"; import { IS_BROWSER } from "../runtime.ts"; import { setup, tw } from "https://esm.sh/twind"; diff --git a/example/pages/[name].tsx b/example/pages/[name].tsx index db752c84..505b0895 100644 --- a/example/pages/[name].tsx +++ b/example/pages/[name].tsx @@ -1,3 +1,5 @@ +/** @jsx h */ + import { h } from "../deps.ts"; interface Props { diff --git a/example/pages/index.tsx b/example/pages/index.tsx index 65089ec6..6300bffc 100644 --- a/example/pages/index.tsx +++ b/example/pages/index.tsx @@ -1,3 +1,5 @@ +/** @jsx h */ + import { RoundedButton } from "../components/Button.tsx"; import { IconMinus, IconPlus } from "../components/Icons.tsx"; import { h, IS_BROWSER, tw, useState } from "../deps.ts"; diff --git a/example/pages/x/[module].tsx b/example/pages/x/[module].tsx index 05a2faac..69940296 100644 --- a/example/pages/x/[module].tsx +++ b/example/pages/x/[module].tsx @@ -1,3 +1,5 @@ +/** @jsx h */ + import { h, PageConfig, PageProps, useData } from "../../deps.ts"; export default function ModuleInfoPage({ params }: PageProps) { diff --git a/example/tsconfig.json b/example/tsconfig.json deleted file mode 100644 index c68288d3..00000000 --- a/example/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "compilerOptions": { - "lib": ["dom", "deno.ns", "deno.unstable"], - "jsxFactory": "h", - "jsxFragmentFactory": "Fragment" - } -} diff --git a/makefile b/makefile index 2bfa0e34..de188d5f 100644 --- a/makefile +++ b/makefile @@ -5,7 +5,7 @@ lint: deno lint test: - deno test --no-check -A --config tsconfig.json + deno test --no-check -A watch_example: - deno run -A --unstable --config example/tsconfig.json --watch example/main.ts \ No newline at end of file + deno run -A --unstable --watch example/main.ts \ No newline at end of file diff --git a/src/cli/init.ts b/src/cli/init.ts index ee7ddfff..f336a99d 100644 --- a/src/cli/init.ts +++ b/src/cli/init.ts @@ -63,7 +63,8 @@ async function init(directory: string) { import.meta.url, )}";\n`; await Deno.writeTextFile(join(directory, "deps.ts"), DEPS_TS); - const PAGES_INDEX_TSX = `import { h, IS_BROWSER, useState } from "../deps.ts"; + const PAGES_INDEX_TSX = `/** @jsx h */ +import { h, IS_BROWSER, useState } from "../deps.ts"; export default function Home() { return ( @@ -97,7 +98,8 @@ function Counter() { join(directory, "pages", "index.tsx"), PAGES_INDEX_TSX, ); - const PAGES_GREET_TSX = `import { h } from "../deps.ts"; + const PAGES_GREET_TSX = `/** @jsx h */ +import { h } from "../deps.ts"; interface Props { params: Record; @@ -136,23 +138,13 @@ export default (_req: Request): Response => { join(directory, "pages", "api", "joke.ts"), PAGES_API_JOKE_TS, ); - const TSCONFIG_JSON = JSON.stringify( - { - "compilerOptions": { - "lib": ["dom", "deno.ns", "deno.unstable"], - "jsxFactory": "h", - "jsxFragmentFactory": "Fragment", - }, - }, - undefined, - 2, - ) + "\n"; - await Deno.writeTextFile( - join(directory, "tsconfig.json"), - TSCONFIG_JSON, - ); const serverUrl = new URL("../../server.ts", import.meta.url); - const MAIN_TS = `import { start } from "${serverUrl}"; + const MAIN_TS = `/// +/// +/// +/// + +import { start } from "${serverUrl}"; import routes from "./routes.gen.ts"; start(routes); @@ -168,7 +160,7 @@ start(routes); Start the project: \`\`\` -deno run -A --unstable --config tsconfig.json --watch main.ts +deno run -A --unstable --watch main.ts \`\`\` After adding, removing, or moving a page in the \`pages\` directory, run: diff --git a/src/server/bundle.ts b/src/server/bundle.ts index eb8f155a..ee767fc0 100644 --- a/src/server/bundle.ts +++ b/src/server/bundle.ts @@ -36,14 +36,12 @@ export class Bundler { bundle: true, entryPoints, format: "esm", - jsxFactory: "h", - jsxFragment: "Fragment", metafile: true, minify: true, outdir: `/`, outfile: "", platform: "neutral", - plugins: [freshPlugin(this.#pages), denoPlugin({ loader: "portable" })], + plugins: [freshPlugin(this.#pages), denoPlugin()], splitting: true, target: ["chrome89", "firefox88", "safari13"], treeShaking: true, diff --git a/src/server/render.tsx b/src/server/render.tsx index 2c0945b8..4d4a3caf 100644 --- a/src/server/render.tsx +++ b/src/server/render.tsx @@ -1,3 +1,5 @@ +/** @jsx h */ + import { renderToString } from "./deps.ts"; import { ComponentChild, h } from "../runtime/deps.ts"; import { DATA_CONTEXT } from "../runtime/hooks.ts"; diff --git a/tests/fixture/README.md b/tests/fixture/README.md index e8d3e69a..850ee95d 100644 --- a/tests/fixture/README.md +++ b/tests/fixture/README.md @@ -5,7 +5,7 @@ Start the project: ``` -deno run -A --unstable --config tsconfig.json --watch main.ts +deno run -A --unstable --watch main.ts ``` After adding, removing, or moving a page in the `pages` directory, run: diff --git a/tests/fixture/pages/[name].tsx b/tests/fixture/pages/[name].tsx index db752c84..505b0895 100644 --- a/tests/fixture/pages/[name].tsx +++ b/tests/fixture/pages/[name].tsx @@ -1,3 +1,5 @@ +/** @jsx h */ + import { h } from "../deps.ts"; interface Props { diff --git a/tests/fixture/pages/index.tsx b/tests/fixture/pages/index.tsx index 6e449cf3..5b7c5277 100644 --- a/tests/fixture/pages/index.tsx +++ b/tests/fixture/pages/index.tsx @@ -1,3 +1,5 @@ +/** @jsx h */ + import { h, IS_BROWSER, useData } from "../deps.ts"; export default function Home() { diff --git a/tests/fixture/pages/props/[id].tsx b/tests/fixture/pages/props/[id].tsx index 7a5a0369..b0a439bc 100644 --- a/tests/fixture/pages/props/[id].tsx +++ b/tests/fixture/pages/props/[id].tsx @@ -1,3 +1,5 @@ +/** @jsx h */ + import { h, PageProps } from "../../deps.ts"; export default function Home(props: PageProps) { diff --git a/tests/fixture/pages/static.tsx b/tests/fixture/pages/static.tsx index 1d7ab74f..02bc8be4 100644 --- a/tests/fixture/pages/static.tsx +++ b/tests/fixture/pages/static.tsx @@ -1,3 +1,5 @@ +/** @jsx h */ + import { h, PageConfig } from "../deps.ts"; export default function StaticPage() { diff --git a/tests/fixture/tsconfig.json b/tests/fixture/tsconfig.json deleted file mode 100644 index 798d070e..00000000 --- a/tests/fixture/tsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "compilerOptions": { - "jsxFactory": "h", - "jsxFragmentFactory": "Fragment" - } -}