Repository: denoland/deno
File: cli/lib/worker.rs (Rust)

Code before:
  #[inline]
  pub fn dispatch_process_exit_event(&mut self) -> Result<(), Box<JsError>> {
    self.worker.dispatch_process_exit_event()
  }

  pub async fn execute_main_module(&mut self) -> Result<(), CoreError> {
    let id = self.worker.preload_main_module(&self.main_module).await?;
    self.worker.evaluate_module(id).await
  }

  pub async fn execute_side_module(&mut self) -> Result<(), CoreError> {
    let id = self.worker.preload_side_module(&self.main_module).await?;
    self.worker.evaluate_module(id).await
  }

  pub async fn execute_preload_modules(&mut self) -> Result<(), CoreError> {
    for preload_module_url in self.preload_modules.iter() {
      let id = self.worker.preload_side_module(preload_module_url).await?;
      self.worker.evaluate_module(id).await?;
      self.worker.run_event_loop(false).await?;
    }
    for require_module_url in self.require_modules.iter() {
      let id = self.worker.preload_side_module(require_module_url).await?;
      self.worker.evaluate_module(id).await?;
      self.worker.run_event_loop(false).await?;
    }
    Ok(())
  }

  pub async fn run(&mut self) -> Result<i32, CoreError> {
    log::debug!("main_module {}", self.main_module);

    // Run preload modules first if they were defined
    self.execute_preload_modules().await?;

    self.execute_main_module().await?;
    self.worker.dispatch_load_event()?;

    loop {
      self
        .worker
        .run_event_loop(/* wait for inspector */ false)
        .await?;

      let web_continue = self.worker.dispatch_beforeunload_event()?;
      if !web_continue {
        let node_continue = self.worker.dispatch_process_beforeexit_event()?;
        if !node_continue {
          break;
        }
      }

Review comment (suggestion):
This is really confusing me still 😬 can you add a comment here, that says something like - "even though we load as ESM here, these files will be forced to be loaded as CJS because of checks in `get_known_mode_with_is_script`"

Code after:

  #[inline]
  pub fn dispatch_process_exit_event(&mut self) -> Result<(), Box<JsError>> {
    self.worker.dispatch_process_exit_event()
  }

  pub async fn execute_main_module(&mut self) -> Result<(), CoreError> {
    let id = self.worker.preload_main_module(&self.main_module).await?;
    self.worker.evaluate_module(id).await
  }

  pub async fn execute_side_module(&mut self) -> Result<(), CoreError> {
    let id = self.worker.preload_side_module(&self.main_module).await?;
    self.worker.evaluate_module(id).await
  }

  pub async fn execute_preload_modules(&mut self) -> Result<(), CoreError> {
    for preload_module_url in self.preload_modules.iter() {
      let id = self.worker.preload_side_module(preload_module_url).await?;
      self.worker.evaluate_module(id).await?;
      self.worker.run_event_loop(false).await?;
    }
    // Even though we load as ESM here, these files will be forced to be loaded as CJS
    // because of checks in get_known_mode_with_is_script
    for require_module_url in self.require_modules.iter() {
      let id = self.worker.preload_side_module(require_module_url).await?;
      self.worker.evaluate_module(id).await?;
      self.worker.run_event_loop(false).await?;
    }
    Ok(())
  }

  pub async fn run(&mut self) -> Result<i32, CoreError> {
    log::debug!("main_module {}", self.main_module);

    // Run preload modules first if they were defined
    self.execute_preload_modules().await?;

    self.execute_main_module().await?;
    self.worker.dispatch_load_event()?;

    loop {
      self
        .worker
        .run_event_loop(/* wait for inspector */ false)
        .await?;

      let web_continue = self.worker.dispatch_beforeunload_event()?;
      if !web_continue {
        let node_continue = self.worker.dispatch_process_beforeexit_event()?;
        if !node_continue {