3dad3c90d0
Uses the logic from the sqltools VSCode add-on, with a workaround for the use of 'type' in some table columns. By detecting the presence of 'BUILD_WORKSPACE_DIRECTORY' we can tell if the rule is running in test mode or was run directly, avoiding the need for separate check and fix rules. It might be nice to extend this to other formatting rules in the future as well.
26 lines
791 B
Python
26 lines
791 B
Python
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
|
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
|
|
|
|
def sql_format_setup():
|
|
ts_library(
|
|
name = "sql_format_lib",
|
|
srcs = ["//ts:sql_format.ts"],
|
|
deps = [
|
|
"@npm//@sqltools/formatter",
|
|
"@npm//@types/node",
|
|
"@npm//@types/diff",
|
|
"@npm//diff",
|
|
],
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
native.exports_files(["sql_format.ts"])
|
|
|
|
def sql_format(name = "sql_format", srcs = [], **kwargs):
|
|
nodejs_test(
|
|
name = name,
|
|
entry_point = "//ts:sql_format.ts",
|
|
args = [native.package_name() + "/" + f for f in srcs],
|
|
data = ["//ts:sql_format_lib", "@npm//tslib", "@npm//diff"] + srcs,
|
|
**kwargs
|
|
)
|