Commit 118242e
authored
major: build islands + scan routeDir without importing user code (#3122)
This fixes a bunch of long standing issues in our tracker where a build
wouldn't finish because of importing user code. It's common for backend
apps to spawn some open ended tasks like subscribing to Deno KV or other
things. This addresses another problem of having to set up ENV vars just
for the build, even though they are technically not required to build
islands.
This also gives a roughly ~30% performance boost on cold starts (at
least on `deno.com`). Unfortunately, this does require some breaking
changes. But I believe the performance improvements + removing the
footgun of loading user code during build is well worth it. This work is
also a precursor in case we want to exploring moving to vite at some
point in the future.
## Breaking changes
1. Build options have moved to the builder.
```diff
// main.ts
- const app = new App({ build: { outDir: "dist/" } })
+ const app = new App()
// dev.ts
- const builder = new Builder();
+ const builder = new Builder({ outDir: "dist/" });
```
2. Another breaking change is how file based routes are loaded. Since
they're prepared and loaded by the builder the API changed.
```diff
// main.ts
const app = new App()
.use(staticFiles())
- await fsRoutes(app, {
- loadIsland: (path) => import(`./islands/${path}`),
- loadRoute: (path) => import(`./routes/${path}`),
- });
+ app.fsRoutes()
```
You can optionally change the `islandDir` or `routeDir` by passing that
to the `Builder`:
```ts
// dev.ts
const builder = new Builder({
islandDir: "/path/to/islands",
routeDir: "/path/to/routes"
});
```
3. Import `app` lazily in `dev.ts`. Passing `app` to `builder.build()`
is not necessary anymore.
```diff
- import { app } from "./main.ts";
const builder = new Builder({ target: "safari12" });
if (Deno.args.includes("build")) {
- await builder.build(app);
+ await builder.build();
} else {
- await builder.listen(app);
+ await builder.listen(() => import("./main.ts"));
}
```
4. The production run command has changed. It's now using `deno serve`
```diff
// deno.json
{
"tasks": {
"dev": "deno run -A --watch=static/,routes/ dev.ts",
"dev": "deno run -A dev.ts build",
- "start": "deno run -A main.ts",
+ "start": "deno serve -A _fresh/server.js",
}
}
```
Remove this bit in `main.ts`:
```diff
// main.ts
- if (import.meta.main) {
- await app.listen()
- }
```
Fixes #2240
Fixes #2640
Fixes #2592
Fixes #18431 parent 69af00e commit 118242e
File tree
54 files changed
+1910
-1769
lines changed- .github/workflows
- docs/canary
- deployment
- examples
- examples
- init/src
- plugin-tailwindcss/src
- src
- dev
- middlewares
- plugins/fs_routes
- runtime/server
- tests
- fixture_island_groups/routes
- both
- (_islands)
- foo/(_islands)
- fixture_precompile
- invalid
- valid
- update/src
- www
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
54 files changed
+1910
-1769
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | | - | |
| 34 | + | |
36 | 35 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
62 | | - | |
| 61 | + | |
63 | 62 | | |
64 | 63 | | |
65 | 64 | | |
66 | 65 | | |
67 | | - | |
| 66 | + | |
68 | 67 | | |
69 | 68 | | |
70 | | - | |
| 69 | + | |
71 | 70 | | |
72 | 71 | | |
73 | 72 | | |
| |||
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
97 | 87 | | |
98 | 88 | | |
99 | 89 | | |
| |||
226 | 216 | | |
227 | 217 | | |
228 | 218 | | |
229 | | - | |
230 | | - | |
231 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
232 | 222 | | |
233 | 223 | | |
234 | 224 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | 18 | | |
29 | 19 | | |
30 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
| 165 | + | |
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| |||
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
352 | | - | |
| 352 | + | |
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
| |||
371 | 371 | | |
372 | 372 | | |
373 | 373 | | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
| 374 | + | |
| 375 | + | |
382 | 376 | | |
383 | 377 | | |
384 | 378 | | |
| |||
489 | 483 | | |
490 | 484 | | |
491 | 485 | | |
492 | | - | |
493 | 486 | | |
494 | 487 | | |
495 | | - | |
| 488 | + | |
496 | 489 | | |
497 | | - | |
| 490 | + | |
498 | 491 | | |
499 | | - | |
| 492 | + | |
500 | 493 | | |
501 | 494 | | |
502 | 495 | | |
| |||
506 | 499 | | |
507 | 500 | | |
508 | 501 | | |
509 | | - | |
| 502 | + | |
510 | 503 | | |
511 | 504 | | |
512 | 505 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
149 | 151 | | |
150 | | - | |
151 | | - | |
152 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
153 | 155 | | |
154 | | - | |
| 156 | + | |
155 | 157 | | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
164 | 167 | | |
165 | 168 | | |
166 | 169 | | |
| |||
240 | 243 | | |
241 | 244 | | |
242 | 245 | | |
243 | | - | |
| 246 | + | |
244 | 247 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
10 | | - | |
| 9 | + | |
11 | 10 | | |
12 | | - | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
16 | 14 | | |
17 | | - | |
| 15 | + | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
| |||
0 commit comments