2021-03-20 05:56:08 +01:00
|
|
|
load("@npm//svelte-check:index.bzl", _svelte_check = "svelte_check_test")
|
2021-04-16 15:18:33 +02:00
|
|
|
load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo", "declaration_info")
|
2021-04-15 06:27:53 +02:00
|
|
|
load("@io_bazel_rules_sass//:defs.bzl", "SassInfo")
|
|
|
|
|
2021-04-16 15:18:33 +02:00
|
|
|
def _get_dep_sources(dep):
|
|
|
|
if SassInfo in dep:
|
|
|
|
return dep[SassInfo].transitive_sources
|
|
|
|
elif DeclarationInfo in dep:
|
|
|
|
return dep[DeclarationInfo].transitive_declarations
|
|
|
|
else:
|
|
|
|
return []
|
|
|
|
|
2021-04-15 06:27:53 +02:00
|
|
|
def _get_sources(deps):
|
2021-04-16 15:18:33 +02:00
|
|
|
return depset([], transitive = [_get_dep_sources(dep) for dep in deps])
|
2021-03-20 05:56:08 +01:00
|
|
|
|
2021-03-20 11:42:29 +01:00
|
|
|
def _svelte(ctx):
|
|
|
|
args = ctx.actions.args()
|
|
|
|
args.use_param_file("@%s", use_always = True)
|
|
|
|
args.set_param_file_format("multiline")
|
2021-03-20 05:56:08 +01:00
|
|
|
|
2021-03-20 11:42:29 +01:00
|
|
|
args.add(ctx.file.entry_point.path)
|
|
|
|
args.add(ctx.outputs.mjs.path)
|
|
|
|
args.add(ctx.outputs.dts.path)
|
2021-03-21 05:23:40 +01:00
|
|
|
args.add(ctx.outputs.css.path)
|
2021-04-15 06:27:53 +02:00
|
|
|
args.add(ctx.var["BINDIR"])
|
|
|
|
args.add(ctx.var["GENDIR"])
|
2021-03-20 11:42:29 +01:00
|
|
|
args.add_all(ctx.files._shims)
|
2021-03-20 05:56:08 +01:00
|
|
|
|
2021-04-15 06:27:53 +02:00
|
|
|
deps = _get_sources(ctx.attr.deps).to_list()
|
|
|
|
|
2021-03-20 11:42:29 +01:00
|
|
|
ctx.actions.run(
|
|
|
|
execution_requirements = {"supports-workers": "1"},
|
|
|
|
executable = ctx.executable._svelte_bin,
|
2021-03-21 05:23:40 +01:00
|
|
|
outputs = [ctx.outputs.mjs, ctx.outputs.dts, ctx.outputs.css],
|
2021-04-15 06:27:53 +02:00
|
|
|
inputs = [ctx.file.entry_point] + ctx.files._shims + deps,
|
2021-03-20 11:42:29 +01:00
|
|
|
mnemonic = "Svelte",
|
|
|
|
arguments = [args],
|
2021-03-20 05:56:08 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
return [
|
2021-03-20 11:42:29 +01:00
|
|
|
declaration_info(depset([ctx.outputs.dts]), deps = [ctx.attr._shims]),
|
2021-03-20 05:56:08 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
svelte = rule(
|
|
|
|
implementation = _svelte,
|
|
|
|
attrs = {
|
|
|
|
"entry_point": attr.label(allow_single_file = True),
|
2021-04-15 06:27:53 +02:00
|
|
|
"deps": attr.label_list(),
|
2021-03-20 11:42:29 +01:00
|
|
|
"_svelte_bin": attr.label(
|
|
|
|
default = Label("//ts/svelte:svelte_bin"),
|
2021-03-20 05:56:08 +01:00
|
|
|
executable = True,
|
|
|
|
cfg = "host",
|
|
|
|
),
|
|
|
|
"_shims": attr.label(
|
|
|
|
default = Label("@npm//svelte2tsx:svelte2tsx__typings"),
|
|
|
|
allow_files = True,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
outputs = {
|
2021-03-20 11:42:29 +01:00
|
|
|
"mjs": "%{name}.svelte.mjs",
|
|
|
|
"dts": "%{name}.svelte.d.ts",
|
2021-03-21 05:23:40 +01:00
|
|
|
"css": "%{name}.svelte.css",
|
2021-03-20 05:56:08 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2021-04-19 23:51:09 +02:00
|
|
|
def compile_svelte(name, srcs, deps = [], visibility = ["//visibility:private"]):
|
2021-03-20 05:56:08 +01:00
|
|
|
for src in srcs:
|
|
|
|
svelte(
|
|
|
|
name = src.replace(".svelte", ""),
|
|
|
|
entry_point = src,
|
2021-04-15 06:27:53 +02:00
|
|
|
deps = deps,
|
2021-04-19 23:51:09 +02:00
|
|
|
visibility = visibility,
|
2021-03-20 05:56:08 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
native.filegroup(
|
|
|
|
name = name,
|
|
|
|
srcs = srcs,
|
2021-04-19 23:51:09 +02:00
|
|
|
visibility = visibility,
|
2021-03-20 05:56:08 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def svelte_check(name = "svelte_check", srcs = []):
|
|
|
|
_svelte_check(
|
|
|
|
name = name,
|
|
|
|
args = [
|
|
|
|
"--workspace",
|
|
|
|
native.package_name(),
|
2021-04-12 06:28:09 +02:00
|
|
|
"--fail-on-warnings",
|
|
|
|
"--fail-on-hints",
|
2021-03-20 05:56:08 +01:00
|
|
|
],
|
|
|
|
data = [
|
|
|
|
"//ts:tsconfig.json",
|
2021-03-22 15:41:43 +01:00
|
|
|
"//ts/sveltelib",
|
2021-03-20 05:56:08 +01:00
|
|
|
"//ts/lib",
|
|
|
|
"//ts/lib:backend_proto",
|
|
|
|
"@npm//sass",
|
|
|
|
] + srcs,
|
2021-04-15 06:27:53 +02:00
|
|
|
env = {"SASS_PATH": "$(rootpath //ts:tsconfig.json)/../.."},
|
2021-03-20 05:56:08 +01:00
|
|
|
)
|