From fa1acb62cbe54d6f13f3c6897d69c9912831e4bd Mon Sep 17 00:00:00 2001 From: chyzwar Date: Sun, 26 May 2024 13:47:26 +0200 Subject: [PATCH 1/6] feat(conf): handle reset as set to undefined, expose more spec --- packages/conf/src/__tests__/Ini.test.ts | 17 ++++ packages/conf/src/__tests__/service.test.ts | 3 +- packages/conf/src/exec.ts | 74 +++++++------- packages/conf/src/index.ts | 5 +- packages/conf/src/ini.ts | 3 + packages/conf/src/install.ts | 12 +-- packages/conf/src/kill.ts | 14 +-- packages/conf/src/resource.ts | 48 ++++----- packages/conf/src/service.ts | 22 ++-- packages/conf/src/timer.ts | 40 +++++--- packages/conf/src/types.ts | 4 + packages/conf/src/unit.ts | 106 +++++++++++++++----- 12 files changed, 223 insertions(+), 125 deletions(-) create mode 100644 packages/conf/src/types.ts diff --git a/packages/conf/src/__tests__/Ini.test.ts b/packages/conf/src/__tests__/Ini.test.ts index e848df6..6f993fc 100644 --- a/packages/conf/src/__tests__/Ini.test.ts +++ b/packages/conf/src/__tests__/Ini.test.ts @@ -51,6 +51,11 @@ ExecPreStart=/opt/example/agent start-2 \ User=root `; +const unitOnlyDesc = ` +[Unit] +Description=example +` + describe("INI - fromString", () => { test("should parse INI data", () => { const expected = { @@ -77,6 +82,18 @@ describe("INI - fromString", () => { expect(object).toEqual(expected); }); + test("should omit undefined values", () => { + const obj = { + Unit: { + Description: "example", + After: undefined, + }, + }; + const ini = INI.fromObject(obj); + const result = ini.toString(); + expect(result.trim()).toEqual(unitOnlyDesc.trim()); + }) + test("should parse INI data with line dataUnitWithBackslash", () => { const expected = { Unit: { diff --git a/packages/conf/src/__tests__/service.test.ts b/packages/conf/src/__tests__/service.test.ts index 6cea50f..4b545b4 100644 --- a/packages/conf/src/__tests__/service.test.ts +++ b/packages/conf/src/__tests__/service.test.ts @@ -101,7 +101,8 @@ describe("Service", () => { service .getInstallSection() - .setWantedBy("multi-user.target"); + .setWantedBy("multi-user.target") + .setRequiredBy(); expect(service.toObject()).toMatchObject(serviceObj); }); diff --git a/packages/conf/src/exec.ts b/packages/conf/src/exec.ts index a834093..efe26ec 100644 --- a/packages/conf/src/exec.ts +++ b/packages/conf/src/exec.ts @@ -1308,7 +1308,7 @@ export class ExecSectionBuilder { * Set ExecSearchPath * @see {@link ExecSectionConfig.ExecSearchPath} */ - public setExecSearchPath(value: string): this { + public setExecSearchPath(value?: string): this { this.section.ExecSearchPath = value; return this; } @@ -1317,7 +1317,7 @@ export class ExecSectionBuilder { * Set WorkingDirectory * @see {@link ExecSectionConfig.WorkingDirectory} */ - public setWorkingDirectory(value: string): this { + public setWorkingDirectory(value?: string): this { this.section.WorkingDirectory = value; return this; } @@ -1326,7 +1326,7 @@ export class ExecSectionBuilder { * Set RootDirectory * @see {@link ExecSectionConfig.RootDirectory} */ - public setRootDirectory(value: string): this { + public setRootDirectory(value?: string): this { this.section.RootDirectory = value; return this; } @@ -1335,7 +1335,7 @@ export class ExecSectionBuilder { * Set RootImage * @see {@link ExecSectionConfig.RootImage} */ - public setRootImage(value: string): this { + public setRootImage(value?: string): this { this.section.RootImage = value; return this; } @@ -1344,7 +1344,7 @@ export class ExecSectionBuilder { * Set RootImageOptions * @see {@link ExecSectionConfig.RootImageOptions} */ - public setRootImageOptions(value: string): this { + public setRootImageOptions(value?: string): this { this.section.RootImageOptions = value; return this; } @@ -1353,7 +1353,7 @@ export class ExecSectionBuilder { * Set RootEphemeral * @see {@link ExecSectionConfig.RootEphemeral} */ - public setRootEphemeral(value: boolean): this { + public setRootEphemeral(value?: boolean): this { this.section.RootEphemeral = value; return this; } @@ -1362,7 +1362,7 @@ export class ExecSectionBuilder { * Set RootHash * @see {@link ExecSectionConfig.RootHash} */ - public setRootHash(value: string): this { + public setRootHash(value?: string): this { this.section.RootHash = value; return this; } @@ -1371,7 +1371,7 @@ export class ExecSectionBuilder { * Set RootHashSignature * @see {@link ExecSectionConfig.RootHashSignature} */ - public setRootHashSignature(value: string): this { + public setRootHashSignature(value?: string): this { this.section.RootHashSignature = value; return this; } @@ -1380,7 +1380,7 @@ export class ExecSectionBuilder { * Set RootVerity * @see {@link ExecSectionConfig.RootVerity} */ - public setRootVerity(value: string): this { + public setRootVerity(value?: string): this { this.section.RootVerity = value; return this; } @@ -1389,7 +1389,7 @@ export class ExecSectionBuilder { * Set RootImagePolicy * @see {@link ExecSectionConfig.RootImagePolicy} */ - public setRootImagePolicy(value: string): this { + public setRootImagePolicy(value?: string): this { this.section.RootImagePolicy = value; return this; } @@ -1398,7 +1398,7 @@ export class ExecSectionBuilder { * Set MountImagePolicy * @see {@link ExecSectionConfig.MountImagePolicy} */ - public setMountImagePolicy(value: string): this { + public setMountImagePolicy(value?: string): this { this.section.MountImagePolicy = value; return this; } @@ -1407,7 +1407,7 @@ export class ExecSectionBuilder { * Set ExtensionImagePolicy * @see {@link ExecSectionConfig.ExtensionImagePolicy} */ - public setExtensionImagePolicy(value: string): this { + public setExtensionImagePolicy(value?: string): this { this.section.ExtensionImagePolicy = value; return this; } @@ -1416,7 +1416,7 @@ export class ExecSectionBuilder { * Set MountAPIVFS * @see {@link ExecSectionConfig.MountAPIVFS} */ - public setMountAPIVFS(value: boolean): this { + public setMountAPIVFS(value?: boolean): this { this.section.MountAPIVFS = value; return this; } @@ -1426,7 +1426,7 @@ export class ExecSectionBuilder { * @see {@link ExecSectionConfig.ProtectProc} */ - public setProtectProc(value: "default" | "invisible" | "noaccess" | "ptraceable"): this { + public setProtectProc(value?: "default" | "invisible" | "noaccess" | "ptraceable"): this { this.section.ProtectProc = value; return this; } @@ -1435,7 +1435,7 @@ export class ExecSectionBuilder { * Set ProcSubset * @see {@link ExecSectionConfig.ProcSubset} */ - public setProcSubset(value: "all" | "pid"): this { + public setProcSubset(value?: "all" | "pid"): this { this.section.ProcSubset = value; return this; } @@ -1444,7 +1444,7 @@ export class ExecSectionBuilder { * Set BindPaths * @see {@link ExecSectionConfig.BindPaths} */ - public setBindPaths(value: string): this { + public setBindPaths(value?: string): this { this.section.BindPaths = value; return this; } @@ -1453,7 +1453,7 @@ export class ExecSectionBuilder { * Set BindReadOnlyPaths * @see {@link ExecSectionConfig.BindReadOnlyPaths} */ - public setBindReadOnlyPaths(value: string): this { + public setBindReadOnlyPaths(value?: string): this { this.section.BindReadOnlyPaths = value; return this; } @@ -1462,7 +1462,7 @@ export class ExecSectionBuilder { * Set MountImages * @see {@link ExecSectionConfig.MountImages} */ - public setMountImages(value: string): this { + public setMountImages(value?: string): this { this.section.MountImages = value; return this; } @@ -1471,7 +1471,7 @@ export class ExecSectionBuilder { * Set ExtensionImages * @see {@link ExecSectionConfig.ExtensionImages} */ - public setExtensionImages(value: string): this { + public setExtensionImages(value?: string): this { this.section.ExtensionImages = value; return this; } @@ -1480,7 +1480,7 @@ export class ExecSectionBuilder { * Set ExtensionDirectories * @see {@link ExecSectionConfig.ExtensionDirectories} */ - public setExtensionDirectories(value: string): this { + public setExtensionDirectories(value?: string): this { this.section.ExtensionDirectories = value; return this; } @@ -1489,7 +1489,7 @@ export class ExecSectionBuilder { * Set User * @see {@link ExecSectionConfig.User} */ - public setUser(value: string): this { + public setUser(value?: string): this { this.section.User = value; return this; } @@ -1498,7 +1498,7 @@ export class ExecSectionBuilder { * Set Group * @see {@link ExecSectionConfig.Group} */ - public setGroup(value: string): this { + public setGroup(value?: string): this { this.section.Group = value; return this; } @@ -1507,7 +1507,7 @@ export class ExecSectionBuilder { * Set DynamicUser * @see {@link ExecSectionConfig.DynamicUser} */ - public setDynamicUser(value: boolean): this { + public setDynamicUser(value?: boolean): this { this.section.DynamicUser = value; return this; } @@ -1516,7 +1516,7 @@ export class ExecSectionBuilder { * Set SupplementaryGroups * @see {@link ExecSectionConfig.SupplementaryGroups} */ - public setSupplementaryGroups(value: string): this { + public setSupplementaryGroups(value?: string): this { this.section.SupplementaryGroups = value; return this; } @@ -1525,7 +1525,7 @@ export class ExecSectionBuilder { * Set SetLoginEnvironment * @see {@link ExecSectionConfig.SetLoginEnvironment} */ - public setSetLoginEnvironment(value: boolean): this { + public setSetLoginEnvironment(value?: boolean): this { this.section.SetLoginEnvironment = value; return this; } @@ -1534,7 +1534,7 @@ export class ExecSectionBuilder { * Set PAMName * @see {@link ExecSectionConfig.PAMName} */ - public setPAMName(value: string): this { + public setPAMName(value?: string): this { this.section.PAMName = value; return this; } @@ -1543,7 +1543,7 @@ export class ExecSectionBuilder { * Set CapabilityBoundingSet * @see {@link ExecSectionConfig.CapabilityBoundingSet} */ - public setCapabilityBoundingSet(value: string): this { + public setCapabilityBoundingSet(value?: string): this { this.section.CapabilityBoundingSet = value; return this; } @@ -1552,7 +1552,7 @@ export class ExecSectionBuilder { * Set AmbientCapabilities * @see {@link ExecSectionConfig.AmbientCapabilities} */ - public setAmbientCapabilities(value: string): this { + public setAmbientCapabilities(value?: string): this { this.section.AmbientCapabilities = value; return this; } @@ -1561,7 +1561,7 @@ export class ExecSectionBuilder { * Set NoNewPrivileges * @see {@link ExecSectionConfig.NoNewPrivileges} */ - public setNoNewPrivileges(value: boolean): this { + public setNoNewPrivileges(value?: boolean): this { this.section.NoNewPrivileges = value; return this; } @@ -1570,7 +1570,7 @@ export class ExecSectionBuilder { * Set SecureBits * @see {@link ExecSectionConfig.SecureBits} */ - public setSecureBits(value: string): this { + public setSecureBits(value?: string): this { this.section.SecureBits = value; return this; } @@ -1579,7 +1579,7 @@ export class ExecSectionBuilder { * Set Environment * @see {@link ExecSectionConfig.Environment} */ - public setEnvironment(value: string[] | string): this { + public setEnvironment(value?: string[] | string): this { this.section.Environment = value; return this; } @@ -1588,7 +1588,7 @@ export class ExecSectionBuilder { * Set EnvironmentFile * @see {@link ExecSectionConfig.EnvironmentFile} */ - public setEnvironmentFile(value: string[] | string): this { + public setEnvironmentFile(value?: string[] | string): this { this.section.EnvironmentFile = value; return this; } @@ -1597,7 +1597,7 @@ export class ExecSectionBuilder { * Set PassEnvironment * @see {@link ExecSectionConfig.PassEnvironment} */ - public setPassEnvironment(value: string[] | string): this { + public setPassEnvironment(value?: string[] | string): this { this.section.PassEnvironment = value; return this; } @@ -1606,7 +1606,7 @@ export class ExecSectionBuilder { * Set UnsetEnvironment * @see {@link ExecSectionConfig.UnsetEnvironment} */ - public setUnsetEnvironment(value: string[] | string): this { + public setUnsetEnvironment(value?: string[] | string): this { this.section.UnsetEnvironment = value; return this; } @@ -1615,7 +1615,7 @@ export class ExecSectionBuilder { * Set SELinuxContext * @see {@link ExecSectionConfig.SELinuxContext} */ - public setSELinuxContext(value: string): this { + public setSELinuxContext(value?: string): this { this.section.SELinuxContext = value; return this; } @@ -1624,7 +1624,7 @@ export class ExecSectionBuilder { * Set AppArmorProfile * @see {@link ExecSectionConfig.AppArmorProfile} */ - public setAppArmorProfile(value: string): this { + public setAppArmorProfile(value?: string): this { this.section.AppArmorProfile = value; return this; } @@ -1633,7 +1633,7 @@ export class ExecSectionBuilder { * Set SmackProcessLabel * @see {@link ExecSectionConfig.SmackProcessLabel} */ - public setSmackProcessLabel(value: string): this { + public setSmackProcessLabel(value?: string): this { this.section.SmackProcessLabel = value; return this; } diff --git a/packages/conf/src/index.ts b/packages/conf/src/index.ts index e409b32..10d5871 100644 --- a/packages/conf/src/index.ts +++ b/packages/conf/src/index.ts @@ -27,6 +27,7 @@ export { TimerSectionBuilder, } from "./timer.js"; - - +export { + Unit +} from "./types.js"; diff --git a/packages/conf/src/ini.ts b/packages/conf/src/ini.ts index 049c27b..e4307da 100644 --- a/packages/conf/src/ini.ts +++ b/packages/conf/src/ini.ts @@ -67,6 +67,9 @@ export class INI { if (typeof sectionValue === "string") { continue; } + if (typeof sectionValue === "undefined") { + continue; + } if (typeof sectionValue === "number") { continue; } diff --git a/packages/conf/src/install.ts b/packages/conf/src/install.ts index e667d3e..6d35109 100644 --- a/packages/conf/src/install.ts +++ b/packages/conf/src/install.ts @@ -109,7 +109,7 @@ export class InstallSectionBuilder { * Set alias for the unit * @see {@link InstallSectionConfig.Alias} */ - public setAlias(alias: string[] | string): this { + public setAlias(alias?: string[] | string): this { this.section.Alias = alias; return this; } @@ -118,7 +118,7 @@ export class InstallSectionBuilder { * Set WantedBy for the unit * @see {@link InstallSectionConfig.WantedBy} */ - public setWantedBy(wantedBy: string[] | string): this { + public setWantedBy(wantedBy?: string[] | string): this { this.section.WantedBy = wantedBy; return this; } @@ -127,7 +127,7 @@ export class InstallSectionBuilder { * Set RequiredBy for the unit * @see {@link InstallSectionConfig.RequiredBy} */ - public setRequiredBy(requiredBy: string[] | string): this { + public setRequiredBy(requiredBy?: string[] | string): this { this.section.RequiredBy = requiredBy; return this; } @@ -136,7 +136,7 @@ export class InstallSectionBuilder { * Set UpheldBy for the unit * @see {@link InstallSectionConfig.UpheldBy} */ - public setUpheldBy(upheldBy: string[] | string): this { + public setUpheldBy(upheldBy?: string[] | string): this { this.section.UpheldBy = upheldBy; return this; } @@ -145,7 +145,7 @@ export class InstallSectionBuilder { * Set Also for the unit * @see {@link InstallSectionConfig.Also} */ - public setAlso(also: string[] | string): this { + public setAlso(also?: string[] | string): this { this.section.Also = also; return this; } @@ -154,7 +154,7 @@ export class InstallSectionBuilder { * Set DefaultInstance for the unit * @see {@link InstallSectionConfig.DefaultInstance} */ - public setDefaultInstance(defaultInstance: string): this { + public setDefaultInstance(defaultInstance?: string): this { this.section.DefaultInstance = defaultInstance; return this; } diff --git a/packages/conf/src/kill.ts b/packages/conf/src/kill.ts index 1329d5d..89ad7a9 100644 --- a/packages/conf/src/kill.ts +++ b/packages/conf/src/kill.ts @@ -146,7 +146,7 @@ export class KillSectionBuilder { * Set KillMode * @see {@link KillSectionConfig.KillMode} */ - public setKillMode(value: KillSectionConfig["KillMode"]): this { + public setKillMode(value?: KillSectionConfig["KillMode"]): this { this.section.KillMode = value; return this; } @@ -155,7 +155,7 @@ export class KillSectionBuilder { * Set KillSignal * @see {@link KillSectionConfig.KillSignal} */ - public setKillSignal(value: KillSectionConfig["KillSignal"]): this { + public setKillSignal(value?: KillSectionConfig["KillSignal"]): this { this.section.KillSignal = value; return this; } @@ -164,7 +164,7 @@ export class KillSectionBuilder { * Set RestartKillSignal * @see {@link KillSectionConfig.RestartKillSignal} */ - public setRestartKillSignal(value: KillSectionConfig["RestartKillSignal"]): this { + public setRestartKillSignal(value?: KillSectionConfig["RestartKillSignal"]): this { this.section.RestartKillSignal = value; return this; } @@ -173,7 +173,7 @@ export class KillSectionBuilder { * Set SendSIGHUP * @see {@link KillSectionConfig.SendSIGHUP} */ - public setSendSIGHUP(value: KillSectionConfig["SendSIGHUP"]): this { + public setSendSIGHUP(value?: KillSectionConfig["SendSIGHUP"]): this { this.section.SendSIGHUP = value; return this; } @@ -182,7 +182,7 @@ export class KillSectionBuilder { * Set SendSIGKILL * @see {@link KillSectionConfig.SendSIGKILL} */ - public setSendSIGKILL(value: KillSectionConfig["SendSIGKILL"]): this { + public setSendSIGKILL(value?: KillSectionConfig["SendSIGKILL"]): this { this.section.SendSIGKILL = value; return this; } @@ -191,7 +191,7 @@ export class KillSectionBuilder { * Set FinalKillSignal * @see {@link KillSectionConfig.FinalKillSignal} */ - public setFinalKillSignal(value: KillSectionConfig["FinalKillSignal"]): this { + public setFinalKillSignal(value?: KillSectionConfig["FinalKillSignal"]): this { this.section.FinalKillSignal = value; return this; } @@ -200,7 +200,7 @@ export class KillSectionBuilder { * Set WatchdogSignal * @see {@link KillSectionConfig.WatchdogSignal} */ - public setWatchdogSignal(value: KillSectionConfig["WatchdogSignal"]): this { + public setWatchdogSignal(value?: KillSectionConfig["WatchdogSignal"]): this { this.section.WatchdogSignal = value; return this; } diff --git a/packages/conf/src/resource.ts b/packages/conf/src/resource.ts index a84838c..47ecfcb 100644 --- a/packages/conf/src/resource.ts +++ b/packages/conf/src/resource.ts @@ -1174,7 +1174,7 @@ export class ResourceSectionBuilder { * Set resource CPUAccounting * @see {@link ResourceSectionConfig.CPUAccounting} */ - public setCPUAccounting(value: ResourceSectionConfig["CPUAccounting"]): this { + public setCPUAccounting(value?: ResourceSectionConfig["CPUAccounting"]): this { this.section.CPUAccounting = value; return this; } @@ -1183,7 +1183,7 @@ export class ResourceSectionBuilder { * Set resource CPUWeight * @see {@link ResourceSectionConfig.CPUWeight} */ - public setCPUWeight(value: ResourceSectionConfig["CPUWeight"]): this { + public setCPUWeight(value?: ResourceSectionConfig["CPUWeight"]): this { this.section.CPUWeight = value; return this; } @@ -1192,7 +1192,7 @@ export class ResourceSectionBuilder { * Set resource StartupCPUWeight * @see {@link ResourceSectionConfig.StartupCPUWeight} */ - public setStartupCPUWeight(value: ResourceSectionConfig["StartupCPUWeight"]): this { + public setStartupCPUWeight(value?: ResourceSectionConfig["StartupCPUWeight"]): this { this.section.StartupCPUWeight = value; return this; } @@ -1201,7 +1201,7 @@ export class ResourceSectionBuilder { * Set resource CPUQuota * @see {@link ResourceSectionConfig.CPUQuota} */ - public setCPUQuota(value: ResourceSectionConfig["CPUQuota"]): this { + public setCPUQuota(value?: ResourceSectionConfig["CPUQuota"]): this { this.section.CPUQuota = value; return this; } @@ -1210,7 +1210,7 @@ export class ResourceSectionBuilder { * Set resource CPUQuotaPeriodSec * @see {@link ResourceSectionConfig.CPUQuotaPeriodSec} */ - public setCPUQuotaPeriodSec(value: ResourceSectionConfig["CPUQuotaPeriodSec"]): this { + public setCPUQuotaPeriodSec(value?: ResourceSectionConfig["CPUQuotaPeriodSec"]): this { this.section.CPUQuotaPeriodSec = value; return this; } @@ -1219,7 +1219,7 @@ export class ResourceSectionBuilder { * Set resource AllowedCPUs * @see {@link ResourceSectionConfig.AllowedCPUs} */ - public setAllowedCPUs(value: ResourceSectionConfig["AllowedCPUs"]): this { + public setAllowedCPUs(value?: ResourceSectionConfig["AllowedCPUs"]): this { this.section.AllowedCPUs = value; return this; } @@ -1228,7 +1228,7 @@ export class ResourceSectionBuilder { * Set resource StartupAllowedCPUs * @see {@link ResourceSectionConfig.StartupAllowedCPUs} */ - public setStartupAllowedCPUs(value: ResourceSectionConfig["StartupAllowedCPUs"]): this { + public setStartupAllowedCPUs(value?: ResourceSectionConfig["StartupAllowedCPUs"]): this { this.section.StartupAllowedCPUs = value; return this; } @@ -1237,7 +1237,7 @@ export class ResourceSectionBuilder { * Set resource MemoryAccounting * @see {@link ResourceSectionConfig.MemoryAccounting} */ - public setMemoryAccounting(value: ResourceSectionConfig["MemoryAccounting"]): this { + public setMemoryAccounting(value?: ResourceSectionConfig["MemoryAccounting"]): this { this.section.MemoryAccounting = value; return this; } @@ -1246,7 +1246,7 @@ export class ResourceSectionBuilder { * Set resource MemoryMin * @see {@link ResourceSectionConfig.MemoryMin} */ - public setMemoryMin(value: ResourceSectionConfig["MemoryMin"]): this { + public setMemoryMin(value?: ResourceSectionConfig["MemoryMin"]): this { this.section.MemoryMin = value; return this; } @@ -1255,7 +1255,7 @@ export class ResourceSectionBuilder { * Set resource MemoryLow * @see {@link ResourceSectionConfig.MemoryLow} */ - public setMemoryLow(value: ResourceSectionConfig["MemoryLow"]): this { + public setMemoryLow(value?: ResourceSectionConfig["MemoryLow"]): this { this.section.MemoryLow = value; return this; } @@ -1264,7 +1264,7 @@ export class ResourceSectionBuilder { * Set resource StartupMemoryLow * @see {@link ResourceSectionConfig.StartupMemoryLow} */ - public setStartupMemoryLow(value: ResourceSectionConfig["StartupMemoryLow"]): this { + public setStartupMemoryLow(value?: ResourceSectionConfig["StartupMemoryLow"]): this { this.section.StartupMemoryLow = value; return this; } @@ -1273,7 +1273,7 @@ export class ResourceSectionBuilder { * Set resource DefaultStartupMemoryLow * @see {@link ResourceSectionConfig.DefaultStartupMemoryLow} */ - public setDefaultStartupMemoryLow(value: ResourceSectionConfig["DefaultStartupMemoryLow"]): this { + public setDefaultStartupMemoryLow(value?: ResourceSectionConfig["DefaultStartupMemoryLow"]): this { this.section.DefaultStartupMemoryLow = value; return this; } @@ -1282,7 +1282,7 @@ export class ResourceSectionBuilder { * Set resource MemoryHigh * @see {@link ResourceSectionConfig.MemoryHigh} */ - public setMemoryHigh(value: ResourceSectionConfig["MemoryHigh"]): this { + public setMemoryHigh(value?: ResourceSectionConfig["MemoryHigh"]): this { this.section.MemoryHigh = value; return this; } @@ -1291,7 +1291,7 @@ export class ResourceSectionBuilder { * Set resource StartupMemoryHigh * @see {@link ResourceSectionConfig.StartupMemoryHigh} */ - public setStartupMemoryHigh(value: ResourceSectionConfig["StartupMemoryHigh"]): this { + public setStartupMemoryHigh(value?: ResourceSectionConfig["StartupMemoryHigh"]): this { this.section.StartupMemoryHigh = value; return this; } @@ -1300,7 +1300,7 @@ export class ResourceSectionBuilder { * Set resource MemoryMax * @see {@link ResourceSectionConfig.MemoryMax} */ - public setMemoryMax(value: ResourceSectionConfig["MemoryMax"]): this { + public setMemoryMax(value?: ResourceSectionConfig["MemoryMax"]): this { this.section.MemoryMax = value; return this; } @@ -1309,7 +1309,7 @@ export class ResourceSectionBuilder { * Set resource StartupMemoryMax * @see {@link ResourceSectionConfig.StartupMemoryMax} */ - public setStartupMemoryMax(value: ResourceSectionConfig["StartupMemoryMax"]): this { + public setStartupMemoryMax(value?: ResourceSectionConfig["StartupMemoryMax"]): this { this.section.StartupMemoryMax = value; return this; } @@ -1318,7 +1318,7 @@ export class ResourceSectionBuilder { * Set resource MemorySwapMax * @see {@link ResourceSectionConfig.MemorySwapMax} */ - public setMemorySwapMax(value: ResourceSectionConfig["MemorySwapMax"]): this { + public setMemorySwapMax(value?: ResourceSectionConfig["MemorySwapMax"]): this { this.section.MemorySwapMax = value; return this; } @@ -1327,7 +1327,7 @@ export class ResourceSectionBuilder { * Set resource StartupMemorySwapMax * @see {@link ResourceSectionConfig.StartupMemorySwapMax} */ - public setStartupMemorySwapMax(value: ResourceSectionConfig["StartupMemorySwapMax"]): this { + public setStartupMemorySwapMax(value?: ResourceSectionConfig["StartupMemorySwapMax"]): this { this.section.StartupMemorySwapMax = value; return this; } @@ -1336,7 +1336,7 @@ export class ResourceSectionBuilder { * Set resource MemoryZSwapMax * @see {@link ResourceSectionConfig.MemoryZSwapMax} */ - public setMemoryZSwapMax(value: ResourceSectionConfig["MemoryZSwapMax"]): this { + public setMemoryZSwapMax(value?: ResourceSectionConfig["MemoryZSwapMax"]): this { this.section.MemoryZSwapMax = value; return this; } @@ -1345,7 +1345,7 @@ export class ResourceSectionBuilder { * Set resource StartupMemoryZSwapMax * @see {@link ResourceSectionConfig.StartupMemoryZSwapMax} */ - public setStartupMemoryZSwapMax(value: ResourceSectionConfig["StartupMemoryZSwapMax"]): this { + public setStartupMemoryZSwapMax(value?: ResourceSectionConfig["StartupMemoryZSwapMax"]): this { this.section.StartupMemoryZSwapMax = value; return this; } @@ -1354,7 +1354,7 @@ export class ResourceSectionBuilder { * Set resource AllowedMemoryNodes * @see {@link ResourceSectionConfig.AllowedMemoryNodes} */ - public setAllowedMemoryNodes(value: ResourceSectionConfig["AllowedMemoryNodes"]): this { + public setAllowedMemoryNodes(value?: ResourceSectionConfig["AllowedMemoryNodes"]): this { this.section.AllowedMemoryNodes = value; return this; } @@ -1363,7 +1363,7 @@ export class ResourceSectionBuilder { * Set resource StartupAllowedMemoryNodes * @see {@link ResourceSectionConfig.StartupAllowedMemoryNodes} */ - public setStartupAllowedMemoryNodes(value: ResourceSectionConfig["StartupAllowedMemoryNodes"]): this { + public setStartupAllowedMemoryNodes(value?: ResourceSectionConfig["StartupAllowedMemoryNodes"]): this { this.section.StartupAllowedMemoryNodes = value; return this; } @@ -1372,7 +1372,7 @@ export class ResourceSectionBuilder { * Set resource TasksAccounting * @see {@link ResourceSectionConfig.TasksAccounting} */ - public setTasksAccounting(value: ResourceSectionConfig["TasksAccounting"]): this { + public setTasksAccounting(value?: ResourceSectionConfig["TasksAccounting"]): this { this.section.TasksAccounting = value; return this; } @@ -1381,7 +1381,7 @@ export class ResourceSectionBuilder { * Set resource TasksMax * @see {@link ResourceSectionConfig.TasksMax} */ - public setTasksMax(value: ResourceSectionConfig["TasksMax"]): this { + public setTasksMax(value?: ResourceSectionConfig["TasksMax"]): this { this.section.TasksMax = value; return this; } diff --git a/packages/conf/src/service.ts b/packages/conf/src/service.ts index 31c69e9..73428eb 100644 --- a/packages/conf/src/service.ts +++ b/packages/conf/src/service.ts @@ -1444,7 +1444,7 @@ export class ServiceSectionBuilder { * Set service SuccessExitStatus * @see {@link ServiceSectionConfig.SuccessExitStatus} */ - public setSuccessExitStatus(successExitStatus: string) { + public setSuccessExitStatus(successExitStatus: ServiceSectionConfig["SuccessExitStatus"]) { this.section.SuccessExitStatus = successExitStatus; return this; } @@ -1452,7 +1452,7 @@ export class ServiceSectionBuilder { * Set service RestartPreventExitStatus * @see {@link ServiceSectionConfig.RestartPreventExitStatus} */ - public setRestartPreventExitStatus(restartPreventExitStatus: string) { + public setRestartPreventExitStatus(restartPreventExitStatus: ServiceSectionConfig["RestartPreventExitStatus"]) { this.section.RestartPreventExitStatus = restartPreventExitStatus; return this; } @@ -1460,7 +1460,7 @@ export class ServiceSectionBuilder { * Set service RestartForceExitStatus * @see {@link ServiceSectionConfig.RestartForceExitStatus} */ - public setRestartForceExitStatus(restartForceExitStatus: string) { + public setRestartForceExitStatus(restartForceExitStatus: ServiceSectionConfig["RestartForceExitStatus"]) { this.section.RestartForceExitStatus = restartForceExitStatus; return this; } @@ -1468,7 +1468,7 @@ export class ServiceSectionBuilder { * Set service RootDirectoryStartOnly * @see {@link ServiceSectionConfig.RootDirectoryStartOnly} */ - public setRootDirectoryStartOnly(rootDirectoryStartOnly: boolean) { + public setRootDirectoryStartOnly(rootDirectoryStartOnly: ServiceSectionConfig["RootDirectoryStartOnly"]) { this.section.RootDirectoryStartOnly = rootDirectoryStartOnly; return this; } @@ -1476,7 +1476,7 @@ export class ServiceSectionBuilder { * Set service NonBlocking * @see {@link ServiceSectionConfig.NonBlocking} */ - public setNonBlocking(nonBlocking: boolean) { + public setNonBlocking(nonBlocking: ServiceSectionConfig["NonBlocking"]) { this.section.NonBlocking = nonBlocking; return this; } @@ -1492,7 +1492,7 @@ export class ServiceSectionBuilder { * Set service Sockets * @see {@link ServiceSectionConfig.Sockets} */ - public setSockets(sockets: string[] | string) { + public setSockets(sockets: ServiceSectionConfig["Sockets"]) { this.section.Sockets = sockets; return this; } @@ -1500,7 +1500,7 @@ export class ServiceSectionBuilder { * Set service FileDescriptorStoreMax * @see {@link ServiceSectionConfig.FileDescriptorStoreMax} */ - public setFileDescriptorStoreMax(fileDescriptorStoreMax: number) { + public setFileDescriptorStoreMax(fileDescriptorStoreMax: ServiceSectionConfig["FileDescriptorStoreMax"]) { this.section.FileDescriptorStoreMax = fileDescriptorStoreMax; return this; } @@ -1519,7 +1519,7 @@ export class ServiceSectionBuilder { * Set service USBFunctionDescriptors * @see {@link ServiceSectionConfig.USBFunctionDescriptors} */ - public setUSBFunctionDescriptors(usbFunctionDescriptors: string) { + public setUSBFunctionDescriptors(usbFunctionDescriptors: ServiceSectionConfig["USBFunctionDescriptors"]) { this.section.USBFunctionDescriptors = usbFunctionDescriptors; return this; } @@ -1528,7 +1528,7 @@ export class ServiceSectionBuilder { * Set service USBFunctionStrings * @see {@link ServiceSectionConfig.USBFunctionStrings} */ - public setUSBFunctionStrings(usbFunctionStrings: string) { + public setUSBFunctionStrings(usbFunctionStrings: ServiceSectionConfig["USBFunctionStrings"]) { this.section.USBFunctionStrings = usbFunctionStrings; return this; } @@ -1583,6 +1583,10 @@ export class Service { this.installSection = new InstallSectionBuilder(Install); } + public getType() { + return 'service' + } + public getServiceSection() { return this.serviceSection; } diff --git a/packages/conf/src/timer.ts b/packages/conf/src/timer.ts index c66e54b..f1fbb49 100644 --- a/packages/conf/src/timer.ts +++ b/packages/conf/src/timer.ts @@ -350,7 +350,7 @@ export class TimerSectionBuilder { * @see {@link TimerSection.OnActiveSec} */ public setOnActiveSec( - onActiveSec: TimerSection["OnActiveSec"] + onActiveSec?: TimerSection["OnActiveSec"] ) { this.section.OnActiveSec = onActiveSec; return this; @@ -361,7 +361,7 @@ export class TimerSectionBuilder { * @see {@link TimerSection.OnBootSec} */ public setOnBootSec( - onBootSec: TimerSection["OnBootSec"] + onBootSec?: TimerSection["OnBootSec"] ) { this.section.OnBootSec = onBootSec; return this; @@ -371,8 +371,9 @@ export class TimerSectionBuilder { * Set timer OnStartupSec * @see {@link TimerSection.OnStartupSec} */ + public setOnStartupSec( - onStartupSec: TimerSection["OnStartupSec"] + onStartupSec?: TimerSection["OnStartupSec"] ) { this.section.OnStartupSec = onStartupSec; return this; @@ -383,7 +384,7 @@ export class TimerSectionBuilder { * @see {@link TimerSection.OnUnitActiveSec} */ public setOnUnitActiveSec( - onUnitActiveSec: TimerSection["OnUnitActiveSec"] + onUnitActiveSec?: TimerSection["OnUnitActiveSec"] ) { this.section.OnUnitActiveSec = onUnitActiveSec; return this; @@ -394,7 +395,7 @@ export class TimerSectionBuilder { * @see {@link TimerSection.OnUnitInactiveSec} */ public setOnUnitInactiveSec( - onUnitInactiveSec: TimerSection["OnUnitInactiveSec"] + onUnitInactiveSec?: TimerSection["OnUnitInactiveSec"] ) { this.section.OnUnitInactiveSec = onUnitInactiveSec; return this; @@ -405,7 +406,7 @@ export class TimerSectionBuilder { * @see {@link TimerSectionConfig.OnCalendar} */ public setOnCalendar( - onCalendar: TimerSectionConfig["OnCalendar"] + onCalendar?: TimerSectionConfig["OnCalendar"] ) { this.section.OnCalendar = onCalendar; return this; @@ -416,7 +417,7 @@ export class TimerSectionBuilder { * @see {@link TimerSectionConfig.AccuracySec} */ public setAccuracySec( - accuracySec: TimerSectionConfig["AccuracySec"] + accuracySec?: TimerSectionConfig["AccuracySec"] ) { this.section.AccuracySec = accuracySec; return this; @@ -427,7 +428,7 @@ export class TimerSectionBuilder { * @see {@link TimerSectionConfig.RandomizedDelaySec} */ public setRandomizedDelaySec( - randomizedDelaySec: TimerSectionConfig["RandomizedDelaySec"] + randomizedDelaySec?: TimerSectionConfig["RandomizedDelaySec"] ) { this.section.RandomizedDelaySec = randomizedDelaySec; return this; @@ -438,7 +439,7 @@ export class TimerSectionBuilder { * @see {@link TimerSectionConfig.FixedRandomDelay} */ public setFixedRandomDelay( - fixedRandomDelay: TimerSectionConfig["FixedRandomDelay"] + fixedRandomDelay?: TimerSectionConfig["FixedRandomDelay"] ) { this.section.FixedRandomDelay = fixedRandomDelay; return this; @@ -449,7 +450,7 @@ export class TimerSectionBuilder { * @see {@link TimerSectionConfig.OnClockChange} */ public setOnClockChange( - onClockChange: TimerSectionConfig["OnClockChange"] + onClockChange?: TimerSectionConfig["OnClockChange"] ) { this.section.OnClockChange = onClockChange; return this; @@ -460,7 +461,7 @@ export class TimerSectionBuilder { * @see {@link TimerSectionConfig.Unit} */ public setUnit( - unit: TimerSectionConfig["Unit"] + unit?: TimerSectionConfig["Unit"] ) { this.section.Unit = unit; return this; @@ -471,7 +472,7 @@ export class TimerSectionBuilder { * @see {@link TimerSectionConfig.Persistent} */ public setPersistent( - persistent: TimerSectionConfig["Persistent"] + persistent?: TimerSectionConfig["Persistent"] ) { this.section.Persistent = persistent; return this; @@ -482,7 +483,7 @@ export class TimerSectionBuilder { * @see {@link TimerSectionConfig.WakeSystem} */ public setWakeSystem( - wakeSystem: TimerSectionConfig["WakeSystem"] + wakeSystem?: TimerSectionConfig["WakeSystem"] ) { this.section.WakeSystem = wakeSystem; return this; @@ -493,7 +494,7 @@ export class TimerSectionBuilder { * @see {@link TimerSectionConfig.RemainAfterElapse} */ public setRemainAfterElapse( - remainAfterElapse: TimerSectionConfig["RemainAfterElapse"] + remainAfterElapse?: TimerSectionConfig["RemainAfterElapse"] ) { this.section.RemainAfterElapse = remainAfterElapse; return this; @@ -521,6 +522,9 @@ export class Timer { this.unitSection = new UnitSectionBuilder(Unit); this.installSection = new InstallSectionBuilder(Install); } + public getType() { + return 'timer' + } public getTimerSection() { return this.timerSection; @@ -534,6 +538,9 @@ export class Timer { return this.installSection; } + /** + * Convert the timer to an object + */ public toObject() { const object = { Unit: this.unitSection.toObject(), @@ -546,6 +553,9 @@ export class Timer { .toObject(); } + /** + * Convert the timer to an INI string + */ public toINIString() { const object = { Unit: this.unitSection.toObject(), @@ -559,7 +569,7 @@ export class Timer { } /** - * Create an service from an object + * Create an timer from an object */ public static fromObject(obj: unknown) { if (obj instanceof Object) { diff --git a/packages/conf/src/types.ts b/packages/conf/src/types.ts new file mode 100644 index 0000000..2f98b1b --- /dev/null +++ b/packages/conf/src/types.ts @@ -0,0 +1,4 @@ +import { Service } from "./service.js"; +import { Timer } from "./timer.js"; + +export type Unit = Service | Timer; diff --git a/packages/conf/src/unit.ts b/packages/conf/src/unit.ts index ceaf188..c90deaf 100644 --- a/packages/conf/src/unit.ts +++ b/packages/conf/src/unit.ts @@ -90,7 +90,7 @@ export interface UnitSection { Added in version 201. */ - Requires?: string[] | string; + Requires?: string; /** Requisite= @@ -106,7 +106,7 @@ export interface UnitSection { Added in version 201. */ - Requisite?: string[] | string; + Requisite?: string; /** BindsTo= @@ -133,7 +133,7 @@ export interface UnitSection { Added in version 201. */ - BindsTo?: string[] | string; + BindsTo?: string; /** PartOf= @@ -148,7 +148,7 @@ export interface UnitSection { Added in version 201. */ - PartOf?: string[] | string; + PartOf?: string; /** Upholds= @@ -165,7 +165,7 @@ export interface UnitSection { Added in version 249. */ - Upholds?: string[] | string; + Upholds?: string; /** Conflicts= @@ -189,7 +189,7 @@ export interface UnitSection { Added in version 201. */ - Conflicts?: string[] | string; + Conflicts?: string; /** Before=, After= @@ -239,13 +239,19 @@ export interface UnitSection { the "failed" state. Added in version 201. + */ + OnFailure?: string; + /** OnSuccess= A space-separated list of one or more units that are activated when this unit enters the "inactive" state. Added in version 249. + */ + OnSuccess?: string; + /** PropagatesReloadTo=, ReloadPropagatedFrom= A space-separated list of one or more units to which reload requests from this unit shall be propagated to, or units from which reload requests shall be propagated to @@ -253,7 +259,10 @@ export interface UnitSection { enqueue reload requests on all units that are linked to it using these two settings. Added in version 201. + */ + PropagatesReloadTo?: string; + /** PropagatesStopTo=, StopPropagatedFrom= A space-separated list of one or more units to which stop requests from this unit shall be propagated to, or units from which stop requests shall be propagated to this @@ -261,7 +270,10 @@ export interface UnitSection { stop requests on all units that are linked to it using these two settings. Added in version 249. + */ + PropagatesStopTo?: string; + /** JoinsNamespaceOf= For units that start processes (such as service units), lists one or more other units whose network and/or temporary file namespace to join. If this is specified on a unit @@ -278,7 +290,10 @@ export interface UnitSection { namespace is joined. Added in version 209. + */ + JoinsNamespaceOf?: string; + /** RequiresMountsFor= Takes a space-separated list of absolute paths. Automatically adds dependencies of type Requires= and After= for all mount units required to access the specified path. @@ -1013,14 +1028,19 @@ export const UnitSectionSchema = implement().with({ Description: z.string().optional(), Documentation: z.union([z.string(), z.array(z.string())]).optional(), Wants: z.union([z.string(), z.array(z.string())]).optional(), - Requires: z.union([z.string(), z.array(z.string())]).optional(), - Requisite: z.union([z.string(), z.array(z.string())]).optional(), - BindsTo: z.union([z.string(), z.array(z.string())]).optional(), - PartOf: z.union([z.string(), z.array(z.string())]).optional(), - Upholds: z.union([z.string(), z.array(z.string())]).optional(), - Conflicts: z.union([z.string(), z.array(z.string())]).optional(), + Requires: z.string().optional(), + Requisite: z.string().optional(), + BindsTo: z.string().optional(), + PartOf: z.string().optional(), + Upholds: z.string().optional(), + Conflicts: z.string().optional(), After: z.union([z.string(), z.array(z.string())]).optional(), Before: z.union([z.string(), z.array(z.string())]).optional(), + OnFailure: z.string().optional(), + OnSuccess: z.string().optional(), + PropagatesReloadTo: z.string().optional(), + PropagatesStopTo: z.string().optional(), + JoinsNamespaceOf: z.string().optional(), }); export class UnitSectionBuilder { @@ -1041,7 +1061,7 @@ export class UnitSectionBuilder { /** * @see {@link UnitSection.Description} */ - public setDescription(description: string) { + public setDescription(description?: string) { this.section.Description = description; return this; } @@ -1049,7 +1069,7 @@ export class UnitSectionBuilder { /** * @see {@link UnitSection.Documentation} */ - public setDocumentation(documentation: string[] | string) { + public setDocumentation(documentation?: string[] | string) { this.section.Documentation = documentation; return this; } @@ -1057,7 +1077,7 @@ export class UnitSectionBuilder { /** * @see {@link UnitSection.Wants} */ - public setWants(wants: string[] | string) { + public setWants(wants?: string) { this.section.Wants = wants; return this; } @@ -1065,7 +1085,7 @@ export class UnitSectionBuilder { /** * @see {@link UnitSection.Requires} */ - public setRequires(requires: string[] | string) { + public setRequires(requires?: string) { this.section.Requires = requires; return this; } @@ -1073,7 +1093,7 @@ export class UnitSectionBuilder { /** * @see {@link UnitSection.Requisite} */ - public setRequisite(requisite: string[] | string) { + public setRequisite(requisite?: string) { this.section.Requisite = requisite; return this; } @@ -1081,7 +1101,7 @@ export class UnitSectionBuilder { /** * @see {@link UnitSection.BindsTo} */ - public setBindsTo(bindsTo: string[] | string) { + public setBindsTo(bindsTo?: string) { this.section.BindsTo = bindsTo; return this; } @@ -1089,7 +1109,7 @@ export class UnitSectionBuilder { /** * @see {@link UnitSection.PartOf} */ - public setPartOf(partOf: string[] | string) { + public setPartOf(partOf?: string) { this.section.PartOf = partOf; return this; } @@ -1097,7 +1117,7 @@ export class UnitSectionBuilder { /** * @see {@link UnitSection.Upholds} */ - public setUpholds(upholds: string[] | string) { + public setUpholds(upholds?: string) { this.section.Upholds = upholds; return this; } @@ -1105,7 +1125,7 @@ export class UnitSectionBuilder { /** * @see {@link UnitSection.Conflicts} */ - public setConflicts(conflicts: string[] | string) { + public setConflicts(conflicts?: string) { this.section.Conflicts = conflicts; return this; } @@ -1113,7 +1133,7 @@ export class UnitSectionBuilder { /** * @see {@link UnitSection.After} */ - public setAfter(after: string[] | string) { + public setAfter(after?: string[] | string) { this.section.After = after; return this; } @@ -1121,10 +1141,48 @@ export class UnitSectionBuilder { /** * @see {@link UnitSection.Before} */ - public setBefore(before: string[] | string) { + public setBefore(before?: string[] | string) { this.section.Before = before; return this; } - + /** + * @see {@link UnitSection.OnFailure} + */ + public setOnFailure(onFailure?: string) { + this.section.OnFailure = onFailure; + return this; + } + + /** + * @see {@link UnitSection.OnSuccess} + */ + public setOnSuccess(onSuccess?: string) { + this.section.OnSuccess = onSuccess; + return this; + } + + /** + * @see {@link UnitSection.PropagatesReloadTo} + */ + public setPropagatesReloadTo(propagatesReloadTo?: string) { + this.section.PropagatesReloadTo = propagatesReloadTo; + return this; + } + + /** + * @see {@link UnitSection.PropagatesStopTo} + */ + public setPropagatesStopTo(propagatesStopTo?: string) { + this.section.PropagatesStopTo = propagatesStopTo; + return this; + } + + /** + * @see {@link UnitSection.JoinsNamespaceOf} + */ + public setJoinsNamespaceOf(joinsNamespaceOf?: string) { + this.section.JoinsNamespaceOf = joinsNamespaceOf; + return this; + } } From a157297b12690d14a3426df32897851ee1c6dc39 Mon Sep 17 00:00:00 2001 From: chyzwar Date: Sun, 26 May 2024 13:48:04 +0200 Subject: [PATCH 2/6] feat(ctl): new package for interfacing with systemctl --- packages/ctl/Readme.md | 57 ++++++++++++ packages/ctl/package.json | 47 ++++++++++ packages/ctl/src/ctl.ts | 157 ++++++++++++++++++++++++++++++++++ packages/ctl/src/index.ts | 10 +++ packages/ctl/tsconfig.json | 13 +++ packages/ctl/vitest.config.ts | 8 ++ 6 files changed, 292 insertions(+) create mode 100644 packages/ctl/Readme.md create mode 100644 packages/ctl/package.json create mode 100644 packages/ctl/src/ctl.ts create mode 100644 packages/ctl/src/index.ts create mode 100644 packages/ctl/tsconfig.json create mode 100644 packages/ctl/vitest.config.ts diff --git a/packages/ctl/Readme.md b/packages/ctl/Readme.md new file mode 100644 index 0000000..2c18307 --- /dev/null +++ b/packages/ctl/Readme.md @@ -0,0 +1,57 @@ + +## @systemd-js/ctl + +Control over units. Interface to systemctl. +At the moment this lack proper error handling. + +### Installation + +```sh +yarn add @systemd-js/ctl +``` + +### Examples + +State manipulation of existing service. + +```ts +import {Ctl} from "@systemd-js/ctl"; + +const ctl = new Ctl("test.service") + +ctl.disable() +ctl.enable() +ctl.stop() +ctl.start() +ctl.restart() + +``` + +Creation of new service "example.service" + +```ts +import {Service} from "@systemd-js/config"; +import {Ctl} from "@systemd-js/ctl"; + +const service = new Service(); + +service + .getUnitSection() + .setDescription("This is a example unit") + +service + .getInstallSection() + .setWantedBy("multi-user.target") + +service + .getServiceSection() + .setType("simple") + .setExecStart("/usr/bin/echo 'Hello World'") + +const ctl = new Ctl("example", service) + +ctl.create() +ctl.enable() +ctl.start() + +``` diff --git a/packages/ctl/package.json b/packages/ctl/package.json new file mode 100644 index 0000000..f587dc8 --- /dev/null +++ b/packages/ctl/package.json @@ -0,0 +1,47 @@ +{ + "name": "@systemd-js/ctl", + "version": "0.1.2", + "engines": { + "node": "20.x", + "yarn": "4.x" + }, + "repository": { + "type": "git", + "url": "https://github.com/chyzwar/systemd" + }, + "sideEffects": false, + "publishConfig": { + "access": "public" + }, + "main": "lib/index.js", + "type": "module", + "author": "chyzwar", + "license": "Apache-2.0", + "description": "Controlling runtime of systemd units", + "keywords": [ + "systemd", + "systemctl", + "systemd-timer", + "systemd-service" + ], + "scripts": { + "lint": "eslint . --cache", + "lint:fix": "eslint . --fix --cache", + "build": "tsc --build", + "build:watch": "tsc --build --watch", + "test": "vitest --run", + "test:coverage": "vitest --coverage", + "test:watch": "vitest" + }, + "dependencies": { + "@systemd-js/ctl": "^0.1.2" + }, + "devDependencies": { + "@chyzwar/eslint-config": "^0.2.26", + "@chyzwar/tsconfig": "^0.2.26", + "@types/node": "^20.12.12", + "eslint": "^9.2.0", + "typescript": "^5.4.5", + "vitest": "^1.6.0" + } +} diff --git a/packages/ctl/src/ctl.ts b/packages/ctl/src/ctl.ts new file mode 100644 index 0000000..182f336 --- /dev/null +++ b/packages/ctl/src/ctl.ts @@ -0,0 +1,157 @@ +import { execSync } from "node:child_process"; +import { existsSync, readFileSync, writeFileSync } from "node:fs"; +import { INI, Service, Timer, Unit } from "@systemd-js/conf"; +import { extname } from "node:path"; + + +const getType = (name: string, unit?: Unit) => { + if(unit) { + return unit.getType(); + } + const type = extname(name).slice(1); + if (!type) { + throw new Error(`Unit type not found in name: ${name}`); + } + return type; +}; + +const getName = (name: string) => { + const type = extname(name); + if (!type) { + return name; + } + return name.replace(type, ""); +}; + +const getPath = (name: string, type: string) => { + return `/etc/systemd/system/${name}.${type}`; +}; + +const getUnit = (unitName: string, type: string = getType(unitName)): Unit | undefined => { + const name = getName(unitName); + const path = `/etc/systemd/system/${name}.${type}`; + + if (existsSync(path)) { + const content = readFileSync(path, "utf-8"); + switch (type) { + case "service": { + const ini = INI.fromString(content); + const unit = Service.fromINI(ini); + return unit; + } + case "timer": { + const ini = INI.fromString(content); + const unit = Timer.fromINI(ini); + return unit; + } + default: + throw new Error(`Unit type not supported: ${type}`); + } + } + return; +}; + +export class Ctl { + private type: string; + private name: string; + private path: string; + + private unit?: Unit; + private current?: Unit; + + constructor(name: string, unit?: Unit) { + this.name = getName(name); + this.type = getType(name, unit); + this.current = getUnit( + this.name, + this.type, + ); + this.path = getPath( + this.name, + this.type, + ); + this.unit = unit; + } + + public create() { + if (!this.unit) { + throw new Error("Unit not found"); + } + const unitString = this.unit.toINIString(); + const currentUnit = this.current?.toINIString(); + + if (currentUnit !== unitString) { + writeFileSync(this.path, unitString); + } + } + + public enable() { + execSync(`systemctl enable ${this.name}.${this.type}`); + } + + public disable() { + execSync(`systemctl disable ${this.name}.${this.type}`); + } + + public start() { + execSync(`systemctl start ${this.name}.${this.type}`); + } + + public stop() { + execSync(`systemctl stop ${this.name}.${this.type}`); + } + + public restart() { + execSync(`systemctl restart ${this.name}.${this.type}`); + } +} + +export function createUnit(unitName: string, unit: Unit) { + const name = getName(unitName); + const type = getType(unitName, unit); + const path = getPath (name, type); + + const current = getUnit(name, type); + const currentUnit = current?.toINIString(); + const unitString = unit.toINIString(); + + if (currentUnit !== unitString) { + writeFileSync(path, unitString); + } +} + +export function enableUnit(unitName: string, unit?: Unit) { + const type = getType(unitName, unit); + const name = getName(unitName); + + execSync(`systemctl enable ${name}.${type}`); +} + +export function disableUnit(unitName: string, unit?: Unit) { + const type = getType(unitName, unit); + const name = getName(unitName); + + execSync(`systemctl disable ${name}.${type}`); +} + +export function startUnit(unitName: string, unit?: Unit) { + const type = getType(unitName, unit); + const name = getName(unitName); + + execSync(`systemctl start ${name}.${type}`); +} + +export function stopUnit(unitName: string, unit?: Unit) { + const type = getType(unitName, unit); + const name = getName(unitName); + + execSync(`systemctl stop ${name}.${type}`); +} + +export function restartUnit(unitName: string, unit?: Unit) { + const type = getType(unitName, unit); + const name = getName(unitName); + + execSync(`systemctl restart ${name}.${type}`); +} + diff --git a/packages/ctl/src/index.ts b/packages/ctl/src/index.ts new file mode 100644 index 0000000..d17dc82 --- /dev/null +++ b/packages/ctl/src/index.ts @@ -0,0 +1,10 @@ +export { + Ctl, + + createUnit, + enableUnit, + disableUnit, + startUnit, + stopUnit, + restartUnit, +} from "./ctl.js"; diff --git a/packages/ctl/tsconfig.json b/packages/ctl/tsconfig.json new file mode 100644 index 0000000..e148df7 --- /dev/null +++ b/packages/ctl/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "@chyzwar/tsconfig/lib.json", + "compilerOptions": { + "target": "ES2022", + "outDir": "lib", + "rootDir": "src", + "composite": false, + "tsBuildInfoFile": "./lib/buildInfo.json" + }, + "include": [ + "src/**/*" + ] +} diff --git a/packages/ctl/vitest.config.ts b/packages/ctl/vitest.config.ts new file mode 100644 index 0000000..4d797ee --- /dev/null +++ b/packages/ctl/vitest.config.ts @@ -0,0 +1,8 @@ +import { defineProject } from "vitest/config"; + + +export default defineProject({ + test: { + + }, +}); \ No newline at end of file From fbf3ed4589a08e6ec878635fe9c8bbb36f377fdb Mon Sep 17 00:00:00 2001 From: chyzwar Date: Sun, 26 May 2024 13:48:39 +0200 Subject: [PATCH 3/6] chore(root): tweaks in lerna and new package --- lerna.json | 12 +++++++++--- tsconfig.json | 1 + vitest.workspace.ts | 3 ++- yarn.lock | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lerna.json b/lerna.json index 324b253..8976402 100644 --- a/lerna.json +++ b/lerna.json @@ -8,14 +8,20 @@ "version": "0.1.3", "changelogPreset": "conventional-changelog-conventionalcommits", "command": { + "publish": { + "cleanupTempFiles": true, + "removePackageFields": [ + "devDependencies", + "scripts" + ] + }, "version": { - "noPrivate": true, - "skipBumpOnlyReleases": true, "conventionalCommits": true, "syncWorkspaceLock": true, "createRelease": "github", - "message": "chore(release): new versions", + "message": "chore(release): publish new version %v", "changelogIncludeCommitsClientLogin": " - by @%l", + "changelogHeaderMessage": "## Manage systemd services with Node.js", "allowBranch": "master", "ignoreChanges": [ "yarn.lock" diff --git a/tsconfig.json b/tsconfig.json index 1c5d2d3..53f56e2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,5 +9,6 @@ "include": [], "references": [ {"path": "./packages/conf"}, + {"path": "./packages/ctl"}, ] } diff --git a/vitest.workspace.ts b/vitest.workspace.ts index eb04b17..8cbc080 100644 --- a/vitest.workspace.ts +++ b/vitest.workspace.ts @@ -1,7 +1,8 @@ import { defineWorkspace } from "vitest/config"; const projects = [ - "conf", + "conf", + "ctl" ]; export default defineWorkspace( diff --git a/yarn.lock b/yarn.lock index e8fffe2..fb0427e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1186,6 +1186,20 @@ __metadata: languageName: unknown linkType: soft +"@systemd-js/ctl@npm:^0.1.2, @systemd-js/ctl@workspace:packages/ctl": + version: 0.0.0-use.local + resolution: "@systemd-js/ctl@workspace:packages/ctl" + dependencies: + "@chyzwar/eslint-config": "npm:^0.2.26" + "@chyzwar/tsconfig": "npm:^0.2.26" + "@systemd-js/ctl": "npm:^0.1.2" + "@types/node": "npm:^20.12.12" + eslint: "npm:^9.2.0" + typescript: "npm:^5.4.5" + vitest: "npm:^1.6.0" + languageName: unknown + linkType: soft + "@systemd/root@workspace:.": version: 0.0.0-use.local resolution: "@systemd/root@workspace:." From 808bd60e38a14210d89536231f8f9b5d43ab665c Mon Sep 17 00:00:00 2001 From: chyzwar Date: Sun, 26 May 2024 22:22:41 +0200 Subject: [PATCH 4/6] feat(conf): improve docs, fix lint issues --- packages/conf/package.json | 2 +- packages/conf/src/__tests__/Ini.test.ts | 4 ++-- packages/conf/src/index.ts | 4 ++-- packages/conf/src/service.ts | 16 ++++++++++++++-- packages/conf/src/timer.ts | 16 ++++++++++++++-- packages/conf/src/types.ts | 6 +++--- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/packages/conf/package.json b/packages/conf/package.json index f3a1208..53c0e38 100644 --- a/packages/conf/package.json +++ b/packages/conf/package.json @@ -40,7 +40,7 @@ "@chyzwar/eslint-config": "^0.2.26", "@chyzwar/tsconfig": "^0.2.26", "@types/node": "^20.12.12", - "eslint": "^9.2.0", + "eslint": "^9.3.0", "typescript": "^5.4.5", "vitest": "^1.6.0" } diff --git a/packages/conf/src/__tests__/Ini.test.ts b/packages/conf/src/__tests__/Ini.test.ts index 6f993fc..6f2c8c9 100644 --- a/packages/conf/src/__tests__/Ini.test.ts +++ b/packages/conf/src/__tests__/Ini.test.ts @@ -54,7 +54,7 @@ User=root const unitOnlyDesc = ` [Unit] Description=example -` +`; describe("INI - fromString", () => { test("should parse INI data", () => { @@ -92,7 +92,7 @@ describe("INI - fromString", () => { const ini = INI.fromObject(obj); const result = ini.toString(); expect(result.trim()).toEqual(unitOnlyDesc.trim()); - }) + }); test("should parse INI data with line dataUnitWithBackslash", () => { const expected = { diff --git a/packages/conf/src/index.ts b/packages/conf/src/index.ts index 10d5871..d798b68 100644 --- a/packages/conf/src/index.ts +++ b/packages/conf/src/index.ts @@ -27,7 +27,7 @@ export { TimerSectionBuilder, } from "./timer.js"; -export { - Unit +export type { + Unit, } from "./types.js"; diff --git a/packages/conf/src/service.ts b/packages/conf/src/service.ts index 73428eb..d2589eb 100644 --- a/packages/conf/src/service.ts +++ b/packages/conf/src/service.ts @@ -1583,18 +1583,30 @@ export class Service { this.installSection = new InstallSectionBuilder(Install); } - public getType() { - return 'service' + public static getType() { + return "service"; } + /** + * Get builder for [Service] section + * @returns {ServiceSectionBuilder} Unit section + */ public getServiceSection() { return this.serviceSection; } + /** + * Get builder for [Unit] section + * @returns {UnitSectionBuilder} Unit section + */ public getUnitSection() { return this.unitSection; } + /** + * Get builder for [Install] section + * @returns {InstallSectionBuilder} Install section + */ public getInstallSection() { return this.installSection; } diff --git a/packages/conf/src/timer.ts b/packages/conf/src/timer.ts index f1fbb49..e75c196 100644 --- a/packages/conf/src/timer.ts +++ b/packages/conf/src/timer.ts @@ -522,18 +522,30 @@ export class Timer { this.unitSection = new UnitSectionBuilder(Unit); this.installSection = new InstallSectionBuilder(Install); } - public getType() { - return 'timer' + public static getType() { + return "timer"; } + /** + * Get the [Timer] section of the timer + * @returns {TimerSectionBuilder} + */ public getTimerSection() { return this.timerSection; } + /** + * Get the [Unit] section of the timer + * @returns {UnitSectionBuilder} + */ public getUnitSection() { return this.unitSection; } + /** + * Get the [Install] section of the timer + * @returns {InstallSectionBuilder} + */ public getInstallSection() { return this.installSection; } diff --git a/packages/conf/src/types.ts b/packages/conf/src/types.ts index 2f98b1b..0037ec2 100644 --- a/packages/conf/src/types.ts +++ b/packages/conf/src/types.ts @@ -1,4 +1,4 @@ -import { Service } from "./service.js"; -import { Timer } from "./timer.js"; +import type { Service } from "./service.js"; +import type { Timer } from "./timer.js"; -export type Unit = Service | Timer; +export type Unit = Service | Timer; From 0813ad5b6bbb81498abca04b4d24c495c0559ddc Mon Sep 17 00:00:00 2001 From: chyzwar Date: Sun, 26 May 2024 22:23:16 +0200 Subject: [PATCH 5/6] chore(ctl): lint fixes --- packages/ctl/package.json | 2 +- packages/ctl/src/ctl.ts | 55 ++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/packages/ctl/package.json b/packages/ctl/package.json index f587dc8..150dc0e 100644 --- a/packages/ctl/package.json +++ b/packages/ctl/package.json @@ -40,7 +40,7 @@ "@chyzwar/eslint-config": "^0.2.26", "@chyzwar/tsconfig": "^0.2.26", "@types/node": "^20.12.12", - "eslint": "^9.2.0", + "eslint": "^9.3.0", "typescript": "^5.4.5", "vitest": "^1.6.0" } diff --git a/packages/ctl/src/ctl.ts b/packages/ctl/src/ctl.ts index 182f336..8522f7f 100644 --- a/packages/ctl/src/ctl.ts +++ b/packages/ctl/src/ctl.ts @@ -1,12 +1,14 @@ +/* eslint-disable @typescript-eslint/consistent-return */ import { execSync } from "node:child_process"; import { existsSync, readFileSync, writeFileSync } from "node:fs"; -import { INI, Service, Timer, Unit } from "@systemd-js/conf"; +import type { Unit } from "@systemd-js/conf"; +import { INI, Service, Timer } from "@systemd-js/conf"; import { extname } from "node:path"; -const getType = (name: string, unit?: Unit) => { +const getType = (name: string, unit?: Unit): string => { if(unit) { - return unit.getType(); + return (unit.constructor as typeof Service).getType(); } const type = extname(name).slice(1); if (!type) { @@ -31,44 +33,43 @@ const getUnit = (unitName: string, type: string = getType(unitName)): Unit | und const name = getName(unitName); const path = `/etc/systemd/system/${name}.${type}`; - if (existsSync(path)) { - const content = readFileSync(path, "utf-8"); - switch (type) { - case "service": { - const ini = INI.fromString(content); - const unit = Service.fromINI(ini); - return unit; - } - case "timer": { - const ini = INI.fromString(content); - const unit = Timer.fromINI(ini); - return unit; - } - default: - throw new Error(`Unit type not supported: ${type}`); + if (!existsSync(path)) { + return; + } + + const content = readFileSync(path, "utf-8"); + switch (type) { + case "service": { + const ini = INI.fromString(content); + return Service.fromINI(ini); + } + case "timer": { + const ini = INI.fromString(content); + return Timer.fromINI(ini); } + default: + throw new Error(`Unit type not supported: ${type}`); } - return; }; export class Ctl { - private type: string; - private name: string; - private path: string; + private readonly type: string; + private readonly name: string; + private readonly path: string; - private unit?: Unit; - private current?: Unit; + private readonly unit?: Unit; + private readonly current?: Unit; - constructor(name: string, unit?: Unit) { + public constructor(name: string, unit?: Unit) { this.name = getName(name); this.type = getType(name, unit); this.current = getUnit( this.name, - this.type, + this.type ); this.path = getPath( this.name, - this.type, + this.type ); this.unit = unit; } From 8652bcadfffd436001ca0c3bd645c2a8bdde4a61 Mon Sep 17 00:00:00 2001 From: chyzwar Date: Sun, 26 May 2024 22:24:00 +0200 Subject: [PATCH 6/6] chore(root): update deps --- .vscode/settings.json | 1 + package.json | 4 +- vitest.workspace.ts | 2 +- yarn.lock | 165 ++++++++++++++++++++++++++---------------- 4 files changed, 105 insertions(+), 67 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c85cfc2..3cababd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "eslint.enable": true, "editor.formatOnSave": true, + "eslint.experimental.useFlatConfig": true, "[typescript]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" } diff --git a/package.json b/package.json index 7598feb..386ef20 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,9 @@ "@lerna-lite/version": "^3.4.0", "@types/node": "^20.12.12", "conventional-changelog-conventionalcommits": "^7.0.2", - "eslint": "^9.2.0", + "eslint": "^9.3.0", "husky": "^9.0.11", - "lint-staged": "^15.2.2", + "lint-staged": "^15.2.5", "ts-node": "^10.9.2", "typescript": "^5.4.5", "vitest": "^1.6.0" diff --git a/vitest.workspace.ts b/vitest.workspace.ts index 8cbc080..d9fe53d 100644 --- a/vitest.workspace.ts +++ b/vitest.workspace.ts @@ -2,7 +2,7 @@ import { defineWorkspace } from "vitest/config"; const projects = [ "conf", - "ctl" + "ctl", ]; export default defineWorkspace( diff --git a/yarn.lock b/yarn.lock index fb0427e..184396c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -437,9 +437,9 @@ __metadata: languageName: node linkType: hard -"@eslint/eslintrc@npm:^3.0.2": - version: 3.0.2 - resolution: "@eslint/eslintrc@npm:3.0.2" +"@eslint/eslintrc@npm:^3.1.0": + version: 3.1.0 + resolution: "@eslint/eslintrc@npm:3.1.0" dependencies: ajv: "npm:^6.12.4" debug: "npm:^4.3.2" @@ -450,11 +450,18 @@ __metadata: js-yaml: "npm:^4.1.0" minimatch: "npm:^3.1.2" strip-json-comments: "npm:^3.1.1" - checksum: 10c2/9e116bbab4cbd7666cefd5e99901067ce6a19dfd52fe94a95b69756d80139463b4fd8564581d328d47f0f796f5a62193fe0351c9af6df12b1e93a3368a8a84eb + checksum: 10c2/015cf3f926adaf5d7c68c04ad1529ff04b490ea6f7496c096364c4617f708fdc5a38a47dde1cbb5f69a4a190b8d6b0cd48268f464f5a25c5269a18841ede7509 + languageName: node + linkType: hard + +"@eslint/js@npm:9.3.0": + version: 9.3.0 + resolution: "@eslint/js@npm:9.3.0" + checksum: 10c2/e608c847c7ac483a3ae0146383f239fa13b342aab9abb6ec2f73fa12d4da2b04cf3e062366bf0b80fcce281d53386e4fba7297542da50506a22141e978c2e3bf languageName: node linkType: hard -"@eslint/js@npm:9.2.0, @eslint/js@npm:^9.2.0": +"@eslint/js@npm:^9.2.0": version: 9.2.0 resolution: "@eslint/js@npm:9.2.0" checksum: 10c2/cbf7f82da19c2e294f4d08758777b4fc1fcbfbe953630fbebe0c3f01535698d3f7b2689b6783150e5d6b8ae19f194be4fa0f0ed626099b54c2e04251bb501f3f @@ -486,10 +493,10 @@ __metadata: languageName: node linkType: hard -"@humanwhocodes/retry@npm:^0.2.3": - version: 0.2.4 - resolution: "@humanwhocodes/retry@npm:0.2.4" - checksum: 10c2/01c575b49774bafa3270577e7b4e2ddee56a6fdee4d7e2683604cbe103187243bcc0ef02118ae2abe9d1156b11ba34fe0df07240cbfa7f6e77379455c4aed6da +"@humanwhocodes/retry@npm:^0.3.0": + version: 0.3.0 + resolution: "@humanwhocodes/retry@npm:0.3.0" + checksum: 10c2/783288a12b780f13e480b71c3f0772df42820282370ec4e55b9cbbc4ba867521192660b1bf9dc76d082745853c5fb81a5c8135a614435ec7351fda2d1cfd9dc9 languageName: node linkType: hard @@ -1179,7 +1186,7 @@ __metadata: "@chyzwar/eslint-config": "npm:^0.2.26" "@chyzwar/tsconfig": "npm:^0.2.26" "@types/node": "npm:^20.12.12" - eslint: "npm:^9.2.0" + eslint: "npm:^9.3.0" typescript: "npm:^5.4.5" vitest: "npm:^1.6.0" zod: "npm:^3.23.8" @@ -1194,7 +1201,7 @@ __metadata: "@chyzwar/tsconfig": "npm:^0.2.26" "@systemd-js/ctl": "npm:^0.1.2" "@types/node": "npm:^20.12.12" - eslint: "npm:^9.2.0" + eslint: "npm:^9.3.0" typescript: "npm:^5.4.5" vitest: "npm:^1.6.0" languageName: unknown @@ -1212,9 +1219,9 @@ __metadata: "@lerna-lite/version": "npm:^3.4.0" "@types/node": "npm:^20.12.12" conventional-changelog-conventionalcommits: "npm:^7.0.2" - eslint: "npm:^9.2.0" + eslint: "npm:^9.3.0" husky: "npm:^9.0.11" - lint-staged: "npm:^15.2.2" + lint-staged: "npm:^15.2.5" ts-node: "npm:^10.9.2" typescript: "npm:^5.4.5" vitest: "npm:^1.6.0" @@ -1754,6 +1761,15 @@ __metadata: languageName: node linkType: hard +"braces@npm:^3.0.3": + version: 3.0.3 + resolution: "braces@npm:3.0.3" + dependencies: + fill-range: "npm:^7.1.1" + checksum: 10c2/0fcf8974fcdf6acab83ea526fad9697c0f7b67c1c0306a889e6c0f472592a6772ecef17f4599358789be50d2367bb7f6222279ef6ae27de3a9448c6804d5b46a + languageName: node + linkType: hard + "buffer@npm:^5.5.0": version: 5.7.1 resolution: "buffer@npm:5.7.1" @@ -1833,13 +1849,6 @@ __metadata: languageName: node linkType: hard -"chalk@npm:5.3.0, chalk@npm:^5.3.0": - version: 5.3.0 - resolution: "chalk@npm:5.3.0" - checksum: 10c2/8d82f3c487711bdc3491929e26faa8cabb618e24788516c53db26bd2dc924ae4cc73631481640536d641a74f929bdeb292057a2633e6ef0b74af4d4fad575daf - languageName: node - linkType: hard - "chalk@npm:^2.4.2": version: 2.4.2 resolution: "chalk@npm:2.4.2" @@ -1861,6 +1870,13 @@ __metadata: languageName: node linkType: hard +"chalk@npm:^5.3.0, chalk@npm:~5.3.0": + version: 5.3.0 + resolution: "chalk@npm:5.3.0" + checksum: 10c2/8d82f3c487711bdc3491929e26faa8cabb618e24788516c53db26bd2dc924ae4cc73631481640536d641a74f929bdeb292057a2633e6ef0b74af4d4fad575daf + languageName: node + linkType: hard + "chardet@npm:^0.7.0": version: 0.7.0 resolution: "chardet@npm:0.7.0" @@ -2034,10 +2050,10 @@ __metadata: languageName: node linkType: hard -"commander@npm:11.1.0": - version: 11.1.0 - resolution: "commander@npm:11.1.0" - checksum: 10c2/78ada0c4ad35447fd7a5bf66aecdf0ad0e5055e25a8b0f3c789abadd05cdc0657499a63a7cd36459253336fe4d3382003ed720155f733f2199c0017df5af5f72 +"commander@npm:~12.1.0": + version: 12.1.0 + resolution: "commander@npm:12.1.0" + checksum: 10c2/53472625adf5926e1a55748cb710f1e1ba2424b0d711c43b85011807aa15997a4153197d94d10f7b8eb8569eed25761964f6dd4de6a4e8d8a8d642eb4b850cdc languageName: node linkType: hard @@ -2240,7 +2256,7 @@ __metadata: languageName: node linkType: hard -"debug@npm:4, debug@npm:4.3.4, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.4": +"debug@npm:4, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.4, debug@npm:~4.3.4": version: 4.3.4 resolution: "debug@npm:4.3.4" dependencies: @@ -2595,17 +2611,17 @@ __metadata: languageName: node linkType: hard -"eslint@npm:^9.2.0": - version: 9.2.0 - resolution: "eslint@npm:9.2.0" +"eslint@npm:^9.3.0": + version: 9.3.0 + resolution: "eslint@npm:9.3.0" dependencies: "@eslint-community/eslint-utils": "npm:^4.2.0" "@eslint-community/regexpp": "npm:^4.6.1" - "@eslint/eslintrc": "npm:^3.0.2" - "@eslint/js": "npm:9.2.0" + "@eslint/eslintrc": "npm:^3.1.0" + "@eslint/js": "npm:9.3.0" "@humanwhocodes/config-array": "npm:^0.13.0" "@humanwhocodes/module-importer": "npm:^1.0.1" - "@humanwhocodes/retry": "npm:^0.2.3" + "@humanwhocodes/retry": "npm:^0.3.0" "@nodelib/fs.walk": "npm:^1.2.8" ajv: "npm:^6.12.4" chalk: "npm:^4.0.0" @@ -2635,7 +2651,7 @@ __metadata: text-table: "npm:^0.2.0" bin: eslint: bin/eslint.js - checksum: 10c2/212f3b4fd4b5532ab7b9a5e55c0533910d9bbb7bc2c7e4cfb1ee2417a24a7fa31110c4c926cc9264ec5ad157b3581e0f51bfff36f8dae1e5e710285215d0e419 + checksum: 10c2/118101d606880d7f657ba6859e82989a48866f48bda01df450b8e868616d227875b565e177a748291c1f210238f16e62ff7eb35cd26b8bbe8455edeb4655c38d languageName: node linkType: hard @@ -2698,7 +2714,7 @@ __metadata: languageName: node linkType: hard -"execa@npm:8.0.1, execa@npm:^8.0.1": +"execa@npm:^8.0.1, execa@npm:~8.0.1": version: 8.0.1 resolution: "execa@npm:8.0.1" dependencies: @@ -2804,6 +2820,15 @@ __metadata: languageName: node linkType: hard +"fill-range@npm:^7.1.1": + version: 7.1.1 + resolution: "fill-range@npm:7.1.1" + dependencies: + to-regex-range: "npm:^5.0.1" + checksum: 10c2/1fad086c1d028caf894f8e97ba71d7552a4cc1d26ee34673207f7577c9f539f8332cd6e9acb9012c3b5bb18da828bbbc09cbfb066863d79550c4ac48976c9698 + languageName: node + linkType: hard + "find-up@npm:^4.0.0": version: 4.1.0 resolution: "find-up@npm:4.1.0" @@ -3829,10 +3854,10 @@ __metadata: languageName: node linkType: hard -"lilconfig@npm:3.0.0": - version: 3.0.0 - resolution: "lilconfig@npm:3.0.0" - checksum: 10c2/a2047af44a92a865882e5bc769097b2d3497a47dd4fe23f22970ae4856f2e3d964786a2ed97283f66aeb5af00e91045a5e9f53291be70058287292ccb37624e9 +"lilconfig@npm:~3.1.1": + version: 3.1.1 + resolution: "lilconfig@npm:3.1.1" + checksum: 10c2/82e15560ca7601b35a02121440bb661027a712404ddd6a27439353c74ef38702516091fce22add79a6bb3f4962cf2be1f228e95a0b1a624849ea9b3343b2a0e7 languageName: node linkType: hard @@ -3850,37 +3875,37 @@ __metadata: languageName: node linkType: hard -"lint-staged@npm:^15.2.2": - version: 15.2.2 - resolution: "lint-staged@npm:15.2.2" +"lint-staged@npm:^15.2.5": + version: 15.2.5 + resolution: "lint-staged@npm:15.2.5" dependencies: - chalk: "npm:5.3.0" - commander: "npm:11.1.0" - debug: "npm:4.3.4" - execa: "npm:8.0.1" - lilconfig: "npm:3.0.0" - listr2: "npm:8.0.1" - micromatch: "npm:4.0.5" - pidtree: "npm:0.6.0" - string-argv: "npm:0.3.2" - yaml: "npm:2.3.4" + chalk: "npm:~5.3.0" + commander: "npm:~12.1.0" + debug: "npm:~4.3.4" + execa: "npm:~8.0.1" + lilconfig: "npm:~3.1.1" + listr2: "npm:~8.2.1" + micromatch: "npm:~4.0.7" + pidtree: "npm:~0.6.0" + string-argv: "npm:~0.3.2" + yaml: "npm:~2.4.2" bin: lint-staged: bin/lint-staged.js - checksum: 10c2/a7eaddc88e969b6d0a4f22e224dda616c4008292feb0e0e4ee5888f06df96d117ae13c5b86d4015c051097f700716121619b66b4017abacab25af7d2509e30dd + checksum: 10c2/204eb8e4d446a6ee0024e3a11eb4dced515cb7820de8c14df58a00a9e64db58723bde9a1da2903fe80acc95d650c37c074c6688bdeb26129f00a219b478740d6 languageName: node linkType: hard -"listr2@npm:8.0.1": - version: 8.0.1 - resolution: "listr2@npm:8.0.1" +"listr2@npm:~8.2.1": + version: 8.2.1 + resolution: "listr2@npm:8.2.1" dependencies: cli-truncate: "npm:^4.0.0" colorette: "npm:^2.0.20" eventemitter3: "npm:^5.0.1" log-update: "npm:^6.0.0" - rfdc: "npm:^1.3.0" + rfdc: "npm:^1.3.1" wrap-ansi: "npm:^9.0.0" - checksum: 10c2/257e359ce2484f06828995c6667a90d48ccbc453d3addd23da863a4e3d87f8cf92ffdfe4bcc27dbc7b2605a1d4d81764d15d45eb1fb881046f72b3c910bc41c9 + checksum: 10c2/4edf1120989ba4963155f6e47b04e03bc5a698c388150b856cbc0a3f7e5102132e729614a8b9d309078129e8477f40672b727f914be59b8399e2d510f4e70230 languageName: node linkType: hard @@ -4101,7 +4126,7 @@ __metadata: languageName: node linkType: hard -"micromatch@npm:4.0.5, micromatch@npm:^4.0.4": +"micromatch@npm:^4.0.4": version: 4.0.5 resolution: "micromatch@npm:4.0.5" dependencies: @@ -4111,6 +4136,16 @@ __metadata: languageName: node linkType: hard +"micromatch@npm:~4.0.7": + version: 4.0.7 + resolution: "micromatch@npm:4.0.7" + dependencies: + braces: "npm:^3.0.3" + picomatch: "npm:^2.3.1" + checksum: 10c2/87e6ea4885904df63cb654dae478ef4f7c22e068672f518ae5ea52f715eccb745a356749a21d125afddd24fe5c0f8fd6c42e8be132fb30ff32a5d73d2598dc3b + languageName: node + linkType: hard + "mimic-fn@npm:^2.1.0": version: 2.1.0 resolution: "mimic-fn@npm:2.1.0" @@ -4872,7 +4907,7 @@ __metadata: languageName: node linkType: hard -"pidtree@npm:0.6.0": +"pidtree@npm:~0.6.0": version: 0.6.0 resolution: "pidtree@npm:0.6.0" bin: @@ -5133,7 +5168,7 @@ __metadata: languageName: node linkType: hard -"rfdc@npm:^1.3.0": +"rfdc@npm:^1.3.1": version: 1.3.1 resolution: "rfdc@npm:1.3.1" checksum: 10c2/de398400f451f99756da7262752582f638b508f15acae3ee0c0027a2ac50736062e54fde83a9896b0c584c463794e69ccdff1a2492bafc6a2fd4095ac5e63641 @@ -5488,7 +5523,7 @@ __metadata: languageName: node linkType: hard -"string-argv@npm:0.3.2": +"string-argv@npm:~0.3.2": version: 0.3.2 resolution: "string-argv@npm:0.3.2" checksum: 10c2/2d245996e1de6939c7726f609a35a8fe61b87f3a6bc6cc4bbec81843219d35d09b2ad7e394b5b7af3656baa15b4d18424ee4bcda67a50b932dba84f0978417c0 @@ -6245,10 +6280,12 @@ __metadata: languageName: node linkType: hard -"yaml@npm:2.3.4": - version: 2.3.4 - resolution: "yaml@npm:2.3.4" - checksum: 10c2/9345ff147e1408c8a9bd5fcacba14b511b2fa185715c3e3f8bc4190fa29d6127f88f39e1b8f9fdf85878b464d3ced20a951bb4151d37e5090c5f5523595b6d1d +"yaml@npm:~2.4.2": + version: 2.4.2 + resolution: "yaml@npm:2.4.2" + bin: + yaml: bin.mjs + checksum: 10c2/7c87b3794985aab4f9783b0153d91a00ed8ff6ee4e081b62b2bc0ae4b9e85344b6bb822d6ee144b6bca659cc8f7d4a83aa235a63c392b7ad60a94be3f68d1e80 languageName: node linkType: hard