1919
2020
2121class Yarn (Npm ):
22-
22+
2323 def __init__ (self , input_dir , output_dir ):
2424 super ().__init__ (input_dir , output_dir )
2525 self .package_manager_name = const .YARN
2626 self .yarn_version = None
27-
27+
2828 def detect_yarn_version (self ):
2929 """Detect Yarn version (1.x = Classic, 2+ = Berry)"""
3030 if self .yarn_version is not None :
3131 return self .yarn_version
32-
32+
3333 try :
3434 result = subprocess .run ('yarn -v' , shell = True , capture_output = True , text = True , encoding = 'utf-8' )
3535 if result .returncode == 0 :
@@ -47,32 +47,30 @@ def start_license_checker(self):
4747 license_checker_cmd = f'license-checker --production --json --out { self .input_file_name } '
4848 custom_path_option = ' --customPath '
4949 node_modules = 'node_modules'
50-
51- # Detect Yarn version
50+
5251 self .detect_yarn_version ()
53-
52+
5453 # For Yarn Berry (2+), check if using PnP mode
5554 is_pnp_mode = False
5655 if self .yarn_version and self .yarn_version >= 2 :
5756 # Check if .pnp.cjs exists (PnP mode indicator)
5857 if os .path .exists ('.pnp.cjs' ) or os .path .exists ('.pnp.js' ):
5958 is_pnp_mode = True
6059 logger .info ("Detected Yarn Berry with PnP mode" )
61-
60+
6261 if not os .path .isdir (node_modules ):
63- logger .info (f "node_modules directory does not exist." )
62+ logger .info ("node_modules directory does not exist." )
6463 self .flag_tmp_node_modules = True
65-
64+
6665 # For PnP mode, try to force node_modules creation
6766 if is_pnp_mode :
6867 logger .info ("Attempting to create node_modules for PnP project..." )
69- # Try setting nodeLinker to node-modules temporarily
7068 yarn_install_cmd = 'YARN_NODE_LINKER=node-modules yarn install --production --ignore-scripts'
7169 logger .info (f"Executing: { yarn_install_cmd } " )
7270 else :
7371 yarn_install_cmd = 'yarn install --production --ignore-scripts'
7472 logger .info (f"Executing: { yarn_install_cmd } " )
75-
73+
7674 cmd_ret = subprocess .call (yarn_install_cmd , shell = True )
7775 if cmd_ret != 0 :
7876 logger .error (f"{ yarn_install_cmd } failed" )
0 commit comments