code: def _compile_models(
      custom_models: dict[str, CustomModel]
  ) -> dict[str, AttrDict]:
      """Returns the compiled implementation of supplied `models`."""
      ordered_models = sorted(
          custom_models.values(), key=lambda model: model.full_name
      )
      custom_impls = {}
  
      dependencies: list[tuple[str, str]] = []
      for model in ordered_models:
          dependencies.extend(list(model.dependencies.items()))
  
      if dependencies:
          dependencies = sorted(
              dependencies, key=lambda name_version: name_version[0]
          )
          _run_npmjs(
              ["install", "--no-progress"]
              + [
                  name + "@" + version
                  for (name, version) in dependencies
              ]
          )
  
      for model in ordered_models:
          impl = model.implementation
          compiled = _CACHING_IMPLEMENTATION(model, impl)
          if compiled is None:
              compiled = nodejs_compile(
                  impl.code, lang=impl.lang, file=impl.file
              )
              if "error" in compiled:
                  raise CompilationError(compiled.error)
  
          custom_impls[model.full_name] = compiled
  
      return custom_impls
  
imports: from __future__ import annotations
  import logging
  import hashlib
  import json
  import os
  import re
  import sys
  from os.path import abspath, dirname, exists, isabs, join
  from pathlib import Path
  from subprocess import PIPE, Popen
  from typing import Any, Callable, Sequence
  from ..core.has_props import HasProps
  from ..settings import settings
  from .strings import snakify
label_desc: Use image node_id 19 for calling a global function with example usage: _compile_models(custom_models) and returns: custom_impls