@@ -2,7 +2,6 @@ import { basename, dirname, extname, join } from "https://deno.land/std@0.136.0/
22import { ensureDir } from "https://deno.land/std@0.136.0/fs/ensure_dir.ts" ;
33import { build as esbuild , type Loader , stop } from "https://deno.land/x/esbuild@v0.14.38/mod.js" ;
44import { parseExportNames } from "https://deno.land/x/aleph_compiler@0.1.0/mod.ts" ;
5- import cache from "../lib/cache.ts" ;
65import { existsDir , existsFile } from "../lib/fs.ts" ;
76import { parseHtmlLinks } from "./html.ts" ;
87import log from "../lib/log.ts" ;
@@ -45,6 +44,7 @@ export async function build(serverEntry?: string) {
4544 const platform = config ?. build ?. platform ?? "deno" ;
4645 const target = config ?. build ?. target ?? "es2020" ;
4746 const outputDir = join ( workingDir , config ?. build ?. outputDir ?? "dist" ) ;
47+ const modulesProxyPort = Deno . env . get ( "ALEPH_MODULES_PROXY_PORT" ) ;
4848
4949 if ( platform === "cloudflare" || platform === "vercel" ) {
5050 log . fatal ( `Deploy to ${ supportedPlatforms [ platform ] } is not supported yet` ) ;
@@ -64,13 +64,20 @@ export async function build(serverEntry?: string) {
6464 if ( config ?. routes ) {
6565 const { routes } = await initRoutes ( config ?. routes ) ;
6666 routeFiles = await Promise . all ( routes . map ( async ( [ _ , { filename } ] ) => {
67- const code = await Deno . readTextFile ( filename ) ;
67+ let code : string ;
68+ const ext = extname ( filename ) . slice ( 1 ) ;
69+ if ( builtinModuleExts . includes ( ext ) ) {
70+ code = await Deno . readTextFile ( filename ) ;
71+ } else if ( modulesProxyPort ) {
72+ code = await fetch ( `http://localhost:${ modulesProxyPort } /${ filename . slice ( 1 ) } ` ) . then ( ( res ) => res . text ( ) ) ;
73+ } else {
74+ throw new Error ( `Unsupported module type: ${ ext } ` ) ;
75+ }
6876 const exportNames = await parseExportNames ( filename , code ) ;
6977 return [ filename , exportNames ] ;
7078 } ) ) ;
7179 }
7280
73- const modulesProxyPort = Deno . env . get ( "ALEPH_MODULES_PROXY_PORT" ) ;
7481 const serverEntryCode = [
7582 `import { DependencyGraph } from "${ alephPkgUri } /server/graph.ts";` ,
7683 `import graph from "./server_dependency_graph.js";` ,
@@ -211,7 +218,7 @@ export async function build(serverEntry?: string) {
211218 // bundle `server/transformer.ts` with `server/server_dist.ts` content
212219 url . pathname = util . trimSuffix ( url . pathname , "transformer.ts" ) + "serve_dist.ts" ;
213220 }
214- const res = await cache ( url . href ) ;
221+ const res = await fetch ( url . href ) ;
215222 const contents = await res . text ( ) ;
216223 let ext = extname ( url . pathname ) . slice ( 1 ) ;
217224 if ( ext === "mjs" ) {
0 commit comments