Workaround to load realm from ubuntu_server.js

This commit is contained in:
yenda 2018-11-29 17:03:48 +01:00
parent 07c3b1f722
commit edffdd3d36
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
1 changed files with 22 additions and 44 deletions

View File

@ -18,6 +18,13 @@
'use strict';
console.log("outerRealmConstructor: " + typeof outerRealmConstructor);
if (typeof outerRealmConstructor !== 'undefined') {
var realmConstructor = outerRealmConstructor;
module.exports = realmConstructor;
}
if (typeof outerRealmConstructor === 'undefined') {
const require_method = require;
// Prevent React Native packager from seeing modules required with this
@ -35,12 +42,12 @@ function getContext() {
return 'vscodedebugger';
}
return process.type === 'renderer' ? 'electron' : 'node.js';
return process.type === 'renderer' ? 'electron' : 'nodejs';
}
// When running via Jest, the jest object is defined.
if (typeof jest === 'object') {
return 'node.js';
return 'nodejs';
}
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') { // eslint-disable-line no-undef
@ -57,6 +64,9 @@ function getContext() {
return 'chromedebugger';
}
// react-native-desktop expects "nodejs" env
return 'nodejs';
// Otherwise, we must be in a "normal" react native situation.
// In that case, the Realm type should have been injected by the native code.
// If it hasn't, the user likely forgot to run link.
@ -87,35 +97,12 @@ function getContext() {
throw Error("Unknown execution context");
}
function createUserAgentDescription() {
// Detect if in ReactNative (running on a phone) or in a Node.js environment
// Credit: https://stackoverflow.com/questions/39468022/how-do-i-know-if-my-code-is-running-as-react-native
try {
var userAgent = "RealmJS/";
var context = getContext();
userAgent = userAgent + require('../package.json').version + " (" + context + ", ";
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
// Running on ReactNative
const Platform = require('react-native').Platform;
userAgent += Platform.OS + ", v" + Platform.Version;
} else {
// Running on a normal machine
userAgent += process.version;
}
return userAgent += ")";
} catch (e) {
return "RealmJS/Unknown"
}
}
var realmConstructor;
const context = getContext();
switch(context) {
case 'node.js':
switch(getContext()) {
case 'nodejs':
case 'electron':
nodeRequire('./submit-analytics')('Run', context);
nodeRequire('./submit-analytics')('Run');
var binary = nodeRequire('node-pre-gyp');
var path = nodeRequire('path');
@ -142,14 +129,5 @@ if (!realmConstructor) {
require('./extensions')(realmConstructor);
if (realmConstructor.Sync) {
if (context === 'node.js') {
nodeRequire('./notifier')(realmConstructor);
if (!realmConstructor.Worker) {
Object.defineProperty(realmConstructor, 'Worker', {value: nodeRequire('./worker')});
}
}
realmConstructor.Sync._initializeSyncManager(createUserAgentDescription());
}
module.exports = realmConstructor;
}