@workflow/sveltekit 4.0.0-beta.4 → 4.0.0-beta.41
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 +33 -60
- package/dist/builder.js.map +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +14 -106
- package/dist/plugin.js.map +1 -1
- package/package.json +10 -9
package/dist/builder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAGA,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;YAqCvB,eAAe;YAuCf,mBAAmB;YAqCnB,iBAAiB;YAqDjB,mBAAmB;CA8BlC"}
|
package/dist/builder.js
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
1
|
import { constants } from 'node:fs';
|
|
2
2
|
import { access, mkdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { join, resolve } from 'node:path';
|
|
4
|
-
import { BaseBuilder } from '@workflow/builders';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
`;
|
|
4
|
+
import { BaseBuilder, NORMALIZE_REQUEST_CODE, } from '@workflow/builders';
|
|
5
|
+
const SVELTEKIT_VIRTUAL_MODULES = [
|
|
6
|
+
'$env/*', // All $env subpaths
|
|
7
|
+
'$lib', // Exact $lib import
|
|
8
|
+
'$lib/*', // All $lib subpaths
|
|
9
|
+
'$app/*', // All $app subpaths
|
|
10
|
+
];
|
|
18
11
|
export class SvelteKitBuilder extends BaseBuilder {
|
|
19
12
|
constructor(config) {
|
|
13
|
+
const workingDir = config?.workingDir || process.cwd();
|
|
20
14
|
super({
|
|
21
15
|
...config,
|
|
22
|
-
dirs: ['workflows'],
|
|
16
|
+
dirs: ['workflows', 'src/workflows', 'routes', 'src/routes'],
|
|
23
17
|
buildTarget: 'sveltekit',
|
|
24
18
|
stepsBundlePath: '', // unused in base
|
|
25
19
|
workflowsBundlePath: '', // unused in base
|
|
26
20
|
webhookBundlePath: '', // unused in base
|
|
27
|
-
workingDir
|
|
21
|
+
workingDir,
|
|
22
|
+
externalPackages: [...SVELTEKIT_VIRTUAL_MODULES],
|
|
28
23
|
});
|
|
29
24
|
}
|
|
30
25
|
async build() {
|
|
@@ -39,42 +34,48 @@ export class SvelteKitBuilder extends BaseBuilder {
|
|
|
39
34
|
}
|
|
40
35
|
// Get workflow and step files to bundle
|
|
41
36
|
const inputFiles = await this.getInputFiles();
|
|
42
|
-
const
|
|
37
|
+
const tsconfigPath = await this.findTsConfigPath();
|
|
43
38
|
const options = {
|
|
44
39
|
inputFiles,
|
|
45
40
|
workflowGeneratedDir,
|
|
46
|
-
|
|
47
|
-
tsPaths: tsConfig.paths,
|
|
41
|
+
tsconfigPath,
|
|
48
42
|
};
|
|
49
43
|
// Generate the three SvelteKit route handlers
|
|
50
|
-
await this.buildStepsRoute(options);
|
|
44
|
+
const manifest = await this.buildStepsRoute(options);
|
|
51
45
|
await this.buildWorkflowsRoute(options);
|
|
52
46
|
await this.buildWebhookRoute({ workflowGeneratedDir });
|
|
47
|
+
// Generate unified manifest
|
|
48
|
+
const workflowBundlePath = join(workflowGeneratedDir, 'flow/+server.js');
|
|
49
|
+
await this.createManifest({
|
|
50
|
+
workflowBundlePath,
|
|
51
|
+
manifestDir: workflowGeneratedDir,
|
|
52
|
+
manifest,
|
|
53
|
+
});
|
|
53
54
|
}
|
|
54
|
-
async buildStepsRoute({ inputFiles, workflowGeneratedDir,
|
|
55
|
+
async buildStepsRoute({ inputFiles, workflowGeneratedDir, tsconfigPath, }) {
|
|
55
56
|
// Create steps route: .well-known/workflow/v1/step/+server.js
|
|
56
57
|
const stepsRouteDir = join(workflowGeneratedDir, 'step');
|
|
57
58
|
await mkdir(stepsRouteDir, { recursive: true });
|
|
58
|
-
await this.createStepsBundle({
|
|
59
|
+
const { manifest } = await this.createStepsBundle({
|
|
59
60
|
format: 'esm',
|
|
60
61
|
inputFiles,
|
|
61
62
|
outfile: join(stepsRouteDir, '+server.js'),
|
|
62
63
|
externalizeNonSteps: true,
|
|
63
|
-
|
|
64
|
-
tsPaths,
|
|
64
|
+
tsconfigPath,
|
|
65
65
|
});
|
|
66
66
|
// Post-process the generated file to wrap with SvelteKit request converter
|
|
67
67
|
const stepsRouteFile = join(stepsRouteDir, '+server.js');
|
|
68
68
|
let stepsRouteContent = await readFile(stepsRouteFile, 'utf-8');
|
|
69
69
|
// Replace the default export with SvelteKit-compatible handler
|
|
70
|
-
stepsRouteContent = stepsRouteContent.replace(/export\s*\{\s*stepEntrypoint\s+as\s+POST\s*\}\s*;?$/m, `${
|
|
70
|
+
stepsRouteContent = stepsRouteContent.replace(/export\s*\{\s*stepEntrypoint\s+as\s+POST\s*\}\s*;?$/m, `${NORMALIZE_REQUEST_CODE}
|
|
71
71
|
export const POST = async ({request}) => {
|
|
72
|
-
const normalRequest = await
|
|
72
|
+
const normalRequest = await normalizeRequest(request);
|
|
73
73
|
return stepEntrypoint(normalRequest);
|
|
74
74
|
}`);
|
|
75
75
|
await writeFile(stepsRouteFile, stepsRouteContent);
|
|
76
|
+
return manifest;
|
|
76
77
|
}
|
|
77
|
-
async buildWorkflowsRoute({ inputFiles, workflowGeneratedDir,
|
|
78
|
+
async buildWorkflowsRoute({ inputFiles, workflowGeneratedDir, tsconfigPath, }) {
|
|
78
79
|
// Create workflows route: .well-known/workflow/v1/flow/+server.js
|
|
79
80
|
const workflowsRouteDir = join(workflowGeneratedDir, 'flow');
|
|
80
81
|
await mkdir(workflowsRouteDir, { recursive: true });
|
|
@@ -83,16 +84,15 @@ export const POST = async ({request}) => {
|
|
|
83
84
|
outfile: join(workflowsRouteDir, '+server.js'),
|
|
84
85
|
bundleFinalOutput: false,
|
|
85
86
|
inputFiles,
|
|
86
|
-
|
|
87
|
-
tsPaths,
|
|
87
|
+
tsconfigPath,
|
|
88
88
|
});
|
|
89
89
|
// Post-process the generated file to wrap with SvelteKit request converter
|
|
90
90
|
const workflowsRouteFile = join(workflowsRouteDir, '+server.js');
|
|
91
91
|
let workflowsRouteContent = await readFile(workflowsRouteFile, 'utf-8');
|
|
92
92
|
// Replace the default export with SvelteKit-compatible handler
|
|
93
|
-
workflowsRouteContent = workflowsRouteContent.replace(/export const POST = workflowEntrypoint\(workflowCode\);?$/m, `${
|
|
93
|
+
workflowsRouteContent = workflowsRouteContent.replace(/export const POST = workflowEntrypoint\(workflowCode\);?$/m, `${NORMALIZE_REQUEST_CODE}
|
|
94
94
|
export const POST = async ({request}) => {
|
|
95
|
-
const normalRequest = await
|
|
95
|
+
const normalRequest = await normalizeRequest(request);
|
|
96
96
|
return workflowEntrypoint(workflowCode)(normalRequest);
|
|
97
97
|
}`);
|
|
98
98
|
await writeFile(workflowsRouteFile, workflowsRouteContent);
|
|
@@ -106,42 +106,15 @@ export const POST = async ({request}) => {
|
|
|
106
106
|
});
|
|
107
107
|
// Post-process the generated file to wrap with SvelteKit request converter
|
|
108
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
109
|
// Update handler signature to accept token as parameter
|
|
113
110
|
webhookRouteContent = webhookRouteContent.replace(/async function handler\(request\) \{[\s\S]*?const token = decodeURIComponent\(pathParts\[pathParts\.length - 1\]\);/, `async function handler(request, token) {`);
|
|
114
111
|
// Remove the URL parsing code since we get token from params
|
|
115
112
|
webhookRouteContent = webhookRouteContent.replace(/const url = new URL\(request\.url\);[\s\S]*?const pathParts = url\.pathname\.split\('\/'\);[\s\S]*?\n/, '');
|
|
116
113
|
// 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;/, `${
|
|
114
|
+
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;/, `${NORMALIZE_REQUEST_CODE}
|
|
118
115
|
const createSvelteKitHandler = (method) => async ({ request, params, platform }) => {
|
|
119
|
-
|
|
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);
|
|
116
|
+
const normalRequest = await normalizeRequest(request);
|
|
138
117
|
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
118
|
return response;
|
|
146
119
|
};
|
|
147
120
|
|
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,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,
|
|
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,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,CA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.ts
CHANGED
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
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"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,111 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { createBuildQueue } from '@workflow/builders';
|
|
2
|
+
import { workflowTransformPlugin } from '@workflow/rollup';
|
|
3
|
+
import { workflowHotUpdatePlugin } from '@workflow/vite';
|
|
4
4
|
import { SvelteKitBuilder } from './builder.js';
|
|
5
5
|
export function workflowPlugin() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// Only apply the transform if file needs it
|
|
13
|
-
if (!code.match(/(use step|use workflow)/)) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
const isTypeScript = id.endsWith('.ts') || id.endsWith('.tsx');
|
|
17
|
-
const isTsx = id.endsWith('.tsx');
|
|
18
|
-
const swcPlugin = resolveModulePath('@workflow/swc-plugin', {
|
|
19
|
-
from: [import.meta.url],
|
|
20
|
-
});
|
|
21
|
-
// Calculate relative filename for SWC plugin
|
|
22
|
-
// The SWC plugin uses filename to generate workflowId, so it must be relative
|
|
23
|
-
const workingDir = process.cwd();
|
|
24
|
-
const normalizedWorkingDir = workingDir
|
|
25
|
-
.replace(/\\/g, '/')
|
|
26
|
-
.replace(/\/$/, '');
|
|
27
|
-
const normalizedFilepath = id.replace(/\\/g, '/');
|
|
28
|
-
// Windows fix: Use case-insensitive comparison to work around drive letter casing issues
|
|
29
|
-
const lowerWd = normalizedWorkingDir.toLowerCase();
|
|
30
|
-
const lowerPath = normalizedFilepath.toLowerCase();
|
|
31
|
-
let relativeFilename;
|
|
32
|
-
if (lowerPath.startsWith(lowerWd + '/')) {
|
|
33
|
-
// File is under working directory - manually calculate relative path
|
|
34
|
-
relativeFilename = normalizedFilepath.substring(normalizedWorkingDir.length + 1);
|
|
35
|
-
}
|
|
36
|
-
else if (lowerPath === lowerWd) {
|
|
37
|
-
// File IS the working directory (shouldn't happen)
|
|
38
|
-
relativeFilename = '.';
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
// Use relative() for files outside working directory
|
|
42
|
-
relativeFilename = relative(workingDir, id).replace(/\\/g, '/');
|
|
43
|
-
if (relativeFilename.startsWith('../')) {
|
|
44
|
-
relativeFilename = relativeFilename
|
|
45
|
-
.split('/')
|
|
46
|
-
.filter((part) => part !== '..')
|
|
47
|
-
.join('/');
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// Final safety check - ensure we never pass an absolute path to SWC
|
|
51
|
-
if (relativeFilename.includes(':') || relativeFilename.startsWith('/')) {
|
|
52
|
-
// This should rarely happen, but use filename split as last resort
|
|
53
|
-
relativeFilename = normalizedFilepath.split('/').pop() || 'unknown.ts';
|
|
54
|
-
}
|
|
55
|
-
// Transform with SWC
|
|
56
|
-
const result = await transform(code, {
|
|
57
|
-
filename: relativeFilename,
|
|
58
|
-
jsc: {
|
|
59
|
-
parser: {
|
|
60
|
-
syntax: isTypeScript ? 'typescript' : 'ecmascript',
|
|
61
|
-
tsx: isTsx,
|
|
62
|
-
},
|
|
63
|
-
target: 'es2022',
|
|
64
|
-
experimental: {
|
|
65
|
-
plugins: [[swcPlugin, { mode: 'client' }]],
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
minify: false,
|
|
69
|
-
sourceMaps: true,
|
|
70
|
-
inlineSourcesContent: true,
|
|
71
|
-
});
|
|
72
|
-
return {
|
|
73
|
-
code: result.code,
|
|
74
|
-
map: result.map ? JSON.parse(result.map) : null,
|
|
75
|
-
};
|
|
6
|
+
const builder = new SvelteKitBuilder();
|
|
7
|
+
const enqueue = createBuildQueue();
|
|
8
|
+
return [
|
|
9
|
+
workflowTransformPlugin(),
|
|
10
|
+
{
|
|
11
|
+
name: 'workflow:sveltekit',
|
|
76
12
|
},
|
|
77
|
-
|
|
78
|
-
builder
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
// TODO: Move this to @workflow/vite or something since this is vite specific
|
|
84
|
-
async handleHotUpdate(ctx) {
|
|
85
|
-
const { file, server, read } = ctx;
|
|
86
|
-
// Check if this is a TS/JS file that might contain workflow directives
|
|
87
|
-
const jsTsRegex = /\.(ts|tsx|js|jsx|mjs|cjs)$/;
|
|
88
|
-
if (!jsTsRegex.test(file)) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
// Read the file to check for workflow/step directives
|
|
92
|
-
const content = await read();
|
|
93
|
-
const useWorkflowPattern = /^\s*(['"])use workflow\1;?\s*$/m;
|
|
94
|
-
const useStepPattern = /^\s*(['"])use step\1;?\s*$/m;
|
|
95
|
-
if (!useWorkflowPattern.test(content) && !useStepPattern.test(content)) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
// Rebuild everything - simpler and more reliable than tracking individual files
|
|
99
|
-
console.log('Workflow file changed, regenerating routes...');
|
|
100
|
-
await builder.build();
|
|
101
|
-
// Trigger full reload of workflow routes
|
|
102
|
-
server.ws.send({
|
|
103
|
-
type: 'full-reload',
|
|
104
|
-
path: '*',
|
|
105
|
-
});
|
|
106
|
-
// Let Vite handle the normal HMR for the changed file
|
|
107
|
-
return;
|
|
108
|
-
},
|
|
109
|
-
};
|
|
13
|
+
workflowHotUpdatePlugin({
|
|
14
|
+
builder,
|
|
15
|
+
enqueue,
|
|
16
|
+
}),
|
|
17
|
+
];
|
|
110
18
|
}
|
|
111
19
|
//# sourceMappingURL=plugin.js.map
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workflow/sveltekit",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.41",
|
|
4
4
|
"description": "SvelteKit integration for Workflow DevKit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"license": "
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
16
|
"url": "https://github.com/vercel/workflow.git",
|
|
@@ -20,18 +20,19 @@
|
|
|
20
20
|
".": "./dist/index.js"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@swc/core": "1.
|
|
24
|
-
"@sveltejs/kit": "^2.48.2",
|
|
25
|
-
"fs-extra": "^11.3.2",
|
|
23
|
+
"@swc/core": "1.15.3",
|
|
26
24
|
"exsolve": "^1.0.7",
|
|
25
|
+
"fs-extra": "^11.3.2",
|
|
27
26
|
"pathe": "^2.0.3",
|
|
28
|
-
"@workflow/builders": "4.0.1-beta.
|
|
29
|
-
"@workflow/
|
|
27
|
+
"@workflow/builders": "4.0.1-beta.43",
|
|
28
|
+
"@workflow/rollup": "4.0.0-beta.9",
|
|
29
|
+
"@workflow/swc-plugin": "4.1.0-beta.15",
|
|
30
|
+
"@workflow/vite": "4.0.0-beta.2"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@types/fs-extra": "
|
|
33
|
+
"@types/fs-extra": "11.0.4",
|
|
33
34
|
"@types/node": "22.19.0",
|
|
34
|
-
"vite": "
|
|
35
|
+
"vite": "7.1.12",
|
|
35
36
|
"@workflow/tsconfig": "4.0.1-beta.0"
|
|
36
37
|
},
|
|
37
38
|
"scripts": {
|