resolve a path_alias to its absolutely referenced path from an import map entries.
if the input path_alias is not a part of the provided import_map_entries, then undefined will be returned.
for further reading on the specifics of what constitutes an import-map, see the documentation of ImportMap.
this function has the potential to be faster if you provide pre-sorted import_map_entries,
in addition to also providing configuration options for relative paths.
to understand how configure the behavior of the resolver differently, using the optional config parameter,
check out the documentation comments of ResolvePathFromImportMapEntriesConfig.
but for a summary, here is the breakdown:
config.baseAliasDir: if defined (non-empty string),
then the given base directory path will be prepended to all relative path-aliases of your import map entries.
however, this will not affect any path-aliases that do not begin with a "./" (i.e. non-relative path-aliases).
config.basePathDir: if defined (non-empty string),
then the given base directory path will be prepended to the resolved matching path-value
if it is a relative path (which is checked via isAbsolutePath).
config.sort: specify true (default behavior) if your input import_map_entries is not already sorted alias-length-wise.
it is necessary for the import_map_entries to be sorted for the import-map specification-compliant match to be selected.
so, if your import map entries are pre-sorted, you can save time by setting this option to false.
config.errorCheck: if a path-value match is found for some path_alias, however the alias-path of the entry is directory,
but the corresponding path-value is not a directory (i.e. does not end in "/"), then an error will be thrown.
resolve a
path_alias
to its absolutely referenced path from an import map entries. if the inputpath_alias
is not a part of the providedimport_map_entries
, thenundefined
will be returned.for further reading on the specifics of what constitutes an import-map, see the documentation of ImportMap.
why use this function when resolvePathFromImportMap exists?
this function has the potential to be faster if you provide pre-sorted
import_map_entries
, in addition to also providing configuration options for relative paths.to understand how configure the behavior of the resolver differently, using the optional
config
parameter, check out the documentation comments of ResolvePathFromImportMapEntriesConfig. but for a summary, here is the breakdown:config.baseAliasDir
: if defined (non-empty string), then the given base directory path will be prepended to all relative path-aliases of your import map entries. however, this will not affect any path-aliases that do not begin with a"./"
(i.e. non-relative path-aliases).config.basePathDir
: if defined (non-empty string), then the given base directory path will be prepended to the resolved matching path-value if it is a relative path (which is checked via isAbsolutePath).config.sort
: specifytrue
(default behavior) if your inputimport_map_entries
is not already sorted alias-length-wise. it is necessary for theimport_map_entries
to be sorted for the import-map specification-compliant match to be selected. so, if your import map entries are pre-sorted, you can save time by setting this option tofalse
.config.errorCheck
: if a path-value match is found for somepath_alias
, however the alias-path of the entry is directory, but the corresponding path-value is not a directory (i.e. does not end in "/"), then an error will be thrown.Example