@workflow/sveltekit 4.0.4 → 4.0.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.map +1 -1
- package/dist/builder.js +16 -7
- package/dist/builder.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/vc-config.d.ts +3 -0
- package/dist/vc-config.d.ts.map +1 -0
- package/dist/vc-config.js +43 -0
- package/dist/vc-config.js.map +1 -0
- package/package.json +5 -5
package/dist/builder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,WAAW,
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,WAAW,EAGX,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;YA6DvB,eAAe;YA4Cf,mBAAmB;YA4CnB,iBAAiB;YAqDjB,mBAAmB;CA8BlC"}
|
package/dist/builder.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { constants } from 'node:fs';
|
|
2
2
|
import { access, copyFile, mkdir, readFile, stat, writeFile, } from 'node:fs/promises';
|
|
3
3
|
import { join, resolve } from 'node:path';
|
|
4
|
-
import { BaseBuilder, NORMALIZE_REQUEST_CODE, } from '@workflow/builders';
|
|
4
|
+
import { BaseBuilder, NORMALIZE_REQUEST_CODE, replaceGeneratedRouteExport, } from '@workflow/builders';
|
|
5
5
|
const SVELTEKIT_VIRTUAL_MODULES = [
|
|
6
6
|
'$env/*', // All $env subpaths
|
|
7
7
|
'$lib', // Exact $lib import
|
|
@@ -62,6 +62,9 @@ export class SvelteKitBuilder extends BaseBuilder {
|
|
|
62
62
|
if (this.shouldExposePublicManifest && manifestJson) {
|
|
63
63
|
const staticManifestDir = join(this.config.workingDir, 'static/.well-known/workflow/v1');
|
|
64
64
|
await mkdir(staticManifestDir, { recursive: true });
|
|
65
|
+
if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {
|
|
66
|
+
await writeFile(join(staticManifestDir, '.gitignore'), '*');
|
|
67
|
+
}
|
|
65
68
|
await copyFile(join(workflowGeneratedDir, 'manifest.json'), join(staticManifestDir, 'manifest.json'));
|
|
66
69
|
}
|
|
67
70
|
}
|
|
@@ -80,11 +83,14 @@ export class SvelteKitBuilder extends BaseBuilder {
|
|
|
80
83
|
const stepsRouteFile = join(stepsRouteDir, '+server.js');
|
|
81
84
|
let stepsRouteContent = await readFile(stepsRouteFile, 'utf-8');
|
|
82
85
|
// Replace the default export with SvelteKit-compatible handler
|
|
83
|
-
stepsRouteContent = stepsRouteContent
|
|
84
|
-
|
|
86
|
+
stepsRouteContent = replaceGeneratedRouteExport(stepsRouteContent, /export\s*\{\s*stepEntrypoint\w*\s+as\s+HEAD\s*,\s*stepEntrypoint\w*\s+as\s+POST\s*\}\s*;?\s*$/m, `${NORMALIZE_REQUEST_CODE}
|
|
87
|
+
const handleStepRequest = async ({request}) => {
|
|
85
88
|
const normalRequest = await normalizeRequest(request);
|
|
86
89
|
return stepEntrypoint(normalRequest);
|
|
87
|
-
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const HEAD = handleStepRequest;
|
|
93
|
+
export const POST = handleStepRequest;`, 'Failed to wrap generated SvelteKit step route');
|
|
88
94
|
await writeFile(stepsRouteFile, stepsRouteContent);
|
|
89
95
|
return manifest;
|
|
90
96
|
}
|
|
@@ -103,11 +109,14 @@ export const POST = async ({request}) => {
|
|
|
103
109
|
const workflowsRouteFile = join(workflowsRouteDir, '+server.js');
|
|
104
110
|
let workflowsRouteContent = await readFile(workflowsRouteFile, 'utf-8');
|
|
105
111
|
// Replace the default export with SvelteKit-compatible handler
|
|
106
|
-
workflowsRouteContent = workflowsRouteContent
|
|
107
|
-
|
|
112
|
+
workflowsRouteContent = replaceGeneratedRouteExport(workflowsRouteContent, /const handler = workflowEntrypoint\(workflowCode\);\s*export const HEAD = handler;\s*export const POST = handler;?\s*$/m, `${NORMALIZE_REQUEST_CODE}
|
|
113
|
+
const handleWorkflowRequest = async ({request}) => {
|
|
108
114
|
const normalRequest = await normalizeRequest(request);
|
|
109
115
|
return workflowEntrypoint(workflowCode)(normalRequest);
|
|
110
|
-
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const HEAD = handleWorkflowRequest;
|
|
119
|
+
export const POST = handleWorkflowRequest;`, 'Failed to wrap generated SvelteKit workflow route');
|
|
111
120
|
await writeFile(workflowsRouteFile, workflowsRouteContent);
|
|
112
121
|
return manifest;
|
|
113
122
|
}
|
package/dist/builder.js.map
CHANGED
|
@@ -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,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,E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AC,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,IAAI,EACJ,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,2BAA2B,GAE5B,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,UAAU,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAEvD,KAAK,CAAC;YACJ,GAAG,MAAM;YACT,IAAI,EAAE,CAAC,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,CAAC;YAC5D,WAAW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AAM,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 replaceGeneratedRouteExport,\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 if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {\n await writeFile(join(staticManifestDir, '.gitignore'), '*');\n }\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 = replaceGeneratedRouteExport(\n stepsRouteContent,\n /export\\s*\\{\\s*stepEntrypoint\\w*\\s+as\\s+HEAD\\s*,\\s*stepEntrypoint\\w*\\s+as\\s+POST\\s*\\}\\s*;?\\s*$/m,\n `${NORMALIZE_REQUEST_CODE}\nconst handleStepRequest = async ({request}) => {\n const normalRequest = await normalizeRequest(request);\n return stepEntrypoint(normalRequest);\n};\n\nexport const HEAD = handleStepRequest;\nexport const POST = handleStepRequest;`,\n 'Failed to wrap generated SvelteKit step route'\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 = replaceGeneratedRouteExport(\n workflowsRouteContent,\n /const handler = workflowEntrypoint\\(workflowCode\\);\\s*export const HEAD = handler;\\s*export const POST = handler;?\\s*$/m,\n `${NORMALIZE_REQUEST_CODE}\nconst handleWorkflowRequest = async ({request}) => {\n const normalRequest = await normalizeRequest(request);\n return workflowEntrypoint(workflowCode)(normalRequest);\n};\n\nexport const HEAD = handleWorkflowRequest;\nexport const POST = handleWorkflowRequest;`,\n 'Failed to wrap generated SvelteKit workflow route'\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"]}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsFA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
3
|
import { SvelteKitBuilder } from './builder.js';
|
|
4
|
+
import { stripWorkflowQueueTriggers } from './vc-config.js';
|
|
4
5
|
const builder = new SvelteKitBuilder();
|
|
5
6
|
// This needs to be in the top-level as we need to create these
|
|
6
7
|
// entries before svelte plugin is started or the entries are
|
|
@@ -43,13 +44,18 @@ process.on('beforeExit', () => {
|
|
|
43
44
|
},
|
|
44
45
|
},
|
|
45
46
|
]) {
|
|
47
|
+
const funcDir = path.dirname(file);
|
|
48
|
+
if (!fs.existsSync(funcDir)) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const sourceFuncDir = path.join(funcDir.replace(/\.func$/, ''), '__data.json.func');
|
|
46
52
|
// Un-symlink these as they can't be shared due to different
|
|
47
53
|
// experimental triggers config
|
|
48
|
-
const toCopy = fs.readdirSync(
|
|
49
|
-
fs.removeSync(
|
|
50
|
-
fs.mkdirSync(
|
|
54
|
+
const toCopy = fs.readdirSync(funcDir);
|
|
55
|
+
fs.removeSync(funcDir);
|
|
56
|
+
fs.mkdirSync(funcDir, { recursive: true });
|
|
51
57
|
for (const item of toCopy) {
|
|
52
|
-
fs.copySync(path.join(
|
|
58
|
+
fs.copySync(path.join(sourceFuncDir, item), path.join(funcDir, item));
|
|
53
59
|
}
|
|
54
60
|
// Update .vc-config.json with the new experimental triggers config
|
|
55
61
|
const existingConfig = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
@@ -57,6 +63,9 @@ process.on('beforeExit', () => {
|
|
|
57
63
|
...existingConfig,
|
|
58
64
|
...config,
|
|
59
65
|
}));
|
|
66
|
+
// The source function may be a shared catchall. It must not keep stale
|
|
67
|
+
// workflow queue triggers after the dedicated function is copied out.
|
|
68
|
+
stripWorkflowQueueTriggers(path.join(sourceFuncDir, '.vc-config.json'));
|
|
60
69
|
}
|
|
61
70
|
});
|
|
62
71
|
export { workflowPlugin } from './plugin.js';
|
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;
|
|
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;AAChD,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAE5D,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,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;QACD;YACE,IAAI,EAAE,4EAA4E;YAClF,MAAM,EAAE;gBACN,WAAW,EAAE,KAAK;gBAClB,oBAAoB,EAAE;oBACpB;wBACE,IAAI,EAAE,cAAc;wBACpB,KAAK,EAAE,cAAc;wBACrB,QAAQ,EAAE,SAAS;wBACnB,iBAAiB,EAAE,CAAC;wBACpB,mB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path';\nimport fs from 'fs-extra';\n\nimport { SvelteKitBuilder } from './builder.js';\nimport { stripWorkflowQueueTriggers } from './vc-config.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 const funcDir = path.dirname(file);\n if (!fs.existsSync(funcDir)) {\n continue;\n }\n\n const sourceFuncDir = path.join(\n funcDir.replace(/\\.func$/, ''),\n '__data.json.func'\n );\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(path.join(sourceFuncDir, item), path.join(funcDir, item));\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 // The source function may be a shared catchall. It must not keep stale\n // workflow queue triggers after the dedicated function is copied out.\n stripWorkflowQueueTriggers(path.join(sourceFuncDir, '.vc-config.json'));\n }\n});\n\nexport { workflowPlugin } from './plugin.js';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vc-config.d.ts","sourceRoot":"","sources":["../src/vc-config.ts"],"names":[],"mappings":"AAiBA,wBAAgB,oCAAoC,CAClD,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,cAAc,EAAE,OAAO,GAAG,OAAO,CAqBlC;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,QAYtD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { STEP_QUEUE_TRIGGER, WORKFLOW_QUEUE_TRIGGER } from '@workflow/builders';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
const WORKFLOW_QUEUE_TOPICS = new Set([
|
|
4
|
+
STEP_QUEUE_TRIGGER.topic,
|
|
5
|
+
WORKFLOW_QUEUE_TRIGGER.topic,
|
|
6
|
+
]);
|
|
7
|
+
function isWorkflowQueueTrigger(trigger) {
|
|
8
|
+
if (typeof trigger !== 'object' || trigger === null) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const topic = trigger.topic;
|
|
12
|
+
return typeof topic === 'string' && WORKFLOW_QUEUE_TOPICS.has(topic);
|
|
13
|
+
}
|
|
14
|
+
export function stripWorkflowQueueTriggersFromConfig(existingConfig) {
|
|
15
|
+
const experimentalTriggers = existingConfig.experimentalTriggers;
|
|
16
|
+
if (!Array.isArray(experimentalTriggers)) {
|
|
17
|
+
return existingConfig;
|
|
18
|
+
}
|
|
19
|
+
const filteredTriggers = experimentalTriggers.filter((trigger) => !isWorkflowQueueTrigger(trigger));
|
|
20
|
+
if (filteredTriggers.length === experimentalTriggers.length) {
|
|
21
|
+
return existingConfig;
|
|
22
|
+
}
|
|
23
|
+
const nextConfig = { ...existingConfig };
|
|
24
|
+
if (filteredTriggers.length > 0) {
|
|
25
|
+
nextConfig.experimentalTriggers = filteredTriggers;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
delete nextConfig.experimentalTriggers;
|
|
29
|
+
}
|
|
30
|
+
return nextConfig;
|
|
31
|
+
}
|
|
32
|
+
export function stripWorkflowQueueTriggers(file) {
|
|
33
|
+
if (!fs.existsSync(file)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const existingConfig = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
37
|
+
const nextConfig = stripWorkflowQueueTriggersFromConfig(existingConfig);
|
|
38
|
+
if (nextConfig === existingConfig) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
fs.writeFileSync(file, JSON.stringify(nextConfig));
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=vc-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vc-config.js","sourceRoot":"","sources":["../src/vc-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,MAAM,UAAU,CAAC;AAE1B,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,kBAAkB,CAAC,KAAK;IACxB,sBAAsB,CAAC,KAAK;CAC7B,CAAC,CAAC;AAEH,SAAS,sBAAsB,CAAC,OAAgB;IAC9C,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACpD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,KAAK,GAAI,OAA+B,CAAC,KAAK,CAAC;IACrD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,oCAAoC,CAElD,cAAuB;IACvB,MAAM,oBAAoB,GAAG,cAAc,CAAC,oBAAoB,CAAC;IACjE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,CAAC;QACzC,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,MAAM,gBAAgB,GAAG,oBAAoB,CAAC,MAAM,CAClD,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAC9C,CAAC;IACF,IAAI,gBAAgB,CAAC,MAAM,KAAK,oBAAoB,CAAC,MAAM,EAAE,CAAC;QAC5D,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,MAAM,UAAU,GAA4B,EAAE,GAAG,cAAc,EAAE,CAAC;IAClE,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,UAAU,CAAC,oBAAoB,GAAG,gBAAgB,CAAC;IACrD,CAAC;SAAM,CAAC;QACN,OAAO,UAAU,CAAC,oBAAoB,CAAC;IACzC,CAAC;IAED,OAAO,UAAqB,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,IAAY;IACrD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO;IACT,CAAC;IAED,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACjE,MAAM,UAAU,GAAG,oCAAoC,CAAC,cAAc,CAAC,CAAC;IACxE,IAAI,UAAU,KAAK,cAAc,EAAE,CAAC;QAClC,OAAO;IACT,CAAC;IAED,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { STEP_QUEUE_TRIGGER, WORKFLOW_QUEUE_TRIGGER } from '@workflow/builders';\nimport fs from 'fs-extra';\n\nconst WORKFLOW_QUEUE_TOPICS = new Set([\n STEP_QUEUE_TRIGGER.topic,\n WORKFLOW_QUEUE_TRIGGER.topic,\n]);\n\nfunction isWorkflowQueueTrigger(trigger: unknown) {\n if (typeof trigger !== 'object' || trigger === null) {\n return false;\n }\n\n const topic = (trigger as { topic?: unknown }).topic;\n return typeof topic === 'string' && WORKFLOW_QUEUE_TOPICS.has(topic);\n}\n\nexport function stripWorkflowQueueTriggersFromConfig<\n TConfig extends Record<string, unknown>,\n>(existingConfig: TConfig): TConfig {\n const experimentalTriggers = existingConfig.experimentalTriggers;\n if (!Array.isArray(experimentalTriggers)) {\n return existingConfig;\n }\n\n const filteredTriggers = experimentalTriggers.filter(\n (trigger) => !isWorkflowQueueTrigger(trigger)\n );\n if (filteredTriggers.length === experimentalTriggers.length) {\n return existingConfig;\n }\n\n const nextConfig: Record<string, unknown> = { ...existingConfig };\n if (filteredTriggers.length > 0) {\n nextConfig.experimentalTriggers = filteredTriggers;\n } else {\n delete nextConfig.experimentalTriggers;\n }\n\n return nextConfig as TConfig;\n}\n\nexport function stripWorkflowQueueTriggers(file: string) {\n if (!fs.existsSync(file)) {\n return;\n }\n\n const existingConfig = JSON.parse(fs.readFileSync(file, 'utf8'));\n const nextConfig = stripWorkflowQueueTriggersFromConfig(existingConfig);\n if (nextConfig === existingConfig) {\n return;\n }\n\n fs.writeFileSync(file, JSON.stringify(nextConfig));\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workflow/sveltekit",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.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/builders": "4.0.
|
|
28
|
-
"@workflow/rollup": "4.0.
|
|
29
|
-
"@workflow/swc-plugin": "4.1.
|
|
30
|
-
"@workflow/vite": "4.0.
|
|
27
|
+
"@workflow/builders": "4.0.6",
|
|
28
|
+
"@workflow/rollup": "4.0.5",
|
|
29
|
+
"@workflow/swc-plugin": "4.1.1",
|
|
30
|
+
"@workflow/vite": "4.0.5"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/fs-extra": "11.0.4",
|