@vite-hub/schedule 0.4.1 → 0.5.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 (53) hide show
  1. package/README.md +12 -7
  2. package/dist/{console-wEhr0LWn.d.ts → console-DFI1QBkP.d.ts} +2 -4
  3. package/dist/cron-BT3ef48f.js +68 -0
  4. package/dist/definition.d.ts +2 -4
  5. package/dist/definition.js +4 -6
  6. package/dist/{due-sOJvF_6Z.js → due-D-0trD1g.js} +23 -9
  7. package/dist/durability.d.ts +3 -5
  8. package/dist/durability.js +6 -7
  9. package/dist/{error-diagnostics-BBtYYl8j.js → error-diagnostics-B1AaIGWP.js} +2 -7
  10. package/dist/{error-diagnostics-CQ4BUqRe.js → error-diagnostics-kKXseq8d.js} +10 -3
  11. package/dist/index.d.ts +3 -13
  12. package/dist/index.js +5 -8
  13. package/dist/{started-name-ruCM1EtQ.js → inspect-CW0qwt9p.js} +3 -9
  14. package/dist/{kv-storage-2kZtP2CC.js → kv-storage-Dsr3TL9c.js} +1 -2
  15. package/dist/{kv-storage-Bm9aYLfZ.d.ts → kv-storage-hI2IOjb5.d.ts} +0 -2
  16. package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
  17. package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CqZkx1Rm.d.ts} +8 -6
  18. package/dist/{operations-DqwmJ8MN.js → operations-BTUQeba1.js} +7 -11
  19. package/dist/operations.d.ts +2 -6
  20. package/dist/operations.js +11 -16
  21. package/dist/os.d.ts +0 -9
  22. package/dist/os.js +23 -104
  23. package/dist/out-By90R-Bo.js +22706 -0
  24. package/dist/rolldown-runtime-DegdyBIC.js +25 -0
  25. package/dist/runtime/console.d.ts +2 -4
  26. package/dist/runtime/console.js +3 -4
  27. package/dist/runtime/kv.d.ts +2 -4
  28. package/dist/runtime/kv.js +2 -3
  29. package/dist/runtime/process.d.ts +1 -3
  30. package/dist/runtime/process.js +28 -52
  31. package/dist/runtime/state.d.ts +1 -1
  32. package/dist/runtime/state.js +1 -2
  33. package/dist/runtime/static.d.ts +2 -73
  34. package/dist/runtime/static.js +3 -2
  35. package/dist/runtime.d.ts +5 -7
  36. package/dist/runtime.js +5 -5
  37. package/dist/{started-B0pc3JY0.js → started-B1Se_Iwo.js} +6 -8
  38. package/dist/{started-Bk2Icknk.js → started-Bzvr4t5f.js} +26 -9
  39. package/dist/{started-errors-DEmYH-vp.js → started-errors-IG9DlT2A.js} +49 -12
  40. package/dist/started-name-w6n9uDdt.js +4 -0
  41. package/dist/{state-CPd10SXq.d.ts → state-BDEDVlyr.d.ts} +3 -6
  42. package/dist/{state-D4SZH6zk.js → state-BZLy46UJ.js} +73 -122
  43. package/dist/static-Bg7Jj92L.js +603 -0
  44. package/dist/static-DeRvJqcQ.d.ts +92 -0
  45. package/dist/{store-DeMojnXM.d.ts → store-CEv3cScg.d.ts} +4 -12
  46. package/dist/{time-zone-SBldrUgt.js → time-zone-pMp_g8Uu.js} +1 -2
  47. package/dist/{types-Cw5LjPuc.d.ts → types-DTVPVY5O.d.ts} +0 -2
  48. package/dist/vite.d.ts +6 -20
  49. package/dist/vite.js +2943 -297
  50. package/package.json +9 -9
  51. package/dist/invariant-DolT9EEx.js +0 -22
  52. package/dist/static-7JCga3Iu.js +0 -281
  53. package/dist/wait-until-Dy4Bn3ZN.js +0 -112
