@peers-app/peers-sdk 0.12.2 → 0.12.4
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.
|
@@ -46,9 +46,11 @@ class UserContext {
|
|
|
46
46
|
* so any tables in packages have been registered are available at sync time
|
|
47
47
|
*/
|
|
48
48
|
loadAllPackages() {
|
|
49
|
-
this.userDataContext.packageLoader.loadAllPackages()
|
|
49
|
+
this.userDataContext.packageLoader.loadAllPackages()
|
|
50
|
+
.catch(err => console.error('[UserContext] loadAllPackages failed for userDataContext:', err));
|
|
50
51
|
for (const groupContext of this.groupDataContexts.values()) {
|
|
51
|
-
groupContext.packageLoader.loadAllPackages()
|
|
52
|
+
groupContext.packageLoader.loadAllPackages()
|
|
53
|
+
.catch(err => console.error('[UserContext] loadAllPackages failed for groupContext:', err));
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
async loadGroupContexts() {
|
|
@@ -95,6 +95,20 @@ class PackageLoader {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
_evaluateBundle(pkg, bundleCode) {
|
|
98
|
+
// Node.js built-in modules that do not exist in React Native (and would cause
|
|
99
|
+
// a fatal native error if passed through to RN's require). We block them here
|
|
100
|
+
// and throw a descriptive JS Error instead, which the surrounding try/catch
|
|
101
|
+
// converts into a warning rather than a process-killing crash.
|
|
102
|
+
//
|
|
103
|
+
// In Node.js / Electron environments these modules ARE available, so we skip
|
|
104
|
+
// the guard and let require pass through normally.
|
|
105
|
+
const isNodeEnvironment = typeof process !== 'undefined' && !!process.versions?.node;
|
|
106
|
+
const NODE_ONLY_MODULES = new Set([
|
|
107
|
+
'child_process', 'fs', 'path', 'os', 'crypto', 'http', 'https',
|
|
108
|
+
'net', 'tls', 'stream', 'buffer', 'util', 'events', 'assert',
|
|
109
|
+
'dns', 'url', 'querystring', 'readline', 'repl', 'vm',
|
|
110
|
+
'worker_threads', 'cluster', 'perf_hooks',
|
|
111
|
+
]);
|
|
98
112
|
const moduleExports = {};
|
|
99
113
|
const module = { exports: moduleExports };
|
|
100
114
|
const customRequire = (moduleId) => {
|
|
@@ -113,26 +127,37 @@ class PackageLoader {
|
|
|
113
127
|
// external Node modules they need (e.g. child_process, os, path), and the loader
|
|
114
128
|
// should verify they are allowed before granting access. For now we pass through
|
|
115
129
|
// to the underlying require and log a warning so usages remain visible.
|
|
130
|
+
if (!isNodeEnvironment && NODE_ONLY_MODULES.has(moduleId)) {
|
|
131
|
+
// Throw a plain JS Error so the surrounding try/catch can handle it
|
|
132
|
+
// gracefully instead of letting RN's require trigger a native fatal.
|
|
133
|
+
throw new Error(`[PackageLoader] Package "${pkg.name}" required Node.js-only module "${moduleId}" which is not available in this environment`);
|
|
134
|
+
}
|
|
116
135
|
console.warn(`Package ${pkg.name} is requiring a module ${moduleId}, which is not provided by the package loader.`);
|
|
117
136
|
return _require(moduleId);
|
|
118
137
|
}
|
|
119
138
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
packageInstance
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
139
|
+
try {
|
|
140
|
+
const bundleFunction = new Function('module', 'exports', 'require', bundleCode);
|
|
141
|
+
bundleFunction(module, moduleExports, customRequire);
|
|
142
|
+
const bundleExports = module.exports;
|
|
143
|
+
const packageInstance = bundleExports?.exports || bundleExports?.package || bundleExports?.default || bundleExports;
|
|
144
|
+
this.packageInstances[pkg.packageId] = packageInstance;
|
|
145
|
+
if (packageInstance && typeof packageInstance === 'object') {
|
|
146
|
+
packageInstance.toolInstances?.forEach((toolInstance) => {
|
|
147
|
+
(0, tools_1.registerTool)(toolInstance);
|
|
148
|
+
(0, tools_2.Tools)(this.dataContext).save(toolInstance.tool);
|
|
149
|
+
});
|
|
150
|
+
packageInstance.tableDefinitions?.forEach((tableDefinition) => {
|
|
151
|
+
this.dataContext.tableContainer.registerTableDefinition(tableDefinition, { overwrite: true });
|
|
152
|
+
});
|
|
153
|
+
return packageInstance;
|
|
154
|
+
}
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
console.warn(`[PackageLoader] Failed to evaluate bundle for "${pkg.name}":`, err.message);
|
|
159
|
+
return undefined;
|
|
134
160
|
}
|
|
135
|
-
return;
|
|
136
161
|
}
|
|
137
162
|
}
|
|
138
163
|
exports.PackageLoader = PackageLoader;
|