Skip to content

Commit

Permalink
fix: use ':' instead of '=' for esbuild 'define' argument (#2469)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsoulanille authored Feb 17, 2021
1 parent 3e1ebf9 commit b0fddae
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/esbuild/esbuild.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _esbuild_impl(ctx):
args.add_joined(["--target", ctx.attr.target], join_with = "=")
args.add_joined(["--log-level", "info"], join_with = "=")
args.add_joined(["--metafile", metafile.path], join_with = "=")
args.add_all(ctx.attr.define, format_each = "--define=%s")
args.add_all(ctx.attr.define, format_each = "--define:%s")
args.add_all(ctx.attr.external, format_each = "--external=%s")

# disable the error limit and show all errors
Expand Down
28 changes: 28 additions & 0 deletions packages/esbuild/test/define/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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",
define = [
"process.env.NODE_ENV=\"defined_in_bundle\"",
],
entry_point = "main.ts",
deps = [":main"],
)

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

const helper = require(process.env.BAZEL_NODE_RUNFILES_HELPER);
const location = helper.resolve('build_bazel_rules_nodejs/packages/esbuild/test/define/bundle.js');

describe('esbuild define', () => {
it('defines variables', () => {
const bundle = readFileSync(location, {encoding: 'utf8'});
expect(bundle).toContain(`nodeEnv = "defined_in_bundle"`);
});
})
1 change: 1 addition & 0 deletions packages/esbuild/test/define/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const nodeEnv = process.env.NODE_ENV;

0 comments on commit b0fddae

Please sign in to comment.