@@ -1,9 +1,10 @@
1
- import { t as scheduleErrorDiagnostics } from "./error-diagnostics-BBtYYl8j.js";
2
- import { c as runScheduleFrom, o as loadStaticScheduleDefinition } from "./started-errors-DEmYH-vp.js";
3
- import { i as getScheduleRunStore, n as getProcessScheduleDefinitions, o as getStartedScheduleRuntime, t as getHostScheduleInventory } from "./state-D4SZH6zk.js";
4
- import { i as startSchedule, r as listSchedules, t as cancelSchedule } from "./started-B0pc3JY0.js";
5
- import { n as redactInspectionText } from "./started-name-ruCM1EtQ.js";
6
- //#region src/runtime/operations.ts
1
+ import { t as redactInspectionText } from "./inspect-CW0qwt9p.js";
2
+ import { t as scheduleErrorDiagnostics } from "./error-diagnostics-B1AaIGWP.js";
3
+ import { c as runScheduleFrom, o as loadStaticScheduleDefinition } from "./started-errors-IG9DlT2A.js";
4
+ import "./started-name-w6n9uDdt.js";
5
+ import { i as getScheduleRunStore, n as getProcessScheduleDefinitions, o as getStartedScheduleRuntime, t as getHostScheduleInventory } from "./state-BZLy46UJ.js";
6
+ import { i as startSchedule, r as listSchedules, t as cancelSchedule } from "./started-B1Se_Iwo.js";
7
+ // src/runtime/operations.ts
7
8
  function isoDate(value) {
8
9
  if (value === void 0) return;
9
10
  const date = value instanceof Date ? value : new Date(value);
@@ -77,7 +78,6 @@ async function listScheduleRuns(scheduleId, options = {}) {
77
78
  async function listScheduleRunAttempts(runId) {
78
79
  return [...await getScheduleRunStore().listAttempts(runId)].sort((left, right) => new Date(left.startedAt).getTime() - new Date(right.startedAt).getTime()).map(summarizeScheduleRunAttempt);
79
80
  }
80
- /** Gives an operation error its HTTP status and the redacted message that the CLI and the Console report. */
81
81
  function withStatus(error, status, fix) {
82
82
  return Object.defineProperties(error, {
83
83
  ...fix && !Reflect.get(error, "fix") ? { fix: {
@@ -103,13 +103,11 @@ function withStatus(error, status, fix) {
103
103
  const errorFix = { SCHEDULE_INVALID_SCHEDULED_AT: "Pass `at` as an ISO 8601 date-time with a time zone, such as 2026-01-31T23:59:00Z or 2026-01-31T23:59:00+01:00." };
104
104
  const errorStatus = {
105
105
  SCHEDULE_DEFINITION_NOT_FOUND: 404,
106
- SCHEDULE_HISTORY_INCOMPLETE: 503,
107
106
  SCHEDULE_INVALID_SCHEDULED_AT: 400,
108
107
  SCHEDULE_MANUAL_RUN_DISABLED: 403,
109
108
  SCHEDULE_OPERATION_FAILED: 500,
110
109
  SCHEDULE_RUN_NOT_FOUND: 404
111
110
  };
112
- /** Gives a Schedule error the status and the redacted message that every surface reports. */
113
111
  async function attempt(work) {
114
112
  try {
115
113
  return await work();
@@ -133,7 +131,6 @@ async function runScheduleAttempts(input) {
133
131
  };
134
132
  });
135
133
  }
136
- /** The manual Static Schedule Definitions that the Console installed. Only `console.invoke` installs them. */
137
134
  const consoleSchedulesKey = Symbol.for("vitehub.console.schedules");
138
135
  /**
139
136
  * Runs a Static Schedule Definition that sets `manual: true`, as if its cron fired at `at` (default: now). The registry holds only those definitions, and it is empty
@@ -203,5 +200,4 @@ async function runScheduleCancel(input) {
203
200
  if (error) throw operationError(error);
204
201
  return { schedule: summarizeStartedSchedule(schedule) };
205
202
  }
206
- //#endregion
207
203
  export { listScheduleRunAttempts, listScheduleRuns, runScheduleAttempts, runScheduleCancel, runScheduleList, runScheduleNow, runScheduleRuns, runScheduleStart, summarizeScheduleRun, summarizeScheduleRunAttempt };
@@ -1,6 +1,5 @@
1
- import { h as ScheduleRunStatus, l as ScheduleRunAttemptStatus } from "./types-Cw5LjPuc.js";
2
- import { t as AnyOperation } from "./operation-definition-nmRu_O3V.js";
3
- //#region src/runtime/operations.d.ts
1
+ import { t as AnyOperation } from "./operation-definition-CqZkx1Rm.js";
2
+ import { h as ScheduleRunStatus, l as ScheduleRunAttemptStatus } from "./types-DTVPVY5O.js";
4
3
  /** Error of a run or attempt. The stack is not included. */
5
4
  interface ScheduleRunErrorSummary {
6
5
  message: string;
@@ -82,12 +81,9 @@ interface ScheduleListResult {
82
81
  interface StartedScheduleResult {
83
82
  schedule: StartedScheduleSummary;
84
83
  }
85
- //#endregion
86
- //#region src/operations.d.ts
87
84
  /**
88
85
  * The `schedule.*` operations: runs, attempts, run, list, start, and cancel. The Console, `vitehub schedule`, and agents
89
86
  * run them.
90
87
  */
91
88
  export declare const scheduleOperations: readonly AnyOperation[];
92
- //#endregion
93
89
  export type { ScheduleAttemptsResult, ScheduleListResult, ScheduleRunResult, ScheduleRunsResult, StartedScheduleResult };
@@ -1,8 +1,8 @@
1
- import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
2
- import { t as internalErrorDiagnostics } from "./error-diagnostics-CQ4BUqRe.js";
1
+ import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
2
+ import { t as internalErrorDiagnostics } from "./error-diagnostics-kKXseq8d.js";
3
3
  import { toJsonSchema } from "@valibot/to-json-schema";
4
4
  import * as v from "valibot";
5
- //#region ../internal/src/standard-schema.ts
5
+ // ../internal/src/standard-schema.ts
6
6
  function readOwn(value, key) {
7
7
  if (value === null || Object(value) !== value) return;
8
8
  try {
@@ -31,8 +31,7 @@ function standardJsonSchema(schema, direction, target = "draft-2020-12", library
31
31
  return;
32
32
  }
33
33
  }
34
- //#endregion
35
- //#region ../internal/src/valibot.ts
34
+ // ../internal/src/valibot.ts
36
35
  const valibotTargets = /* @__PURE__ */ new Set([
37
36
  "draft-07",
38
37
  "draft-2020-12",
@@ -73,8 +72,7 @@ function withValibotJsonSchema(schema, options = {}) {
73
72
  }
74
73
  };
75
74
  }
76
- //#endregion
77
- //#region ../internal/src/operation-definition.ts
75
+ // ../internal/src/operation-definition.ts
78
76
  const nameFormat = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/;
79
77
  const kinds = /* @__PURE__ */ new Set([
80
78
  "read",
@@ -134,16 +132,14 @@ function isSectionId(section) {
134
132
  function operationInputJsonSchema(operation) {
135
133
  return standardJsonSchema(operation.input, "input") ?? { type: "object" };
136
134
  }
137
- //#endregion
138
- //#region ../internal/src/operations.ts
135
+ // ../internal/src/operations.ts
139
136
  /** Align rows of text cells in columns for CLI output. The last column is not padded. */
140
137
  function table(rows) {
141
138
  const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
142
139
  return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" ")).join("\n");
143
140
  }
144
- //#endregion
145
- //#region src/operations.ts
146
- const runtime = () => import("./operations-DqwmJ8MN.js");
141
+ // src/operations.ts
142
+ const runtime = () => import("./operations-BTUQeba1.js");
147
143
  const id = v.pipe(v.string(), v.minLength(1));
148
144
  function formatRuns({ runs }) {
149
145
  if (runs.length === 0) return "No runs.\n";
@@ -194,7 +190,7 @@ function defineScheduleOperation(definition) {
194
190
  }
195
191
  const runs = defineScheduleOperation({
196
192
  cli: {
197
- command: "runs",
193
+ command: "runs list",
198
194
  format: formatRuns,
199
195
  namespace: "schedule",
200
196
  positional: ["id"]
@@ -210,12 +206,12 @@ const runs = defineScheduleOperation({
210
206
  });
211
207
  const attempts = defineScheduleOperation({
212
208
  cli: {
213
- command: "attempts",
209
+ command: "runs get",
214
210
  format: formatAttempts,
215
211
  namespace: "schedule",
216
212
  positional: ["id"]
217
213
  },
218
- description: "List the attempts of one Schedule Run, oldest first.",
214
+ description: "Show one Schedule Run with its attempts, oldest first.",
219
215
  input: v.object({ id }),
220
216
  kind: "read",
221
217
  name: "schedule.attempts",
@@ -317,5 +313,4 @@ const scheduleOperations = [
317
313
  run: async (input) => await (await runtime()).runScheduleCancel(input)
318
314
  })
319
315
  ];
320
- //#endregion
321
316
  export { scheduleOperations };
package/dist/os.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ErrorCatalog, Result } from "@vite-hub/runtime";
2
2
  import { posix } from "node:path";
3
- //#region src/os/errors.d.ts
4
3
  /** Operating systems that `@vite-hub/schedule/os` installs timers on, as `process.platform` names them. */
5
4
  type OsSchedulePlatform = "linux" | "darwin" | "win32";
6
5
  /** `"user"` runs as the current user. `"system"` runs as root or SYSTEM and needs root or Administrator to install. */
@@ -40,7 +39,6 @@ type TimeZoneUnsupported = {
40
39
  timeZone: string;
41
40
  machineTimeZone: string;
42
41
  };
43
- /** A code whose `error.data` holds the values of its message. */
44
42
  type Code<TData> = {
45
43
  fix: string;
46
44
  why: (data: TData) => string;
@@ -58,8 +56,6 @@ type OsScheduleErrorCodes = {
58
56
  };
59
57
  export declare const osScheduleErrors: ErrorCatalog<OsScheduleErrorCodes>;
60
58
  type OsScheduleErrorCode = keyof OsScheduleErrorCodes;
61
- //#endregion
62
- //#region src/os/host.d.ts
63
59
  interface OsScheduleStatus {
64
60
  name: string;
65
61
  platform: OsSchedulePlatform;
@@ -94,8 +90,6 @@ interface OsScheduleRemoval {
94
90
  */
95
91
  existed: boolean;
96
92
  }
97
- //#endregion
98
- //#region src/os/schedules.d.ts
99
93
  /** Any object with `cron` and an optional `timeZone`. The result of `defineSchedule()` fits. */
100
94
  interface OsScheduleTiming {
101
95
  cron?: string;
@@ -147,8 +141,6 @@ interface OsScheduleUnit {
147
141
  status(): Promise<Result<OsScheduleStatus, OsScheduleErrorCode>>;
148
142
  uninstall(): Promise<Result<OsScheduleRemoval, OsScheduleErrorCode>>;
149
143
  }
150
- //#endregion
151
- //#region src/os.d.ts
152
144
  /**
153
145
  * Installs `schedule` as an OS timer named `name` that runs `options.command`: a systemd timer on Linux, a launchd job
154
146
  * on macOS, or a Task Scheduler task on Windows. It runs on the Schedule's `cron` in its `timeZone`, or fails with a
@@ -163,5 +155,4 @@ export declare function osScheduleStatus(name: string, target?: OsScheduleTarget
163
155
  * A timer of the same name that ViteHub did not install in this scope stays as it is, and `existed` is `false`.
164
156
  */
165
157
  export declare function uninstallOsSchedule(name: string, target?: OsScheduleTarget): Promise<Result<OsScheduleRemoval, OsScheduleErrorCode>>;
166
- //#endregion
167
158
  export type { InstallOsScheduleOptions, OsScheduleErrorCode, OsSchedulePlatform, OsScheduleRemoval, OsScheduleScope, OsScheduleStatus, OsScheduleTarget, OsScheduleTiming, OsScheduleUnit };
package/dist/os.js CHANGED
@@ -1,15 +1,14 @@
1
- import { t as isIanaTimeZone } from "./time-zone-SBldrUgt.js";
2
- import { t as isRecord } from "./object-Da1zyPCR.js";
3
- import { n as invariantError } from "./invariant-DolT9EEx.js";
4
- import { r as timeZoneOffsetMinutes } from "./due-sOJvF_6Z.js";
1
+ import { t as isRecord } from "./object-CAK6UYR5.js";
2
+ import { t as isIanaTimeZone } from "./time-zone-pMp_g8Uu.js";
3
+ import { a as parseCronFields, c as timesOfDay, i as isWeekdayRestricted, n as isDayRestricted, o as range, r as isMonthRestricted, s as runsEveryDay, t as arithmeticStep, u as invariantError } from "./cron-BT3ef48f.js";
4
+ import { i as timeZoneOffsetMinutes } from "./due-D-0trD1g.js";
5
5
  import { defineErrors } from "@vite-hub/runtime";
6
- import { parseCronExpression } from "cron-schedule";
7
6
  import { homedir, userInfo } from "node:os";
8
7
  import { basename, dirname, join, posix, win32 } from "node:path";
9
8
  import { mkdir, readFile, realpath, rm, rmdir, writeFile } from "node:fs/promises";
10
9
  import { execFile } from "node:child_process";
11
10
  import { createHash } from "node:crypto";
12
- //#region src/os/host.ts
11
+ // src/os/host.ts
13
12
  const generatedHeader = "Generated by ViteHub (@vite-hub/schedule/os). installOsSchedule() replaces this file.";
14
13
  /** Path helpers of the target OS, so a fake Windows host gives Windows paths on Linux. */
15
14
  function pathsFor(platform) {
@@ -112,55 +111,7 @@ function createNodeHost() {
112
111
  }
113
112
  };
114
113
  }
115
- //#endregion
116
- //#region src/os/cron.ts
117
- const allMonths = range(1, 12);
118
- const allWeekdays = range(0, 6);
119
- function range(first, last) {
120
- return Array.from({ length: last - first + 1 }, (_, index) => first + index);
121
- }
122
- /** Reads a five-field cron. Returns `undefined` for anything else. */
123
- function parseCronFields(cron) {
124
- if (cron.trim() !== cron || cron.split(/\s+/).length !== 5) return void 0;
125
- try {
126
- const parsed = parseCronExpression(cron);
127
- const sorted = (values) => [...new Set(values)].sort((left, right) => left - right);
128
- return {
129
- minutes: sorted(parsed.minutes),
130
- hours: sorted(parsed.hours),
131
- days: sorted(parsed.days),
132
- months: sorted(parsed.months.map((month) => month + 1)),
133
- weekdays: sorted(parsed.weekdays.map((weekday) => weekday % 7))
134
- };
135
- } catch {
136
- return;
137
- }
138
- }
139
- function isDayRestricted(fields) {
140
- return fields.days.length !== 31;
141
- }
142
- function isWeekdayRestricted(fields) {
143
- return fields.weekdays.length !== allWeekdays.length;
144
- }
145
- function isMonthRestricted(fields) {
146
- return fields.months.length !== allMonths.length;
147
- }
148
- /** True when every day field holds every value, so the cron runs on every day. */
149
- function runsEveryDay(fields) {
150
- return !isDayRestricted(fields) && !isWeekdayRestricted(fields) && !isMonthRestricted(fields);
151
- }
152
- /** Minutes of the day when the cron runs, sorted. */
153
- function timesOfDay(fields) {
154
- return fields.hours.flatMap((hour) => fields.minutes.map((minute) => hour * 60 + minute));
155
- }
156
- /** The step of a sorted list of two or more values with equal gaps, else `undefined`. One value has step 0. */
157
- function arithmeticStep(values) {
158
- if (values.length < 2) return 0;
159
- const step = values[1] - values[0];
160
- return values.every((value, index) => index === 0 || value - values[index - 1] === step) ? step : void 0;
161
- }
162
- //#endregion
163
- //#region src/os/errors.ts
114
+ // src/os/errors.ts
164
115
  const platformNames = {
165
116
  darwin: "launchd",
166
117
  linux: "systemd",
@@ -211,8 +162,7 @@ const osScheduleErrors = /*#__PURE__*/ defineErrors({
211
162
  }
212
163
  }
213
164
  });
214
- //#endregion
215
- //#region src/os/time-zone.ts
165
+ // src/os/time-zone.ts
216
166
  const minuteMs = 6e4;
217
167
  const dayMs$1 = 1440 * minuteMs;
218
168
  const dayMinutes = 1440;
@@ -220,7 +170,6 @@ const sampledDays = 732;
220
170
  function modulo(value, size) {
221
171
  return (value % size + size) % size;
222
172
  }
223
- /** The minutes, from `from` to `to`, where the offset of `timeZone` changes. It assumes at most one change a day. */
224
173
  function offsetChanges(timeZone, from, to) {
225
174
  const offset = (time) => timeZoneOffsetMinutes(new Date(time), timeZone);
226
175
  const changes = [];
@@ -268,7 +217,6 @@ function clockChanges(timeZone, from) {
268
217
  }
269
218
  return changes;
270
219
  }
271
- /** Every value of `offset(timeZone) - offset(machineTimeZone)`, in minutes, in the two years from `from`. */
272
220
  function offsetDifferences(timeZone, machineTimeZone, from) {
273
221
  const start = Math.floor(from.getTime() / minuteMs) * minuteMs;
274
222
  const end = start + sampledDays * dayMs$1;
@@ -279,7 +227,6 @@ function offsetDifferences(timeZone, machineTimeZone, from) {
279
227
  ];
280
228
  return [...new Set(instants.map((time) => timeZoneOffsetMinutes(new Date(time), timeZone) - timeZoneOffsetMinutes(new Date(time), machineTimeZone)))].sort((left, right) => left - right);
281
229
  }
282
- /** Hours and minutes whose product is exactly `times` (minutes of the day), else `undefined`. */
283
230
  function asProduct(times) {
284
231
  const unique = new Set(times);
285
232
  const hours = [...new Set([...unique].map((time) => Math.floor(time / 60)))].sort((left, right) => left - right);
@@ -289,7 +236,6 @@ function asProduct(times) {
289
236
  minutes
290
237
  } : void 0;
291
238
  }
292
- /** The cron moved by a constant `difference`: the machine time is the Schedule time minus `difference` minutes. */
293
239
  function shiftFields(fields, difference) {
294
240
  const shifted = timesOfDay(fields).map((time) => time - difference);
295
241
  const product = asProduct(shifted.map((time) => modulo(time, dayMinutes)));
@@ -337,8 +283,7 @@ function machineFieldsOrError(platform, spec, host) {
337
283
  machineTimeZone: host.machineTimeZone
338
284
  }), void 0];
339
285
  }
340
- //#endregion
341
- //#region src/os/launchd.ts
286
+ // src/os/launchd.ts
342
287
  const intervalKeys = /* @__PURE__ */ new Set([
343
288
  "Minute",
344
289
  "Hour",
@@ -441,7 +386,6 @@ function parseLaunchdPlist(plist) {
441
386
  ...logFile === void 0 ? {} : { logFile: unxml(logFile) }
442
387
  };
443
388
  }
444
- /** Reads `launchctl print` output: the `state` and `last exit code` lines of the service, one tab deep. */
445
389
  function parseLaunchctlPrint(output) {
446
390
  const state = output.match(/^\tstate = (.+)$/m)?.[1]?.trim();
447
391
  const lastExit = output.match(/^\tlast exit code = (-?\d+)/m)?.[1];
@@ -451,7 +395,6 @@ function parseLaunchctlPrint(output) {
451
395
  };
452
396
  }
453
397
  const dayMs = 864e5;
454
- /** UTC instant of a wall-clock time in `timeZone`. A time in a daylight saving gap moves forward by the gap. */
455
398
  function zonedInstant(year, month, day, minuteOfDay, timeZone) {
456
399
  const local = Date.UTC(year, month - 1, day, 0, minuteOfDay);
457
400
  const guess = local - timeZoneOffsetMinutes(new Date(local), timeZone) * 6e4;
@@ -495,7 +438,6 @@ function createLaunchdDriver(host, scope) {
495
438
  output: commandOutput(result)
496
439
  }), void 0];
497
440
  }
498
- /** The domain that has the job loaded, and its `launchctl print` output. */
499
441
  async function loaded(name) {
500
442
  for (const domain of domains) {
501
443
  const result = await host.exec("launchctl", ["print", `${domain}/${name}`]);
@@ -505,10 +447,6 @@ function createLaunchdDriver(host, scope) {
505
447
  };
506
448
  }
507
449
  }
508
- /**
509
- * The plist and the loaded job of `name`, and the resource that holds the name when ViteHub did not install it: a
510
- * plist at our path without our header, or a job with this label that launchd loaded from another plist.
511
- */
512
450
  async function owner(name) {
513
451
  const path = plistPath(name);
514
452
  const plist = await host.fs.readFile(path);
@@ -649,8 +587,7 @@ function createLaunchdDriver(host, scope) {
649
587
  }
650
588
  };
651
589
  }
652
- //#endregion
653
- //#region ../internal/src/systemd.ts
590
+ // ../internal/src/systemd.ts
654
591
  /** systemd expands `%` specifiers in every value, and a line break ends the setting. */
655
592
  function systemdValue(value, lineBreak) {
656
593
  if (/[\n\r]/.test(value)) lineBreak();
@@ -665,8 +602,7 @@ function systemdExecArgument(value, lineBreak) {
665
602
  function systemdAssignment(name, value, lineBreak) {
666
603
  return `"${systemdValue(`${name}=${value}`, lineBreak).replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}"`;
667
604
  }
668
- //#endregion
669
- //#region src/os/systemd.ts
605
+ // src/os/systemd.ts
670
606
  const weekdayNames$1 = [
671
607
  "Sun",
672
608
  "Mon",
@@ -683,7 +619,6 @@ function lineBreak() {
683
619
  function pad$1(value) {
684
620
  return String(value).padStart(2, "0");
685
621
  }
686
- /** `1..5`, `0,15,30,45`, or `*` when the list holds every value. Runs of three or more become ranges. */
687
622
  function calendarList(values, size, format = pad$1) {
688
623
  if (values.length === size) return "*";
689
624
  const parts = [];
@@ -746,7 +681,6 @@ function renderSystemdTimer(spec) {
746
681
  ""
747
682
  ].join("\n");
748
683
  }
749
- /** Reads `systemctl show` output: blocks of `Key=value` lines, one block per unit, keyed by `Id`. */
750
684
  function parseSystemctlShow(output) {
751
685
  const units = /* @__PURE__ */ new Map();
752
686
  for (const block of output.split(/\n\s*\n/)) {
@@ -760,7 +694,6 @@ function parseSystemctlShow(output) {
760
694
  }
761
695
  return units;
762
696
  }
763
- /** `@1794841368` (`--timestamp=unix`) as a Date. Empty or `0` means never. */
764
697
  function unixTimestamp(value) {
765
698
  const seconds = Number(value?.replace(/^@/, ""));
766
699
  return value && Number.isFinite(seconds) && seconds > 0 ? /* @__PURE__ */ new Date(seconds * 1e3) : void 0;
@@ -781,10 +714,6 @@ const statusProperties = [
781
714
  ];
782
715
  const exitedCode = "1";
783
716
  const marker = `# ${generatedHeader}`;
784
- /**
785
- * The unit or file that holds `name` when ViteHub did not install it: a file at our path without our header, or a
786
- * loaded unit that systemd reads from another file, such as /usr/lib/systemd/user/<name>.service or a transient unit.
787
- */
788
717
  async function foreignResource(host, paths, texts, units, name) {
789
718
  for (const kind of ["service", "timer"]) {
790
719
  const text = texts[kind];
@@ -865,7 +794,6 @@ function createSystemdDriver(host, scope) {
865
794
  ...timer === void 0 ? {} : { timer }
866
795
  };
867
796
  }
868
- /** The resource that holds `name` when ViteHub did not install it in this scope. */
869
797
  async function foreign(name, files, texts) {
870
798
  const fileOwner = await foreignResource(host, files, texts, /* @__PURE__ */ new Map(), name);
871
799
  if (fileOwner) return [void 0, fileOwner];
@@ -1012,8 +940,7 @@ function createSystemdDriver(host, scope) {
1012
940
  }
1013
941
  };
1014
942
  }
1015
- //#endregion
1016
- //#region src/os/task-scheduler.ts
943
+ // src/os/task-scheduler.ts
1017
944
  const maxTriggers = 48;
1018
945
  const weekdayNames = [
1019
946
  "Sunday",
@@ -1041,14 +968,12 @@ const monthNames = [
1041
968
  const taskNeverRan = 267011;
1042
969
  const taskRunning = 267009;
1043
970
  const { join: join$1 } = pathsFor("win32");
1044
- /** An XML duration, such as `PT23H52M30S`. */
1045
971
  function taskDuration(seconds) {
1046
972
  const hours = Math.floor(seconds / 3600);
1047
973
  const minutes = Math.floor(seconds % 3600 / 60);
1048
974
  const rest = seconds % 60;
1049
975
  return `PT${hours ? `${hours}H` : ""}${minutes ? `${minutes}M` : ""}${rest || !seconds ? `${rest}S` : ""}`;
1050
976
  }
1051
- /** One trigger for the runs. The duration ends half a step after the last run. */
1052
977
  function trigger({ start, step, count }) {
1053
978
  if (count < 2) return { start };
1054
979
  return {
@@ -1059,15 +984,10 @@ function trigger({ start, step, count }) {
1059
984
  }
1060
985
  };
1061
986
  }
1062
- /**
1063
- * Task Scheduler repeats a trigger in elapsed time. When the clocks change between the first and the last run, the
1064
- * later runs move by the change, and the duration ends at another time of day. Such runs need one trigger per time.
1065
- */
1066
987
  function crossesChange(runs, changes) {
1067
988
  const last = runs.start + (runs.count - 1) * runs.step;
1068
989
  return runs.count > 1 && changes.some((change) => runs.start < change.end && last >= change.start);
1069
990
  }
1070
- /** The fewest triggers that start at every time of the day of the cron, and keep their times across `changes`. */
1071
991
  function timeTriggers(fields, changes) {
1072
992
  const times = timesOfDay(fields);
1073
993
  const single = (start) => ({
@@ -1156,7 +1076,6 @@ function taskTriggers(fields, clock = {
1156
1076
  function xml(value) {
1157
1077
  return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;");
1158
1078
  }
1159
- /** A PowerShell single-quoted string. PowerShell also reads the typographic single quotes as quotes. */
1160
1079
  function powerShellString(value) {
1161
1080
  return `'${value.replace(/['\u2018\u2019\u201A\u201B]/g, "$&$&")}'`;
1162
1081
  }
@@ -1208,6 +1127,15 @@ function renderTaskWrapper(spec, logFile) {
1208
1127
  function parseTaskWrapperLog(wrapper) {
1209
1128
  return wrapper.match(/^\$log = '((?:[^']|'')*)'\r?$/m)?.[1]?.replaceAll("''", "'");
1210
1129
  }
1130
+ /**
1131
+ * The base64 PowerShell command that runs the wrapper and exits with its exit code. Task Scheduler expands `%NAME%` in
1132
+ * the arguments of a task and has no escape for `%`, so a wrapper path in the arguments breaks under a folder such as
1133
+ * `C:\Users\pct %PATH%`. Base64 has no `%`.
1134
+ */
1135
+ function runWrapperCommand(wrapper) {
1136
+ const script = `$global:LASTEXITCODE = 1\n& ${powerShellString(wrapper)}\nexit $global:LASTEXITCODE`;
1137
+ return Buffer.from(script, "utf16le").toString("base64");
1138
+ }
1211
1139
  /** The task XML. The description ends with a hash of the XML and the wrapper, which a later install compares. */
1212
1140
  function renderTaskXml(spec, triggers, options) {
1213
1141
  const render = (description) => [
@@ -1255,7 +1183,7 @@ function renderTaskXml(spec, triggers, options) {
1255
1183
  " <Actions Context=\"Author\">",
1256
1184
  " <Exec>",
1257
1185
  " <Command>powershell.exe</Command>",
1258
- ` <Arguments>${xml(`-NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File "${options.wrapper}"`)}</Arguments>`,
1186
+ ` <Arguments>${xml(`-NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -EncodedCommand ${runWrapperCommand(options.wrapper)}`)}</Arguments>`,
1259
1187
  " </Exec>",
1260
1188
  " </Actions>",
1261
1189
  "</Task>",
@@ -1273,16 +1201,11 @@ function taskOwnerScope(description) {
1273
1201
  function taskDescriptionHash(description) {
1274
1202
  return description?.match(/sha256:([0-9a-f]{64})/)?.[1];
1275
1203
  }
1276
- /**
1277
- * Windows PowerShell 5.1 joins native arguments without escaping them, so a quote, an empty argument, or a trailing
1278
- * backslash in an argument with spaces reaches the program changed.
1279
- */
1280
1204
  function unsafeWindowsArgument(argument) {
1281
1205
  if (argument === "") return "an empty argument";
1282
1206
  if (argument.includes("\"")) return "an argument with a double quote";
1283
1207
  if (/\s/.test(argument) && argument.endsWith("\\")) return "an argument with spaces that ends with a backslash";
1284
1208
  }
1285
- /** Reads the JSON of the status script. */
1286
1209
  function parseTaskInfo(output) {
1287
1210
  const value = JSON.parse(output.trim() || "{}");
1288
1211
  if (typeof value !== "object" || value === null || !("installed" in value)) return { installed: false };
@@ -1304,7 +1227,6 @@ function taskInfoScript(name) {
1304
1227
  }
1305
1228
  /** Task Scheduler tasks in the root folder, run as the current user or as SYSTEM. */
1306
1229
  function createTaskSchedulerDriver(host, scope) {
1307
- /** A task of this name that ViteHub did not install in this scope. */
1308
1230
  const foreign = (task) => task.installed && taskOwnerScope(task.description) !== scope;
1309
1231
  const taskResource = (name, task) => {
1310
1232
  const owner = taskOwnerScope(task.description);
@@ -1471,8 +1393,7 @@ function createTaskSchedulerDriver(host, scope) {
1471
1393
  }
1472
1394
  };
1473
1395
  }
1474
- //#endregion
1475
- //#region src/os/schedules.ts
1396
+ // src/os/schedules.ts
1476
1397
  const optionKeys = /* @__PURE__ */ new Set([
1477
1398
  "catchUp",
1478
1399
  "command",
@@ -1628,8 +1549,7 @@ function createOsSchedules(host) {
1628
1549
  uninstallOsSchedule
1629
1550
  };
1630
1551
  }
1631
- //#endregion
1632
- //#region src/os.ts
1552
+ // src/os.ts
1633
1553
  let schedules;
1634
1554
  function nodeSchedules() {
1635
1555
  schedules ??= createOsSchedules(createNodeHost());
@@ -1655,5 +1575,4 @@ function osScheduleStatus(name, target) {
1655
1575
  function uninstallOsSchedule(name, target) {
1656
1576
  return nodeSchedules().uninstallOsSchedule(name, target);
1657
1577
  }
1658
- //#endregion
1659
1578
  export { installOsSchedule, osScheduleErrors, osScheduleStatus, uninstallOsSchedule };