@@ -43,7 +43,7 @@ export async function build() {
4343 user_config : await get_user_pranx_config ( ) ,
4444 } ) ;
4545
46- const browser_bundle_metafile = await bundle_browser ( {
46+ const browser_bundle_result = await bundle_browser ( {
4747 optimize : true ,
4848 user_config : await get_user_pranx_config ( ) ,
4949 } ) ;
@@ -58,81 +58,90 @@ export async function build() {
5858
5959 server_entry_module = ( await import ( server_site_manifest . entry_server ) ) as ServerEntryModule ;
6060
61- const pranx_bundle_replace_path = join ( ".pranx" , "browser" ) ;
61+ const pranx_browser_base_path = join ( ".pranx" , "browser" ) ;
6262
63- const css_output : {
63+ type CSS_OUTPUT = {
6464 entry : string ;
6565 [ key : string ] : string ;
66- } = {
66+ } ;
67+
68+ const css_output : CSS_OUTPUT = {
6769 entry : "" ,
6870 } ;
6971
7072 // Calculating css files
71- for ( const [ file , _output ] of Object . entries ( browser_bundle_metafile . metafile . outputs ) ) {
73+ for ( const [ file , _output ] of Object . entries ( browser_bundle_result . metafile . outputs ) ) {
74+ if ( ! file . endsWith ( ".css" ) ) continue ;
75+
7276 if ( file . endsWith ( "entry-client.css" ) ) {
73- css_output . entry = file . replace ( pranx_bundle_replace_path , "" ) ;
77+ css_output . entry = file . replace ( pranx_browser_base_path , "" ) ;
7478 continue ;
7579 }
7680
77- if ( file . endsWith ( ".css" ) ) {
78- const pages_relative_path = file . replace ( pranx_bundle_replace_path , "" ) ;
81+ const css_file_relative = file . replace ( pranx_browser_base_path , "" ) ;
7982
80- const path_splitted = pages_relative_path . replace ( "page.css" , "" ) . split ( "/" ) ;
81- path_splitted . pop ( ) ;
82- const final_path = path_splitted . join ( "/" ) || "/" ;
83+ const path_normalized = `/${ css_file_relative
84+ . replace ( "page.css" , "" )
85+ . split ( "/" )
86+ . filter ( Boolean )
87+ . join ( "/" ) } `;
8388
84- css_output [ final_path ] = pages_relative_path ;
85- }
89+ css_output [ path_normalized ] = css_file_relative ;
8690 }
8791
88- // Generating Manifest and generating static pages
89- for ( const [ file , _output ] of Object . entries ( browser_bundle_metafile . metafile . outputs ) ) {
92+ // Generating Manifest and generating static pages data
93+ for ( const [ file , _output ] of Object . entries ( browser_bundle_result . metafile . outputs ) ) {
9094 if ( ! file . endsWith ( "page.js" ) ) continue ;
9195
92- const pages_relative_path = file . replace ( pranx_bundle_replace_path , "" ) ;
96+ const pages_relative_path = file . replace ( pranx_browser_base_path , "" ) ;
9397
94- const path_splitted = pages_relative_path . replace ( "page.js" , "" ) . split ( "/" ) ;
95- path_splitted . pop ( ) ;
96- const final_path = path_splitted . join ( "/" ) || "/" ;
98+ const final_path_normalized = `/${ pages_relative_path
99+ . replace ( "page.js" , "" )
100+ . split ( "/" )
101+ . filter ( Boolean )
102+ . join ( "/" ) } `;
97103
98104 const module_path = join ( OUTPUT_BUNDLE_SERVER_DIR , "pages" , pages_relative_path ) ;
105+
99106 const {
100- // default: PageComponent,
101- getServerSideProps,
102- getStaticProps,
103- getStaticPaths,
104- // meta: metadata,
107+ getServerSideProps = undefined ,
108+ getStaticProps = undefined ,
109+ getStaticPaths = undefined ,
105110 } = ( await import ( module_path ) ) as PageModule ;
106111
107112 if ( getServerSideProps && ( getStaticProps || getStaticPaths ) ) {
108113 logger . error ( `
109- msg: "Only one can be present: getServerSideProps or getStaticProps/getStaticPaths"
110- file: ${ module_path }
111- path: ${ final_path } ` ) ;
114+ msg: "Only one can be present: getServerSideProps or getStaticProps/getStaticPaths"
115+ file: ${ module_path }
116+ path: ${ final_path_normalized }
117+ ` ) ;
112118 process . exit ( 1 ) ;
113119 }
114120
115121 const isStatic = ! getServerSideProps ;
116- const isUrlDynamic = final_path . includes ( "[" ) ;
122+ const isUrlDynamic = final_path_normalized . includes ( "[" ) ;
117123 const dynamic_params = ! isUrlDynamic
118124 ? [ ]
119- : path_splitted
125+ : final_path_normalized
126+ . split ( "/" )
120127 . filter ( ( i ) => i . startsWith ( "[" ) && i . endsWith ( "]" ) )
121128 . map ( ( i ) => i . replace ( "[" , "" ) . replace ( "]" , "" ) ) ;
122129
123130 if ( isStatic && isUrlDynamic && ! getStaticPaths ) {
124131 logger . error ( `
125- msg: "getStaticPaths must be present on static pages with dynamic params"
126- file: ${ module_path }
127- path: ${ final_path } ` ) ;
132+ msg: "getStaticPaths must be present on static pages with dynamic params"
133+ file: ${ module_path }
134+ path: ${ final_path_normalized }
135+ ` ) ;
128136 process . exit ( 1 ) ;
129137 }
130138
131139 if ( ! isStatic && isUrlDynamic && ! getServerSideProps ) {
132140 logger . error ( `
133- msg: "getServerSideProps must be present on server pages with dynamic params"
134- file: ${ module_path }
135- path: ${ final_path } ` ) ;
141+ msg: "getServerSideProps must be present on server pages with dynamic params"
142+ file: ${ module_path }
143+ path: ${ final_path_normalized }
144+ ` ) ;
136145 process . exit ( 1 ) ;
137146 }
138147
@@ -143,17 +152,17 @@ path: ${final_path}`);
143152
144153 if ( isStatic && isUrlDynamic && getStaticPaths ) {
145154 const static_paths_result = await getStaticPaths ( ) ;
146- const new_final_path = final_path ;
155+ const new_final_path = final_path_normalized ;
147156
148157 server_site_manifest . routes . push ( {
149- path : final_path ,
158+ path : final_path_normalized ,
150159 module : pages_relative_path ,
151160 props : statics_fn_result . props ,
152161 rendering_kind : "static" ,
153162 revalidate : statics_fn_result . revalidate || - 1 ,
154163 is_dynamic : isUrlDynamic ,
155164 dynamic_params : dynamic_params ,
156- css : [ css_output . entry , css_output [ final_path ] || "" ] . filter ( Boolean ) ,
165+ css : [ css_output . entry , css_output [ final_path_normalized ] || "" ] . filter ( Boolean ) ,
157166 static_generated_routes : [ ] ,
158167 absolute_module_path : module_path ,
159168 } ) ;
@@ -168,10 +177,11 @@ path: ${final_path}`);
168177
169178 if ( replaced_path . includes ( "[" ) ) {
170179 logger . error ( `
171- msg: "getStaticPaths did not return all the necessary params"
172- file: ${ module_path }
173- path: ${ final_path }
174- params returned by getStaticPaths: ${ JSON . stringify ( static_path . params ) } ` ) ;
180+ msg: "getStaticPaths did not return all the necessary params"
181+ file: ${ module_path }
182+ path: ${ final_path_normalized }
183+ params returned by getStaticPaths: ${ JSON . stringify ( static_path . params ) }
184+ ` ) ;
175185 process . exit ( 1 ) ;
176186 }
177187
@@ -202,15 +212,15 @@ params returned by getStaticPaths: ${JSON.stringify(static_path.params)}`);
202212 }
203213
204214 server_site_manifest . routes . push ( {
205- path : final_path ,
215+ path : final_path_normalized ,
206216 module : pages_relative_path ,
207217 props : statics_fn_result . props ,
208218 rendering_kind : isStatic ? "static" : "server-side" ,
209219 revalidate : statics_fn_result . revalidate || - 1 ,
210220 static_generated_routes : [ ] ,
211221 is_dynamic : isUrlDynamic ,
212222 dynamic_params : dynamic_params ,
213- css : [ css_output . entry , css_output [ final_path ] || "" ] . filter ( Boolean ) as string [ ] ,
223+ css : [ css_output . entry , css_output [ final_path_normalized ] || "" ] . filter ( Boolean ) as string [ ] ,
214224 absolute_module_path : module_path ,
215225 } ) ;
216226 }
@@ -224,7 +234,7 @@ params returned by getStaticPaths: ${JSON.stringify(static_path.params)}`);
224234 rendering_kind : r . rendering_kind ,
225235 css : r . css ,
226236 is_dynamic : r . is_dynamic ,
227- path_parsed_for_routing : filePathToRoutingPath ( r . path ) ,
237+ path_parsed_for_routing : filePathToRoutingPath ( r . path , false ) ,
228238 static_generated_routes : r . static_generated_routes . map ( ( r ) => {
229239 return {
230240 path : r . path ,
0 commit comments