@vite-hub/schedule 0.3.1 → 0.5.0
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 +24 -19
- package/dist/{console-wEhr0LWn.d.ts → console-DueeEBcM.d.ts} +2 -0
- package/dist/cron-C1l3TquN.js +70 -0
- package/dist/definition.js +1 -2
- package/dist/{due-BVMRQ93v.js → due-n120-_nz.js} +22 -7
- package/dist/durability.d.ts +2 -2
- package/dist/durability.js +5 -5
- package/dist/{error-diagnostics-DSkCJC_L.js → error-diagnostics-C0KyI408.js} +10 -2
- package/dist/{error-diagnostics-Mpeks7J0.js → error-diagnostics-DTmP6baC.js} +5 -5
- package/dist/index.d.ts +19 -5
- package/dist/index.js +34 -6
- package/dist/{kv-storage-iJChCS5A.js → kv-storage-2kZtP2CC.js} +2 -2
- package/dist/{kv-storage-C0KZZB6v.d.ts → kv-storage-Bm9aYLfZ.d.ts} +5 -1
- package/dist/{operation-definition-8gOe-ubD.d.ts → operation-definition-CI2PJGqu.d.ts} +13 -2
- package/dist/{operations-DwZWFIUX.js → operations-DlrK9mlH.js} +29 -9
- package/dist/operations.d.ts +10 -1
- package/dist/operations.js +13 -10
- package/dist/os.d.ts +0 -1
- package/dist/os.js +12 -84
- package/dist/out-BbXG-yVX.js +21755 -0
- package/dist/rolldown-runtime-CMFfr-1z.js +26 -0
- package/dist/runtime/console.d.ts +1 -1
- package/dist/runtime/console.js +2 -2
- package/dist/runtime/kv.d.ts +1 -1
- package/dist/runtime/kv.js +1 -1
- package/dist/runtime/process.js +24 -45
- package/dist/runtime/state.d.ts +2 -2
- package/dist/runtime/state.js +2 -2
- package/dist/runtime/static.d.ts +2 -73
- package/dist/runtime/static.js +3 -2
- package/dist/runtime.d.ts +4 -4
- package/dist/runtime.js +5 -5
- package/dist/{started-Bx7MDbrl.js → started-BWWr7Ufw.js} +3 -4
- package/dist/{started-BuGmnus4.js → started-BXdWMdji.js} +24 -6
- package/dist/{started-errors-p7cu_rI7.js → started-errors-BMg04lL3.js} +73 -26
- package/dist/started-name-DudQ0fsR.js +5 -0
- package/dist/{state-B-Fuyfb4.js → state-BjWnxyhv.js} +79 -118
- package/dist/{state-Do2wV4Tx.d.ts → state-CJKAhskJ.d.ts} +12 -2
- package/dist/static-BgoOCoe5.js +610 -0
- package/dist/static-CcBWx1kU.d.ts +96 -0
- package/dist/{store-Df0-fzCl.d.ts → store-CZHZfttA.d.ts} +3 -7
- package/dist/vite.d.ts +5 -3
- package/dist/vite.js +2963 -590
- package/package.json +6 -6
- package/dist/invariant-DolT9EEx.js +0 -22
- package/dist/static-DQwzzvPg.js +0 -266
- package/dist/wait-until-Dy4Bn3ZN.js +0 -112
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { t as scheduleErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { i as
|
|
1
|
+
import { t as scheduleErrorDiagnostics } from "./error-diagnostics-DTmP6baC.js";
|
|
2
|
+
import { c as runScheduleFrom, o as loadStaticScheduleDefinition } from "./started-errors-BMg04lL3.js";
|
|
3
|
+
import "./started-name-DudQ0fsR.js";
|
|
4
|
+
import { i as getScheduleRunStore, n as getProcessScheduleDefinitions, o as getStartedScheduleRuntime, t as getHostScheduleInventory } from "./state-BjWnxyhv.js";
|
|
5
|
+
import { i as startSchedule, r as listSchedules, t as cancelSchedule } from "./started-BWWr7Ufw.js";
|
|
5
6
|
import { t as redactInspectionText } from "./inspect-DTfAo5gS.js";
|
|
6
7
|
//#region src/runtime/operations.ts
|
|
7
8
|
function isoDate(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
|
|
@@ -164,10 +161,33 @@ const startedErrorStatus = {
|
|
|
164
161
|
function operationError(error) {
|
|
165
162
|
return withStatus(error, startedErrorStatus[error.code] ?? 500);
|
|
166
163
|
}
|
|
164
|
+
async function listStaticSchedules(filter) {
|
|
165
|
+
const inventory = getHostScheduleInventory();
|
|
166
|
+
const registry = inventory?.registry ?? {};
|
|
167
|
+
const timings = new Map([...Object.entries(inventory?.timings ?? {}), ...getProcessScheduleDefinitions() ?? []]);
|
|
168
|
+
const names = [.../* @__PURE__ */ new Set([...timings.keys(), ...Object.keys(registry)])].filter((name) => name !== "vitehub/started-schedules" && (filter === void 0 || name === filter)).sort((left, right) => left.localeCompare(right));
|
|
169
|
+
return (await Promise.all(names.map(async (name) => [name, timings.get(name) ?? await loadStaticScheduleDefinition(name, registry)]))).flatMap(([name, definition]) => definition?.cron === void 0 ? [] : [{
|
|
170
|
+
cron: definition.cron,
|
|
171
|
+
name,
|
|
172
|
+
...definition.timeZone === void 0 ? {} : { timeZone: definition.timeZone }
|
|
173
|
+
}]);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Lists the Static Schedule Definitions and the Schedules that code started. An app with only cron Schedules has no store
|
|
177
|
+
* for started Schedules, so it lists only its Definitions.
|
|
178
|
+
*/
|
|
167
179
|
async function runScheduleList(input) {
|
|
180
|
+
const definitions = await listStaticSchedules(input.name);
|
|
181
|
+
if (!getStartedScheduleRuntime()) return {
|
|
182
|
+
definitions,
|
|
183
|
+
schedules: []
|
|
184
|
+
};
|
|
168
185
|
const [error, schedules] = await listSchedules(input.name === void 0 ? {} : { name: input.name });
|
|
169
186
|
if (error) throw operationError(error);
|
|
170
|
-
return {
|
|
187
|
+
return {
|
|
188
|
+
definitions,
|
|
189
|
+
schedules: schedules.map(summarizeStartedSchedule)
|
|
190
|
+
};
|
|
171
191
|
}
|
|
172
192
|
async function runScheduleStart(input) {
|
|
173
193
|
const { name, ...options } = input;
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { h as ScheduleRunStatus, l as ScheduleRunAttemptStatus } from "./types-Cw5LjPuc.js";
|
|
2
|
-
import { t as AnyOperation } from "./operation-definition-
|
|
2
|
+
import { t as AnyOperation } from "./operation-definition-CI2PJGqu.js";
|
|
3
3
|
//#region src/runtime/operations.d.ts
|
|
4
4
|
/** Error of a run or attempt. The stack is not included. */
|
|
5
5
|
interface ScheduleRunErrorSummary {
|
|
@@ -65,8 +65,17 @@ interface StartedScheduleSummary {
|
|
|
65
65
|
payload?: unknown;
|
|
66
66
|
timeZone?: string;
|
|
67
67
|
}
|
|
68
|
+
/** Serializable view of one Static Schedule Definition, which runs on its own `cron`. */
|
|
69
|
+
interface ScheduleDefinitionSummary {
|
|
70
|
+
cron: string;
|
|
71
|
+
name: string;
|
|
72
|
+
timeZone?: string;
|
|
73
|
+
}
|
|
68
74
|
/** Result of `schedule.list`. */
|
|
69
75
|
interface ScheduleListResult {
|
|
76
|
+
/** The Static Schedule Definitions of this server, by name. */
|
|
77
|
+
definitions: ScheduleDefinitionSummary[];
|
|
78
|
+
/** The Schedules that code started with `startSchedule()`, oldest first. Empty when no Definition can be started. */
|
|
70
79
|
schedules: StartedScheduleSummary[];
|
|
71
80
|
}
|
|
72
81
|
/** Result of `schedule.start` and `schedule.cancel`. */
|
package/dist/operations.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
|
|
2
|
-
import { t as internalErrorDiagnostics } from "./error-diagnostics-
|
|
2
|
+
import { t as internalErrorDiagnostics } from "./error-diagnostics-C0KyI408.js";
|
|
3
3
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
4
4
|
import * as v from "valibot";
|
|
5
5
|
//#region ../internal/src/standard-schema.ts
|
|
@@ -143,7 +143,7 @@ function table(rows) {
|
|
|
143
143
|
}
|
|
144
144
|
//#endregion
|
|
145
145
|
//#region src/operations.ts
|
|
146
|
-
const runtime = () => import("./operations-
|
|
146
|
+
const runtime = () => import("./operations-DlrK9mlH.js");
|
|
147
147
|
const id = v.pipe(v.string(), v.minLength(1));
|
|
148
148
|
function formatRuns({ runs }) {
|
|
149
149
|
if (runs.length === 0) return "No runs.\n";
|
|
@@ -194,7 +194,7 @@ function defineScheduleOperation(definition) {
|
|
|
194
194
|
}
|
|
195
195
|
const runs = defineScheduleOperation({
|
|
196
196
|
cli: {
|
|
197
|
-
command: "runs",
|
|
197
|
+
command: "runs list",
|
|
198
198
|
format: formatRuns,
|
|
199
199
|
namespace: "schedule",
|
|
200
200
|
positional: ["id"]
|
|
@@ -210,12 +210,12 @@ const runs = defineScheduleOperation({
|
|
|
210
210
|
});
|
|
211
211
|
const attempts = defineScheduleOperation({
|
|
212
212
|
cli: {
|
|
213
|
-
command: "
|
|
213
|
+
command: "runs get",
|
|
214
214
|
format: formatAttempts,
|
|
215
215
|
namespace: "schedule",
|
|
216
216
|
positional: ["id"]
|
|
217
217
|
},
|
|
218
|
-
description: "
|
|
218
|
+
description: "Show one Schedule Run with its attempts, oldest first.",
|
|
219
219
|
input: v.object({ id }),
|
|
220
220
|
kind: "read",
|
|
221
221
|
name: "schedule.attempts",
|
|
@@ -242,9 +242,11 @@ function timingOf(schedule) {
|
|
|
242
242
|
if (schedule.at) return `once at ${schedule.at}`;
|
|
243
243
|
return schedule.timeZone && schedule.timeZone !== "UTC" ? `${schedule.cron} (${schedule.timeZone})` : schedule.cron ?? "-";
|
|
244
244
|
}
|
|
245
|
-
function formatSchedules({ schedules }) {
|
|
246
|
-
if (schedules.length === 0) return "No
|
|
247
|
-
|
|
245
|
+
function formatSchedules({ definitions = [], schedules }) {
|
|
246
|
+
if (definitions.length === 0 && schedules.length === 0) return "No Schedules.\n";
|
|
247
|
+
const parts = [];
|
|
248
|
+
if (definitions.length > 0) parts.push(table([["SCHEDULE", "CRON"], ...definitions.map((definition) => [definition.name, definition.timeZone && definition.timeZone !== "UTC" ? `${definition.cron} (${definition.timeZone})` : definition.cron])]));
|
|
249
|
+
if (schedules.length > 0) parts.push(table([[
|
|
248
250
|
"ID",
|
|
249
251
|
"SCHEDULE",
|
|
250
252
|
"RUNS",
|
|
@@ -254,7 +256,8 @@ function formatSchedules({ schedules }) {
|
|
|
254
256
|
schedule.name,
|
|
255
257
|
timingOf(schedule),
|
|
256
258
|
schedule.createdAt
|
|
257
|
-
])])
|
|
259
|
+
])]));
|
|
260
|
+
return `${parts.join("\n\n")}\n`;
|
|
258
261
|
}
|
|
259
262
|
function formatStartedSchedule(verb) {
|
|
260
263
|
return ({ schedule }) => `${verb} ${schedule.id}: ${schedule.name}, ${timingOf(schedule)}\n`;
|
|
@@ -274,7 +277,7 @@ const scheduleOperations = [
|
|
|
274
277
|
namespace: "schedule",
|
|
275
278
|
positional: ["name"]
|
|
276
279
|
},
|
|
277
|
-
description: "List the Schedules that code started with startSchedule(), oldest first. `name` keeps
|
|
280
|
+
description: "List the Static Schedule Definitions with their cron, and the Schedules that code started with startSchedule(), oldest first. `name` keeps one Definition and its started Schedules.",
|
|
278
281
|
input: v.object({ name: v.optional(id) }),
|
|
279
282
|
kind: "read",
|
|
280
283
|
name: "schedule.list",
|
package/dist/os.d.ts
CHANGED
package/dist/os.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { t as isIanaTimeZone } from "./time-zone-SBldrUgt.js";
|
|
2
2
|
import { t as isRecord } from "./object-Da1zyPCR.js";
|
|
3
|
-
import {
|
|
4
|
-
import { r as
|
|
3
|
+
import { i as timeZoneOffsetMinutes } from "./due-n120-_nz.js";
|
|
4
|
+
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-C1l3TquN.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";
|
|
@@ -113,53 +112,6 @@ function createNodeHost() {
|
|
|
113
112
|
};
|
|
114
113
|
}
|
|
115
114
|
//#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
115
|
//#region src/os/errors.ts
|
|
164
116
|
const platformNames = {
|
|
165
117
|
darwin: "launchd",
|
|
@@ -220,7 +172,6 @@ const sampledDays = 732;
|
|
|
220
172
|
function modulo(value, size) {
|
|
221
173
|
return (value % size + size) % size;
|
|
222
174
|
}
|
|
223
|
-
/** The minutes, from `from` to `to`, where the offset of `timeZone` changes. It assumes at most one change a day. */
|
|
224
175
|
function offsetChanges(timeZone, from, to) {
|
|
225
176
|
const offset = (time) => timeZoneOffsetMinutes(new Date(time), timeZone);
|
|
226
177
|
const changes = [];
|
|
@@ -268,7 +219,6 @@ function clockChanges(timeZone, from) {
|
|
|
268
219
|
}
|
|
269
220
|
return changes;
|
|
270
221
|
}
|
|
271
|
-
/** Every value of `offset(timeZone) - offset(machineTimeZone)`, in minutes, in the two years from `from`. */
|
|
272
222
|
function offsetDifferences(timeZone, machineTimeZone, from) {
|
|
273
223
|
const start = Math.floor(from.getTime() / minuteMs) * minuteMs;
|
|
274
224
|
const end = start + sampledDays * dayMs$1;
|
|
@@ -279,7 +229,6 @@ function offsetDifferences(timeZone, machineTimeZone, from) {
|
|
|
279
229
|
];
|
|
280
230
|
return [...new Set(instants.map((time) => timeZoneOffsetMinutes(new Date(time), timeZone) - timeZoneOffsetMinutes(new Date(time), machineTimeZone)))].sort((left, right) => left - right);
|
|
281
231
|
}
|
|
282
|
-
/** Hours and minutes whose product is exactly `times` (minutes of the day), else `undefined`. */
|
|
283
232
|
function asProduct(times) {
|
|
284
233
|
const unique = new Set(times);
|
|
285
234
|
const hours = [...new Set([...unique].map((time) => Math.floor(time / 60)))].sort((left, right) => left - right);
|
|
@@ -289,7 +238,6 @@ function asProduct(times) {
|
|
|
289
238
|
minutes
|
|
290
239
|
} : void 0;
|
|
291
240
|
}
|
|
292
|
-
/** The cron moved by a constant `difference`: the machine time is the Schedule time minus `difference` minutes. */
|
|
293
241
|
function shiftFields(fields, difference) {
|
|
294
242
|
const shifted = timesOfDay(fields).map((time) => time - difference);
|
|
295
243
|
const product = asProduct(shifted.map((time) => modulo(time, dayMinutes)));
|
|
@@ -441,7 +389,6 @@ function parseLaunchdPlist(plist) {
|
|
|
441
389
|
...logFile === void 0 ? {} : { logFile: unxml(logFile) }
|
|
442
390
|
};
|
|
443
391
|
}
|
|
444
|
-
/** Reads `launchctl print` output: the `state` and `last exit code` lines of the service, one tab deep. */
|
|
445
392
|
function parseLaunchctlPrint(output) {
|
|
446
393
|
const state = output.match(/^\tstate = (.+)$/m)?.[1]?.trim();
|
|
447
394
|
const lastExit = output.match(/^\tlast exit code = (-?\d+)/m)?.[1];
|
|
@@ -451,7 +398,6 @@ function parseLaunchctlPrint(output) {
|
|
|
451
398
|
};
|
|
452
399
|
}
|
|
453
400
|
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
401
|
function zonedInstant(year, month, day, minuteOfDay, timeZone) {
|
|
456
402
|
const local = Date.UTC(year, month - 1, day, 0, minuteOfDay);
|
|
457
403
|
const guess = local - timeZoneOffsetMinutes(new Date(local), timeZone) * 6e4;
|
|
@@ -495,7 +441,6 @@ function createLaunchdDriver(host, scope) {
|
|
|
495
441
|
output: commandOutput(result)
|
|
496
442
|
}), void 0];
|
|
497
443
|
}
|
|
498
|
-
/** The domain that has the job loaded, and its `launchctl print` output. */
|
|
499
444
|
async function loaded(name) {
|
|
500
445
|
for (const domain of domains) {
|
|
501
446
|
const result = await host.exec("launchctl", ["print", `${domain}/${name}`]);
|
|
@@ -505,10 +450,6 @@ function createLaunchdDriver(host, scope) {
|
|
|
505
450
|
};
|
|
506
451
|
}
|
|
507
452
|
}
|
|
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
453
|
async function owner(name) {
|
|
513
454
|
const path = plistPath(name);
|
|
514
455
|
const plist = await host.fs.readFile(path);
|
|
@@ -683,7 +624,6 @@ function lineBreak() {
|
|
|
683
624
|
function pad$1(value) {
|
|
684
625
|
return String(value).padStart(2, "0");
|
|
685
626
|
}
|
|
686
|
-
/** `1..5`, `0,15,30,45`, or `*` when the list holds every value. Runs of three or more become ranges. */
|
|
687
627
|
function calendarList(values, size, format = pad$1) {
|
|
688
628
|
if (values.length === size) return "*";
|
|
689
629
|
const parts = [];
|
|
@@ -746,7 +686,6 @@ function renderSystemdTimer(spec) {
|
|
|
746
686
|
""
|
|
747
687
|
].join("\n");
|
|
748
688
|
}
|
|
749
|
-
/** Reads `systemctl show` output: blocks of `Key=value` lines, one block per unit, keyed by `Id`. */
|
|
750
689
|
function parseSystemctlShow(output) {
|
|
751
690
|
const units = /* @__PURE__ */ new Map();
|
|
752
691
|
for (const block of output.split(/\n\s*\n/)) {
|
|
@@ -760,7 +699,6 @@ function parseSystemctlShow(output) {
|
|
|
760
699
|
}
|
|
761
700
|
return units;
|
|
762
701
|
}
|
|
763
|
-
/** `@1794841368` (`--timestamp=unix`) as a Date. Empty or `0` means never. */
|
|
764
702
|
function unixTimestamp(value) {
|
|
765
703
|
const seconds = Number(value?.replace(/^@/, ""));
|
|
766
704
|
return value && Number.isFinite(seconds) && seconds > 0 ? /* @__PURE__ */ new Date(seconds * 1e3) : void 0;
|
|
@@ -781,10 +719,6 @@ const statusProperties = [
|
|
|
781
719
|
];
|
|
782
720
|
const exitedCode = "1";
|
|
783
721
|
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
722
|
async function foreignResource(host, paths, texts, units, name) {
|
|
789
723
|
for (const kind of ["service", "timer"]) {
|
|
790
724
|
const text = texts[kind];
|
|
@@ -865,7 +799,6 @@ function createSystemdDriver(host, scope) {
|
|
|
865
799
|
...timer === void 0 ? {} : { timer }
|
|
866
800
|
};
|
|
867
801
|
}
|
|
868
|
-
/** The resource that holds `name` when ViteHub did not install it in this scope. */
|
|
869
802
|
async function foreign(name, files, texts) {
|
|
870
803
|
const fileOwner = await foreignResource(host, files, texts, /* @__PURE__ */ new Map(), name);
|
|
871
804
|
if (fileOwner) return [void 0, fileOwner];
|
|
@@ -1041,14 +974,12 @@ const monthNames = [
|
|
|
1041
974
|
const taskNeverRan = 267011;
|
|
1042
975
|
const taskRunning = 267009;
|
|
1043
976
|
const { join: join$1 } = pathsFor("win32");
|
|
1044
|
-
/** An XML duration, such as `PT23H52M30S`. */
|
|
1045
977
|
function taskDuration(seconds) {
|
|
1046
978
|
const hours = Math.floor(seconds / 3600);
|
|
1047
979
|
const minutes = Math.floor(seconds % 3600 / 60);
|
|
1048
980
|
const rest = seconds % 60;
|
|
1049
981
|
return `PT${hours ? `${hours}H` : ""}${minutes ? `${minutes}M` : ""}${rest || !seconds ? `${rest}S` : ""}`;
|
|
1050
982
|
}
|
|
1051
|
-
/** One trigger for the runs. The duration ends half a step after the last run. */
|
|
1052
983
|
function trigger({ start, step, count }) {
|
|
1053
984
|
if (count < 2) return { start };
|
|
1054
985
|
return {
|
|
@@ -1059,15 +990,10 @@ function trigger({ start, step, count }) {
|
|
|
1059
990
|
}
|
|
1060
991
|
};
|
|
1061
992
|
}
|
|
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
993
|
function crossesChange(runs, changes) {
|
|
1067
994
|
const last = runs.start + (runs.count - 1) * runs.step;
|
|
1068
995
|
return runs.count > 1 && changes.some((change) => runs.start < change.end && last >= change.start);
|
|
1069
996
|
}
|
|
1070
|
-
/** The fewest triggers that start at every time of the day of the cron, and keep their times across `changes`. */
|
|
1071
997
|
function timeTriggers(fields, changes) {
|
|
1072
998
|
const times = timesOfDay(fields);
|
|
1073
999
|
const single = (start) => ({
|
|
@@ -1156,7 +1082,6 @@ function taskTriggers(fields, clock = {
|
|
|
1156
1082
|
function xml(value) {
|
|
1157
1083
|
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
1158
1084
|
}
|
|
1159
|
-
/** A PowerShell single-quoted string. PowerShell also reads the typographic single quotes as quotes. */
|
|
1160
1085
|
function powerShellString(value) {
|
|
1161
1086
|
return `'${value.replace(/['\u2018\u2019\u201A\u201B]/g, "$&$&")}'`;
|
|
1162
1087
|
}
|
|
@@ -1208,6 +1133,15 @@ function renderTaskWrapper(spec, logFile) {
|
|
|
1208
1133
|
function parseTaskWrapperLog(wrapper) {
|
|
1209
1134
|
return wrapper.match(/^\$log = '((?:[^']|'')*)'\r?$/m)?.[1]?.replaceAll("''", "'");
|
|
1210
1135
|
}
|
|
1136
|
+
/**
|
|
1137
|
+
* The base64 PowerShell command that runs the wrapper and exits with its exit code. Task Scheduler expands `%NAME%` in
|
|
1138
|
+
* the arguments of a task and has no escape for `%`, so a wrapper path in the arguments breaks under a folder such as
|
|
1139
|
+
* `C:\Users\pct %PATH%`. Base64 has no `%`.
|
|
1140
|
+
*/
|
|
1141
|
+
function runWrapperCommand(wrapper) {
|
|
1142
|
+
const script = `$global:LASTEXITCODE = 1\n& ${powerShellString(wrapper)}\nexit $global:LASTEXITCODE`;
|
|
1143
|
+
return Buffer.from(script, "utf16le").toString("base64");
|
|
1144
|
+
}
|
|
1211
1145
|
/** The task XML. The description ends with a hash of the XML and the wrapper, which a later install compares. */
|
|
1212
1146
|
function renderTaskXml(spec, triggers, options) {
|
|
1213
1147
|
const render = (description) => [
|
|
@@ -1255,7 +1189,7 @@ function renderTaskXml(spec, triggers, options) {
|
|
|
1255
1189
|
" <Actions Context=\"Author\">",
|
|
1256
1190
|
" <Exec>",
|
|
1257
1191
|
" <Command>powershell.exe</Command>",
|
|
1258
|
-
` <Arguments>${xml(`-NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -
|
|
1192
|
+
` <Arguments>${xml(`-NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -EncodedCommand ${runWrapperCommand(options.wrapper)}`)}</Arguments>`,
|
|
1259
1193
|
" </Exec>",
|
|
1260
1194
|
" </Actions>",
|
|
1261
1195
|
"</Task>",
|
|
@@ -1273,16 +1207,11 @@ function taskOwnerScope(description) {
|
|
|
1273
1207
|
function taskDescriptionHash(description) {
|
|
1274
1208
|
return description?.match(/sha256:([0-9a-f]{64})/)?.[1];
|
|
1275
1209
|
}
|
|
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
1210
|
function unsafeWindowsArgument(argument) {
|
|
1281
1211
|
if (argument === "") return "an empty argument";
|
|
1282
1212
|
if (argument.includes("\"")) return "an argument with a double quote";
|
|
1283
1213
|
if (/\s/.test(argument) && argument.endsWith("\\")) return "an argument with spaces that ends with a backslash";
|
|
1284
1214
|
}
|
|
1285
|
-
/** Reads the JSON of the status script. */
|
|
1286
1215
|
function parseTaskInfo(output) {
|
|
1287
1216
|
const value = JSON.parse(output.trim() || "{}");
|
|
1288
1217
|
if (typeof value !== "object" || value === null || !("installed" in value)) return { installed: false };
|
|
@@ -1304,7 +1233,6 @@ function taskInfoScript(name) {
|
|
|
1304
1233
|
}
|
|
1305
1234
|
/** Task Scheduler tasks in the root folder, run as the current user or as SYSTEM. */
|
|
1306
1235
|
function createTaskSchedulerDriver(host, scope) {
|
|
1307
|
-
/** A task of this name that ViteHub did not install in this scope. */
|
|
1308
1236
|
const foreign = (task) => task.installed && taskOwnerScope(task.description) !== scope;
|
|
1309
1237
|
const taskResource = (name, task) => {
|
|
1310
1238
|
const owner = taskOwnerScope(task.description);
|