svelte needs its shims to generate prop typing

I erroneously removed them near the end of the ts_project work, and
didn't realise the properties had broken.
This commit is contained in:
Damien Elmes 2021-10-07 21:29:21 +10:00
parent 1aaf8fce1e
commit 79ceb89637
2 changed files with 13 additions and 20 deletions

View file

@ -3,17 +3,6 @@ load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo", "declaratio
load("@io_bazel_rules_sass//:defs.bzl", "SassInfo")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
def _get_dep_sources(dep):
if SassInfo in dep:
return dep[SassInfo].transitive_sources
elif DeclarationInfo in dep:
return dep[DeclarationInfo].transitive_declarations
else:
return []
def _get_sources(deps):
return depset([], transitive = [_get_dep_sources(dep) for dep in deps])
def _svelte(ctx):
args = ctx.actions.args()
args.use_param_file("@%s", use_always = True)
@ -25,18 +14,19 @@ def _svelte(ctx):
args.add(ctx.outputs.css.path)
args.add(ctx.var["BINDIR"])
args.add(ctx.var["GENDIR"])
args.add_all(ctx.files._shims)
ctx.actions.run(
execution_requirements = {"supports-workers": "1"},
executable = ctx.executable._svelte_bin,
outputs = [ctx.outputs.mjs, ctx.outputs.dts, ctx.outputs.css],
inputs = [ctx.file.entry_point],
inputs = [ctx.file.entry_point] + ctx.files._shims,
mnemonic = "Svelte",
arguments = [args],
)
return [
declaration_info(depset([ctx.outputs.dts]), deps = []),
declaration_info(depset([ctx.outputs.dts]), deps = [ctx.attr._shims]),
]
svelte = rule(
@ -48,6 +38,10 @@ svelte = rule(
executable = True,
cfg = "host",
),
"_shims": attr.label(
default = Label("@npm//svelte2tsx:svelte2tsx__typings"),
allow_files = True,
),
},
outputs = {
"mjs": "%{name}.svelte.mjs",
@ -82,7 +76,6 @@ def svelte_check(name = "svelte_check", srcs = []):
"--fail-on-hints",
],
data = [
"//ts:tsconfig_bin",
"@npm//sass",
] + srcs,
env = {"SASS_PATH": "ts/sass"},

View file

@ -90,8 +90,8 @@ const languageServiceHost: ts.LanguageServiceHost = {
const languageService = ts.createLanguageService(languageServiceHost);
function compile(tsPath: string) {
parsedCommandLine.fileNames = [tsPath];
function compile(tsPath: string, tsLibs: string[]) {
parsedCommandLine.fileNames = [tsPath, ...tsLibs];
const program = languageService.getProgram()!;
const tsHost = ts.createCompilerHost(parsedCommandLine.options);
const createdFiles = {};
@ -124,8 +124,8 @@ function readFile(file) {
});
}
async function writeDts(tsPath, dtsPath) {
const dtsSource = compile(tsPath);
async function writeDts(tsPath, dtsPath, tsLibs) {
const dtsSource = compile(tsPath, tsLibs);
await writeFile(dtsPath, dtsSource);
}
@ -192,12 +192,12 @@ async function writeJs(
}
async function compileSvelte(args) {
const [sveltePath, mjsPath, dtsPath, cssPath, binDir, genDir] = args;
const [sveltePath, mjsPath, dtsPath, cssPath, binDir, genDir, ...tsLibs] = args;
const svelteSource = (await readFile(sveltePath)) as string;
const mockTsPath = sveltePath + ".tsx";
writeTs(svelteSource, sveltePath, mockTsPath);
await writeDts(mockTsPath, dtsPath);
await writeDts(mockTsPath, dtsPath, tsLibs);
await writeJs(svelteSource, sveltePath, mjsPath, cssPath, binDir, genDir);
return true;