common.mk 1.0 KB

1234567891011121314151617181920212223242526272829
  1. # Copyright (c) Facebook, Inc. and its affiliates.
  2. #
  3. # This source code is licensed under the MIT license found in the
  4. # LICENSE file in the root directory of this source tree.
  5. ##
  6. # Returns the absolute path to the specified npm package, searching from the
  7. # given base directory. This function uses Node's module resolution algorithm
  8. # searching "node_modules" in the base directory and its ancestors. If no
  9. # matching package is found, this function returns an empty string.
  10. #
  11. # The first argument to this function is the base directory from which to begin
  12. # searching. The second argument is the name of the npm package.
  13. #
  14. # Ex: $(call find-node-module,$(LOCAL_PATH),hermes-engine)
  15. ###
  16. define find-node-module
  17. $(strip \
  18. $(eval _base := $(strip $(1))) \
  19. $(eval _package := $(strip $(2))) \
  20. $(eval _candidate := $(abspath $(_base)/node_modules/$(_package))) \
  21. $(if $(realpath $(_candidate)), \
  22. $(_candidate), \
  23. $(if $(_base), \
  24. $(call find-node-module,$(patsubst %/,%,$(dir $(_base))),$(_package)) \
  25. ) \
  26. ) \
  27. )
  28. endef