@workflow/sveltekit 5.0.0-beta.3 → 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.
package/dist/builder.d.ts CHANGED
@@ -2,8 +2,6 @@ import { BaseBuilder, type SvelteKitConfig } from '@workflow/builders';
2
2
  export declare class SvelteKitBuilder extends BaseBuilder {
3
3
  constructor(config?: Partial<SvelteKitConfig>);
4
4
  build(): Promise<void>;
5
- private buildStepsRoute;
6
- private buildWorkflowsRoute;
7
5
  private buildWebhookRoute;
8
6
  private findRoutesDirectory;
9
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,WAAW,EAEX,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAC;AAS5B,qBAAa,gBAAiB,SAAQ,WAAW;gBACnC,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC;IAe9B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YA0DvB,eAAe;YAuCf,mBAAmB;YAuCnB,iBAAiB;YAqDjB,mBAAmB;CA8BlC"}
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,WAAW,EAEX,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAC;AAS5B,qBAAa,gBAAiB,SAAQ,WAAW;gBACnC,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC;IAgB9B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YA6EvB,iBAAiB;YAqDjB,mBAAmB;CA8BlC"}
package/dist/builder.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { constants } from 'node:fs';
2
- import { access, copyFile, mkdir, readFile, stat, writeFile, } from 'node:fs/promises';
2
+ import { access, copyFile, mkdir, readFile, rm, stat, writeFile, } from 'node:fs/promises';
3
3
  import { join, resolve } from 'node:path';
4
4
  import { BaseBuilder, NORMALIZE_REQUEST_CODE, } from '@workflow/builders';
5
5
  const SVELTEKIT_VIRTUAL_MODULES = [
@@ -20,6 +20,7 @@ export class SvelteKitBuilder extends BaseBuilder {
20
20
  webhookBundlePath: '', // unused in base
21
21
  workingDir,
22
22
  externalPackages: [...SVELTEKIT_VIRTUAL_MODULES],
23
+ sourcemap: config?.sourcemap,
23
24
  });
24
25
  }
25
26
  async build() {
@@ -32,24 +33,37 @@ export class SvelteKitBuilder extends BaseBuilder {
32
33
  if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {
33
34
  await writeFile(join(workflowGeneratedDir, '.gitignore'), '*');
34
35
  }
36
+ // Clean up stale V1 step route directory (may persist via Vercel build cache)
37
+ await rm(join(workflowGeneratedDir, 'step'), {
38
+ recursive: true,
39
+ force: true,
40
+ });
35
41
  // Get workflow and step files to bundle
36
42
  const inputFiles = await this.getInputFiles();
37
43
  const tsconfigPath = await this.findTsConfigPath();
38
- const options = {
44
+ // Create combined bundle for flow route
45
+ const flowRouteDir = join(workflowGeneratedDir, 'flow');
46
+ await mkdir(flowRouteDir, { recursive: true });
47
+ const { manifest } = await this.createCombinedBundle({
39
48
  inputFiles,
40
- workflowGeneratedDir,
49
+ stepsOutfile: join(flowRouteDir, '__step_registrations.js'),
50
+ flowOutfile: join(flowRouteDir, '+server.js'),
51
+ format: 'esm',
52
+ bundleFinalOutput: false,
53
+ externalizeNonSteps: true,
41
54
  tsconfigPath,
42
- };
43
- // Generate the three SvelteKit route handlers
44
- const stepsManifest = await this.buildStepsRoute(options);
45
- const workflowsManifest = await this.buildWorkflowsRoute(options);
55
+ });
56
+ // Post-process the generated file to wrap with SvelteKit request converter
57
+ const workflowsRouteFile = join(flowRouteDir, '+server.js');
58
+ let workflowsRouteContent = await readFile(workflowsRouteFile, 'utf-8');
59
+ // Replace the default export with SvelteKit-compatible handler
60
+ workflowsRouteContent = workflowsRouteContent.replace(/export const POST = workflowEntrypoint\(workflowCode\);?$/m, `${NORMALIZE_REQUEST_CODE}
61
+ export const POST = async ({request}) => {
62
+ const normalRequest = await normalizeRequest(request);
63
+ return workflowEntrypoint(workflowCode)(normalRequest);
64
+ }`);
65
+ await writeFile(workflowsRouteFile, workflowsRouteContent);
46
66
  await this.buildWebhookRoute({ workflowGeneratedDir });
47
- // Merge manifests from both bundles
48
- const manifest = {
49
- steps: { ...stepsManifest.steps, ...workflowsManifest.steps },
50
- workflows: { ...stepsManifest.workflows, ...workflowsManifest.workflows },
51
- classes: { ...stepsManifest.classes, ...workflowsManifest.classes },
52
- };
53
67
  // Generate unified manifest
54
68
  const workflowBundlePath = join(workflowGeneratedDir, 'flow/+server.js');
55
69
  const manifestJson = await this.createManifest({
@@ -65,52 +79,6 @@ export class SvelteKitBuilder extends BaseBuilder {
65
79
  await copyFile(join(workflowGeneratedDir, 'manifest.json'), join(staticManifestDir, 'manifest.json'));
66
80
  }
67
81
  }
68
- async buildStepsRoute({ inputFiles, workflowGeneratedDir, tsconfigPath, }) {
69
- // Create steps route: .well-known/workflow/v1/step/+server.js
70
- const stepsRouteDir = join(workflowGeneratedDir, 'step');
71
- await mkdir(stepsRouteDir, { recursive: true });
72
- const { manifest } = await this.createStepsBundle({
73
- format: 'esm',
74
- inputFiles,
75
- outfile: join(stepsRouteDir, '+server.js'),
76
- externalizeNonSteps: true,
77
- tsconfigPath,
78
- });
79
- // Post-process the generated file to wrap with SvelteKit request converter
80
- const stepsRouteFile = join(stepsRouteDir, '+server.js');
81
- let stepsRouteContent = await readFile(stepsRouteFile, 'utf-8');
82
- // Replace the default export with SvelteKit-compatible handler
83
- stepsRouteContent = stepsRouteContent.replace(/export\s*\{\s*stepEntrypoint\s+as\s+POST\s*\}\s*;?$/m, `${NORMALIZE_REQUEST_CODE}
84
- export const POST = async ({request}) => {
85
- const normalRequest = await normalizeRequest(request);
86
- return stepEntrypoint(normalRequest);
87
- }`);
88
- await writeFile(stepsRouteFile, stepsRouteContent);
89
- return manifest;
90
- }
91
- async buildWorkflowsRoute({ inputFiles, workflowGeneratedDir, tsconfigPath, }) {
92
- // Create workflows route: .well-known/workflow/v1/flow/+server.js
93
- const workflowsRouteDir = join(workflowGeneratedDir, 'flow');
94
- await mkdir(workflowsRouteDir, { recursive: true });
95
- const { manifest } = await this.createWorkflowsBundle({
96
- format: 'esm',
97
- outfile: join(workflowsRouteDir, '+server.js'),
98
- bundleFinalOutput: false,
99
- inputFiles,
100
- tsconfigPath,
101
- });
102
- // Post-process the generated file to wrap with SvelteKit request converter
103
- const workflowsRouteFile = join(workflowsRouteDir, '+server.js');
104
- let workflowsRouteContent = await readFile(workflowsRouteFile, 'utf-8');
105
- // Replace the default export with SvelteKit-compatible handler
106
- workflowsRouteContent = workflowsRouteContent.replace(/export const POST = workflowEntrypoint\(workflowCode\);?$/m, `${NORMALIZE_REQUEST_CODE}
107
- export const POST = async ({request}) => {
108
- const normalRequest = await normalizeRequest(request);
109
- return workflowEntrypoint(workflowCode)(normalRequest);
110
- }`);
111
- await writeFile(workflowsRouteFile, workflowsRouteContent);
112
- return manifest;
113
- }
114
82
  async buildWebhookRoute({ workflowGeneratedDir, }) {
115
83
  // Create webhook route: .well-known/workflow/v1/webhook/[token]/+server.js
116
84
  const webhookRouteFile = join(workflowGeneratedDir, 'webhook/[token]/+server.js');
@@ -1 +1 @@
1
- {"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EACL,MAAM,EACN,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,WAAW,EACX,sBAAsB,GAEvB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,yBAAyB,GAAG;IAChC,QAAQ,EAAE,oBAAoB;IAC9B,MAAM,EAAE,o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M,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAEhE,uDAAuD;QACvD,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;YACxC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC;YAC1C,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,uCAAuC,SAAS,EAAE,CAAC,CAAC;YACtE,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;QAAC,MAAM,CAAC;YACP,yBAAyB;YACzB,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,aAAa,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;gBAC5C,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC;gBAClD,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,EAAE,CAAC;oBACnC,MAAM,IAAI,KAAK,CACb,uCAAuC,aAAa,EAAE,CACvD,CAAC;gBACJ,CAAC;gBACD,OAAO,aAAa,CAAC;YACvB,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,IAAI,KAAK,CACb,+FAA+F,CAChG,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import { constants } from 'node:fs';\nimport {\n access,\n copyFile,\n mkdir,\n readFile,\n stat,\n writeFile,\n} from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\nimport {\n BaseBuilder,\n NORMALIZE_REQUEST_CODE,\n type SvelteKitConfig,\n} from '@workflow/builders';\n\nconst SVELTEKIT_VIRTUAL_MODULES = [\n '$env/*', // All $env subpaths\n '$lib', // Exact $lib import\n '$lib/*', // All $lib subpaths\n '$app/*', // All $app subpaths\n];\n\nexport class SvelteKitBuilder extends BaseBuilder {\n constructor(config?: Partial<SvelteKitConfig>) {\n const workingDir = config?.workingDir || process.cwd();\n\n super({\n ...config,\n dirs: ['workflows', 'src/workflows', 'routes', 'src/routes'],\n buildTarget: 'sveltekit' as const,\n stepsBundlePath: '', // unused in base\n workflowsBundlePath: '', // unused in base\n webhookBundlePath: '', // unused in base\n workingDir,\n externalPackages: [...SVELTEKIT_VIRTUAL_MODULES],\n });\n }\n\n override async build(): Promise<void> {\n // Find SvelteKit routes directory (src/routes or routes)\n const routesDir = await this.findRoutesDirectory();\n const workflowGeneratedDir = join(routesDir, '.well-known/workflow/v1');\n\n // Ensure output directories exist\n await mkdir(workflowGeneratedDir, { recursive: true });\n\n // Add .gitignore to exclude generated files from version control\n if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {\n await writeFile(join(workflowGeneratedDir, '.gitignore'), '*');\n }\n\n // Get workflow and step files to bundle\n const inputFiles = await this.getInputFiles();\n const tsconfigPath = await this.findTsConfigPath();\n\n const options = {\n inputFiles,\n workflowGeneratedDir,\n tsconfigPath,\n };\n\n // Generate the three SvelteKit route handlers\n const stepsManifest = await this.buildStepsRoute(options);\n const workflowsManifest = await this.buildWorkflowsRoute(options);\n await this.buildWebhookRoute({ workflowGeneratedDir });\n\n // Merge manifests from both bundles\n const manifest = {\n steps: { ...stepsManifest.steps, ...workflowsManifest.steps },\n workflows: { ...stepsManifest.workflows, ...workflowsManifest.workflows },\n classes: { ...stepsManifest.classes, ...workflowsManifest.classes },\n };\n\n // Generate unified manifest\n const workflowBundlePath = join(workflowGeneratedDir, 'flow/+server.js');\n const manifestJson = await this.createManifest({\n workflowBundlePath,\n manifestDir: workflowGeneratedDir,\n manifest,\n });\n\n // Expose manifest as a static file when WORKFLOW_PUBLIC_MANIFEST=1.\n // SvelteKit serves files from static/ at the root URL.\n if (this.shouldExposePublicManifest && manifestJson) {\n const staticManifestDir = join(\n this.config.workingDir,\n 'static/.well-known/workflow/v1'\n );\n await mkdir(staticManifestDir, { recursive: true });\n await copyFile(\n join(workflowGeneratedDir, 'manifest.json'),\n join(staticManifestDir, 'manifest.json')\n );\n }\n }\n\n private async buildStepsRoute({\n inputFiles,\n workflowGeneratedDir,\n tsconfigPath,\n }: {\n inputFiles: string[];\n workflowGeneratedDir: string;\n tsconfigPath?: string;\n }) {\n // Create steps route: .well-known/workflow/v1/step/+server.js\n const stepsRouteDir = join(workflowGeneratedDir, 'step');\n await mkdir(stepsRouteDir, { recursive: true });\n\n const { manifest } = await this.createStepsBundle({\n format: 'esm',\n inputFiles,\n outfile: join(stepsRouteDir, '+server.js'),\n externalizeNonSteps: true,\n tsconfigPath,\n });\n\n // Post-process the generated file to wrap with SvelteKit request converter\n const stepsRouteFile = join(stepsRouteDir, '+server.js');\n let stepsRouteContent = await readFile(stepsRouteFile, 'utf-8');\n\n // Replace the default export with SvelteKit-compatible handler\n stepsRouteContent = stepsRouteContent.replace(\n /export\\s*\\{\\s*stepEntrypoint\\s+as\\s+POST\\s*\\}\\s*;?$/m,\n `${NORMALIZE_REQUEST_CODE}\nexport const POST = async ({request}) => {\n const normalRequest = await normalizeRequest(request);\n return stepEntrypoint(normalRequest);\n}`\n );\n\n await writeFile(stepsRouteFile, stepsRouteContent);\n return manifest;\n }\n\n private async buildWorkflowsRoute({\n inputFiles,\n workflowGeneratedDir,\n tsconfigPath,\n }: {\n inputFiles: string[];\n workflowGeneratedDir: string;\n tsconfigPath?: string;\n }) {\n // Create workflows route: .well-known/workflow/v1/flow/+server.js\n const workflowsRouteDir = join(workflowGeneratedDir, 'flow');\n await mkdir(workflowsRouteDir, { recursive: true });\n\n const { manifest } = await this.createWorkflowsBundle({\n format: 'esm',\n outfile: join(workflowsRouteDir, '+server.js'),\n bundleFinalOutput: false,\n inputFiles,\n tsconfigPath,\n });\n\n // Post-process the generated file to wrap with SvelteKit request converter\n const workflowsRouteFile = join(workflowsRouteDir, '+server.js');\n let workflowsRouteContent = await readFile(workflowsRouteFile, 'utf-8');\n\n // Replace the default export with SvelteKit-compatible handler\n workflowsRouteContent = workflowsRouteContent.replace(\n /export const POST = workflowEntrypoint\\(workflowCode\\);?$/m,\n `${NORMALIZE_REQUEST_CODE}\nexport const POST = async ({request}) => {\n const normalRequest = await normalizeRequest(request);\n return workflowEntrypoint(workflowCode)(normalRequest);\n}`\n );\n await writeFile(workflowsRouteFile, workflowsRouteContent);\n\n return manifest;\n }\n\n private async buildWebhookRoute({\n workflowGeneratedDir,\n }: {\n workflowGeneratedDir: string;\n }) {\n // Create webhook route: .well-known/workflow/v1/webhook/[token]/+server.js\n const webhookRouteFile = join(\n workflowGeneratedDir,\n 'webhook/[token]/+server.js'\n );\n\n await this.createWebhookBundle({\n outfile: webhookRouteFile,\n bundle: false, // SvelteKit will handle bundling\n });\n\n // Post-process the generated file to wrap with SvelteKit request converter\n let webhookRouteContent = await readFile(webhookRouteFile, 'utf-8');\n\n // Update handler signature to accept token as parameter\n webhookRouteContent = webhookRouteContent.replace(\n /async function handler\\(request\\) \\{[\\s\\S]*?const token = decodeURIComponent\\(pathParts\\[pathParts\\.length - 1\\]\\);/,\n `async function handler(request, token) {`\n );\n\n // Remove the URL parsing code since we get token from params\n webhookRouteContent = webhookRouteContent.replace(\n /const url = new URL\\(request\\.url\\);[\\s\\S]*?const pathParts = url\\.pathname\\.split\\('\\/'\\);[\\s\\S]*?\\n/,\n ''\n );\n\n // Replace all HTTP method exports with SvelteKit-compatible handlers\n webhookRouteContent = webhookRouteContent.replace(\n /export const GET = handler;\\nexport const POST = handler;\\nexport const PUT = handler;\\nexport const PATCH = handler;\\nexport const DELETE = handler;\\nexport const HEAD = handler;\\nexport const OPTIONS = handler;/,\n `${NORMALIZE_REQUEST_CODE}\nconst createSvelteKitHandler = (method) => async ({ request, params, platform }) => {\n const normalRequest = await normalizeRequest(request);\n const response = await handler(normalRequest, params.token);\n return response;\n};\n\nexport const GET = createSvelteKitHandler('GET');\nexport const POST = createSvelteKitHandler('POST');\nexport const PUT = createSvelteKitHandler('PUT');\nexport const PATCH = createSvelteKitHandler('PATCH');\nexport const DELETE = createSvelteKitHandler('DELETE');\nexport const HEAD = createSvelteKitHandler('HEAD');\nexport const OPTIONS = createSvelteKitHandler('OPTIONS');`\n );\n\n await writeFile(webhookRouteFile, webhookRouteContent);\n }\n\n private async findRoutesDirectory(): Promise<string> {\n const routesDir = resolve(this.config.workingDir, 'src/routes');\n const rootRoutesDir = resolve(this.config.workingDir, 'routes');\n\n // Try src/routes first (standard SvelteKit convention)\n try {\n await access(routesDir, constants.F_OK);\n const routesStats = await stat(routesDir);\n if (!routesStats.isDirectory()) {\n throw new Error(`Path exists but is not a directory: ${routesDir}`);\n }\n return routesDir;\n } catch {\n // Try routes as fallback\n try {\n await access(rootRoutesDir, constants.F_OK);\n const rootRoutesStats = await stat(rootRoutesDir);\n if (!rootRoutesStats.isDirectory()) {\n throw new Error(\n `Path exists but is not a directory: ${rootRoutesDir}`\n );\n }\n return rootRoutesDir;\n } catch {\n throw new Error(\n 'Could not find SvelteKit routes directory. Expected either \"src/routes\" or \"routes\" to exist.'\n );\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EACL,MAAM,EACN,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,EAAE,EACF,IAAI,EACJ,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,WAAW,EACX,sBAAsB,GAEvB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,yBAAyB,GAAG;IAChC,QAAQ,EAAE,oBAAoB;IAC9B,MAAM,EAAE,oBAAoB;IAC5B,QAAQ,EAAE,oBAAoB;IAC9B,QAAQ,EAAE,oBAAoB;CAC/B,CAAC;AAEF,MAAM,OAAO,gBAAiB,SAAQ,WAAW;IAC/C,YAAY,MAAiC;QAC3C,MAAM,UAAU,GAAG,MAAM,EAAE,UAA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AAI,CAAC,CAAC;YACxC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,CAAC;YAC1C,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,uCAAuC,SAAS,EAAE,CAAC,CAAC;YACtE,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;QAAC,MAAM,CAAC;YACP,yBAAyB;YACzB,IAAI,CAAC;gBACH,MAAM,MAAM,CAAC,aAAa,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;gBAC5C,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC;gBAClD,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,EAAE,CAAC;oBACnC,MAAM,IAAI,KAAK,CACb,uCAAuC,aAAa,EAAE,CACvD,CAAC;gBACJ,CAAC;gBACD,OAAO,aAAa,CAAC;YACvB,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,IAAI,KAAK,CACb,+FAA+F,CAChG,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import { constants } from 'node:fs';\nimport {\n access,\n copyFile,\n mkdir,\n readFile,\n rm,\n stat,\n writeFile,\n} from 'node:fs/promises';\nimport { join, resolve } from 'node:path';\nimport {\n BaseBuilder,\n NORMALIZE_REQUEST_CODE,\n type SvelteKitConfig,\n} from '@workflow/builders';\n\nconst SVELTEKIT_VIRTUAL_MODULES = [\n '$env/*', // All $env subpaths\n '$lib', // Exact $lib import\n '$lib/*', // All $lib subpaths\n '$app/*', // All $app subpaths\n];\n\nexport class SvelteKitBuilder extends BaseBuilder {\n constructor(config?: Partial<SvelteKitConfig>) {\n const workingDir = config?.workingDir || process.cwd();\n\n super({\n ...config,\n dirs: ['workflows', 'src/workflows', 'routes', 'src/routes'],\n buildTarget: 'sveltekit' as const,\n stepsBundlePath: '', // unused in base\n workflowsBundlePath: '', // unused in base\n webhookBundlePath: '', // unused in base\n workingDir,\n externalPackages: [...SVELTEKIT_VIRTUAL_MODULES],\n sourcemap: config?.sourcemap,\n });\n }\n\n override async build(): Promise<void> {\n // Find SvelteKit routes directory (src/routes or routes)\n const routesDir = await this.findRoutesDirectory();\n const workflowGeneratedDir = join(routesDir, '.well-known/workflow/v1');\n\n // Ensure output directories exist\n await mkdir(workflowGeneratedDir, { recursive: true });\n\n // Add .gitignore to exclude generated files from version control\n if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {\n await writeFile(join(workflowGeneratedDir, '.gitignore'), '*');\n }\n\n // Clean up stale V1 step route directory (may persist via Vercel build cache)\n await rm(join(workflowGeneratedDir, 'step'), {\n recursive: true,\n force: true,\n });\n\n // Get workflow and step files to bundle\n const inputFiles = await this.getInputFiles();\n const tsconfigPath = await this.findTsConfigPath();\n\n // Create combined bundle for flow route\n const flowRouteDir = join(workflowGeneratedDir, 'flow');\n await mkdir(flowRouteDir, { recursive: true });\n\n const { manifest } = await this.createCombinedBundle({\n inputFiles,\n stepsOutfile: join(flowRouteDir, '__step_registrations.js'),\n flowOutfile: join(flowRouteDir, '+server.js'),\n format: 'esm',\n bundleFinalOutput: false,\n externalizeNonSteps: true,\n tsconfigPath,\n });\n\n // Post-process the generated file to wrap with SvelteKit request converter\n const workflowsRouteFile = join(flowRouteDir, '+server.js');\n let workflowsRouteContent = await readFile(workflowsRouteFile, 'utf-8');\n\n // Replace the default export with SvelteKit-compatible handler\n workflowsRouteContent = workflowsRouteContent.replace(\n /export const POST = workflowEntrypoint\\(workflowCode\\);?$/m,\n `${NORMALIZE_REQUEST_CODE}\nexport const POST = async ({request}) => {\n const normalRequest = await normalizeRequest(request);\n return workflowEntrypoint(workflowCode)(normalRequest);\n}`\n );\n await writeFile(workflowsRouteFile, workflowsRouteContent);\n\n await this.buildWebhookRoute({ workflowGeneratedDir });\n\n // Generate unified manifest\n const workflowBundlePath = join(workflowGeneratedDir, 'flow/+server.js');\n const manifestJson = await this.createManifest({\n workflowBundlePath,\n manifestDir: workflowGeneratedDir,\n manifest,\n });\n\n // Expose manifest as a static file when WORKFLOW_PUBLIC_MANIFEST=1.\n // SvelteKit serves files from static/ at the root URL.\n if (this.shouldExposePublicManifest && manifestJson) {\n const staticManifestDir = join(\n this.config.workingDir,\n 'static/.well-known/workflow/v1'\n );\n await mkdir(staticManifestDir, { recursive: true });\n await copyFile(\n join(workflowGeneratedDir, 'manifest.json'),\n join(staticManifestDir, 'manifest.json')\n );\n }\n }\n\n private async buildWebhookRoute({\n workflowGeneratedDir,\n }: {\n workflowGeneratedDir: string;\n }) {\n // Create webhook route: .well-known/workflow/v1/webhook/[token]/+server.js\n const webhookRouteFile = join(\n workflowGeneratedDir,\n 'webhook/[token]/+server.js'\n );\n\n await this.createWebhookBundle({\n outfile: webhookRouteFile,\n bundle: false, // SvelteKit will handle bundling\n });\n\n // Post-process the generated file to wrap with SvelteKit request converter\n let webhookRouteContent = await readFile(webhookRouteFile, 'utf-8');\n\n // Update handler signature to accept token as parameter\n webhookRouteContent = webhookRouteContent.replace(\n /async function handler\\(request\\) \\{[\\s\\S]*?const token = decodeURIComponent\\(pathParts\\[pathParts\\.length - 1\\]\\);/,\n `async function handler(request, token) {`\n );\n\n // Remove the URL parsing code since we get token from params\n webhookRouteContent = webhookRouteContent.replace(\n /const url = new URL\\(request\\.url\\);[\\s\\S]*?const pathParts = url\\.pathname\\.split\\('\\/'\\);[\\s\\S]*?\\n/,\n ''\n );\n\n // Replace all HTTP method exports with SvelteKit-compatible handlers\n webhookRouteContent = webhookRouteContent.replace(\n /export const GET = handler;\\nexport const POST = handler;\\nexport const PUT = handler;\\nexport const PATCH = handler;\\nexport const DELETE = handler;\\nexport const HEAD = handler;\\nexport const OPTIONS = handler;/,\n `${NORMALIZE_REQUEST_CODE}\nconst createSvelteKitHandler = (method) => async ({ request, params, platform }) => {\n const normalRequest = await normalizeRequest(request);\n const response = await handler(normalRequest, params.token);\n return response;\n};\n\nexport const GET = createSvelteKitHandler('GET');\nexport const POST = createSvelteKitHandler('POST');\nexport const PUT = createSvelteKitHandler('PUT');\nexport const PATCH = createSvelteKitHandler('PATCH');\nexport const DELETE = createSvelteKitHandler('DELETE');\nexport const HEAD = createSvelteKitHandler('HEAD');\nexport const OPTIONS = createSvelteKitHandler('OPTIONS');`\n );\n\n await writeFile(webhookRouteFile, webhookRouteContent);\n }\n\n private async findRoutesDirectory(): Promise<string> {\n const routesDir = resolve(this.config.workingDir, 'src/routes');\n const rootRoutesDir = resolve(this.config.workingDir, 'routes');\n\n // Try src/routes first (standard SvelteKit convention)\n try {\n await access(routesDir, constants.F_OK);\n const routesStats = await stat(routesDir);\n if (!routesStats.isDirectory()) {\n throw new Error(`Path exists but is not a directory: ${routesDir}`);\n }\n return routesDir;\n } catch {\n // Try routes as fallback\n try {\n await access(rootRoutesDir, constants.F_OK);\n const rootRoutesStats = await stat(rootRoutesDir);\n if (!rootRoutesStats.isDirectory()) {\n throw new Error(\n `Path exists but is not a directory: ${rootRoutesDir}`\n );\n }\n return rootRoutesDir;\n } catch {\n throw new Error(\n 'Could not find SvelteKit routes directory. Expected either \"src/routes\" or \"routes\" to exist.'\n );\n }\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA8EA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiEA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -11,6 +11,8 @@ process.on('beforeExit', () => {
11
11
  if (!process.env.VERCEL_DEPLOYMENT_ID) {
12
12
  return;
13
13
  }
14
+ // V2: Only the combined flow handler needs queue triggers.
15
+ // The separate step route was removed.
14
16
  for (const { file, config } of [
15
17
  {
16
18
  file: '.vercel/output/functions/.well-known/workflow/v1/flow.func/.vc-config.json',
@@ -27,29 +29,18 @@ process.on('beforeExit', () => {
27
29
  ],
28
30
  },
29
31
  },
30
- {
31
- file: '.vercel/output/functions/.well-known/workflow/v1/step.func/.vc-config.json',
32
- config: {
33
- maxDuration: 'max',
34
- experimentalTriggers: [
35
- {
36
- type: 'queue/v2beta',
37
- topic: '__wkf_step_*',
38
- consumer: 'default',
39
- retryAfterSeconds: 5,
40
- initialDelaySeconds: 0,
41
- },
42
- ],
43
- },
44
- },
45
32
  ]) {
33
+ const funcDir = path.dirname(file);
34
+ if (!fs.existsSync(funcDir)) {
35
+ continue;
36
+ }
46
37
  // Un-symlink these as they can't be shared due to different
47
38
  // experimental triggers config
48
- const toCopy = fs.readdirSync(path.dirname(file));
49
- fs.removeSync(path.dirname(file));
50
- fs.mkdirSync(path.dirname(file), { recursive: true });
39
+ const toCopy = fs.readdirSync(funcDir);
40
+ fs.removeSync(funcDir);
41
+ fs.mkdirSync(funcDir, { recursive: true });
51
42
  for (const item of toCopy) {
52
- fs.copySync(path.join(path.dirname(file).replace(/\.func$/, ''), '__data.json.func', item), path.join(path.dirname(file), item));
43
+ fs.copySync(path.join(funcDir.replace(/\.func$/, ''), '__data.json.func', item), path.join(funcDir, item));
53
44
  }
54
45
  // Update .vc-config.json with the new experimental triggers config
55
46
  const existingConfig = JSON.parse(fs.readFileSync(file, 'utf8'));
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,UAAU,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,OAAO,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAEvC,+DAA+D;AAC/D,6DAA6D;AAC7D,uDAAuD;AACvD,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;AAEtB,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE;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C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CACpC,CAAC;QACJ,CAAC;QAED,mEAAmE;QACnE,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QACjE,EAAE,CAAC,aAAa,CACd,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC;YACb,GAAG,cAAc;YACjB,GAAG,MAAM;SACV,CAAC,CACH,CAAC;IACJ,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC","sourcesContent":["import path from 'node:path';\nimport fs from 'fs-extra';\n\nimport { SvelteKitBuilder } from './builder.js';\n\nconst builder = new SvelteKitBuilder();\n\n// This needs to be in the top-level as we need to create these\n// entries before svelte plugin is started or the entries are\n// a race to be created before svelte discovers entries\nawait builder.build();\n\nprocess.on('beforeExit', () => {\n // Don't patch functions output if not in Vercel adapter\n if (!process.env.VERCEL_DEPLOYMENT_ID) {\n return;\n }\n for (const { file, config } of [\n {\n file: '.vercel/output/functions/.well-known/workflow/v1/flow.func/.vc-config.json',\n config: {\n maxDuration: 'max',\n experimentalTriggers: [\n {\n type: 'queue/v2beta',\n topic: '__wkf_workflow_*',\n consumer: 'default',\n retryAfterSeconds: 5,\n initialDelaySeconds: 0,\n },\n ],\n },\n },\n {\n file: '.vercel/output/functions/.well-known/workflow/v1/step.func/.vc-config.json',\n config: {\n maxDuration: 'max',\n experimentalTriggers: [\n {\n type: 'queue/v2beta',\n topic: '__wkf_step_*',\n consumer: 'default',\n retryAfterSeconds: 5,\n initialDelaySeconds: 0,\n },\n ],\n },\n },\n ]) {\n // Un-symlink these as they can't be shared due to different\n // experimental triggers config\n const toCopy = fs.readdirSync(path.dirname(file));\n fs.removeSync(path.dirname(file));\n fs.mkdirSync(path.dirname(file), { recursive: true });\n\n for (const item of toCopy) {\n fs.copySync(\n path.join(\n path.dirname(file).replace(/\\.func$/, ''),\n '__data.json.func',\n item\n ),\n path.join(path.dirname(file), item)\n );\n }\n\n // Update .vc-config.json with the new experimental triggers config\n const existingConfig = JSON.parse(fs.readFileSync(file, 'utf8'));\n fs.writeFileSync(\n file,\n JSON.stringify({\n ...existingConfig,\n ...config,\n })\n );\n }\n});\n\nexport { workflowPlugin } from './plugin.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,UAAU,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,OAAO,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAEvC,+DAA+D;AAC/D,6DAA6D;AAC7D,uDAAuD;AACvD,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;AAEtB,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE;IAC5B,wDAAwD;IACxD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC;QACtC,OAAO;IACT,CAAC;IACD,2DAA2D;IAC3D,uCAAuC;IACvC,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI;QAC7B;YACE,IAAI,EAAE,4EAA4E;YAClF,MAAM,EAAE;gBACN,WAAW,EAAE,KAAK;gBAClB,oBAAoB,EAAE;oBACpB;wBACE,IAAI,EAAE,cAAc;wBACpB,KAAK,EAAE,kBAAkB;wBACzB,QAAQ,EAAE,SAAS;wBACnB,iBAAiB,EAAE,CAAC;wBACpB,mBAAmB,EAAE,CAAC;qBACvB;iBACF;aACF;SACF;KACF,EAAE,CAAC;QACF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5B,SAAS;QACX,CAAC;QACD,4DAA4D;QAC5D,+BAA+B;QAC/B,MAAM,MAAM,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QACvC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACvB,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAE3C,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;YAC1B,EAAE,CAAC,QAAQ,CACT,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,EACnE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CACzB,CAAC;QACJ,CAAC;QAED,mEAAmE;QACnE,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QACjE,EAAE,CAAC,aAAa,CACd,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC;YACb,GAAG,cAAc;YACjB,GAAG,MAAM;SACV,CAAC,CACH,CAAC;IACJ,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC","sourcesContent":["import path from 'node:path';\nimport fs from 'fs-extra';\n\nimport { SvelteKitBuilder } from './builder.js';\n\nconst builder = new SvelteKitBuilder();\n\n// This needs to be in the top-level as we need to create these\n// entries before svelte plugin is started or the entries are\n// a race to be created before svelte discovers entries\nawait builder.build();\n\nprocess.on('beforeExit', () => {\n // Don't patch functions output if not in Vercel adapter\n if (!process.env.VERCEL_DEPLOYMENT_ID) {\n return;\n }\n // V2: Only the combined flow handler needs queue triggers.\n // The separate step route was removed.\n for (const { file, config } of [\n {\n file: '.vercel/output/functions/.well-known/workflow/v1/flow.func/.vc-config.json',\n config: {\n maxDuration: 'max',\n experimentalTriggers: [\n {\n type: 'queue/v2beta',\n topic: '__wkf_workflow_*',\n consumer: 'default',\n retryAfterSeconds: 5,\n initialDelaySeconds: 0,\n },\n ],\n },\n },\n ]) {\n const funcDir = path.dirname(file);\n if (!fs.existsSync(funcDir)) {\n continue;\n }\n // Un-symlink these as they can't be shared due to different\n // experimental triggers config\n const toCopy = fs.readdirSync(funcDir);\n fs.removeSync(funcDir);\n fs.mkdirSync(funcDir, { recursive: true });\n\n for (const item of toCopy) {\n fs.copySync(\n path.join(funcDir.replace(/\\.func$/, ''), '__data.json.func', item),\n path.join(funcDir, item)\n );\n }\n\n // Update .vc-config.json with the new experimental triggers config\n const existingConfig = JSON.parse(fs.readFileSync(file, 'utf8'));\n fs.writeFileSync(\n file,\n JSON.stringify({\n ...existingConfig,\n ...config,\n })\n );\n }\n});\n\nexport { workflowPlugin } from './plugin.js';\n"]}
package/dist/plugin.d.ts CHANGED
@@ -1,3 +1,12 @@
1
1
  import type { Plugin } from 'vite';
2
- export declare function workflowPlugin(): Plugin[];
2
+ export interface WorkflowPluginOptions {
3
+ /**
4
+ * Controls how source maps are emitted for workflow bundles. Accepts the
5
+ * same values as esbuild's `sourcemap` option: `true`/`'inline'` (default),
6
+ * `'linked'`, `'external'`, `'both'`, or `false` to omit source maps. Can
7
+ * also be set via the `WORKFLOW_SOURCEMAP` environment variable.
8
+ */
9
+ sourcemap?: boolean | 'inline' | 'linked' | 'external' | 'both';
10
+ }
11
+ export declare function workflowPlugin(options?: WorkflowPluginOptions): Plugin[];
3
12
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,wBAAgB,cAAc,IAAI,MAAM,EAAE,CAczC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAC;CACjE;AAED,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,EAAE,CAc5E"}
package/dist/plugin.js CHANGED
@@ -2,8 +2,8 @@ import { createBuildQueue } from '@workflow/builders';
2
2
  import { workflowTransformPlugin } from '@workflow/rollup';
3
3
  import { workflowHotUpdatePlugin } from '@workflow/vite';
4
4
  import { SvelteKitBuilder } from './builder.js';
5
- export function workflowPlugin() {
6
- const builder = new SvelteKitBuilder();
5
+ export function workflowPlugin(options = {}) {
6
+ const builder = new SvelteKitBuilder({ sourcemap: options.sourcemap });
7
7
  const enqueue = createBuildQueue();
8
8
  return [
9
9
  workflowTransformPlugin(),
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,IAAI,gBAAgB,EAAE,CAAC;IACvC,MAAM,OAAO,GAAG,gBAAgB,EAAE,CAAC;IAEnC,OAAO;QACL,uBAAuB,EAAY;QACnC;YACE,IAAI,EAAE,oBAAoB;SAC3B;QACD,uBAAuB,CAAC;YACtB,OAAO;YACP,OAAO;SACR,CAAC;KACH,CAAC;AACJ,CAAC","sourcesContent":["import { createBuildQueue } from '@workflow/builders';\nimport { workflowTransformPlugin } from '@workflow/rollup';\nimport { workflowHotUpdatePlugin } from '@workflow/vite';\nimport type { Plugin } from 'vite';\nimport { SvelteKitBuilder } from './builder.js';\n\nexport function workflowPlugin(): Plugin[] {\n const builder = new SvelteKitBuilder();\n const enqueue = createBuildQueue();\n\n return [\n workflowTransformPlugin() as Plugin,\n {\n name: 'workflow:sveltekit',\n },\n workflowHotUpdatePlugin({\n builder,\n enqueue,\n }),\n ];\n}\n"]}
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAYhD,MAAM,UAAU,cAAc,CAAC,UAAiC,EAAE;IAChE,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IACvE,MAAM,OAAO,GAAG,gBAAgB,EAAE,CAAC;IAEnC,OAAO;QACL,uBAAuB,EAAY;QACnC;YACE,IAAI,EAAE,oBAAoB;SAC3B;QACD,uBAAuB,CAAC;YACtB,OAAO;YACP,OAAO;SACR,CAAC;KACH,CAAC;AACJ,CAAC","sourcesContent":["import { createBuildQueue } from '@workflow/builders';\nimport { workflowTransformPlugin } from '@workflow/rollup';\nimport { workflowHotUpdatePlugin } from '@workflow/vite';\nimport type { Plugin } from 'vite';\nimport { SvelteKitBuilder } from './builder.js';\n\nexport interface WorkflowPluginOptions {\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 * `'linked'`, `'external'`, `'both'`, or `false` to omit source maps. Can\n * also be set via the `WORKFLOW_SOURCEMAP` environment variable.\n */\n sourcemap?: boolean | 'inline' | 'linked' | 'external' | 'both';\n}\n\nexport function workflowPlugin(options: WorkflowPluginOptions = {}): Plugin[] {\n const builder = new SvelteKitBuilder({ sourcemap: options.sourcemap });\n const enqueue = createBuildQueue();\n\n return [\n workflowTransformPlugin() as Plugin,\n {\n name: 'workflow:sveltekit',\n },\n workflowHotUpdatePlugin({\n builder,\n enqueue,\n }),\n ];\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workflow/sveltekit",
3
- "version": "5.0.0-beta.3",
3
+ "version": "5.0.0-beta.5",
4
4
  "description": "SvelteKit integration for Workflow SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,10 +24,10 @@
24
24
  "exsolve": "^1.0.8",
25
25
  "fs-extra": "^11.3.2",
26
26
  "pathe": "^2.0.3",
27
- "@workflow/rollup": "5.0.0-beta.3",
28
- "@workflow/builders": "5.0.0-beta.3",
29
- "@workflow/swc-plugin": "5.0.0-beta.3",
30
- "@workflow/vite": "5.0.0-beta.3"
27
+ "@workflow/swc-plugin": "5.0.0-beta.4",
28
+ "@workflow/builders": "5.0.0-beta.5",
29
+ "@workflow/vite": "5.0.0-beta.5",
30
+ "@workflow/rollup": "5.0.0-beta.5"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/fs-extra": "11.0.4",