Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ js_library(
name = "scheduling_kit",
srcs = [":scheduling_kit_build"],
tags = ["manual"],
# Runtime dependencies (package.json "dependencies") that consumers do not
# provide themselves. Declaring them here carries their npm package store
# infos through //:pkg so Bazel consumers that link this module via
# npm_link_package (e.g. scheduling-bridge) get the dep store entries
# linked next to the package.
#
# `effect` is intentionally NOT linked: consumers declare their own copy
# and effect values cross the package boundary (e.g. re-exported Errors),
# so a second linked copy would fork runtime identity (instanceof) and
# break consumer declaration emit (TS2742) with duplicate type roots.
# Peer dependencies are likewise excluded; consumers provide them.
deps = [
":node_modules/drizzle-orm",
":node_modules/zod",
],
visibility = ["//visibility:public"],
)

Expand Down
35 changes: 29 additions & 6 deletions scripts/svelte-package-bazel-wrapper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,45 +122,68 @@ function prepareWritableProject(inputDir) {
return { tempRoot, workDir };
}

const forwardedArgs = [];
const parsedArgs = [];
let resolvedInput;
let outputDir = "dist";
for (let index = 0; index < process.argv.length - 2; index += 1) {
const arg = process.argv[index + 2];

if (arg === "-i" || arg === "--input") {
resolvedInput = resolveExistingPath(process.argv[index + 3]);
forwardedArgs.push(arg, "src");
parsedArgs.push({ kind: "input", flag: arg });
index += 1;
continue;
}

if (arg.startsWith("--input=")) {
resolvedInput = resolveExistingPath(arg.slice("--input=".length));
forwardedArgs.push("--input=src");
parsedArgs.push({ kind: "input", flag: "--input=" });
continue;
}

if (arg === "-o" || arg === "--output") {
outputDir = process.argv[index + 3];
forwardedArgs.push(arg, path.resolve(originalCwd, outputDir));
parsedArgs.push({ kind: "output", flag: arg });
index += 1;
continue;
}

if (arg.startsWith("--output=")) {
outputDir = arg.slice("--output=".length);
forwardedArgs.push(`--output=${path.resolve(originalCwd, outputDir)}`);
parsedArgs.push({ kind: "output", flag: "--output=" });
continue;
}

forwardedArgs.push(arg);
parsedArgs.push({ kind: "raw", value: arg });
}

if (!resolvedInput) {
throw new Error("Missing required svelte-package input directory");
}

// Anchor the output directory next to the resolved input tree artifact, which
// lives in the declared output package directory of this module. Resolving
// against the action cwd (BAZEL_BINDIR) breaks when this module is built as a
// Bazel external module (bazel_dep consumer): declared outputs live under
// bazel-out/.../bin/external/<repo>/, while cwd stays at the bindir root, so
// svelte-package would write outside the declared output tree and Bazel would
// silently package an empty dist/.
const resolvedOutput = path.isAbsolute(outputDir)
? outputDir
: path.resolve(path.dirname(resolvedInput), outputDir);

const forwardedArgs = parsedArgs.flatMap((entry) => {
if (entry.kind === "input") {
return entry.flag === "--input=" ? ["--input=src"] : [entry.flag, "src"];
}
if (entry.kind === "output") {
return entry.flag === "--output="
? [`--output=${resolvedOutput}`]
: [entry.flag, resolvedOutput];
}
return [entry.value];
});

const { tempRoot, workDir } = prepareWritableProject(resolvedInput);
const result = spawnSync(
process.execPath,
Expand Down
Loading