code: def _bundle_models(custom_models: dict[str, CustomModel]) -> str:
      """Create a JavaScript bundle with selected `models`."""
      exports = []
      modules = []
  
      lib_dir = Path(bokehjs_dir) / "js" / "lib"
      known_modules: set[str] = set()
  
      for path in lib_dir.rglob("*.d.ts"):
          s = str(path.relative_to(lib_dir))
          if s.endswith(".d.ts"):
              s = s[:-5]  # TODO: removesuffix() (Py 3.9+)
          s = s.replace(os.path.sep, "/")
          known_modules.add(s)
  
      custom_impls = _compile_models(custom_models)
  
      extra_modules = {}
  
      def resolve_modules(
          to_resolve: set[str], root: str
      ) -> dict[str, str]:
          resolved = {}
          for module in to_resolve:
              if module.startswith(("./", "../")):
  
                  def mkpath(module: str, ext: str = "") -> str:
                      return abspath(
                          join(root, *module.split("/")) + ext
                      )
  
                  if module.endswith(exts):
                      path = mkpath(module)
                      if not exists(path):
                          raise RuntimeError(
                              "no such module: %s" % module
                          )
                  else:
                      for ext in exts:
                          path = mkpath(module, ext)
                          if exists(path):
                              break
                      else:
                          raise RuntimeError(
                              "no such module: %s" % module
                          )
  
                  impl = FromFile(path)
                  compiled = nodejs_compile(
                      impl.code, lang=impl.lang, file=impl.file
                  )
  
                  if impl.lang == "less":
                      code = _style_template % dict(
                          css=json.dumps(compiled.code)
                      )
                      deps = []
                  else:
                      code = compiled.code
                      deps = compiled.deps
  
                  sig = hashlib.sha256(code.encode("utf-8")).hexdigest()
                  resolved[module] = sig
  
                  deps_map = resolve_deps(deps, dirname(path))
  
                  if sig not in extra_modules:
                      extra_modules[sig] = True
                      modules.append((sig, code, deps_map))
              else:
                  index = (
                      module
                      + ("" if module.endswith("/") else "/")
                      + "index"
                  )
                  if index not in known_modules:
                      raise RuntimeError("no such module: %s" % module)
  
          return resolved
  
      def resolve_deps(deps: list[str], root: str) -> dict[str, str]:
          custom_modules = {
              model.module for model in custom_models.values()
          }
          missing = set(deps) - known_modules - custom_modules
          return resolve_modules(missing, root)
  
      for model in custom_models.values():
          compiled = custom_impls[model.full_name]
          deps_map = resolve_deps(compiled.deps, model.path)
  
          exports.append((model.name, model.module))
          modules.append((model.module, compiled.code, deps_map))
  
      # sort everything by module name
      exports = sorted(exports, key=lambda spec: spec[1])
      modules = sorted(modules, key=lambda spec: spec[0])
  
      bare_modules = []
      for i, (module, code, deps) in enumerate(modules):
          for name, ref in deps.items():
              code = code.replace(
                  """require("%s")""" % name, """require("%s")""" % ref
              )
              code = code.replace(
                  """require('%s')""" % name, """require('%s')""" % ref
              )
          bare_modules.append((module, code))
  
      sep = ",\n"
  
      rendered_exports = sep.join(
          _export_template % dict(name=name, module=module)
          for (name, module) in exports
      )
      rendered_modules = sep.join(
          _module_template % dict(module=module, source=code)
          for (module, code) in bare_modules
      )
  
      content = _plugin_template % dict(
          prelude=_plugin_prelude,
          exports=rendered_exports,
          modules=rendered_modules,
      )
      return _plugin_umd % dict(content=content)
  
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 20 for calling a global function with example usage: _bundle_models(custom_models) and returns: unknown, resolved, resolve_modules, abspath