@deepseek-ai/cordis-plugin-loader 1.0.1-rc.1 → 1.0.2
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/lib/index.js +9 -23
- package/lib/types/config/entry.d.ts +3 -15
- package/lib/types/config/entry.d.ts.map +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/config/entry.ts +9 -28
- package/src/index.ts +5 -8
package/lib/index.js
CHANGED
|
@@ -294,8 +294,6 @@ function isJsExpr(value) {
|
|
|
294
294
|
}
|
|
295
295
|
//#endregion
|
|
296
296
|
//#region lib/types/config/entry.js
|
|
297
|
-
/** Static plugin hook for resolving a container config while preserving nested entry configs. */
|
|
298
|
-
const EntryConfigResolver = Symbol.for("cordis.loader.entry-config-resolver");
|
|
299
297
|
function updateError(stage, options, cause) {
|
|
300
298
|
const detail = cause instanceof Error ? cause.message : String(cause);
|
|
301
299
|
return new Error(`failed to ${stage} loader entry ${options.id} (${options.name}): ${detail}`, { cause });
|
|
@@ -335,8 +333,6 @@ var Entry = class Entry {
|
|
|
335
333
|
subtree;
|
|
336
334
|
_initTask;
|
|
337
335
|
_disposing = 0;
|
|
338
|
-
runtimeEnabled = false;
|
|
339
|
-
runtimeEnableTask;
|
|
340
336
|
constructor(loader) {
|
|
341
337
|
this.loader = loader;
|
|
342
338
|
this.ctx = loader.ctx.extend({ [Entry.key]: this });
|
|
@@ -356,28 +352,20 @@ var Entry = class Entry {
|
|
|
356
352
|
}
|
|
357
353
|
_disabled(options) {
|
|
358
354
|
if (options.group) return false;
|
|
359
|
-
if (
|
|
355
|
+
if (this.disabledOf(options)) return true;
|
|
360
356
|
let entry = this.parent.ctx.fiber.entry;
|
|
361
357
|
while (entry) {
|
|
362
|
-
if (entry.options
|
|
358
|
+
if (this.disabledOf(entry.options)) return true;
|
|
363
359
|
entry = entry.parent.ctx.fiber.entry;
|
|
364
360
|
}
|
|
365
361
|
return false;
|
|
366
362
|
}
|
|
367
363
|
/**
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
* @returns a promise settling after its initial activation attempt.
|
|
364
|
+
* Effective disabled state: a `!!js` expression evaluates against the loader
|
|
365
|
+
* context. The raw node stays in the options, so write-back keeps the form.
|
|
371
366
|
*/
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
this.runtimeEnabled = true;
|
|
375
|
-
this.runtimeEnableTask = this.refresh().catch((error) => {
|
|
376
|
-
this.runtimeEnabled = false;
|
|
377
|
-
this.runtimeEnableTask = void 0;
|
|
378
|
-
throw error;
|
|
379
|
-
});
|
|
380
|
-
return this.runtimeEnableTask;
|
|
367
|
+
disabledOf(options) {
|
|
368
|
+
return isJsExpr(options.disabled) ? Boolean(this.evaluate(options.disabled.__jsExpr)) : Boolean(options.disabled);
|
|
381
369
|
}
|
|
382
370
|
evaluate(expr) {
|
|
383
371
|
return evaluate(this.ctx, expr);
|
|
@@ -687,10 +675,8 @@ var Loader = class extends EntryTree {
|
|
|
687
675
|
ctx.on("internal/config", function(_config, next) {
|
|
688
676
|
const config = next();
|
|
689
677
|
if (!this.entry || this.parent.fiber?.entry === this.entry) return config;
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
const resolve = plugin?.[EntryConfigResolver];
|
|
693
|
-
return resolve ? resolve(this.ctx, config) : interpolate(this.ctx, config);
|
|
678
|
+
if ((this.runtime?.callback)?.[EntryGroup.key]) return config;
|
|
679
|
+
return interpolate(this.ctx, config);
|
|
694
680
|
}, { global: true });
|
|
695
681
|
ctx.on("internal/update", async function(config, noSave, next) {
|
|
696
682
|
if (!this.entry || noSave || this.parent.fiber?.entry === this.entry) return next();
|
|
@@ -755,4 +741,4 @@ var Loader = class extends EntryTree {
|
|
|
755
741
|
}
|
|
756
742
|
};
|
|
757
743
|
//#endregion
|
|
758
|
-
export { Entry,
|
|
744
|
+
export { Entry, EntryGroup, EntryTree, GlobalRealm, Group, Loader, Loader as default, LocalRealm, ModuleLoader, Realm, evaluate, interpolate, isJsExpr };
|
|
@@ -2,15 +2,6 @@ import { Context, Fiber, Inject } from '@deepseek-ai/cordis';
|
|
|
2
2
|
import { Loader } from '../index.ts';
|
|
3
3
|
import { EntryGroup } from './group.ts';
|
|
4
4
|
import { EntryTree } from './tree.ts';
|
|
5
|
-
/** Static plugin hook for resolving a container config while preserving nested entry configs. */
|
|
6
|
-
export declare const EntryConfigResolver: unique symbol;
|
|
7
|
-
/**
|
|
8
|
-
* Resolve a container's own config while preserving any nested entry configs.
|
|
9
|
-
* @param ctx - the container plugin context.
|
|
10
|
-
* @param config - the container's raw config.
|
|
11
|
-
* @returns the config to validate for this activation.
|
|
12
|
-
*/
|
|
13
|
-
export type EntryConfigResolver = (ctx: Context, config: any) => any;
|
|
14
5
|
/** Serialized plugin entry options stored in loader config files. */
|
|
15
6
|
export interface EntryOptions {
|
|
16
7
|
/** Stable id inside the containing entry tree. */
|
|
@@ -38,8 +29,6 @@ export declare class Entry {
|
|
|
38
29
|
subtree?: EntryTree;
|
|
39
30
|
_initTask?: Promise<void>;
|
|
40
31
|
_disposing: number;
|
|
41
|
-
private runtimeEnabled;
|
|
42
|
-
private runtimeEnableTask?;
|
|
43
32
|
constructor(loader: Loader);
|
|
44
33
|
get context(): Context;
|
|
45
34
|
get id(): string;
|
|
@@ -47,11 +36,10 @@ export declare class Entry {
|
|
|
47
36
|
get disabled(): boolean;
|
|
48
37
|
private _disabled;
|
|
49
38
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* @returns a promise settling after its initial activation attempt.
|
|
39
|
+
* Effective disabled state: a `!!js` expression evaluates against the loader
|
|
40
|
+
* context. The raw node stays in the options, so write-back keeps the form.
|
|
53
41
|
*/
|
|
54
|
-
|
|
42
|
+
private disabledOf;
|
|
55
43
|
evaluate(expr: string): any;
|
|
56
44
|
private _patchContext;
|
|
57
45
|
refresh(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../../src/config/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAGrC,
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../../src/config/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAGrC,qEAAqE;AACrE,MAAM,WAAW,YAAY;IAC3B,kDAAkD;IAClD,EAAE,EAAE,MAAM,CAAA;IACV,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,mCAAmC;IACnC,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,0CAA0C;IAC1C,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACtB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACzB,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB;AA6BD,wDAAwD;AACxD,qBAAa,KAAK;IAcG,MAAM,EAAE,MAAM;IAbjC,MAAM,CAAC,QAAQ,CAAC,GAAG,gBAA6B;IAEzC,GAAG,EAAE,OAAO,CAAA;IACZ,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,MAAM,EAAG,UAAU,CAAA;IAEnB,OAAO,EAAS,YAAY,CAAA;IAC5B,QAAQ,CAAC,EAAE,UAAU,CAAA;IACrB,OAAO,CAAC,EAAE,SAAS,CAAA;IAE1B,SAAS,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,UAAU,SAAI;gBAEK,MAAM,EAAE,MAAM;IAKjC,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,EAAE,WAML;IAED,mEAAmE;IACnE,IAAI,QAAQ,YAEX;IAED,OAAO,CAAC,SAAS;IAYjB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAMlB,QAAQ,CAAC,IAAI,EAAE,MAAM;YAIP,aAAa;IAUrB,OAAO;IAMP,QAAQ,CAAC,KAAK,oBAAa;IAWjC,iFAAiF;IAC3E,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,EAAE,MAAM,UAAQ,EAAE,KAAK,UAAQ;IA0G1E,aAAa,iBAQZ;IAED,2EAA2E;IACrE,IAAI;IAUJ,MAAM;YAQE,KAAK;YAcL,MAAM;CAYrB"}
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAsB,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,qBAAqB,CAAA;AACtF,OAAO,EAA8B,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAsB,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,qBAAqB,CAAA;AACtF,OAAO,EAA8B,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;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SAAQ,SAAS;IAYF,MAAM,EAAE,MAAM,CAAC,MAAM;IAX9C,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,SAAS,CAAA;IAEnC,OAAO,MAEe;IAEtB,IAAI,SAAW;IACf,QAAQ,2BAA8B;IAEtC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAsB;gBAEpC,GAAG,EAAE,OAAO,EAAS,MAAM,GAAE,MAAM,CAAC,MAAW;IAqF3D,KAAK;IAIL,CAAC,OAAO,CAAC,KAAK,CAAC;IAMf,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM;IAKlC,4DAA4D;IAC5D,MAAM,CAAC,KAAK,QAAiB;IAS7B,2EAA2E;IAC3E,IAAI;IAGJ,wEAAwE;IACxE,aAAa,CAAC,OAAO,EAAE,GAAG;CAQ3B;AAED,eAAe,MAAM,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/cordis-plugin-loader",
|
|
3
3
|
"description": "Plugin loader for cordis",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"publishConfig": {
|
|
6
|
-
"access": "
|
|
6
|
+
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"node-addon-require-builtin": "^0.1.4",
|
|
34
|
-
"@deepseek-ai/cordis": "^4.0.1
|
|
34
|
+
"@deepseek-ai/cordis": "^4.0.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"node-addon-require-builtin": {
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@deepseek-ai/cosmokit": "^1.8.2
|
|
42
|
+
"@deepseek-ai/cosmokit": "^1.8.2"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/src/config/entry.ts
CHANGED
|
@@ -3,18 +3,7 @@ import { deepEqual, isNullable } from '@deepseek-ai/cosmokit'
|
|
|
3
3
|
import { Loader } from '../index.ts'
|
|
4
4
|
import { EntryGroup } from './group.ts'
|
|
5
5
|
import { EntryTree } from './tree.ts'
|
|
6
|
-
import { evaluate } from './utils.ts'
|
|
7
|
-
|
|
8
|
-
/** Static plugin hook for resolving a container config while preserving nested entry configs. */
|
|
9
|
-
export const EntryConfigResolver = Symbol.for('cordis.loader.entry-config-resolver')
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Resolve a container's own config while preserving any nested entry configs.
|
|
13
|
-
* @param ctx - the container plugin context.
|
|
14
|
-
* @param config - the container's raw config.
|
|
15
|
-
* @returns the config to validate for this activation.
|
|
16
|
-
*/
|
|
17
|
-
export type EntryConfigResolver = (ctx: Context, config: any) => any
|
|
6
|
+
import { evaluate, isJsExpr } from './utils.ts'
|
|
18
7
|
|
|
19
8
|
/** Serialized plugin entry options stored in loader config files. */
|
|
20
9
|
export interface EntryOptions {
|
|
@@ -73,8 +62,6 @@ export class Entry {
|
|
|
73
62
|
|
|
74
63
|
_initTask?: Promise<void>
|
|
75
64
|
_disposing = 0
|
|
76
|
-
private runtimeEnabled = false
|
|
77
|
-
private runtimeEnableTask?: Promise<void>
|
|
78
65
|
|
|
79
66
|
constructor(public loader: Loader) {
|
|
80
67
|
this.ctx = loader.ctx.extend({ [Entry.key]: this })
|
|
@@ -101,29 +88,23 @@ export class Entry {
|
|
|
101
88
|
private _disabled(options: EntryOptions) {
|
|
102
89
|
// group is always enabled
|
|
103
90
|
if (options.group) return false
|
|
104
|
-
if (
|
|
91
|
+
if (this.disabledOf(options)) return true
|
|
105
92
|
let entry = this.parent.ctx.fiber.entry
|
|
106
93
|
while (entry) {
|
|
107
|
-
if (entry.options
|
|
94
|
+
if (this.disabledOf(entry.options)) return true
|
|
108
95
|
entry = entry.parent.ctx.fiber.entry
|
|
109
96
|
}
|
|
110
97
|
return false
|
|
111
98
|
}
|
|
112
99
|
|
|
113
100
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* @returns a promise settling after its initial activation attempt.
|
|
101
|
+
* Effective disabled state: a `!!js` expression evaluates against the loader
|
|
102
|
+
* context. The raw node stays in the options, so write-back keeps the form.
|
|
117
103
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
this.runtimeEnabled = false
|
|
123
|
-
this.runtimeEnableTask = undefined
|
|
124
|
-
throw error
|
|
125
|
-
})
|
|
126
|
-
return this.runtimeEnableTask
|
|
104
|
+
private disabledOf(options: EntryOptions): boolean {
|
|
105
|
+
return isJsExpr(options.disabled)
|
|
106
|
+
? Boolean(this.evaluate(options.disabled.__jsExpr))
|
|
107
|
+
: Boolean(options.disabled)
|
|
127
108
|
}
|
|
128
109
|
|
|
129
110
|
evaluate(expr: string) {
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { Context, FiberState, Inject, Service, type Fiber } from '@deepseek-ai/cordis'
|
|
2
2
|
import { defineProperty, isNullable, type Dict } from '@deepseek-ai/cosmokit'
|
|
3
3
|
import { ModuleLoader } from './internal.ts'
|
|
4
|
-
import {
|
|
5
|
-
Entry,
|
|
6
|
-
EntryConfigResolver,
|
|
7
|
-
type EntryConfigResolver as ConfigResolver,
|
|
8
|
-
type EntryOptions,
|
|
9
|
-
} from './config/entry.ts'
|
|
4
|
+
import { Entry, type EntryOptions } from './config/entry.ts'
|
|
10
5
|
import { EntryGroup } from './config/group.ts'
|
|
11
6
|
import isolate from './config/isolate.ts'
|
|
12
7
|
import { EntryTree } from './config/tree.ts'
|
|
@@ -97,10 +92,12 @@ export class Loader extends EntryTree {
|
|
|
97
92
|
ctx.on('internal/config', function (this: Fiber, _config, next) {
|
|
98
93
|
const config = next()
|
|
99
94
|
if (!this.entry || this.parent.fiber?.entry === this.entry) return config
|
|
95
|
+
// Tree carriers (Group, Include) keep their configs literal: their
|
|
96
|
+
// entry and patch lists hold other rows' configs, whose `!!js`
|
|
97
|
+
// expressions belong to those rows' own fibers.
|
|
100
98
|
const plugin = this.runtime?.callback as Record<PropertyKey, unknown> | undefined
|
|
101
99
|
if (plugin?.[EntryGroup.key]) return config
|
|
102
|
-
|
|
103
|
-
return resolve ? resolve(this.ctx, config) : interpolate(this.ctx, config)
|
|
100
|
+
return interpolate(this.ctx, config)
|
|
104
101
|
}, { global: true })
|
|
105
102
|
|
|
106
103
|
ctx.on('internal/update', async function (config, noSave, next) {
|