@antelopejs/core 1.4.9 → 1.4.11
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/dist/core/module-manager.d.ts +1 -1
- package/dist/core/module-manager.js +39 -19
- package/dist/core/module-manager.js.map +1 -1
- package/dist/core/module.d.ts +1 -0
- package/dist/core/module.js +11 -1
- package/dist/core/module.js.map +1 -1
- package/dist/core/resolution/resolver-detour.js +37 -12
- package/dist/core/resolution/resolver-detour.js.map +1 -1
- package/dist/core/resolution/resolver.d.ts +51 -31
- package/dist/core/resolution/resolver.js +475 -177
- package/dist/core/resolution/resolver.js.map +1 -1
- package/package.json +2 -2
- package/dist/core/module-context.d.ts +0 -7
- package/dist/core/module-context.js +0 -60
- package/dist/core/module-context.js.map +0 -1
|
@@ -1,23 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.Resolver = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
4
|
+
const node_util_1 = require("node:util");
|
|
5
|
+
const interface_core_1 = require("@antelopejs/interface-core");
|
|
9
6
|
const internal_1 = require("@antelopejs/interface-core/internal");
|
|
10
7
|
const package_resolution_1 = require("./package-resolution");
|
|
11
8
|
const CORE_PKG = "@antelopejs/interface-core";
|
|
12
9
|
const CORE_PACKAGE = (0, package_resolution_1.resolvePackage)(CORE_PKG, __dirname);
|
|
13
10
|
const CORE_RESOLVE_FROM = CORE_PACKAGE?.root ?? __dirname;
|
|
14
11
|
const CORE_ENTRY = CORE_PACKAGE?.entry ?? CORE_PKG;
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const CLASS_PREFIX = "class ";
|
|
13
|
+
const PROXY_ATTACHMENT_METHODS = new Set([
|
|
14
|
+
"detach",
|
|
15
|
+
"onCall",
|
|
16
|
+
"onHandlers",
|
|
17
|
+
"onRegister",
|
|
18
|
+
"onUnregister",
|
|
19
|
+
]);
|
|
19
20
|
let nextResolverIdentity = 1;
|
|
20
|
-
|
|
21
|
+
function isRecognizedInterfaceProxy(value, kind) {
|
|
22
|
+
if (node_util_1.types.isProxy(value)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (value instanceof interface_core_1.AsyncProxy ||
|
|
26
|
+
value instanceof interface_core_1.EventProxy ||
|
|
27
|
+
value instanceof interface_core_1.RegisteringProxy) {
|
|
28
|
+
return (0, interface_core_1.IsInterfaceProxy)(value, kind);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
return (0, interface_core_1.IsInterfaceProxy)(value, kind);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function getProxyCandidate(candidate) {
|
|
38
|
+
if (typeof candidate === "function" && "proxy" in candidate) {
|
|
39
|
+
return candidate.proxy;
|
|
40
|
+
}
|
|
41
|
+
return candidate;
|
|
42
|
+
}
|
|
43
|
+
function collectProxyReferences(value) {
|
|
44
|
+
const references = [];
|
|
45
|
+
const visited = new WeakSet();
|
|
46
|
+
const visit = (candidate) => {
|
|
47
|
+
if ((typeof candidate !== "object" && typeof candidate !== "function") ||
|
|
48
|
+
candidate === null) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (node_util_1.types.isProxy(candidate)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const proxy = getProxyCandidate(candidate);
|
|
55
|
+
if (isRecognizedInterfaceProxy(proxy)) {
|
|
56
|
+
const identity = (0, interface_core_1.GetInterfaceProxyIdentity)(proxy);
|
|
57
|
+
if (identity) {
|
|
58
|
+
references.push({ identity, proxy: proxy });
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (visited.has(candidate)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
visited.add(candidate);
|
|
66
|
+
Object.values(candidate).forEach(visit);
|
|
67
|
+
};
|
|
68
|
+
visit(value);
|
|
69
|
+
return references;
|
|
70
|
+
}
|
|
21
71
|
class Resolver {
|
|
22
72
|
pathMapper;
|
|
23
73
|
moduleByFolder = new Map();
|
|
@@ -25,85 +75,153 @@ class Resolver {
|
|
|
25
75
|
interfacePackages = new Map();
|
|
26
76
|
interfacePackageEntries = new Map();
|
|
27
77
|
interfacePackageResolveFrom = new Map();
|
|
78
|
+
lifecycleInterfacePackages = new Set();
|
|
79
|
+
stubbedInterfacePackages = new Set();
|
|
28
80
|
stubModulePath;
|
|
29
81
|
resolverIdentity = nextResolverIdentity++;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
82
|
+
interfaceGraphFiles = new Map();
|
|
83
|
+
interfaceDependencies = new Map();
|
|
84
|
+
boundValues = new WeakMap();
|
|
85
|
+
routedEvents = new Map();
|
|
86
|
+
proxyOwners = new Map();
|
|
87
|
+
providerlessContexts = new WeakMap();
|
|
88
|
+
stubbedContexts = new WeakSet();
|
|
33
89
|
constructor(pathMapper) {
|
|
34
90
|
this.pathMapper = pathMapper;
|
|
35
91
|
}
|
|
36
92
|
resolve(request, parent) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const inheritedAlias = this.resolveInheritedAlias(request, parent?.filename);
|
|
41
|
-
if (inheritedAlias) {
|
|
42
|
-
return inheritedAlias;
|
|
43
|
-
}
|
|
44
|
-
const matchingModule = this.resolveLocalModule(parent?.filename);
|
|
45
|
-
if (matchingModule) {
|
|
46
|
-
const mapped = this.pathMapper.resolve(request, matchingModule.manifest);
|
|
93
|
+
const parentModule = this.resolveLocalModule(parent?.filename);
|
|
94
|
+
if (parentModule) {
|
|
95
|
+
const mapped = this.pathMapper.resolve(request, parentModule.manifest);
|
|
47
96
|
if (mapped) {
|
|
48
97
|
return { resolvedPath: mapped };
|
|
49
98
|
}
|
|
50
99
|
}
|
|
51
100
|
const coreResult = this.resolveInterfaceCore(request);
|
|
52
101
|
if (coreResult) {
|
|
53
|
-
return coreResult;
|
|
102
|
+
return this.bindResultProvider(coreResult, CORE_PKG, false, parent, parentModule);
|
|
54
103
|
}
|
|
55
104
|
const interfaceRequest = this.resolveInterfacePackage(request);
|
|
56
105
|
if (interfaceRequest) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (!provider) {
|
|
61
|
-
return interfaceRequest.result;
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
...interfaceRequest.result,
|
|
65
|
-
alias: this.getInterfaceAlias(interfaceRequest.packageName, provider),
|
|
66
|
-
};
|
|
106
|
+
this.trackInterfaceDependency(parent?.filename, interfaceRequest.packageName);
|
|
107
|
+
return this.bindResultProvider(interfaceRequest.result, interfaceRequest.packageName, this.interfaceGraphFiles.get(parent?.filename ?? "") !==
|
|
108
|
+
interfaceRequest.packageName, parent, parentModule);
|
|
67
109
|
}
|
|
68
|
-
return
|
|
110
|
+
return this.resolveRelativeInterface(request, parent, parentModule);
|
|
69
111
|
}
|
|
70
|
-
ownsResolutionContext(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
112
|
+
ownsResolutionContext(_request, parent) {
|
|
113
|
+
const contextModule = (0, internal_1.getModuleContext)()?.module;
|
|
114
|
+
if (contextModule && this.modulesById.has(contextModule)) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
return Boolean(this.resolveLocalModule(parent?.filename));
|
|
75
118
|
}
|
|
76
119
|
requiresPreResolution(request, parent) {
|
|
77
|
-
|
|
78
|
-
|
|
120
|
+
return Boolean(this.findRequestedInterface(request, parent?.filename));
|
|
121
|
+
}
|
|
122
|
+
bindProviderRoutes(result, value) {
|
|
123
|
+
const references = collectProxyReferences(value);
|
|
124
|
+
if (result.interfaceName) {
|
|
125
|
+
this.registerProxyOwners(result.interfaceName, references);
|
|
126
|
+
}
|
|
127
|
+
const context = (0, internal_1.captureModuleContext)();
|
|
128
|
+
if (!context?.providerRoutes) {
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
this.replayKnownRoutes(context);
|
|
132
|
+
if (!result.provider) {
|
|
133
|
+
return this.bindStubbedInterfaceValue(result, value, context);
|
|
79
134
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return Boolean(matchingModule &&
|
|
83
|
-
interfaceRequest &&
|
|
84
|
-
this.resolveProvider(matchingModule, interfaceRequest));
|
|
135
|
+
this.bindImportedRoutes(context, result, references);
|
|
136
|
+
return result.bindExports ? this.bindInterfaceValue(value, context) : value;
|
|
85
137
|
}
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
|
|
138
|
+
trackInterfaceFile(result, resolvedPath) {
|
|
139
|
+
if (result.interfaceName) {
|
|
140
|
+
this.interfaceGraphFiles.set(resolvedPath, result.interfaceName);
|
|
89
141
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
142
|
+
}
|
|
143
|
+
getInterfaceEntryToPrime(result, resolvedPath) {
|
|
144
|
+
const interfaceName = result.interfaceName;
|
|
145
|
+
if (!interfaceName || this.lifecycleInterfacePackages.has(interfaceName)) {
|
|
146
|
+
return undefined;
|
|
93
147
|
}
|
|
94
|
-
|
|
95
|
-
|
|
148
|
+
const entry = this.interfacePackageEntries.get(interfaceName);
|
|
149
|
+
if (!entry || entry === resolvedPath || require.cache[entry]) {
|
|
150
|
+
return undefined;
|
|
96
151
|
}
|
|
97
|
-
|
|
98
|
-
|
|
152
|
+
return {
|
|
153
|
+
...result,
|
|
154
|
+
resolvedPath: entry,
|
|
155
|
+
resolveFrom: undefined,
|
|
156
|
+
bindExports: false,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
isInterfaceGraphFile(filePath) {
|
|
160
|
+
return this.interfaceGraphFiles.has(filePath);
|
|
161
|
+
}
|
|
162
|
+
buildProviderRoutes(moduleId) {
|
|
163
|
+
const routes = {};
|
|
164
|
+
this.bindKnownRoutes(moduleId, routes);
|
|
165
|
+
return routes;
|
|
99
166
|
}
|
|
100
167
|
clearCache() {
|
|
101
|
-
for (const
|
|
102
|
-
|
|
103
|
-
|
|
168
|
+
for (const event of this.routedEvents.values()) {
|
|
169
|
+
internal_1.internal.knownEvents.delete(event);
|
|
170
|
+
const identity = (0, interface_core_1.GetInterfaceProxyIdentity)(event);
|
|
171
|
+
if (identity) {
|
|
172
|
+
internal_1.internal.proxyStates.delete(identity);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
this.routedEvents.clear();
|
|
176
|
+
this.interfaceGraphFiles.clear();
|
|
177
|
+
this.interfaceDependencies.clear();
|
|
178
|
+
this.proxyOwners.clear();
|
|
179
|
+
}
|
|
180
|
+
registerProxyOwners(interfaceName, references) {
|
|
181
|
+
for (const { identity, proxy } of references) {
|
|
182
|
+
const owner = this.proxyOwners.get(identity);
|
|
183
|
+
if (!owner) {
|
|
184
|
+
this.proxyOwners.set(identity, {
|
|
185
|
+
interfaceName,
|
|
186
|
+
proxies: new WeakSet([proxy]),
|
|
187
|
+
});
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (owner.interfaceName !== interfaceName && !owner.proxies.has(proxy)) {
|
|
191
|
+
throw new Error(`Interface packages '${owner.interfaceName}' and '${interfaceName}' declare distinct proxies with identity '${identity}'. Use unique interface proxy identities.`);
|
|
192
|
+
}
|
|
193
|
+
owner.proxies.add(proxy);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
bindImportedRoutes(context, result, references) {
|
|
197
|
+
for (const { identity } of references) {
|
|
198
|
+
const owner = this.proxyOwners.get(identity)?.interfaceName;
|
|
199
|
+
if (result.interfaceName && owner !== result.interfaceName) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
this.bindRoute(context.module, context.providerRoutes, identity, result.provider);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
replayKnownRoutes(context) {
|
|
206
|
+
this.bindKnownRoutes(context.module, context.providerRoutes);
|
|
207
|
+
}
|
|
208
|
+
bindKnownRoutes(moduleId, routes) {
|
|
209
|
+
const module = this.modulesById.get(moduleId);
|
|
210
|
+
if (!module) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
for (const [identity, { interfaceName }] of this.proxyOwners) {
|
|
214
|
+
for (const provider of this.resolveProviders(module, interfaceName)) {
|
|
215
|
+
this.bindRoute(moduleId, routes, identity, provider);
|
|
104
216
|
}
|
|
105
217
|
}
|
|
106
|
-
|
|
218
|
+
}
|
|
219
|
+
bindRoute(moduleId, routes, identity, provider) {
|
|
220
|
+
const current = routes[identity];
|
|
221
|
+
if (current && current !== provider) {
|
|
222
|
+
throw new Error(`Module '${moduleId}' resolves proxy '${identity}' to both '${current}' and '${provider}'. Use unique interface proxy identities.`);
|
|
223
|
+
}
|
|
224
|
+
routes[identity] = provider;
|
|
107
225
|
}
|
|
108
226
|
resolveInterfaceCore(request) {
|
|
109
227
|
if (request === CORE_PKG) {
|
|
@@ -115,43 +233,44 @@ class Resolver {
|
|
|
115
233
|
return undefined;
|
|
116
234
|
}
|
|
117
235
|
resolveInterfacePackage(request) {
|
|
118
|
-
for (const [
|
|
119
|
-
if (request ===
|
|
236
|
+
for (const [packageName, rootDir] of this.interfacePackages) {
|
|
237
|
+
if (request === packageName) {
|
|
120
238
|
return {
|
|
121
|
-
packageName
|
|
239
|
+
packageName,
|
|
122
240
|
result: {
|
|
123
|
-
resolvedPath: this.interfacePackageEntries.get(
|
|
241
|
+
resolvedPath: this.interfacePackageEntries.get(packageName) ?? rootDir,
|
|
124
242
|
},
|
|
125
243
|
};
|
|
126
244
|
}
|
|
127
|
-
if (request.startsWith(`${
|
|
245
|
+
if (request.startsWith(`${packageName}/`)) {
|
|
128
246
|
return {
|
|
129
|
-
packageName
|
|
247
|
+
packageName,
|
|
130
248
|
result: {
|
|
131
249
|
resolvedPath: request,
|
|
132
|
-
resolveFrom: this.interfacePackageResolveFrom.get(
|
|
250
|
+
resolveFrom: this.interfacePackageResolveFrom.get(packageName) ?? rootDir,
|
|
133
251
|
},
|
|
134
252
|
};
|
|
135
253
|
}
|
|
136
254
|
}
|
|
137
255
|
return undefined;
|
|
138
256
|
}
|
|
139
|
-
|
|
140
|
-
if (!
|
|
257
|
+
resolveRelativeInterface(request, parent, parentModule) {
|
|
258
|
+
if (!request.startsWith(".") || !parent?.filename) {
|
|
141
259
|
return undefined;
|
|
142
260
|
}
|
|
143
|
-
const
|
|
144
|
-
if (!
|
|
261
|
+
const packageName = this.findInterfacePackageByPath(parent.filename);
|
|
262
|
+
if (!packageName) {
|
|
145
263
|
return undefined;
|
|
146
264
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
265
|
+
return this.bindResultProvider({ resolvedPath: request }, packageName, !this.interfaceGraphFiles.has(parent.filename), parent, parentModule);
|
|
266
|
+
}
|
|
267
|
+
bindResultProvider(result, packageName, bindExports, parent, parentModule) {
|
|
268
|
+
const provider = this.resolveRequestProvider(packageName, parent?.filename, parentModule);
|
|
151
269
|
return {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
270
|
+
...result,
|
|
271
|
+
bindExports,
|
|
272
|
+
interfaceName: packageName,
|
|
273
|
+
provider,
|
|
155
274
|
};
|
|
156
275
|
}
|
|
157
276
|
resolveProvider(module, packageName) {
|
|
@@ -160,124 +279,303 @@ class Resolver {
|
|
|
160
279
|
}
|
|
161
280
|
return internal_1.internal.interfaceConnections[module.id]?.[packageName]?.find(({ selected }) => selected)?.provider;
|
|
162
281
|
}
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
282
|
+
resolveRequestProvider(packageName, parentFilename, parentModule) {
|
|
283
|
+
const contextModule = (0, internal_1.getModuleContext)()?.module;
|
|
284
|
+
const consumer = contextModule
|
|
285
|
+
? this.modulesById.get(contextModule)
|
|
286
|
+
: undefined;
|
|
287
|
+
const direct = consumer
|
|
288
|
+
? this.resolveProvider(consumer, packageName)
|
|
289
|
+
: undefined;
|
|
290
|
+
if (direct) {
|
|
291
|
+
return direct;
|
|
168
292
|
}
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return alias;
|
|
293
|
+
const parentInterface = parentFilename
|
|
294
|
+
? this.interfaceGraphFiles.get(parentFilename)
|
|
295
|
+
: undefined;
|
|
296
|
+
const inherited = consumer && parentInterface
|
|
297
|
+
? this.resolveChildProvider(consumer, parentInterface, packageName)
|
|
298
|
+
: undefined;
|
|
299
|
+
return (inherited ??
|
|
300
|
+
(parentModule
|
|
301
|
+
? this.resolveProvider(parentModule, packageName)
|
|
302
|
+
: undefined));
|
|
180
303
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
304
|
+
resolveChildProvider(consumer, parentInterface, childInterface) {
|
|
305
|
+
for (const provider of this.resolveProviders(consumer, parentInterface)) {
|
|
306
|
+
const providerModule = this.modulesById.get(provider);
|
|
307
|
+
const childProvider = providerModule
|
|
308
|
+
? this.resolveProvider(providerModule, childInterface)
|
|
309
|
+
: undefined;
|
|
310
|
+
if (childProvider) {
|
|
311
|
+
return childProvider;
|
|
312
|
+
}
|
|
184
313
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
resolveProviders(module, interfaceName, visited = new Set()) {
|
|
317
|
+
const direct = this.resolveProvider(module, interfaceName);
|
|
318
|
+
if (direct) {
|
|
319
|
+
return new Set([direct]);
|
|
188
320
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (existing) {
|
|
192
|
-
return existing;
|
|
321
|
+
if (visited.has(interfaceName)) {
|
|
322
|
+
return new Set();
|
|
193
323
|
}
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
wrappersByRoot.set(corePackage.root, wrappers);
|
|
200
|
-
const facadePath = this.createCoreFacade(entry, wrappers, namespace);
|
|
201
|
-
paths.set(entry, facadePath);
|
|
202
|
-
alias.coreFacadeEntries.add(facadePath);
|
|
203
|
-
return facadePath;
|
|
204
|
-
}
|
|
205
|
-
createCoreWrappers(namespace, coreEntry) {
|
|
206
|
-
const core = require(coreEntry);
|
|
207
|
-
let nextAnonymousIdentity = 1;
|
|
208
|
-
const namespacedIdentity = (identity) => `${namespace}:${identity ?? `anonymous:${nextAnonymousIdentity++}`}`;
|
|
209
|
-
class AsyncProxy extends core.AsyncProxy {
|
|
210
|
-
constructor(identity) {
|
|
211
|
-
super(namespacedIdentity(identity));
|
|
324
|
+
visited.add(interfaceName);
|
|
325
|
+
const providers = new Set();
|
|
326
|
+
for (const [parent, children] of this.interfaceDependencies) {
|
|
327
|
+
if (!children.has(interfaceName)) {
|
|
328
|
+
continue;
|
|
212
329
|
}
|
|
330
|
+
this.collectChildProviders(module, parent, interfaceName, visited, providers);
|
|
213
331
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
332
|
+
return providers;
|
|
333
|
+
}
|
|
334
|
+
collectChildProviders(module, parentInterface, childInterface, visited, providers) {
|
|
335
|
+
for (const parentProvider of this.resolveProviders(module, parentInterface, new Set(visited))) {
|
|
336
|
+
const providerModule = this.modulesById.get(parentProvider);
|
|
337
|
+
const childProvider = providerModule
|
|
338
|
+
? this.resolveProvider(providerModule, childInterface)
|
|
339
|
+
: undefined;
|
|
340
|
+
if (childProvider) {
|
|
341
|
+
providers.add(childProvider);
|
|
217
342
|
}
|
|
218
343
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
344
|
+
}
|
|
345
|
+
trackInterfaceDependency(parentFilename, childInterface) {
|
|
346
|
+
const parentInterface = parentFilename
|
|
347
|
+
? this.interfaceGraphFiles.get(parentFilename)
|
|
348
|
+
: undefined;
|
|
349
|
+
if (!parentInterface || parentInterface === childInterface) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const dependencies = this.interfaceDependencies.get(parentInterface) ?? new Set();
|
|
353
|
+
dependencies.add(childInterface);
|
|
354
|
+
this.interfaceDependencies.set(parentInterface, dependencies);
|
|
355
|
+
}
|
|
356
|
+
findRequestedInterface(request, parentFilename) {
|
|
357
|
+
if (request === CORE_PKG || request.startsWith(`${CORE_PKG}/`)) {
|
|
358
|
+
return CORE_PKG;
|
|
359
|
+
}
|
|
360
|
+
const direct = this.findInterfacePackageRequest(request);
|
|
361
|
+
if (direct) {
|
|
362
|
+
return direct;
|
|
363
|
+
}
|
|
364
|
+
return request.startsWith(".") && parentFilename
|
|
365
|
+
? this.findInterfacePackageByPath(parentFilename)
|
|
366
|
+
: undefined;
|
|
367
|
+
}
|
|
368
|
+
findInterfacePackageRequest(request) {
|
|
369
|
+
return [...this.interfacePackages.keys()].find((packageName) => request === packageName || request.startsWith(`${packageName}/`));
|
|
370
|
+
}
|
|
371
|
+
findInterfacePackageByPath(fileName) {
|
|
372
|
+
const coreRoot = CORE_PACKAGE?.root ?? "";
|
|
373
|
+
let matchingRoot = coreRoot && (0, package_resolution_1.isPathWithin)(fileName, coreRoot) ? coreRoot : "";
|
|
374
|
+
let matchingPackage = matchingRoot ? CORE_PKG : undefined;
|
|
375
|
+
for (const [packageName, root] of this.interfacePackages) {
|
|
376
|
+
if ((0, package_resolution_1.isPathWithin)(fileName, root) && root.length > matchingRoot.length) {
|
|
377
|
+
matchingRoot = root;
|
|
378
|
+
matchingPackage = packageName;
|
|
222
379
|
}
|
|
223
380
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return
|
|
381
|
+
return matchingPackage;
|
|
382
|
+
}
|
|
383
|
+
bindInterfaceValue(value, context) {
|
|
384
|
+
if (isRecognizedInterfaceProxy(value, "event")) {
|
|
385
|
+
return this.getRoutedEvent(value, context);
|
|
386
|
+
}
|
|
387
|
+
if (typeof value === "function" &&
|
|
388
|
+
this.isClass(value)) {
|
|
389
|
+
return value;
|
|
390
|
+
}
|
|
391
|
+
if (!this.isBindableValue(value)) {
|
|
392
|
+
return value;
|
|
393
|
+
}
|
|
394
|
+
const cached = this.boundValues.get(value)?.get(context);
|
|
395
|
+
if (cached) {
|
|
396
|
+
return cached;
|
|
397
|
+
}
|
|
398
|
+
const bound = typeof value === "function"
|
|
399
|
+
? this.createFunctionFacade(value, context)
|
|
400
|
+
: this.createObjectFacade(value, context);
|
|
401
|
+
const contexts = this.boundValues.get(value) ??
|
|
402
|
+
new WeakMap();
|
|
403
|
+
contexts.set(context, bound);
|
|
404
|
+
this.boundValues.set(value, contexts);
|
|
405
|
+
return bound;
|
|
406
|
+
}
|
|
407
|
+
bindStubbedInterfaceValue(result, value, context) {
|
|
408
|
+
if (!result.interfaceName ||
|
|
409
|
+
!this.stubbedInterfacePackages.has(result.interfaceName)) {
|
|
410
|
+
return value;
|
|
411
|
+
}
|
|
412
|
+
const providerless = this.getProviderlessContext(context, result.interfaceName);
|
|
413
|
+
return this.bindInterfaceValue(value, providerless);
|
|
414
|
+
}
|
|
415
|
+
getProviderlessContext(context, interfaceName) {
|
|
416
|
+
const contexts = this.providerlessContexts.get(context) ?? new Map();
|
|
417
|
+
const existing = contexts.get(interfaceName);
|
|
418
|
+
if (existing) {
|
|
419
|
+
return existing;
|
|
420
|
+
}
|
|
421
|
+
const providerless = {
|
|
422
|
+
...context,
|
|
423
|
+
provider: undefined,
|
|
424
|
+
providerRoutes: this.filterStubbedProviderRoutes(context, interfaceName),
|
|
229
425
|
};
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
InterfaceFunction: {
|
|
248
|
-
enumerable: true,
|
|
249
|
-
value: wrappers.InterfaceFunction,
|
|
426
|
+
contexts.set(interfaceName, providerless);
|
|
427
|
+
this.providerlessContexts.set(context, contexts);
|
|
428
|
+
this.stubbedContexts.add(providerless);
|
|
429
|
+
return providerless;
|
|
430
|
+
}
|
|
431
|
+
filterStubbedProviderRoutes(context, interfaceName) {
|
|
432
|
+
const routes = context.providerRoutes ?? {};
|
|
433
|
+
return new Proxy(routes, {
|
|
434
|
+
get: (target, identity) => {
|
|
435
|
+
const owner = typeof identity === "string"
|
|
436
|
+
? this.proxyOwners.get(identity)?.interfaceName
|
|
437
|
+
: undefined;
|
|
438
|
+
if (owner === interfaceName &&
|
|
439
|
+
this.stubbedInterfacePackages.has(interfaceName)) {
|
|
440
|
+
return undefined;
|
|
441
|
+
}
|
|
442
|
+
return Reflect.get(target, identity);
|
|
250
443
|
},
|
|
251
|
-
RegisteringProxy: { enumerable: true, value: wrappers.RegisteringProxy },
|
|
252
444
|
});
|
|
253
|
-
const facadeModule = new node_module_1.default(facadePath);
|
|
254
|
-
facadeModule.filename = facadePath;
|
|
255
|
-
facadeModule.exports = facade;
|
|
256
|
-
facadeModule.loaded = true;
|
|
257
|
-
require.cache[facadePath] = facadeModule;
|
|
258
|
-
return facadePath;
|
|
259
445
|
}
|
|
260
|
-
|
|
261
|
-
|
|
446
|
+
isBindableValue(value) {
|
|
447
|
+
if ((typeof value !== "object" && typeof value !== "function") ||
|
|
448
|
+
value === null) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
if (node_util_1.types.isProxy(value)) {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
if (typeof value === "function" || isRecognizedInterfaceProxy(value)) {
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
const prototype = Object.getPrototypeOf(value);
|
|
458
|
+
return (Array.isArray(value) ||
|
|
459
|
+
prototype === Object.prototype ||
|
|
460
|
+
prototype === null);
|
|
262
461
|
}
|
|
263
|
-
|
|
264
|
-
return
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
462
|
+
isClass(value) {
|
|
463
|
+
return Function.prototype.toString.call(value).startsWith(CLASS_PREFIX);
|
|
464
|
+
}
|
|
465
|
+
createObjectFacade(value, context) {
|
|
466
|
+
const members = new Map();
|
|
467
|
+
const facade = new Proxy(value, {
|
|
468
|
+
get: (target, property) => {
|
|
469
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, property);
|
|
470
|
+
if (descriptor &&
|
|
471
|
+
!descriptor.configurable &&
|
|
472
|
+
"value" in descriptor &&
|
|
473
|
+
!descriptor.writable) {
|
|
474
|
+
return descriptor.value;
|
|
475
|
+
}
|
|
476
|
+
const member = Reflect.get(target, property, target);
|
|
477
|
+
const cached = members.get(property);
|
|
478
|
+
if (cached && Object.is(cached.source, member)) {
|
|
479
|
+
return cached.bound;
|
|
480
|
+
}
|
|
481
|
+
const bound = typeof member === "function" && !this.isClass(member)
|
|
482
|
+
? this.bindObjectFunction(member, target, facade, property, context)
|
|
483
|
+
: this.bindInterfaceValue(member, context);
|
|
484
|
+
members.set(property, { bound, source: member });
|
|
485
|
+
return bound;
|
|
486
|
+
},
|
|
271
487
|
});
|
|
488
|
+
return facade;
|
|
272
489
|
}
|
|
273
|
-
|
|
274
|
-
|
|
490
|
+
bindObjectFunction(member, target, facade, property, context) {
|
|
491
|
+
const isStubAttachment = this.stubbedContexts.has(context) &&
|
|
492
|
+
isRecognizedInterfaceProxy(target) &&
|
|
493
|
+
PROXY_ATTACHMENT_METHODS.has(property);
|
|
494
|
+
return isStubAttachment
|
|
495
|
+
? member.bind(target)
|
|
496
|
+
: this.createFunctionFacade(member, context, target, facade);
|
|
275
497
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
498
|
+
createFunctionFacade(value, context, boundThis, facadeThis) {
|
|
499
|
+
return new Proxy(value, {
|
|
500
|
+
apply: (target, thisArg, argumentsList) => {
|
|
501
|
+
const receiver = boundThis &&
|
|
502
|
+
(!facadeThis || thisArg === facadeThis || thisArg === undefined)
|
|
503
|
+
? boundThis
|
|
504
|
+
: thisArg;
|
|
505
|
+
const result = (0, internal_1.runWithCapturedModuleContext)(context, () => Reflect.apply(target, receiver, argumentsList.map((argument) => this.bindInterfaceValue(argument, context))));
|
|
506
|
+
return this.bindFunctionResult(result, context);
|
|
507
|
+
},
|
|
508
|
+
construct: (target, argumentsList, newTarget) => (0, internal_1.runWithCapturedModuleContext)(context, () => Reflect.construct(target, argumentsList, newTarget)),
|
|
509
|
+
get: (target, property) => {
|
|
510
|
+
if (property === "prototype") {
|
|
511
|
+
return target.prototype;
|
|
512
|
+
}
|
|
513
|
+
return this.bindInterfaceValue(Reflect.get(target, property, target), context);
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
bindFunctionResult(value, context) {
|
|
518
|
+
if (value instanceof Promise) {
|
|
519
|
+
return value.then((result) => typeof result === "function"
|
|
520
|
+
? this.bindInterfaceValue(result, context)
|
|
521
|
+
: result);
|
|
522
|
+
}
|
|
523
|
+
return typeof value === "function"
|
|
524
|
+
? this.bindInterfaceValue(value, context)
|
|
525
|
+
: value;
|
|
526
|
+
}
|
|
527
|
+
getRoutedEvent(value, context) {
|
|
528
|
+
const identity = (0, interface_core_1.GetInterfaceProxyIdentity)(value);
|
|
529
|
+
const provider = identity
|
|
530
|
+
? (context.providerRoutes?.[identity] ?? context.provider)
|
|
531
|
+
: undefined;
|
|
532
|
+
if (!identity || !provider) {
|
|
533
|
+
return value;
|
|
534
|
+
}
|
|
535
|
+
const key = `${identity}\0${provider}`;
|
|
536
|
+
const routed = this.routedEvents.get(key);
|
|
537
|
+
if (routed) {
|
|
538
|
+
return this.bindRoutedEvent(routed, context);
|
|
279
539
|
}
|
|
280
|
-
|
|
540
|
+
const created = new interface_core_1.EventProxy(`${this.resolverIdentity}:${provider}:${identity}`);
|
|
541
|
+
this.routedEvents.set(key, created);
|
|
542
|
+
return this.bindRoutedEvent(created, context);
|
|
543
|
+
}
|
|
544
|
+
bindRoutedEvent(event, context) {
|
|
545
|
+
const cached = this.boundValues.get(event)?.get(context);
|
|
546
|
+
if (cached) {
|
|
547
|
+
return cached;
|
|
548
|
+
}
|
|
549
|
+
const bound = this.createEventFacade(event, context);
|
|
550
|
+
const contexts = this.boundValues.get(event) ??
|
|
551
|
+
new WeakMap();
|
|
552
|
+
contexts.set(context, bound);
|
|
553
|
+
this.boundValues.set(event, contexts);
|
|
554
|
+
return bound;
|
|
555
|
+
}
|
|
556
|
+
createEventFacade(event, context) {
|
|
557
|
+
const handlers = new WeakMap();
|
|
558
|
+
const register = (handler) => {
|
|
559
|
+
const bound = handlers.get(handler) ?? this.createFunctionFacade(handler, context);
|
|
560
|
+
handlers.set(handler, bound);
|
|
561
|
+
return (0, internal_1.runWithCapturedModuleContext)(context, () => event.register(bound));
|
|
562
|
+
};
|
|
563
|
+
const unregister = (handler) => (0, internal_1.runWithCapturedModuleContext)(context, () => event.unregister(handlers.get(handler) ?? handler));
|
|
564
|
+
const emit = this.createFunctionFacade(event.emit, context, event);
|
|
565
|
+
return new Proxy(event, {
|
|
566
|
+
get: (target, property) => {
|
|
567
|
+
if (property === "register") {
|
|
568
|
+
return register;
|
|
569
|
+
}
|
|
570
|
+
if (property === "unregister") {
|
|
571
|
+
return unregister;
|
|
572
|
+
}
|
|
573
|
+
if (property === "emit") {
|
|
574
|
+
return emit;
|
|
575
|
+
}
|
|
576
|
+
return Reflect.get(target, property, target);
|
|
577
|
+
},
|
|
578
|
+
});
|
|
281
579
|
}
|
|
282
580
|
resolveLocalModule(fileName) {
|
|
283
581
|
if (!fileName) {
|