Skip to content

Commit

Permalink
fix(esbuild): set correct base url when rule is at root (#2506)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattem authored Mar 6, 2021
1 parent 2efe437 commit 92e8169
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 219 deletions.
258 changes: 44 additions & 214 deletions examples/esbuild/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"tslib": "1.9.0",
"typescript": "3.5.3"
},
"dependencies": {
"chalk": "4.1.0"
},
"scripts": {
"test": "bazel test //..."
}
Expand Down
9 changes: 8 additions & 1 deletion examples/esbuild/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ ts_project(
"main.ts",
"name.ts",
],
tsconfig = {},
tsconfig = {
"compilerOptions": {
"esModuleInterop": True,
},
},
deps = [
"@npm//chalk",
],
)

# create a single bundle of the JS sources
Expand Down
8 changes: 5 additions & 3 deletions examples/esbuild/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import chalk from 'chalk';

import {NAME} from './name';

export function greeting(name: string): string {
return `Hello ${name}!`;
return `Hello ${chalk.bold(name)}!`;
}

const sentance = greeting(NAME);
console.log(sentance);
const sentence = greeting(NAME);
console.log(sentence);
7 changes: 6 additions & 1 deletion packages/esbuild/helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def write_jsconfig_file(ctx, path_alias_mappings):
ctx: The rule context
path_alias_mappings: Dict with the mappings
Returns:
File object reference for the jsconfig file
"""

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

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

0 comments on commit 92e8169

Please sign in to comment.