From b0fddaeedff9d53619367ecf0387085c2442a2d7 Mon Sep 17 00:00:00 2001 From: Matthew Soulanille Date: Wed, 17 Feb 2021 03:29:08 -0800 Subject: [PATCH] fix: use ':' instead of '=' for esbuild 'define' argument (#2469) --- packages/esbuild/esbuild.bzl | 2 +- packages/esbuild/test/define/BUILD.bazel | 28 +++++++++++++++++++++ packages/esbuild/test/define/bundle_test.js | 11 ++++++++ packages/esbuild/test/define/main.ts | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 packages/esbuild/test/define/BUILD.bazel create mode 100644 packages/esbuild/test/define/bundle_test.js create mode 100644 packages/esbuild/test/define/main.ts diff --git a/packages/esbuild/esbuild.bzl b/packages/esbuild/esbuild.bzl index 6df768a8ec..3536e3f2d8 100644 --- a/packages/esbuild/esbuild.bzl +++ b/packages/esbuild/esbuild.bzl @@ -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 diff --git a/packages/esbuild/test/define/BUILD.bazel b/packages/esbuild/test/define/BUILD.bazel new file mode 100644 index 0000000000..bd894ab8fa --- /dev/null +++ b/packages/esbuild/test/define/BUILD.bazel @@ -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"], +) diff --git a/packages/esbuild/test/define/bundle_test.js b/packages/esbuild/test/define/bundle_test.js new file mode 100644 index 0000000000..7099c871e7 --- /dev/null +++ b/packages/esbuild/test/define/bundle_test.js @@ -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"`); + }); +}) diff --git a/packages/esbuild/test/define/main.ts b/packages/esbuild/test/define/main.ts new file mode 100644 index 0000000000..bfb3fddc48 --- /dev/null +++ b/packages/esbuild/test/define/main.ts @@ -0,0 +1 @@ +export const nodeEnv = process.env.NODE_ENV;