@@ -559,6 +559,54 @@ def ensure_css_node_modules() -> None:
559559 log .debug ("" , exc_info = True )
560560
561561
562+ def ensure_dynsub_node_modules () -> None :
563+ # Look for node_modules and install if we can.
564+ with working_directory (
565+ resources .resource_base_path () / "core" / "script" / "dynsub"
566+ ):
567+ # Make sure node version is at least 22.10:
568+ try :
569+ node_cmd = shutil .which ("node" )
570+ if node_cmd is None :
571+ log .warning (
572+ "Node.js must be installed to extract dynamic substitutions. Please install node.js and npm."
573+ )
574+ raise FileNotFoundError
575+ node_version = subprocess .run ([node_cmd , "-v" ], capture_output = True )
576+ log .debug (f"Node version: { node_version .stdout .decode ()} " )
577+ node_version_decode = node_version .stdout .decode ().split ("." )
578+ main_version = int (node_version_decode [0 ][1 :])
579+ sub_version = int (node_version_decode [1 ])
580+ if main_version < 22 | (main_version == 22 and sub_version < 10 ):
581+ log .warning (
582+ "Node version must be at least 22.10 to extract dynamic substitutions. Please update node.js and npm."
583+ )
584+ return
585+ except Exception as e :
586+ log .debug (e )
587+ log .debug ("" , exc_info = True )
588+ # Check if node_modules is already present:
589+ if Path ("node_modules" ).exists ():
590+ log .debug ("Node modules already installed." )
591+ return
592+ # If not, try to install them:
593+ log .debug (
594+ "Attempting to install/update required node packages extract dynamic susbstitutions."
595+ )
596+ try :
597+ npm_cmd = shutil .which ("npm" )
598+ if npm_cmd is None :
599+ log .warning ("Cannot find npm. Install npm and try again." )
600+ raise FileNotFoundError
601+ subprocess .run ([npm_cmd , "install" ])
602+ except Exception as e :
603+ log .warning (
604+ "Unable to install npm packages. Unable to extract dynamic substitutions."
605+ )
606+ log .warning (e )
607+ log .debug ("" , exc_info = True )
608+
609+
562610def playwright_install () -> None :
563611 """
564612 Run `playwright install` to ensure that its required browsers and tools are available to it.
0 commit comments