@vite-hub/schedule 0.0.4 → 0.3.1

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.
Files changed (62) hide show
  1. package/README.md +139 -58
  2. package/dist/console-wEhr0LWn.d.ts +330 -0
  3. package/dist/definition.d.ts +8 -6
  4. package/dist/definition.js +34 -28
  5. package/dist/due-BVMRQ93v.js +144 -0
  6. package/dist/durability.d.ts +14 -0
  7. package/dist/durability.js +23 -0
  8. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  9. package/dist/error-diagnostics-Mpeks7J0.js +166 -0
  10. package/dist/index.d.ts +61 -40
  11. package/dist/index.js +27 -7
  12. package/dist/inspect-DTfAo5gS.js +118 -0
  13. package/dist/invariant-DolT9EEx.js +22 -0
  14. package/dist/kv-storage-C0KZZB6v.d.ts +18 -0
  15. package/dist/{kv-storage-DWinmLLy.js → kv-storage-iJChCS5A.js} +2 -2
  16. package/dist/object-Da1zyPCR.js +11 -0
  17. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  18. package/dist/operations-DwZWFIUX.js +184 -0
  19. package/dist/operations.d.ts +84 -0
  20. package/dist/operations.js +318 -0
  21. package/dist/os.d.ts +167 -0
  22. package/dist/os.js +1659 -0
  23. package/dist/registry-module.d.ts +0 -5
  24. package/dist/runtime/console.d.ts +12 -0
  25. package/dist/runtime/console.js +85 -0
  26. package/dist/runtime/kv.d.ts +4 -0
  27. package/dist/{kv-BJ1I9IlJ.js → runtime/kv.js} +1 -1
  28. package/dist/runtime/process.d.ts +53 -5
  29. package/dist/runtime/process.js +501 -251
  30. package/dist/runtime/state.d.ts +2 -13
  31. package/dist/runtime/state.js +2 -2
  32. package/dist/runtime/static.d.ts +44 -12
  33. package/dist/runtime/static.js +2 -150
  34. package/dist/runtime.d.ts +38 -4
  35. package/dist/runtime.js +6 -3
  36. package/dist/started-BuGmnus4.js +201 -0
  37. package/dist/started-Bx7MDbrl.js +146 -0
  38. package/dist/started-errors-p7cu_rI7.js +250 -0
  39. package/dist/state-B-Fuyfb4.js +468 -0
  40. package/dist/state-Do2wV4Tx.d.ts +49 -0
  41. package/dist/static-DQwzzvPg.js +266 -0
  42. package/dist/store-Df0-fzCl.d.ts +53 -0
  43. package/dist/time-zone-SBldrUgt.js +59 -0
  44. package/dist/types-Cw5LjPuc.d.ts +167 -0
  45. package/dist/vite.d.ts +214 -11
  46. package/dist/vite.js +5876 -3
  47. package/dist/wait-until-Dy4Bn3ZN.js +112 -0
  48. package/package.json +65 -24
  49. package/dist/client-DpCD4YFE.js +0 -233
  50. package/dist/discovery-DkFAN7Wd.d.ts +0 -15
  51. package/dist/discovery-DvU3B6iD.js +0 -753
  52. package/dist/due-Bbh4yIxq.js +0 -59
  53. package/dist/execute-B-pii4wf.js +0 -211
  54. package/dist/nuxt.d.ts +0 -19
  55. package/dist/nuxt.js +0 -26
  56. package/dist/runtime/driver.d.ts +0 -26
  57. package/dist/runtime/driver.js +0 -337
  58. package/dist/state-By7WU_ks.js +0 -472
  59. package/dist/store-t-74rsM_.d.ts +0 -48
  60. package/dist/types-Bcje4dLV.d.ts +0 -136
  61. package/dist/vite-BHs17nWX.js +0 -4166
  62. package/dist/wait-until-BzIwzXw4.js +0 -23
