From c9dd476eef9b6065bc4325dc45b93aba4d161900 Mon Sep 17 00:00:00 2001 From: Matthew Soulanille Date: Wed, 17 Feb 2021 20:29:37 -0500 Subject: [PATCH] fix: use ':' instead of '=' for esbuild 'external' argument --- packages/esbuild/esbuild.bzl | 2 +- .../esbuild/test/external-flag/BUILD.bazel | 28 +++++++++++++++++++ .../esbuild/test/external-flag/bundle_test.js | 12 ++++++++ packages/esbuild/test/external-flag/main.ts | 4 +++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 packages/esbuild/test/external-flag/BUILD.bazel create mode 100644 packages/esbuild/test/external-flag/bundle_test.js create mode 100644 packages/esbuild/test/external-flag/main.ts diff --git a/packages/esbuild/esbuild.bzl b/packages/esbuild/esbuild.bzl index bbcf5c792e..255f4ca8cf 100644 --- a/packages/esbuild/esbuild.bzl +++ b/packages/esbuild/esbuild.bzl @@ -50,7 +50,7 @@ def _esbuild_impl(ctx): 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.external, format_each = "--external=%s") + args.add_all(ctx.attr.external, format_each = "--external:%s") # disable the error limit and show all errors args.add_joined(["--error-limit", "0"], join_with = "=") diff --git a/packages/esbuild/test/external-flag/BUILD.bazel b/packages/esbuild/test/external-flag/BUILD.bazel new file mode 100644 index 0000000000..886a80397e --- /dev/null +++ b/packages/esbuild/test/external-flag/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", + entry_point = "main.ts", + external = [ + "fs", + ], + deps = [":main"], +) + +jasmine_node_test( + name = "bundle_test", + srcs = ["bundle_test.js"], + data = [":bundle"], +) diff --git a/packages/esbuild/test/external-flag/bundle_test.js b/packages/esbuild/test/external-flag/bundle_test.js new file mode 100644 index 0000000000..0770e66d7e --- /dev/null +++ b/packages/esbuild/test/external-flag/bundle_test.js @@ -0,0 +1,12 @@ +const {readFileSync} = require('fs'); + +const helper = require(process.env.BAZEL_NODE_RUNFILES_HELPER); +const location = + helper.resolve('build_bazel_rules_nodejs/packages/esbuild/test/external-flag/bundle.js'); + +describe('esbuild external-flag', () => { + it('compiles with the external module \'fs\'', () => { + const bundle = readFileSync(location, {encoding: 'utf8'}); + expect(bundle).toContain('console.log(fs)'); + }); +}) diff --git a/packages/esbuild/test/external-flag/main.ts b/packages/esbuild/test/external-flag/main.ts new file mode 100644 index 0000000000..8f2042b9b0 --- /dev/null +++ b/packages/esbuild/test/external-flag/main.ts @@ -0,0 +1,4 @@ +import * as fs from 'fs'; + +// Prevent 'fs' from being tree-shaken. +console.log(fs);