diff --git a/.github/workflows/workspace_snippet.sh b/.github/workflows/workspace_snippet.sh index 8fc3f57..37e7e11 100755 --- a/.github/workflows/workspace_snippet.sh +++ b/.github/workflows/workspace_snippet.sh @@ -34,7 +34,7 @@ rules_swc_dependencies() load("@aspect_rules_swc//swc:repositories.bzl", "swc_register_toolchains") swc_register_toolchains( name = "swc", - swc_version = "v1.2.118", + swc_version = "v1.2.168", ) # Fetches a NodeJS interpreter, needed to run the swc CLI. diff --git a/WORKSPACE b/WORKSPACE index 19e7f82..2e1d057 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -16,7 +16,7 @@ load("//swc:repositories.bzl", "swc_register_toolchains") swc_register_toolchains( name = "default_swc", - swc_version = "v1.2.141", + swc_version = "v1.2.168", ) load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains") diff --git a/examples/transitive/BUILD.bazel b/examples/transitive/BUILD.bazel new file mode 100644 index 0000000..1d2f9ac --- /dev/null +++ b/examples/transitive/BUILD.bazel @@ -0,0 +1,21 @@ +"""Test transitive dependencies between typescript files +which are transpiled separately as "libraries" but which +have runtime dependencies. +""" + +load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") + +genrule( + name = "run", + outs = ["actual"], + cmd = "$(location //examples/transitive/app:bin) > $@", + tools = ["//examples/transitive/app:bin"], +) + +# Assert the output of the program matches the expected file +write_source_files( + name = "assertion", + files = { + "expected": "actual", + }, +) diff --git a/examples/transitive/app/BUILD.bazel b/examples/transitive/app/BUILD.bazel new file mode 100644 index 0000000..db77214 --- /dev/null +++ b/examples/transitive/app/BUILD.bazel @@ -0,0 +1,24 @@ +load("@aspect_rules_swc//swc:swc.bzl", "swc") +load("@aspect_rules_js//js:nodejs_binary.bzl", "nodejs_binary") + +package(default_visibility = ["//:__subpackages__"]) + +swc( + name = "app", + srcs = ["a.ts"], + args = [ + "--config", + "module.type=commonjs", + ], + # In Bazel, a "data" dependency is a runtime dependency. + # This file isn't required to transpile b.ts -> b.js + # however any program which depends on lib_b should have + # lib_c available in the "runfiles". + data = ["//examples/transitive/lib_b"], +) + +nodejs_binary( + name = "bin", + data = [":app"], + entry_point = "a.js", +) diff --git a/examples/transitive/app/a.ts b/examples/transitive/app/a.ts new file mode 100644 index 0000000..30851ea --- /dev/null +++ b/examples/transitive/app/a.ts @@ -0,0 +1,3 @@ +import { b } from "../lib_b/b"; + +console.log("output of app:", b); diff --git a/examples/transitive/expected b/examples/transitive/expected new file mode 100644 index 0000000..97a3814 --- /dev/null +++ b/examples/transitive/expected @@ -0,0 +1 @@ +output of app: 3 diff --git a/examples/transitive/lib_b/BUILD.bazel b/examples/transitive/lib_b/BUILD.bazel new file mode 100644 index 0000000..7132210 --- /dev/null +++ b/examples/transitive/lib_b/BUILD.bazel @@ -0,0 +1,17 @@ +load("@aspect_rules_swc//swc:swc.bzl", "swc") + +package(default_visibility = ["//:__subpackages__"]) + +swc( + name = "lib_b", + srcs = ["b.ts"], + args = [ + "--config", + "module.type=commonjs", + ], + # In Bazel, a "data" dependency is a runtime dependency. + # This file isn't required to transpile b.ts -> b.js + # however any program which depends on lib_b should have + # lib_c available in the "runfiles". + data = ["//examples/transitive/lib_c"], +) diff --git a/examples/transitive/lib_b/b.ts b/examples/transitive/lib_b/b.ts new file mode 100644 index 0000000..e4a14aa --- /dev/null +++ b/examples/transitive/lib_b/b.ts @@ -0,0 +1,3 @@ +import { c } from "../lib_c/c"; + +export const b = 2 + c; diff --git a/examples/transitive/lib_c/BUILD.bazel b/examples/transitive/lib_c/BUILD.bazel new file mode 100644 index 0000000..9bc63ef --- /dev/null +++ b/examples/transitive/lib_c/BUILD.bazel @@ -0,0 +1,12 @@ +load("@aspect_rules_swc//swc:swc.bzl", "swc") + +package(default_visibility = ["//:__subpackages__"]) + +swc( + name = "lib_c", + srcs = ["c.ts"], + args = [ + "--config", + "module.type=commonjs", + ], +) diff --git a/examples/transitive/lib_c/c.ts b/examples/transitive/lib_c/c.ts new file mode 100644 index 0000000..351d3e8 --- /dev/null +++ b/examples/transitive/lib_c/c.ts @@ -0,0 +1 @@ +export const c = 1; diff --git a/swc/private/swc.bzl b/swc/private/swc.bzl index 174f536..e75e3bd 100644 --- a/swc/private/swc.bzl +++ b/swc/private/swc.bzl @@ -163,10 +163,14 @@ def _impl(ctx): ), ) + # See https://docs.bazel.build/versions/main/skylark/rules.html#runfiles + runfiles = ctx.runfiles(files = outputs + ctx.files.data) + runfiles = runfiles.merge_all([d[DefaultInfo].default_runfiles for d in ctx.attr.data]) + providers = [ DefaultInfo( files = depset(outputs), - runfiles = ctx.runfiles(outputs, transitive_files = depset(ctx.files.data)), + runfiles = runfiles, ), ] diff --git a/swc/private/versions.bzl b/swc/private/versions.bzl index eb19328..1dd009c 100644 --- a/swc/private/versions.bzl +++ b/swc/private/versions.bzl @@ -1,6 +1,21 @@ "Mirror of release info" TOOL_VERSIONS = { + "v1.2.168": { + "android-arm-eabi": "sha384-eegQUZCJXBzl5Y4IeELJhlVGAUkspDA6cIqHJxEY6nSMRsJ5azxPAYHPMjd/7HcB", + "android-arm64": "sha384-iDGIuT+rMBqEFXynqgqUCEwaEysPNHPgU5zHVrw0ZoTBmbgU7hE/bDI6qtwEuhGB", + "darwin-arm64": "sha384-cC7J5IXEiivWG9fLk70P3/eR3xlC9c6pEQ7eDSLEbUPayV9dzd2sfL6zJNAVzJke", + "darwin-x64": "sha384-cdoeWiAiFuC6trXvaOIKHaghIOgGjE8FYU+ApLIX10uuASykH0KBUls8YzI/z0BF", + "freebsd-x64": "sha384-i/sWnzLH7iq73TnVt0Gc7N1jllFITcKp14PIEB/GPuR2XfH5Lta6N2AtAHlIRJj6", + "linux-arm-gnueabihf": "sha384-JAMYCgrMEUFVmDdXSjJJCnaatsyQ3PXB1UwlGwZ3ggXx3TQ8q6zUjXPcaWPMPDdd", + "linux-arm64-gnu": "sha384-6vN8ks/3LXz1y1Vlt99MZTpieafcdy1E+Umd8Al3v/dPECuhq9r+nOseFzNBCYwK", + "linux-arm64-musl": "sha384-jJhVdadlEqOIKadZBzlMue1t8YYNJ/kdsdbUt0UM+gc6Zbp1DJr1oai3maH6lvTc", + "linux-x64-gnu": "sha384-Of6s4gjX/7JGFpReGFG0lozDS6i7AJcJ3xBOEoYvAo33dXakrg+NTOORTtUvyHQS", + "linux-x64-musl": "sha384-c537PkbC8nkaQP+lMkKWjUZ1Xl2qpCnDW5tc1SMRb1SGgLWuSj4AZ1GjmT5CFVV9", + "win32-arm64-msvc": "sha384-inYv8Ad8efI6sT5nZ9dlGq0aeaBIzo8S2ZcG8MafsdipilHazxm/BYdQWZTsazAP", + "win32-ia32-msvc": "sha384-3Sxwt0BN2W7N/xei9wcONc6MQbEQo9EcnfoeO+pNBGR1e4t0QVAVufpzK4G+ZDHs", + "win32-x64-msvc": "sha384-HJKPVPvKu6nWu6vdXrnVK5ClFoKA7pM1C4fgiQ2eBt0N/syTzD9HRGbB24s1Ru3B", + }, "v1.2.141": { "android-arm-eabi": "sha384-1Kpl5sj2A50yTtZu5Ae7rGGY+t+0FYvcy/VCUp1IM8lW36RuhERqfahcWdmgtinB", "android-arm64": "sha384-F/kmewGo2LlmyIeEQBnctRBJULmcSbko/5Gz1AJNxATWS1JUEX8C06AhdTpV7dk0",