specifierOf

tcmts.cli.mirror.specifierOf · #dirpt4df · term · runs anywhere

How a module is imported, for an import tcm adds: node:fs, react/jsx-runtime, #tcm/host.

import { tcmModule } from "#codebase/tcmts/core/types";
import type { ExtRef } from "#codebase/tcmts/core/types";

export function specifierOf(ext: ExtRef): string {
  const own = tcmModule(ext.module);
  if (own) return own.spec;
  const npm = /^npm:(.+)@[^@]+$/.exec(ext.module);
  const base = npm ? npm[1]! : ext.module;
  return ext.subpath ? `${base}/${ext.subpath}` : base;
}

uses

used by