Skip to content

Commit

Permalink
fix(esbuild): update to esbuild 0.11
Browse files Browse the repository at this point in the history
Fixes #2552
  • Loading branch information
jbedard committed Apr 6, 2021
1 parent 73a9811 commit 33f9496
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 40 deletions.
8 changes: 4 additions & 4 deletions examples/esbuild/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/3.2.3/rules_nodejs-3.2.3.tar.gz"],
)

_ESBUILD_VERSION = "0.8.48"
_ESBUILD_VERSION = "0.11.5"

http_archive(
name = "esbuild_darwin",
build_file_content = """exports_files(["bin/esbuild"])""",
sha256 = "d21a722873ed24586f071973b77223553fca466946f3d7e3976eeaccb14424e6",
sha256 = "98436890727bdb0d4beddd9c9e07d0aeff0e8dfe0169f85e568eca0dd43f665e",
strip_prefix = "package",
urls = [
"https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-%s.tgz" % _ESBUILD_VERSION,
Expand All @@ -40,7 +40,7 @@ http_archive(
http_archive(
name = "esbuild_windows",
build_file_content = """exports_files(["esbuild.exe"])""",
sha256 = "fe5dcb97b4c47f9567012f0a45c19c655f3d2e0d76932f6dd12715dbebbd6eb0",
sha256 = "589c8ff97210bd41de106e6317ce88f9e88d2cacfd8178ae1217f2b857ff6c3a",
strip_prefix = "package",
urls = [
"https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-%s.tgz" % _ESBUILD_VERSION,
Expand All @@ -50,7 +50,7 @@ http_archive(
http_archive(
name = "esbuild_linux",
build_file_content = """exports_files(["bin/esbuild"])""",
sha256 = "60dabe141e5dfcf99e7113bded6012868132068a582a102b258fb7b1cfdac14b",
sha256 = "113c2e84895f4422a3676db4e15d9f01b2b4fac041edab25284fdb9574ba58a0",
strip_prefix = "package",
urls = [
"https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-%s.tgz" % _ESBUILD_VERSION,
Expand Down
8 changes: 4 additions & 4 deletions packages/esbuild/_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ yarn add -D @bazel/esbuild
Add an `http_archive` fetching the esbuild binary for each platform that you need to support.

```python
_ESBUILD_VERSION = "0.8.48" # reminder: update SHAs below when changing this value
_ESBUILD_VERSION = "0.11.5" # reminder: update SHAs below when changing this value
http_archive(
name = "esbuild_darwin",
urls = [
"https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-%s.tgz" % _ESBUILD_VERSION,
],
strip_prefix = "package",
build_file_content = """exports_files(["bin/esbuild"])""",
sha256 = "d21a722873ed24586f071973b77223553fca466946f3d7e3976eeaccb14424e6",
sha256 = "98436890727bdb0d4beddd9c9e07d0aeff0e8dfe0169f85e568eca0dd43f665e",
)

http_archive(
Expand All @@ -36,7 +36,7 @@ http_archive(
],
strip_prefix = "package",
build_file_content = """exports_files(["esbuild.exe"])""",
sha256 = "fe5dcb97b4c47f9567012f0a45c19c655f3d2e0d76932f6dd12715dbebbd6eb0",
sha256 = "589c8ff97210bd41de106e6317ce88f9e88d2cacfd8178ae1217f2b857ff6c3a",
)

http_archive(
Expand All @@ -46,7 +46,7 @@ http_archive(
],
strip_prefix = "package",
build_file_content = """exports_files(["bin/esbuild"])""",
sha256 = "60dabe141e5dfcf99e7113bded6012868132068a582a102b258fb7b1cfdac14b",
sha256 = "113c2e84895f4422a3676db4e15d9f01b2b4fac041edab25284fdb9574ba58a0",
)
```

Expand Down
4 changes: 2 additions & 2 deletions packages/esbuild/esbuild.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def _esbuild_impl(ctx):
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
args.add_joined(["--error-limit", "0"], join_with = "=")
# disable the log limit and show all logs
args.add_joined(["--log-limit", "0"], join_with = "=")

if ctx.attr.minify:
args.add("--minify")
Expand Down
8 changes: 4 additions & 4 deletions packages/esbuild/esbuild_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# IMPORTANT: Keep this file in sync with the documentation in _README.md

_VERSION = "0.8.48" # reminder: update SHAs below when changing this version
_VERSION = "0.11.5" # reminder: update SHAs below when changing this version

def esbuild_dependencies():
"""Helper to install required dependencies for the esbuild rules"""
Expand All @@ -20,7 +20,7 @@ def esbuild_dependencies():
],
strip_prefix = "package",
build_file_content = """exports_files(["bin/esbuild"])""",
sha256 = "d21a722873ed24586f071973b77223553fca466946f3d7e3976eeaccb14424e6",
sha256 = "98436890727bdb0d4beddd9c9e07d0aeff0e8dfe0169f85e568eca0dd43f665e",
)

http_archive(
Expand All @@ -30,7 +30,7 @@ def esbuild_dependencies():
],
strip_prefix = "package",
build_file_content = """exports_files(["esbuild.exe"])""",
sha256 = "fe5dcb97b4c47f9567012f0a45c19c655f3d2e0d76932f6dd12715dbebbd6eb0",
sha256 = "589c8ff97210bd41de106e6317ce88f9e88d2cacfd8178ae1217f2b857ff6c3a",
)

http_archive(
Expand All @@ -40,5 +40,5 @@ def esbuild_dependencies():
],
strip_prefix = "package",
build_file_content = """exports_files(["bin/esbuild"])""",
sha256 = "60dabe141e5dfcf99e7113bded6012868132068a582a102b258fb7b1cfdac14b",
sha256 = "113c2e84895f4422a3676db4e15d9f01b2b4fac041edab25284fdb9574ba58a0",
)
22 changes: 16 additions & 6 deletions packages/esbuild/test/splitting/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
load("//:index.bzl", "nodejs_test")
load("//:tools/defaults.bzl", "pkg_tar")
load("//packages/esbuild/test:tests.bzl", "esbuild")
load("//packages/typescript:index.bzl", "ts_library")
load("//packages/typescript:index.bzl", "ts_project")

ts_library(
ts_project(
name = "main",
srcs = [
"main.ts",
"other.ts",
],
deps = [
"@npm//@angular/core",
],
tsconfig = {
"compilerOptions": {
"lib": [
"esnext",
"dom",
],
"module": "esnext",
"types": [],
},
},
)

esbuild(
name = "bundle",
args = ["--keep-names"],
args = [
"--keep-names",
"--resolve-extensions=.js,.mjs",
],
entry_point = "main.ts",
output_dir = True,
deps = [":main"],
Expand Down
6 changes: 3 additions & 3 deletions packages/esbuild/test/splitting/bundle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const helper = require(process.env.BAZEL_NODE_RUNFILES_HELPER);
const location = helper.resolve('build_bazel_rules_nodejs/packages/esbuild/test/splitting/bundle');

const main = readFileSync(join(location, 'main.js'), {encoding: 'utf8'});
const hasImportOfCore = main.indexOf(`import("./other.js")`) > -1;
const hasImportOfCore = main.match(/import\(".\/(other-[a-zA-Z0-9]+\.js)"\)/);

if (!hasImportOfCore) {
console.error(`Expected entry_point 'main.js' to have an import of './other.js'`);
console.error(`Expected entry_point 'main.js' to have an import of './other-[hash].js'`);
}

// throws if file does not exist
lstatSync(join(location, 'other.js'));
lstatSync(join(location, hasImportOfCore && hasImportOfCore[1]));

process.exit(hasImportOfCore ? 0 : 1);
56 changes: 39 additions & 17 deletions packages/esbuild/test/typescript/bundle.golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
var __name = (target, value) => __defProp(target, "name", {value, configurable: true});
var __commonJS = (callback, module) => () => {
if (!module) {
module = {exports: {}};
callback(module.exports, module);
}
return module.exports;
};
var __exportStar = (target, module, desc) => {
var __commonJS = (cb, mod) => () => (mod || cb((mod = {exports: {}}).exports, mod), mod.exports);
var __reExport = (target, module, desc) => {
if (module && typeof module === "object" || typeof module === "function") {
for (let key of __getOwnPropNames(module))
if (!__hasOwnProp.call(target, key) && key !== "default")
Expand All @@ -22,9 +16,7 @@ var __exportStar = (target, module, desc) => {
return target;
};
var __toModule = (module) => {
if (module && module.__esModule)
return module;
return __exportStar(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", {value: module, enumerable: true})), module);
return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? {get: () => module.default, enumerable: true} : {value: module, enumerable: true})), module);
};


Expand All @@ -45,22 +37,52 @@ var require_module_dynamic = __commonJS((exports, module) => {
});


var import_module_dynamic = __toModule(require_module_dynamic());
var require_lib = __commonJS((exports, module) => {
(function(factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== void 0)
module.exports = v;
} else if (typeof define === "function" && define.amd) {
define("build_bazel_rules_nodejs/packages/esbuild/test/typescript/generated-module/lib", ["require", "exports"], factory);
}
})(function(require2, exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", {value: true});
exports2.getId = () => `generated-module`;
});
});


var getId = /* @__PURE__ */ __name(() => "module-one", "getId");
var require_lib2 = __commonJS((exports, module) => {
(function(factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== void 0)
module.exports = v;
} else if (typeof define === "function" && define.amd) {
define("build_bazel_rules_nodejs/packages/esbuild/test/typescript/relative-module/lib", ["require", "exports"], factory);
}
})(function(require2, exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", {value: true});
exports2.getId = () => "relative-module";
});
});


var getId2 = /* @__PURE__ */ __name(() => "module-two", "getId");
var import_module_dynamic = __toModule(require_module_dynamic());


var getId3 = /* @__PURE__ */ __name(() => `generated-module`, "getId");
var getId = /* @__PURE__ */ __name(() => "module-one", "getId");


var getId4 = /* @__PURE__ */ __name(() => "relative-module", "getId");
var getId2 = /* @__PURE__ */ __name(() => "module-two", "getId");


var ID = `Full ID: ${getId()} - ${getId2()} - ${import_module_dynamic.getId()} - ${getId4()} - ${getId3()}`;
var import_lib = __toModule(require_lib());
var import_lib2 = __toModule(require_lib2());
var ID = `Full ID: ${getId()} - ${getId2()} - ${(0, import_module_dynamic.getId)()} - ${(0, import_lib2.getId)()} - ${(0, import_lib.getId)()}`;
console.log(ID);
export {
ID
Expand Down

0 comments on commit 33f9496

Please sign in to comment.