initial commit taken from gitlab.lrz.de

This commit is contained in:
privatereese
2018-08-24 18:09:42 +02:00
parent ae54ed4c48
commit fc05486403
28494 changed files with 2159823 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule getDevServer
* @flow
*/
'use strict';
const {SourceCode} = require('NativeModules');
let _cachedDevServerURL: ?string;
const FALLBACK = 'http://localhost:8081/';
type DevServerInfo = {
url: string,
bundleLoadedFromServer: boolean,
};
/**
* Many RN development tools rely on the development server (packager) running
* @return URL to packager with trailing slash
*/
function getDevServer(): DevServerInfo {
if (_cachedDevServerURL === undefined) {
const match = SourceCode && SourceCode.scriptURL && SourceCode.scriptURL.match(/^https?:\/\/.*?\//);
_cachedDevServerURL = match ? match[0] : null;
}
return {
url: _cachedDevServerURL || FALLBACK,
bundleLoadedFromServer: _cachedDevServerURL !== null,
};
}
module.exports = getDevServer;

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule openFileInEditor
* @flow
*/
'use strict';
const getDevServer = require('getDevServer');
function openFileInEditor(file: string, lineNumber: number) {
fetch(getDevServer().url + 'open-stack-frame', {
method: 'POST',
body: JSON.stringify({file, lineNumber}),
});
}
module.exports = openFileInEditor;

View File

@@ -0,0 +1,41 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule parseErrorStack
* @flow
*/
'use strict';
export type StackFrame = {
column: ?number,
file: string,
lineNumber: number,
methodName: string,
};
export type ExtendedError = Error & {
framesToPop?: number,
};
function parseErrorStack(e: ExtendedError): Array<StackFrame> {
if (!e || !e.stack) {
return [];
}
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
const stacktraceParser = require('stacktrace-parser');
const stack = Array.isArray(e.stack) ? e.stack : stacktraceParser.parse(e.stack);
let framesToPop = typeof e.framesToPop === 'number' ? e.framesToPop : 0;
while (framesToPop--) {
stack.shift();
}
return stack;
}
module.exports = parseErrorStack;

View File

@@ -0,0 +1,62 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule setupDevtools
* @flow
*/
'use strict';
type DevToolsPluginConnection = {
isAppActive: () => boolean,
host: string,
port: number,
};
type DevToolsPlugin = {
connectToDevTools: (connection: DevToolsPluginConnection) => void,
};
let register = function () {
// noop
};
if (__DEV__) {
const AppState = require('AppState');
const WebSocket = require('WebSocket');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an
* error found when Flow v0.54 was deployed. To see the error delete this
* comment and run Flow. */
const reactDevTools = require('react-devtools-core');
const getDevServer = require('getDevServer');
// Initialize dev tools only if the native module for WebSocket is available
if (WebSocket.isAvailable) {
// Don't steal the DevTools from currently active app.
// Note: if you add any AppState subscriptions to this file,
// you will also need to guard against `AppState.isAvailable`,
// or the code will throw for bundles that don't have it.
const isAppActive = () => AppState.currentState !== 'background';
// Get hostname from development server (packager)
const devServer = getDevServer();
const host = devServer.bundleLoadedFromServer
? devServer.url.replace(/https?:\/\//, '').split(':')[0]
: 'localhost';
reactDevTools.connectToDevTools({
isAppActive,
host,
// Read the optional global variable for backward compatibility.
// It was added in https://github.com/facebook/react-native/commit/bf2b435322e89d0aeee8792b1c6e04656c2719a0.
port: window.__REACT_DEVTOOLS_PORT__,
resolveRNStyle: require('flattenStyle'),
});
}
}
module.exports = {
register,
};

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule symbolicateStackTrace
* @flow
*/
'use strict';
const getDevServer = require('getDevServer');
const {SourceCode} = require('NativeModules');
// Avoid requiring fetch on load of this module; see symbolicateStackTrace
let fetch;
import type {StackFrame} from 'parseErrorStack';
function isSourcedFromDisk(sourcePath: string): boolean {
return !/^http/.test(sourcePath) && /[\\/]/.test(sourcePath);
}
async function symbolicateStackTrace(stack: Array<StackFrame>): Promise<Array<StackFrame>> {
// RN currently lazy loads whatwg-fetch using a custom fetch module, which,
// when called for the first time, requires and re-exports 'whatwg-fetch'.
// However, when a dependency of the project tries to require whatwg-fetch
// either directly or indirectly, whatwg-fetch is required before
// RN can lazy load whatwg-fetch. As whatwg-fetch checks
// for a fetch polyfill before loading, it will in turn try to load
// RN's fetch module, which immediately tries to import whatwg-fetch AGAIN.
// This causes a circular require which results in RN's fetch module
// exporting fetch as 'undefined'.
// The fix below postpones trying to load fetch until the first call to symbolicateStackTrace.
// At that time, we will have either global.fetch (whatwg-fetch) or RN's fetch.
if (!fetch) {
fetch = global.fetch || require('fetch').fetch;
}
const devServer = getDevServer();
if (!devServer.bundleLoadedFromServer) {
throw new Error('Bundle was not loaded from the packager');
}
let stackCopy = stack;
if (SourceCode.scriptURL) {
let foundInternalSource: boolean = false;
stackCopy = stack.map((frame: StackFrame) => {
// If the sources exist on disk rather than appearing to come from the packager,
// replace the location with the packager URL until we reach an internal source
// which does not have a path (no slashes), indicating a switch from within
// the application to a surrounding debugging environment.
if (!foundInternalSource && isSourcedFromDisk(frame.file)) {
// Copy frame into new object and replace 'file' property
return {...frame, file: SourceCode.scriptURL};
}
foundInternalSource = true;
return frame;
});
}
const response = await fetch(devServer.url + 'symbolicate', {
method: 'POST',
body: JSON.stringify({stack: stackCopy}),
});
const json = await response.json();
return json.stack;
}
module.exports = symbolicateStackTrace;