Skip to content
This repository was archived by the owner on May 6, 2023. It is now read-only.

Commit d83d2b9

Browse files
committed
update path scanning methods to be fully exhausted when run in sh shell
1 parent 7d15ea9 commit d83d2b9

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/utils/ScanPaths.ts

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const ScanPaths: ScanPaths = async (basePath: string, currentPath: string): Prom
3030
//This is just meant to exhaust the 2 default paths (routes and src/routes) if a custom route root is not given in the config.
3131
if (basePath === "routes") {
3232
const rootExists = existsSync(thisPath);
33-
console.log(rootExists);
3433
if (!rootExists) {
3534
return await ScanPaths("src/routes", "");
3635
} else if (rootExists) {

src/utils/ValidateRoutes.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Transpiler } from "bun";
22
import { Route, RoutePath, ValidateRoute } from "index.d";
3+
import { join } from "path";
4+
import { cwd } from "process";
35

46
const transpiler = new Transpiler({ loader: "ts" });
57

@@ -19,7 +21,7 @@ const validateRoute: ValidateRoute = async (path: RoutePath): Promise<Route | ne
1921
throw new Error("Module must be a Typescript file", { cause: `${path} does not point to a Typescript file` });
2022
}
2123

22-
const loadedFile = await Bun.file(path.FullPath);
24+
const loadedFile = await Bun.file(join(cwd(), path.FullPath));
2325
const fileContents = await loadedFile.text();
2426
const transpiled = await transpiler.scan(fileContents);
2527
if (!transpiled.exports.includes("default")) {
@@ -28,7 +30,7 @@ const validateRoute: ValidateRoute = async (path: RoutePath): Promise<Route | ne
2830
if (transpiled.exports.length > 1) {
2931
throw new Error("Route must have only a single export that is default (for now)", { cause: `${path.FullPath} exports more than just default` });
3032
}
31-
if (typeof require(path.FullPath).default !== "function") {
33+
if (typeof require(join(cwd(), path.FullPath)).default !== "function") {
3234
throw new Error("Route must export a default function", { cause: `${path.FullPath} default export is not a function` });
3335
}
3436

@@ -40,12 +42,14 @@ const validateRoute: ValidateRoute = async (path: RoutePath): Promise<Route | ne
4042
throw new Error("Route file must be a Typescript file (or the .ts extension)", { cause: `${path.FullPath} has the extension: ${parts[1]} - or something that ISNT .ts` });
4143
}
4244

43-
//const params = parts[0].match(/(?<=\[)(.*?)(?=\])/g);
45+
const delegate = await import(join(cwd(), path.FullPath));
4446

4547
return {
4648
route: parts[0],
4749
routeParameters: {},
48-
delegate: require(path.FullPath).default
50+
// delegate: require(path.FullPath).default,
51+
delegate: delegate.default
52+
4953
};
5054
}
5155

0 commit comments

Comments
 (0)