Skip to content

Commit 0fdeffc

Browse files
committed
chmod
1 parent 6bf6543 commit 0fdeffc

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

crates/rspack_plugin_esm_library/src/render.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl EsmLibraryPlugin {
101101
chunk_init_fragments.insert(
102102
0,
103103
Box::new(rspack_core::NormalInitFragment::new(
104-
format!("{}\n", hashbang),
104+
format!("{hashbang}\n"),
105105
rspack_core::InitFragmentStage::StageConstants,
106106
i32::MIN,
107107
rspack_core::InitFragmentKey::unique(),
@@ -117,7 +117,7 @@ impl EsmLibraryPlugin {
117117
chunk_init_fragments.insert(
118118
insert_pos,
119119
Box::new(rspack_core::NormalInitFragment::new(
120-
format!("{}\n", directive),
120+
format!("{directive}\n"),
121121
rspack_core::InitFragmentStage::StageConstants,
122122
i32::MIN + 1 + idx as i32,
123123
rspack_core::InitFragmentKey::unique(),

crates/rspack_plugin_rslib/src/plugin.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::{
44
};
55

66
use 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
};
1212
use 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+
182207
impl 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

Comments
 (0)