@workflow/nitro 5.0.0-beta.4 → 5.0.0-beta.5

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 +1 @@
1
- {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EAEX,2BAA2B,EAC5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAezC,qBAAa,aAAc,SAAQ,2BAA2B;gBAChD,KAAK,EAAE,KAAK;IAWT,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAWtC;AAED,qBAAa,YAAa,SAAQ,WAAW;;gBAE/B,KAAK,EAAE,KAAK;IAkBf,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CA2EhC"}
1
+ {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EAEX,2BAA2B,EAC5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAezC,qBAAa,aAAc,SAAQ,2BAA2B;gBAChD,KAAK,EAAE,KAAK;IAYT,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAWtC;AAED,qBAAa,YAAa,SAAQ,WAAW;;gBAE/B,KAAK,EAAE,KAAK;IAmBf,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAkDhC"}
package/dist/builders.js CHANGED
@@ -1,5 +1,4 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
1
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
3
2
  import { BaseBuilder, createBaseBuilderConfig, VercelBuildOutputAPIBuilder, } from '@workflow/builders';
4
3
  import { join } from 'pathe';
5
4
  /**
@@ -18,6 +17,7 @@ export class VercelBuilder extends VercelBuildOutputAPIBuilder {
18
17
  workingDir: nitro.options.rootDir,
19
18
  dirs: ['.'], // Different apps that use nitro have different directories
20
19
  runtime: nitro.options.workflow?.runtime,
20
+ sourcemap: nitro.options.workflow?.sourcemap,
21
21
  externalPackages: getNitroStringExternals(nitro),
22
22
  }),
23
23
  buildTarget: 'vercel-build-output-api',
@@ -41,6 +41,7 @@ export class LocalBuilder extends BaseBuilder {
41
41
  workingDir: nitro.options.rootDir,
42
42
  watch: nitro.options.dev,
43
43
  dirs: ['.'], // Different apps that use nitro have different directories
44
+ sourcemap: nitro.options.workflow?.sourcemap,
44
45
  externalPackages: getNitroStringExternals(nitro),
45
46
  }),
46
47
  buildTarget: 'next', // Placeholder, not actually used
@@ -61,59 +62,37 @@ export class LocalBuilder extends BaseBuilder {
61
62
  async #buildOnce() {
62
63
  const inputFiles = await this.getInputFiles();
63
64
  await mkdir(this.#outDir, { recursive: true });
64
- // Build to temporary files first, then move them into place.
65
- // This prevents leaving partial/inconsistent output when a build
66
- // fails mid-way (e.g., a file was deleted between discovery and
67
- // compilation during dev HMR). A per-build UUID guarantees uniqueness
68
- // across concurrent invocations, in case the queue is bypassed.
69
- const tmpSuffix = `.tmp.${randomUUID()}`;
70
- const workflowsTmpFile = join(this.#outDir, `workflows${tmpSuffix}.mjs`);
71
- const stepsTmpFile = join(this.#outDir, `steps${tmpSuffix}.mjs`);
72
- const webhookTmpFile = join(this.#outDir, `webhook${tmpSuffix}.mjs`);
73
- try {
74
- const { manifest: workflowsManifest } = await this.createWorkflowsBundle({
75
- outfile: workflowsTmpFile,
76
- bundleFinalOutput: false,
77
- format: 'esm',
78
- inputFiles,
79
- });
80
- const { manifest: stepsManifest } = await this.createStepsBundle({
81
- outfile: stepsTmpFile,
82
- externalizeNonSteps: true,
83
- format: 'esm',
84
- inputFiles,
85
- });
86
- await this.createWebhookBundle({
87
- outfile: webhookTmpFile,
88
- bundle: false,
89
- });
90
- // All builds succeeded — atomically move files into place
91
- await rename(workflowsTmpFile, join(this.#outDir, 'workflows.mjs'));
92
- await rename(stepsTmpFile, join(this.#outDir, 'steps.mjs'));
93
- await rename(webhookTmpFile, join(this.#outDir, 'webhook.mjs'));
94
- // Merge manifests from both bundles
95
- const manifest = {
96
- steps: { ...stepsManifest.steps, ...workflowsManifest.steps },
97
- workflows: {
98
- ...stepsManifest.workflows,
99
- ...workflowsManifest.workflows,
100
- },
101
- classes: { ...stepsManifest.classes, ...workflowsManifest.classes },
102
- };
103
- // Generate manifest
104
- const workflowBundlePath = join(this.#outDir, 'workflows.mjs');
105
- await this.createManifest({
106
- workflowBundlePath,
107
- manifestDir: this.#outDir,
108
- manifest,
109
- });
110
- }
111
- finally {
112
- // Clean up temporary files on success or failure
113
- await unlink(workflowsTmpFile).catch(() => { });
114
- await unlink(stepsTmpFile).catch(() => { });
115
- await unlink(webhookTmpFile).catch(() => { });
116
- }
65
+ // V2: The combined bundle's flow route references the steps file by
66
+ // name in its import statement, so we build directly to final names.
67
+ // (The V1 atomic tmp-file pattern doesn't work here because renaming
68
+ // the steps file would leave the flow route's import stale.)
69
+ const { manifest } = await this.createCombinedBundle({
70
+ inputFiles,
71
+ stepsOutfile: join(this.#outDir, 'steps.mjs'),
72
+ flowOutfile: join(this.#outDir, 'workflows.mjs'),
73
+ format: 'esm',
74
+ // bundleFinalOutput: false — Nitro externalizes the workflow build dir
75
+ // during dev, and its own rollup pipeline handles bundling for prod.
76
+ // Using true causes "Dynamic require of X is not supported" errors
77
+ // because esbuild wraps CJS require() calls in ESM output.
78
+ bundleFinalOutput: false,
79
+ externalizeNonSteps: true,
80
+ // In dev, Nitro dynamically imports the generated workflow files from
81
+ // disk, so there is no later Rollup pass to resolve externalized local
82
+ // TypeScript imports. In prod, Nitro/Rollup handles those imports.
83
+ bundleTransitiveLocalStepDependencies: this.config.watch,
84
+ });
85
+ await this.createWebhookBundle({
86
+ outfile: join(this.#outDir, 'webhook.mjs'),
87
+ bundle: false,
88
+ });
89
+ // Generate manifest
90
+ const workflowBundlePath = join(this.#outDir, 'workflows.mjs');
91
+ await this.createManifest({
92
+ workflowBundlePath,
93
+ manifestDir: this.#outDir,
94
+ manifest,
95
+ });
117
96
  }
118
97
  }
119
98
  //# sourceMappingURL=builders.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAE7B;;;;GAIG;AACH,SAAS,uBAAuB,CAAC,KAAY;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CACzD,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CACtD,CAAC;IACF,OAAO,SAAS,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACnE,CAAC;AAED,MAAM,OAAO,aAAc,SAAQ,2BAA2B;IAC5D,YAAY,KAAY;QACtB,KAAK,CAAC;YACJ,GAAG,uBAAuB,CAAC;gBACzB,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO;gBACjC,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,2DAA2D;gBACxE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO;gBACxC,gBAAgB,EAAE,uBAAuB,CAAC,KAAK,CAAC;aACjD,CAAC;YACF,WAAW,EAAE,yBAAyB;SACvC,CAAC,CAAC;IACL,CAAC;IACQ,KAAK,CAAC,KAAK;QA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C,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;CACF","sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';\nimport {\n BaseBuilder,\n createBaseBuilderConfig,\n VercelBuildOutputAPIBuilder,\n} from '@workflow/builders';\nimport type { Nitro } from 'nitro/types';\nimport { join } from 'pathe';\n\n/**\n * Forward string entries from Nitro's `externals.external` config to the\n * workflow builder's esbuild `external` option. RegExp and function entries\n * are skipped since esbuild's `external` only supports literal strings.\n */\nfunction getNitroStringExternals(nitro: Nitro): string[] | undefined {\n const externals = nitro.options.externals?.external?.filter(\n (entry): entry is string => typeof entry === 'string'\n );\n return externals && externals.length > 0 ? externals : undefined;\n}\n\nexport class VercelBuilder extends VercelBuildOutputAPIBuilder {\n constructor(nitro: Nitro) {\n super({\n ...createBaseBuilderConfig({\n workingDir: nitro.options.rootDir,\n dirs: ['.'], // Different apps that use nitro have different directories\n runtime: nitro.options.workflow?.runtime,\n externalPackages: getNitroStringExternals(nitro),\n }),\n buildTarget: 'vercel-build-output-api',\n });\n }\n override async build(): Promise<void> {\n const configPath = join(\n this.config.workingDir,\n '.vercel/output/config.json'\n );\n const originalConfig = JSON.parse(await readFile(configPath, 'utf-8'));\n await super.build();\n const newConfig = JSON.parse(await readFile(configPath, 'utf-8'));\n originalConfig.routes.unshift(...newConfig.routes);\n await writeFile(configPath, JSON.stringify(originalConfig, null, 2));\n }\n}\n\nexport class LocalBuilder extends BaseBuilder {\n #outDir: string;\n constructor(nitro: Nitro) {\n const outDir = join(nitro.options.buildDir, 'workflow');\n super({\n ...createBaseBuilderConfig({\n workingDir: nitro.options.rootDir,\n watch: nitro.options.dev,\n dirs: ['.'], // Different apps that use nitro have different directories\n externalPackages: getNitroStringExternals(nitro),\n }),\n buildTarget: 'next', // Placeholder, not actually used\n });\n this.#outDir = outDir;\n }\n\n // Serialize concurrent build() calls so overlapping dev rebuilds don't\n // stomp on each other's temp files or partially overwrite output.\n #buildQueue: Promise<void> = Promise.resolve();\n\n override build(): Promise<void> {\n const next = this.#buildQueue.then(\n () => this.#buildOnce(),\n () => this.#buildOnce()\n );\n // Swallow rejections on the queue itself so a failed build doesn't\n // permanently reject all subsequent builds; each caller still sees\n // its own rejection via the returned promise.\n this.#buildQueue = next.catch(() => {});\n return next;\n }\n\n async #buildOnce(): Promise<void> {\n const inputFiles = await this.getInputFiles();\n await mkdir(this.#outDir, { recursive: true });\n\n // Build to temporary files first, then move them into place.\n // This prevents leaving partial/inconsistent output when a build\n // fails mid-way (e.g., a file was deleted between discovery and\n // compilation during dev HMR). A per-build UUID guarantees uniqueness\n // across concurrent invocations, in case the queue is bypassed.\n const tmpSuffix = `.tmp.${randomUUID()}`;\n const workflowsTmpFile = join(this.#outDir, `workflows${tmpSuffix}.mjs`);\n const stepsTmpFile = join(this.#outDir, `steps${tmpSuffix}.mjs`);\n const webhookTmpFile = join(this.#outDir, `webhook${tmpSuffix}.mjs`);\n\n try {\n const { manifest: workflowsManifest } = await this.createWorkflowsBundle({\n outfile: workflowsTmpFile,\n bundleFinalOutput: false,\n format: 'esm',\n inputFiles,\n });\n\n const { manifest: stepsManifest } = await this.createStepsBundle({\n outfile: stepsTmpFile,\n externalizeNonSteps: true,\n format: 'esm',\n inputFiles,\n });\n\n await this.createWebhookBundle({\n outfile: webhookTmpFile,\n bundle: false,\n });\n\n // All builds succeeded atomically move files into place\n await rename(workflowsTmpFile, join(this.#outDir, 'workflows.mjs'));\n await rename(stepsTmpFile, join(this.#outDir, 'steps.mjs'));\n await rename(webhookTmpFile, join(this.#outDir, 'webhook.mjs'));\n\n // Merge manifests from both bundles\n const manifest = {\n steps: { ...stepsManifest.steps, ...workflowsManifest.steps },\n workflows: {\n ...stepsManifest.workflows,\n ...workflowsManifest.workflows,\n },\n classes: { ...stepsManifest.classes, ...workflowsManifest.classes },\n };\n\n // Generate manifest\n const workflowBundlePath = join(this.#outDir, 'workflows.mjs');\n await this.createManifest({\n workflowBundlePath,\n manifestDir: this.#outDir,\n manifest,\n });\n } finally {\n // Clean up temporary files on success or failure\n await unlink(workflowsTmpFile).catch(() => {});\n await unlink(stepsTmpFile).catch(() => {});\n await unlink(webhookTmpFile).catch(() => {});\n }\n }\n}\n"]}
1
+ {"version":3,"file":"builders.js","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAE7B;;;;GAIG;AACH,SAAS,uBAAuB,CAAC,KAAY;IAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,CACzD,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CACtD,CAAC;IACF,OAAO,SAAS,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACnE,CAAC;AAED,MAAM,OAAO,aAAc,SAAQ,2BAA2B;IAC5D,YAAY,KAAY;QACtB,KAAK,CAAC;YACJ,GAAG,uBAAuB,CAAC;gBACzB,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO;gBACjC,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,2DAA2D;gBACxE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO;gBACxC,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS;gBAC5C,gBAAgB,EAAE,uBAAuB,CAAC,KAAK,CAAC;aACjD,CAAC;YACF,WAAW,EAAE,yBAAyB;SACvC,CAAC,CAAC;IACL,CAAC;IACQ,KAAK,CAA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AI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QAC/D,MAAM,IAAI,CAAC,cAAc,CAAC;YACxB,kBAAkB;YAClB,WAAW,EAAE,IAAI,CAAC,OAAO;YACzB,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport {\n BaseBuilder,\n createBaseBuilderConfig,\n VercelBuildOutputAPIBuilder,\n} from '@workflow/builders';\nimport type { Nitro } from 'nitro/types';\nimport { join } from 'pathe';\n\n/**\n * Forward string entries from Nitro's `externals.external` config to the\n * workflow builder's esbuild `external` option. RegExp and function entries\n * are skipped since esbuild's `external` only supports literal strings.\n */\nfunction getNitroStringExternals(nitro: Nitro): string[] | undefined {\n const externals = nitro.options.externals?.external?.filter(\n (entry): entry is string => typeof entry === 'string'\n );\n return externals && externals.length > 0 ? externals : undefined;\n}\n\nexport class VercelBuilder extends VercelBuildOutputAPIBuilder {\n constructor(nitro: Nitro) {\n super({\n ...createBaseBuilderConfig({\n workingDir: nitro.options.rootDir,\n dirs: ['.'], // Different apps that use nitro have different directories\n runtime: nitro.options.workflow?.runtime,\n sourcemap: nitro.options.workflow?.sourcemap,\n externalPackages: getNitroStringExternals(nitro),\n }),\n buildTarget: 'vercel-build-output-api',\n });\n }\n override async build(): Promise<void> {\n const configPath = join(\n this.config.workingDir,\n '.vercel/output/config.json'\n );\n const originalConfig = JSON.parse(await readFile(configPath, 'utf-8'));\n await super.build();\n const newConfig = JSON.parse(await readFile(configPath, 'utf-8'));\n originalConfig.routes.unshift(...newConfig.routes);\n await writeFile(configPath, JSON.stringify(originalConfig, null, 2));\n }\n}\n\nexport class LocalBuilder extends BaseBuilder {\n #outDir: string;\n constructor(nitro: Nitro) {\n const outDir = join(nitro.options.buildDir, 'workflow');\n super({\n ...createBaseBuilderConfig({\n workingDir: nitro.options.rootDir,\n watch: nitro.options.dev,\n dirs: ['.'], // Different apps that use nitro have different directories\n sourcemap: nitro.options.workflow?.sourcemap,\n externalPackages: getNitroStringExternals(nitro),\n }),\n buildTarget: 'next', // Placeholder, not actually used\n });\n this.#outDir = outDir;\n }\n\n // Serialize concurrent build() calls so overlapping dev rebuilds don't\n // stomp on each other's temp files or partially overwrite output.\n #buildQueue: Promise<void> = Promise.resolve();\n\n override build(): Promise<void> {\n const next = this.#buildQueue.then(\n () => this.#buildOnce(),\n () => this.#buildOnce()\n );\n // Swallow rejections on the queue itself so a failed build doesn't\n // permanently reject all subsequent builds; each caller still sees\n // its own rejection via the returned promise.\n this.#buildQueue = next.catch(() => {});\n return next;\n }\n\n async #buildOnce(): Promise<void> {\n const inputFiles = await this.getInputFiles();\n await mkdir(this.#outDir, { recursive: true });\n\n // V2: The combined bundle's flow route references the steps file by\n // name in its import statement, so we build directly to final names.\n // (The V1 atomic tmp-file pattern doesn't work here because renaming\n // the steps file would leave the flow route's import stale.)\n const { manifest } = await this.createCombinedBundle({\n inputFiles,\n stepsOutfile: join(this.#outDir, 'steps.mjs'),\n flowOutfile: join(this.#outDir, 'workflows.mjs'),\n format: 'esm',\n // bundleFinalOutput: false Nitro externalizes the workflow build dir\n // during dev, and its own rollup pipeline handles bundling for prod.\n // Using true causes \"Dynamic require of X is not supported\" errors\n // because esbuild wraps CJS require() calls in ESM output.\n bundleFinalOutput: false,\n externalizeNonSteps: true,\n // In dev, Nitro dynamically imports the generated workflow files from\n // disk, so there is no later Rollup pass to resolve externalized local\n // TypeScript imports. In prod, Nitro/Rollup handles those imports.\n bundleTransitiveLocalStepDependencies: this.config.watch,\n });\n\n await this.createWebhookBundle({\n outfile: join(this.#outDir, 'webhook.mjs'),\n bundle: false,\n });\n\n // Generate manifest\n const workflowBundlePath = join(this.#outDir, 'workflows.mjs');\n await this.createManifest({\n workflowBundlePath,\n manifestDir: this.#outDir,\n manifest,\n });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAA6B,MAAM,aAAa,CAAC;AAGpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,YAAY,EAAE,aAAa,EAAE,CAAC;;;6BAIT,KAAK;;AAF1B,wBAwMwB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAA6B,MAAM,aAAa,CAAC;AAGpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,YAAY,EAAE,aAAa,EAAE,CAAC;;;6BAIT,KAAK;;AAF1B,wBAqMwB"}
package/dist/index.js CHANGED
@@ -144,7 +144,9 @@ export default {
144
144
  });
145
145
  }
146
146
  addVirtualHandler(nitro, '/.well-known/workflow/v1/webhook/:token', 'workflow/webhook.mjs');
147
- addVirtualHandler(nitro, '/.well-known/workflow/v1/step', 'workflow/steps.mjs');
147
+ // V2: single combined handler for both workflow and step execution.
148
+ // The step registrations are imported as side effects by the combined
149
+ // handler — no separate step route needed.
148
150
  addVirtualHandler(nitro, '/.well-known/workflow/v1/flow', 'workflow/workflows.mjs');
149
151
  // Expose manifest as a public HTTP route when WORKFLOW_PUBLIC_MANIFEST=1
150
152
  if (process.env.WORKFLOW_PUBLIC_MANIFEST === '1') {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAK5D,eAAe;IACb,IA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,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport { workflowTransformPlugin } from '@workflow/rollup';\nimport type { Nitro, NitroModule, RollupConfig } from 'nitro/types';\nimport { join } from 'pathe';\nimport { LocalBuilder, VercelBuilder } from './builders.js';\nimport type { ModuleOptions } from './types';\n\nexport type { ModuleOptions };\n\nexport default {\n name: 'workflow/nitro',\n async setup(nitro: Nitro) {\n const isVercelDeploy =\n !nitro.options.dev && nitro.options.preset === 'vercel';\n\n // Pre-built workflow bundles directory - must be excluded from re-transformation\n const workflowBuildDir = join(nitro.options.buildDir, 'workflow');\n\n // Add transform plugin at the BEGINNING to run before other transforms\n // (especially before class property transforms that rename classes like _ClassName)\n nitro.hooks.hook('rollup:before', (_nitro: Nitro, config: RollupConfig) => {\n (config.plugins as Array<unknown>).unshift(\n workflowTransformPlugin({\n // Exclude pre-built workflow bundles from re-transformation\n // These are already processed and re-processing causes issues like\n // undefined class references when Nitro's bundler renames variables\n exclude: [workflowBuildDir],\n })\n );\n });\n\n // NOTE: Temporary workaround for debug unenv mock\n if (!nitro.options.workflow?._vite) {\n nitro.options.alias['debug'] ??= 'debug';\n }\n\n if (nitro.options.dev) {\n const workflowBuildGlob = `${join(nitro.options.buildDir, 'workflow')}/**`;\n nitro.options.watchOptions ||= {};\n const existingIgnored = nitro.options.watchOptions.ignored;\n if (!existingIgnored) {\n nitro.options.watchOptions.ignored = [workflowBuildGlob];\n } else if (Array.isArray(existingIgnored)) {\n nitro.options.watchOptions.ignored = [\n ...existingIgnored,\n workflowBuildGlob,\n ];\n } else {\n nitro.options.watchOptions.ignored = [\n existingIgnored,\n workflowBuildGlob,\n ];\n }\n }\n\n // In dev mode, force workflow SDK packages to be bundled by Nitro's\n // Rollup rather than externalized. This ensures the SWC transform\n // plugin processes files containing workflow patterns (like\n // @workflow/core/dist/runtime/run.js) and adds the classId\n // registration IIFEs needed for serialization. Without this, serde\n // classes from npm packages (like `Run`) would be externalized, the\n // SWC transform would never fire on them, and serialization would\n // fail with \"must have a static classId property\".\n //\n // We use a Rollup resolveId hook (added BEFORE the externalization\n // plugin) that intercepts workflow package imports and marks them\n // as non-external. This is more targeted than `noExternals = true`\n // which would bundle ALL dependencies and cause TDZ errors from\n // circular imports in packages like vue-bundle-renderer/h3.\n if (nitro.options.dev) {\n nitro.hooks.hook(\n 'rollup:before',\n (_nitro: Nitro, config: RollupConfig) => {\n (config.plugins as Array<unknown>).unshift({\n name: 'workflow:force-inline',\n async resolveId(\n this: { resolve: Function },\n source: string,\n importer: string | undefined,\n options: { skipSelf?: boolean }\n ) {\n if (!importer) return null;\n // Let other plugins resolve first to get the file path\n const resolved = await this.resolve(source, importer, {\n ...options,\n skipSelf: true,\n });\n if (!resolved) return null;\n if (!resolved.external) return null;\n // Force workflow packages and their internal imports\n // to be bundled (not external). We match both the\n // package specifier (e.g., `@workflow/core/runtime`)\n // and resolved file paths within workflow packages.\n const isWorkflowPkg =\n /^@?workflow(\\/|$)/.test(source) ||\n /[\\\\/]packages[\\\\/](workflow|core|serde|errors|utils|builders|rollup|ai|world|world-local|world-vercel|world-postgres|world-testing|cli|next|nitro|nuxt|vite|vitest|web|web-shared|astro|sveltekit|nest)[\\\\/]/.test(\n resolved.id\n );\n if (isWorkflowPkg) {\n // Strip file:// protocol if present — Rollup needs\n // a plain filesystem path to load the module.\n // `fileURLToPath` correctly handles Windows paths\n // (e.g., file:///C:/... -> C:\\...) and percent-decoding.\n let resolvedId = resolved.id;\n if (resolvedId.startsWith('file://')) {\n resolvedId = fileURLToPath(resolvedId);\n }\n return { id: resolvedId, external: false };\n }\n return null;\n },\n });\n }\n );\n }\n\n // Add tsConfig plugin\n if (nitro.options.workflow?.typescriptPlugin) {\n nitro.options.typescript.tsConfig ||= {};\n nitro.options.typescript.tsConfig.compilerOptions ||= {};\n nitro.options.typescript.tsConfig.compilerOptions.plugins ||= [];\n nitro.options.typescript.tsConfig.compilerOptions.plugins.push({\n name: 'workflow',\n });\n }\n\n // Generate functions for vercel build\n if (isVercelDeploy) {\n nitro.hooks.hook('compiled', async () => {\n await new VercelBuilder(nitro).build();\n });\n }\n\n // Generate local bundles for dev and local prod\n if (!isVercelDeploy) {\n const builder = new LocalBuilder(nitro);\n let isInitialBuild = true;\n\n nitro.hooks.hook('build:before', async () => {\n await builder.build();\n\n // For prod: write the manifest handler file with inlined content\n // now that the builder has generated the manifest. Rollup will\n // bundle this file into the compiled output.\n if (\n !nitro.options.dev &&\n process.env.WORKFLOW_PUBLIC_MANIFEST === '1'\n ) {\n writeManifestHandler(nitro);\n }\n });\n\n // Allows for HMR - but skip the first dev:reload since build:before already ran\n if (nitro.options.dev) {\n nitro.hooks.hook('dev:reload', async () => {\n if (isInitialBuild) {\n isInitialBuild = false;\n return;\n }\n try {\n await builder.build();\n } catch (error) {\n // During dev, files may be added/removed while the builder\n // is rebuilding (e.g., during test cleanup). Log the error\n // but don't crash — the next file change will trigger\n // another rebuild with the correct file list.\n console.warn('Warning: Workflow rebuild failed:', error);\n }\n });\n }\n\n addVirtualHandler(\n nitro,\n '/.well-known/workflow/v1/webhook/:token',\n 'workflow/webhook.mjs'\n );\n\n addVirtualHandler(\n nitro,\n '/.well-known/workflow/v1/step',\n 'workflow/steps.mjs'\n );\n\n addVirtualHandler(\n nitro,\n '/.well-known/workflow/v1/flow',\n 'workflow/workflows.mjs'\n );\n\n // Expose manifest as a public HTTP route when WORKFLOW_PUBLIC_MANIFEST=1\n if (process.env.WORKFLOW_PUBLIC_MANIFEST === '1') {\n // Write a placeholder manifest-data.mjs so rollup can resolve the\n // import. It will be overwritten with the real manifest in build:before.\n // Write a placeholder handler file so rollup can resolve the path\n // during prod compilation. It will be overwritten with the real\n // manifest content by writeManifestHandler() in build:before.\n if (!nitro.options.dev) {\n const dir = join(nitro.options.buildDir, 'workflow');\n mkdirSync(dir, { recursive: true });\n const handlerPath = join(dir, 'manifest-handler.mjs');\n writeFileSync(\n handlerPath,\n 'export default async () => new Response(\"Manifest not found\", { status: 404 });\\n'\n );\n }\n addManifestHandler(nitro);\n }\n }\n },\n} satisfies NitroModule;\n\nfunction addVirtualHandler(nitro: Nitro, route: string, buildPath: string) {\n nitro.options.handlers.push({\n route,\n handler: `#${buildPath}`,\n });\n const handlerImportPath = JSON.stringify(\n join(nitro.options.buildDir, buildPath)\n );\n\n if (nitro.options.dev) {\n // Dev mode: load generated workflow bundles from disk at request time.\n // This keeps `.nitro/workflow/*.mjs` out of Nitro's own bundle graph,\n // which avoids rebuild loops and stale dependency graphs during HMR.\n // Cache-bust by file mtime so each successful rebuild loads fresh code.\n if (!nitro.routing) {\n nitro.options.virtual[`#${buildPath}`] = /* js */ `\n import { fromWebHandler } from \"h3\";\n import { statSync } from \"node:fs\";\n import { pathToFileURL } from \"node:url\";\n\n const handlerPath = ${handlerImportPath};\n let currentVersion = \"\";\n let currentImportPath = \"\";\n\n async function loadPOST() {\n const version = String(statSync(handlerPath).mtimeMs);\n if (version !== currentVersion) {\n currentVersion = version;\n currentImportPath = pathToFileURL(handlerPath).href + \"?t=\" + version;\n }\n return (await import(currentImportPath)).POST;\n }\n\n export default fromWebHandler(async (request, context) => {\n const POST = await loadPOST();\n return POST(request, context);\n });\n `;\n } else {\n nitro.options.virtual[`#${buildPath}`] = /* js */ `\n import { statSync } from \"node:fs\";\n import { pathToFileURL } from \"node:url\";\n\n const handlerPath = ${handlerImportPath};\n let currentVersion = \"\";\n let currentImportPath = \"\";\n\n async function loadPOST() {\n const version = String(statSync(handlerPath).mtimeMs);\n if (version !== currentVersion) {\n currentVersion = version;\n currentImportPath = pathToFileURL(handlerPath).href + \"?t=\" + version;\n }\n return (await import(currentImportPath)).POST;\n }\n\n export default async ({ req }) => {\n try {\n const POST = await loadPOST();\n return await POST(req);\n } catch (error) {\n console.error('Handler error:', error);\n return new Response('Internal Server Error', { status: 500 });\n }\n };\n `;\n }\n return;\n }\n\n // Keep a bare import alongside `POST`: in Nuxt + Nitro production builds\n // using `@workflow/nuxt`, importing only `POST` could drop the generated\n // step bundle's top-level registrations, so the handler loaded but steps\n // were missing at runtime.\n\n if (!nitro.routing) {\n // Nitro v2 (legacy)\n nitro.options.virtual[`#${buildPath}`] = /* js */ `\n import ${handlerImportPath};\n import { fromWebHandler } from \"h3\";\n import { POST } from ${handlerImportPath};\n export default fromWebHandler(POST);\n `;\n } else {\n // Nitro v3+ (native web handlers)\n nitro.options.virtual[`#${buildPath}`] = /* js */ `\n import ${handlerImportPath};\n import { POST } from ${handlerImportPath};\n export default async ({ req }) => {\n try {\n return await POST(req);\n } catch (error) {\n console.error('Handler error:', error);\n return new Response('Internal Server Error', { status: 500 });\n }\n };\n `;\n }\n}\n\nconst MANIFEST_VIRTUAL_ID = '#workflow/manifest-handler';\n\nfunction addManifestHandler(nitro: Nitro) {\n const route = '/.well-known/workflow/v1/manifest.json';\n const manifestPath = join(nitro.options.buildDir, 'workflow/manifest.json');\n const handlerPath = join(\n nitro.options.buildDir,\n 'workflow/manifest-handler.mjs'\n );\n\n if (nitro.options.dev) {\n // Dev mode: use a virtual handler that reads the manifest from disk at\n // request time. The absolute path is valid because we're on the build machine.\n nitro.options.handlers.push({ route, handler: MANIFEST_VIRTUAL_ID });\n nitro.options.virtual[MANIFEST_VIRTUAL_ID] = !nitro.routing\n ? /* js */ `\n import { fromWebHandler } from \"h3\";\n import { readFileSync } from \"node:fs\";\n function GET() {\n try {\n const manifest = readFileSync(${JSON.stringify(manifestPath)}, \"utf-8\");\n return new Response(manifest, {\n headers: { \"content-type\": \"application/json\" },\n });\n } catch {\n return new Response(\"Manifest not found\", { status: 404 });\n }\n }\n export default fromWebHandler(GET);\n `\n : /* js */ `\n import { readFileSync } from \"node:fs\";\n export default async () => {\n try {\n const manifest = readFileSync(${JSON.stringify(manifestPath)}, \"utf-8\");\n return new Response(manifest, {\n headers: { \"content-type\": \"application/json\" },\n });\n } catch {\n return new Response(\"Manifest not found\", { status: 404 });\n }\n };\n `;\n } else {\n // Prod mode: register a physical handler file that will be written by\n // writeManifestHandler() after the builder generates the manifest.\n // This file is bundled by rollup into the compiled output.\n nitro.options.handlers.push({ route, handler: handlerPath });\n }\n}\n\n/**\n * Writes a physical manifest handler file with the manifest content inlined.\n * Must be called after the builder generates the manifest (during build:before)\n * and before Nitro compiles the bundle with rollup.\n */\nfunction writeManifestHandler(nitro: Nitro) {\n const manifestPath = join(nitro.options.buildDir, 'workflow/manifest.json');\n const handlerPath = join(\n nitro.options.buildDir,\n 'workflow/manifest-handler.mjs'\n );\n const dir = join(nitro.options.buildDir, 'workflow');\n mkdirSync(dir, { recursive: true });\n\n try {\n const manifestContent = readFileSync(manifestPath, 'utf-8');\n JSON.parse(manifestContent); // validate\n\n const handlerCode = !nitro.routing\n ? `import { fromWebHandler } from \"h3\";\nconst manifest = ${JSON.stringify(manifestContent)};\nexport default fromWebHandler(() => new Response(manifest, {\n headers: { \"content-type\": \"application/json\" },\n}));\n`\n : `const manifest = ${JSON.stringify(manifestContent)};\nexport default async () => new Response(manifest, {\n headers: { \"content-type\": \"application/json\" },\n});\n`;\n writeFileSync(handlerPath, handlerCode);\n } catch {\n // Write a 404 fallback handler\n const fallback = !nitro.routing\n ? `import { fromWebHandler } from \"h3\";\nexport default fromWebHandler(() => new Response(\"Manifest not found\", { status: 404 }));\n`\n : `export default async () => new Response(\"Manifest not found\", { status: 404 });\n`;\n writeFileSync(handlerPath, fallback);\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAE,YAA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YACK,CAAC,CAAC;CACP,CAAC;QACE,aAAa,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACvC,CAAC;AACH,CAAC","sourcesContent":["import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport { workflowTransformPlugin } from '@workflow/rollup';\nimport type { Nitro, NitroModule, RollupConfig } from 'nitro/types';\nimport { join } from 'pathe';\nimport { LocalBuilder, VercelBuilder } from './builders.js';\nimport type { ModuleOptions } from './types';\n\nexport type { ModuleOptions };\n\nexport default {\n name: 'workflow/nitro',\n async setup(nitro: Nitro) {\n const isVercelDeploy =\n !nitro.options.dev && nitro.options.preset === 'vercel';\n\n // Pre-built workflow bundles directory - must be excluded from re-transformation\n const workflowBuildDir = join(nitro.options.buildDir, 'workflow');\n\n // Add transform plugin at the BEGINNING to run before other transforms\n // (especially before class property transforms that rename classes like _ClassName)\n nitro.hooks.hook('rollup:before', (_nitro: Nitro, config: RollupConfig) => {\n (config.plugins as Array<unknown>).unshift(\n workflowTransformPlugin({\n // Exclude pre-built workflow bundles from re-transformation\n // These are already processed and re-processing causes issues like\n // undefined class references when Nitro's bundler renames variables\n exclude: [workflowBuildDir],\n })\n );\n });\n\n // NOTE: Temporary workaround for debug unenv mock\n if (!nitro.options.workflow?._vite) {\n nitro.options.alias['debug'] ??= 'debug';\n }\n\n if (nitro.options.dev) {\n const workflowBuildGlob = `${join(nitro.options.buildDir, 'workflow')}/**`;\n nitro.options.watchOptions ||= {};\n const existingIgnored = nitro.options.watchOptions.ignored;\n if (!existingIgnored) {\n nitro.options.watchOptions.ignored = [workflowBuildGlob];\n } else if (Array.isArray(existingIgnored)) {\n nitro.options.watchOptions.ignored = [\n ...existingIgnored,\n workflowBuildGlob,\n ];\n } else {\n nitro.options.watchOptions.ignored = [\n existingIgnored,\n workflowBuildGlob,\n ];\n }\n }\n\n // In dev mode, force workflow SDK packages to be bundled by Nitro's\n // Rollup rather than externalized. This ensures the SWC transform\n // plugin processes files containing workflow patterns (like\n // @workflow/core/dist/runtime/run.js) and adds the classId\n // registration IIFEs needed for serialization. Without this, serde\n // classes from npm packages (like `Run`) would be externalized, the\n // SWC transform would never fire on them, and serialization would\n // fail with \"must have a static classId property\".\n //\n // We use a Rollup resolveId hook (added BEFORE the externalization\n // plugin) that intercepts workflow package imports and marks them\n // as non-external. This is more targeted than `noExternals = true`\n // which would bundle ALL dependencies and cause TDZ errors from\n // circular imports in packages like vue-bundle-renderer/h3.\n if (nitro.options.dev) {\n nitro.hooks.hook(\n 'rollup:before',\n (_nitro: Nitro, config: RollupConfig) => {\n (config.plugins as Array<unknown>).unshift({\n name: 'workflow:force-inline',\n async resolveId(\n this: { resolve: Function },\n source: string,\n importer: string | undefined,\n options: { skipSelf?: boolean }\n ) {\n if (!importer) return null;\n // Let other plugins resolve first to get the file path\n const resolved = await this.resolve(source, importer, {\n ...options,\n skipSelf: true,\n });\n if (!resolved) return null;\n if (!resolved.external) return null;\n // Force workflow packages and their internal imports\n // to be bundled (not external). We match both the\n // package specifier (e.g., `@workflow/core/runtime`)\n // and resolved file paths within workflow packages.\n const isWorkflowPkg =\n /^@?workflow(\\/|$)/.test(source) ||\n /[\\\\/]packages[\\\\/](workflow|core|serde|errors|utils|builders|rollup|ai|world|world-local|world-vercel|world-postgres|world-testing|cli|next|nitro|nuxt|vite|vitest|web|web-shared|astro|sveltekit|nest)[\\\\/]/.test(\n resolved.id\n );\n if (isWorkflowPkg) {\n // Strip file:// protocol if present — Rollup needs\n // a plain filesystem path to load the module.\n // `fileURLToPath` correctly handles Windows paths\n // (e.g., file:///C:/... -> C:\\...) and percent-decoding.\n let resolvedId = resolved.id;\n if (resolvedId.startsWith('file://')) {\n resolvedId = fileURLToPath(resolvedId);\n }\n return { id: resolvedId, external: false };\n }\n return null;\n },\n });\n }\n );\n }\n\n // Add tsConfig plugin\n if (nitro.options.workflow?.typescriptPlugin) {\n nitro.options.typescript.tsConfig ||= {};\n nitro.options.typescript.tsConfig.compilerOptions ||= {};\n nitro.options.typescript.tsConfig.compilerOptions.plugins ||= [];\n nitro.options.typescript.tsConfig.compilerOptions.plugins.push({\n name: 'workflow',\n });\n }\n\n // Generate functions for vercel build\n if (isVercelDeploy) {\n nitro.hooks.hook('compiled', async () => {\n await new VercelBuilder(nitro).build();\n });\n }\n\n // Generate local bundles for dev and local prod\n if (!isVercelDeploy) {\n const builder = new LocalBuilder(nitro);\n let isInitialBuild = true;\n\n nitro.hooks.hook('build:before', async () => {\n await builder.build();\n\n // For prod: write the manifest handler file with inlined content\n // now that the builder has generated the manifest. Rollup will\n // bundle this file into the compiled output.\n if (\n !nitro.options.dev &&\n process.env.WORKFLOW_PUBLIC_MANIFEST === '1'\n ) {\n writeManifestHandler(nitro);\n }\n });\n\n // Allows for HMR - but skip the first dev:reload since build:before already ran\n if (nitro.options.dev) {\n nitro.hooks.hook('dev:reload', async () => {\n if (isInitialBuild) {\n isInitialBuild = false;\n return;\n }\n try {\n await builder.build();\n } catch (error) {\n // During dev, files may be added/removed while the builder\n // is rebuilding (e.g., during test cleanup). Log the error\n // but don't crash — the next file change will trigger\n // another rebuild with the correct file list.\n console.warn('Warning: Workflow rebuild failed:', error);\n }\n });\n }\n\n addVirtualHandler(\n nitro,\n '/.well-known/workflow/v1/webhook/:token',\n 'workflow/webhook.mjs'\n );\n\n // V2: single combined handler for both workflow and step execution.\n // The step registrations are imported as side effects by the combined\n // handler — no separate step route needed.\n addVirtualHandler(\n nitro,\n '/.well-known/workflow/v1/flow',\n 'workflow/workflows.mjs'\n );\n\n // Expose manifest as a public HTTP route when WORKFLOW_PUBLIC_MANIFEST=1\n if (process.env.WORKFLOW_PUBLIC_MANIFEST === '1') {\n // Write a placeholder manifest-data.mjs so rollup can resolve the\n // import. It will be overwritten with the real manifest in build:before.\n // Write a placeholder handler file so rollup can resolve the path\n // during prod compilation. It will be overwritten with the real\n // manifest content by writeManifestHandler() in build:before.\n if (!nitro.options.dev) {\n const dir = join(nitro.options.buildDir, 'workflow');\n mkdirSync(dir, { recursive: true });\n const handlerPath = join(dir, 'manifest-handler.mjs');\n writeFileSync(\n handlerPath,\n 'export default async () => new Response(\"Manifest not found\", { status: 404 });\\n'\n );\n }\n addManifestHandler(nitro);\n }\n }\n },\n} satisfies NitroModule;\n\nfunction addVirtualHandler(nitro: Nitro, route: string, buildPath: string) {\n nitro.options.handlers.push({\n route,\n handler: `#${buildPath}`,\n });\n const handlerImportPath = JSON.stringify(\n join(nitro.options.buildDir, buildPath)\n );\n\n if (nitro.options.dev) {\n // Dev mode: load generated workflow bundles from disk at request time.\n // This keeps `.nitro/workflow/*.mjs` out of Nitro's own bundle graph,\n // which avoids rebuild loops and stale dependency graphs during HMR.\n // Cache-bust by file mtime so each successful rebuild loads fresh code.\n if (!nitro.routing) {\n nitro.options.virtual[`#${buildPath}`] = /* js */ `\n import { fromWebHandler } from \"h3\";\n import { statSync } from \"node:fs\";\n import { pathToFileURL } from \"node:url\";\n\n const handlerPath = ${handlerImportPath};\n let currentVersion = \"\";\n let currentImportPath = \"\";\n\n async function loadPOST() {\n const version = String(statSync(handlerPath).mtimeMs);\n if (version !== currentVersion) {\n currentVersion = version;\n currentImportPath = pathToFileURL(handlerPath).href + \"?t=\" + version;\n }\n return (await import(currentImportPath)).POST;\n }\n\n export default fromWebHandler(async (request, context) => {\n const POST = await loadPOST();\n return POST(request, context);\n });\n `;\n } else {\n nitro.options.virtual[`#${buildPath}`] = /* js */ `\n import { statSync } from \"node:fs\";\n import { pathToFileURL } from \"node:url\";\n\n const handlerPath = ${handlerImportPath};\n let currentVersion = \"\";\n let currentImportPath = \"\";\n\n async function loadPOST() {\n const version = String(statSync(handlerPath).mtimeMs);\n if (version !== currentVersion) {\n currentVersion = version;\n currentImportPath = pathToFileURL(handlerPath).href + \"?t=\" + version;\n }\n return (await import(currentImportPath)).POST;\n }\n\n export default async ({ req }) => {\n try {\n const POST = await loadPOST();\n return await POST(req);\n } catch (error) {\n console.error('Handler error:', error);\n return new Response('Internal Server Error', { status: 500 });\n }\n };\n `;\n }\n return;\n }\n\n // Keep a bare import alongside `POST`: in Nuxt + Nitro production builds\n // using `@workflow/nuxt`, importing only `POST` could drop the generated\n // step bundle's top-level registrations, so the handler loaded but steps\n // were missing at runtime.\n\n if (!nitro.routing) {\n // Nitro v2 (legacy)\n nitro.options.virtual[`#${buildPath}`] = /* js */ `\n import ${handlerImportPath};\n import { fromWebHandler } from \"h3\";\n import { POST } from ${handlerImportPath};\n export default fromWebHandler(POST);\n `;\n } else {\n // Nitro v3+ (native web handlers)\n nitro.options.virtual[`#${buildPath}`] = /* js */ `\n import ${handlerImportPath};\n import { POST } from ${handlerImportPath};\n export default async ({ req }) => {\n try {\n return await POST(req);\n } catch (error) {\n console.error('Handler error:', error);\n return new Response('Internal Server Error', { status: 500 });\n }\n };\n `;\n }\n}\n\nconst MANIFEST_VIRTUAL_ID = '#workflow/manifest-handler';\n\nfunction addManifestHandler(nitro: Nitro) {\n const route = '/.well-known/workflow/v1/manifest.json';\n const manifestPath = join(nitro.options.buildDir, 'workflow/manifest.json');\n const handlerPath = join(\n nitro.options.buildDir,\n 'workflow/manifest-handler.mjs'\n );\n\n if (nitro.options.dev) {\n // Dev mode: use a virtual handler that reads the manifest from disk at\n // request time. The absolute path is valid because we're on the build machine.\n nitro.options.handlers.push({ route, handler: MANIFEST_VIRTUAL_ID });\n nitro.options.virtual[MANIFEST_VIRTUAL_ID] = !nitro.routing\n ? /* js */ `\n import { fromWebHandler } from \"h3\";\n import { readFileSync } from \"node:fs\";\n function GET() {\n try {\n const manifest = readFileSync(${JSON.stringify(manifestPath)}, \"utf-8\");\n return new Response(manifest, {\n headers: { \"content-type\": \"application/json\" },\n });\n } catch {\n return new Response(\"Manifest not found\", { status: 404 });\n }\n }\n export default fromWebHandler(GET);\n `\n : /* js */ `\n import { readFileSync } from \"node:fs\";\n export default async () => {\n try {\n const manifest = readFileSync(${JSON.stringify(manifestPath)}, \"utf-8\");\n return new Response(manifest, {\n headers: { \"content-type\": \"application/json\" },\n });\n } catch {\n return new Response(\"Manifest not found\", { status: 404 });\n }\n };\n `;\n } else {\n // Prod mode: register a physical handler file that will be written by\n // writeManifestHandler() after the builder generates the manifest.\n // This file is bundled by rollup into the compiled output.\n nitro.options.handlers.push({ route, handler: handlerPath });\n }\n}\n\n/**\n * Writes a physical manifest handler file with the manifest content inlined.\n * Must be called after the builder generates the manifest (during build:before)\n * and before Nitro compiles the bundle with rollup.\n */\nfunction writeManifestHandler(nitro: Nitro) {\n const manifestPath = join(nitro.options.buildDir, 'workflow/manifest.json');\n const handlerPath = join(\n nitro.options.buildDir,\n 'workflow/manifest-handler.mjs'\n );\n const dir = join(nitro.options.buildDir, 'workflow');\n mkdirSync(dir, { recursive: true });\n\n try {\n const manifestContent = readFileSync(manifestPath, 'utf-8');\n JSON.parse(manifestContent); // validate\n\n const handlerCode = !nitro.routing\n ? `import { fromWebHandler } from \"h3\";\nconst manifest = ${JSON.stringify(manifestContent)};\nexport default fromWebHandler(() => new Response(manifest, {\n headers: { \"content-type\": \"application/json\" },\n}));\n`\n : `const manifest = ${JSON.stringify(manifestContent)};\nexport default async () => new Response(manifest, {\n headers: { \"content-type\": \"application/json\" },\n});\n`;\n writeFileSync(handlerPath, handlerCode);\n } catch {\n // Write a 404 fallback handler\n const fallback = !nitro.routing\n ? `import { fromWebHandler } from \"h3\";\nexport default fromWebHandler(() => new Response(\"Manifest not found\", { status: 404 }));\n`\n : `export default async () => new Response(\"Manifest not found\", { status: 404 });\n`;\n writeFileSync(handlerPath, fallback);\n }\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -18,6 +18,19 @@ export interface ModuleOptions {
18
18
  * @example "nodejs24.x"
19
19
  */
20
20
  runtime?: string;
21
+ /**
22
+ * Controls how source maps are emitted for workflow bundles. Accepts the
23
+ * same values as esbuild's `sourcemap` option: `true`/`'inline'` (default
24
+ * for step/workflow bundles), `'linked'`, `'external'`, `'both'`, or
25
+ * `false` to omit source maps.
26
+ *
27
+ * Set to `false` for smaller function bundles — useful for staying under
28
+ * the Vercel 250MB function size limit — at the cost of stack traces that
29
+ * point at generated code instead of your source files.
30
+ *
31
+ * Can also be set via the `WORKFLOW_SOURCEMAP` environment variable.
32
+ */
33
+ sourcemap?: boolean | 'inline' | 'linked' | 'external' | 'both';
21
34
  }
22
35
  declare module 'nitro/types' {
23
36
  interface NitroOptions {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,gBAAgB;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,YAAY;QACpB,QAAQ,CAAC,EAAE,aAAa,CAAC;KAC1B;CACF;AAGD,OAAO,QAAQ,WAAW,CAAC;IACzB,UAAU,YAAY;QACpB,QAAQ,CAAC,EAAE,aAAa,CAAC;KAC1B;CACF"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,gBAAgB;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;CACjE;AAED,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,YAAY;QACpB,QAAQ,CAAC,EAAE,aAAa,CAAC;KAC1B;CACF;AAGD,OAAO,QAAQ,WAAW,CAAC;IACzB,UAAU,YAAY;QACpB,QAAQ,CAAC,EAAE,aAAa,CAAC;KAC1B;CACF"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface ModuleOptions {\n /** @internal */\n _vite?: boolean;\n\n /**\n * Directories to scan for workflows and steps.\n *\n * By default, `workflows/` directory will be scanned from root and all layer source dirs.\n */\n dirs?: string[];\n\n /**\n * Enable workflow TypeScript plugin in generated tsconfig.json\n * @default false\n */\n typescriptPlugin?: boolean;\n\n /**\n * Node.js runtime version for Vercel Functions.\n * @example \"nodejs22.x\"\n * @example \"nodejs24.x\"\n */\n runtime?: string;\n}\n\ndeclare module 'nitro/types' {\n interface NitroOptions {\n workflow?: ModuleOptions;\n }\n}\n\n// @ts-expect-error (legacy)\ndeclare module 'nitropack' {\n interface NitroOptions {\n workflow?: ModuleOptions;\n }\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface ModuleOptions {\n /** @internal */\n _vite?: boolean;\n\n /**\n * Directories to scan for workflows and steps.\n *\n * By default, `workflows/` directory will be scanned from root and all layer source dirs.\n */\n dirs?: string[];\n\n /**\n * Enable workflow TypeScript plugin in generated tsconfig.json\n * @default false\n */\n typescriptPlugin?: boolean;\n\n /**\n * Node.js runtime version for Vercel Functions.\n * @example \"nodejs22.x\"\n * @example \"nodejs24.x\"\n */\n runtime?: string;\n\n /**\n * Controls how source maps are emitted for workflow bundles. Accepts the\n * same values as esbuild's `sourcemap` option: `true`/`'inline'` (default\n * for step/workflow bundles), `'linked'`, `'external'`, `'both'`, or\n * `false` to omit source maps.\n *\n * Set to `false` for smaller function bundles — useful for staying under\n * the Vercel 250MB function size limit — at the cost of stack traces that\n * point at generated code instead of your source files.\n *\n * Can also be set via the `WORKFLOW_SOURCEMAP` environment variable.\n */\n sourcemap?: boolean | 'inline' | 'linked' | 'external' | 'both';\n}\n\ndeclare module 'nitro/types' {\n interface NitroOptions {\n workflow?: ModuleOptions;\n }\n}\n\n// @ts-expect-error (legacy)\ndeclare module 'nitropack' {\n interface NitroOptions {\n workflow?: ModuleOptions;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workflow/nitro",
3
- "version": "5.0.0-beta.4",
3
+ "version": "5.0.0-beta.5",
4
4
  "description": "Nitro integration for Workflow SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,11 +24,11 @@
24
24
  "@swc/core": "1.15.3",
25
25
  "exsolve": "1.0.8",
26
26
  "pathe": "2.0.3",
27
- "@workflow/builders": "5.0.0-beta.4",
28
- "@workflow/core": "5.0.0-beta.4",
29
- "@workflow/rollup": "5.0.0-beta.4",
30
- "@workflow/swc-plugin": "5.0.0-beta.3",
31
- "@workflow/vite": "5.0.0-beta.4"
27
+ "@workflow/builders": "5.0.0-beta.5",
28
+ "@workflow/core": "5.0.0-beta.5",
29
+ "@workflow/rollup": "5.0.0-beta.5",
30
+ "@workflow/swc-plugin": "5.0.0-beta.4",
31
+ "@workflow/vite": "5.0.0-beta.5"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "22.19.0",