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 `/// <reference>` directives, and the JSX
transform is specified via the `/** @jsx h */` pragma.

The future is configless!
This commit is contained in:
Luca Casonato
2021-08-08 11:11:34 +02:00
committed by GitHub
parent 384daf0e06
commit 8e83a032d9
21 changed files with 44 additions and 42 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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:
+2
View File
@@ -1,3 +1,5 @@
/** @jsx h */
import { h, tw } from "../deps.ts";
export function RoundedButton(props: h.JSX.HTMLAttributes<HTMLButtonElement>) {
+2
View File
@@ -1,3 +1,5 @@
/** @jsx h */
import { h, tw } from "../deps.ts";
export function IconMinus() {
+5
View File
@@ -1,3 +1,8 @@
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" />
export * from "../runtime.ts";
import { IS_BROWSER } from "../runtime.ts";
import { setup, tw } from "https://esm.sh/twind";
+2
View File
@@ -1,3 +1,5 @@
/** @jsx h */
import { h } from "../deps.ts";
interface Props {
+2
View File
@@ -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";
+2
View File
@@ -1,3 +1,5 @@
/** @jsx h */
import { h, PageConfig, PageProps, useData } from "../../deps.ts";
export default function ModuleInfoPage({ params }: PageProps) {
-7
View File
@@ -1,7 +0,0 @@
{
"compilerOptions": {
"lib": ["dom", "deno.ns", "deno.unstable"],
"jsxFactory": "h",
"jsxFragmentFactory": "Fragment"
}
}
+2 -2
View File
@@ -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
deno run -A --unstable --watch example/main.ts
+11 -19
View File
@@ -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<string, string | string[]>;
@@ -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 = `/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" />
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:
+1 -3
View File
@@ -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,
+2
View File
@@ -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";
+1 -1
View File
@@ -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:
+2
View File
@@ -1,3 +1,5 @@
/** @jsx h */
import { h } from "../deps.ts";
interface Props {
+2
View File
@@ -1,3 +1,5 @@
/** @jsx h */
import { h, IS_BROWSER, useData } from "../deps.ts";
export default function Home() {
+2
View File
@@ -1,3 +1,5 @@
/** @jsx h */
import { h, PageProps } from "../../deps.ts";
export default function Home(props: PageProps) {
+2
View File
@@ -1,3 +1,5 @@
/** @jsx h */
import { h, PageConfig } from "../deps.ts";
export default function StaticPage() {
-6
View File
@@ -1,6 +0,0 @@
{
"compilerOptions": {
"jsxFactory": "h",
"jsxFragmentFactory": "Fragment"
}
}