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

Commit 20fe78a

Browse files
committed
Init module loaders only in cli mode
1 parent a936148 commit 20fe78a

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

server/config.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -160,29 +160,31 @@ export async function loadImportMap(): Promise<ImportMap> {
160160

161161
export async function initModuleLoaders(importMap: ImportMap): Promise<ModuleLoader[]> {
162162
const loaders: ModuleLoader[] = [];
163-
for (const key in importMap.imports) {
164-
if (/^\*\.[a-z0-9]+$/i.test(key)) {
165-
let src = importMap.imports[key];
166-
if (src.endsWith("!loader")) {
167-
src = util.trimSuffix(src, "!loader");
168-
if (src.startsWith("./") || src.startsWith("../")) {
169-
src = "file://" + join(dirname(importMap.__filename), src);
170-
}
171-
let { default: loader } = await import(src);
172-
if (typeof loader === "function") {
173-
loader = new loader();
174-
}
175-
if (
176-
typeof loader === "object" && loader !== null &&
177-
typeof loader.test === "function" && typeof loader.load === "function"
178-
) {
179-
const reg = globToRegExp("/**/" + key);
180-
loaders.push({
181-
test: (pathname: string) => {
182-
return reg.test(pathname) && loader.test(pathname);
183-
},
184-
load: (pathname: string, env: Record<string, unknown>) => loader.load(pathname, env),
185-
});
163+
if (Deno.env.get("ALEPH_CLI")) {
164+
for (const key in importMap.imports) {
165+
if (/^\*\.[a-z0-9]+$/i.test(key)) {
166+
let src = importMap.imports[key];
167+
if (src.endsWith("!loader")) {
168+
src = util.trimSuffix(src, "!loader");
169+
if (src.startsWith("./") || src.startsWith("../")) {
170+
src = "file://" + join(dirname(importMap.__filename), src);
171+
}
172+
let { default: loader } = await import(src);
173+
if (typeof loader === "function") {
174+
loader = new loader();
175+
}
176+
if (
177+
typeof loader === "object" && loader !== null &&
178+
typeof loader.test === "function" && typeof loader.load === "function"
179+
) {
180+
const reg = globToRegExp("/**/" + key);
181+
loaders.push({
182+
test: (pathname: string) => {
183+
return reg.test(pathname) && loader.test(pathname);
184+
},
185+
load: (pathname: string, env: Record<string, unknown>) => loader.load(pathname, env),
186+
});
187+
}
186188
}
187189
}
188190
}

server/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const serve = (options: ServerOptions = {}) => {
8686
} catch (err) {
8787
if (!(err instanceof Deno.errors.NotFound)) {
8888
log.error(err);
89-
return new Response("Internal Server Error", { status: 500 });
89+
return new Response(err.message, { status: 500 });
9090
}
9191
}
9292
}

0 commit comments

Comments
 (0)