Skip to content

Commit

Permalink
Add fixture for declaration transpiler test
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMitchell-at authored and MichaelMitchell-at committed Oct 6, 2024
1 parent 8b99db3 commit 1e88035
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
12 changes: 10 additions & 2 deletions ts/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//ts:defs.bzl", "ts_project")
load(":flags_test.bzl", "ts_project_flags_test_suite")
load(":mock_transpiler.bzl", "mock")
load(":mock_declaration_transpiler.bzl", mock_declaration_transpiler = "mock")
load(":mock_transpiler.bzl", mock_transpiler = "mock")
load(":transpiler_tests.bzl", "transpiler_test_suite")
load(":ts_project_test.bzl", "ts_project_test_suite")

Expand All @@ -15,8 +16,9 @@ ts_project_flags_test_suite(name = "ts_project_flags_test")
ts_project(
name = "rootdir_works_with_repeated_directory",
srcs = ["root/deep/root/deep_src.ts"],
declaration_transpiler = mock_declaration_transpiler,
root_dir = "root",
transpiler = mock,
transpiler = mock_transpiler,
tsconfig = {
"compilerOptions": {
"declaration": True,
Expand All @@ -31,3 +33,9 @@ bzl_library(
visibility = ["//visibility:public"],
deps = ["@aspect_rules_ts//ts/private:ts_lib"],
)

bzl_library(
name = "mock_declaration_transpiler",
srcs = ["mock_declaration_transpiler.bzl"],
visibility = ["//visibility:public"],
)
29 changes: 27 additions & 2 deletions ts/test/mock_transpiler.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"Fixture to demonstrate a custom transpiler for ts_project"

load("@aspect_rules_js//js:libs.bzl", "js_lib_helpers")
load("@aspect_rules_js//js:providers.bzl", "JsInfo")
load("@aspect_rules_ts//ts/private:ts_lib.bzl", "lib")

_DUMMY_SOURCEMAP = """{"version":3,"sources":["%s"],"mappings":"AAAO,KAAK,CAAC","file":"in.js","sourcesContent":["fake"]}"""
Expand All @@ -21,15 +23,38 @@ def _mock_impl(ctx):
inputs = [src],
outputs = [js_file],
command = "cp $@",
arguments = [src.path, js_file.path.replace(".ts", ".js")],
arguments = [src.path, js_file.path],
)

ctx.actions.write(
output = map_file,
content = _DUMMY_SOURCEMAP % src.short_path,
)

return DefaultInfo(files = depset(out_files))
output_sources_depset = depset(out_files)

runfiles = js_lib_helpers.gather_runfiles(
ctx = ctx,
sources = output_sources_depset,
data = [],
deps = ctx.attr.srcs,
)

return [
JsInfo(
target = ctx.label,
sources = output_sources_depset,
types = depset(),
transitive_sources = depset(),
transitive_types = depset(),
npm_sources = depset(),
npm_package_store_infos = depset(),
),
DefaultInfo(
files = output_sources_depset,
runfiles = runfiles,
),
]

mock_impl = rule(
attrs = {
Expand Down

0 comments on commit 1e88035

Please sign in to comment.