fix: Dependency (#2784)

* fix: Dependency

* fix: set deps during container init
This commit is contained in:
Jade
2024-11-13 10:53:19 -07:00
committed by GitHub
parent c088ab7a79
commit db6fc661a6
3 changed files with 69 additions and 26 deletions

View File

@@ -301,6 +301,20 @@ export class SystemForEmbassy implements System {
await effects.setMainStatus({ status: "stopped" }) await effects.setMainStatus({ status: "stopped" })
await this.exportActions(effects) await this.exportActions(effects)
await this.exportNetwork(effects) await this.exportNetwork(effects)
await this.containerSetDependencies(effects)
}
async containerSetDependencies(effects: T.Effects) {
const oldDeps: Record<string, string[]> = Object.fromEntries(
await effects
.getDependencies()
.then((x) =>
x.flatMap((x) =>
x.kind === "running" ? [[x.id, x?.healthChecks || []]] : [],
),
)
.catch(() => []),
)
await this.setDependencies(effects, oldDeps)
} }
async exit(): Promise<void> { async exit(): Promise<void> {
@@ -650,7 +664,7 @@ export class SystemForEmbassy implements System {
), ),
) )
const dependsOn = answer["depends-on"] ?? answer.dependsOn ?? {} const dependsOn = answer["depends-on"] ?? answer.dependsOn ?? {}
await this.setConfigSetConfig(effects, dependsOn) await this.setDependencies(effects, dependsOn)
return return
} else if (setConfigValue.type === "script") { } else if (setConfigValue.type === "script") {
const moduleCode = await this.moduleCode const moduleCode = await this.moduleCode
@@ -673,31 +687,60 @@ export class SystemForEmbassy implements System {
}), }),
) )
const dependsOn = answer["depends-on"] ?? answer.dependsOn ?? {} const dependsOn = answer["depends-on"] ?? answer.dependsOn ?? {}
await this.setConfigSetConfig(effects, dependsOn) await this.setDependencies(effects, dependsOn)
return return
} }
} }
private async setConfigSetConfig( private async setDependencies(
effects: Effects, effects: Effects,
dependsOn: { [x: string]: readonly string[] }, rawDepends: { [x: string]: readonly string[] },
) { ) {
const dependsOn: Record<string, readonly string[] | null> = {
...Object.fromEntries(
Object.entries(this.manifest.dependencies || {})?.map((x) => [
x[0],
null,
]) || [],
),
...rawDepends,
}
await effects.setDependencies({ await effects.setDependencies({
dependencies: Object.entries(dependsOn).flatMap(([key, value]) => { dependencies: Object.entries(dependsOn).flatMap(
const dependency = this.manifest.dependencies?.[key] ([key, value]): T.Dependencies => {
if (!dependency) return [] const dependency = this.manifest.dependencies?.[key]
const versionRange = dependency.version if (!dependency) return []
const registryUrl = DEFAULT_REGISTRY if (value == null) {
const kind = "running" const versionRange = dependency.version
return [ if (dependency.requirement.type === "required") {
{ return [
id: key, {
versionRange, id: key,
registryUrl, versionRange,
kind, kind: "running",
healthChecks: [...value], healthChecks: [],
}, },
] ]
}), }
return [
{
kind: "exists",
id: key,
versionRange,
},
]
}
const versionRange = dependency.version
const kind = "running"
return [
{
id: key,
versionRange,
kind,
healthChecks: [...value],
},
]
},
),
}) })
} }

2
package-lock.json generated
View File

@@ -1,5 +1,5 @@
{ {
"name": "embassy-os", "name": "start-os",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": {} "packages": {}

View File

@@ -1191,11 +1191,11 @@ export module Mock {
name: 'Datetime', name: 'Datetime',
required: false, required: false,
}), }),
file: ISB.Value.file({ // file: ISB.Value.file({
name: 'File', // name: 'File',
required: false, // required: false,
extensions: ['png', 'pdf'], // extensions: ['png', 'pdf'],
}), // }),
users: ISB.Value.multiselect({ users: ISB.Value.multiselect({
name: 'Users', name: 'Users',
default: [], default: [],