function getPackageNameForModulePath(canonicalNameMap, modulePath) {
  const packageDir = getPackageDirForModulePath(canonicalNameMap, modulePath)
  if (packageDir === undefined) {
    const relativeToRoot = path.relative(canonicalNameMap.rootDir, modulePath)
    return `external:${relativeToRoot}`
  }
  const packageName = /** @type {string} */ (canonicalNameMap.get(packageDir))
  const relativeToPackageDir = path.relative(packageDir, modulePath)
  // files should never be associated with a package directory across a package boundary (as tested via the presense of "node_modules" in the path)
  if (relativeToPackageDir.includes('node_modules')) {
    throw new Error(
      `LavaMoat - Encountered unknown package directory "${relativeToPackageDir}" for file "${modulePath}"`
    )
  }
  return packageName
}
@param {CanonicalNameMap} canonicalNameMap
@param {string} modulePath
@returns {string}