File tree Expand file tree Collapse file tree 12 files changed +82
-10
lines changed Expand file tree Collapse file tree 12 files changed +82
-10
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ export const EXPRESS_SERVER = (args: {
42
42
} ) =>
43
43
String . raw `
44
44
import { createRequestHandler } from "@remix-run/express";
45
- import { installGlobals } from "@remix-run/node";
45
+ import { installGlobals, getServerBuild } from "@remix-run/node";
46
46
import express from "express";
47
47
48
48
installGlobals();
@@ -71,9 +71,7 @@ export const EXPRESS_SERVER = (args: {
71
71
app.all(
72
72
"*",
73
73
createRequestHandler({
74
- build: viteDevServer
75
- ? () => viteDevServer.ssrLoadModule("virtual:remix/server-build")
76
- : await import("./build/index.js"),
74
+ build: await getServerBuild("./build/server/index.js", viteDevServer),
77
75
getLoadContext: () => (${ JSON . stringify ( args . loadContext ?? { } ) } ),
78
76
})
79
77
);
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ const customServerFile = ({
95
95
96
96
return String . raw `
97
97
import { createRequestHandler } from "@remix-run/express";
98
- import { installGlobals } from "@remix-run/node";
98
+ import { installGlobals, getServerBuild } from "@remix-run/node";
99
99
import express from "express";
100
100
installGlobals();
101
101
@@ -115,9 +115,7 @@ const customServerFile = ({
115
115
app.all(
116
116
"${ basename } *",
117
117
createRequestHandler({
118
- build: viteDevServer
119
- ? () => viteDevServer.ssrLoadModule("virtual:remix/server-build")
120
- : await import("./build/server/index.js"),
118
+ build: await getServerBuild("./build/server/index.js", viteDevServer),
121
119
})
122
120
);
123
121
app.get("*", (_req, res) => {
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export {
15
15
defer ,
16
16
broadcastDevReady ,
17
17
logDevReady ,
18
+ getServerBuild ,
18
19
isCookie ,
19
20
isSession ,
20
21
json ,
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export {
17
17
broadcastDevReady ,
18
18
createSession ,
19
19
defer ,
20
+ getServerBuild ,
20
21
isCookie ,
21
22
isSession ,
22
23
json ,
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ export {
27
27
defer ,
28
28
broadcastDevReady ,
29
29
logDevReady ,
30
+ getServerBuild ,
30
31
isCookie ,
31
32
isSession ,
32
33
json ,
Original file line number Diff line number Diff line change
1
+ import { getServerBuild } from "../build" ;
2
+
3
+ it ( "getServerBuild throws when path is relative" , async ( ) => {
4
+ await expect ( ( ) => getServerBuild ( "./build/server/index.js" ) ) . rejects . toThrow (
5
+ "Server build path must be absolute, but received relative path: ./build/server/index.js"
6
+ ) ;
7
+ } ) ;
8
+
9
+ it ( "getServerBuild throws when build does not exist" , async ( ) => {
10
+ await expect ( ( ) =>
11
+ getServerBuild ( "/this/path/doesnt/exist.js" )
12
+ ) . rejects . toThrow (
13
+ "Could not import server build from '/this/path/doesnt/exist.js'. Did you forget to run 'remix vite:build' first?"
14
+ ) ;
15
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import type { ViteDevServer } from "vite" ;
2
+ import path from "pathe" ;
3
+
1
4
import type { ActionFunctionArgs , LoaderFunctionArgs } from "./routeModules" ;
2
5
import type { AssetsManifest , EntryContext , FutureConfig } from "./entry" ;
3
6
import type { ServerRouteManifest } from "./routes" ;
4
7
import type { AppLoadContext } from "./data" ;
5
8
9
+ export async function getServerBuild (
10
+ buildPath : string ,
11
+ {
12
+ viteDevServer,
13
+ } : {
14
+ viteDevServer ?: ViteDevServer ;
15
+ } = { }
16
+ ) : Promise < ServerBuild | ( ( ) => Promise < ServerBuild > ) > {
17
+ if ( viteDevServer ) {
18
+ return ( ) =>
19
+ viteDevServer . ssrLoadModule (
20
+ "virtual:remix/server-build"
21
+ ) as Promise < ServerBuild > ;
22
+ }
23
+
24
+ if ( ! path . isAbsolute ( buildPath ) ) {
25
+ throw new Error (
26
+ `Server build path must be absolute, but received relative path: ${ buildPath } `
27
+ ) ;
28
+ }
29
+
30
+ // Convert file path meant for `import` to URL for Windows compatibility
31
+ let buildURL = "file:///" + encodeURI ( buildPath ) ;
32
+ return import ( buildURL ) . catch ( ( ) => {
33
+ throw Error (
34
+ `Could not import server build from '${ buildPath } '. Did you forget to run 'remix vite:build' first?`
35
+ ) ;
36
+ } ) ;
37
+ }
38
+
6
39
// NOTE: IF you modify `ServerBuild`, be sure to modify the
7
40
// `remix-dev/server-build.ts` file to reflect the new field as well
8
41
Original file line number Diff line number Diff line change @@ -80,3 +80,4 @@ export type {
80
80
UploadHandler ,
81
81
UploadHandlerPart ,
82
82
} from "./reexport" ;
83
+ export { getServerBuild } from "./reexport" ;
Original file line number Diff line number Diff line change 20
20
"@types/cookie" : " ^0.6.0" ,
21
21
"@web3-storage/multipart-parser" : " ^1.0.0" ,
22
22
"cookie" : " ^0.6.0" ,
23
+ "pathe" : " ^1.1.2" ,
23
24
"set-cookie-parser" : " ^2.4.8" ,
24
25
"source-map" : " ^0.7.3"
25
26
},
26
27
"devDependencies" : {
27
28
"@types/set-cookie-parser" : " ^2.4.1" ,
28
- "typescript" : " ^5.1.6"
29
+ "typescript" : " ^5.1.6" ,
30
+ "vite" : " ^5.1.0"
29
31
},
30
32
"peerDependencies" : {
31
- "typescript" : " ^5.1.0"
33
+ "typescript" : " ^5.1.0" ,
34
+ "vite" : " ^5.1.0"
32
35
},
33
36
"peerDependenciesMeta" : {
34
37
"typescript" : {
35
38
"optional" : true
39
+ },
40
+ "vite" : {
41
+ "optional" : true
36
42
}
37
43
},
38
44
"engines" : {
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export type {
7
7
ServerBuild ,
8
8
ServerEntryModule ,
9
9
} from "./build" ;
10
+ export { getServerBuild } from "./build" ;
10
11
11
12
export type { UploadHandlerPart , UploadHandler } from "./formData" ;
12
13
export type {
Original file line number Diff line number Diff line change 5
5
"lib" : [" ES2022" ],
6
6
"target" : " ES2022" ,
7
7
"composite" : true ,
8
+ "module" : " ESNext" ,
8
9
9
10
"moduleResolution" : " Bundler" ,
10
11
"allowSyntheticDefaultImports" : true ,
Original file line number Diff line number Diff line change @@ -10747,6 +10747,11 @@ pathe@^1.0.0, pathe@^1.1.0:
10747
10747
resolved "https://registry.npmjs.org/pathe/-/pathe-1.1.0.tgz#e2e13f6c62b31a3289af4ba19886c230f295ec03"
10748
10748
integrity sha512-ODbEPR0KKHqECXW1GoxdDb+AZvULmXjVPy4rt+pGo2+TnjJTIPJQSVS6N63n8T2Ip+syHhbn52OewKicV0373w==
10749
10749
10750
+ pathe@^1.1.2:
10751
+ version "1.1.2"
10752
+ resolved "https://registry.npmjs.org/pathe/-/pathe-1.1.2.tgz#6c4cb47a945692e48a1ddd6e4094d170516437ec"
10753
+ integrity sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==
10754
+
10750
10755
peek-stream@^1.1.0:
10751
10756
version "1.1.3"
10752
10757
resolved "https://registry.npmjs.org/peek-stream/-/peek-stream-1.1.3.tgz"
@@ -13494,6 +13499,17 @@ vite@5.1.3:
13494
13499
optionalDependencies:
13495
13500
fsevents "~2.3.2"
13496
13501
13502
+ vite@^5.1.0:
13503
+ version "5.1.4"
13504
+ resolved "https://registry.npmjs.org/vite/-/vite-5.1.4.tgz#14e9d3e7a6e488f36284ef13cebe149f060bcfb6"
13505
+ integrity sha512-n+MPqzq+d9nMVTKyewqw6kSt+R3CkvF9QAKY8obiQn8g1fwTscKxyfaYnC632HtBXAQGc1Yjomphwn1dtwGAHg==
13506
+ dependencies:
13507
+ esbuild "^0.19.3"
13508
+ postcss "^8.4.35"
13509
+ rollup "^4.2.0"
13510
+ optionalDependencies:
13511
+ fsevents "~2.3.3"
13512
+
13497
13513
w3c-xmlserializer@^4.0.0:
13498
13514
version "4.0.0"
13499
13515
resolved "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-4.0.0.tgz#aebdc84920d806222936e3cdce408e32488a3073"
You can’t perform that action at this time.
0 commit comments