@workflow/builders 4.0.5 → 4.0.7

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.
Files changed (34) hide show
  1. package/dist/base-builder.d.ts +23 -4
  2. package/dist/base-builder.d.ts.map +1 -1
  3. package/dist/base-builder.js +122 -7
  4. package/dist/base-builder.js.map +1 -1
  5. package/dist/discover-entries-esbuild-plugin.d.ts +5 -3
  6. package/dist/discover-entries-esbuild-plugin.d.ts.map +1 -1
  7. package/dist/discover-entries-esbuild-plugin.js +32 -8
  8. package/dist/discover-entries-esbuild-plugin.js.map +1 -1
  9. package/dist/external-package-warning.test.d.ts +2 -0
  10. package/dist/external-package-warning.test.d.ts.map +1 -0
  11. package/dist/external-package-warning.test.js +219 -0
  12. package/dist/external-package-warning.test.js.map +1 -0
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/request-converter.d.ts +2 -1
  18. package/dist/request-converter.d.ts.map +1 -1
  19. package/dist/request-converter.js +19 -1
  20. package/dist/request-converter.js.map +1 -1
  21. package/dist/request-converter.test.d.ts +2 -0
  22. package/dist/request-converter.test.d.ts.map +1 -0
  23. package/dist/request-converter.test.js +28 -0
  24. package/dist/request-converter.test.js.map +1 -0
  25. package/dist/swc-esbuild-plugin.d.ts +9 -0
  26. package/dist/swc-esbuild-plugin.d.ts.map +1 -1
  27. package/dist/swc-esbuild-plugin.js +24 -1
  28. package/dist/swc-esbuild-plugin.js.map +1 -1
  29. package/dist/swc-esbuild-plugin.test.js +184 -0
  30. package/dist/swc-esbuild-plugin.test.js.map +1 -1
  31. package/dist/vercel-build-output-api.d.ts.map +1 -1
  32. package/dist/vercel-build-output-api.js +3 -0
  33. package/dist/vercel-build-output-api.js.map +1 -1
  34. package/package.json +5 -5
@@ -1,10 +1,11 @@
1
1
  import * as esbuild from 'esbuild';
2
2
  import { type WorkflowManifest } from './apply-swc-transform.js';
3
3
  import type { WorkflowConfig } from './types.js';
4
+ export type DiscoveredEntryCollection = string[] | Set<string>;
4
5
  export interface DiscoveredEntries {
5
- discoveredSteps: string[];
6
- discoveredWorkflows: string[];
7
- discoveredSerdeFiles: string[];
6
+ discoveredSteps: DiscoveredEntryCollection;
7
+ discoveredWorkflows: DiscoveredEntryCollection;
8
+ discoveredSerdeFiles: DiscoveredEntryCollection;
8
9
  }
9
10
  /**
10
11
  * Base class for workflow builders. Provides common build logic for transforming
@@ -14,6 +15,11 @@ export interface DiscoveredEntries {
14
15
  */
15
16
  export declare abstract class BaseBuilder {
16
17
  protected config: WorkflowConfig;
18
+ /**
19
+ * Tracks which external packages have already been warned about
20
+ * to avoid duplicate warnings across multiple discoverEntries() calls.
21
+ */
22
+ private warnedExternalPackages;
17
23
  constructor(config: WorkflowConfig);
18
24
  protected get transformProjectRoot(): string;
19
25
  /**
@@ -56,6 +62,17 @@ export declare abstract class BaseBuilder {
56
62
  * (e.g., when files are added/removed during watch mode).
57
63
  */
58
64
  private discoveredEntries;
65
+ /**
66
+ * Pseudo-packages that should not be checked for workflow patterns.
67
+ */
68
+ private static readonly PSEUDO_PACKAGES;
69
+ /**
70
+ * Checks each package in externalPackages for workflow patterns and emits
71
+ * warnings if any contain "use step", "use workflow" directives, or
72
+ * serialization classes. These patterns will not be transformed by the
73
+ * workflow compiler when the package is externalized.
74
+ */
75
+ private warnAboutExternalWorkflowPackages;
59
76
  protected discoverEntries(inputs: string[], outdir: string, tsconfigPath?: string): Promise<DiscoveredEntries>;
60
77
  /**
61
78
  * Writes debug information to a JSON file for troubleshooting build issues.
@@ -77,14 +94,16 @@ export declare abstract class BaseBuilder {
77
94
  * Steps have full Node.js runtime access and handle side effects, API calls, etc.
78
95
  *
79
96
  * @param externalizeNonSteps - If true, only bundles step entry points and externalizes other code
97
+ * @param bundleTransitiveLocalStepDependencies - If true, also bundles project-local files imported by step entries for direct runtime loading
80
98
  * @returns Build context (for watch mode) and the collected workflow manifest
81
99
  */
82
- protected createStepsBundle({ inputFiles, format, outfile, externalizeNonSteps, rewriteTsExtensions, tsconfigPath, discoveredEntries, }: {
100
+ protected createStepsBundle({ inputFiles, format, outfile, externalizeNonSteps, bundleTransitiveLocalStepDependencies, rewriteTsExtensions, tsconfigPath, discoveredEntries, }: {
83
101
  tsconfigPath?: string;
84
102
  inputFiles: string[];
85
103
  outfile: string;
86
104
  format?: 'cjs' | 'esm';
87
105
  externalizeNonSteps?: boolean;
106
+ bundleTransitiveLocalStepDependencies?: boolean;
88
107
  rewriteTsExtensions?: boolean;
89
108
  discoveredEntries?: DiscoveredEntries;
90
109
  }): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"base-builder.d.ts","sourceRoot":"","sources":["../src/base-builder.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA2BjD,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC;AAED;;;;;GAKG;AACH,8BAAsB,WAAW;IAC/B,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC;gBAErB,MAAM,EAAE,cAAc;IAIlC,SAAS,KAAK,oBAAoB,IAAI,MAAM,CAE3C;IAED;;;OAGG;IACH,SAAS,KAAK,wBAAwB,IAAI,OAAO,CAEhD;IAED,SAAS,CAAC,kBAAkB,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAMtD,OAAO,CAAC,4BAA4B;IAMpC,OAAO,CAAC,0BAA0B;IAMlC,OAAO,CAAC,qBAAqB;IAM7B;;;;;;OAMG;IACH,OAAO,CAAC,wBAAwB;IAiBhC;;;OAGG;IAC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AC5B,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAuD/B,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,wBAAwB;IAyDhC,OAAO,CAAC,sBAAsB;CAc/B"}
@@ -1,5 +1,6 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { mkdir, readFile, realpath, rename, writeFile } from 'node:fs/promises';
3
+ import { createRequire } from 'node:module';
3
4
  import { basename, dirname, join, relative, resolve } from 'node:path';
4
5
  import { promisify } from 'node:util';
5
6
  import { pluralize, usesVercelWorld } from '@workflow/utils';
@@ -15,8 +16,10 @@ import { getImportPath } from './module-specifier.js';
15
16
  import { createNodeModuleErrorPlugin } from './node-module-esbuild-plugin.js';
16
17
  import { createPseudoPackagePlugin } from './pseudo-package-esbuild-plugin.js';
17
18
  import { createSwcPlugin } from './swc-esbuild-plugin.js';
19
+ import { detectWorkflowPatterns } from './transform-utils.js';
18
20
  import { extractWorkflowGraphs } from './workflows-extractor.js';
19
21
  const enhancedResolve = promisify(enhancedResolveOriginal);
22
+ const require = createRequire(import.meta.url);
20
23
  const EMIT_SOURCEMAPS_FOR_DEBUGGING = process.env.WORKFLOW_EMIT_SOURCEMAPS_FOR_DEBUGGING === '1';
21
24
  /**
22
25
  * Normalize an array of file paths by appending the `realpath()` of each entry
@@ -36,6 +39,11 @@ async function withRealpaths(entries) {
36
39
  */
37
40
  export class BaseBuilder {
38
41
  config;
42
+ /**
43
+ * Tracks which external packages have already been warned about
44
+ * to avoid duplicate warnings across multiple discoverEntries() calls.
45
+ */
46
+ warnedExternalPackages = new Set();
39
47
  constructor(config) {
40
48
  this.config = config;
41
49
  }
@@ -107,6 +115,7 @@ export class BaseBuilder {
107
115
  '**/node_modules/**',
108
116
  '**/.git/**',
109
117
  '**/.next/**',
118
+ '**/.nitro/**',
110
119
  '**/.nuxt/**',
111
120
  '**/.output/**',
112
121
  '**/.vercel/**',
@@ -141,15 +150,114 @@ export class BaseBuilder {
141
150
  * (e.g., when files are added/removed during watch mode).
142
151
  */
143
152
  discoveredEntries = new WeakMap();
153
+ /**
154
+ * Pseudo-packages that should not be checked for workflow patterns.
155
+ */
156
+ static PSEUDO_PACKAGES = new Set([
157
+ 'server-only',
158
+ 'client-only',
159
+ ]);
160
+ /**
161
+ * Checks each package in externalPackages for workflow patterns and emits
162
+ * warnings if any contain "use step", "use workflow" directives, or
163
+ * serialization classes. These patterns will not be transformed by the
164
+ * workflow compiler when the package is externalized.
165
+ */
166
+ async warnAboutExternalWorkflowPackages() {
167
+ const externalPackages = this.config.externalPackages;
168
+ if (!externalPackages?.length)
169
+ return;
170
+ for (const pkg of externalPackages) {
171
+ if (BaseBuilder.PSEUDO_PACKAGES.has(pkg))
172
+ continue;
173
+ if (this.warnedExternalPackages.has(pkg))
174
+ continue;
175
+ if (pkg.startsWith('.') ||
176
+ pkg.startsWith('/') ||
177
+ pkg.startsWith('$') ||
178
+ pkg.includes('*') ||
179
+ pkg.includes(':')) {
180
+ continue;
181
+ }
182
+ try {
183
+ // Check package.json dependencies for @workflow/serde (fast path)
184
+ let hasWorkflowSerdeDep = false;
185
+ try {
186
+ const pkgJsonPath = require.resolve(`${pkg}/package.json`, {
187
+ paths: [this.config.workingDir],
188
+ });
189
+ const pkgJsonSource = await readFile(pkgJsonPath, 'utf-8');
190
+ const pkgJson = JSON.parse(pkgJsonSource);
191
+ const dependencies = typeof pkgJson.dependencies === 'object' &&
192
+ pkgJson.dependencies !== null &&
193
+ !Array.isArray(pkgJson.dependencies)
194
+ ? pkgJson.dependencies
195
+ : {};
196
+ const peerDependencies = typeof pkgJson.peerDependencies === 'object' &&
197
+ pkgJson.peerDependencies !== null &&
198
+ !Array.isArray(pkgJson.peerDependencies)
199
+ ? pkgJson.peerDependencies
200
+ : {};
201
+ hasWorkflowSerdeDep =
202
+ Object.hasOwn(dependencies, '@workflow/serde') ||
203
+ Object.hasOwn(peerDependencies, '@workflow/serde');
204
+ }
205
+ catch {
206
+ // package.json not resolvable - continue to source check
207
+ }
208
+ // Check source patterns (thorough path).
209
+ // Note: require.resolve only inspects the package's main entry point.
210
+ // If workflow constructs live in sub-paths (e.g. `my-pkg/workflows`),
211
+ // they won't be detected here. The @workflow/serde dep check above
212
+ // partially covers serde cases. This is acceptable as a best-effort
213
+ // heuristic — the primary fix is auto-removal in withWorkflow().
214
+ let hasUseStep = false;
215
+ let hasUseWorkflow = false;
216
+ let hasSerde = hasWorkflowSerdeDep;
217
+ try {
218
+ const entryPath = require.resolve(pkg, {
219
+ paths: [this.config.workingDir],
220
+ });
221
+ const source = await readFile(entryPath, 'utf-8');
222
+ const patterns = detectWorkflowPatterns(source);
223
+ hasUseStep = patterns.hasUseStep;
224
+ hasUseWorkflow = patterns.hasUseWorkflow;
225
+ if (!hasSerde) {
226
+ hasSerde = patterns.hasSerde;
227
+ }
228
+ }
229
+ catch {
230
+ // Entry file not resolvable or not readable - use what we have
231
+ }
232
+ if (!hasUseStep && !hasUseWorkflow && !hasSerde)
233
+ continue;
234
+ // Build a specific description of what was found
235
+ const issues = [];
236
+ if (hasUseWorkflow)
237
+ issues.push('"use workflow" functions');
238
+ if (hasUseStep)
239
+ issues.push('"use step" functions');
240
+ if (hasSerde)
241
+ issues.push('serialization classes');
242
+ this.warnedExternalPackages.add(pkg);
243
+ console.warn(`\n${chalk.yellow('⚠')} Warning: ${chalk.bold(`"${pkg}"`)} is listed in ${chalk.bold('externalPackages')} (${chalk.bold('serverExternalPackages')} in Next.js) but contains workflow code (${issues.join(', ')}).` +
244
+ `\n This code will ${chalk.bold('not')} be transformed by the workflow compiler, which can cause runtime failures.` +
245
+ `\n Remove ${chalk.bold(`"${pkg}"`)} from ${chalk.bold('externalPackages')} (${chalk.bold('serverExternalPackages')} in Next.js) to fix this.\n`);
246
+ }
247
+ catch {
248
+ // Best-effort: if anything goes wrong, skip this package silently
249
+ }
250
+ }
251
+ }
144
252
  async discoverEntries(inputs, outdir, tsconfigPath) {
145
253
  const previousResult = this.discoveredEntries.get(inputs);
146
254
  if (previousResult) {
147
255
  return previousResult;
148
256
  }
149
257
  const state = {
150
- discoveredSteps: [],
151
- discoveredWorkflows: [],
152
- discoveredSerdeFiles: [],
258
+ discoveredSteps: new Set(),
259
+ discoveredWorkflows: new Set(),
260
+ discoveredSerdeFiles: new Set(),
153
261
  };
154
262
  const discoverStart = Date.now();
155
263
  const effectiveTsconfigPath = tsconfigPath ?? (await this.findTsConfigPath());
@@ -175,6 +283,8 @@ export class BaseBuilder {
175
283
  }
176
284
  catch (_) { }
177
285
  this.logBaseBuilderInfo(`Discovering workflow directives`, `${Date.now() - discoverStart}ms`);
286
+ // Warn about external packages that contain workflow code
287
+ await this.warnAboutExternalWorkflowPackages();
178
288
  this.discoveredEntries.set(inputs, state);
179
289
  return state;
180
290
  }
@@ -270,9 +380,10 @@ export class BaseBuilder {
270
380
  * Steps have full Node.js runtime access and handle side effects, API calls, etc.
271
381
  *
272
382
  * @param externalizeNonSteps - If true, only bundles step entry points and externalizes other code
383
+ * @param bundleTransitiveLocalStepDependencies - If true, also bundles project-local files imported by step entries for direct runtime loading
273
384
  * @returns Build context (for watch mode) and the collected workflow manifest
274
385
  */
275
- async createStepsBundle({ inputFiles, format = 'cjs', outfile, externalizeNonSteps, rewriteTsExtensions, tsconfigPath, discoveredEntries, }) {
386
+ async createStepsBundle({ inputFiles, format = 'cjs', outfile, externalizeNonSteps, bundleTransitiveLocalStepDependencies, rewriteTsExtensions, tsconfigPath, discoveredEntries, }) {
276
387
  // These need to handle watching for dev to scan for
277
388
  // new entries and changes to existing ones
278
389
  const discovered = discoveredEntries ??
@@ -339,7 +450,7 @@ export class BaseBuilder {
339
450
  // Serde files for cross-context class registration
340
451
  ${serdeImports}
341
452
  // API entrypoint
342
- export { stepEntrypoint as POST } from 'workflow/runtime';`;
453
+ export { stepEntrypoint as HEAD, stepEntrypoint as POST } from 'workflow/runtime';`;
343
454
  // Bundle with esbuild and our custom SWC plugin
344
455
  const entriesToBundle = externalizeNonSteps
345
456
  ? [
@@ -410,6 +521,7 @@ export class BaseBuilder {
410
521
  outdir: outfile ? dirname(outfile) : undefined,
411
522
  projectRoot: this.transformProjectRoot,
412
523
  workflowManifest,
524
+ bundleTransitiveLocalStepDependencies,
413
525
  rewriteTsExtensions,
414
526
  sideEffectEntries: normalizedSideEffectEntries,
415
527
  }),
@@ -642,7 +754,10 @@ import { workflowEntrypoint } from 'workflow/runtime';
642
754
 
643
755
  const workflowCode = \`${workflowBundleCode.replace(/[\\`$]/g, '\\$&')}\`;
644
756
 
645
- export const POST = workflowEntrypoint(workflowCode);`;
757
+ const handler = workflowEntrypoint(workflowCode);
758
+
759
+ export const HEAD = handler;
760
+ export const POST = handler;`;
646
761
  // we skip the final bundling step for Next.js so it can bundle itself
647
762
  if (!bundleFinalOutput) {
648
763
  if (!outfile) {
@@ -738,7 +853,7 @@ export const POST = workflowEntrypoint(workflowCode);`;
738
853
  const { discoveredSerdeFiles } = await this.discoverEntries(inputFiles, outputDir);
739
854
  // Identify serde files that aren't in the inputFiles (deduplicated)
740
855
  const inputFilesNormalized = new Set(inputFiles.map((f) => f.replace(/\\/g, '/')));
741
- const serdeOnlyFiles = discoveredSerdeFiles.filter((f) => !inputFilesNormalized.has(f));
856
+ const serdeOnlyFiles = [...discoveredSerdeFiles].filter((f) => !inputFilesNormalized.has(f));
742
857
  // Re-exports for input files (user's workflow/step definitions).
743
858
  // These must use valid relative specifiers because some frameworks pass
744
859
  // generated files like ".output/server/index.mjs" as input files.