@@ -1,753 +0,0 @@
1
- import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
2
- import { isAbsolute, relative, resolve, sep } 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 isGitRepositoryDirectory(directory) {
165
- return existsSync(resolve$1(directory, ".git"));
166
- }
167
- function listMatchingFiles(root, predicate, options = {}) {
168
- const files = [];
169
- for (const entry of readDirEntries(root)) {
170
- const absolute = resolve$1(root, entry.name);
171
- if (entry.isDirectory() && !entry.isSymbolicLink()) {
172
- if (isGitRepositoryDirectory(absolute)) continue;
173
- if (entry.name.startsWith(".")) continue;
174
- if (ignoredDirs.has(entry.name)) continue;
175
- files.push(...listMatchingFiles(absolute, predicate, options));
176
- continue;
177
- }
178
- if (entry.name.startsWith(".") && !options.includeHidden) continue;
179
- if (entry.isFile() && predicate(entry.name)) files.push(absolute);
180
- }
181
- return files.sort();
182
- }
183
- function listSourceFiles(root, options = {}) {
184
- return listMatchingFiles(root, (name) => sourceFilePattern.test(name) && !declarationFilePattern.test(name), options);
185
- }
186
- function normalizePathDefinitionName(rootDir, file) {
187
- return relative$1(rootDir, file).replace(sourceFilePattern, "").replace(/\/index$/i, "");
188
- }
189
- function normalizeSuffixDefinitionName(rootDir, file, pattern, options = {}) {
190
- const normalized = relative$1(rootDir, file).replace(pattern, "");
191
- if (options.stripPrefix && normalized.startsWith(options.stripPrefix)) return normalized.slice(options.stripPrefix.length);
192
- return normalized;
193
- }
194
- function sortDefinitions(definitions) {
195
- return [...definitions.values()].sort((left, right) => left.name.localeCompare(right.name));
196
- }
197
- function registerDefinition(definitions, definition, sourceLabel) {
198
- const existing = definitions.get(definition.name);
199
- if (existing) throw new Error(`Duplicate ${sourceLabel} name "${definition.name}":\n - ${existing.handler}\n - ${definition.handler}`);
200
- definitions.set(definition.name, definition);
201
- }
202
- function mergeDefinitions(feature, ...sources) {
203
- const definitions = /* @__PURE__ */ new Map();
204
- for (const source of sources) {
205
- if (!source) continue;
206
- for (const definition of source) {
207
- const existing = definitions.get(definition.name);
208
- 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"})`);
209
- if (!existing) definitions.set(definition.name, definition);
210
- }
211
- }
212
- return sortDefinitions(definitions);
213
- }
214
- function createDefinition(source, file, name) {
215
- if (source.createDefinition) return source.createDefinition({
216
- file,
217
- name
218
- });
219
- return {
220
- handler: file,
221
- name,
222
- source: source.source
223
- };
224
- }
225
- function scanSuffixDefinitions(feature, source) {
226
- const definitions = /* @__PURE__ */ new Map();
227
- for (const root of source.roots) for (const file of listMatchingFiles(root, (name) => source.pattern.test(name), { includeHidden: source.includeHidden })) {
228
- const name = source.normalizeName(root, file);
229
- if (!name) continue;
230
- registerDefinition(definitions, createDefinition(source, file, name), feature);
231
- }
232
- return sortDefinitions(definitions);
233
- }
234
- function scanDirectoryDefinitions(feature, source) {
235
- const definitions = /* @__PURE__ */ new Map();
236
- for (const scanDir of source.scanDirs) {
237
- const directory = resolve$1(scanDir, source.subdir);
238
- for (const file of listSourceFiles(directory, { includeHidden: source.includeHidden })) {
239
- const name = source.normalizeName ? source.normalizeName(directory, file) : normalizePathDefinitionName(directory, file);
240
- if (!name) continue;
241
- registerDefinition(definitions, createDefinition(source, file, name), feature);
242
- }
243
- }
244
- return sortDefinitions(definitions);
245
- }
246
- function discoverDefinitions(feature, sources) {
247
- return mergeDefinitions(feature, ...sources.map((source) => source.kind === "suffix" ? scanSuffixDefinitions(feature, source) : scanDirectoryDefinitions(feature, source)));
248
- }
249
- function createImportExpression(registryFile, file) {
250
- const importPath = relative$1(resolve$1(registryFile, ".."), file);
251
- return `import(${JSON.stringify(importPath.startsWith(".") ? importPath : `./${importPath}`)})`;
252
- }
253
- function createRuntimeRegistryContents(registryFile, definitions) {
254
- return [
255
- "",
256
- "const registry = {",
257
- ...definitions.map((definition) => ` ${JSON.stringify(definition.name)}: async () => ${createImportExpression(registryFile, definition.handler)},`),
258
- "}",
259
- "",
260
- "export default registry",
261
- ""
262
- ].join("\n");
263
- }
264
- async function writeRuntimeRegistryFile(registryFile, definitions) {
265
- await writeFileIfChanged(registryFile, createRuntimeRegistryContents(registryFile, definitions));
266
- }
267
- async function writeFileIfChanged(file, contents) {
268
- if (await readFile(file, "utf8").catch(() => void 0) === contents) return;
269
- await mkdir(resolve$1(file, ".."), { recursive: true });
270
- await writeFile(file, contents, "utf8");
271
- }
272
- //#endregion
273
- //#region ../internal/src/source-scanner.ts
274
- function isQuote(char) {
275
- return char === "\"" || char === "'" || char === "`";
276
- }
277
- function skipQuoted(source, index, controlFlowRegexes = /* @__PURE__ */ new Map()) {
278
- const quote = source[index];
279
- if (quote === "`") return skipTemplateLiteral(source, index, controlFlowRegexes);
280
- index += 1;
281
- while (index < source.length) {
282
- if (source[index] === "\\") {
283
- index += 2;
284
- continue;
285
- }
286
- if (source[index] === quote) return index + 1;
287
- index += 1;
288
- }
289
- return index;
290
- }
291
- function skipTemplateLiteral(source, index, controlFlowRegexes) {
292
- index += 1;
293
- let expressionDepth = 0;
294
- let previousSignificant = "";
295
- while (index < source.length) {
296
- const char = source[index];
297
- const next = source[index + 1];
298
- if (char === "\\") {
299
- index += 2;
300
- continue;
301
- }
302
- if (expressionDepth === 0) {
303
- if (char === "`") return index + 1;
304
- if (char === "$" && next === "{") {
305
- expressionDepth = 1;
306
- previousSignificant = "{";
307
- index += 2;
308
- continue;
309
- }
310
- index += 1;
311
- continue;
312
- }
313
- if (char === "\"" || char === "'") {
314
- index = skipQuoted(source, index, controlFlowRegexes);
315
- previousSignificant = "literal";
316
- continue;
317
- }
318
- if (char === "`") {
319
- index = skipTemplateLiteral(source, index, controlFlowRegexes);
320
- previousSignificant = "literal";
321
- continue;
322
- }
323
- if (char === "/" && next === "/") {
324
- index = skipLineComment(source, index);
325
- continue;
326
- }
327
- if (char === "/" && next === "*") {
328
- index = skipBlockComment(source, index);
329
- continue;
330
- }
331
- if (char === "/" && (isRegexLiteralStart(previousSignificant) || isControlFlowRegexStart(source, index, controlFlowRegexes))) {
332
- index = skipRegexLiteral(source, index);
333
- previousSignificant = "/";
334
- continue;
335
- }
336
- if (char === "{") expressionDepth += 1;
337
- if (char === "}") expressionDepth -= 1;
338
- previousSignificant = trackSignificant(previousSignificant, char);
339
- index += 1;
340
- }
341
- return index;
342
- }
343
- function skipLineComment(source, index) {
344
- const end = source.indexOf("\n", index + 2);
345
- return end === -1 ? source.length : end + 1;
346
- }
347
- function skipBlockComment(source, index) {
348
- const end = source.indexOf("*/", index + 2);
349
- return end === -1 ? source.length : end + 2;
350
- }
351
- function isIdentifierChar(char) {
352
- return !!char && /[\w$]/.test(char);
353
- }
354
- function isRegexLiteralStart(previousSignificant) {
355
- const token = previousSignificant.trimEnd();
356
- if (/^\.[\w$]+$/.test(token)) return false;
357
- return !token || /[({[=,:!&|?;>+\-*%^~]/.test(token) || /\b(?:await|case|delete|do|else|in|instanceof|return|throw|typeof|void|yield)$/.test(token);
358
- }
359
- function findLineCommentStart(source, start, end, controlFlowRegexes) {
360
- for (let index = start; index <= end;) {
361
- const char = source[index];
362
- const next = source[index + 1];
363
- if (isQuote(char)) {
364
- index = skipQuoted(source, index, controlFlowRegexes);
365
- continue;
366
- }
367
- if (char === "/" && next === "*") {
368
- index = skipBlockComment(source, index);
369
- continue;
370
- }
371
- if (char === "/" && next === "/") return index;
372
- index += 1;
373
- }
374
- return -1;
375
- }
376
- function previousCodeIndex(source, index, controlFlowRegexes) {
377
- let current = index;
378
- while (current >= 0) {
379
- while (/\s/.test(source[current] ?? "")) current--;
380
- if (source[current] === "/" && source[current - 1] === "*") {
381
- const start = source.lastIndexOf("/*", current - 2);
382
- if (start === -1) return current;
383
- current = start - 1;
384
- continue;
385
- }
386
- const lineStart = source.lastIndexOf("\n", current) + 1;
387
- const lineComment = findLineCommentStart(source, lineStart, current, controlFlowRegexes);
388
- if (lineComment !== -1 && lineComment <= current) {
389
- current = lineStart - 1;
390
- continue;
391
- }
392
- return current;
393
- }
394
- return current;
395
- }
396
- function isControlFlowRegexStart(source, index, controlFlowRegexes = /* @__PURE__ */ new Map()) {
397
- const cached = controlFlowRegexes.get(index);
398
- if (cached !== void 0) return cached;
399
- if (controlFlowRegexes.has(index)) return true;
400
- controlFlowRegexes.set(index, void 0);
401
- try {
402
- const closeParen = previousCodeIndex(source, index - 1, controlFlowRegexes);
403
- if (source[closeParen] !== ")") {
404
- controlFlowRegexes.set(index, false);
405
- return false;
406
- }
407
- for (let current = closeParen; current >= 0; current--) {
408
- if (source[current] !== "(") continue;
409
- if (findMatching(source, current, "(", ")", controlFlowRegexes) !== closeParen) continue;
410
- const head = source.slice(0, current).replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g, " ");
411
- const result = /(?:^|[^\w$])(?:catch|for|if|while|with)\s*$/.test(head);
412
- controlFlowRegexes.set(index, result);
413
- return result;
414
- }
415
- controlFlowRegexes.set(index, false);
416
- return false;
417
- } catch (error) {
418
- controlFlowRegexes.delete(index);
419
- throw error;
420
- }
421
- }
422
- function skipRegexLiteral(source, index) {
423
- index += 1;
424
- while (index < source.length) {
425
- const char = source[index];
426
- if (char === "\\") {
427
- index += 2;
428
- continue;
429
- }
430
- if (char === "[") {
431
- index += 1;
432
- while (index < source.length) {
433
- if (source[index] === "\\") {
434
- index += 2;
435
- continue;
436
- }
437
- if (source[index] === "]") break;
438
- index += 1;
439
- }
440
- }
441
- if (char === "/") {
442
- index += 1;
443
- while (/[a-z]/i.test(source[index] ?? "")) index += 1;
444
- return index;
445
- }
446
- index += 1;
447
- }
448
- return index;
449
- }
450
- function trackSignificant(previousSignificant, char) {
451
- if (/[a-z$]/i.test(char ?? "")) return /[\w$]$/.test(previousSignificant) || previousSignificant === "." ? previousSignificant + char : char ?? "";
452
- if (/\s/.test(char ?? "")) return /[\w$]$/.test(previousSignificant) ? `${previousSignificant} ` : previousSignificant;
453
- if (!/\s/.test(char ?? "")) return char ?? "";
454
- return previousSignificant;
455
- }
456
- function isFunctionDeclarationName(source, index) {
457
- return /(?:^|[^\w$])(?:async\s+)?function\s*\*?\s*$/.test(source.slice(0, index));
458
- }
459
- function previousNonWhitespace(source, index) {
460
- let current = index - 1;
461
- while (/\s/.test(source[current] ?? "")) current -= 1;
462
- return source[current];
463
- }
464
- function nextNonWhitespace(source, index) {
465
- return source[skipWhitespaceAndComments(source, index)];
466
- }
467
- function skipWhitespaceAndComments(source, index) {
468
- while (index < source.length) {
469
- if (/\s/.test(source[index] ?? "")) {
470
- index += 1;
471
- continue;
472
- }
473
- if (source[index] === "/" && source[index + 1] === "/") {
474
- index = skipLineComment(source, index);
475
- continue;
476
- }
477
- if (source[index] === "/" && source[index + 1] === "*") {
478
- index = skipBlockComment(source, index);
479
- continue;
480
- }
481
- return index;
482
- }
483
- return index;
484
- }
485
- function stripBoundaryComments(source) {
486
- return source.replace(/^(?:\s|\/\/[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/)+/, "").replace(/(?:\s|\/\/[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/)+$/, "");
487
- }
488
- function maskSourceLiterals(source) {
489
- const output = source.split("");
490
- let previousSignificant = "";
491
- const mask = (start, end) => {
492
- for (let index = start; index < end; index++) if (output[index] !== "\n" && output[index] !== "\r") output[index] = " ";
493
- };
494
- for (let index = 0; index < source.length;) {
495
- const char = source[index];
496
- const next = source[index + 1];
497
- let end;
498
- if (isQuote(char)) {
499
- end = skipQuoted(source, index);
500
- previousSignificant = "literal";
501
- } else if (char === "/" && next === "/") end = skipLineComment(source, index);
502
- else if (char === "/" && next === "*") end = skipBlockComment(source, index);
503
- else if (char === "/" && (isRegexLiteralStart(previousSignificant) || isControlFlowRegexStart(source, index))) {
504
- end = skipRegexLiteral(source, index);
505
- previousSignificant = "/";
506
- }
507
- if (end !== void 0) {
508
- mask(index, end);
509
- index = end;
510
- continue;
511
- }
512
- previousSignificant = trackSignificant(previousSignificant, char);
513
- index += 1;
514
- }
515
- return output.join("");
516
- }
517
- function isMethodDeclarationName(source, index, closeParen) {
518
- const previous = previousNonWhitespace(source, index);
519
- return source[skipWhitespaceAndComments(source, closeParen + 1)] === "{" && previous !== "(" && previous !== "=" && previous !== "," && previous !== ":";
520
- }
521
- function isMemberAccessName(source, index) {
522
- return previousNonWhitespace(source, index) === ".";
523
- }
524
- function findMatching(source, index, open, close, controlFlowRegexes = /* @__PURE__ */ new Map()) {
525
- let depth = 0;
526
- let previousSignificant = "";
527
- for (let current = index; current < source.length; current++) {
528
- const char = source[current];
529
- const next = source[current + 1];
530
- if (isQuote(char)) {
531
- current = skipQuoted(source, current, controlFlowRegexes) - 1;
532
- previousSignificant = "literal";
533
- continue;
534
- }
535
- if (char === "/" && next === "/") {
536
- current = skipLineComment(source, current) - 1;
537
- continue;
538
- }
539
- if (char === "/" && next === "*") {
540
- current = skipBlockComment(source, current) - 1;
541
- continue;
542
- }
543
- if (char === "/" && (isRegexLiteralStart(previousSignificant) || isControlFlowRegexStart(source, current, controlFlowRegexes))) {
544
- current = skipRegexLiteral(source, current) - 1;
545
- previousSignificant = "/";
546
- continue;
547
- }
548
- if (char === open) {
549
- depth += 1;
550
- previousSignificant = char;
551
- continue;
552
- }
553
- if (char === close && !(open === "<" && close === ">" && source[current - 1] === "=")) {
554
- depth -= 1;
555
- if (depth === 0) return current;
556
- previousSignificant = char;
557
- continue;
558
- }
559
- previousSignificant = trackSignificant(previousSignificant, char);
560
- }
561
- }
562
- function splitTopLevel(source, separator = ",") {
563
- const parts = [];
564
- let depth = 0;
565
- let previousSignificant = "";
566
- let start = 0;
567
- for (let index = 0; index < source.length; index++) {
568
- const char = source[index];
569
- const next = source[index + 1];
570
- if (isQuote(char)) {
571
- index = skipQuoted(source, index) - 1;
572
- previousSignificant = "literal";
573
- continue;
574
- }
575
- if (char === "/" && next === "/") {
576
- index = skipLineComment(source, index) - 1;
577
- continue;
578
- }
579
- if (char === "/" && next === "*") {
580
- index = skipBlockComment(source, index) - 1;
581
- continue;
582
- }
583
- if (char === "/" && (isRegexLiteralStart(previousSignificant) || isControlFlowRegexStart(source, index))) {
584
- index = skipRegexLiteral(source, index) - 1;
585
- previousSignificant = "/";
586
- continue;
587
- }
588
- if (char === "<") {
589
- const genericEnd = findMatching(source, index, "<", ">");
590
- if (genericEnd !== void 0 && nextNonWhitespace(source, genericEnd + 1) === "(") {
591
- index = genericEnd;
592
- previousSignificant = ">";
593
- continue;
594
- }
595
- }
596
- if (char === "(" || char === "{" || char === "[") {
597
- depth += 1;
598
- previousSignificant = char;
599
- continue;
600
- }
601
- if (char === ")" || char === "}" || char === "]") {
602
- depth -= 1;
603
- previousSignificant = char;
604
- continue;
605
- }
606
- if (char === separator && depth === 0) {
607
- parts.push(source.slice(start, index).trim());
608
- start = index + 1;
609
- continue;
610
- }
611
- previousSignificant = trackSignificant(previousSignificant, char);
612
- }
613
- parts.push(source.slice(start).trim());
614
- return parts;
615
- }
616
- function findIdentifierCalls(source, name) {
617
- const calls = [];
618
- let previousSignificant = "";
619
- for (let index = 0; index < source.length; index++) {
620
- const char = source[index];
621
- const next = source[index + 1];
622
- if (isQuote(char)) {
623
- index = skipQuoted(source, index) - 1;
624
- previousSignificant = "literal";
625
- continue;
626
- }
627
- if (char === "/" && next === "/") {
628
- index = skipLineComment(source, index) - 1;
629
- continue;
630
- }
631
- if (char === "/" && next === "*") {
632
- index = skipBlockComment(source, index) - 1;
633
- continue;
634
- }
635
- if (char === "/" && (isRegexLiteralStart(previousSignificant) || isControlFlowRegexStart(source, index))) {
636
- index = skipRegexLiteral(source, index) - 1;
637
- previousSignificant = "/";
638
- continue;
639
- }
640
- if (!source.startsWith(name, index) || isIdentifierChar(source[index - 1]) || isIdentifierChar(source[index + name.length]) || isFunctionDeclarationName(source, index) || isMemberAccessName(source, index)) {
641
- previousSignificant = trackSignificant(previousSignificant, char);
642
- continue;
643
- }
644
- let openParen = skipWhitespaceAndComments(source, index + name.length);
645
- if (source[openParen] === "<") {
646
- const genericEnd = findMatching(source, openParen, "<", ">");
647
- if (genericEnd === void 0) {
648
- previousSignificant = trackSignificant(previousSignificant, char);
649
- continue;
650
- }
651
- openParen = skipWhitespaceAndComments(source, genericEnd + 1);
652
- }
653
- if (source[openParen] !== "(") {
654
- previousSignificant = trackSignificant(previousSignificant, char);
655
- continue;
656
- }
657
- const closeParen = findMatching(source, openParen, "(", ")");
658
- if (closeParen === void 0) {
659
- previousSignificant = trackSignificant(previousSignificant, char);
660
- continue;
661
- }
662
- if (isMethodDeclarationName(source, index, closeParen)) {
663
- previousSignificant = trackSignificant(previousSignificant, char);
664
- continue;
665
- }
666
- calls.push({
667
- arguments: splitTopLevel(source.slice(openParen + 1, closeParen)),
668
- closeParen,
669
- name,
670
- openParen,
671
- start: index
672
- });
673
- previousSignificant = ")";
674
- index = closeParen;
675
- }
676
- return calls;
677
- }
678
- function findDefaultExportCall(source, names) {
679
- const masked = maskSourceLiterals(source);
680
- const calls = names.flatMap((name) => findIdentifierCalls(source, name)).sort((left, right) => left.start - right.start);
681
- for (const call of calls) {
682
- const callArgument = stripBoundaryComments(call.arguments[0] || "");
683
- if (!callArgument.startsWith("{")) continue;
684
- const objectEnd = findMatching(callArgument, 0, "{", "}");
685
- if (objectEnd === void 0) continue;
686
- const suffix = stripBoundaryComments(callArgument.slice(objectEnd + 1));
687
- if (suffix && !/^(?:as|satisfies)\b/.test(suffix)) continue;
688
- const argument = callArgument.slice(0, objectEnd + 1);
689
- if (/\bexport\s+default\s*(?:\(\s*)*$/.test(masked.slice(0, call.start))) return {
690
- ...call,
691
- argument
692
- };
693
- }
694
- }
695
- function readObjectProperty(objectSource, propertyName) {
696
- const normalized = stripBoundaryComments(objectSource);
697
- if (!normalized.startsWith("{") || !normalized.endsWith("}")) return;
698
- for (const property of splitTopLevel(normalized.slice(1, -1))) {
699
- const parts = splitTopLevel(property, ":");
700
- if (parts.length < 2) continue;
701
- if (stripBoundaryComments(parts.shift()).replace(/^["'`](.*)["'`]$/s, "$1") === propertyName) return stripBoundaryComments(parts.join(":"));
702
- }
703
- }
704
- //#endregion
705
- //#region src/discovery.ts
706
- const scheduleSuffixPattern = /\.schedule\.(?:c|m)?[jt]s$/i;
707
- function readScheduleDiscoveryMetadata(file) {
708
- const definition = findDefaultExportCall(readFileSync(file, "utf8"), ["defineSchedule", "defineScheduleTarget"]);
709
- if (!definition) return { allowRuntimeSchedules: false };
710
- if (definition.name === "defineScheduleTarget") return {
711
- allowRuntimeSchedules: true,
712
- runtimeOnly: true
713
- };
714
- return { allowRuntimeSchedules: readObjectProperty(definition.argument, "allowRuntimeSchedules") === "true" };
715
- }
716
- function createDiscoveredScheduleDefinition(source) {
717
- return (context) => {
718
- return {
719
- ...readScheduleDiscoveryMetadata(context.file),
720
- handler: context.file,
721
- name: context.name,
722
- source
723
- };
724
- };
725
- }
726
- function normalizeSuffixScheduleName(rootDir, file) {
727
- return normalizeSuffixDefinitionName(rootDir, file, scheduleSuffixPattern, { stripPrefix: "src/" });
728
- }
729
- function normalizeDirectoryScheduleName(directory, file) {
730
- return normalizePathDefinitionName(directory, file);
731
- }
732
- function discoverScheduleDefinitions(options) {
733
- if (options.mode === "server-schedules") return discoverDefinitions("schedule", [createDirectoryDefinitionSource("server-schedules", options.scanDirs, "schedules", {
734
- createDefinition: createDiscoveredScheduleDefinition("server-schedules"),
735
- normalizeName: normalizeDirectoryScheduleName
736
- })]);
737
- const roots = resolveDefinitionScanRoots(options.rootDir, options.scanDirs);
738
- const serverRoots = resolveDefinitionScanRoots(options.serverRootDir || options.rootDir, options.scanDirs);
739
- const serverScanDirs = options.serverDirs ?? serverRoots.map((root) => resolve(root, "server"));
740
- for (const directory of serverScanDirs) if (roots.every((root) => {
741
- const path = relative(resolve(root), resolve(directory));
742
- return path === ".." || path.startsWith(`..${sep}`) || isAbsolute(path);
743
- })) roots.push(directory);
744
- return mergeDefinitions("schedule", discoverDefinitions("schedule", [createSuffixDefinitionSource("vite-suffix", roots, scheduleSuffixPattern, normalizeSuffixScheduleName, { createDefinition: createDiscoveredScheduleDefinition("vite-suffix") })]).filter((definition) => !serverScanDirs.some((directory) => {
745
- const path = relative(resolve(directory, "schedules"), definition.handler);
746
- return path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
747
- })), discoverDefinitions("schedule", [createDirectoryDefinitionSource("server-schedules", serverScanDirs, "schedules", {
748
- createDefinition: createDiscoveredScheduleDefinition("server-schedules"),
749
- normalizeName: normalizeDirectoryScheduleName
750
- })]));
751
- }
752
- //#endregion
753
- export { readObjectProperty as a, writeRuntimeRegistryFile as c, dirname$1 as d, relative$1 as f, maskSourceLiterals as i, createImportPath as l, findDefaultExportCall as n, splitTopLevel as o, resolve$1 as p, findMatching as r, createRuntimeRegistryContents as s, discoverScheduleDefinitions as t, ensureGeneratedDir as u };