Skip to content

Commit 019d6a7

Browse files
fix
1 parent ff2b9c1 commit 019d6a7

File tree

7 files changed

+21
-26
lines changed

7 files changed

+21
-26
lines changed

deno.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"imports": {
4747
"@deno/doc": "jsr:@deno/doc@^0.172.0",
4848
"@deno/esbuild-plugin": "jsr:@deno/esbuild-plugin@^1.1.1",
49-
"@deno/loader": "jsr:@deno/loader@^0.2.1",
5049
"@std/cli": "jsr:@std/cli@^1.0.19",
5150
"@std/collections": "jsr:@std/collections@^1.0.11",
5251
"@std/http": "jsr:@std/http@^1.0.15",

deno.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dev/file_transformer_test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ function testTransformer(files: Record<string, string>, root = "/") {
1717
const buf = new TextEncoder().encode(content);
1818
return Promise.resolve(buf);
1919
},
20+
readTextFile: (file) => {
21+
if (file instanceof URL) throw new Error("Not supported");
22+
// deno-lint-ignore no-explicit-any
23+
const content = (files as any)[file];
24+
return Promise.resolve(content);
25+
},
2026
};
2127
return new FileTransformer(mockFs, root);
2228
}

src/dev/fs_crawl.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as path from "@std/path";
55
import { pathToPattern } from "../router.ts";
66
import { CommandType } from "../commands.ts";
77
import { sortRoutePaths } from "../fs_routes.ts";
8-
import { RequestedModuleType, ResolutionMode, Workspace } from "@deno/loader";
98
import type { RouteConfig } from "../types.ts";
109

1110
const GROUP_REG = /[/\\\\]\((_[^/\\\\]+)\)[/\\\\]/;
@@ -17,12 +16,6 @@ export async function crawlRouteDir<State>(
1716
onIslandSpecifier: (spec: string) => void,
1817
files: FsRouteFileNoMod<State>[],
1918
) {
20-
const workspace = await new Workspace({
21-
noTranspile: true,
22-
preserveJsx: true,
23-
});
24-
const loader = await workspace.createLoader({ entrypoints: [] });
25-
2619
await walkDir(
2720
fs,
2821
routeDir,
@@ -82,23 +75,15 @@ export async function crawlRouteDir<State>(
8275

8376
routePattern = pathToPattern(id.slice(1));
8477

85-
const resolved = loader.resolve(
86-
entry.path,
87-
undefined,
88-
ResolutionMode.Import,
89-
);
90-
const loaded = await loader.load(resolved, RequestedModuleType.Text);
91-
if (loaded.kind !== "external") {
92-
const text = new TextDecoder().decode(loaded.code);
93-
lazy = !text.includes("routeOverride");
78+
const code = await fs.readTextFile(entry.path);
79+
lazy = !code.includes("routeOverride");
9480

95-
// TODO: We could do an AST parse here to detect the
96-
// kind of handler that's used to get a more accurate
97-
// list of methods this route supports.
98-
overrideConfig = {
99-
methods: "ALL",
100-
};
101-
}
81+
// TODO: We could do an AST parse here to detect the
82+
// kind of handler that's used to get a more accurate
83+
// list of methods this route supports.
84+
overrideConfig = {
85+
methods: "ALL",
86+
};
10287
}
10388

10489
files.push({

src/fs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface FsAdapter {
99
isDirectory(path: string | URL): Promise<boolean>;
1010
mkdirp(dir: string): Promise<void>;
1111
readFile(path: string | URL): Promise<Uint8Array>;
12+
readTextFile(path: string | URL): Promise<string>;
1213
}
1314

1415
export const fsAdapter: FsAdapter = {
@@ -33,4 +34,5 @@ export const fsAdapter: FsAdapter = {
3334
}
3435
},
3536
readFile: Deno.readFile,
37+
readTextFile: Deno.readTextFile,
3638
};

src/fs_routes_test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ Deno.test("fsRoutes - warn on _middleware with object handler", async () => {
14801480

14811481
expect(warnSpy.fake).toHaveBeenCalledTimes(1);
14821482
expect(warnSpy.fake).toHaveBeenLastCalledWith(
1483-
"🍋 %c[WARNING] Unsupported route config: Middleware does not support object handlers with GET, POST, etc.",
1483+
"🍋 %c[WARNING] Unsupported route config: Middleware does not support object handlers with GET, POST, etc. in routes/_middleware.ts",
14841484
expect.any(String),
14851485
);
14861486
});

src/test_utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ export function createFakeFs(files: Record<string, unknown>): FsAdapter {
121121
async mkdirp(_dir: string) {
122122
},
123123
readFile: Deno.readFile,
124+
// deno-lint-ignore require-await
125+
async readTextFile(path) {
126+
return String(files[String(path)]);
127+
},
124128
};
125129
}
126130

0 commit comments

Comments
 (0)