@deepseek-ai/cordis-plugin-loader 1.0.3 → 1.0.5

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.
@@ -39,27 +39,12 @@ export abstract class EntryTree {
39
39
  .filter(isNonNullable)
40
40
  }
41
41
 
42
- /**
43
- * Wait until this tree has no active import or lifecycle tasks.
44
- * @throws a settled fiber failure, or an aggregate when several fibers failed.
45
- */
42
+ /** Wait until this tree has no pending import or lifecycle tasks. */
46
43
  async await() {
47
44
  while (true) {
48
45
  const tasks = this.getTasks()
49
- if (tasks.length) {
50
- await Promise.allSettled(tasks)
51
- continue
52
- }
53
- const outcomes = await Promise.allSettled(
54
- [...this.entries()].map(entry => entry._await()),
55
- )
56
- const failures = outcomes
57
- .filter((outcome): outcome is PromiseRejectedResult => outcome.status === 'rejected')
58
- .map(outcome => outcome.reason)
59
- if (failures.length === 1) throw failures[0]
60
- if (failures.length > 1) throw new AggregateError(failures, 'loader fibers failed')
61
- this.ctx.reflect.notify(['loader'])
62
- if (!this.getTasks().length) return
46
+ if (!tasks.length) return
47
+ await Promise.allSettled(tasks)
63
48
  }
64
49
  }
65
50
 
@@ -96,17 +81,15 @@ export abstract class EntryTree {
96
81
  /** Create an entry in the root group or a nested group. */
97
82
  async create(options: Omit<EntryOptions, 'id'>, parent: string | null = null, position = Infinity) {
98
83
  const group = this.resolveGroup(parent)
99
- const id = await group.create(options)
100
- const entry = this.resolve(id)
101
- group.data.splice(position, 0, entry.options)
84
+ group.data.splice(position, 0, options as EntryOptions)
102
85
  group.tree.write()
103
- return id
86
+ return group.create(options)
104
87
  }
105
88
 
106
89
  /** Stop and remove an entry from its parent group. */
107
- async remove(id: string) {
90
+ remove(id: string) {
108
91
  const entry = this.resolve(id)
109
- await entry.parent.remove(id)
92
+ entry.parent.remove(id)
110
93
  entry.parent.tree.write()
111
94
  }
112
95
 
@@ -114,31 +97,15 @@ export abstract class EntryTree {
114
97
  async update(id: string, options: Omit<EntryOptions, 'id' | 'name'>, parent?: string | null, position?: number) {
115
98
  const entry = this.resolve(id)
116
99
  const source = entry.parent
117
- const sourceIndex = source.data.indexOf(entry.options)
118
- let target = source
119
100
  if (parent !== undefined) {
120
- target = this.resolveGroup(parent)
101
+ const target = this.resolveGroup(parent)
121
102
  source.unlink(entry.options)
122
103
  target.data.splice(position ?? Infinity, 0, entry.options)
104
+ target.tree.write()
123
105
  entry.parent = target
124
106
  }
125
- try {
126
- await entry.update(options, false, true)
127
- } catch (error) {
128
- if (parent !== undefined) {
129
- target.unlink(entry.options)
130
- source.data.splice(sourceIndex < 0 ? source.data.length : sourceIndex, 0, entry.options)
131
- entry.parent = source
132
- try {
133
- await entry.update({}, false, true)
134
- } catch (rollbackError) {
135
- throw new AggregateError([error, rollbackError], `failed to roll back loader entry move ${id}`)
136
- }
137
- }
138
- throw error
139
- }
140
107
  source.tree.write()
141
- if (target !== source) target.tree.write()
108
+ return entry.update(options, false, true)
142
109
  }
143
110
 
144
111
  /** Import a plugin module from a specifier or `cordis:` builtin. */
@@ -8,7 +8,7 @@ export const evaluate = new Function('ctx', 'expr', `
8
8
  }
9
9
  `) as ((ctx: object, expr: string) => any)
10
10
 
11
- /** Recursively replace YAML `!js` expression nodes with evaluated values. */
11
+ /** Recursively replace YAML `!!js` expression nodes with evaluated values. */
12
12
  export function interpolate(ctx: object, value: any) {
13
13
  if (isJsExpr(value)) {
14
14
  return evaluate(ctx, value.__jsExpr)
package/src/index.ts CHANGED
@@ -26,7 +26,19 @@ declare module '@deepseek-ai/cordis' {
26
26
  'loader/config-update'(): void
27
27
  'loader/entry-init'(entry: Entry): void
28
28
  'loader/partial-dispose'(entry: Entry, legacy: Partial<EntryOptions>, active: boolean): void
29
- 'loader/patch-context'(entry: Entry, next: () => void | Promise<void>): void | Promise<void>
29
+ /**
30
+ * Volatile config values were committed into the running fiber without a remount; dispatched to the owning fiber only.
31
+ * @param paths - changed config paths as key arrays; every value is committed before dispatch.
32
+ * @mode emit
33
+ */
34
+ 'loader/volatile-update'(paths: readonly (readonly string[])[]): void
35
+ /**
36
+ * Refresh entry context before applying config.
37
+ * @param entry - entry containing the new raw config and optional current fiber.
38
+ * @param next - continue context refresh and Loader's config update.
39
+ * @mode waterfall
40
+ */
41
+ 'loader/patch-context'(entry: Entry, next: () => void): void
30
42
  }
31
43
 
32
44
  interface Context {
@@ -100,12 +112,12 @@ export class Loader extends EntryTree {
100
112
  return interpolate(this.ctx, config)
101
113
  }, { global: true })
102
114
 
103
- ctx.on('internal/update', async function (config, noSave, next) {
115
+ ctx.on('internal/update', function (config, noSave, next) {
104
116
  if (!this.entry || noSave || this.parent.fiber?.entry === this.entry) return next()
105
- await next()
106
117
  const unparse = this.runtime?.Config?.['simplify']
107
- this.entry.options.config = unparse ? unparse(config) : config
118
+ this.entry.options.config = unparse ? unparse.call(this.runtime!.Config, config) : config
108
119
  this.entry.parent.tree.write()
120
+ return next()
109
121
  }, { global: true, prepend: true })
110
122
 
111
123
  ctx.on('internal/update', function (config, _, next) {
@@ -143,12 +155,9 @@ export class Loader extends EntryTree {
143
155
  const treeOwner = fiber.entry.parent.tree.ctx.fiber
144
156
  if (!treeOwner.uid || treeOwner.state === FiberState.UNLOADING) return
145
157
 
146
- // case 6: Loader is replacing or removing this exact fiber
147
- if (fiber.entry._disposing) return
148
-
149
158
  this.showLog(fiber.entry, 'unload')
150
159
 
151
- // case 7: fiber is disposed by loader behavior
160
+ // case 6: fiber is disposed by loader behavior
152
161
  // such as inject checker, config file update, ancestor group disable
153
162
  if (fiber.entry.disabled) return
154
163