From 3d416b4a685ccdc7a19a8ba04350507a8dc59d3c Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 18 Oct 2021 14:14:16 +1000 Subject: [PATCH] convert sql_format to ts_project; move into separate folder --- rslib/BUILD.bazel | 2 +- ts/BUILD.bazel | 3 --- ts/congrats/BUILD.bazel | 1 - ts/sql_format.bzl | 25 ------------------------- ts/sql_format/BUILD.bazel | 19 +++++++++++++++++++ ts/sql_format/defs.bzl | 10 ++++++++++ ts/{ => sql_format}/sql_format.ts | 0 ts/sql_format/tsconfig.json | 14 ++++++++++++++ 8 files changed, 44 insertions(+), 30 deletions(-) delete mode 100644 ts/sql_format.bzl create mode 100644 ts/sql_format/BUILD.bazel create mode 100644 ts/sql_format/defs.bzl rename ts/{ => sql_format}/sql_format.ts (100%) create mode 100644 ts/sql_format/tsconfig.json diff --git a/rslib/BUILD.bazel b/rslib/BUILD.bazel index 565b3ce7b..e194e7127 100644 --- a/rslib/BUILD.bazel +++ b/rslib/BUILD.bazel @@ -4,7 +4,7 @@ load("@rules_rust//rust:rust.bzl", "rust_binary", "rust_library", "rust_test") load("@rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script") load(":rustfmt.bzl", "rustfmt_fix", "rustfmt_test") -load("//ts:sql_format.bzl", "sql_format") +load("//ts/sql_format:defs.bzl", "sql_format") # Build script ####################### diff --git a/ts/BUILD.bazel b/ts/BUILD.bazel index bc337e8bb..e9c5afe2d 100644 --- a/ts/BUILD.bazel +++ b/ts/BUILD.bazel @@ -1,13 +1,10 @@ load("//ts:prettier.bzl", "prettier", "prettier_test") -load("//ts:sql_format.bzl", "sql_format_setup") load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") prettier() prettier_test() -sql_format_setup() - # Exported files ################# diff --git a/ts/congrats/BUILD.bazel b/ts/congrats/BUILD.bazel index f1ee634f6..ae1dccdee 100644 --- a/ts/congrats/BUILD.bazel +++ b/ts/congrats/BUILD.bazel @@ -1,4 +1,3 @@ -load("@npm//@bazel/typescript:index.bzl", "ts_library") load("//ts:prettier.bzl", "prettier_test") load("//ts:eslint.bzl", "eslint_test") load("//ts/svelte:svelte.bzl", "compile_svelte", "svelte_check") diff --git a/ts/sql_format.bzl b/ts/sql_format.bzl deleted file mode 100644 index 517aea31a..000000000 --- a/ts/sql_format.bzl +++ /dev/null @@ -1,25 +0,0 @@ -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", - ], - tsconfig = "//ts:tsconfig_bin", - visibility = ["//visibility:public"], - ) - -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 - ) diff --git a/ts/sql_format/BUILD.bazel b/ts/sql_format/BUILD.bazel new file mode 100644 index 000000000..bbd3297fd --- /dev/null +++ b/ts/sql_format/BUILD.bazel @@ -0,0 +1,19 @@ +load("//ts:typescript.bzl", "typescript") +load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") + +_deps = [ + "@npm//@sqltools/formatter", + "@npm//@types/diff", + "@npm//@types/node", + "@npm//diff", +] + +typescript( + name = "sql_format_lib", + srcs = ["sql_format.ts"], + deps = _deps, +) + +# a hack to allow us to define the test in a different file; there +# should be a better way +exports_files(["sql_format.ts"]) diff --git a/ts/sql_format/defs.bzl b/ts/sql_format/defs.bzl new file mode 100644 index 000000000..a43eb6fc7 --- /dev/null +++ b/ts/sql_format/defs.bzl @@ -0,0 +1,10 @@ +load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test") + +def sql_format(name = "sql_format", srcs = [], **kwargs): + nodejs_test( + name = name, + entry_point = "//ts/sql_format:sql_format.ts", + args = [native.package_name() + "/" + f for f in srcs], + data = ["//ts/sql_format:sql_format_lib", "@npm//tslib", "@npm//diff"] + srcs, + **kwargs + ) diff --git a/ts/sql_format.ts b/ts/sql_format/sql_format.ts similarity index 100% rename from ts/sql_format.ts rename to ts/sql_format/sql_format.ts diff --git a/ts/sql_format/tsconfig.json b/ts/sql_format/tsconfig.json new file mode 100644 index 000000000..0f2224052 --- /dev/null +++ b/ts/sql_format/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../tsconfig.json", + "include": ["*"], + "references": [], + "compilerOptions": { + "types": ["node"], + // ignore missing optional modules like postcss + "skipLibCheck": true, + // ensure node can run the resulting code + "noEmitHelpers": false, + "importHelpers": false, + "module": "commonjs", + } +}