From 554081cee3c23a4dd612a808ddc5e976b0d02750 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 20 Mar 2021 23:13:27 +1000 Subject: [PATCH] convert svelte worker to ts Should make it easier to maintain, and ironically it also fixes the issue with .mjs files from this morning. --- ts/svelte/BUILD.bazel | 28 ++++++++++++++++++---------- ts/svelte/{svelte.js => svelte.ts} | 10 ++++------ 2 files changed, 22 insertions(+), 16 deletions(-) rename ts/svelte/{svelte.js => svelte.ts} (93%) diff --git a/ts/svelte/BUILD.bazel b/ts/svelte/BUILD.bazel index 185663b94..55b761337 100644 --- a/ts/svelte/BUILD.bazel +++ b/ts/svelte/BUILD.bazel @@ -1,16 +1,24 @@ load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") +load("@npm//@bazel/typescript:index.bzl", "ts_library") + +_deps = [ + "@npm//@bazel/worker", + "@npm//sass", + "@npm//svelte", + "@npm//svelte-preprocess", + "@npm//svelte2tsx", + "@npm//typescript", +] + +ts_library( + name = "svelte_bin_ts", + srcs = ["svelte.ts"], + deps = _deps, +) nodejs_binary( name = "svelte_bin", - data = [ - ":svelte.js", - "@npm//@bazel/worker", - "@npm//sass", - "@npm//svelte", - "@npm//svelte-preprocess", - "@npm//svelte2tsx", - "@npm//typescript", - ], - entry_point = ":svelte.js", + data = ["svelte_bin_ts"] + _deps, + entry_point = ":svelte.ts", visibility = ["//visibility:public"], ) diff --git a/ts/svelte/svelte.js b/ts/svelte/svelte.ts similarity index 93% rename from ts/svelte/svelte.js rename to ts/svelte/svelte.ts index 7798b2a59..064ebef33 100644 --- a/ts/svelte/svelte.js +++ b/ts/svelte/svelte.ts @@ -1,14 +1,12 @@ const fs = require("fs"); -const process = require("process"); -const path = require("path"); const worker = require("@bazel/worker"); -const svelte = require("svelte/compiler.js"); const svelte2tsx = require("svelte2tsx"); const preprocess = require("svelte-preprocess"); -const ts = require("typescript"); +import * as ts from "typescript"; +import * as svelte from "svelte/compiler"; const tsOptions = { - jsx: "preserve", + jsx: ts.JsxEmit.Preserve, declaration: true, emitDeclarationOnly: true, skipLibCheck: true, @@ -73,7 +71,7 @@ async function writeJs(source, inputFilename, outputPath) { try { const processed = await svelte.preprocess(source, preprocessOptions); - const result = svelte.compile(processed.toString(), { + const result = svelte.compile(processed.toString!(), { format: "esm", generate: "dom", filename: outputPath,