1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
# Copyright 2023 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")
template("bundle_js") {
node(target_name) {
script = "//ui/webui/resources/tools/bundle_js.py"
forward_variables_from(invoker,
[
"visibility",
"deps",
])
# This depfile is generated by bundle_js.py
depfile = "${target_gen_dir}/${target_name}.d"
out_folder = target_gen_dir
if (defined(invoker.out_folder)) {
out_folder = invoker.out_folder
}
outputs = []
input_count = 0
foreach(f, invoker.js_module_in_files) {
assert(get_path_info(f, "extension") == "js")
bundle_path = get_path_info(f, "dir")
input_count = input_count + 1
out_file = string_replace(get_path_info(f, "file"), ".js", ".rollup.js")
outputs += [
"$out_folder/$bundle_path/$out_file",
"$out_folder/$bundle_path/${out_file}.map",
]
if (input_count == 2) {
outputs += [
"$out_folder/$bundle_path/shared.rollup.js",
"$out_folder/$bundle_path/shared.rollup.js.map",
]
}
}
outputs += [ "$out_folder/${target_name}_requestlist.txt" ]
# Note that we have to manually pass the sources to our script if the
# script needs them as inputs.
args = [
"--host",
invoker.host,
"--input",
invoker.input,
"--out_folder",
rebase_path(out_folder, root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
"--target_name",
target_name,
]
inputs = []
if (defined(invoker.rollup_config)) {
inputs += [ invoker.rollup_config ]
args += [
"--rollup_config",
rebase_path(invoker.rollup_config, root_build_dir),
]
} else {
inputs += [ "//ui/webui/resources/tools/rollup_plugin.mjs" ]
outputs += [ "$out_folder/rollup.config.mjs" ]
}
if (defined(invoker.excludes)) {
args += [ "--exclude" ] + invoker.excludes
}
external_paths = []
# Add invoker.external_paths before the default external_paths so that they
# are considered first.
if (defined(invoker.external_paths)) {
external_paths += invoker.external_paths
}
# Specify default external_paths. The order here matters in multiple ways.
# 1) chrome:// URLs need to be listed before scheme relative URLs
# (otherwise chrome-extension:// contexts break)
# 2) Longer prefixes need to be listed before shorter prefixes, otherwise
# mappings are incorrect.
# 3) chrome:// URLs should not be listed at all for chrome-untrusted://
# contexts, otherwise generated bundle includes chrome:// URLs which is
# incorrect.
polymer_path =
rebase_path("//third_party/polymer/v3_0/components-chromium/",
root_build_dir)
resources_path =
rebase_path("$root_gen_dir/ui/webui/resources/tsc/", root_build_dir)
is_chrome_untrusted =
string_replace(invoker.host, "chrome-untrusted://", "") != invoker.host
if (is_chromeos) {
ash_resources_path =
rebase_path("$root_gen_dir/ash/webui/common/resources/preprocessed/",
root_build_dir)
if (!is_chrome_untrusted) {
external_paths +=
[ "chrome://resources/ash/common/|$ash_resources_path" ]
}
external_paths += [ "//resources/ash/common/|$ash_resources_path" ]
}
if (!is_chrome_untrusted) {
external_paths += [ "chrome://resources/polymer/v3_0/|$polymer_path" ]
}
external_paths += [ "//resources/polymer/v3_0/|$polymer_path" ]
lit_path = rebase_path("${root_gen_dir}/third_party/lit/v3_0/minified/",
root_build_dir)
if (!is_chrome_untrusted) {
external_paths += [ "chrome://resources/lit/v3_0/|$lit_path" ]
}
external_paths += [ "//resources/lit/v3_0/|$lit_path" ]
if (!is_chrome_untrusted) {
external_paths += [ "chrome://resources/|$resources_path" ]
}
external_paths += [ "//resources/|$resources_path" ]
args += [ "--external_paths" ] + external_paths
args += [ "--js_module_in_files" ] + invoker.js_module_in_files
if (defined(invoker.out_manifest)) {
args += [
"--out-manifest",
rebase_path(invoker.out_manifest, root_build_dir),
]
outputs += [ invoker.out_manifest ]
}
}
}
|