Skip to content

Commit

Permalink
fix: use ':' instead of '=' for esbuild 'external' argument (#2475)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsoulanille authored Feb 18, 2021
1 parent 3191280 commit bc7dc82
Show file tree
Hide file tree
Showing 4 changed files with 45 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 @@ -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 = "=")
Expand Down
28 changes: 28 additions & 0 deletions packages/esbuild/test/external-flag/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",
entry_point = "main.ts",
external = [
"fs",
],
deps = [":main"],
)

jasmine_node_test(
name = "bundle_test",
srcs = ["bundle_test.js"],
data = [":bundle"],
)
12 changes: 12 additions & 0 deletions packages/esbuild/test/external-flag/bundle_test.js
Original file line number Diff line number Diff line change
@@ -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)');
});
})
4 changes: 4 additions & 0 deletions packages/esbuild/test/external-flag/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as fs from 'fs';

// Prevent 'fs' from being tree-shaken.
console.log(fs);

0 comments on commit bc7dc82

Please sign in to comment.