Skip to content

Commit

Permalink
fix(esbuild): 'output' is passed twice when used (#2587)
Browse files Browse the repository at this point in the history
Fix esbuild_macro always passing the 'output' argument as generated by the rule's name even when the user provides their own 'output' argument.
  • Loading branch information
mattsoulanille authored Apr 6, 2021
1 parent 425dbd6 commit 57218a6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/esbuild/esbuild.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,18 @@ def esbuild_macro(name, output_dir = False, **kwargs):
**kwargs
)
else:
output = "%s.js" % name
if "output" in kwargs:
output = kwargs.pop("output")

output_map = None
sourcemap = kwargs.get("sourcemap", None)
if sourcemap != "inline":
output_map = "%s.js.map" % name
output_map = "%s.map" % output

esbuild(
name = name,
output = "%s.js" % name,
output = output,
output_map = output_map,
**kwargs
)
29 changes: 29 additions & 0 deletions packages/esbuild/test/output/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load("//packages/esbuild/test:tests.bzl", "esbuild")
load("//packages/jasmine:index.bzl", "jasmine_node_test")
load("//packages/typescript:index.bzl", "ts_library")

ts_library(
name = "main",
srcs = [
"main.ts",
],
deps = [
"@npm//@types/node",
],
)

esbuild(
name = "bundle_different_output",
args = ["--keep-names"],
entry_point = "main.ts",
output = "different_output.js",
deps = [":main"],
)

jasmine_node_test(
name = "bundle_test",
srcs = ["bundle_test.js"],
data = [
":bundle_different_output",
],
)
25 changes: 25 additions & 0 deletions packages/esbuild/test/output/bundle_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const {readFileSync} = require('fs');
const path = require('path');

const helper = require(process.env.BAZEL_NODE_RUNFILES_HELPER);
const locationBase = 'build_bazel_rules_nodejs/packages/esbuild/test/output/';

// Location for :bundle_output
const bundleOutputLocation = helper.resolve(path.join(locationBase, 'different_output.js'));
const bundleOutputSourcemapLocation =
helper.resolve(path.join(locationBase, 'different_output.js.map'));

describe('esbuild sourcemap', () => {
it('writes the bundle with name specified by \'output\'', () => {
const bundle = readFileSync(bundleOutputLocation, {encoding: 'utf8'});
expect(bundle).toContain('foo = {');
// Sourcemaps should point to the right file
expect(bundle).toContain('//# sourceMappingURL=different_output.js.map');
});

it('writes the sourcemap with name specified by \'output\'', () => {
const sourcemap = readFileSync(bundleOutputSourcemapLocation, {encoding: 'utf8'});
expect(sourcemap).toContain('"sources":');
expect(sourcemap).toContain('"mappings":');
});
})
8 changes: 8 additions & 0 deletions packages/esbuild/test/output/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Foo {
x: number, y: string,
}

export const foo: Foo = {
x: 123,
y: 'hello',
}

0 comments on commit 57218a6

Please sign in to comment.