diff --git a/BUILD.bazel b/BUILD.bazel index 8340e9b..99f3b46 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -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"], ) diff --git a/scripts/svelte-package-bazel-wrapper.mjs b/scripts/svelte-package-bazel-wrapper.mjs index 33c3215..df63166 100644 --- a/scripts/svelte-package-bazel-wrapper.mjs +++ b/scripts/svelte-package-bazel-wrapper.mjs @@ -122,7 +122,7 @@ 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) { @@ -130,37 +130,60 @@ for (let index = 0; index < process.argv.length - 2; index += 1) { 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//, 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,