Workaround to load realm from ubuntu_server.js
This commit is contained in:
parent
07c3b1f722
commit
edffdd3d36
54
lib/index.js
54
lib/index.js
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue