@@ -154,7 +154,7 @@ impl BuildSystem {
154
154
if self . release {
155
155
args. push ( "--release" ) ;
156
156
}
157
- println ! ( "📦 starting cargo build on {}" , & self . manifest. package. name) ; // TODO: pin down logging.
157
+ println ! ( "starting cargo build on {}" , & self . manifest. package. name) ; // TODO: pin down logging.
158
158
let app_target_wasm = self . app_target_wasm . clone ( ) ;
159
159
spawn ( async move {
160
160
// Spawn the cargo build process.
@@ -187,7 +187,7 @@ impl BuildSystem {
187
187
fn spawn_wasm_bindgen_build ( & self , file_name : String ) -> JoinHandle < Result < WasmBindgenOutput > > {
188
188
let ( dist, bindgen_out, app_target_wasm) = ( self . dist . clone ( ) , self . bindgen_out . clone ( ) , self . app_target_wasm . clone ( ) ) ;
189
189
190
- println ! ( "📦 starting wasm-bindgen build" ) ; // TODO: pin down logging.
190
+ println ! ( "starting wasm-bindgen build" ) ; // TODO: pin down logging.
191
191
spawn ( async move {
192
192
let arg_out_path = format ! ( "--out-dir={}" , bindgen_out. display( ) ) ;
193
193
let arg_out_name = format ! ( "--out-name={}" , & file_name) ;
@@ -232,10 +232,10 @@ impl BuildSystem {
232
232
/// for the asset is finished, it will be able to update the DOM correctly based on its own
233
233
/// ID. All of these trunk specific IDs will be removed from the DOM before it is written.
234
234
async fn spawn_asset_pipelines ( & mut self , target_html : & mut Document ) -> Result < ( ) > {
235
- println ! ( "📦 spawning asset pipelines" ) ;
235
+ println ! ( "spawning asset pipelines" ) ;
236
236
237
- // Accumulate stylesheet assets to be processed .
238
- let style_assets = target_html. select ( r#"html head link"# )
237
+ // Accumulate assets declared in HTML head section links for processing .
238
+ let asset_links = target_html. select ( r#"html head link"# )
239
239
. iter ( )
240
240
. filter_map ( |node| {
241
241
// Be sure our link has an href to process, else skip.
@@ -245,24 +245,26 @@ impl BuildSystem {
245
245
} ;
246
246
Some ( ( node, href) )
247
247
} )
248
- . enumerate ( )
249
- . fold ( vec ! [ ] , |mut acc, ( idx, ( mut node, href) ) | {
250
- // Take the path to referenced resource, if it is a valid asset, then we continue.
251
- let path = self . target_html_dir . join ( href. as_ref ( ) ) ;
252
- let rel = node. attr_or ( "rel" , "" ) . to_string ( ) . to_lowercase ( ) ;
253
- let id = format ! ( "link-{}" , idx) ;
254
- let asset = match AssetFile :: new ( path, AssetType :: Link { rel} , id) {
255
- Ok ( asset) => asset,
256
- Err ( _) => return acc,
257
- } ;
258
- // Update the DOM with an ID for async processing.
259
- node. set_attr ( TRUNK_ID , & asset. id ) ;
260
- acc. push ( asset) ;
261
- acc
262
- } ) ;
248
+ . enumerate ( ) ;
249
+
250
+ // Update the DOM for each extracted asset as long as it is a valid FS path.
251
+ let mut assets = vec ! [ ] ;
252
+ for ( idx, ( mut node, href) ) in asset_links {
253
+ // Take the path to referenced resource, if it is a valid asset, then we continue.
254
+ let path = self . target_html_dir . join ( href. as_ref ( ) ) ;
255
+ let rel = node. attr_or ( "rel" , "" ) . to_string ( ) . to_lowercase ( ) ;
256
+ let id = format ! ( "link-{}" , idx) ;
257
+ let asset = match AssetFile :: new ( path, AssetType :: Link { rel} , id) . await {
258
+ Ok ( asset) => asset,
259
+ Err ( _) => continue ,
260
+ } ;
261
+ // Update the DOM with an ID for async processing.
262
+ node. set_attr ( TRUNK_ID , & asset. id ) ;
263
+ assets. push ( asset) ;
264
+ }
263
265
264
266
// Route assets over to the appropriate pipeline handler.
265
- for asset in style_assets {
267
+ for asset in assets {
266
268
self . spawn_asset_bundle ( asset) . await ?;
267
269
}
268
270
Ok ( ( ) )
@@ -375,10 +377,18 @@ impl AssetFile {
375
377
///
376
378
/// Any errors returned from this constructor indicate that one of these invariants was not
377
379
/// upheld.
378
- pub fn new ( path : PathBuf , atype : AssetType , id : String ) -> Result < Self > {
380
+ pub async fn new ( path : PathBuf , atype : AssetType , id : String ) -> Result < Self > {
379
381
// Take the path to referenced resource, if it is actually an FS path, then we continue.
380
- let path = path. canonicalize ( ) ?;
381
- ensure ! ( path. is_file( ) , "target file does not exist on the FS" ) ;
382
+ let path = match fs:: canonicalize ( & path) . await {
383
+ Ok ( path) => path,
384
+ Err ( _) => {
385
+ if !path. to_string_lossy ( ) . contains ( "://" ) {
386
+ eprintln ! ( "skipping invalid path: {}" , path. to_string_lossy( ) ) ;
387
+ }
388
+ return Err ( anyhow ! ( "skipping asset which is not a valid path" ) ) ;
389
+ }
390
+ } ;
391
+ ensure ! ( path. is_file( ) . await , "target file does not exist on the FS" ) ;
382
392
let file_name = match path. file_name ( ) {
383
393
Some ( file_name) => file_name. to_owned ( ) ,
384
394
None => bail ! ( "asset has no file name" ) ,
@@ -391,7 +401,7 @@ impl AssetFile {
391
401
Some ( ext) => ext. to_string_lossy ( ) . to_lowercase ( ) ,
392
402
None => bail ! ( "asset has no file extension" ) ,
393
403
} ;
394
- Ok ( Self { path, file_name, file_stem, ext, atype, id} )
404
+ Ok ( Self { path : path . into ( ) , file_name, file_stem, ext, atype, id} )
395
405
}
396
406
}
397
407
0 commit comments