@@ -4,9 +4,9 @@ use std::{
44} ;
55
66use rspack_core:: {
7- ChunkUkey , Compilation , CompilationParams , CompilerCompilation , CompilerFinishMake , ModuleType ,
8- NormalModuleFactoryParser , ParserAndGenerator , ParserOptions , Plugin , get_module_directives ,
9- get_module_hashbang,
7+ AssetEmittedInfo , ChunkUkey , Compilation , CompilationParams , CompilerAssetEmitted ,
8+ CompilerCompilation , CompilerFinishMake , ModuleType , NormalModuleFactoryParser ,
9+ ParserAndGenerator , ParserOptions , Plugin , get_module_directives , get_module_hashbang,
1010 rspack_sources:: { ConcatSource , RawStringSource , SourceExt } ,
1111} ;
1212use rspack_error:: Result ;
@@ -179,6 +179,31 @@ async fn finish_make(&self, compilation: &mut Compilation) -> Result<()> {
179179 Ok ( ( ) )
180180}
181181
182+ #[ plugin_hook( CompilerAssetEmitted for RslibPlugin ) ]
183+ async fn asset_emitted (
184+ & self ,
185+ _compilation : & Compilation ,
186+ _filename : & str ,
187+ info : & AssetEmittedInfo ,
188+ ) -> Result < ( ) > {
189+ use std:: os:: unix:: fs:: PermissionsExt ;
190+
191+ use rspack_core:: rspack_sources:: Source ;
192+
193+ // Check if the file content starts with a hashbang
194+ let content = info. source . source ( ) . into_string_lossy ( ) ;
195+ if content. starts_with ( "#!" ) {
196+ // Set file permissions to 0o755 (rwxr-xr-x)
197+ let metadata = std:: fs:: metadata ( & info. target_path )
198+ . map_err ( |e| rspack_error:: error!( "Failed to get file metadata: {}" , e) ) ?;
199+ let mut permissions = metadata. permissions ( ) ;
200+ permissions. set_mode ( 0o755 ) ;
201+ std:: fs:: set_permissions ( & info. target_path , permissions)
202+ . map_err ( |e| rspack_error:: error!( "Failed to set file permissions: {}" , e) ) ?;
203+ }
204+ Ok ( ( ) )
205+ }
206+
182207impl Plugin for RslibPlugin {
183208 fn name ( & self ) -> & ' static str {
184209 "rslib"
@@ -192,6 +217,10 @@ impl Plugin for RslibPlugin {
192217 . tap ( nmf_parser:: new ( self ) ) ;
193218
194219 ctx. compiler_hooks . finish_make . tap ( finish_make:: new ( self ) ) ;
220+ ctx
221+ . compiler_hooks
222+ . asset_emitted
223+ . tap ( asset_emitted:: new ( self ) ) ;
195224
196225 Ok ( ( ) )
197226 }
0 commit comments