diff --git a/rules_ts/.gitignore b/rules_ts/.gitignore index 336b287..4cdd99d 100644 --- a/rules_ts/.gitignore +++ b/rules_ts/.gitignore @@ -7,6 +7,7 @@ ts_project_sandboxed_worker ts_project_swc ts_project_worker_swc ts_project_sandboxed_worker_swc +ts_project_esbuild ts_project_rules_nodejs ts_project_rules_nodejs_swc ts_library diff --git a/rules_ts/WORKSPACE b/rules_ts/WORKSPACE index b69a3eb..35ac932 100644 --- a/rules_ts/WORKSPACE +++ b/rules_ts/WORKSPACE @@ -43,6 +43,29 @@ swc_register_toolchains( swc_version = "v1.2.204", ) +local_repository( + name = "aspect_rules_esbuild", + path = "../../rules_esbuild", +) + +#http_archive( +# name = "aspect_rules_esbuild", +# sha256 = "1e365451341ffb2490193292dfd9953f2ca009586c2381cb4dc08d01e48866b7", +# strip_prefix = "rules_esbuild-0.12.0", +# url = "https://github.com/aspect-build/rules_esbuild/archive/refs/tags/v0.12.0.tar.gz", +#) + +load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependencies") + +rules_esbuild_dependencies() + +load("@aspect_rules_esbuild//esbuild:repositories.bzl", "LATEST_VERSION", "esbuild_register_toolchains") + +esbuild_register_toolchains( + name = "esbuild", + esbuild_version = LATEST_VERSION, +) + ######################################################## # Below only needed for legacy rules_nodejs comparison # diff --git a/rules_ts/generator.js b/rules_ts/generator.js index 4d09a65..4a6589f 100644 --- a/rules_ts/generator.js +++ b/rules_ts/generator.js @@ -39,6 +39,7 @@ class Generator { 'ts_project_swc', 'ts_project_worker_swc', 'ts_project_sandboxed_worker_swc', + 'ts_project_esbuild', 'ts_project_rules_nodejs', 'ts_project_rules_nodejs_swc', 'ts_library', @@ -155,6 +156,12 @@ ${this._ts_attributes()} 'load("@aspect_rules_swc//swc:defs.bzl", "swc_transpiler")', ].join("\n") + case 'ts_project_esbuild': + return [ + 'load("@aspect_rules_ts//ts:defs.bzl", "ts_project")', + 'load("@aspect_rules_js//js:defs.bzl", "js_library")', + 'load("@aspect_rules_esbuild//esbuild:defs.bzl", "esbuild_transpiler")', + ].join("\n") case 'ts_project_rules_nodejs': return [ 'load("@npm//@bazel/typescript:index.bzl", "ts_project")', @@ -207,6 +214,7 @@ ${this._ts_attributes()} case 'ts_project_swc': case 'ts_project_worker_swc': case 'ts_project_sandboxed_worker_swc': + case 'ts_project_esbuild': return ` # Generated BUILD file, see /generate.js load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin") @@ -280,6 +288,13 @@ ${rootDeps.map(d => ` \"${d}\",`).join("\n")} attrs.push(' supports_workers = True,') break; + case 'ts_project_esbuild': + attrs.push(` tsconfig = "//${this.outputDir}:tsconfig",`) + attrs.push(' declaration = True,') + attrs.push(' transpiler = esbuild_transpiler,') + attrs.push(' supports_workers = False,') + break; + case 'ts_project_rules_nodejs': attrs.push(` tsconfig = "//${this.outputDir}:tsconfig.json",`) attrs.push(' declaration = True,') diff --git a/rules_ts/run_benchmarks.sh b/rules_ts/run_benchmarks.sh index e8ca013..14e4d32 100755 --- a/rules_ts/run_benchmarks.sh +++ b/rules_ts/run_benchmarks.sh @@ -11,6 +11,7 @@ styles=( 'ts_project_swc' 'ts_project_worker_swc' 'ts_project_sandboxed_worker_swc' + 'ts_project_esbuild' 'ts_project_rules_nodejs' 'ts_project_rules_nodejs_swc' 'ts_library'