quota-keepalive 0.1.8 → 0.1.9
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/package.json +1 -1
- package/src/live-options.js +24 -3
- package/src/runner.js +11 -1
package/package.json
CHANGED
package/src/live-options.js
CHANGED
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises"
|
|
2
|
+
import { createRequire } from "node:module"
|
|
2
3
|
import { isAbsolute, join, resolve } from "node:path"
|
|
3
4
|
import { fileURLToPath } from "node:url"
|
|
4
5
|
import { magpieConfigHome } from "./common.js"
|
|
5
6
|
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
|
+
const PACKAGE = require("../package.json")
|
|
9
|
+
const EXACT_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/
|
|
10
|
+
|
|
6
11
|
export const PLUGIN_DIR = fileURLToPath(new URL("..", import.meta.url))
|
|
12
|
+
export const PLUGIN_NAME = PACKAGE.name
|
|
13
|
+
|
|
14
|
+
export function pluginSpecMatches(
|
|
15
|
+
spec,
|
|
16
|
+
{ packageName = PLUGIN_NAME, pluginDir = PLUGIN_DIR } = {},
|
|
17
|
+
) {
|
|
18
|
+
const value = typeof spec === "string" ? spec.trim() : ""
|
|
19
|
+
if (!value) return false
|
|
20
|
+
if (isAbsolute(value)) return resolve(value) === resolve(pluginDir)
|
|
21
|
+
|
|
22
|
+
const npmSpec = value.startsWith("npm:") ? value.slice(4) : value
|
|
23
|
+
if (npmSpec === packageName) return true
|
|
24
|
+
const versionPrefix = `${packageName}@`
|
|
25
|
+
if (!npmSpec.startsWith(versionPrefix)) return false
|
|
26
|
+
|
|
27
|
+
const version = npmSpec.slice(versionPrefix.length)
|
|
28
|
+
return version === "latest" || EXACT_VERSION.test(version)
|
|
29
|
+
}
|
|
7
30
|
|
|
8
31
|
function entryMatches(entry) {
|
|
9
|
-
|
|
10
|
-
if (!spec || !isAbsolute(spec)) return false
|
|
11
|
-
return resolve(spec) === resolve(PLUGIN_DIR)
|
|
32
|
+
return pluginSpecMatches(entry?.spec)
|
|
12
33
|
}
|
|
13
34
|
|
|
14
35
|
export async function readLivePluginOptions(configHome = magpieConfigHome()) {
|
package/src/runner.js
CHANGED
|
@@ -34,6 +34,14 @@ const BUILTIN_PROVIDERS = Object.freeze([
|
|
|
34
34
|
|
|
35
35
|
let refreshRunning = false
|
|
36
36
|
|
|
37
|
+
export function runInBackgroundTask(task) {
|
|
38
|
+
try {
|
|
39
|
+
return Promise.resolve(typeof task === "function" ? task() : task).catch(() => {})
|
|
40
|
+
} catch {
|
|
41
|
+
return Promise.resolve()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
37
45
|
function nowIso() {
|
|
38
46
|
return new Date().toISOString()
|
|
39
47
|
}
|
|
@@ -551,6 +559,7 @@ export async function consumePendingCommand({
|
|
|
551
559
|
runMagpieJson = defaultRunMagpieJson,
|
|
552
560
|
checkin = null,
|
|
553
561
|
keepalive = null,
|
|
562
|
+
runInBackground = runInBackgroundTask,
|
|
554
563
|
}) {
|
|
555
564
|
const id = sanitize(rawOptions.pendingId, 80)
|
|
556
565
|
const action = sanitize(rawOptions.pendingAction, 24)
|
|
@@ -570,7 +579,7 @@ export async function consumePendingCommand({
|
|
|
570
579
|
const command = await claimCommand({ commandPath: config.commandPath, id })
|
|
571
580
|
if (!command || command.action !== action) return null
|
|
572
581
|
|
|
573
|
-
|
|
582
|
+
const task = (async () => {
|
|
574
583
|
let outcome
|
|
575
584
|
try {
|
|
576
585
|
outcome = await runCommand({
|
|
@@ -618,6 +627,7 @@ export async function consumePendingCommand({
|
|
|
618
627
|
await refreshSnapshot(config, null)
|
|
619
628
|
}
|
|
620
629
|
})()
|
|
630
|
+
runInBackground(task)
|
|
621
631
|
|
|
622
632
|
return { id, action, status: "running" }
|
|
623
633
|
}
|