Skip to content

Commit 0e6aff5

Browse files
fix: broken init script (#1642)
1 parent c175e28 commit 0e6aff5

File tree

3 files changed

+53
-61
lines changed

3 files changed

+53
-61
lines changed

dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import { dev } from "./src/dev/mod.ts";
1+
import { dev } from "./src/dev/dev_command.ts";
22
export default dev;

src/dev/dev_command.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { updateCheck } from "./update_check.ts";
2+
import { DAY, dirname, fromFileUrl, join } from "./deps.ts";
3+
import { FreshOptions } from "../server/mod.ts";
4+
import { build } from "./build.ts";
5+
import { collect, ensureMinDenoVersion, generate, Manifest } from "./mod.ts";
6+
7+
export async function dev(
8+
base: string,
9+
entrypoint: string,
10+
options: FreshOptions = {},
11+
) {
12+
ensureMinDenoVersion();
13+
14+
// Run update check in background
15+
updateCheck(DAY).catch(() => {});
16+
17+
entrypoint = new URL(entrypoint, base).href;
18+
19+
const dir = dirname(fromFileUrl(base));
20+
21+
let currentManifest: Manifest;
22+
const prevManifest = Deno.env.get("FRSH_DEV_PREVIOUS_MANIFEST");
23+
if (prevManifest) {
24+
currentManifest = JSON.parse(prevManifest);
25+
} else {
26+
currentManifest = { islands: [], routes: [] };
27+
}
28+
const newManifest = await collect(dir);
29+
Deno.env.set("FRSH_DEV_PREVIOUS_MANIFEST", JSON.stringify(newManifest));
30+
31+
const manifestChanged =
32+
!arraysEqual(newManifest.routes, currentManifest.routes) ||
33+
!arraysEqual(newManifest.islands, currentManifest.islands);
34+
35+
if (manifestChanged) await generate(dir, newManifest);
36+
37+
if (Deno.args.includes("build")) {
38+
await build(join(dir, "fresh.gen.ts"), options);
39+
} else {
40+
await import(entrypoint);
41+
}
42+
}
43+
44+
function arraysEqual<T>(a: T[], b: T[]): boolean {
45+
if (a.length !== b.length) return false;
46+
for (let i = 0; i < a.length; ++i) {
47+
if (a[i] !== b[i]) return false;
48+
}
49+
return true;
50+
}

src/dev/mod.ts

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
import { updateCheck } from "./update_check.ts";
2-
import {
3-
DAY,
4-
dirname,
5-
fromFileUrl,
6-
gte,
7-
join,
8-
posix,
9-
relative,
10-
walk,
11-
WalkEntry,
12-
} from "./deps.ts";
1+
import { gte, join, posix, relative, walk, WalkEntry } from "./deps.ts";
132
import { error } from "./error.ts";
14-
import { FreshOptions } from "../server/mod.ts";
15-
import { build } from "./build.ts";
163

174
const MIN_DENO_VERSION = "1.31.0";
185

@@ -57,7 +44,7 @@ async function collectDir(
5744
}
5845
}
5946

60-
interface Manifest {
47+
export interface Manifest {
6148
routes: string[];
6249
islands: string[];
6350
}
@@ -184,48 +171,3 @@ export default manifest;
184171
"color: blue; font-weight: bold",
185172
);
186173
}
187-
188-
export async function dev(
189-
base: string,
190-
entrypoint: string,
191-
options: FreshOptions = {},
192-
) {
193-
ensureMinDenoVersion();
194-
195-
// Run update check in background
196-
updateCheck(DAY).catch(() => {});
197-
198-
entrypoint = new URL(entrypoint, base).href;
199-
200-
const dir = dirname(fromFileUrl(base));
201-
202-
let currentManifest: Manifest;
203-
const prevManifest = Deno.env.get("FRSH_DEV_PREVIOUS_MANIFEST");
204-
if (prevManifest) {
205-
currentManifest = JSON.parse(prevManifest);
206-
} else {
207-
currentManifest = { islands: [], routes: [] };
208-
}
209-
const newManifest = await collect(dir);
210-
Deno.env.set("FRSH_DEV_PREVIOUS_MANIFEST", JSON.stringify(newManifest));
211-
212-
const manifestChanged =
213-
!arraysEqual(newManifest.routes, currentManifest.routes) ||
214-
!arraysEqual(newManifest.islands, currentManifest.islands);
215-
216-
if (manifestChanged) await generate(dir, newManifest);
217-
218-
if (Deno.args.includes("build")) {
219-
await build(join(dir, "fresh.gen.ts"), options);
220-
} else {
221-
await import(entrypoint);
222-
}
223-
}
224-
225-
function arraysEqual<T>(a: T[], b: T[]): boolean {
226-
if (a.length !== b.length) return false;
227-
for (let i = 0; i < a.length; ++i) {
228-
if (a[i] !== b[i]) return false;
229-
}
230-
return true;
231-
}

0 commit comments

Comments
 (0)