@@ -2,7 +2,6 @@ import { basename, dirname, extname, join } from "https://deno.land/
[email protected] /
2
2
import { ensureDir } from "https://deno.land/[email protected] /fs/ensure_dir.ts" ;
3
3
import { build as esbuild , type Loader , stop } from "https://deno.land/x/[email protected] /mod.js" ;
4
4
import { parseExportNames } from "https://deno.land/x/[email protected] /mod.ts" ;
5
- import cache from "../lib/cache.ts" ;
6
5
import { existsDir , existsFile } from "../lib/fs.ts" ;
7
6
import { parseHtmlLinks } from "./html.ts" ;
8
7
import log from "../lib/log.ts" ;
@@ -45,6 +44,7 @@ export async function build(serverEntry?: string) {
45
44
const platform = config ?. build ?. platform ?? "deno" ;
46
45
const target = config ?. build ?. target ?? "es2020" ;
47
46
const outputDir = join ( workingDir , config ?. build ?. outputDir ?? "dist" ) ;
47
+ const modulesProxyPort = Deno . env . get ( "ALEPH_MODULES_PROXY_PORT" ) ;
48
48
49
49
if ( platform === "cloudflare" || platform === "vercel" ) {
50
50
log . fatal ( `Deploy to ${ supportedPlatforms [ platform ] } is not supported yet` ) ;
@@ -64,13 +64,20 @@ export async function build(serverEntry?: string) {
64
64
if ( config ?. routes ) {
65
65
const { routes } = await initRoutes ( config ?. routes ) ;
66
66
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
+ }
68
76
const exportNames = await parseExportNames ( filename , code ) ;
69
77
return [ filename , exportNames ] ;
70
78
} ) ) ;
71
79
}
72
80
73
- const modulesProxyPort = Deno . env . get ( "ALEPH_MODULES_PROXY_PORT" ) ;
74
81
const serverEntryCode = [
75
82
`import { DependencyGraph } from "${ alephPkgUri } /server/graph.ts";` ,
76
83
`import graph from "./server_dependency_graph.js";` ,
@@ -211,7 +218,7 @@ export async function build(serverEntry?: string) {
211
218
// bundle `server/transformer.ts` with `server/server_dist.ts` content
212
219
url . pathname = util . trimSuffix ( url . pathname , "transformer.ts" ) + "serve_dist.ts" ;
213
220
}
214
- const res = await cache ( url . href ) ;
221
+ const res = await fetch ( url . href ) ;
215
222
const contents = await res . text ( ) ;
216
223
let ext = extname ( url . pathname ) . slice ( 1 ) ;
217
224
if ( ext === "mjs" ) {
0 commit comments