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("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
load("@npm//@bazel/typescript:index.bzl", "ts_library")
nodejs_binary( _deps = [
name = "svelte_bin",
data = [
":svelte.js",
"@npm//@bazel/worker", "@npm//@bazel/worker",
"@npm//sass", "@npm//sass",
"@npm//svelte", "@npm//svelte",
"@npm//svelte-preprocess", "@npm//svelte-preprocess",
"@npm//svelte2tsx", "@npm//svelte2tsx",
"@npm//typescript", "@npm//typescript",
], ]
entry_point = ":svelte.js",
ts_library(
name = "svelte_bin_ts",
srcs = ["svelte.ts"],
deps = _deps,
)
nodejs_binary(
name = "svelte_bin",
data = ["svelte_bin_ts"] + _deps,
entry_point = ":svelte.ts",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )

View File

@ -1,14 +1,12 @@
const fs = require("fs"); const fs = require("fs");
const process = require("process");
const path = require("path");
const worker = require("@bazel/worker"); const worker = require("@bazel/worker");
const svelte = require("svelte/compiler.js");
const svelte2tsx = require("svelte2tsx"); const svelte2tsx = require("svelte2tsx");
const preprocess = require("svelte-preprocess"); const preprocess = require("svelte-preprocess");
const ts = require("typescript"); import * as ts from "typescript";
import * as svelte from "svelte/compiler";
const tsOptions = { const tsOptions = {
jsx: "preserve", jsx: ts.JsxEmit.Preserve,
declaration: true, declaration: true,
emitDeclarationOnly: true, emitDeclarationOnly: true,
skipLibCheck: true, skipLibCheck: true,
@ -73,7 +71,7 @@ async function writeJs(source, inputFilename, outputPath) {
try { try {
const processed = await svelte.preprocess(source, preprocessOptions); const processed = await svelte.preprocess(source, preprocessOptions);
const result = svelte.compile(processed.toString(), { const result = svelte.compile(processed.toString!(), {
format: "esm", format: "esm",
generate: "dom", generate: "dom",
filename: outputPath, filename: outputPath,