8 – How can I get a custom module’s file path in a preprocess function?

Drupal 8 still has drupal_get_path(), which is used from Drupal core modules and third-party modules for the path of files contained in modules directories. (See the code for ckeditor_ckeditor_css_alter() or the example code given in hook_js_alter().

function hook_js_alter(&$javascript, DrupalCoreAssetAttachedAssetsInterface $assets) {
  $javascript('core/assets/vendor/jquery/jquery.min.js')('data') = drupal_get_path('module', 'jquery_update') . '/jquery.js';
}

Deprecate drupal_get_path() and drupal_get_filename() and replace with ExtensionList::getPath() and ExtensionList::getPathname() aims to deprecate the function.
At the moment I am writing this answer, its status is still Needs work (for Drupal 9.3.x). When it’s marked as fixed, instead of drupal_get_path('module', $module_name), modules will use Drupal::service('extension.list.module')->getPath($module_name).

For example, the previous example hook could be rewritten in this way.

function hook_js_alter(&$javascript, DrupalCoreAssetAttachedAssetsInterface $assets) {
  $javascript('core/assets/vendor/jquery/jquery.min.js')('data') = Drupal::service('extension.list.module')->getPath('jquery_update') . '/jquery.js';
}

Alternatively, Drupal::service('extension.path.resolver')->getPath('module', $module_name) could be used, which is what drupal_get_path() and drupal_get_filename() have been deprecated in favor of extension listing services suggests to use in the case the extension type is dynamically specified.