@tailor-platform/sdk 1.79.0 → 1.80.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,18 @@
1
1
  import { n as isSdkBranded } from "./brand-Eo4pLXPJ.mjs";
2
2
  import { t as assertDefined } from "./assert-DBxo8jPo.mjs";
3
3
  import { a as parseBoolean, n as logger, r as styles } from "./logger-BwS4ppwO.mjs";
4
- import { a as TailorFieldSchema, i as AuthInvokerSchema, n as ExecutorSchema, o as loadFilesWithIgnores, r as AuthConfigSchema, s as functionSchema, t as createExecutorService } from "./service-D12iQGcS.mjs";
4
+ import { a as TailorFieldSchema, i as AuthInvokerSchema, n as ExecutorSchema, o as loadFilesWithIgnores, r as AuthConfigSchema, s as functionSchema, t as createExecutorService } from "./service-CDPatibu.mjs";
5
5
  import { t as multiline } from "./multiline-sfHpTZZK.mjs";
6
6
  import { t as isPluginGeneratedType } from "./type-source-DH_LH20p.mjs";
7
7
  import { t as userAgent } from "./user-agent-DX2Jnw0-.mjs";
8
8
  import { builtinModules, createRequire } from "node:module";
9
9
  import { z } from "zod";
10
10
  import { create } from "@bufbuild/protobuf";
11
- import * as fs$1 from "node:fs";
12
- import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
11
+ import * as fs from "node:fs";
12
+ import { readFileSync } from "node:fs";
13
13
  import { MethodOptions_IdempotencyLevel } from "@bufbuild/protobuf/wkt";
14
14
  import * as path from "pathe";
15
- import { join, resolve } from "pathe";
15
+ import { resolve } from "pathe";
16
16
  import { pathToFileURL } from "node:url";
17
17
  import * as os from "node:os";
18
18
  import { OAuth2Client } from "@badgateway/oauth2-client";
@@ -22,7 +22,6 @@ import pLimit from "p-limit";
22
22
  import { resolveTSConfig } from "pkg-types";
23
23
  import * as crypto from "node:crypto";
24
24
  import * as rolldown from "rolldown";
25
- import * as fs from "node:fs/promises";
26
25
  import { parseSync } from "oxc-parser";
27
26
  import * as inflection from "inflection";
28
27
  import * as globals from "globals";
