Skip to content

Commit 92e8169

Browse files
authored
fix(esbuild): set correct base url when rule is at root (#2506)
1 parent 2efe437 commit 92e8169

File tree

5 files changed

+66
-219
lines changed

5 files changed

+66
-219
lines changed

examples/esbuild/package-lock.json

Lines changed: 44 additions & 214 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/esbuild/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"tslib": "1.9.0",
88
"typescript": "3.5.3"
99
},
10+
"dependencies": {
11+
"chalk": "4.1.0"
12+
},
1013
"scripts": {
1114
"test": "bazel test //..."
1215
}

examples/esbuild/src/BUILD.bazel

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ ts_project(
99
"main.ts",
1010
"name.ts",
1111
],
12-
tsconfig = {},
12+
tsconfig = {
13+
"compilerOptions": {
14+
"esModuleInterop": True,
15+
},
16+
},
17+
deps = [
18+
"@npm//chalk",
19+
],
1320
)
1421

1522
# create a single bundle of the JS sources

examples/esbuild/src/main.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import chalk from 'chalk';
2+
13
import {NAME} from './name';
24

35
export function greeting(name: string): string {
4-
return `Hello ${name}!`;
6+
return `Hello ${chalk.bold(name)}!`;
57
}
68

7-
const sentance = greeting(NAME);
8-
console.log(sentance);
9+
const sentence = greeting(NAME);
10+
console.log(sentence);

packages/esbuild/helpers.bzl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def write_jsconfig_file(ctx, path_alias_mappings):
8282
ctx: The rule context
8383
path_alias_mappings: Dict with the mappings
8484
85+
Returns:
86+
File object reference for the jsconfig file
8587
"""
8688

8789
# The package path
@@ -90,7 +92,10 @@ def write_jsconfig_file(ctx, path_alias_mappings):
9092
# Replace all segments in the path with .. join them with "/" and postfix
9193
# it with another / to get a relative path from the build file dir
9294
# to the workspace root.
93-
base_url_path = "/".join([".." for segment in rule_path.split("/")]) + "/"
95+
if len(rule_path) == 0:
96+
base_url_path = "."
97+
else:
98+
base_url_path = "/".join([".." for segment in rule_path.split("/")]) + "/"
9499

95100
# declare the jsconfig_file
96101
jsconfig_file = ctx.actions.declare_file("%s.config.json" % ctx.attr.name)

0 commit comments

Comments
 (0)