a factory function that returns a general purpose path resolver function for your esbuild plugin, tuned to your specific config.

given a certain esbuild esbuild.OnResolveArgs | args, and your expected resolved esbuild.OnResolveResult | result here is what the returned resolver function takes care of:

  1. figure out the absolute resolved result.path:
  • if args.parse is an absolute path (i.e. when config.isAbsolutePath(args.parse) === true), then it will be returned as is.
  • if args.parse is a relative path (i.e. when config.isAbsolutePath(args.parse) === false), then:
    • we figure out the absolute parent directory dir, by:
      • joining args.importer with args.resolveDir (via config.resolvePath) if args.importer is not absolute.
      • otherwise set dir to args.importer if it is absolute.
    • join dir with args.parse using config.resolvePath and return it as result.path.
  1. take care of namespace:
  • set result.namespace to config.namespace
  • backup the original namespace args.namespace to config.pluginData.originalNamespace
  1. inherit import maps from plugin data:
  • set result.pluginData.importMap to args.pluginData.importMap (which is originally set by the loaders of our typical plugin)