code: def to_single_stage_lockfile(stage: "Stage", **kwargs) -> dict:
      from dvc.cachemgr import LEGACY_HASH_NAMES
      from dvc.output import (
          _serialize_hi_to_dict,
          _serialize_tree_obj_to_files,
          split_file_meta_from_cloud,
      )
      from dvc_data.hashfile.tree import Tree
  
      assert stage.cmd
  
      def _dumpd(item: "Output"):
          ret: Dict[str, Any] = {item.PARAM_PATH: item.def_path}
          if item.hash_name not in LEGACY_HASH_NAMES:
              ret[item.PARAM_HASH] = "md5"
          if item.hash_info.isdir and kwargs.get("with_files"):
              obj = item.obj or item.get_obj()
              if obj:
                  assert isinstance(obj, Tree)
                  ret[item.PARAM_FILES] = [
                      split_file_meta_from_cloud(f)
                      for f in _serialize_tree_obj_to_files(obj)
                  ]
          else:
              meta_d = item.meta.to_dict()
              meta_d.pop("isdir", None)
              ret.update(_serialize_hi_to_dict(item.hash_info))
              ret.update(split_file_meta_from_cloud(meta_d))
          return ret
  
      res = OrderedDict([("cmd", stage.cmd)])
      params, deps = split_params_deps(stage)
      deps, outs = (
          [
              _dumpd(item)
              for item in sorted(items, key=attrgetter("def_path"))
          ]
          for items in [deps, stage.outs]
      )
      params = _serialize_params_values(params)
      if deps:
          res[PARAM_DEPS] = deps
      if params:
          res[PARAM_PARAMS] = params
      if outs:
          res[PARAM_OUTS] = outs
  
      return res
  
file_path: dvc/dvc/stage/serialize.py
imports: from collections import OrderedDict
  from operator import attrgetter
  from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Union, no_type_check
  from funcy import post_processing
  from dvc.dependency import ParamsDependency
  from dvc.output import Annotation, Output
  from dvc.utils.collections import apply_diff
  from dvc.utils.serialize import parse_yaml_for_update
  from .params import StageParams
  from .utils import resolve_wdir, split_params_deps
label_desc: Use image node_id 7 for calling a global function with example usage: to_single_stage_lockfile(stage) and returns: res, ret