diff --git a/ts/svelte/svelte.bzl b/ts/svelte/svelte.bzl index 07ebea648..4e6ffd3bd 100644 --- a/ts/svelte/svelte.bzl +++ b/ts/svelte/svelte.bzl @@ -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"}, diff --git a/ts/svelte/svelte.ts b/ts/svelte/svelte.ts index e44804adc..958544446 100644 --- a/ts/svelte/svelte.ts +++ b/ts/svelte/svelte.ts @@ -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;