mirror of
https://github.com/ankitects/anki.git
synced 2025-12-10 21:36:55 -05:00
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:
parent
1aaf8fce1e
commit
79ceb89637
2 changed files with 13 additions and 20 deletions
|
|
@ -3,17 +3,6 @@ load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo", "declaratio
|
||||||
load("@io_bazel_rules_sass//:defs.bzl", "SassInfo")
|
load("@io_bazel_rules_sass//:defs.bzl", "SassInfo")
|
||||||
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
|
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):
|
def _svelte(ctx):
|
||||||
args = ctx.actions.args()
|
args = ctx.actions.args()
|
||||||
args.use_param_file("@%s", use_always = True)
|
args.use_param_file("@%s", use_always = True)
|
||||||
|
|
@ -25,18 +14,19 @@ def _svelte(ctx):
|
||||||
args.add(ctx.outputs.css.path)
|
args.add(ctx.outputs.css.path)
|
||||||
args.add(ctx.var["BINDIR"])
|
args.add(ctx.var["BINDIR"])
|
||||||
args.add(ctx.var["GENDIR"])
|
args.add(ctx.var["GENDIR"])
|
||||||
|
args.add_all(ctx.files._shims)
|
||||||
|
|
||||||
ctx.actions.run(
|
ctx.actions.run(
|
||||||
execution_requirements = {"supports-workers": "1"},
|
execution_requirements = {"supports-workers": "1"},
|
||||||
executable = ctx.executable._svelte_bin,
|
executable = ctx.executable._svelte_bin,
|
||||||
outputs = [ctx.outputs.mjs, ctx.outputs.dts, ctx.outputs.css],
|
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",
|
mnemonic = "Svelte",
|
||||||
arguments = [args],
|
arguments = [args],
|
||||||
)
|
)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
declaration_info(depset([ctx.outputs.dts]), deps = []),
|
declaration_info(depset([ctx.outputs.dts]), deps = [ctx.attr._shims]),
|
||||||
]
|
]
|
||||||
|
|
||||||
svelte = rule(
|
svelte = rule(
|
||||||
|
|
@ -48,6 +38,10 @@ svelte = rule(
|
||||||
executable = True,
|
executable = True,
|
||||||
cfg = "host",
|
cfg = "host",
|
||||||
),
|
),
|
||||||
|
"_shims": attr.label(
|
||||||
|
default = Label("@npm//svelte2tsx:svelte2tsx__typings"),
|
||||||
|
allow_files = True,
|
||||||
|
),
|
||||||
},
|
},
|
||||||
outputs = {
|
outputs = {
|
||||||
"mjs": "%{name}.svelte.mjs",
|
"mjs": "%{name}.svelte.mjs",
|
||||||
|
|
@ -82,7 +76,6 @@ def svelte_check(name = "svelte_check", srcs = []):
|
||||||
"--fail-on-hints",
|
"--fail-on-hints",
|
||||||
],
|
],
|
||||||
data = [
|
data = [
|
||||||
"//ts:tsconfig_bin",
|
|
||||||
"@npm//sass",
|
"@npm//sass",
|
||||||
] + srcs,
|
] + srcs,
|
||||||
env = {"SASS_PATH": "ts/sass"},
|
env = {"SASS_PATH": "ts/sass"},
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,8 @@ const languageServiceHost: ts.LanguageServiceHost = {
|
||||||
|
|
||||||
const languageService = ts.createLanguageService(languageServiceHost);
|
const languageService = ts.createLanguageService(languageServiceHost);
|
||||||
|
|
||||||
function compile(tsPath: string) {
|
function compile(tsPath: string, tsLibs: string[]) {
|
||||||
parsedCommandLine.fileNames = [tsPath];
|
parsedCommandLine.fileNames = [tsPath, ...tsLibs];
|
||||||
const program = languageService.getProgram()!;
|
const program = languageService.getProgram()!;
|
||||||
const tsHost = ts.createCompilerHost(parsedCommandLine.options);
|
const tsHost = ts.createCompilerHost(parsedCommandLine.options);
|
||||||
const createdFiles = {};
|
const createdFiles = {};
|
||||||
|
|
@ -124,8 +124,8 @@ function readFile(file) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function writeDts(tsPath, dtsPath) {
|
async function writeDts(tsPath, dtsPath, tsLibs) {
|
||||||
const dtsSource = compile(tsPath);
|
const dtsSource = compile(tsPath, tsLibs);
|
||||||
await writeFile(dtsPath, dtsSource);
|
await writeFile(dtsPath, dtsSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,12 +192,12 @@ async function writeJs(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compileSvelte(args) {
|
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 svelteSource = (await readFile(sveltePath)) as string;
|
||||||
|
|
||||||
const mockTsPath = sveltePath + ".tsx";
|
const mockTsPath = sveltePath + ".tsx";
|
||||||
writeTs(svelteSource, sveltePath, mockTsPath);
|
writeTs(svelteSource, sveltePath, mockTsPath);
|
||||||
await writeDts(mockTsPath, dtsPath);
|
await writeDts(mockTsPath, dtsPath, tsLibs);
|
||||||
await writeJs(svelteSource, sveltePath, mjsPath, cssPath, binDir, genDir);
|
await writeJs(svelteSource, sveltePath, mjsPath, cssPath, binDir, genDir);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue