@vite-hub/schedule 0.0.1 → 0.0.3
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/README.md +73 -8
- package/dist/client-BMFCy0dX.js +233 -0
- package/dist/definition.d.ts +7 -0
- package/dist/definition.js +42 -0
- package/dist/discovery-BZlat3Kc.js +776 -0
- package/dist/due-Bbh4yIxq.js +59 -0
- package/dist/execute-ClFYvmp9.js +211 -0
- package/dist/index.d.ts +28 -23
- package/dist/index.js +7 -152
- package/dist/kv-BJ1I9IlJ.js +6 -0
- package/dist/kv-storage-DWinmLLy.js +30 -0
- package/dist/nuxt.d.ts +19 -0
- package/dist/nuxt.js +25 -0
- package/dist/runtime/driver.d.ts +26 -0
- package/dist/runtime/driver.js +334 -0
- package/dist/runtime/process.d.ts +11 -0
- package/dist/runtime/process.js +285 -0
- package/dist/runtime/state.d.ts +2 -2
- package/dist/runtime/state.js +1 -1
- package/dist/runtime/static.d.ts +27 -3
- package/dist/runtime/static.js +126 -3
- package/dist/runtime.d.ts +4 -3
- package/dist/runtime.js +3 -3
- package/dist/{state-DoONzfij.js → state-By7WU_ks.js} +55 -24
- package/dist/store-t-74rsM_.d.ts +48 -0
- package/dist/{types-DOjXDq0s.d.ts → types-Bcje4dLV.d.ts} +34 -9
- package/dist/vite-BX6_KiRw.js +1218 -0
- package/dist/vite.d.ts +35 -6
- package/dist/vite.js +2 -110
- package/dist/wait-until-CR-JjIOb.js +23 -0
- package/package.json +40 -39
- package/dist/client-BJ33CRLg.js +0 -401
- package/dist/discovery-Di9MD-SN.js +0 -574
- package/dist/module-C_j2ahfg.js +0 -1767
- package/dist/nitro.d.ts +0 -6
- package/dist/nitro.js +0 -2
- package/dist/store-CeeSsInC.d.ts +0 -63
|
@@ -0,0 +1,776 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, realpathSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import "node:url";
|
|
5
|
+
//#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
6
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
7
|
+
function normalizeWindowsPath(input = "") {
|
|
8
|
+
if (!input) return input;
|
|
9
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
10
|
+
}
|
|
11
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
12
|
+
const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
13
|
+
const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
14
|
+
function cwd() {
|
|
15
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
|
|
16
|
+
return "/";
|
|
17
|
+
}
|
|
18
|
+
const resolve$1 = function(...arguments_) {
|
|
19
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
20
|
+
let resolvedPath = "";
|
|
21
|
+
let resolvedAbsolute = false;
|
|
22
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
23
|
+
const path = index >= 0 ? arguments_[index] : cwd();
|
|
24
|
+
if (!path || path.length === 0) continue;
|
|
25
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
26
|
+
resolvedAbsolute = isAbsolute$1(path);
|
|
27
|
+
}
|
|
28
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
29
|
+
if (resolvedAbsolute && !isAbsolute$1(resolvedPath)) return `/${resolvedPath}`;
|
|
30
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
31
|
+
};
|
|
32
|
+
function normalizeString(path, allowAboveRoot) {
|
|
33
|
+
let res = "";
|
|
34
|
+
let lastSegmentLength = 0;
|
|
35
|
+
let lastSlash = -1;
|
|
36
|
+
let dots = 0;
|
|
37
|
+
let char = null;
|
|
38
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
39
|
+
if (index < path.length) char = path[index];
|
|
40
|
+
else if (char === "/") break;
|
|
41
|
+
else char = "/";
|
|
42
|
+
if (char === "/") {
|
|
43
|
+
if (lastSlash === index - 1 || dots === 1);
|
|
44
|
+
else if (dots === 2) {
|
|
45
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
46
|
+
if (res.length > 2) {
|
|
47
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
48
|
+
if (lastSlashIndex === -1) {
|
|
49
|
+
res = "";
|
|
50
|
+
lastSegmentLength = 0;
|
|
51
|
+
} else {
|
|
52
|
+
res = res.slice(0, lastSlashIndex);
|
|
53
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
54
|
+
}
|
|
55
|
+
lastSlash = index;
|
|
56
|
+
dots = 0;
|
|
57
|
+
continue;
|
|
58
|
+
} else if (res.length > 0) {
|
|
59
|
+
res = "";
|
|
60
|
+
lastSegmentLength = 0;
|
|
61
|
+
lastSlash = index;
|
|
62
|
+
dots = 0;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (allowAboveRoot) {
|
|
67
|
+
res += res.length > 0 ? "/.." : "..";
|
|
68
|
+
lastSegmentLength = 2;
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
|
|
72
|
+
else res = path.slice(lastSlash + 1, index);
|
|
73
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
74
|
+
}
|
|
75
|
+
lastSlash = index;
|
|
76
|
+
dots = 0;
|
|
77
|
+
} else if (char === "." && dots !== -1) ++dots;
|
|
78
|
+
else dots = -1;
|
|
79
|
+
}
|
|
80
|
+
return res;
|
|
81
|
+
}
|
|
82
|
+
const isAbsolute$1 = function(p) {
|
|
83
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
84
|
+
};
|
|
85
|
+
const relative$1 = function(from, to) {
|
|
86
|
+
const _from = resolve$1(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
87
|
+
const _to = resolve$1(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
88
|
+
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
|
|
89
|
+
const _fromCopy = [..._from];
|
|
90
|
+
for (const segment of _fromCopy) {
|
|
91
|
+
if (_to[0] !== segment) break;
|
|
92
|
+
_from.shift();
|
|
93
|
+
_to.shift();
|
|
94
|
+
}
|
|
95
|
+
return [..._from.map(() => ".."), ..._to].join("/");
|
|
96
|
+
};
|
|
97
|
+
const dirname$1 = function(p) {
|
|
98
|
+
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
99
|
+
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
|
|
100
|
+
return segments.join("/") || (isAbsolute$1(p) ? "/" : ".");
|
|
101
|
+
};
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region ../internal/src/build/paths.ts
|
|
104
|
+
function generatedDirSegments(productName) {
|
|
105
|
+
return [".vitehub", productName];
|
|
106
|
+
}
|
|
107
|
+
function ensureGeneratedDir(rootDir, productName) {
|
|
108
|
+
return resolve$1(rootDir, ...generatedDirSegments(productName));
|
|
109
|
+
}
|
|
110
|
+
function createImportPath(fromFile, targetFile) {
|
|
111
|
+
const importPath = relative$1(realpathIfExists(dirname$1(fromFile)), realpathIfExists(targetFile));
|
|
112
|
+
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
113
|
+
}
|
|
114
|
+
function realpathIfExists(path) {
|
|
115
|
+
try {
|
|
116
|
+
return realpathSync.native(path);
|
|
117
|
+
} catch {
|
|
118
|
+
return resolve$1(path);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region ../internal/src/definition-catalog.ts
|
|
123
|
+
const sourceFilePattern = /\.(?:c|m)?[jt]sx?$/i;
|
|
124
|
+
const declarationFilePattern = /\.d\.(?:c|m)?[jt]sx?$/i;
|
|
125
|
+
const ignoredDirs = new Set([
|
|
126
|
+
"node_modules",
|
|
127
|
+
"dist",
|
|
128
|
+
".output",
|
|
129
|
+
".nuxt",
|
|
130
|
+
".vercel",
|
|
131
|
+
".git",
|
|
132
|
+
".vitehub"
|
|
133
|
+
]);
|
|
134
|
+
function resolveDefinitionScanRoots(rootDir, scanDirs = []) {
|
|
135
|
+
return [...new Set([rootDir, ...scanDirs].filter(Boolean))];
|
|
136
|
+
}
|
|
137
|
+
function createDirectoryDefinitionSource(source, scanDirs, subdir, options = {}) {
|
|
138
|
+
return {
|
|
139
|
+
...options,
|
|
140
|
+
kind: "directory",
|
|
141
|
+
scanDirs,
|
|
142
|
+
source,
|
|
143
|
+
subdir
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function createSuffixDefinitionSource(source, roots, pattern, normalizeName, options = {}) {
|
|
147
|
+
return {
|
|
148
|
+
...options,
|
|
149
|
+
kind: "suffix",
|
|
150
|
+
normalizeName,
|
|
151
|
+
pattern,
|
|
152
|
+
roots,
|
|
153
|
+
source
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function readDirEntries(root) {
|
|
157
|
+
try {
|
|
158
|
+
return readdirSync(root, { withFileTypes: true });
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (error.code === "ENOENT") return [];
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function listMatchingFiles(root, predicate, options = {}) {
|
|
165
|
+
const files = [];
|
|
166
|
+
for (const entry of readDirEntries(root)) {
|
|
167
|
+
const absolute = resolve$1(root, entry.name);
|
|
168
|
+
if (entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
169
|
+
if (entry.name.startsWith(".")) continue;
|
|
170
|
+
if (ignoredDirs.has(entry.name)) continue;
|
|
171
|
+
files.push(...listMatchingFiles(absolute, predicate, options));
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (entry.name.startsWith(".") && !options.includeHidden) continue;
|
|
175
|
+
if (entry.isFile() && predicate(entry.name)) files.push(absolute);
|
|
176
|
+
}
|
|
177
|
+
return files.sort();
|
|
178
|
+
}
|
|
179
|
+
function listSourceFiles(root, options = {}) {
|
|
180
|
+
return listMatchingFiles(root, (name) => sourceFilePattern.test(name) && !declarationFilePattern.test(name), options);
|
|
181
|
+
}
|
|
182
|
+
function normalizePathDefinitionName(rootDir, file) {
|
|
183
|
+
return relative$1(rootDir, file).replace(sourceFilePattern, "").replace(/\/index$/i, "");
|
|
184
|
+
}
|
|
185
|
+
function normalizeSuffixDefinitionName(rootDir, file, pattern, options = {}) {
|
|
186
|
+
const normalized = relative$1(rootDir, file).replace(pattern, "");
|
|
187
|
+
if (options.stripPrefix && normalized.startsWith(options.stripPrefix)) return normalized.slice(options.stripPrefix.length);
|
|
188
|
+
return normalized;
|
|
189
|
+
}
|
|
190
|
+
function sortDefinitions(definitions) {
|
|
191
|
+
return [...definitions.values()].sort((left, right) => left.name.localeCompare(right.name));
|
|
192
|
+
}
|
|
193
|
+
function registerDefinition(definitions, definition, sourceLabel) {
|
|
194
|
+
const existing = definitions.get(definition.name);
|
|
195
|
+
if (existing) throw new Error(`Duplicate ${sourceLabel} name "${definition.name}":\n - ${existing.handler}\n - ${definition.handler}`);
|
|
196
|
+
definitions.set(definition.name, definition);
|
|
197
|
+
}
|
|
198
|
+
function mergeDefinitions(feature, ...sources) {
|
|
199
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
200
|
+
for (const source of sources) {
|
|
201
|
+
if (!source) continue;
|
|
202
|
+
for (const definition of source) {
|
|
203
|
+
const existing = definitions.get(definition.name);
|
|
204
|
+
if (existing && existing.handler !== definition.handler) throw new Error(`Duplicate ${feature} name "${definition.name}" from multiple discovery sources:\n - ${existing.handler} (${existing.source ?? "unknown"})\n - ${definition.handler} (${definition.source ?? "unknown"})`);
|
|
205
|
+
if (!existing) definitions.set(definition.name, definition);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return sortDefinitions(definitions);
|
|
209
|
+
}
|
|
210
|
+
function createDefinition(source, file, name) {
|
|
211
|
+
if (source.createDefinition) return source.createDefinition({
|
|
212
|
+
file,
|
|
213
|
+
name
|
|
214
|
+
});
|
|
215
|
+
return {
|
|
216
|
+
handler: file,
|
|
217
|
+
name,
|
|
218
|
+
source: source.source
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function scanSuffixDefinitions(feature, source) {
|
|
222
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
223
|
+
for (const root of source.roots) for (const file of listMatchingFiles(root, (name) => source.pattern.test(name), { includeHidden: source.includeHidden })) {
|
|
224
|
+
const name = source.normalizeName(root, file);
|
|
225
|
+
if (!name) continue;
|
|
226
|
+
registerDefinition(definitions, createDefinition(source, file, name), feature);
|
|
227
|
+
}
|
|
228
|
+
return sortDefinitions(definitions);
|
|
229
|
+
}
|
|
230
|
+
function scanDirectoryDefinitions(feature, source) {
|
|
231
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
232
|
+
for (const scanDir of source.scanDirs) {
|
|
233
|
+
const directory = resolve$1(scanDir, source.subdir);
|
|
234
|
+
for (const file of listSourceFiles(directory, { includeHidden: source.includeHidden })) {
|
|
235
|
+
const name = source.normalizeName ? source.normalizeName(directory, file) : normalizePathDefinitionName(directory, file);
|
|
236
|
+
if (!name) continue;
|
|
237
|
+
registerDefinition(definitions, createDefinition(source, file, name), feature);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return sortDefinitions(definitions);
|
|
241
|
+
}
|
|
242
|
+
function discoverDefinitions(feature, sources) {
|
|
243
|
+
return mergeDefinitions(feature, ...sources.map((source) => source.kind === "suffix" ? scanSuffixDefinitions(feature, source) : scanDirectoryDefinitions(feature, source)));
|
|
244
|
+
}
|
|
245
|
+
function createImportExpression(registryFile, file) {
|
|
246
|
+
const importPath = relative$1(resolve$1(registryFile, ".."), file);
|
|
247
|
+
return `import(${JSON.stringify(importPath.startsWith(".") ? importPath : `./${importPath}`)})`;
|
|
248
|
+
}
|
|
249
|
+
function createRuntimeRegistryContents(registryFile, definitions) {
|
|
250
|
+
const needsWorkflowRuntime = definitions.some((definition) => definition.steps?.length);
|
|
251
|
+
const runtimeImport = needsWorkflowRuntime ? [`import { createWorkflowSteps } from "@vite-hub/workflow/runtime/execute"`, `import { takeInlineWorkflowDefinitionForModule } from "@vite-hub/workflow/runtime/state"`] : [];
|
|
252
|
+
const imports = definitions.map((definition) => {
|
|
253
|
+
if (!definition.steps?.length) return ` ${JSON.stringify(definition.name)}: async () => ${createImportExpression(registryFile, definition.handler)},`;
|
|
254
|
+
const workflowDirectory = /\.(?:c|m)?[jt]s$/i.test(definition.handler) ? dirname$1(definition.handler) : definition.handler;
|
|
255
|
+
const stepImports = definition.steps.map((step) => {
|
|
256
|
+
const stepName = relative$1(workflowDirectory, step);
|
|
257
|
+
return `{ name: ${JSON.stringify(stepName)}, run: (await ${createImportExpression(registryFile, step)}).default }`;
|
|
258
|
+
});
|
|
259
|
+
const hasIndex = /\.(?:c|m)?[jt]s$/i.test(definition.handler);
|
|
260
|
+
const indexImport = hasIndex ? `const index = await ${createImportExpression(registryFile, definition.handler)}` : "";
|
|
261
|
+
const handler = hasIndex ? `index.default?.handler ? index.default : takeInlineWorkflowDefinitionForModule(${JSON.stringify(definition.name)}, index) || { handler: index.default }` : "{ handler: async (context) => { let value = context.payload; for (const step of Object.values(context.steps || {})) value = await step(value); return value } }";
|
|
262
|
+
return [
|
|
263
|
+
` ${JSON.stringify(definition.name)}: async () => {`,
|
|
264
|
+
` const cached = registryEntryCache.get(${JSON.stringify(definition.name)})`,
|
|
265
|
+
" if (cached) return cached",
|
|
266
|
+
indexImport ? ` ${indexImport}` : "",
|
|
267
|
+
` const steps = [${stepImports.join(", ")}]`,
|
|
268
|
+
` const definition = ${handler}`,
|
|
269
|
+
" const entry = {",
|
|
270
|
+
" ...definition,",
|
|
271
|
+
" options: { ...definition.options, rootStep: false },",
|
|
272
|
+
" handler: async (context) => {",
|
|
273
|
+
" const workflowSteps = createWorkflowSteps(context, steps)",
|
|
274
|
+
" return await definition.handler({ ...context, steps: workflowSteps })",
|
|
275
|
+
" },",
|
|
276
|
+
" }",
|
|
277
|
+
` registryEntryCache.set(${JSON.stringify(definition.name)}, entry)`,
|
|
278
|
+
" return entry",
|
|
279
|
+
" },"
|
|
280
|
+
].filter(Boolean).join("\n");
|
|
281
|
+
});
|
|
282
|
+
return [
|
|
283
|
+
...runtimeImport,
|
|
284
|
+
runtimeImport.length ? "" : "",
|
|
285
|
+
...needsWorkflowRuntime ? ["const registryEntryCache = new Map()", ""] : [],
|
|
286
|
+
"const registry = {",
|
|
287
|
+
...imports,
|
|
288
|
+
"}",
|
|
289
|
+
"",
|
|
290
|
+
"export default registry",
|
|
291
|
+
""
|
|
292
|
+
].join("\n");
|
|
293
|
+
}
|
|
294
|
+
async function writeRuntimeRegistryFile(registryFile, definitions) {
|
|
295
|
+
await writeFileIfChanged(registryFile, createRuntimeRegistryContents(registryFile, definitions));
|
|
296
|
+
}
|
|
297
|
+
async function writeFileIfChanged(file, contents) {
|
|
298
|
+
if (await readFile(file, "utf8").catch(() => void 0) === contents) return;
|
|
299
|
+
await mkdir(resolve$1(file, ".."), { recursive: true });
|
|
300
|
+
await writeFile(file, contents, "utf8");
|
|
301
|
+
}
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region ../internal/src/source-scanner.ts
|
|
304
|
+
function isQuote(char) {
|
|
305
|
+
return char === "\"" || char === "'" || char === "`";
|
|
306
|
+
}
|
|
307
|
+
function skipQuoted(source, index, controlFlowRegexes = /* @__PURE__ */ new Map()) {
|
|
308
|
+
const quote = source[index];
|
|
309
|
+
if (quote === "`") return skipTemplateLiteral(source, index, controlFlowRegexes);
|
|
310
|
+
index += 1;
|
|
311
|
+
while (index < source.length) {
|
|
312
|
+
if (source[index] === "\\") {
|
|
313
|
+
index += 2;
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
if (source[index] === quote) return index + 1;
|
|
317
|
+
index += 1;
|
|
318
|
+
}
|
|
319
|
+
return index;
|
|
320
|
+
}
|
|
321
|
+
function skipTemplateLiteral(source, index, controlFlowRegexes) {
|
|
322
|
+
index += 1;
|
|
323
|
+
let expressionDepth = 0;
|
|
324
|
+
let previousSignificant = "";
|
|
325
|
+
while (index < source.length) {
|
|
326
|
+
const char = source[index];
|
|
327
|
+
const next = source[index + 1];
|
|
328
|
+
if (char === "\\") {
|
|
329
|
+
index += 2;
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (expressionDepth === 0) {
|
|
333
|
+
if (char === "`") return index + 1;
|
|
334
|
+
if (char === "$" && next === "{") {
|
|
335
|
+
expressionDepth = 1;
|
|
336
|
+
previousSignificant = "{";
|
|
337
|
+
index += 2;
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
index += 1;
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (char === "\"" || char === "'") {
|
|
344
|
+
index = skipQuoted(source, index, controlFlowRegexes);
|
|
345
|
+
previousSignificant = "literal";
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (char === "`") {
|
|
349
|
+
index = skipTemplateLiteral(source, index, controlFlowRegexes);
|
|
350
|
+
previousSignificant = "literal";
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (char === "/" && next === "/") {
|
|
354
|
+
index = skipLineComment(source, index);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (char === "/" && next === "*") {
|
|
358
|
+
index = skipBlockComment(source, index);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
if (char === "/" && (isRegexLiteralStart(previousSignificant) || isControlFlowRegexStart(source, index, controlFlowRegexes))) {
|
|
362
|
+
index = skipRegexLiteral(source, index);
|
|
363
|
+
previousSignificant = "/";
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (char === "{") expressionDepth += 1;
|
|
367
|
+
if (char === "}") expressionDepth -= 1;
|
|
368
|
+
previousSignificant = trackSignificant(previousSignificant, char);
|
|
369
|
+
index += 1;
|
|
370
|
+
}
|
|
371
|
+
return index;
|
|
372
|
+
}
|
|
373
|
+
function skipLineComment(source, index) {
|
|
374
|
+
const end = source.indexOf("\n", index + 2);
|
|
375
|
+
return end === -1 ? source.length : end + 1;
|
|
376
|
+
}
|
|
377
|
+
function skipBlockComment(source, index) {
|
|
378
|
+
const end = source.indexOf("*/", index + 2);
|
|
379
|
+
return end === -1 ? source.length : end + 2;
|
|
380
|
+
}
|
|
381
|
+
function isIdentifierChar(char) {
|
|
382
|
+
return !!char && /[\w$]/.test(char);
|
|
383
|
+
}
|
|
384
|
+
function isRegexLiteralStart(previousSignificant) {
|
|
385
|
+
const token = previousSignificant.trimEnd();
|
|
386
|
+
if (/^\.[\w$]+$/.test(token)) return false;
|
|
387
|
+
return !token || /[({[=,:!&|?;>+\-*%^~]/.test(token) || /\b(?:await|case|delete|do|else|in|instanceof|return|throw|typeof|void|yield)$/.test(token);
|
|
388
|
+
}
|
|
389
|
+
function findLineCommentStart(source, start, end, controlFlowRegexes) {
|
|
390
|
+
for (let index = start; index <= end;) {
|
|
391
|
+
const char = source[index];
|
|
392
|
+
const next = source[index + 1];
|
|
393
|
+
if (isQuote(char)) {
|
|
394
|
+
index = skipQuoted(source, index, controlFlowRegexes);
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (char === "/" && next === "*") {
|
|
398
|
+
index = skipBlockComment(source, index);
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
if (char === "/" && next === "/") return index;
|
|
402
|
+
index += 1;
|
|
403
|
+
}
|
|
404
|
+
return -1;
|
|
405
|
+
}
|
|
406
|
+
function previousCodeIndex(source, index, controlFlowRegexes) {
|
|
407
|
+
let current = index;
|
|
408
|
+
while (current >= 0) {
|
|
409
|
+
while (/\s/.test(source[current] ?? "")) current--;
|
|
410
|
+
if (source[current] === "/" && source[current - 1] === "*") {
|
|
411
|
+
const start = source.lastIndexOf("/*", current - 2);
|
|
412
|
+
if (start === -1) return current;
|
|
413
|
+
current = start - 1;
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
const lineStart = source.lastIndexOf("\n", current) + 1;
|
|
417
|
+
const lineComment = findLineCommentStart(source, lineStart, current, controlFlowRegexes);
|
|
418
|
+
if (lineComment !== -1 && lineComment <= current) {
|
|
419
|
+
current = lineStart - 1;
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
return current;
|
|
423
|
+
}
|
|
424
|
+
return current;
|
|
425
|
+
}
|
|
426
|
+
function isControlFlowRegexStart(source, index, controlFlowRegexes = /* @__PURE__ */ new Map()) {
|
|
427
|
+
const cached = controlFlowRegexes.get(index);
|
|
428
|
+
if (cached !== void 0) return cached;
|
|
429
|
+
if (controlFlowRegexes.has(index)) return true;
|
|
430
|
+
controlFlowRegexes.set(index, void 0);
|
|
431
|
+
try {
|
|
432
|
+
const closeParen = previousCodeIndex(source, index - 1, controlFlowRegexes);
|
|
433
|
+
if (source[closeParen] !== ")") {
|
|
434
|
+
controlFlowRegexes.set(index, false);
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
for (let current = closeParen; current >= 0; current--) {
|
|
438
|
+
if (source[current] !== "(") continue;
|
|
439
|
+
if (findMatching(source, current, "(", ")", controlFlowRegexes) !== closeParen) continue;
|
|
440
|
+
const head = source.slice(0, current).replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g, " ");
|
|
441
|
+
const result = /(?:^|[^\w$])(?:catch|for|if|while|with)\s*$/.test(head);
|
|
442
|
+
controlFlowRegexes.set(index, result);
|
|
443
|
+
return result;
|
|
444
|
+
}
|
|
445
|
+
controlFlowRegexes.set(index, false);
|
|
446
|
+
return false;
|
|
447
|
+
} catch (error) {
|
|
448
|
+
controlFlowRegexes.delete(index);
|
|
449
|
+
throw error;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function skipRegexLiteral(source, index) {
|
|
453
|
+
index += 1;
|
|
454
|
+
while (index < source.length) {
|
|
455
|
+
const char = source[index];
|
|
456
|
+
if (char === "\\") {
|
|
457
|
+
index += 2;
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
if (char === "[") {
|
|
461
|
+
index += 1;
|
|
462
|
+
while (index < source.length) {
|
|
463
|
+
if (source[index] === "\\") {
|
|
464
|
+
index += 2;
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
if (source[index] === "]") break;
|
|
468
|
+
index += 1;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (char === "/") {
|
|
472
|
+
index += 1;
|
|
473
|
+
while (/[a-z]/i.test(source[index] ?? "")) index += 1;
|
|
474
|
+
return index;
|
|
475
|
+
}
|
|
476
|
+
index += 1;
|
|
477
|
+
}
|
|
478
|
+
return index;
|
|
479
|
+
}
|
|
480
|
+
function trackSignificant(previousSignificant, char) {
|
|
481
|
+
if (/[a-z$]/i.test(char ?? "")) return /[\w$]$/.test(previousSignificant) || previousSignificant === "." ? previousSignificant + char : char ?? "";
|
|
482
|
+
if (/\s/.test(char ?? "")) return /[\w$]$/.test(previousSignificant) ? `${previousSignificant} ` : previousSignificant;
|
|
483
|
+
if (!/\s/.test(char ?? "")) return char ?? "";
|
|
484
|
+
return previousSignificant;
|
|
485
|
+
}
|
|
486
|
+
function isFunctionDeclarationName(source, index) {
|
|
487
|
+
return /(?:^|[^\w$])(?:async\s+)?function\s*\*?\s*$/.test(source.slice(0, index));
|
|
488
|
+
}
|
|
489
|
+
function previousNonWhitespace(source, index) {
|
|
490
|
+
let current = index - 1;
|
|
491
|
+
while (/\s/.test(source[current] ?? "")) current -= 1;
|
|
492
|
+
return source[current];
|
|
493
|
+
}
|
|
494
|
+
function nextNonWhitespace(source, index) {
|
|
495
|
+
return source[skipWhitespaceAndComments(source, index)];
|
|
496
|
+
}
|
|
497
|
+
function skipWhitespaceAndComments(source, index) {
|
|
498
|
+
while (index < source.length) {
|
|
499
|
+
if (/\s/.test(source[index] ?? "")) {
|
|
500
|
+
index += 1;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
if (source[index] === "/" && source[index + 1] === "/") {
|
|
504
|
+
index = skipLineComment(source, index);
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
if (source[index] === "/" && source[index + 1] === "*") {
|
|
508
|
+
index = skipBlockComment(source, index);
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
return index;
|
|
512
|
+
}
|
|
513
|
+
return index;
|
|
514
|
+
}
|
|
515
|
+
function stripBoundaryComments(source) {
|
|
516
|
+
return source.replace(/^(?:\s|\/\/[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/)+/, "").replace(/(?:\s|\/\/[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/)+$/, "");
|
|
517
|
+
}
|
|
518
|
+
function maskSourceLiterals(source) {
|
|
519
|
+
const output = source.split("");
|
|
520
|
+
let previousSignificant = "";
|
|
521
|
+
const mask = (start, end) => {
|
|
522
|
+
for (let index = start; index < end; index++) if (output[index] !== "\n" && output[index] !== "\r") output[index] = " ";
|
|
523
|
+
};
|
|
524
|
+
for (let index = 0; index < source.length;) {
|
|
525
|
+
const char = source[index];
|
|
526
|
+
const next = source[index + 1];
|
|
527
|
+
let end;
|
|
528
|
+
if (isQuote(char)) {
|
|
529
|
+
end = skipQuoted(source, index);
|
|
530
|
+
previousSignificant = "literal";
|
|
531
|
+
} else if (char === "/" && next === "/") end = skipLineComment(source, index);
|
|
532
|
+
else if (char === "/" && next === "*") end = skipBlockComment(source, index);
|
|
533
|
+
else if (char === "/" && (isRegexLiteralStart(previousSignificant) || isControlFlowRegexStart(source, index))) {
|
|
534
|
+
end = skipRegexLiteral(source, index);
|
|
535
|
+
previousSignificant = "/";
|
|
536
|
+
}
|
|
537
|
+
if (end !== void 0) {
|
|
538
|
+
mask(index, end);
|
|
539
|
+
index = end;
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
previousSignificant = trackSignificant(previousSignificant, char);
|
|
543
|
+
index += 1;
|
|
544
|
+
}
|
|
545
|
+
return output.join("");
|
|
546
|
+
}
|
|
547
|
+
function isMethodDeclarationName(source, index, closeParen) {
|
|
548
|
+
const previous = previousNonWhitespace(source, index);
|
|
549
|
+
return source[skipWhitespaceAndComments(source, closeParen + 1)] === "{" && previous !== "(" && previous !== "=" && previous !== "," && previous !== ":";
|
|
550
|
+
}
|
|
551
|
+
function isMemberAccessName(source, index) {
|
|
552
|
+
return previousNonWhitespace(source, index) === ".";
|
|
553
|
+
}
|
|
554
|
+
function findMatching(source, index, open, close, controlFlowRegexes = /* @__PURE__ */ new Map()) {
|
|
555
|
+
let depth = 0;
|
|
556
|
+
let previousSignificant = "";
|
|
557
|
+
for (let current = index; current < source.length; current++) {
|
|
558
|
+
const char = source[current];
|
|
559
|
+
const next = source[current + 1];
|
|
560
|
+
if (isQuote(char)) {
|
|
561
|
+
current = skipQuoted(source, current, controlFlowRegexes) - 1;
|
|
562
|
+
previousSignificant = "literal";
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
if (char === "/" && next === "/") {
|
|
566
|
+
current = skipLineComment(source, current) - 1;
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
if (char === "/" && next === "*") {
|
|
570
|
+
current = skipBlockComment(source, current) - 1;
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
if (char === "/" && (isRegexLiteralStart(previousSignificant) || isControlFlowRegexStart(source, current, controlFlowRegexes))) {
|
|
574
|
+
current = skipRegexLiteral(source, current) - 1;
|
|
575
|
+
previousSignificant = "/";
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
if (char === open) {
|
|
579
|
+
depth += 1;
|
|
580
|
+
previousSignificant = char;
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
if (char === close && !(open === "<" && close === ">" && source[current - 1] === "=")) {
|
|
584
|
+
depth -= 1;
|
|
585
|
+
if (depth === 0) return current;
|
|
586
|
+
previousSignificant = char;
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
589
|
+
previousSignificant = trackSignificant(previousSignificant, char);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function splitTopLevel(source, separator = ",") {
|
|
593
|
+
const parts = [];
|
|
594
|
+
let depth = 0;
|
|
595
|
+
let previousSignificant = "";
|
|
596
|
+
let start = 0;
|
|
597
|
+
for (let index = 0; index < source.length; index++) {
|
|
598
|
+
const char = source[index];
|
|
599
|
+
const next = source[index + 1];
|
|
600
|
+
if (isQuote(char)) {
|
|
601
|
+
index = skipQuoted(source, index) - 1;
|
|
602
|
+
previousSignificant = "literal";
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
if (char === "/" && next === "/") {
|
|
606
|
+
index = skipLineComment(source, index) - 1;
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
if (char === "/" && next === "*") {
|
|
610
|
+
index = skipBlockComment(source, index) - 1;
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
if (char === "/" && (isRegexLiteralStart(previousSignificant) || isControlFlowRegexStart(source, index))) {
|
|
614
|
+
index = skipRegexLiteral(source, index) - 1;
|
|
615
|
+
previousSignificant = "/";
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
if (char === "<") {
|
|
619
|
+
const genericEnd = findMatching(source, index, "<", ">");
|
|
620
|
+
if (genericEnd !== void 0 && nextNonWhitespace(source, genericEnd + 1) === "(") {
|
|
621
|
+
index = genericEnd;
|
|
622
|
+
previousSignificant = ">";
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (char === "(" || char === "{" || char === "[") {
|
|
627
|
+
depth += 1;
|
|
628
|
+
previousSignificant = char;
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
if (char === ")" || char === "}" || char === "]") {
|
|
632
|
+
depth -= 1;
|
|
633
|
+
previousSignificant = char;
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
if (char === separator && depth === 0) {
|
|
637
|
+
parts.push(source.slice(start, index).trim());
|
|
638
|
+
start = index + 1;
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
previousSignificant = trackSignificant(previousSignificant, char);
|
|
642
|
+
}
|
|
643
|
+
parts.push(source.slice(start).trim());
|
|
644
|
+
return parts;
|
|
645
|
+
}
|
|
646
|
+
function findIdentifierCalls(source, name) {
|
|
647
|
+
const calls = [];
|
|
648
|
+
let previousSignificant = "";
|
|
649
|
+
for (let index = 0; index < source.length; index++) {
|
|
650
|
+
const char = source[index];
|
|
651
|
+
const next = source[index + 1];
|
|
652
|
+
if (isQuote(char)) {
|
|
653
|
+
index = skipQuoted(source, index) - 1;
|
|
654
|
+
previousSignificant = "literal";
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
if (char === "/" && next === "/") {
|
|
658
|
+
index = skipLineComment(source, index) - 1;
|
|
659
|
+
continue;
|
|
660
|
+
}
|
|
661
|
+
if (char === "/" && next === "*") {
|
|
662
|
+
index = skipBlockComment(source, index) - 1;
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
if (char === "/" && (isRegexLiteralStart(previousSignificant) || isControlFlowRegexStart(source, index))) {
|
|
666
|
+
index = skipRegexLiteral(source, index) - 1;
|
|
667
|
+
previousSignificant = "/";
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
if (!source.startsWith(name, index) || isIdentifierChar(source[index - 1]) || isIdentifierChar(source[index + name.length]) || isFunctionDeclarationName(source, index) || isMemberAccessName(source, index)) {
|
|
671
|
+
previousSignificant = trackSignificant(previousSignificant, char);
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
let openParen = skipWhitespaceAndComments(source, index + name.length);
|
|
675
|
+
if (source[openParen] === "<") {
|
|
676
|
+
const genericEnd = findMatching(source, openParen, "<", ">");
|
|
677
|
+
if (genericEnd === void 0) {
|
|
678
|
+
previousSignificant = trackSignificant(previousSignificant, char);
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
openParen = skipWhitespaceAndComments(source, genericEnd + 1);
|
|
682
|
+
}
|
|
683
|
+
if (source[openParen] !== "(") {
|
|
684
|
+
previousSignificant = trackSignificant(previousSignificant, char);
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
const closeParen = findMatching(source, openParen, "(", ")");
|
|
688
|
+
if (closeParen === void 0) {
|
|
689
|
+
previousSignificant = trackSignificant(previousSignificant, char);
|
|
690
|
+
continue;
|
|
691
|
+
}
|
|
692
|
+
if (isMethodDeclarationName(source, index, closeParen)) {
|
|
693
|
+
previousSignificant = trackSignificant(previousSignificant, char);
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
calls.push({
|
|
697
|
+
arguments: splitTopLevel(source.slice(openParen + 1, closeParen)),
|
|
698
|
+
closeParen,
|
|
699
|
+
name,
|
|
700
|
+
openParen,
|
|
701
|
+
start: index
|
|
702
|
+
});
|
|
703
|
+
previousSignificant = ")";
|
|
704
|
+
index = closeParen;
|
|
705
|
+
}
|
|
706
|
+
return calls;
|
|
707
|
+
}
|
|
708
|
+
function findDefaultExportCall(source, names) {
|
|
709
|
+
const masked = maskSourceLiterals(source);
|
|
710
|
+
const calls = names.flatMap((name) => findIdentifierCalls(source, name)).sort((left, right) => left.start - right.start);
|
|
711
|
+
for (const call of calls) {
|
|
712
|
+
const callArgument = stripBoundaryComments(call.arguments[0] || "");
|
|
713
|
+
if (!callArgument.startsWith("{")) continue;
|
|
714
|
+
const objectEnd = findMatching(callArgument, 0, "{", "}");
|
|
715
|
+
if (objectEnd === void 0) continue;
|
|
716
|
+
const suffix = stripBoundaryComments(callArgument.slice(objectEnd + 1));
|
|
717
|
+
if (suffix && !/^(?:as|satisfies)\b/.test(suffix)) continue;
|
|
718
|
+
const argument = callArgument.slice(0, objectEnd + 1);
|
|
719
|
+
if (/\bexport\s+default\s*(?:\(\s*)*$/.test(masked.slice(0, call.start))) return {
|
|
720
|
+
...call,
|
|
721
|
+
argument
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
function readObjectProperty(objectSource, propertyName) {
|
|
726
|
+
const normalized = stripBoundaryComments(objectSource);
|
|
727
|
+
if (!normalized.startsWith("{") || !normalized.endsWith("}")) return;
|
|
728
|
+
for (const property of splitTopLevel(normalized.slice(1, -1))) {
|
|
729
|
+
const parts = splitTopLevel(property, ":");
|
|
730
|
+
if (parts.length < 2) continue;
|
|
731
|
+
if (stripBoundaryComments(parts.shift()).replace(/^["'`](.*)["'`]$/s, "$1") === propertyName) return stripBoundaryComments(parts.join(":"));
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
//#endregion
|
|
735
|
+
//#region src/discovery.ts
|
|
736
|
+
const scheduleSuffixPattern = /\.schedule\.(?:c|m)?[jt]s$/i;
|
|
737
|
+
function readScheduleDiscoveryMetadata(file) {
|
|
738
|
+
const definition = findDefaultExportCall(readFileSync(file, "utf8"), ["defineSchedule", "defineScheduleTarget"]);
|
|
739
|
+
if (!definition) return { allowRuntimeSchedules: false };
|
|
740
|
+
if (definition.name === "defineScheduleTarget") return {
|
|
741
|
+
allowRuntimeSchedules: true,
|
|
742
|
+
runtimeOnly: true
|
|
743
|
+
};
|
|
744
|
+
return { allowRuntimeSchedules: readObjectProperty(definition.argument, "allowRuntimeSchedules") === "true" };
|
|
745
|
+
}
|
|
746
|
+
function createDiscoveredScheduleDefinition(source) {
|
|
747
|
+
return (context) => {
|
|
748
|
+
return {
|
|
749
|
+
...readScheduleDiscoveryMetadata(context.file),
|
|
750
|
+
handler: context.file,
|
|
751
|
+
name: context.name,
|
|
752
|
+
source
|
|
753
|
+
};
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
function normalizeSuffixScheduleName(rootDir, file) {
|
|
757
|
+
return normalizeSuffixDefinitionName(rootDir, file, scheduleSuffixPattern, { stripPrefix: "src/" });
|
|
758
|
+
}
|
|
759
|
+
function normalizeDirectoryScheduleName(directory, file) {
|
|
760
|
+
return normalizePathDefinitionName(directory, file);
|
|
761
|
+
}
|
|
762
|
+
function discoverScheduleDefinitions(options) {
|
|
763
|
+
if (options.mode === "server-schedules") return discoverDefinitions("schedule", [createDirectoryDefinitionSource("server-schedules", options.scanDirs, "schedules", {
|
|
764
|
+
createDefinition: createDiscoveredScheduleDefinition("server-schedules"),
|
|
765
|
+
normalizeName: normalizeDirectoryScheduleName
|
|
766
|
+
})]);
|
|
767
|
+
const roots = resolveDefinitionScanRoots(options.rootDir, options.scanDirs);
|
|
768
|
+
const serverRoots = resolveDefinitionScanRoots(options.serverRootDir || options.rootDir, options.scanDirs);
|
|
769
|
+
const serverScanDirs = options.serverDirs ?? serverRoots.map((root) => resolve(root, "server"));
|
|
770
|
+
return mergeDefinitions("schedule", discoverDefinitions("schedule", [createSuffixDefinitionSource("vite-suffix", roots, scheduleSuffixPattern, normalizeSuffixScheduleName, { createDefinition: createDiscoveredScheduleDefinition("vite-suffix") })]), discoverDefinitions("schedule", [createDirectoryDefinitionSource("server-schedules", serverScanDirs, "schedules", {
|
|
771
|
+
createDefinition: createDiscoveredScheduleDefinition("server-schedules"),
|
|
772
|
+
normalizeName: normalizeDirectoryScheduleName
|
|
773
|
+
})]));
|
|
774
|
+
}
|
|
775
|
+
//#endregion
|
|
776
|
+
export { writeRuntimeRegistryFile as a, createRuntimeRegistryContents as i, findDefaultExportCall as n, createImportPath as o, readObjectProperty as r, ensureGeneratedDir as s, discoverScheduleDefinitions as t };
|