@workflow/sveltekit 4.0.0-beta.2
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/LICENSE.md +201 -0
- package/README.md +3 -0
- package/dist/builder.d.ts +10 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +185 -0
- package/dist/builder.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +3 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +76 -0
- package/dist/plugin.js.map +1 -0
- package/package.json +42 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
<http://www.apache.org/licenses/>
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Vercel Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseBuilder, type SvelteKitConfig } from '@workflow/builders';
|
|
2
|
+
export declare class SvelteKitBuilder extends BaseBuilder {
|
|
3
|
+
constructor(config?: Partial<SvelteKitConfig>);
|
|
4
|
+
build(): Promise<void>;
|
|
5
|
+
private buildStepsRoute;
|
|
6
|
+
private buildWorkflowsRoute;
|
|
7
|
+
private buildWebhookRoute;
|
|
8
|
+
private findRoutesDirectory;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAgBvE,qBAAa,gBAAiB,SAAQ,WAAW;gBACnC,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC;IAY9B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YA8BvB,eAAe;YAyCf,mBAAmB;YAwCnB,iBAAiB;YAoFjB,mBAAmB;CA8BlC"}
|
package/dist/builder.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { access, mkdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { BaseBuilder } from '@workflow/builders';
|
|
5
|
+
// Helper function code for converting SvelteKit requests to standard Request objects
|
|
6
|
+
const SVELTEKIT_REQUEST_CONVERTER = `
|
|
7
|
+
async function convertSvelteKitRequest(request) {
|
|
8
|
+
const options = {
|
|
9
|
+
method: request.method,
|
|
10
|
+
headers: new Headers(request.headers)
|
|
11
|
+
};
|
|
12
|
+
if (!['GET', 'HEAD', 'OPTIONS', 'TRACE', 'CONNECT'].includes(request.method)) {
|
|
13
|
+
options.body = await request.arrayBuffer();
|
|
14
|
+
}
|
|
15
|
+
return new Request(request.url, options);
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
export class SvelteKitBuilder extends BaseBuilder {
|
|
19
|
+
constructor(config) {
|
|
20
|
+
super({
|
|
21
|
+
...config,
|
|
22
|
+
dirs: ['workflows'],
|
|
23
|
+
buildTarget: 'sveltekit',
|
|
24
|
+
stepsBundlePath: '', // unused in base
|
|
25
|
+
workflowsBundlePath: '', // unused in base
|
|
26
|
+
webhookBundlePath: '', // unused in base
|
|
27
|
+
workingDir: config?.workingDir || process.cwd(),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async build() {
|
|
31
|
+
// Find SvelteKit routes directory (src/routes or routes)
|
|
32
|
+
const routesDir = await this.findRoutesDirectory();
|
|
33
|
+
const workflowGeneratedDir = join(routesDir, '.well-known/workflow/v1');
|
|
34
|
+
// Ensure output directories exist
|
|
35
|
+
await mkdir(workflowGeneratedDir, { recursive: true });
|
|
36
|
+
// Add .gitignore to exclude generated files from version control
|
|
37
|
+
if (process.env.VERCEL_DEPLOYMENT_ID === undefined) {
|
|
38
|
+
await writeFile(join(workflowGeneratedDir, '.gitignore'), '*');
|
|
39
|
+
}
|
|
40
|
+
// Get workflow and step files to bundle
|
|
41
|
+
const inputFiles = await this.getInputFiles();
|
|
42
|
+
const tsConfig = await this.getTsConfigOptions();
|
|
43
|
+
const options = {
|
|
44
|
+
inputFiles,
|
|
45
|
+
workflowGeneratedDir,
|
|
46
|
+
tsBaseUrl: tsConfig.baseUrl,
|
|
47
|
+
tsPaths: tsConfig.paths,
|
|
48
|
+
};
|
|
49
|
+
// Generate the three SvelteKit route handlers
|
|
50
|
+
await this.buildStepsRoute(options);
|
|
51
|
+
await this.buildWorkflowsRoute(options);
|
|
52
|
+
await this.buildWebhookRoute({ workflowGeneratedDir });
|
|
53
|
+
}
|
|
54
|
+
async buildStepsRoute({ inputFiles, workflowGeneratedDir, tsPaths, tsBaseUrl, }) {
|
|
55
|
+
// Create steps route: .well-known/workflow/v1/step/+server.js
|
|
56
|
+
const stepsRouteDir = join(workflowGeneratedDir, 'step');
|
|
57
|
+
await mkdir(stepsRouteDir, { recursive: true });
|
|
58
|
+
await this.createStepsBundle({
|
|
59
|
+
format: 'esm',
|
|
60
|
+
inputFiles,
|
|
61
|
+
outfile: join(stepsRouteDir, '+server.js'),
|
|
62
|
+
externalizeNonSteps: true,
|
|
63
|
+
tsBaseUrl,
|
|
64
|
+
tsPaths,
|
|
65
|
+
});
|
|
66
|
+
// Post-process the generated file to wrap with SvelteKit request converter
|
|
67
|
+
const stepsRouteFile = join(stepsRouteDir, '+server.js');
|
|
68
|
+
let stepsRouteContent = await readFile(stepsRouteFile, 'utf-8');
|
|
69
|
+
// Replace the default export with SvelteKit-compatible handler
|
|
70
|
+
stepsRouteContent = stepsRouteContent.replace(/export\s*\{\s*stepEntrypoint\s+as\s+POST\s*\}\s*;?$/m, `${SVELTEKIT_REQUEST_CONVERTER}
|
|
71
|
+
export const POST = async ({request}) => {
|
|
72
|
+
const normalRequest = await convertSvelteKitRequest(request);
|
|
73
|
+
return stepEntrypoint(normalRequest);
|
|
74
|
+
}`);
|
|
75
|
+
await writeFile(stepsRouteFile, stepsRouteContent);
|
|
76
|
+
}
|
|
77
|
+
async buildWorkflowsRoute({ inputFiles, workflowGeneratedDir, tsPaths, tsBaseUrl, }) {
|
|
78
|
+
// Create workflows route: .well-known/workflow/v1/flow/+server.js
|
|
79
|
+
const workflowsRouteDir = join(workflowGeneratedDir, 'flow');
|
|
80
|
+
await mkdir(workflowsRouteDir, { recursive: true });
|
|
81
|
+
await this.createWorkflowsBundle({
|
|
82
|
+
format: 'esm',
|
|
83
|
+
outfile: join(workflowsRouteDir, '+server.js'),
|
|
84
|
+
bundleFinalOutput: false,
|
|
85
|
+
inputFiles,
|
|
86
|
+
tsBaseUrl,
|
|
87
|
+
tsPaths,
|
|
88
|
+
});
|
|
89
|
+
// Post-process the generated file to wrap with SvelteKit request converter
|
|
90
|
+
const workflowsRouteFile = join(workflowsRouteDir, '+server.js');
|
|
91
|
+
let workflowsRouteContent = await readFile(workflowsRouteFile, 'utf-8');
|
|
92
|
+
// Replace the default export with SvelteKit-compatible handler
|
|
93
|
+
workflowsRouteContent = workflowsRouteContent.replace(/export const POST = workflowEntrypoint\(workflowCode\);?$/m, `${SVELTEKIT_REQUEST_CONVERTER}
|
|
94
|
+
export const POST = async ({request}) => {
|
|
95
|
+
const normalRequest = await convertSvelteKitRequest(request);
|
|
96
|
+
return workflowEntrypoint(workflowCode)(normalRequest);
|
|
97
|
+
}`);
|
|
98
|
+
await writeFile(workflowsRouteFile, workflowsRouteContent);
|
|
99
|
+
}
|
|
100
|
+
async buildWebhookRoute({ workflowGeneratedDir, }) {
|
|
101
|
+
// Create webhook route: .well-known/workflow/v1/webhook/[token]/+server.js
|
|
102
|
+
const webhookRouteFile = join(workflowGeneratedDir, 'webhook/[token]/+server.js');
|
|
103
|
+
await this.createWebhookBundle({
|
|
104
|
+
outfile: webhookRouteFile,
|
|
105
|
+
bundle: false, // SvelteKit will handle bundling
|
|
106
|
+
});
|
|
107
|
+
// Post-process the generated file to wrap with SvelteKit request converter
|
|
108
|
+
let webhookRouteContent = await readFile(webhookRouteFile, 'utf-8');
|
|
109
|
+
// For local dev (node), need this since context isn't available to waitUntil()
|
|
110
|
+
// Add SYMBOL_FOR_REQ_CONTEXT at the top after imports
|
|
111
|
+
webhookRouteContent = webhookRouteContent.replace(/(import.*?;)/, `$1\n\nconst SYMBOL_FOR_REQ_CONTEXT = Symbol.for('@vercel/request-context');`);
|
|
112
|
+
// Update handler signature to accept token as parameter
|
|
113
|
+
webhookRouteContent = webhookRouteContent.replace(/async function handler\(request\) \{[\s\S]*?const token = decodeURIComponent\(pathParts\[pathParts\.length - 1\]\);/, `async function handler(request, token) {`);
|
|
114
|
+
// Remove the URL parsing code since we get token from params
|
|
115
|
+
webhookRouteContent = webhookRouteContent.replace(/const url = new URL\(request\.url\);[\s\S]*?const pathParts = url\.pathname\.split\('\/'\);[\s\S]*?\n/, '');
|
|
116
|
+
// Replace all HTTP method exports with SvelteKit-compatible handlers
|
|
117
|
+
webhookRouteContent = webhookRouteContent.replace(/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;/, `${SVELTEKIT_REQUEST_CONVERTER}
|
|
118
|
+
const createSvelteKitHandler = (method) => async ({ request, params, platform }) => {
|
|
119
|
+
// Track background promises for local dev
|
|
120
|
+
const backgroundPromises = [];
|
|
121
|
+
|
|
122
|
+
// Set up context for @vercel/functions waitUntil
|
|
123
|
+
const context = {
|
|
124
|
+
waitUntil: platform?.waitUntil || ((promise) => {
|
|
125
|
+
// Fallback for local dev/tests: collect promises to await them
|
|
126
|
+
backgroundPromises.push(promise.catch(err => console.error('Background task error:', err)));
|
|
127
|
+
})
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Only set context if it doesn't already exist (Vercel sets it and makes it read-only)
|
|
131
|
+
if (!globalThis[SYMBOL_FOR_REQ_CONTEXT]) {
|
|
132
|
+
globalThis[SYMBOL_FOR_REQ_CONTEXT] = {
|
|
133
|
+
get: () => context
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const normalRequest = await convertSvelteKitRequest(request);
|
|
138
|
+
const response = await handler(normalRequest, params.token);
|
|
139
|
+
|
|
140
|
+
// In local dev (no platform.waitUntil), await background tasks before returning
|
|
141
|
+
if (!platform?.waitUntil && backgroundPromises.length > 0) {
|
|
142
|
+
await Promise.all(backgroundPromises);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return response;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const GET = createSvelteKitHandler('GET');
|
|
149
|
+
export const POST = createSvelteKitHandler('POST');
|
|
150
|
+
export const PUT = createSvelteKitHandler('PUT');
|
|
151
|
+
export const PATCH = createSvelteKitHandler('PATCH');
|
|
152
|
+
export const DELETE = createSvelteKitHandler('DELETE');
|
|
153
|
+
export const HEAD = createSvelteKitHandler('HEAD');
|
|
154
|
+
export const OPTIONS = createSvelteKitHandler('OPTIONS');`);
|
|
155
|
+
await writeFile(webhookRouteFile, webhookRouteContent);
|
|
156
|
+
}
|
|
157
|
+
async findRoutesDirectory() {
|
|
158
|
+
const routesDir = resolve(this.config.workingDir, 'src/routes');
|
|
159
|
+
const rootRoutesDir = resolve(this.config.workingDir, 'routes');
|
|
160
|
+
// Try src/routes first (standard SvelteKit convention)
|
|
161
|
+
try {
|
|
162
|
+
await access(routesDir, constants.F_OK);
|
|
163
|
+
const routesStats = await stat(routesDir);
|
|
164
|
+
if (!routesStats.isDirectory()) {
|
|
165
|
+
throw new Error(`Path exists but is not a directory: ${routesDir}`);
|
|
166
|
+
}
|
|
167
|
+
return routesDir;
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
// Try routes as fallback
|
|
171
|
+
try {
|
|
172
|
+
await access(rootRoutesDir, constants.F_OK);
|
|
173
|
+
const rootRoutesStats = await stat(rootRoutesDir);
|
|
174
|
+
if (!rootRoutesStats.isDirectory()) {
|
|
175
|
+
throw new Error(`Path exists but is not a directory: ${rootRoutesDir}`);
|
|
176
|
+
}
|
|
177
|
+
return rootRoutesDir;
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
throw new Error('Could not find SvelteKit routes directory. Expected either "src/routes" or "routes" to exist.');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAwB,MAAM,oBAAoB,CAAC;AAEvE,qFAAqF;AACrF,MAAM,2BAA2B,GAAG;;;;;;;;;;;CAWnC,CAAC;AAEF,MAAM,OAAO,gBAAiB,SAAQ,WAAW;IAC/C,YAAY,MAAiC;QAC3C,KAAK,CAAC;YACJ,GAAG,MAAM;YACT,IAAI,EAAE,CAAC,WAAW,CAAC;YACnB,WAAW,EAAE,WAAoB;YACjC,eAAe,EAAE,EAAE,EAAE,iBAAiB;YACtC,mBAAmB,EAAE,EAAE,EAAE,iBAAiB;YAC1C,iBAAiB,EAAE,EAAE,EAAE,iBAAiB;YACxC,UAAU,EAAE,MAAM,EAAE,UAAU,IAAI,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ACvD,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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA8EA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { SvelteKitBuilder } from './builder.js';
|
|
4
|
+
const builder = new SvelteKitBuilder();
|
|
5
|
+
// This needs to be in the top-level as we need to create these
|
|
6
|
+
// entries before svelte plugin is started or the entries are
|
|
7
|
+
// a race to be created before svelte discovers entries
|
|
8
|
+
await builder.build();
|
|
9
|
+
process.on('beforeExit', () => {
|
|
10
|
+
// Don't patch functions output if not in Vercel adapter
|
|
11
|
+
if (!process.env.VERCEL_DEPLOYMENT_ID) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
for (const { file, config } of [
|
|
15
|
+
{
|
|
16
|
+
file: '.vercel/output/functions/.well-known/workflow/v1/flow.func/.vc-config.json',
|
|
17
|
+
config: {
|
|
18
|
+
experimentalTriggers: [
|
|
19
|
+
{
|
|
20
|
+
type: 'queue/v1beta',
|
|
21
|
+
topic: '__wkf_workflow_*',
|
|
22
|
+
consumer: 'default',
|
|
23
|
+
maxDeliveries: 64,
|
|
24
|
+
retryAfterSeconds: 5,
|
|
25
|
+
initialDelaySeconds: 0,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
file: '.vercel/output/functions/.well-known/workflow/v1/step.func/.vc-config.json',
|
|
32
|
+
config: {
|
|
33
|
+
experimentalTriggers: [
|
|
34
|
+
{
|
|
35
|
+
type: 'queue/v1beta',
|
|
36
|
+
topic: '__wkf_step_*',
|
|
37
|
+
consumer: 'default',
|
|
38
|
+
maxDeliveries: 64,
|
|
39
|
+
retryAfterSeconds: 5,
|
|
40
|
+
initialDelaySeconds: 0,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
]) {
|
|
46
|
+
// Un-symlink these as they can't be shared due to different
|
|
47
|
+
// 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 });
|
|
51
|
+
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));
|
|
53
|
+
}
|
|
54
|
+
// Update .vc-config.json with the new experimental triggers config
|
|
55
|
+
const existingConfig = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
56
|
+
fs.writeFileSync(file, JSON.stringify({
|
|
57
|
+
...existingConfig,
|
|
58
|
+
...config,
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
export { workflowPlugin } from './plugin.js';
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;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,oBAAoB,EAAE;oBACpB;wBACE,IAAI,EAAE,cAAc;wBACpB,KAAK,EAAE,kBAAkB;wBACzB,QAAQ,EAAE,SAAS;wBACnB,aAAa,EAAE,EAAE;wBACjB,iBAAiB,EAAE,CAAC;wBACpB,mBAAmB,EAAE,CAAC;qBACvB;iBACF;aACF;SACF;QACD;YACE,IAAI,EAAE,4EAA4E;YAClF,MAAM,EAAE;gBACN,oBAAoB,EAAE;oBACpB;wBACE,IAAI,EAAE,cAAc;wBACpB,KAAK,EAAE,cAAc;wBACrB,QAAQ,EAAE,SAAS;wBACnB,aAAa,EAAE,EAAE;wBACjB,iBAAiB,E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BAAgB,cAAc,IAAI,MAAM,CAsFvC"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { transform } from '@swc/core';
|
|
2
|
+
import { resolveModulePath } from 'exsolve';
|
|
3
|
+
import { SvelteKitBuilder } from './builder.js';
|
|
4
|
+
export function workflowPlugin() {
|
|
5
|
+
let builder;
|
|
6
|
+
return {
|
|
7
|
+
name: 'workflow:sveltekit',
|
|
8
|
+
// TODO: Move this to @workflow/vite or something since this is vite specific
|
|
9
|
+
// Transform workflow files with SWC
|
|
10
|
+
async transform(code, id) {
|
|
11
|
+
// Only apply the transform if file needs it
|
|
12
|
+
if (!code.match(/(use step|use workflow)/)) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const isTypeScript = id.endsWith('.ts') || id.endsWith('.tsx');
|
|
16
|
+
const isTsx = id.endsWith('.tsx');
|
|
17
|
+
const swcPlugin = resolveModulePath('@workflow/swc-plugin', {
|
|
18
|
+
from: [import.meta.url],
|
|
19
|
+
});
|
|
20
|
+
// Transform with SWC
|
|
21
|
+
const result = await transform(code, {
|
|
22
|
+
filename: id,
|
|
23
|
+
jsc: {
|
|
24
|
+
parser: {
|
|
25
|
+
syntax: isTypeScript ? 'typescript' : 'ecmascript',
|
|
26
|
+
tsx: isTsx,
|
|
27
|
+
},
|
|
28
|
+
target: 'es2022',
|
|
29
|
+
experimental: {
|
|
30
|
+
plugins: [[swcPlugin, { mode: 'client' }]],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
minify: false,
|
|
34
|
+
sourceMaps: true,
|
|
35
|
+
inlineSourcesContent: true,
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
code: result.code,
|
|
39
|
+
map: result.map ? JSON.parse(result.map) : null,
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
configResolved() {
|
|
43
|
+
builder = new SvelteKitBuilder();
|
|
44
|
+
},
|
|
45
|
+
async buildStart() {
|
|
46
|
+
await builder.build();
|
|
47
|
+
},
|
|
48
|
+
// TODO: Move this to @workflow/vite or something since this is vite specific
|
|
49
|
+
async handleHotUpdate(ctx) {
|
|
50
|
+
const { file, server, read } = ctx;
|
|
51
|
+
// Check if this is a TS/JS file that might contain workflow directives
|
|
52
|
+
const jsTsRegex = /\.(ts|tsx|js|jsx|mjs|cjs)$/;
|
|
53
|
+
if (!jsTsRegex.test(file)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// Read the file to check for workflow/step directives
|
|
57
|
+
const content = await read();
|
|
58
|
+
const useWorkflowPattern = /^\s*(['"])use workflow\1;?\s*$/m;
|
|
59
|
+
const useStepPattern = /^\s*(['"])use step\1;?\s*$/m;
|
|
60
|
+
if (!useWorkflowPattern.test(content) && !useStepPattern.test(content)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Rebuild everything - simpler and more reliable than tracking individual files
|
|
64
|
+
console.log('Workflow file changed, regenerating routes...');
|
|
65
|
+
await builder.build();
|
|
66
|
+
// Trigger full reload of workflow routes
|
|
67
|
+
server.ws.send({
|
|
68
|
+
type: 'full-reload',
|
|
69
|
+
path: '*',
|
|
70
|
+
});
|
|
71
|
+
// Let Vite handle the normal HMR for the changed file
|
|
72
|
+
return;
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,UAAU,cAAc;IAC5B,IAAI,OAAyB,CAAC;IAE9B,OAAO;QACL,IAAI,EAAE,oBAAoB;QAE1B,6EAA6E;QAC7E,oCAAo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KAAK,CAAC,UAAU;YACd,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;QAED,6EAA6E;QAC7E,KAAK,CAAC,eAAe,CAAC,GAAe;YACnC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;YAEnC,uEAAuE;YACvE,MAAM,SAAS,GAAG,4BAA4B,CAAC;YAC/C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1B,OAAO;YACT,CAAC;YAED,sDAAsD;YACtD,MAAM,OAAO,GAAG,MAAM,IAAI,EAAE,CAAC;YAC7B,MAAM,kBAAkB,GAAG,iCAAiC,CAAC;YAC7D,MAAM,cAAc,GAAG,6BAA6B,CAAC;YAErD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBACvE,OAAO;YACT,CAAC;YAED,gFAAgF;YAChF,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;YAC7D,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;YAEtB,yCAAyC;YACzC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;gBACb,IAAI,EAAE,aAAa;gBACnB,IAAI,EAAE,GAAG;aACV,CAAC,CAAC;YAEH,sDAAsD;YACtD,OAAO;QACT,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@workflow/sveltekit",
|
|
3
|
+
"version": "4.0.0-beta.2",
|
|
4
|
+
"description": "SvelteKit integration for Workflow DevKit",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/vercel/workflow.git",
|
|
17
|
+
"directory": "packages/sveltekit"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@swc/core": "1.11.24",
|
|
24
|
+
"@sveltejs/kit": "^2.48.2",
|
|
25
|
+
"fs-extra": "^11.3.2",
|
|
26
|
+
"exsolve": "^1.0.7",
|
|
27
|
+
"pathe": "^2.0.3",
|
|
28
|
+
"@workflow/builders": "4.0.1-beta.4",
|
|
29
|
+
"@workflow/swc-plugin": "4.0.1-beta.2"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/fs-extra": "^11.0.4",
|
|
33
|
+
"@types/node": "22.19.0",
|
|
34
|
+
"vite": "^7.1.11",
|
|
35
|
+
"@workflow/tsconfig": "4.0.1-beta.0"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc",
|
|
39
|
+
"dev": "tsc --watch",
|
|
40
|
+
"clean": "tsc --build --clean && rm -rf dist"
|
|
41
|
+
}
|
|
42
|
+
}
|