mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
allow passing sass deps to svelte compile/check
This commit is contained in:
parent
2d417b1160
commit
6cee43631a
2 changed files with 21 additions and 7 deletions
|
@ -1,5 +1,9 @@
|
||||||
load("@npm//svelte-check:index.bzl", _svelte_check = "svelte_check_test")
|
load("@npm//svelte-check:index.bzl", _svelte_check = "svelte_check_test")
|
||||||
load("@build_bazel_rules_nodejs//:providers.bzl", "declaration_info", "run_node")
|
load("@build_bazel_rules_nodejs//:providers.bzl", "declaration_info", "run_node")
|
||||||
|
load("@io_bazel_rules_sass//:defs.bzl", "SassInfo")
|
||||||
|
|
||||||
|
def _get_sources(deps):
|
||||||
|
return depset([], transitive = [dep[SassInfo].transitive_sources for dep in deps])
|
||||||
|
|
||||||
def _svelte(ctx):
|
def _svelte(ctx):
|
||||||
args = ctx.actions.args()
|
args = ctx.actions.args()
|
||||||
|
@ -10,13 +14,17 @@ def _svelte(ctx):
|
||||||
args.add(ctx.outputs.mjs.path)
|
args.add(ctx.outputs.mjs.path)
|
||||||
args.add(ctx.outputs.dts.path)
|
args.add(ctx.outputs.dts.path)
|
||||||
args.add(ctx.outputs.css.path)
|
args.add(ctx.outputs.css.path)
|
||||||
|
args.add(ctx.var["BINDIR"])
|
||||||
|
args.add(ctx.var["GENDIR"])
|
||||||
args.add_all(ctx.files._shims)
|
args.add_all(ctx.files._shims)
|
||||||
|
|
||||||
|
deps = _get_sources(ctx.attr.deps).to_list()
|
||||||
|
|
||||||
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] + ctx.files._shims,
|
inputs = [ctx.file.entry_point] + ctx.files._shims + deps,
|
||||||
mnemonic = "Svelte",
|
mnemonic = "Svelte",
|
||||||
arguments = [args],
|
arguments = [args],
|
||||||
)
|
)
|
||||||
|
@ -29,6 +37,7 @@ svelte = rule(
|
||||||
implementation = _svelte,
|
implementation = _svelte,
|
||||||
attrs = {
|
attrs = {
|
||||||
"entry_point": attr.label(allow_single_file = True),
|
"entry_point": attr.label(allow_single_file = True),
|
||||||
|
"deps": attr.label_list(),
|
||||||
"_svelte_bin": attr.label(
|
"_svelte_bin": attr.label(
|
||||||
default = Label("//ts/svelte:svelte_bin"),
|
default = Label("//ts/svelte:svelte_bin"),
|
||||||
executable = True,
|
executable = True,
|
||||||
|
@ -46,11 +55,12 @@ svelte = rule(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
def compile_svelte(name, srcs):
|
def compile_svelte(name, srcs, deps = []):
|
||||||
for src in srcs:
|
for src in srcs:
|
||||||
svelte(
|
svelte(
|
||||||
name = src.replace(".svelte", ""),
|
name = src.replace(".svelte", ""),
|
||||||
entry_point = src,
|
entry_point = src,
|
||||||
|
deps = deps,
|
||||||
)
|
)
|
||||||
|
|
||||||
native.filegroup(
|
native.filegroup(
|
||||||
|
@ -74,5 +84,5 @@ def svelte_check(name = "svelte_check", srcs = []):
|
||||||
"//ts/lib:backend_proto",
|
"//ts/lib:backend_proto",
|
||||||
"@npm//sass",
|
"@npm//sass",
|
||||||
] + srcs,
|
] + srcs,
|
||||||
link_workspace_root = True,
|
env = {"SASS_PATH": "$(rootpath //ts:tsconfig.json)/../.."},
|
||||||
)
|
)
|
||||||
|
|
|
@ -146,9 +146,13 @@ async function writeJs(
|
||||||
source: string,
|
source: string,
|
||||||
inputFilename: string,
|
inputFilename: string,
|
||||||
outputJsPath: string,
|
outputJsPath: string,
|
||||||
outputCssPath: string
|
outputCssPath: string,
|
||||||
|
binDir: string,
|
||||||
|
genDir: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const preprocessOptions = preprocess({});
|
const preprocessOptions = preprocess({
|
||||||
|
scss: { includePaths: [binDir, genDir] },
|
||||||
|
});
|
||||||
preprocessOptions.filename = inputFilename;
|
preprocessOptions.filename = inputFilename;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -179,13 +183,13 @@ async function writeJs(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function compileSvelte(args) {
|
async function compileSvelte(args) {
|
||||||
const [sveltePath, mjsPath, dtsPath, cssPath, ...tsLibs] = 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 + ".ts";
|
const mockTsPath = sveltePath + ".ts";
|
||||||
await writeTs(svelteSource, sveltePath, mockTsPath);
|
await writeTs(svelteSource, sveltePath, mockTsPath);
|
||||||
await writeDts(mockTsPath, dtsPath, tsLibs);
|
await writeDts(mockTsPath, dtsPath, tsLibs);
|
||||||
await writeJs(svelteSource, sveltePath, mjsPath, cssPath);
|
await writeJs(svelteSource, sveltePath, mjsPath, cssPath, binDir, genDir);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue