@workflow/cli 4.0.1-beta.1 → 4.0.1-beta.11

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 (85) hide show
  1. package/LICENSE.md +201 -21
  2. package/dist/commands/build.d.ts.map +1 -1
  3. package/dist/commands/build.js +10 -11
  4. package/dist/commands/build.js.map +1 -1
  5. package/dist/commands/cancel.d.ts +1 -0
  6. package/dist/commands/cancel.d.ts.map +1 -1
  7. package/dist/commands/dev.js +2 -2
  8. package/dist/commands/dev.js.map +1 -1
  9. package/dist/commands/init.js +1 -1
  10. package/dist/commands/init.js.map +1 -1
  11. package/dist/commands/inspect.d.ts +1 -0
  12. package/dist/commands/inspect.d.ts.map +1 -1
  13. package/dist/commands/inspect.js +21 -4
  14. package/dist/commands/inspect.js.map +1 -1
  15. package/dist/commands/start.d.ts +1 -0
  16. package/dist/commands/start.d.ts.map +1 -1
  17. package/dist/commands/web.d.ts +26 -0
  18. package/dist/commands/web.d.ts.map +1 -0
  19. package/dist/commands/web.js +56 -0
  20. package/dist/commands/web.js.map +1 -0
  21. package/dist/lib/config/types.d.ts +3 -14
  22. package/dist/lib/config/types.d.ts.map +1 -1
  23. package/dist/lib/config/types.js +1 -8
  24. package/dist/lib/config/types.js.map +1 -1
  25. package/dist/lib/config/workflow-config.d.ts.map +1 -1
  26. package/dist/lib/config/workflow-config.js +2 -1
  27. package/dist/lib/config/workflow-config.js.map +1 -1
  28. package/dist/lib/inspect/flags.d.ts +1 -0
  29. package/dist/lib/inspect/flags.d.ts.map +1 -1
  30. package/dist/lib/inspect/flags.js +8 -0
  31. package/dist/lib/inspect/flags.js.map +1 -1
  32. package/dist/lib/inspect/output.d.ts +1 -0
  33. package/dist/lib/inspect/output.d.ts.map +1 -1
  34. package/dist/lib/inspect/output.js +105 -1
  35. package/dist/lib/inspect/output.js.map +1 -1
  36. package/dist/lib/inspect/run.d.ts.map +1 -1
  37. package/dist/lib/inspect/run.js +33 -5
  38. package/dist/lib/inspect/run.js.map +1 -1
  39. package/dist/lib/inspect/setup.js +2 -2
  40. package/dist/lib/inspect/setup.js.map +1 -1
  41. package/dist/lib/inspect/terminal-utils.js +1 -1
  42. package/dist/lib/inspect/web.d.ts.map +1 -1
  43. package/dist/lib/inspect/web.js +22 -8
  44. package/dist/lib/inspect/web.js.map +1 -1
  45. package/package.json +12 -14
  46. package/dist/lib/builders/apply-swc-transform.d.ts +0 -24
  47. package/dist/lib/builders/apply-swc-transform.d.ts.map +0 -1
  48. package/dist/lib/builders/apply-swc-transform.js +0 -38
  49. package/dist/lib/builders/apply-swc-transform.js.map +0 -1
  50. package/dist/lib/builders/base-builder.d.ts +0 -45
  51. package/dist/lib/builders/base-builder.d.ts.map +0 -1
  52. package/dist/lib/builders/base-builder.js +0 -466
  53. package/dist/lib/builders/base-builder.js.map +0 -1
  54. package/dist/lib/builders/discover-entries-esbuild-plugin.d.ts +0 -11
  55. package/dist/lib/builders/discover-entries-esbuild-plugin.d.ts.map +0 -1
  56. package/dist/lib/builders/discover-entries-esbuild-plugin.js +0 -84
  57. package/dist/lib/builders/discover-entries-esbuild-plugin.js.map +0 -1
  58. package/dist/lib/builders/next-build.d.ts +0 -11
  59. package/dist/lib/builders/next-build.d.ts.map +0 -1
  60. package/dist/lib/builders/next-build.js +0 -331
  61. package/dist/lib/builders/next-build.js.map +0 -1
  62. package/dist/lib/builders/node-module-esbuild-plugin.d.ts +0 -3
  63. package/dist/lib/builders/node-module-esbuild-plugin.d.ts.map +0 -1
  64. package/dist/lib/builders/node-module-esbuild-plugin.js +0 -24
  65. package/dist/lib/builders/node-module-esbuild-plugin.js.map +0 -1
  66. package/dist/lib/builders/node-module-esbuild-plugin.test.d.ts +0 -2
  67. package/dist/lib/builders/node-module-esbuild-plugin.test.d.ts.map +0 -1
  68. package/dist/lib/builders/node-module-esbuild-plugin.test.js +0 -128
  69. package/dist/lib/builders/node-module-esbuild-plugin.test.js.map +0 -1
  70. package/dist/lib/builders/swc-esbuild-plugin.d.ts +0 -12
  71. package/dist/lib/builders/swc-esbuild-plugin.d.ts.map +0 -1
  72. package/dist/lib/builders/swc-esbuild-plugin.js +0 -134
  73. package/dist/lib/builders/swc-esbuild-plugin.js.map +0 -1
  74. package/dist/lib/builders/vercel-build-output-api.d.ts +0 -9
  75. package/dist/lib/builders/vercel-build-output-api.d.ts.map +0 -1
  76. package/dist/lib/builders/vercel-build-output-api.js +0 -138
  77. package/dist/lib/builders/vercel-build-output-api.js.map +0 -1
  78. package/dist/lib/builders/vercel-static.d.ts +0 -7
  79. package/dist/lib/builders/vercel-static.d.ts.map +0 -1
  80. package/dist/lib/builders/vercel-static.js +0 -42
  81. package/dist/lib/builders/vercel-static.js.map +0 -1
  82. package/dist/lib/builders/webhook-route.test.d.ts +0 -2
  83. package/dist/lib/builders/webhook-route.test.d.ts.map +0 -1
  84. package/dist/lib/builders/webhook-route.test.js +0 -199
  85. package/dist/lib/builders/webhook-route.test.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workflow/cli",
3
- "version": "4.0.1-beta.1",
3
+ "version": "4.0.1-beta.11",
4
4
  "description": "Command-line interface for Workflow DevKit",
5
5
  "type": "module",
6
6
  "bin": {
@@ -14,7 +14,7 @@
14
14
  "publishConfig": {
15
15
  "access": "public"
16
16
  },
17
- "license": "MIT",
17
+ "license": "Apache-2.0",
18
18
  "repository": {
19
19
  "type": "git",
20
20
  "url": "https://github.com/vercel/workflow.git",
@@ -30,14 +30,13 @@
30
30
  "topicSeparator": " "
31
31
  },
32
32
  "devDependencies": {
33
- "@types/node": "24.6.2",
33
+ "@types/node": "22.19.0",
34
34
  "@workflow/tsconfig": "4.0.1-beta.0"
35
35
  },
36
36
  "dependencies": {
37
37
  "@oclif/core": "^4.0.0",
38
38
  "@oclif/plugin-help": "^6.0.0",
39
39
  "@swc/core": "1.11.24",
40
- "@types/watchpack": "2.4.4",
41
40
  "boxen": "^8.0.1",
42
41
  "builtin-modules": "^5.0.0",
43
42
  "chalk": "^5.6.2",
@@ -46,29 +45,28 @@
46
45
  "date-fns": "^4.1.0",
47
46
  "easy-table": "^1.2.0",
48
47
  "enhanced-resolve": "5.18.2",
49
- "esbuild": "^0.25.6",
48
+ "esbuild": "^0.25.11",
50
49
  "find-up": "7.0.0",
51
50
  "mixpart": "^0.0.4",
52
51
  "open": "^10.2.0",
53
52
  "ora": "^8.2.0",
54
53
  "terminal-link": "^5.0.0",
55
54
  "tinyglobby": "^0.2.14",
56
- "watchpack": "2.4.4",
57
55
  "xdg-app-paths": "^5.1.0",
58
56
  "zod": "4.1.11",
59
- "@workflow/swc-plugin": "4.0.1-beta.1",
60
- "@workflow/errors": "4.0.1-beta.1",
61
- "@workflow/core": "4.0.1-beta.1",
62
- "@workflow/world": "4.0.1-beta.1",
63
- "@workflow/world-local": "4.0.1-beta.1",
64
- "@workflow/world-vercel": "4.0.1-beta.1",
65
- "@workflow/web": "4.0.1-beta.1"
57
+ "@workflow/errors": "4.0.1-beta.3",
58
+ "@workflow/core": "4.0.1-beta.9",
59
+ "@workflow/swc-plugin": "4.0.1-beta.3",
60
+ "@workflow/web": "4.0.1-beta.8",
61
+ "@workflow/world": "4.0.1-beta.4",
62
+ "@workflow/world-local": "4.0.1-beta.5",
63
+ "@workflow/builders": "4.0.1-beta.7",
64
+ "@workflow/world-vercel": "4.0.1-beta.5"
66
65
  },
67
66
  "scripts": {
68
67
  "build": "tsc && chmod +x bin/run.js",
69
68
  "clean": "tsc --build --clean && rm -r dist ||:",
70
69
  "dev": "tsc --watch",
71
- "test": "vitest run src",
72
70
  "typecheck": "tsc --noEmit"
73
71
  }
74
72
  }
@@ -1,24 +0,0 @@
1
- export type WorkflowManifest = {
2
- steps?: {
3
- [relativeFileName: string]: {
4
- [functionName: string]: {
5
- stepId: string;
6
- };
7
- };
8
- };
9
- workflows?: {
10
- [relativeFileName: string]: {
11
- [functionName: string]: {
12
- workflowId: string;
13
- };
14
- };
15
- };
16
- };
17
- export declare function applySwcTransform(filename: string, source: string, mode: 'workflow' | 'step' | 'client' | false, jscConfig?: {
18
- paths?: Record<string, string[]>;
19
- baseUrl?: string;
20
- }): Promise<{
21
- code: string;
22
- workflowManifest: WorkflowManifest;
23
- }>;
24
- //# sourceMappingURL=apply-swc-transform.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apply-swc-transform.d.ts","sourceRoot":"","sources":["../../../src/lib/builders/apply-swc-transform.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE;QACN,CAAC,gBAAgB,EAAE,MAAM,GAAG;YAC1B,CAAC,YAAY,EAAE,MAAM,GAAG;gBACtB,MAAM,EAAE,MAAM,CAAC;aAChB,CAAC;SACH,CAAC;KACH,CAAC;IACF,SAAS,CAAC,EAAE;QACV,CAAC,gBAAgB,EAAE,MAAM,GAAG;YAC1B,CAAC,YAAY,EAAE,MAAM,GAAG;gBACtB,UAAU,EAAE,MAAM,CAAC;aACpB,CAAC;SACH,CAAC;KACH,CAAC;CACH,CAAC;AAEF,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,EAC5C,SAAS,CAAC,EAAE;IACV,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAEjC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GACA,OAAO,CAAC;IACT,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,gBAAgB,CAAC;CACpC,CAAC,CAyCD"}
@@ -1,38 +0,0 @@
1
- import { transform } from '@swc/core';
2
- import { createRequire } from 'module';
3
- const require = createRequire(import.meta.filename);
4
- export async function applySwcTransform(filename, source, mode, jscConfig) {
5
- // Determine if this is a TypeScript file
6
- const isTypeScript = filename.endsWith('.ts') || filename.endsWith('.tsx');
7
- const isTsx = filename.endsWith('.tsx');
8
- // Transform with SWC to support syntax esbuild doesn't
9
- const result = await transform(source, {
10
- filename,
11
- swcrc: false,
12
- jsc: {
13
- parser: {
14
- syntax: isTypeScript ? 'typescript' : 'ecmascript',
15
- tsx: isTsx,
16
- },
17
- target: 'es2022',
18
- experimental: mode
19
- ? {
20
- plugins: [[require.resolve('@workflow/swc-plugin'), { mode }]],
21
- }
22
- : undefined,
23
- ...jscConfig,
24
- },
25
- // TODO: investigate proper source map support as they
26
- // won't even be used in Node.js by default unless we
27
- // intercept errors and apply them ourselves
28
- sourceMaps: false,
29
- minify: false,
30
- });
31
- const workflowCommentMatch = result.code.match(/\/\*\*__internal_workflows({.*?})\*\//s);
32
- const parsedWorkflows = JSON.parse(workflowCommentMatch?.[1] || '{}');
33
- return {
34
- code: result.code,
35
- workflowManifest: parsedWorkflows || {},
36
- };
37
- }
38
- //# sourceMappingURL=apply-swc-transform.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apply-swc-transform.js","sourceRoot":"","sources":["../../../src/lib/builders/apply-swc-transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAmBpD,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,QAAgB,EAChB,MAAc,EACd,IAA4C,EAC5C,SAIC;IAKD,yCAAyC;IACzC,MAAM,YAAY,GAAG,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3E,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAExC,uDAAuD;IACvD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,EAAE;QACrC,QAAQ;QACR,KAAK,EAAE,KAAK;QACZ,GAAG,EAAE;YACH,MAAM,EAAE;gBACN,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY;gBAClD,GAAG,EAAE,KAAK;aACX;YACD,MAAM,EAAE,QAAQ;YAChB,YAAY,EAAE,IAAI;gBAChB,CAAC,CAAC;oBACE,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;iBAC/D;gBACH,CAAC,CAAC,SAAS;YACb,GAAG,SAAS;SACb;QACD,sDAAsD;QACtD,qDAAqD;QACrD,4CAA4C;QAC5C,UAAU,EAAE,KAAK;QACjB,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;IAEH,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAC5C,wCAAwC,CACzC,CAAC;IAEF,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAChC,oBAAoB,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CACd,CAAC;IAEtB,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,gBAAgB,EAAE,eAAe,IAAI,EAAE;KACxC,CAAC;AACJ,CAAC"}
@@ -1,45 +0,0 @@
1
- import * as esbuild from 'esbuild';
2
- import type { WorkflowConfig } from '../config/types.js';
3
- export declare abstract class BaseBuilder {
4
- protected config: WorkflowConfig;
5
- constructor(config: WorkflowConfig);
6
- abstract build(): Promise<void>;
7
- protected getTsConfigOptions(): Promise<{
8
- baseUrl?: string;
9
- paths?: Record<string, string[]>;
10
- }>;
11
- protected getInputFiles(): Promise<string[]>;
12
- private discoveredEntries;
13
- protected discoverEntries(inputs: string[], outdir: string): Promise<{
14
- discoveredSteps: string[];
15
- discoveredWorkflows: string[];
16
- }>;
17
- private writeDebugFile;
18
- private logEsbuildMessages;
19
- protected createStepsBundle({ inputFiles, format, outfile, externalizeNonSteps, tsBaseUrl, tsPaths, }: {
20
- tsPaths?: Record<string, string[]>;
21
- tsBaseUrl?: string;
22
- inputFiles: string[];
23
- outfile: string;
24
- format?: 'cjs' | 'esm';
25
- externalizeNonSteps?: boolean;
26
- }): Promise<esbuild.BuildContext | undefined>;
27
- protected createWorkflowsBundle({ inputFiles, format, outfile, bundleFinalOutput, tsBaseUrl, tsPaths, }: {
28
- tsPaths?: Record<string, string[]>;
29
- tsBaseUrl?: string;
30
- inputFiles: string[];
31
- outfile: string;
32
- format?: 'cjs' | 'esm';
33
- bundleFinalOutput?: boolean;
34
- }): Promise<void | {
35
- interimBundleCtx: esbuild.BuildContext;
36
- bundleFinal: (interimBundleResult: string) => Promise<void>;
37
- }>;
38
- protected buildClientLibrary(): Promise<void>;
39
- protected createWebhookBundle({ outfile, bundle, }: {
40
- outfile: string;
41
- bundle?: boolean;
42
- }): Promise<void>;
43
- private createSwcGitignore;
44
- }
45
- //# sourceMappingURL=base-builder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base-builder.d.ts","sourceRoot":"","sources":["../../../src/lib/builders/base-builder.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAWzD,8BAAsB,WAAW;IAC/B,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC;gBAErB,MAAM,EAAE,cAAc;IAIlC,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;cAEf,kBAAkB,IAAI,OAAO,CAAC;QAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;KAClC,CAAC;cA0Cc,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAwBlD,OAAO,CAAC,iBAAiB,CAMP;cAEF,eAAe,CAC7B,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;QACT,eAAe,EAAE,MAAM,EAAE,CAAC;QAC1B,mBAAmB,EAAE,MAAM,EAAE,CAAC;KAC/B,CAAC;YAyCY,cAAc;IA4B5B,OAAO,CAAC,kBAAkB;cA6BV,iBAAiB,CAAC,EAChC,UAAU,EACV,MAAc,EACd,OAAO,EACP,mBAAmB,EACnB,SAAS,EACT,OAAO,GACR,EAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACnC,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;QACvB,mBAAmB,CAAC,EAAE,OAAO,CAAC;KAC/B,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;cA6G7B,qBAAqB,CAAC,EACpC,UAAU,EACV,MAAc,EACd,OAAO,EACP,iBAAwB,EACxB,SAAS,EACT,OAAO,GACR,EAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACnC,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;QACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;KAC7B,GAAG,OAAO,CAAC,IAAI,GAAG;QACjB,gBAAgB,EAAE,OAAO,CAAC,YAAY,CAAC;QACvC,WAAW,EAAE,CAAC,mBAAmB,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KAC7D,CAAC;cA8Kc,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;cAmDnC,mBAAmB,CAAC,EAClC,OAAO,EACP,MAAc,GACf,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,GAAG,OAAO,CAAC,IAAI,CAAC;YAiFH,kBAAkB;CAUjC"}
@@ -1,466 +0,0 @@
1
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
- import { dirname, join, resolve } from 'node:path';
3
- import { promisify } from 'node:util';
4
- import chalk from 'chalk';
5
- import { parse } from 'comment-json';
6
- import enhancedResolveOriginal from 'enhanced-resolve';
7
- import * as esbuild from 'esbuild';
8
- import { findUp } from 'find-up';
9
- import { glob } from 'tinyglobby';
10
- import { createDiscoverEntriesPlugin } from './discover-entries-esbuild-plugin.js';
11
- import { createNodeModuleErrorPlugin } from './node-module-esbuild-plugin.js';
12
- import { createSwcPlugin } from './swc-esbuild-plugin.js';
13
- const enhancedResolve = promisify(enhancedResolveOriginal);
14
- const EMIT_SOURCEMAPS_FOR_DEBUGGING = process.env.WORKFLOW_EMIT_SOURCEMAPS_FOR_DEBUGGING === '1';
15
- export class BaseBuilder {
16
- config;
17
- constructor(config) {
18
- this.config = config;
19
- }
20
- async getTsConfigOptions() {
21
- const options = {};
22
- const cwd = this.config.workingDir || process.cwd();
23
- const tsJsConfig = await findUp(['tsconfig.json', 'jsconfig.json'], {
24
- cwd,
25
- });
26
- if (tsJsConfig) {
27
- try {
28
- const rawJson = await readFile(tsJsConfig, 'utf8');
29
- const parsed = parse(rawJson);
30
- if (parsed) {
31
- options.paths = parsed.compilerOptions?.paths;
32
- if (parsed.compilerOptions?.baseUrl) {
33
- options.baseUrl = resolve(cwd, parsed.compilerOptions.baseUrl);
34
- }
35
- else {
36
- options.baseUrl = cwd;
37
- }
38
- }
39
- }
40
- catch (err) {
41
- console.error(`Failed to parse ${tsJsConfig} aliases might not apply properly`, err);
42
- }
43
- }
44
- return options;
45
- }
46
- async getInputFiles() {
47
- const result = await glob(this.config.dirs.map((dir) => `${resolve(this.config.workingDir, dir)}/**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}`), {
48
- ignore: [
49
- '**/node_modules/**',
50
- '**/.git/**',
51
- '**/.next/**',
52
- '**/.vercel/**',
53
- '**/.workflow-data/**',
54
- '**/.well-known/workflow/**',
55
- ],
56
- absolute: true,
57
- });
58
- return result;
59
- }
60
- discoveredEntries = new WeakMap();
61
- async discoverEntries(inputs, outdir) {
62
- const previousResult = this.discoveredEntries.get(inputs);
63
- if (previousResult) {
64
- return previousResult;
65
- }
66
- const state = {
67
- discoveredSteps: [],
68
- discoveredWorkflows: [],
69
- };
70
- const discoverStart = Date.now();
71
- try {
72
- await esbuild.build({
73
- treeShaking: true,
74
- entryPoints: inputs,
75
- plugins: [createDiscoverEntriesPlugin(state)],
76
- platform: 'node',
77
- write: false,
78
- outdir,
79
- bundle: true,
80
- sourcemap: EMIT_SOURCEMAPS_FOR_DEBUGGING,
81
- absWorkingDir: this.config.workingDir,
82
- logLevel: 'silent',
83
- });
84
- }
85
- catch (_) { }
86
- console.log(`Discovering workflow directives`, `${Date.now() - discoverStart}ms`);
87
- this.discoveredEntries.set(inputs, state);
88
- return state;
89
- }
90
- // write debug information to JSON file (maybe move to diagnostics folder)
91
- // if on Vercel
92
- async writeDebugFile(outfile, debugData, merge) {
93
- try {
94
- let existing = {};
95
- if (merge) {
96
- existing = JSON.parse(await readFile(`${outfile}.debug.json`, 'utf8').catch(() => '{}'));
97
- }
98
- await writeFile(`${outfile}.debug.json`, JSON.stringify({
99
- ...existing,
100
- ...debugData,
101
- }, null, 2));
102
- }
103
- catch (error) {
104
- console.warn('Failed to write debug file:', error);
105
- }
106
- }
107
- logEsbuildMessages(result, phase) {
108
- if (result.errors && result.errors.length > 0) {
109
- console.error(`❌ esbuild errors in ${phase}:`);
110
- for (const error of result.errors) {
111
- console.error(` ${error.text}`);
112
- if (error.location) {
113
- console.error(` at ${error.location.file}:${error.location.line}:${error.location.column}`);
114
- }
115
- }
116
- }
117
- if (result.warnings && result.warnings.length > 0) {
118
- console.warn(`! esbuild warnings in ${phase}:`);
119
- for (const warning of result.warnings) {
120
- console.warn(` ${warning.text}`);
121
- if (warning.location) {
122
- console.warn(` at ${warning.location.file}:${warning.location.line}:${warning.location.column}`);
123
- }
124
- }
125
- }
126
- }
127
- async createStepsBundle({ inputFiles, format = 'cjs', outfile, externalizeNonSteps, tsBaseUrl, tsPaths, }) {
128
- // These need to handle watching for dev to scan for
129
- // new entries and changes to existing ones
130
- const { discoveredSteps: stepFiles } = await this.discoverEntries(inputFiles, dirname(outfile));
131
- // log the step files for debugging
132
- await this.writeDebugFile(outfile, { stepFiles });
133
- const stepsBundleStart = Date.now();
134
- const workflowManifest = {};
135
- const builtInSteps = 'workflow/internal/builtins';
136
- const resolvedBuiltInSteps = await enhancedResolve(dirname(outfile), 'workflow/internal/builtins').catch((err) => {
137
- throw new Error([
138
- chalk.red('Failed to resolve built-in steps sources.'),
139
- `${chalk.yellow.bold('hint:')} run \`${chalk.cyan.italic('npm install workflow')}\` to resolve this issue.`,
140
- '',
141
- `Caused by: ${chalk.red(String(err))}`,
142
- ].join('\n'));
143
- });
144
- // Create a virtual entry that imports all files. All step definitions
145
- // will get registered thanks to the swc transform.
146
- const imports = stepFiles.map((file) => `import '${file}';`).join('\n');
147
- const entryContent = `
148
- // Built in steps
149
- import '${builtInSteps}';
150
- // User steps
151
- ${imports}
152
- // API entrypoint
153
- export { stepEntrypoint as POST } from 'workflow/runtime';`;
154
- // Bundle with esbuild and our custom SWC plugin
155
- const esbuildCtx = await esbuild.context({
156
- banner: {
157
- js: '// biome-ignore-all lint: generated file\n/* eslint-disable */\n',
158
- },
159
- stdin: {
160
- contents: entryContent,
161
- resolveDir: this.config.workingDir,
162
- sourcefile: 'virtual-entry.js',
163
- loader: 'js',
164
- },
165
- outfile,
166
- absWorkingDir: this.config.workingDir,
167
- bundle: true,
168
- format,
169
- platform: 'node',
170
- conditions: ['node'],
171
- target: 'es2022',
172
- write: true,
173
- treeShaking: true,
174
- keepNames: true,
175
- minify: false,
176
- resolveExtensions: ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'],
177
- // TODO: investigate proper source map support
178
- sourcemap: EMIT_SOURCEMAPS_FOR_DEBUGGING,
179
- plugins: [
180
- createSwcPlugin({
181
- mode: 'step',
182
- entriesToBundle: externalizeNonSteps
183
- ? [
184
- ...stepFiles,
185
- ...(resolvedBuiltInSteps ? [resolvedBuiltInSteps] : []),
186
- ]
187
- : undefined,
188
- outdir: outfile ? dirname(outfile) : undefined,
189
- tsBaseUrl,
190
- tsPaths,
191
- workflowManifest,
192
- }),
193
- ],
194
- // Plugin should catch most things, but this lets users hard override
195
- // if the plugin misses anything that should be externalized
196
- external: this.config.externalPackages || [],
197
- });
198
- const stepsResult = await esbuildCtx.rebuild();
199
- this.logEsbuildMessages(stepsResult, 'steps bundle creation');
200
- console.log('Created steps bundle', `${Date.now() - stepsBundleStart}ms`);
201
- const partialWorkflowManifest = {
202
- steps: workflowManifest.steps,
203
- };
204
- // always write to debug file
205
- await this.writeDebugFile(join(dirname(outfile), 'manifest'), partialWorkflowManifest, true);
206
- // Create .gitignore in .swc directory
207
- await this.createSwcGitignore();
208
- if (this.config.watch) {
209
- return esbuildCtx;
210
- }
211
- await esbuildCtx.dispose();
212
- }
213
- async createWorkflowsBundle({ inputFiles, format = 'cjs', outfile, bundleFinalOutput = true, tsBaseUrl, tsPaths, }) {
214
- const { discoveredWorkflows: workflowFiles } = await this.discoverEntries(inputFiles, dirname(outfile));
215
- // log the workflow files for debugging
216
- await this.writeDebugFile(outfile, { workflowFiles });
217
- // Create a virtual entry that imports all files
218
- const imports = `globalThis.__private_workflows = new Map();\n` +
219
- workflowFiles
220
- .map((file, workflowFileIdx) => `import * as workflowFile${workflowFileIdx} from '${file}';
221
- Object.values(workflowFile${workflowFileIdx}).map(item => item?.workflowId && globalThis.__private_workflows.set(item.workflowId, item))`)
222
- .join('\n');
223
- const bundleStartTime = Date.now();
224
- const workflowManifest = {};
225
- // Bundle with esbuild and our custom SWC plugin in workflow mode.
226
- // this bundle will be run inside a vm isolate
227
- const interimBundleCtx = await esbuild.context({
228
- stdin: {
229
- contents: imports,
230
- resolveDir: this.config.workingDir,
231
- sourcefile: 'virtual-entry.js',
232
- loader: 'js',
233
- },
234
- bundle: true,
235
- absWorkingDir: this.config.workingDir,
236
- format: 'cjs', // Runs inside the VM which expects cjs
237
- platform: 'neutral', // The platform is neither node nor browser
238
- mainFields: ['module', 'main'], // To support npm style imports
239
- conditions: ['workflow'], // Allow packages to export 'workflow' compliant versions
240
- target: 'es2022',
241
- write: false,
242
- treeShaking: true,
243
- keepNames: true,
244
- minify: false,
245
- // TODO: investigate proper source map support
246
- sourcemap: EMIT_SOURCEMAPS_FOR_DEBUGGING,
247
- resolveExtensions: ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'],
248
- plugins: [
249
- createSwcPlugin({
250
- mode: 'workflow',
251
- tsBaseUrl,
252
- tsPaths,
253
- workflowManifest,
254
- }),
255
- // This plugin must run after the swc plugin to ensure dead code elimination
256
- // happens first, preventing false positives on Node.js imports in unused code paths
257
- createNodeModuleErrorPlugin(),
258
- ],
259
- });
260
- const interimBundle = await interimBundleCtx.rebuild();
261
- this.logEsbuildMessages(interimBundle, 'intermediate workflow bundle');
262
- console.log('Created intermediate workflow bundle', `${Date.now() - bundleStartTime}ms`);
263
- const partialWorkflowManifest = {
264
- workflows: workflowManifest.workflows,
265
- };
266
- await this.writeDebugFile(join(dirname(outfile), 'manifest'), partialWorkflowManifest, true);
267
- if (this.config.workflowManifestPath) {
268
- const resolvedPath = resolve(process.cwd(), this.config.workflowManifestPath);
269
- let prefix = '';
270
- if (resolvedPath.endsWith('.cjs')) {
271
- prefix = 'module.exports = ';
272
- }
273
- else if (resolvedPath.endsWith('.js') ||
274
- resolvedPath.endsWith('.mjs')) {
275
- prefix = 'export default ';
276
- }
277
- await mkdir(dirname(resolvedPath), { recursive: true });
278
- await writeFile(resolvedPath, prefix + JSON.stringify(workflowManifest.workflows, null, 2));
279
- }
280
- // Create .gitignore in .swc directory
281
- await this.createSwcGitignore();
282
- if (!interimBundle.outputFiles || interimBundle.outputFiles.length === 0) {
283
- throw new Error('No output files generated from esbuild');
284
- }
285
- const bundleFinal = async (interimBundle) => {
286
- const workflowBundleCode = interimBundle;
287
- // Create the workflow function handler with proper linter suppressions
288
- const workflowFunctionCode = `// biome-ignore-all lint: generated file
289
- /* eslint-disable */
290
- import { workflowEntrypoint } from 'workflow/runtime';
291
-
292
- const workflowCode = \`${workflowBundleCode.replace(/[\\`$]/g, '\\$&')}\`;
293
-
294
- export const POST = workflowEntrypoint(workflowCode);`;
295
- // we skip the final bundling step for Next.js so it can bundle itself
296
- if (!bundleFinalOutput) {
297
- if (!outfile) {
298
- throw new Error(`Invariant: missing outfile for workflow bundle`);
299
- }
300
- // Ensure the output directory exists
301
- const outputDir = dirname(outfile);
302
- await mkdir(outputDir, { recursive: true });
303
- await writeFile(outfile, workflowFunctionCode);
304
- return;
305
- }
306
- const bundleStartTime = Date.now();
307
- // Now bundle this so we can resolve the @workflow/core dependency
308
- // we could remove this if we do nft tracing or similar instead
309
- const finalWorkflowResult = await esbuild.build({
310
- banner: {
311
- js: '// biome-ignore-all lint: generated file\n/* eslint-disable */\n',
312
- },
313
- stdin: {
314
- contents: workflowFunctionCode,
315
- resolveDir: this.config.workingDir,
316
- sourcefile: 'virtual-entry.js',
317
- loader: 'js',
318
- },
319
- outfile,
320
- // TODO: investigate proper source map support
321
- sourcemap: EMIT_SOURCEMAPS_FOR_DEBUGGING,
322
- absWorkingDir: this.config.workingDir,
323
- bundle: true,
324
- format,
325
- platform: 'node',
326
- target: 'es2022',
327
- write: true,
328
- keepNames: true,
329
- minify: false,
330
- external: ['@aws-sdk/credential-provider-web-identity'],
331
- });
332
- this.logEsbuildMessages(finalWorkflowResult, 'final workflow bundle');
333
- console.log('Created final workflow bundle', `${Date.now() - bundleStartTime}ms`);
334
- };
335
- await bundleFinal(interimBundle.outputFiles[0].text);
336
- if (this.config.watch) {
337
- return {
338
- interimBundleCtx,
339
- bundleFinal,
340
- };
341
- }
342
- await interimBundleCtx.dispose();
343
- }
344
- async buildClientLibrary() {
345
- if (!this.config.clientBundlePath) {
346
- // Silently exit since no client bundle was requested
347
- return;
348
- }
349
- console.log('Generating a client library at', this.config.clientBundlePath);
350
- console.log('NOTE: The recommended way to use workflow with a framework like NextJS is using the loader/plugin with webpack/turbobpack/rollup');
351
- // Ensure we have the directory for the client bundle
352
- const outputDir = dirname(this.config.clientBundlePath);
353
- await mkdir(outputDir, { recursive: true });
354
- const inputFiles = await this.getInputFiles();
355
- // Create a virtual entry that imports all files
356
- const imports = inputFiles
357
- .map((file) => `export * from '${file}';`)
358
- .join('\n');
359
- // Bundle with esbuild and our custom SWC plugin
360
- const clientResult = await esbuild.build({
361
- banner: {
362
- js: '// biome-ignore-all lint: generated file\n/* eslint-disable */\n',
363
- },
364
- stdin: {
365
- contents: imports,
366
- resolveDir: this.config.workingDir,
367
- sourcefile: 'virtual-entry.js',
368
- loader: 'js',
369
- },
370
- outfile: this.config.clientBundlePath,
371
- bundle: true,
372
- format: 'esm',
373
- platform: 'node',
374
- target: 'es2022',
375
- write: true,
376
- treeShaking: true,
377
- external: ['@workflow/core'],
378
- resolveExtensions: ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'],
379
- plugins: [createSwcPlugin({ mode: 'client' })],
380
- });
381
- this.logEsbuildMessages(clientResult, 'client library bundle');
382
- // Create .gitignore in .swc directory
383
- await this.createSwcGitignore();
384
- }
385
- async createWebhookBundle({ outfile, bundle = false, }) {
386
- console.log('Creating webhook route');
387
- await mkdir(dirname(outfile), { recursive: true });
388
- // Create a static route that calls resumeWebhook
389
- // This route works for both Next.js and Vercel Build Output API
390
- const routeContent = `import { resumeWebhook } from 'workflow/api';
391
-
392
- async function handler(request) {
393
- const url = new URL(request.url);
394
- // Extract token from pathname: /.well-known/workflow/v1/webhook/{token}
395
- const pathParts = url.pathname.split('/');
396
- const token = decodeURIComponent(pathParts[pathParts.length - 1]);
397
-
398
- if (!token) {
399
- return new Response('Missing token', { status: 400 });
400
- }
401
-
402
- try {
403
- const response = await resumeWebhook(token, request);
404
- return response;
405
- } catch (error) {
406
- // TODO: differentiate between invalid token and other errors
407
- console.error('Error during resumeWebhook', error);
408
- return new Response(null, { status: 404 });
409
- }
410
- }
411
-
412
- export const GET = handler;
413
- export const POST = handler;
414
- export const PUT = handler;
415
- export const PATCH = handler;
416
- export const DELETE = handler;
417
- export const HEAD = handler;
418
- export const OPTIONS = handler;
419
- `;
420
- if (!bundle) {
421
- // For Next.js, just write the unbundled file
422
- await writeFile(outfile, routeContent);
423
- return;
424
- }
425
- // For Build Output API, bundle with esbuild to resolve imports
426
- const webhookBundleStart = Date.now();
427
- const result = await esbuild.build({
428
- banner: {
429
- js: '// biome-ignore-all lint: generated file\n/* eslint-disable */\n',
430
- },
431
- stdin: {
432
- contents: routeContent,
433
- resolveDir: this.config.workingDir,
434
- sourcefile: 'webhook-route.js',
435
- loader: 'js',
436
- },
437
- outfile,
438
- absWorkingDir: this.config.workingDir,
439
- bundle: true,
440
- format: 'cjs',
441
- platform: 'node',
442
- conditions: ['import', 'module', 'node', 'default'],
443
- target: 'es2022',
444
- write: true,
445
- treeShaking: true,
446
- keepNames: true,
447
- minify: false,
448
- resolveExtensions: ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'],
449
- sourcemap: false,
450
- mainFields: ['module', 'main'],
451
- // Don't externalize anything - bundle everything including workflow packages
452
- external: [],
453
- });
454
- this.logEsbuildMessages(result, 'webhook bundle creation');
455
- console.log('Created webhook bundle', `${Date.now() - webhookBundleStart}ms`);
456
- }
457
- async createSwcGitignore() {
458
- try {
459
- await writeFile(join(this.config.workingDir, '.swc', '.gitignore'), '*\n');
460
- }
461
- catch {
462
- // We're intentionally silently ignoring this error - creating .gitignore isn't critical
463
- }
464
- }
465
- }
466
- //# sourceMappingURL=base-builder.js.map