rewrite_imports.gni 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright 2021 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import("//third_party/node/node.gni")
  5. # Rewrites the imports specified in `import_mappings`. Only exact import matches
  6. # will be replaced.
  7. # TODO(crbug.com/1320176): Consider integrating this functionality into
  8. # ts_library.gni.
  9. template("rewrite_imports") {
  10. node(target_name) {
  11. script = "//third_party/material_web_components/rewrite_imports.py"
  12. forward_variables_from(invoker,
  13. [
  14. "deps",
  15. "import_mappings",
  16. ])
  17. inputs = []
  18. outputs = []
  19. foreach(_dep, deps) {
  20. foreach(_output, filter_include(get_target_outputs(_dep), [ "*.js" ])) {
  21. inputs += [ _output ]
  22. outputs += [ "$target_gen_dir/" + get_path_info(_output, "file") ]
  23. }
  24. }
  25. import_mappings = [ "tslib|//resources/mwc/tslib/tslib.js" ]
  26. if (defined(invoker.import_mappings)) {
  27. import_mappings += invoker.import_mappings
  28. }
  29. args = [ "--in_files" ] + rebase_path(inputs, root_build_dir)
  30. args += [
  31. "--out_dir",
  32. rebase_path(target_gen_dir, root_build_dir),
  33. ]
  34. args += [ "--import_mappings" ] + import_mappings
  35. }
  36. }