@@ -307,8 +306,10 @@ function connectCodeName(error) {
307
306
  *
308
307
  * Membership is deliberately an allowlist, not `startsWith("Create")`: swallowing
309
308
  * synthesizes an empty response (see `synthesizeEmptyUnaryResponse`), which is only
310
- * safe when every caller ignores the response body. These are the deploy/apply
311
- * resource creations that fire under heavy parallelism and discard their response.
309
+ * safe when every caller tolerates an empty response body. These are the deploy/apply
310
+ * resource creations that fire under heavy parallelism and discard their response
311
+ * except `CreateSecretManagerSecret`, whose caller reads `secret.updateTime` but
312
+ * degrades safely when it is absent (the next deploy re-updates the secret).
312
313
  *
313
314
  * Intentionally excluded because their callers read the response body — swallowing
314
315
  * would hand back an empty message and corrupt downstream state:
@@ -682,7 +683,7 @@ function hashContent(content) {
682
683
  * @returns Hex-encoded SHA-256 hash of the file content
683
684
  */
684
685
  function hashFile(filePath) {
685
- const content = fs$1.readFileSync(filePath);
686
+ const content = fs.readFileSync(filePath);
686
687
  return crypto.createHash("sha256").update(content).digest("hex");
687
688
  }
688
689
  /**
@@ -811,7 +812,10 @@ function createBundleCache(store) {
811
812
  return;
812
813
  }
813
814
  if (currentHash !== entry.inputHash) return;
814
- return store.restoreBundleContent(cacheKey);
815
+ const content = store.restoreBundleContent(cacheKey);
816
+ const output = entry.outputFiles.find((file) => file.outputPath === cacheKey);
817
+ if (content === void 0 || !output || hashContent(content) !== output.contentHash) return;
818
+ return content;
815
819
  }
816
820
  function save(params) {
817
821
  const { kind, namespace, name, sourceFile, content, dependencyPaths, contextHash } = params;
@@ -858,7 +862,7 @@ function resolveRelativePluginImportPath(pluginImportPath, baseDirs) {
858
862
  if (!pluginImportPath.startsWith(".")) return null;
859
863
  for (const baseDir of baseDirs) {
860
864
  const absolutePath = path.resolve(baseDir, pluginImportPath);
861
- if (fs$1.existsSync(absolutePath)) return absolutePath;
865
+ if (fs.existsSync(absolutePath)) return absolutePath;
862
866
  }
863
867
  return null;
864
868
  }
@@ -942,13 +946,13 @@ function generatePluginExecutorFiles(executors, outputDir, typeGenerationResult,
942
946
  function generateSingleExecutorFile(info, outputDir, typeGenerationResult, sourceTypeInfoMap, baseDirs = []) {
943
947
  const pluginDir = sanitizePluginId$1(info.pluginId);
944
948
  const executorOutputDir = path.join(outputDir, pluginDir, "executors");
945
- fs$1.mkdirSync(executorOutputDir, { recursive: true });
949
+ fs.mkdirSync(executorOutputDir, { recursive: true });
946
950
  const fileName = sanitizeExecutorFileName(info.executor.name);
947
951
  const filePath = path.join(executorOutputDir, `${fileName}.ts`);
948
952
  let content;
949
953
  if (isPluginExecutorWithFile(info.executor)) content = generateExecutorFileContentNew(info, info.executor, outputDir, typeGenerationResult, sourceTypeInfoMap, baseDirs);
950
954
  else content = generateExecutorFileContentLegacy(info.executor);
951
- fs$1.writeFileSync(filePath, content);
955
+ fs.writeFileSync(filePath, content);
952
956
  return filePath;
953
957
  }
954
958
  /**
@@ -1180,7 +1184,7 @@ function extractDynamicImportSpecifier(resolve) {
1180
1184
  function resolvePluginBaseDir(pluginImportPath, baseDirs) {
1181
1185
  if (pluginImportPath.startsWith(".")) {
1182
1186
  const resolvedPath = resolveRelativePluginImportPath(pluginImportPath, baseDirs) ?? path.resolve(baseDirs[0] ?? process.cwd(), pluginImportPath);
1183
- if (fs$1.existsSync(resolvedPath)) return fs$1.statSync(resolvedPath).isDirectory() ? resolvedPath : path.dirname(resolvedPath);
1187
+ if (fs.existsSync(resolvedPath)) return fs.statSync(resolvedPath).isDirectory() ? resolvedPath : path.dirname(resolvedPath);
1184
1188
  return path.extname(resolvedPath) ? path.dirname(resolvedPath) : resolvedPath;
1185
1189
  }
1186
1190
  for (const baseDir of baseDirs) try {
@@ -1267,11 +1271,11 @@ function generatePluginTypeFiles(types, outputDir) {
1267
1271
  seenTypeNames.set(info.type.name, info);
1268
1272
  const pluginDir = sanitizePluginId(info.pluginId);
1269
1273
  const typeOutputDir = path.join(outputDir, pluginDir, "types");
1270
- fs$1.mkdirSync(typeOutputDir, { recursive: true });
1274
+ fs.mkdirSync(typeOutputDir, { recursive: true });
1271
1275
  const fileName = `${toKebabCase(info.type.name)}.ts`;
1272
1276
  const filePath = path.join(typeOutputDir, fileName);
1273
1277
  const content = generateTypeFileContent(info);
1274
- fs$1.writeFileSync(filePath, content);
1278
+ fs.writeFileSync(filePath, content);
1275
1279
  generatedFiles.push(filePath);
1276
1280
  const relativePath = path.relative(outputDir, filePath);
1277
1281
  typeFilePaths.set(info.type.name, relativePath);
@@ -1392,20 +1396,6 @@ function toCamelCase(str) {
1392
1396
  return result.charAt(0).toLowerCase() + result.slice(1);
1393
1397
  }
1394
1398
 
1395
- //#endregion
1396
- //#region src/cli/services/stale-cleanup.ts
1397
- /**
1398
- * Remove stale `.entry.js` files from the output directory.
1399
- *
1400
- * Must be called before parallel bundling; concurrent builds
1401
- * sharing the same output directory would otherwise conflict.
1402
- * @param outputDir - Directory to clean
1403
- */
1404
- async function removeStaleEntryFiles(outputDir) {
1405
- const files = await fs.readdir(outputDir);
1406
- await Promise.all(files.filter((file) => file.endsWith(".entry.js")).map((file) => fs.rm(path.join(outputDir, file), { force: true })));
1407
- }
1408
-
1409
1399
  //#endregion
1410
1400
  //#region src/cli/services/workflow/ast-utils.ts
1411
1401
  /**
@@ -1805,16 +1795,17 @@ function createModuleBindings(program, source) {
1805
1795
  * Build trigger context from configured workflow source files.
1806
1796
  * @param workflowConfig - Workflow file loading configuration
1807
1797
  * @param authNamespace - Auth service namespace used by workflow trigger options
1798
+ * @param baseDir - Directory the workflow config's file patterns are resolved against (defaults to process.cwd())
1808
1799
  * @returns Module-local workflow and job binding metadata
1809
1800
  */
1810
- async function buildTriggerContext(workflowConfig, authNamespace) {
1801
+ async function buildTriggerContext(workflowConfig, authNamespace, baseDir = process.cwd()) {
1811
1802
  const modules = /* @__PURE__ */ new Map();
1812
1803
  if (!workflowConfig) return {
1813
1804
  modules,
1814
1805
  authNamespace
1815
1806
  };
1816
- for (const file of loadFilesWithIgnores(workflowConfig)) try {
1817
- const source = await fs$1.promises.readFile(file, "utf-8");
1807
+ for (const file of loadFilesWithIgnores(workflowConfig, baseDir)) try {
1808
+ const source = await fs.promises.readFile(file, "utf-8");
1818
1809
  const { program } = parseSync("input.ts", source);
1819
1810
  modules.set(normalizeFilePath(file), createModuleBindings(program, source));
1820
1811
  } catch (error) {
@@ -2133,34 +2124,77 @@ const platformBundleDefinePlugin = {
2133
2124
  }
2134
2125
  };
2135
2126
 
2127
+ //#endregion
2128
+ //#region src/cli/shared/resolve-tsconfig.ts
2129
+ const warnedBaseDirs = /* @__PURE__ */ new Set();
2130
+ /**
2131
+ * Resolve the nearest tsconfig.json for baseDir, falling back to the tsconfig
2132
+ * resolved from the invocation cwd when baseDir's own ancestry has none.
2133
+ * @param baseDir - Directory to resolve the tsconfig against
2134
+ * @returns Absolute path to the resolved tsconfig.json, or undefined if none was found
2135
+ */
2136
+ async function resolveTSConfigWithFallback(baseDir) {
2137
+ const tsconfig = await tryResolve(baseDir);
2138
+ if (tsconfig || baseDir === process.cwd()) return tsconfig;
2139
+ const fallback = await tryResolve(process.cwd());
2140
+ if (fallback && !warnedBaseDirs.has(baseDir)) {
2141
+ warnedBaseDirs.add(baseDir);
2142
+ logger.warn(`No tsconfig found from "${baseDir}"; falling back to the tsconfig resolved from process.cwd(). Move (or extend) a tsconfig into this directory before v2, when this fallback will be removed.`);
2143
+ }
2144
+ return fallback;
2145
+ }
2146
+ async function tryResolve(dir) {
2147
+ try {
2148
+ return await resolveTSConfig(dir);
2149
+ } catch {
2150
+ return;
2151
+ }
2152
+ }
2153
+
2154
+ //#endregion
2155
+ //#region src/cli/shared/virtual-entry.ts
2156
+ /**
2157
+ * Create an in-memory rolldown entry module with a deterministic ID.
2158
+ * @param name - Logical entry name
2159
+ * @param code - Entry module source
2160
+ * @param sourceType - Parser type for the generated module
2161
+ * @returns Rolldown input and plugin for loading the entry
2162
+ */
2163
+ function createVirtualEntry(name, code, sourceType = "js") {
2164
+ const input = `tailor-sdk-entry:${name}.${sourceType}`;
2165
+ const resolvedId = `\0${input}`;
2166
+ return {
2167
+ input,
2168
+ plugin: {
2169
+ name: "tailor-sdk-virtual-entry",
2170
+ resolveId(source, importer) {
2171
+ return source === input && importer === void 0 ? resolvedId : null;
2172
+ },
2173
+ load(id) {
2174
+ return id === resolvedId ? code : null;
2175
+ }
2176
+ }
2177
+ };
2178
+ }
2179
+
2136
2180
  //#endregion
2137
2181
  //#region src/cli/services/auth/bundler.ts
2138
2182
  /**
2139
2183
  * Bundle a single auth hook handler.
2140
2184
  *
2141
2185
  * Follows the same pattern as the executor bundler:
2142
- * 1. Generate an entry file that re-exports the handler as `main`
2186
+ * 1. Generate an in-memory entry module that re-exports the handler as `main`
2143
2187
  * 2. Bundle with rolldown + tree-shaking
2144
2188
  * @param options - Bundle options
2145
2189
  * @returns Map of function name to bundled code
2146
2190
  */
2147
2191
  async function bundleAuthHooks(options) {
2148
- const { configPath, authName, handlerAccessPath, env = {}, triggerContext, cache, inlineSourcemap, bundleLogLevel = "DEBUG" } = options;
2192
+ const { configPath, authName, handlerAccessPath, env = {}, triggerContext, cache, inlineSourcemap, bundleLogLevel = "DEBUG", baseDir } = options;
2149
2193
  logger.newline();
2150
2194
  logger.log(`Bundling auth hook for ${styles.info(`"${authName}"`)}`);
2151
- const outputDir = path.resolve(getDistDir(), "auth-hooks");
2152
- fs$1.mkdirSync(outputDir, { recursive: true });
2153
- await removeStaleEntryFiles(outputDir);
2154
- let tsconfig;
2155
- try {
2156
- tsconfig = await resolveTSConfig();
2157
- } catch {
2158
- tsconfig = void 0;
2159
- }
2160
- const functionName = `auth-hook--${authName}--before-login`;
2161
2195
  const absoluteConfigPath = path.resolve(configPath);
2162
- const serializedTriggerContext = serializeTriggerContext(triggerContext);
2163
- const sortedEnvPrefix = JSON.stringify(Object.fromEntries(Object.entries(env).toSorted(([a], [b]) => a.localeCompare(b))));
2196
+ const tsconfig = await resolveTSConfigWithFallback(baseDir);
2197
+ const functionName = `auth-hook--${authName}--before-login`;
2164
2198
  const code = await withCache({
2165
2199
  cache,
2166
2200
  kind: "auth-hook",
@@ -2168,14 +2202,13 @@ async function bundleAuthHooks(options) {
2168
2202
  sourceFile: absoluteConfigPath,
2169
2203
  contextHash: computeBundlerContextHash({
2170
2204
  sourceFile: absoluteConfigPath,
2171
- serializedTriggerContext,
2205
+ serializedTriggerContext: serializeTriggerContext(triggerContext),
2172
2206
  tsconfig,
2173
2207
  inlineSourcemap,
2174
2208
  bundleLogLevel,
2175
- prefix: sortedEnvPrefix
2209
+ prefix: JSON.stringify(Object.fromEntries(Object.entries(env).toSorted(([a], [b]) => a.localeCompare(b))))
2176
2210
  }),
2177
2211
  async build(cachePlugins) {
2178
- const entryPath = path.join(outputDir, `${functionName}.entry.js`);
2179
2212
  const entryContent = multiline`
2180
2213
  import _config from "${absoluteConfigPath}";
2181
2214
  const __auth_hook_function = _config.${handlerAccessPath};
@@ -2184,12 +2217,13 @@ async function bundleAuthHooks(options) {
2184
2217
  return await __auth_hook_function({ ...args, env });
2185
2218
  }
2186
2219
  `;
2187
- fs$1.writeFileSync(entryPath, entryContent);
2220
+ const entry = createVirtualEntry(`auth-hook:${functionName}`, entryContent);
2188
2221
  const triggerPlugin = createTriggerTransformPlugin(triggerContext);
2189
- const plugins = triggerPlugin ? [triggerPlugin] : [];
2222
+ const plugins = [entry.plugin];
2223
+ if (triggerPlugin) plugins.push(triggerPlugin);
2190
2224
  plugins.push(platformBundleDefinePlugin, ...cachePlugins);
2191
2225
  return (await rolldown.build({
2192
- input: entryPath,
2226
+ input: entry.input,
2193
2227
  write: false,
2194
2228
  output: {
2195
2229
  format: "esm",
@@ -3341,7 +3375,7 @@ function buildMinimalEntryFromResolved(imports, declarations, fnSource, sourceFi
3341
3375
  ].join("\n");
3342
3376
  }
3343
3377
  async function bundleScriptTarget(args) {
3344
- const { fn, kind, sourceFilePath, sourceBindings, tempDir, targetIndex, tsconfig } = args;
3378
+ const { fn, kind, sourceFilePath, sourceBindings, typeName, targetIndex, tsconfig } = args;
3345
3379
  const context = `${kind} in ${sourceFilePath}`;
3346
3380
  const fnSource = stringifyFunction(fn);
3347
3381
  const inlineExpr = assertParsableExpression(`(${fnSource})({ value: _value, data: _data, user: ${tailorUserMap} })`, context);
@@ -3351,11 +3385,10 @@ async function bundleScriptTarget(args) {
3351
3385
  if (unresolved.length > 0) throw new Error(`${context} captures unresolvable variables (${unresolved.join(", ")}). Hooks and validators must not reference variables that cannot be resolved from the source file.
3352
3386
  ${kind}: ${fnSource}`);
3353
3387
  const entryContent = buildMinimalEntryFromResolved(imports, declarations, fnSource, sourceFilePath);
3354
- const entryPath = join(tempDir, `tailordb-script-${targetIndex}.entry.ts`);
3355
- writeFileSync(entryPath, entryContent);
3388
+ const entry = createVirtualEntry(`tailordb-script:${typeName}:${targetIndex}`, entryContent, "ts");
3356
3389
  const bundledCode = (await rolldown.build({
3357
- plugins: [platformBundleDefinePlugin],
3358
- input: entryPath,
3390
+ plugins: [entry.plugin, platformBundleDefinePlugin],
3391
+ input: entry.input,
3359
3392
  write: false,
3360
3393
  output: {
3361
3394
  format: "cjs",
@@ -3385,27 +3418,18 @@ async function precompileTailorDBTypeScripts(type, sourceFilePath, tsconfig) {
3385
3418
  const targets = collectScriptTargets(type);
3386
3419
  if (targets.length === 0) return;
3387
3420
  const sourceBindings = collectSourceBindings(sourceFilePath);
3388
- const tempDir = resolve(getDistDir(), "hooks-validate-scripts", type.name);
3389
- mkdirSync(tempDir, { recursive: true });
3390
- try {
3391
- const results = await Promise.allSettled(targets.map((target, index) => bundleScriptTarget({
3392
- fn: target.fn,
3393
- kind: target.kind,
3394
- sourceFilePath,
3395
- sourceBindings,
3396
- tempDir,
3397
- targetIndex: index,
3398
- tsconfig
3399
- })));
3400
- const firstError = results.find((r) => r.status === "rejected");
3401
- if (firstError) throw firstError.reason;
3402
- for (const [index, result] of results.entries()) if (result.status === "fulfilled") setPrecompiledScriptExpr(assertDefined(targets[index], `bundle target at index ${index} missing`).fn, result.value);
3403
- } finally {
3404
- rmSync(tempDir, {
3405
- recursive: true,
3406
- force: true
3407
- });
3408
- }
3421
+ const results = await Promise.allSettled(targets.map((target, index) => bundleScriptTarget({
3422
+ fn: target.fn,
3423
+ kind: target.kind,
3424
+ sourceFilePath,
3425
+ sourceBindings,
3426
+ typeName: type.name,
3427
+ targetIndex: index,
3428
+ tsconfig
3429
+ })));
3430
+ const firstError = results.find((r) => r.status === "rejected");
3431
+ if (firstError) throw firstError.reason;
3432
+ for (const [index, result] of results.entries()) if (result.status === "fulfilled") setPrecompiledScriptExpr(assertDefined(targets[index], `bundle target at index ${index} missing`).fn, result.value);
3409
3433
  }
3410
3434
 
3411
3435
  //#endregion
@@ -3535,7 +3559,7 @@ function formatTailorDBTypeNameSource(source) {
3535
3559
  * @returns A new TailorDBService instance
3536
3560
  */
3537
3561
  function createTailorDBService(params) {
3538
- const { namespace, config, pluginManager } = params;
3562
+ const { namespace, config, pluginManager, baseDir } = params;
3539
3563
  const createRawTypesByName = () => Object.create(null);
3540
3564
  const rawTypes = Object.create(null);
3541
3565
  let types = {};
@@ -3655,13 +3679,8 @@ function createTailorDBService(params) {
3655
3679
  loadTypes: async () => {
3656
3680
  if (!loadPromise) loadPromise = (async () => {
3657
3681
  if (config.files.length === 0) return;
3658
- const typeFiles = [...new Set(loadFilesWithIgnores(config))];
3659
- let tsconfig;
3660
- try {
3661
- tsconfig = await resolveTSConfig();
3662
- } catch {
3663
- tsconfig = void 0;
3664
- }
3682
+ const typeFiles = [...new Set(loadFilesWithIgnores(config, baseDir))];
3683
+ const tsconfig = await resolveTSConfigWithFallback(baseDir);
3665
3684
  logger.newline();
3666
3685
  logger.log(`Found ${styles.highlight(typeFiles.length.toString())} type files for TailorDB service ${styles.highlight(`"${namespace}"`)}`);
3667
3686
  if (pluginManager) for (const typeFile of typeFiles) await loadTypeFile(typeFile, tsconfig);
@@ -3800,9 +3819,31 @@ function resolveBundleConcurrency() {
3800
3819
  * @param worker - Async worker function
3801
3820
  * @returns Worker results in input order
3802
3821
  */
3803
- function withBundleConcurrency(items, worker) {
3804
- const limit = pLimit(resolveBundleConcurrency());
3805
- return Promise.all(items.map((item) => limit(() => worker(item))));
3822
+ async function withBundleConcurrency(items, worker) {
3823
+ const resultCount = items.length;
3824
+ const workItems = items.flatMap((item, index) => [{
3825
+ index,
3826
+ item
3827
+ }]);
3828
+ const results = [];
3829
+ results.length = resultCount;
3830
+ let nextWorkIndex = 0;
3831
+ let rejection;
3832
+ const runWorker = async () => {
3833
+ while (!rejection) {
3834
+ const workItem = workItems[nextWorkIndex++];
3835
+ if (workItem === void 0) return;
3836
+ try {
3837
+ results[workItem.index] = await worker(workItem.item);
3838
+ } catch (reason) {
3839
+ rejection ??= { reason };
3840
+ }
3841
+ }
3842
+ };
3843
+ const workerCount = Math.min(resolveBundleConcurrency(), workItems.length);
3844
+ await Promise.all(Array.from({ length: workerCount }, runWorker));
3845
+ if (rejection) throw rejection.reason;
3846
+ return results;
3806
3847
  }
3807
3848
 
3808
3849
  //#endregion
@@ -3813,7 +3854,7 @@ function withBundleConcurrency(items, worker) {
3813
3854
  * Two delivery paths:
3814
3855
  * - Apply config: shipped with apply and evaluated by the platform before
3815
3856
  * invoking user code.
3816
- * - Bundle inline: interpolated into the generated `.entry.js` wrapper and
3857
+ * - Bundle inline: interpolated into the generated entry module and
3817
3858
  * evaluated inside the bundled script at function entry.
3818
3859
  *
3819
3860
  * The user field mapping (server → SDK) shared across services is defined in
@@ -3898,15 +3939,15 @@ async function loadExecutor(executorFilePath) {
3898
3939
  * Bundle executors from the specified configuration
3899
3940
  *
3900
3941
  * This function:
3901
- * 1. Creates entry file that extracts operation.body
3942
+ * 1. Creates an in-memory entry module that extracts operation.body
3902
3943
  * 2. Bundles in a single step with tree-shaking
3903
3944
  * @param options - Bundle executor options
3904
3945
  * @returns Map of executor name to bundled code
3905
3946
  */
3906
3947
  async function bundleExecutors(options) {
3907
3948
  const bundledCode = /* @__PURE__ */ new Map();
3908
- const { config, triggerContext, additionalFiles = [], cache, inlineSourcemap, bundleLogLevel = "DEBUG" } = options;
3909
- const files = [...loadFilesWithIgnores(config), ...additionalFiles];
3949
+ const { config, triggerContext, additionalFiles = [], cache, inlineSourcemap, bundleLogLevel = "DEBUG", baseDir } = options;
3950
+ const files = [...loadFilesWithIgnores(config, baseDir), ...additionalFiles];
3910
3951
  if (files.length === 0) {
3911
3952
  logger.warn(`No executor files found for patterns: ${config.files.join(", ")}`);
3912
3953
  return bundledCode;
@@ -3933,21 +3974,13 @@ async function bundleExecutors(options) {
3933
3974
  logger.debug(" No function executors to bundle");
3934
3975
  return bundledCode;
3935
3976
  }
3936
- const outputDir = path.resolve(getDistDir(), "executors");
3937
- fs$1.mkdirSync(outputDir, { recursive: true });
3938
- await removeStaleEntryFiles(outputDir);
3939
- let tsconfig;
3940
- try {
3941
- tsconfig = await resolveTSConfig();
3942
- } catch {
3943
- tsconfig = void 0;
3944
- }
3945
- const results = await withBundleConcurrency(executors, (executor) => bundleSingleExecutor(executor, outputDir, tsconfig, triggerContext, cache, inlineSourcemap, bundleLogLevel));
3977
+ const tsconfig = await resolveTSConfigWithFallback(baseDir);
3978
+ const results = await withBundleConcurrency(executors, (executor) => bundleSingleExecutor(executor, tsconfig, triggerContext, cache, inlineSourcemap, bundleLogLevel));
3946
3979
  for (const [name, code] of results) bundledCode.set(name, code);
3947
3980
  logger.log(`${styles.success("Bundled")} ${styles.info("\"executor\"")}`);
3948
3981
  return bundledCode;
3949
3982
  }
3950
- async function bundleSingleExecutor(executor, outputDir, tsconfig, triggerContext, cache, inlineSourcemap, bundleLogLevel = "DEBUG") {
3983
+ async function bundleSingleExecutor(executor, tsconfig, triggerContext, cache, inlineSourcemap, bundleLogLevel = "DEBUG") {
3951
3984
  const serializedTriggerContext = serializeTriggerContext(triggerContext);
3952
3985
  const contextHash = computeBundlerContextHash({
3953
3986
  sourceFile: executor.sourceFile,
@@ -3963,7 +3996,6 @@ async function bundleSingleExecutor(executor, outputDir, tsconfig, triggerContex
3963
3996
  sourceFile: executor.sourceFile,
3964
3997
  contextHash,
3965
3998
  async build(cachePlugins) {
3966
- const entryPath = path.join(outputDir, `${executor.name}.entry.js`);
3967
3999
  const entryContent = multiline`
3968
4000
  import _internalExecutor from "${path.resolve(executor.sourceFile)}";
3969
4001
 
@@ -3974,12 +4006,13 @@ async function bundleSingleExecutor(executor, outputDir, tsconfig, triggerContex
3974
4006
 
3975
4007
  export { __executor_function as main };
3976
4008
  `;
3977
- fs$1.writeFileSync(entryPath, entryContent);
4009
+ const entry = createVirtualEntry(`executor:${executor.name}`, entryContent);
3978
4010
  const triggerPlugin = createTriggerTransformPlugin(triggerContext);
3979
- const plugins = triggerPlugin ? [triggerPlugin] : [];
4011
+ const plugins = [entry.plugin];
4012
+ if (triggerPlugin) plugins.push(triggerPlugin);
3980
4013
  plugins.push(platformBundleDefinePlugin, ...cachePlugins);
3981
4014
  return (await rolldown.build({
3982
- input: entryPath,
4015
+ input: entry.input,
3983
4016
  write: false,
3984
4017
  output: {
3985
4018
  format: "esm",
@@ -4051,31 +4084,25 @@ const GRAPHQL_WEB_MODULE = createRequire(import.meta.url).resolve("@0no-co/graph
4051
4084
  * IIFE defining a global `transform(input)` entry point. `input` gets a
4052
4085
  * generated dispatcher that routes by `req.method`; `output` is used as is.
4053
4086
  * @param adapters - Detected adapters to bundle
4087
+ * @param baseDir - Directory the owning config's tsconfig is resolved against
4054
4088
  * @param cache - Optional bundle cache for skipping unchanged builds
4055
4089
  * @param bundleLogLevel - Controls which console calls are kept in bundled code
4056
4090
  * @returns Bundled scripts keyed by adapter name
4057
4091
  */
4058
- async function bundleHttpAdapters(adapters, cache, bundleLogLevel = "DEBUG") {
4092
+ async function bundleHttpAdapters(adapters, baseDir, cache, bundleLogLevel = "DEBUG") {
4059
4093
  if (adapters.length === 0) return {
4060
4094
  bundledInputs: /* @__PURE__ */ new Map(),
4061
4095
  bundledOutputs: /* @__PURE__ */ new Map()
4062
4096
  };
4063
4097
  logger.newline();
4064
4098
  logger.log(`Bundling ${styles.highlight(adapters.length.toString())} files for ${styles.info("\"http-adapter\"")}`);
4065
- const outputDir = path.resolve(getDistDir(), "http-adapters");
4066
- fs$1.mkdirSync(outputDir, { recursive: true });
4067
- let tsconfig;
4068
- try {
4069
- tsconfig = await resolveTSConfig();
4070
- } catch {
4071
- tsconfig = void 0;
4072
- }
4099
+ const tsconfig = await resolveTSConfigWithFallback(baseDir);
4073
4100
  const results = await withBundleConcurrency(adapters.flatMap((adapter) => {
4074
4101
  return (adapter.hasOutput ? ["input", "output"] : ["input"]).map((kind) => ({
4075
4102
  adapter,
4076
4103
  kind
4077
4104
  }));
4078
- }), ({ adapter, kind }) => bundleAdapterScript(adapter, kind, outputDir, tsconfig, cache, bundleLogLevel));
4105
+ }), ({ adapter, kind }) => bundleAdapterScript(adapter, kind, tsconfig, cache, bundleLogLevel));
4079
4106
  const bundledInputs = /* @__PURE__ */ new Map();
4080
4107
  const bundledOutputs = /* @__PURE__ */ new Map();
4081
4108
  for (const [name, kind, code] of results) if (kind === "input") bundledInputs.set(name, code);
@@ -4086,7 +4113,7 @@ async function bundleHttpAdapters(adapters, cache, bundleLogLevel = "DEBUG") {
4086
4113
  bundledOutputs
4087
4114
  };
4088
4115
  }
4089
- async function bundleAdapterScript(adapter, kind, outputDir, tsconfig, cache, bundleLogLevel = "DEBUG") {
4116
+ async function bundleAdapterScript(adapter, kind, tsconfig, cache, bundleLogLevel = "DEBUG") {
4090
4117
  const contextHash = computeBundlerContextHash({
4091
4118
  sourceFile: adapter.sourceFile,
4092
4119
  serializedTriggerContext: kind === "input" ? adapter.methods.join(",") : "",
@@ -4102,9 +4129,11 @@ async function bundleAdapterScript(adapter, kind, outputDir, tsconfig, cache, bu
4102
4129
  sourceFile: adapter.sourceFile,
4103
4130
  contextHash,
4104
4131
  async build(cachePlugins) {
4105
- const entryPath = path.join(outputDir, `${adapter.name}.${kind}.entry.js`);
4106
4132
  const absoluteSourcePath = path.resolve(adapter.sourceFile);
4133
+ const entryContent = kind === "input" ? buildInputEntry(absoluteSourcePath, adapter.methods, GRAPHQL_WEB_MODULE) : buildOutputEntry(absoluteSourcePath);
4134
+ const entry = createVirtualEntry(`http-adapter:${adapter.name}:${kind}`, entryContent);
4107
4135
  const plugins = [
4136
+ entry.plugin,
4108
4137
  {
4109
4138
  name: "http-adapter-reject-node-imports",
4110
4139
  resolveId(source) {
@@ -4128,30 +4157,21 @@ async function bundleAdapterScript(adapter, kind, outputDir, tsconfig, cache, bu
4128
4157
  },
4129
4158
  ...cachePlugins
4130
4159
  ];
4131
- let bundled;
4132
- try {
4133
- const entryContent = kind === "input" ? buildInputEntry(absoluteSourcePath, adapter.methods, GRAPHQL_WEB_MODULE) : buildOutputEntry(absoluteSourcePath);
4134
- fs$1.writeFileSync(entryPath, entryContent);
4135
- bundled = (await rolldown.build({
4136
- input: entryPath,
4137
- write: false,
4138
- output: {
4139
- format: "iife",
4140
- sourcemap: false,
4141
- minify: true,
4142
- codeSplitting: false
4143
- },
4144
- tsconfig,
4145
- plugins,
4146
- transform: { target: "es2017" },
4147
- treeshake: composeFunctionTreeshakeOptions([createLogLevelTreeshakeOptions(bundleLogLevel)]),
4148
- logLevel: "silent"
4149
- })).output[0].code;
4150
- } finally {
4151
- try {
4152
- fs$1.rmSync(entryPath, { force: true });
4153
- } catch {}
4154
- }
4160
+ const bundled = (await rolldown.build({
4161
+ input: entry.input,
4162
+ write: false,
4163
+ output: {
4164
+ format: "iife",
4165
+ sourcemap: false,
4166
+ minify: true,
4167
+ codeSplitting: false
4168
+ },
4169
+ tsconfig,
4170
+ plugins,
4171
+ transform: { target: "es2017" },
4172
+ treeshake: composeFunctionTreeshakeOptions([createLogLevelTreeshakeOptions(bundleLogLevel)]),
4173
+ logLevel: "silent"
4174
+ })).output[0].code;
4155
4175
  const byteLength = Buffer.byteLength(bundled, "utf8");
4156
4176
  if (byteLength > ADAPTER_BUNDLE_ERROR_BYTES) throw new Error(`HTTP adapter "${adapter.name}" ${kind} script is ${byteLength} bytes, exceeding the ${ADAPTER_BUNDLE_ERROR_BYTES} byte limit`);
4157
4177
  if (byteLength > ADAPTER_BUNDLE_WARN_BYTES) logger.warn(`HTTP adapter "${adapter.name}" ${kind} script is ${byteLength} bytes, larger than the recommended ${ADAPTER_BUNDLE_WARN_BYTES} byte limit`);
@@ -4225,7 +4245,7 @@ function rejectAsyncInBundle(code, adapterName, kind) {
4225
4245
  //#endregion
4226
4246
  //#region src/cli/services/http-adapter/service.ts
4227
4247
  function createHttpAdapterService(params) {
4228
- const { config } = params;
4248
+ const { config, baseDir } = params;
4229
4249
  let adapters = [];
4230
4250
  let fileCount = 0;
4231
4251
  let loaded = false;
@@ -4239,7 +4259,7 @@ function createHttpAdapterService(params) {
4239
4259
  },
4240
4260
  loadAdapters: async () => {
4241
4261
  if (loaded) return;
4242
- const result = await loadAdapterFiles(config);
4262
+ const result = await loadAdapterFiles(config, baseDir);
4243
4263
  adapters = result.adapters;
4244
4264
  fileCount = result.fileCount;
4245
4265
  loaded = true;
@@ -4255,12 +4275,12 @@ function createHttpAdapterService(params) {
4255
4275
  }
4256
4276
  };
4257
4277
  }
4258
- async function loadAdapterFiles(config) {
4278
+ async function loadAdapterFiles(config, baseDir) {
4259
4279
  if (config.files.length === 0) return {
4260
4280
  adapters: [],
4261
4281
  fileCount: 0
4262
4282
  };
4263
- const files = loadFilesWithIgnores(config);
4283
+ const files = loadFilesWithIgnores(config, baseDir);
4264
4284
  const loadResults = await Promise.all(files.map(loadAdapterFromFile));
4265
4285
  const adapters = [];
4266
4286
  const seenNames = /* @__PURE__ */ new Map();
@@ -4350,19 +4370,20 @@ async function loadResolver(resolverFilePath) {
4350
4370
  *
4351
4371
  * This function:
4352
4372
  * 1. Uses a transform plugin to add validation wrapper during bundling
4353
- * 2. Creates entry file
4373
+ * 2. Creates an in-memory entry module
4354
4374
  * 3. Bundles in a single step with tree-shaking
4355
4375
  * @param namespace - Resolver namespace name
4356
4376
  * @param config - Resolver file loading configuration
4377
+ * @param baseDir - Directory the config's file patterns are resolved against
4357
4378
  * @param triggerContext - Trigger context for workflow/job transformations
4358
4379
  * @param cache - Optional bundle cache for skipping unchanged builds
4359
4380
  * @param inlineSourcemap - Whether to enable inline sourcemaps
4360
4381
  * @param bundleLogLevel - Controls which console calls are kept in bundled code
4361
4382
  * @returns Map of resolver name to bundled code
4362
4383
  */
4363
- async function bundleResolvers(namespace, config, triggerContext, cache, inlineSourcemap, bundleLogLevel = "DEBUG") {
4384
+ async function bundleResolvers(namespace, config, baseDir, triggerContext, cache, inlineSourcemap, bundleLogLevel = "DEBUG") {
4364
4385
  const bundledCode = /* @__PURE__ */ new Map();
4365
- const files = loadFilesWithIgnores(config);
4386
+ const files = loadFilesWithIgnores(config, baseDir);
4366
4387
  if (files.length === 0) {
4367
4388
  logger.warn(`No resolver files found for patterns: ${config.files.join(", ")}`);
4368
4389
  return bundledCode;
@@ -4381,21 +4402,13 @@ async function bundleResolvers(namespace, config, triggerContext, cache, inlineS
4381
4402
  sourceFile: file
4382
4403
  });
4383
4404
  }
4384
- const outputDir = path.resolve(getDistDir(), "resolvers");
4385
- fs$1.mkdirSync(outputDir, { recursive: true });
4386
- await removeStaleEntryFiles(outputDir);
4387
- let tsconfig;
4388
- try {
4389
- tsconfig = await resolveTSConfig();
4390
- } catch {
4391
- tsconfig = void 0;
4392
- }
4393
- const results = await withBundleConcurrency(resolvers, (resolver) => bundleSingleResolver(namespace, resolver, outputDir, tsconfig, triggerContext, cache, inlineSourcemap, bundleLogLevel));
4405
+ const tsconfig = await resolveTSConfigWithFallback(baseDir);
4406
+ const results = await withBundleConcurrency(resolvers, (resolver) => bundleSingleResolver(namespace, resolver, tsconfig, triggerContext, cache, inlineSourcemap, bundleLogLevel));
4394
4407
  for (const [name, code] of results) bundledCode.set(name, code);
4395
4408
  logger.log(`${styles.success("Bundled")} ${styles.info(`"${namespace}"`)}`);
4396
4409
  return bundledCode;
4397
4410
  }
4398
- async function bundleSingleResolver(namespace, resolver, outputDir, tsconfig, triggerContext, cache, inlineSourcemap, bundleLogLevel = "DEBUG") {
4411
+ async function bundleSingleResolver(namespace, resolver, tsconfig, triggerContext, cache, inlineSourcemap, bundleLogLevel = "DEBUG") {
4399
4412
  const serializedTriggerContext = serializeTriggerContext(triggerContext);
4400
4413
  const contextHash = computeBundlerContextHash({
4401
4414
  sourceFile: resolver.sourceFile,
@@ -4412,7 +4425,6 @@ async function bundleSingleResolver(namespace, resolver, outputDir, tsconfig, tr
4412
4425
  sourceFile: resolver.sourceFile,
4413
4426
  contextHash,
4414
4427
  async build(cachePlugins) {
4415
- const entryPath = path.join(outputDir, `${resolver.name}.entry.js`);
4416
4428
  const entryContent = multiline`
4417
4429
  import _internalResolver from "${path.resolve(resolver.sourceFile)}";
4418
4430
  import { t } from "@tailor-platform/sdk";
@@ -4439,12 +4451,13 @@ async function bundleSingleResolver(namespace, resolver, outputDir, tsconfig, tr
4439
4451
 
4440
4452
  export { $tailor_resolver_body as main };
4441
4453
  `;
4442
- fs$1.writeFileSync(entryPath, entryContent);
4454
+ const entry = createVirtualEntry(`resolver:${resolver.name}`, entryContent);
4443
4455
  const triggerPlugin = createTriggerTransformPlugin(triggerContext);
4444
- const plugins = triggerPlugin ? [triggerPlugin] : [];
4456
+ const plugins = [entry.plugin];
4457
+ if (triggerPlugin) plugins.push(triggerPlugin);
4445
4458
  plugins.push(platformBundleDefinePlugin, ...cachePlugins);
4446
4459
  return (await rolldown.build({
4447
- input: entryPath,
4460
+ input: entry.input,
4448
4461
  write: false,
4449
4462
  output: {
4450
4463
  format: "esm",
@@ -4468,9 +4481,10 @@ async function bundleSingleResolver(namespace, resolver, outputDir, tsconfig, tr
4468
4481
  * Creates a new ResolverService instance.
4469
4482
  * @param namespace - The namespace for this resolver service
4470
4483
  * @param config - The resolver service configuration
4484
+ * @param baseDir - Directory the config's file patterns are resolved against
4471
4485
  * @returns A new ResolverService instance
4472
4486
  */
4473
- function createResolverService(namespace, config) {
4487
+ function createResolverService(namespace, config, baseDir) {
4474
4488
  const resolvers = {};
4475
4489
  const loadResolverForFile = async (resolverFile) => {
4476
4490
  try {
@@ -4499,7 +4513,7 @@ function createResolverService(namespace, config) {
4499
4513
  loadResolvers: async () => {
4500
4514
  if (Object.keys(resolvers).length > 0) return;
4501
4515
  if (config.files.length === 0) return;
4502
- const resolverFiles = loadFilesWithIgnores(config);
4516
+ const resolverFiles = loadFilesWithIgnores(config, baseDir);
4503
4517
  logger.log(`Found ${styles.highlight(resolverFiles.length.toString())} resolver files for service ${styles.highlight(`"${namespace}"`)}`);
4504
4518
  await Promise.all(resolverFiles.map((resolverFile) => loadResolverForFile(resolverFile)));
4505
4519
  assertUniqueResolverNames(resolvers, namespace);
@@ -4632,7 +4646,7 @@ function transformWorkflowSource(source, targetJobName, targetJobExportName, oth
4632
4646
  function safeRealpath(p) {
4633
4647
  const resolved = path.resolve(p);
4634
4648
  try {
4635
- return fs$1.realpathSync(resolved);
4649
+ return fs.realpathSync(resolved);
4636
4650
  } catch (e) {
4637
4651
  logger.debug(`realpathSync failed for ${resolved}: ${e instanceof Error ? e.message : e}`);
4638
4652
  return resolved;
@@ -4644,19 +4658,20 @@ function safeRealpath(p) {
4644
4658
  * This function:
4645
4659
  * 1. Detects which jobs are actually used (mainJobs + their dependencies)
4646
4660
  * 2. Uses a transform plugin to transform trigger calls during bundling
4647
- * 3. Creates entry file and bundles with tree-shaking
4661
+ * 3. Creates an in-memory entry module and bundles with tree-shaking
4648
4662
  *
4649
4663
  * Returns metadata about which jobs each workflow uses.
4650
4664
  * @param allJobs - All available job infos
4651
4665
  * @param mainJobNames - Names of main jobs
4652
4666
  * @param env - Environment variables to inject
4653
4667
  * @param triggerContext - Trigger context for transformations
4668
+ * @param baseDir - Directory the owning config's tsconfig is resolved against
4654
4669
  * @param cache - Optional bundle cache for skipping unchanged builds
4655
4670
  * @param inlineSourcemap - Whether to enable inline sourcemaps
4656
4671
  * @param bundleLogLevel - Controls which console calls are kept in bundled code
4657
4672
  * @returns Workflow job bundling result
4658
4673
  */
4659
- async function bundleWorkflowJobs(allJobs, mainJobNames, env = {}, triggerContext, cache, inlineSourcemap, bundleLogLevel = "DEBUG") {
4674
+ async function bundleWorkflowJobs(allJobs, mainJobNames, env = {}, triggerContext, baseDir, cache, inlineSourcemap, bundleLogLevel = "DEBUG") {
4660
4675
  if (allJobs.length === 0) {
4661
4676
  logger.warn("No workflow jobs to bundle");
4662
4677
  return {
@@ -4668,19 +4683,8 @@ async function bundleWorkflowJobs(allJobs, mainJobNames, env = {}, triggerContex
4668
4683
  const { usedJobs, mainJobDeps } = await filterUsedJobs(allJobs, mainJobNames, triggerContext);
4669
4684
  logger.newline();
4670
4685
  logger.log(`Bundling ${styles.highlight(usedJobs.length.toString())} files for ${styles.info("\"workflow-job\"")}`);
4671
- const outputDir = path.resolve(getDistDir(), "workflow-jobs");
4672
- fs$1.mkdirSync(outputDir, { recursive: true });
4673
- const currentJobNames = new Set(usedJobs.map((j) => j.name));
4674
- const existingFiles = fs$1.readdirSync(outputDir);
4675
- for (const file of existingFiles) if (file.endsWith(".js") && !currentJobNames.has(path.basename(file, ".js"))) fs$1.rmSync(path.join(outputDir, file), { force: true });
4676
- else if (file.endsWith(".js.map") && !currentJobNames.has(path.basename(file, ".js.map"))) fs$1.rmSync(path.join(outputDir, file), { force: true });
4677
- let tsconfig;
4678
- try {
4679
- tsconfig = await resolveTSConfig();
4680
- } catch {
4681
- tsconfig = void 0;
4682
- }
4683
- const results = await withBundleConcurrency(usedJobs, (job) => bundleSingleJob(job, usedJobs, outputDir, tsconfig, env, triggerContext, cache, inlineSourcemap, bundleLogLevel));
4686
+ const tsconfig = await resolveTSConfigWithFallback(baseDir);
4687
+ const results = await withBundleConcurrency(usedJobs, (job) => bundleSingleJob(job, usedJobs, tsconfig, env, triggerContext, cache, inlineSourcemap, bundleLogLevel));
4684
4688
  const bundledCode = /* @__PURE__ */ new Map();
4685
4689
  for (const [name, code] of results) bundledCode.set(name, code);
4686
4690
  logger.log(`${styles.success("Bundled")} ${styles.info("\"workflow-job\"")}`);
@@ -4716,7 +4720,7 @@ async function filterUsedJobs(allJobs, mainJobNames, triggerContext) {
4716
4720
  const dependencies = /* @__PURE__ */ new Map();
4717
4721
  const fileResults = await Promise.all(Array.from(jobsBySourceFile.entries()).map(async ([sourceFile, jobs]) => {
4718
4722
  try {
4719
- const source = await fs$1.promises.readFile(sourceFile, "utf-8");
4723
+ const source = await fs.promises.readFile(sourceFile, "utf-8");
4720
4724
  const { program } = parseSync("input.ts", source);
4721
4725
  const detectedJobs = findAllJobs(program, source);
4722
4726
  const triggerCalls = detectResolvedTriggerCalls(program, source, triggerContext, sourceFile);
@@ -4756,7 +4760,7 @@ async function filterUsedJobs(allJobs, mainJobNames, triggerContext) {
4756
4760
  mainJobDeps
4757
4761
  };
4758
4762
  }
4759
- async function bundleSingleJob(job, allJobs, outputDir, tsconfig, env, triggerContext, cache, inlineSourcemap, bundleLogLevel = "DEBUG") {
4763
+ async function bundleSingleJob(job, allJobs, tsconfig, env, triggerContext, cache, inlineSourcemap, bundleLogLevel = "DEBUG") {
4760
4764
  const serializedTriggerContext = serializeTriggerContext(triggerContext);
4761
4765
  const sortedEnvPrefix = JSON.stringify(Object.fromEntries(Object.entries(env).toSorted(([a], [b]) => a.localeCompare(b))));
4762
4766
  const contextHash = computeBundlerContextHash({
@@ -4774,7 +4778,6 @@ async function bundleSingleJob(job, allJobs, outputDir, tsconfig, env, triggerCo
4774
4778
  sourceFile: job.sourceFile,
4775
4779
  contextHash,
4776
4780
  async build(cachePlugins) {
4777
- const entryPath = path.join(outputDir, `${job.name}.entry.js`);
4778
4781
  const absoluteSourcePath = path.resolve(job.sourceFile);
4779
4782
  const entryContent = multiline`
4780
4783
  import { ${job.exportName} } from "${absoluteSourcePath}";
@@ -4785,10 +4788,11 @@ async function bundleSingleJob(job, allJobs, outputDir, tsconfig, env, triggerCo
4785
4788
  return await ${job.exportName}.body(input, { env, invoker });
4786
4789
  }
4787
4790
  `;
4788
- fs$1.writeFileSync(entryPath, entryContent);
4791
+ const entry = createVirtualEntry(`workflow-job:${job.name}`, entryContent);
4789
4792
  const resolvedSourceFile = safeRealpath(job.sourceFile);
4790
4793
  const otherJobExportNames = allJobs.filter((candidate) => candidate.name !== job.name && safeRealpath(candidate.sourceFile) === resolvedSourceFile).map((j) => j.exportName);
4791
4794
  const plugins = [
4795
+ entry.plugin,
4792
4796
  {
4793
4797
  name: "workflow-transform",
4794
4798
  transform: {
@@ -4807,7 +4811,7 @@ async function bundleSingleJob(job, allJobs, outputDir, tsconfig, env, triggerCo
4807
4811
  ...cachePlugins
4808
4812
  ];
4809
4813
  return (await rolldown.build({
4810
- input: entryPath,
4814
+ input: entry.input,
4811
4815
  write: false,
4812
4816
  output: {
4813
4817
  format: "esm",
@@ -4887,7 +4891,7 @@ const WorkflowSchema = z.object({
4887
4891
  * @returns A new WorkflowService instance
4888
4892
  */
4889
4893
  function createWorkflowService(params) {
4890
- const { config } = params;
4894
+ const { config, baseDir } = params;
4891
4895
  let workflows = {};
4892
4896
  let workflowSources = [];
4893
4897
  let jobs = [];
@@ -4909,7 +4913,7 @@ function createWorkflowService(params) {
4909
4913
  },
4910
4914
  loadWorkflows: async () => {
4911
4915
  if (loaded) return;
4912
- const result = await loadAndCollectJobs(config);
4916
+ const result = await loadAndCollectJobs(config, baseDir);
4913
4917
  workflows = result.workflows;
4914
4918
  workflowSources = result.workflowSources;
4915
4919
  jobs = result.jobs;
@@ -4931,9 +4935,10 @@ function createWorkflowService(params) {
4931
4935
  * Load workflow files and collect all jobs in a single pass.
4932
4936
  * Dependencies are detected at bundle time via AST analysis.
4933
4937
  * @param config - Workflow service configuration
4938
+ * @param baseDir - Directory the config's file patterns are resolved against
4934
4939
  * @returns Loaded workflows and collected jobs
4935
4940
  */
4936
- async function loadAndCollectJobs(config) {
4941
+ async function loadAndCollectJobs(config, baseDir) {
4937
4942
  const workflows = {};
4938
4943
  const workflowSources = [];
4939
4944
  const collectedJobs = [];
@@ -4943,7 +4948,7 @@ async function loadAndCollectJobs(config) {
4943
4948
  jobs: collectedJobs,
4944
4949
  fileCount: 0
4945
4950
  };
4946
- const workflowFiles = loadFilesWithIgnores(config);
4951
+ const workflowFiles = loadFilesWithIgnores(config, baseDir);
4947
4952
  const fileCount = workflowFiles.length;
4948
4953
  const allJobsMap = /* @__PURE__ */ new Map();
4949
4954
  const loadResults = await Promise.all(workflowFiles.map(async (workflowFile) => {
@@ -5245,7 +5250,7 @@ const StaticWebsiteSchema = z.object({
5245
5250
 
5246
5251
  //#endregion
5247
5252
  //#region src/cli/services/application.ts
5248
- function defineTailorDB(config, pluginManager) {
5253
+ function defineTailorDB(config, baseDir, pluginManager) {
5249
5254
  const tailorDBServices = [];
5250
5255
  const externalTailorDBNamespaces = [];
5251
5256
  const subgraphs = [];
@@ -5260,7 +5265,8 @@ function defineTailorDB(config, pluginManager) {
5260
5265
  const tailorDB = createTailorDBService({
5261
5266
  namespace,
5262
5267
  config: TailorDBServiceConfigSchema.parse(serviceConfig),
5263
- pluginManager
5268
+ pluginManager,
5269
+ baseDir
5264
5270
  });
5265
5271
  tailorDBServices.push(tailorDB);
5266
5272
  }
@@ -5275,7 +5281,7 @@ function defineTailorDB(config, pluginManager) {
5275
5281
  subgraphs
5276
5282
  };
5277
5283
  }
5278
- function defineResolver(config) {
5284
+ function defineResolver(config, baseDir) {
5279
5285
  const resolverServices = [];
5280
5286
  const subgraphs = [];
5281
5287
  if (!config) return {
@@ -5284,7 +5290,7 @@ function defineResolver(config) {
5284
5290
  };
5285
5291
  for (const [namespace, serviceConfig] of Object.entries(config)) {
5286
5292
  if (!("external" in serviceConfig)) {
5287
- const resolverService = createResolverService(namespace, serviceConfig);
5293
+ const resolverService = createResolverService(namespace, serviceConfig, baseDir);
5288
5294
  resolverServices.push(resolverService);
5289
5295
  }
5290
5296
  subgraphs.push({
@@ -5340,17 +5346,26 @@ function defineAuth(config, tailorDBServices, externalTailorDBNamespaces) {
5340
5346
  subgraphs
5341
5347
  };
5342
5348
  }
5343
- function defineExecutor(config, hasPluginExecutors) {
5349
+ function defineExecutor(config, baseDir, hasPluginExecutors) {
5344
5350
  if (!config && !hasPluginExecutors) return;
5345
- return createExecutorService({ config: config ?? { files: [] } });
5351
+ return createExecutorService({
5352
+ config: config ?? { files: [] },
5353
+ baseDir
5354
+ });
5346
5355
  }
5347
- function defineWorkflow(config) {
5356
+ function defineWorkflow(config, baseDir) {
5348
5357
  if (!config) return;
5349
- return createWorkflowService({ config });
5358
+ return createWorkflowService({
5359
+ config,
5360
+ baseDir
5361
+ });
5350
5362
  }
5351
- function defineHttpAdapterService(config) {
5363
+ function defineHttpAdapterService(config, baseDir) {
5352
5364
  if (!config) return;
5353
- return createHttpAdapterService({ config });
5365
+ return createHttpAdapterService({
5366
+ config,
5367
+ baseDir
5368
+ });
5354
5369
  }
5355
5370
  function defineStaticWebsites(websites) {
5356
5371
  const staticWebsiteServices = [];
@@ -5396,9 +5411,9 @@ function parseSecretManager(config) {
5396
5411
  ignoreNullishValues
5397
5412
  };
5398
5413
  }
5399
- function defineServices(config, pluginManager) {
5400
- const tailordbResult = defineTailorDB(config.db, pluginManager);
5401
- const resolverResult = defineResolver(config.resolver);
5414
+ function defineServices(config, baseDir, pluginManager) {
5415
+ const tailordbResult = defineTailorDB(config.db, baseDir, pluginManager);
5416
+ const resolverResult = defineResolver(config.resolver, baseDir);
5402
5417
  const idpResult = defineIdp(config.idp);
5403
5418
  const authResult = defineAuth(config.auth, tailordbResult.tailorDBServices, tailordbResult.externalTailorDBNamespaces);
5404
5419
  const staticWebsiteServices = defineStaticWebsites(config.staticWebsites);
@@ -5454,10 +5469,11 @@ function buildApplication(params) {
5454
5469
  */
5455
5470
  function defineApplication(params) {
5456
5471
  const { config, pluginManager } = params;
5457
- const services = defineServices(config, pluginManager);
5458
- const executorService = defineExecutor(config.executor, false);
5459
- const workflowService = defineWorkflow(config.workflow);
5460
- const httpAdapterService = defineHttpAdapterService(config.httpAdapter);
5472
+ const baseDir = path.dirname(config.path);
5473
+ const services = defineServices(config, baseDir, pluginManager);
5474
+ const executorService = defineExecutor(config.executor, baseDir, false);
5475
+ const workflowService = defineWorkflow(config.workflow, baseDir);
5476
+ const httpAdapterService = defineHttpAdapterService(config.httpAdapter, baseDir);
5461
5477
  return buildApplication({
5462
5478
  config,
5463
5479
  ...services,
@@ -5502,19 +5518,20 @@ function generatePluginFilesIfNeeded(pluginManager, tailorDBServices, configPath
5502
5518
  */
5503
5519
  async function loadApplication(params) {
5504
5520
  const { config, pluginManager, bundleCache } = params;
5505
- const { tailordbResult, resolverResult, idpResult, authResult, staticWebsiteServices, aiGatewayServices, secrets, ignoreNullishValues } = defineServices(config, pluginManager);
5521
+ const baseDir = path.dirname(config.path);
5522
+ const { tailordbResult, resolverResult, idpResult, authResult, staticWebsiteServices, aiGatewayServices, secrets, ignoreNullishValues } = defineServices(config, baseDir, pluginManager);
5506
5523
  for (const tailordb of tailordbResult.tailorDBServices) {
5507
5524
  await tailordb.loadTypes();
5508
5525
  await tailordb.processNamespacePlugins();
5509
5526
  }
5510
5527
  assertUniqueLocalTailorDBTypeNames({ tailorDBServices: tailordbResult.tailorDBServices });
5511
5528
  const pluginExecutorFiles = generatePluginFilesIfNeeded(pluginManager, tailordbResult.tailorDBServices, config.path);
5512
- const executorService = defineExecutor(config.executor, pluginExecutorFiles.length > 0);
5513
- const workflowService = defineWorkflow(config.workflow);
5529
+ const executorService = defineExecutor(config.executor, baseDir, pluginExecutorFiles.length > 0);
5530
+ const workflowService = defineWorkflow(config.workflow, baseDir);
5514
5531
  if (workflowService) await workflowService.loadWorkflows();
5515
- const httpAdapterService = defineHttpAdapterService(config.httpAdapter);
5532
+ const httpAdapterService = defineHttpAdapterService(config.httpAdapter, baseDir);
5516
5533
  if (httpAdapterService) await httpAdapterService.loadAdapters();
5517
- const triggerContext = await buildTriggerContext(config.workflow, authResult.authService?.config.name);
5534
+ const triggerContext = await buildTriggerContext(config.workflow, authResult.authService?.config.name, baseDir);
5518
5535
  const inlineSourcemap = resolveInlineSourcemap(config.inlineSourcemap);
5519
5536
  const bundleLogLevel = resolveBundleLogLevel(config.logLevel);
5520
5537
  const bundledScripts = {
@@ -5524,7 +5541,7 @@ async function loadApplication(params) {
5524
5541
  authHooks: /* @__PURE__ */ new Map()
5525
5542
  };
5526
5543
  for (const pipeline of resolverResult.resolverServices) {
5527
- const resolverBundles = await bundleResolvers(pipeline.namespace, pipeline.config, triggerContext, bundleCache, inlineSourcemap, bundleLogLevel);
5544
+ const resolverBundles = await bundleResolvers(pipeline.namespace, pipeline.config, baseDir, triggerContext, bundleCache, inlineSourcemap, bundleLogLevel);
5528
5545
  for (const [name, code] of resolverBundles) bundledScripts.resolvers.set(resolverBundleKey(pipeline.namespace, name), code);
5529
5546
  }
5530
5547
  if (executorService) bundledScripts.executors = await bundleExecutors({
@@ -5533,12 +5550,13 @@ async function loadApplication(params) {
5533
5550
  additionalFiles: [...pluginExecutorFiles],
5534
5551
  cache: bundleCache,
5535
5552
  inlineSourcemap,
5536
- bundleLogLevel
5553
+ bundleLogLevel,
5554
+ baseDir
5537
5555
  });
5538
5556
  let workflowBuildResult;
5539
5557
  if (workflowService && workflowService.jobs.length > 0) {
5540
5558
  const mainJobNames = workflowService.workflowSources.map((ws) => ws.workflow.mainJob.name);
5541
- workflowBuildResult = await bundleWorkflowJobs(workflowService.jobs, mainJobNames, config.env ?? {}, triggerContext, bundleCache, inlineSourcemap, bundleLogLevel);
5559
+ workflowBuildResult = await bundleWorkflowJobs(workflowService.jobs, mainJobNames, config.env ?? {}, triggerContext, baseDir, bundleCache, inlineSourcemap, bundleLogLevel);
5542
5560
  bundledScripts.workflowJobs = workflowBuildResult.bundledCode;
5543
5561
  }
5544
5562
  let httpAdapterBuildResult;
@@ -5547,7 +5565,7 @@ async function loadApplication(params) {
5547
5565
  sourceFile: a.sourceFile,
5548
5566
  methods: a.methods,
5549
5567
  hasOutput: a.hasOutput
5550
- })), bundleCache, bundleLogLevel);
5568
+ })), baseDir, bundleCache, bundleLogLevel);
5551
5569
  if (authResult.authService?.config.hooks?.beforeLogin) {
5552
5570
  const authName = authResult.authService.config.name;
5553
5571
  bundledScripts.authHooks = await bundleAuthHooks({
@@ -5558,7 +5576,8 @@ async function loadApplication(params) {
5558
5576
  triggerContext,
5559
5577
  cache: bundleCache,
5560
5578
  inlineSourcemap,
5561
- bundleLogLevel
5579
+ bundleLogLevel,
5580
+ baseDir
5562
5581
  });
5563
5582
  }
5564
5583
  for (const pipeline of resolverResult.resolverServices) await pipeline.loadResolvers();
@@ -5592,5 +5611,5 @@ async function loadApplication(params) {
5592
5611
  }
5593
5612
 
5594
5613
  //#endregion
5595
- export { fetchAllTolerant as A, initOperatorClient as B, createBundleCache as C, closeConnectionPool as D, hashFile as E, getConsoleBaseUrl as F, byName as G, normalizeBaseUrl as H, getOAuth2ClientId as I, LOG_LEVELS as K, getOrNull as L, fetchPaged as M, fetchPlatformMachineUserToken as N, defaultPlatformBaseUrl as O, fetchUserInfo as P, getPlatformBaseUrl as R, hasGenerationHooks as S, hashContent as T, rememberPlatformConfigForToken as U, isDefaultPlatform as V, resolveStaticWebsiteUrls as W, platformBundleDefinePlugin as _, resolveInlineSourcemap as a, resolveBundleLogLevel as b, ResolverSchema as c, buildExecutorArgsExpr as d, buildResolverOperationHookExpr as f, stringifyFunction as g, TailorDBTypeSchema as h, resolverBundleKey as i, fetchMachineUserToken as j, fetchAll as k, HTTP_METHODS as l, assertUniqueTailorDBTypeNamesWithExternal as m, generatePluginFilesIfNeeded as n, WorkflowJobFunctionExecutionPolicySchema as o, assertUniqueLocalTailorDBTypeNames as p, loadApplication as r, WorkflowJobSchema as s, defineApplication as t, INVOKER_EXPR as u, composeFunctionTreeshakeOptions as v, getDistDir as w, getPluginGenerationDependencies as x, createLogLevelTreeshakeOptions as y, initOAuth2Client as z };
5596
- //# sourceMappingURL=application-fjqb-Gh8.mjs.map
5614
+ export { fetchAll as A, initOAuth2Client as B, hasGenerationHooks as C, hashFile as D, hashContent as E, fetchUserInfo as F, resolveStaticWebsiteUrls as G, isDefaultPlatform as H, getConsoleBaseUrl as I, LOG_LEVELS as J, byName as K, getOAuth2ClientId as L, fetchMachineUserToken as M, fetchPaged as N, closeConnectionPool as O, fetchPlatformMachineUserToken as P, getOrNull as R, getPluginGenerationDependencies as S, getDistDir as T, normalizeBaseUrl as U, initOperatorClient as V, rememberPlatformConfigForToken as W, resolveTSConfigWithFallback as _, resolveInlineSourcemap as a, createLogLevelTreeshakeOptions as b, ResolverSchema as c, buildExecutorArgsExpr as d, buildResolverOperationHookExpr as f, stringifyFunction as g, TailorDBTypeSchema as h, resolverBundleKey as i, fetchAllTolerant as j, defaultPlatformBaseUrl as k, HTTP_METHODS as l, assertUniqueTailorDBTypeNamesWithExternal as m, generatePluginFilesIfNeeded as n, WorkflowJobFunctionExecutionPolicySchema as o, assertUniqueLocalTailorDBTypeNames as p, createApplyLimiter as q, loadApplication as r, WorkflowJobSchema as s, defineApplication as t, INVOKER_EXPR as u, platformBundleDefinePlugin as v, createBundleCache as w, resolveBundleLogLevel as x, composeFunctionTreeshakeOptions as y, getPlatformBaseUrl as z };
5615
+ //# sourceMappingURL=application-C1d52JP9.mjs.map