@@ -205,59 +205,61 @@ impl LinkerPipe {
205205 artifact : & ResolvedArtifact ,
206206 node_modules_dir : & std:: path:: Path ,
207207 ) -> Result < ( ) > {
208- if let Some ( pkg_json) = & artifact. package {
209- if let Some ( bin) = & pkg_json. bin {
210- let bin_dir = node_modules_dir. join ( ".bin" ) ;
211- fs:: create_dir_all ( & bin_dir) . await ?;
212-
213- let bins = match bin {
214- PackageBin :: String ( path) => {
215- let mut map = HashMap :: new ( ) ;
216- map. insert ( artifact. name . clone ( ) , path. clone ( ) ) ;
217- map
218- }
219- PackageBin :: Map ( map) => map. clone ( ) ,
220- } ;
208+ if artifact. package . is_none ( ) {
209+ return Ok ( ( ) ) ;
210+ }
211+ let pkg_json = artifact. package . as_ref ( ) . expect ( "package is not present" ) ;
212+ if let Some ( bin) = & pkg_json. bin {
213+ let bin_dir = node_modules_dir. join ( ".bin" ) ;
214+ fs:: create_dir_all ( & bin_dir) . await ?;
215+
216+ let bins = match bin {
217+ PackageBin :: String ( path) => {
218+ let mut map = HashMap :: new ( ) ;
219+ map. insert ( artifact. name . clone ( ) , path. clone ( ) ) ;
220+ map
221+ }
222+ PackageBin :: Map ( map) => map. clone ( ) ,
223+ } ;
221224
222- for ( bin_name, bin_path) in bins {
223- let target_path = bin_dir. join ( & bin_name) ;
225+ for ( bin_name, bin_path) in bins {
226+ let target_path = bin_dir. join ( & bin_name) ;
224227
225- // The path to the script relative to the package root
226- // We need to link to node_modules/<package_name>/<bin_path>
227- // But since we are in node_modules/.bin, the relative path is ../<package_name>/<bin_path>
228+ // The path to the script relative to the package root
229+ // We need to link to node_modules/<package_name>/<bin_path>
230+ // But since we are in node_modules/.bin, the relative path is ../<package_name>/<bin_path>
228231
229- let package_dir = node_modules_dir. join ( & artifact. name ) ;
230- let source_path = package_dir. join ( & bin_path) ;
232+ let package_dir = node_modules_dir. join ( & artifact. name ) ;
233+ let source_path = package_dir. join ( & bin_path) ;
231234
232- // Remove existing link if exists
233- if target_path. exists ( ) {
234- if target_path. is_symlink ( ) {
235- fs:: remove_file ( & target_path) . await ?;
236- } else {
237- fs:: remove_dir_all ( & target_path) . await ?;
238- }
235+ // Remove existing link if exists
236+ if target_path. exists ( ) {
237+ if target_path. is_symlink ( ) {
238+ fs:: remove_file ( & target_path) . await ?;
239+ } else {
240+ fs:: remove_dir_all ( & target_path) . await ?;
239241 }
242+ }
240243
241- #[ cfg( unix) ]
242- {
243- tokio:: fs:: symlink ( & source_path, & target_path) . await ?;
244+ #[ cfg( unix) ]
245+ {
246+ tokio:: fs:: symlink ( & source_path, & target_path) . await ?;
244247
245- // Make executable
246- use std:: os:: unix:: fs:: PermissionsExt ;
247- if let Ok ( metadata) = fs:: metadata ( & source_path) . await {
248- let mut perms = metadata. permissions ( ) ;
249- perms. set_mode ( 0o755 ) ;
250- let _ = fs:: set_permissions ( & source_path, perms) . await ;
251- }
252- }
253- #[ cfg( windows) ]
254- {
255- // On Windows we might need a shim, but for now let's try symlink
256- tokio:: fs:: symlink_file ( & source_path, & target_path) . await ?;
248+ // Make executable
249+ use std:: os:: unix:: fs:: PermissionsExt ;
250+ if let Ok ( metadata) = fs:: metadata ( & source_path) . await {
251+ let mut perms = metadata. permissions ( ) ;
252+ perms. set_mode ( 0o755 ) ;
253+ let _ = fs:: set_permissions ( & source_path, perms) . await ;
257254 }
258-
259- debug:: info!( "Linked bin {} -> {:?}" , bin_name, source_path) ;
260255 }
256+ #[ cfg( windows) ]
257+ {
258+ // On Windows we might need a shim, but for now let's try symlink
259+ tokio:: fs:: symlink_file ( & source_path, & target_path) . await ?;
260+ }
261+
262+ debug:: info!( "Linked bin {} -> {:?}" , bin_name, source_path) ;
261263 }
262264 }
263265 Ok ( ( ) )
0 commit comments