convert svelte worker to ts

Should make it easier to maintain, and ironically it also fixes
the issue with .mjs files from this morning.
This commit is contained in:
Damien Elmes 2021-03-20 23:13:27 +10:00
parent 0cc06ad03b
commit 554081cee3
2 changed files with 22 additions and 16 deletions

View File

@ -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"],
)

View File

@ -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,