Skip to content

Commit dd4c4f3

Browse files
authored
fix(esbuild): prefer finding entry_point files in deps rather than srcs (#2692)
When using esbuild with `js_library`, the entry_point may be part of the deps, therefore the path will end up in `bazel-out/` inside the sandbox where esbuild is running, however the entrypoint path will be in the sources path, leaving any relative path inputs to no longer be relative to the entrypoint file. The reordering here forces the `resolve_entry_point` method to prefer the file that resides in the `bazel-out/` path in the sandbox. A possible future breaking change would be to force users to list the entrypoint file(s) in either srcs or deps for the correct pathing, or remove `srcs` from esbuild, meaning all input files must be in the output tree.
1 parent 936ed97 commit dd4c4f3

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

packages/esbuild/esbuild.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def _esbuild_impl(ctx):
4141
entry_points = desugar_entry_point_names(ctx.file.entry_point, ctx.files.entry_points)
4242

4343
deps_inputs = depset(transitive = deps_depsets).to_list()
44-
inputs = filter_files(entry_points) + ctx.files.srcs + deps_inputs
44+
45+
# TODO(mattem): 4.0.0 breaking change, entry_points must exist in deps, and are not considered additional srcs
46+
inputs = deps_inputs + ctx.files.srcs + filter_files(entry_points)
4547

4648
metafile = ctx.actions.declare_file("%s_metadata.json" % ctx.attr.name)
4749
outputs = [metafile]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
load("//:index.bzl", "generated_file_test", "js_library", "nodejs_binary", "npm_package_bin")
2+
load("//packages/esbuild/test:tests.bzl", "esbuild")
3+
4+
js_library(
5+
name = "lib",
6+
srcs = ["lib.jsx"],
7+
)
8+
9+
js_library(
10+
name = "main",
11+
srcs = ["main.js"],
12+
deps = [":lib"],
13+
)
14+
15+
esbuild(
16+
name = "bundle",
17+
entry_point = "main.js",
18+
deps = [
19+
":main",
20+
],
21+
)
22+
23+
nodejs_binary(
24+
name = "bin",
25+
data = [
26+
":bundle",
27+
],
28+
entry_point = "bundle.js",
29+
)
30+
31+
npm_package_bin(
32+
name = "runner",
33+
stdout = "out.txt",
34+
tool = ":bin",
35+
)
36+
37+
generated_file_test(
38+
name = "test",
39+
src = "out.golden.txt",
40+
generated = "out.txt",
41+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const NAME = 'rules_nodejs';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {NAME as name} from './lib';
2+
3+
console.log(name);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules_nodejs

0 commit comments

Comments
 (0)