# Copyright 2021 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/node/node.gni")
# Rewrites the imports specified in `import_mappings`. Only exact import matches
# will be replaced.
# TODO(crbug.com/1320176): Consider integrating this functionality into
# ts_library.gni.
template("rewrite_imports") {
node(target_name) {
script = "//third_party/material_web_components/rewrite_imports.py"
manifest_out = "${target_gen_dir}/${target_name}.manifest"
forward_variables_from(invoker,
[
"deps",
"base_dir",
"out_dir",
"in_files",
"testonly",
])
inputs = []
outputs = [ manifest_out ]
foreach(_file, in_files) {
inputs += [ "${base_dir}/${_file}" ]
outputs += [ "${out_dir}/${_file}" ]
}
import_mappings = [ "tslib|//resources/mwc/tslib/tslib.js" ]
if (defined(invoker.import_mappings)) {
import_mappings += invoker.import_mappings
}
import_var_mappings = []
if (defined(invoker.import_var_mappings)) {
import_var_mappings += invoker.import_var_mappings
}
args = [ "--in_files" ] + in_files
args += [
"--base_dir",
rebase_path(base_dir, root_build_dir),
]
args += [
"--out_dir",
rebase_path(out_dir, root_build_dir),
]
args += [
"--manifest_out",
rebase_path(manifest_out, root_build_dir),
]
args += [ "--import_mappings" ] + import_mappings
args += [ "--import_var_mappings" ] + import_var_mappings
}
}