Skip to content

Commit

Permalink
feature: bundle=false support
Browse files Browse the repository at this point in the history
  • Loading branch information
josephglanville committed Nov 17, 2022
1 parent 49342d1 commit fe693f7
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions esbuild/private/esbuild.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ edge16, node10, esnext). Default es2015.
See https://esbuild.github.io/api/#target for more details
""",
),
"bundle": attr.bool(
default = True,
doc = """If true, esbuild will bundle the input files, inlining their dependencies recursively"""
),
"config": attr.label(
mandatory = False,
allow_single_file = True,
Expand All @@ -172,7 +176,7 @@ def _esbuild_impl(ctx):
entry_points = desugar_entry_point_names(ctx.file.entry_point, ctx.files.entry_points)

args = dict({
"bundle": True,
"bundle": ctx.attr.bundle,
"define": dict([
[
k,
Expand Down Expand Up @@ -249,6 +253,7 @@ def _esbuild_impl(ctx):

args.update({"outfile": js_out.short_path})


env = {
"BAZEL_BINDIR": ctx.bin_dir.path,
"ESBUILD_BINARY_PATH": "../../../" + esbuild_toolinfo.target_tool_path,
Expand Down Expand Up @@ -318,6 +323,18 @@ def _esbuild_impl(ctx):
executable = launcher,
)

output_sources_depset = depset(output_sources)

transitive_sources = js_lib_helpers.gather_transitive_sources(
sources = output_sources_depset,
targets = ctx.attr.srcs,
)

transitive_declarations = js_lib_helpers.gather_transitive_declarations(
declarations = [],
targets = ctx.attr.srcs,
)

npm_linked_packages = js_lib_helpers.gather_npm_linked_packages(
srcs = ctx.attr.srcs,
deps = [],
Expand All @@ -327,14 +344,12 @@ def _esbuild_impl(ctx):
targets = ctx.attr.data,
)

output_sources_depset = depset(output_sources)

runfiles = js_lib_helpers.gather_runfiles(
ctx = ctx,
sources = output_sources_depset,
data = ctx.attr.data,
# Since we're bundling, we don't propogate any transitive runfiles from dependencies
deps = [],
# Don't include transitive runfiles when bundling
deps = [] if ctx.attr.bundle else ctx.attr.srcs,
)

return [
Expand All @@ -347,15 +362,16 @@ def _esbuild_impl(ctx):
npm_linked_packages = npm_linked_packages.direct,
npm_package_store_deps = npm_package_store_deps,
sources = output_sources_depset,
# Since we're bundling, we don't propogate linked npm packages from dependencies since
# If we're bundling, we don't propogate linked npm packages from dependencies since
# they are bundled and the dependencies are dropped. If a subset of linked npm
# dependencies are not bundled it is up the the user to re-specify these in `data` if
# they are runtime dependencies to progagate to binary rules or `srcs` if they are to be
# propagated to downstream build targets.
transitive_npm_linked_package_files = npm_linked_packages.direct_files,
transitive_npm_linked_packages = npm_linked_packages.direct,
# Since we're bundling, we don't propogate any transitive sources from dependencies
transitive_sources = output_sources_depset,
transitive_npm_linked_package_files = npm_linked_packages.direct_files if ctx.attr.bundle else npm_linked_packages.transitive_files,
transitive_npm_linked_packages = npm_linked_packages.direct if ctx.attr.bundle else npm_linked_packages.transitive,
# If we're bundling, we don't propogate any transitive sources from dependencies
transitive_sources = output_sources_depset if ctx.attr.bundle else transitive_sources,
transitive_declarations = depset() if ctx.attr.bundle else transitive_declarations
),
]

Expand Down

0 comments on commit fe693f7

Please sign in to comment.