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,39 @@
/**
* 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.
*/
'use strict';
var chalk = require('chalk');
var formatBanner = require('metro-core/src/formatBanner');
var semver = require('semver');
module.exports = function() {
if (!semver.satisfies(process.version, '>=4')) {
var engine = semver.satisfies(process.version, '<1')
? 'Node'
: 'io.js';
var message = 'You are currently running ' + engine + ' ' +
process.version + '.\n' +
'\n' +
'React Native runs on Node 4.0 or newer. There are several ways to ' +
'upgrade Node.js depending on your preference.\n' +
'\n' +
'nvm: nvm install node && nvm alias default node\n' +
'Homebrew: brew unlink iojs; brew install node\n' +
'Installer: download the Mac .pkg from https://nodejs.org/\n' +
'\n' +
'About Node.js: https://nodejs.org\n' +
'Follow along at: https://github.com/facebook/react-native/issues/2545';
console.log(formatBanner(message, {
chalkFunction: chalk.green,
marginLeft: 1,
marginRight: 1,
paddingBottom: 1,
}));
process.exit(1);
}
};

View File

@@ -0,0 +1,26 @@
/**
* 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.
*/
'use strict';
const copyToClipBoard = require('../util/copyToClipBoard');
var chalk = require('chalk');
/**
* Handle the request from JS to copy contents onto host system clipboard.
* This is only supported on Mac for now.
*/
module.exports = function(req, res, next) {
if (req.url === '/copy-to-clipboard') {
var ret = copyToClipBoard(req.rawBody);
if (!ret) {
console.warn(chalk.red('Copy button is not supported on this platform!'));
}
res.end('OK');
} else {
next();
}
};

View File

@@ -0,0 +1,70 @@
/**
* 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.
*
* @format
*/
'use strict';
const launchChrome = require('../util/launchChrome');
const {exec} = require('child_process');
function launchChromeDevTools(host, args = '') {
var debuggerURL = 'http://' + host + '/debugger-ui' + args;
console.log('Launching Dev Tools...');
launchChrome(debuggerURL);
}
function escapePath(pathname) {
// " Can escape paths with spaces in OS X, Windows, and *nix
return '"' + pathname + '"';
}
function launchDevTools({host, projectRoots}, isChromeConnected) {
// Explicit config always wins
var customDebugger = process.env.REACT_DEBUGGER;
if (customDebugger) {
var projects = projectRoots.map(escapePath).join(' ');
var command = customDebugger + ' ' + projects;
console.log('Starting custom debugger by executing: ' + command);
exec(command, function(error, stdout, stderr) {
if (error !== null) {
console.log('Error while starting custom debugger: ' + error);
}
});
} else if (!isChromeConnected()) {
// Dev tools are not yet open; we need to open a session
launchChromeDevTools(host);
}
}
module.exports = function(options, isChromeConnected) {
return function(req, res, next) {
var host = req.headers.host;
if (req.url === '/launch-safari-devtools') {
// TODO: remove `console.log` and dev tools binary
console.log(
'We removed support for Safari dev-tools. ' +
'If you still need this, please let us know.',
);
} else if (req.url === '/launch-chrome-devtools') {
// TODO: Remove this case in the future
console.log(
'The method /launch-chrome-devtools is deprecated. You are ' +
' probably using an application created with an older CLI with the ' +
' packager of a newer CLI. Please upgrade your application: ' +
'https://facebook.github.io/react-native/docs/upgrading.html',
);
launchDevTools(options, isChromeConnected);
res.end('OK');
} else if (req.url === '/launch-js-devtools') {
launchDevTools({...options, host}, isChromeConnected);
res.end('OK');
} else {
next();
}
};
};

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>React Native</title>
</head>
<body>
<p>React Native packager is running.</p>
<p><a href="http://facebook.github.io/react-native/">Visit documentation</a></p>
</body>
</html>

View File

@@ -0,0 +1,18 @@
/**
* 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.
*/
'use strict';
const fs = require('fs');
const path = require('path');
module.exports = function(req, res, next) {
if (req.url === '/') {
res.end(fs.readFileSync(path.join(__dirname, 'index.html')));
} else {
next();
}
};

View File

@@ -0,0 +1,20 @@
/**
* 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.
*/
'use strict';
module.exports = function(req, res, next) {
req.rawBody = '';
req.setEncoding('utf8');
req.on('data', function(chunk) {
req.rawBody += chunk;
});
req.on('end', function() {
next();
});
};

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.
*/
'use strict';
const launchEditor = require('../util/launchEditor');
module.exports = function({projectRoots}) {
return function(req, res, next) {
if (req.url === '/open-stack-frame') {
const frame = JSON.parse(req.rawBody);
launchEditor(frame.file, frame.lineNumber, projectRoots);
res.end('OK');
} else {
next();
}
};
};

View File

@@ -0,0 +1,19 @@
/**
* 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.
*/
'use strict';
/**
* Status page so that anyone who needs to can verify that the packager is
* running on 8081 and not another program / service.
*/
module.exports = function(req, res, next) {
if (req.url === '/status') {
res.end('packager-status:running');
} else {
next();
}
};

View File

@@ -0,0 +1,27 @@
/**
* 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.
*/
'use strict';
const fs = require('fs');
module.exports = function(req, res, next) {
if (req.url !== '/systrace') {
next();
return;
}
console.log('Dumping profile information...');
var dumpName = '/tmp/dump_' + Date.now() + '.json';
fs.writeFileSync(dumpName, req.rawBody);
var response =
'Your profile was saved at:\n' + dumpName + '\n\n' +
'On Google Chrome navigate to chrome://tracing and then click on "load" ' +
'to load and visualise your profile.\n\n' +
'This message is also printed to your console by the packager so you can copy it :)';
console.log(response);
res.end(response);
};

View File

@@ -0,0 +1,17 @@
/**
* 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.
*/
'use strict';
module.exports = (url, middleware) => {
return (req, res, next) => {
if (req.url === url || req.url.startsWith(url + '/')) {
middleware(req, res, next);
} else {
next();
}
};
};

200
node_modules/react-native/local-cli/server/runServer.js generated vendored Normal file
View File

@@ -0,0 +1,200 @@
/**
* 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.
*
* @flow
* @format
*/
'use strict';
require('../../setupBabel')();
const Metro = require('metro');
const HmrServer = require('metro/src/HmrServer');
const {Terminal} = require('metro-core');
const attachWebsocketServer = require('./util/attachWebsocketServer');
const compression = require('compression');
const connect = require('connect');
const copyToClipBoardMiddleware = require('./middleware/copyToClipBoardMiddleware');
const defaultAssetExts = Metro.defaults.assetExts;
const defaultSourceExts = Metro.defaults.sourceExts;
const defaultPlatforms = Metro.defaults.platforms;
const defaultProvidesModuleNodeModules =
Metro.defaults.providesModuleNodeModules;
const errorhandler = require('errorhandler');
const fs = require('fs');
const getDevToolsMiddleware = require('./middleware/getDevToolsMiddleware');
const http = require('http');
const https = require('https');
const indexPageMiddleware = require('./middleware/indexPage');
const loadRawBodyMiddleware = require('./middleware/loadRawBodyMiddleware');
const messageSocket = require('./util/messageSocket.js');
const morgan = require('morgan');
const openStackFrameInEditorMiddleware = require('./middleware/openStackFrameInEditorMiddleware');
const path = require('path');
const serveStatic = require('serve-static');
const statusPageMiddleware = require('./middleware/statusPageMiddleware.js');
const systraceProfileMiddleware = require('./middleware/systraceProfileMiddleware.js');
const webSocketProxy = require('./util/webSocketProxy.js');
/* $FlowFixMe(site=react_native_oss) */
const TransformCaching = require('metro/src/lib/TransformCaching');
const {ASSET_REGISTRY_PATH} = require('../core/Constants');
/* $FlowFixMe(site=react_native_oss) */
import type {ConfigT} from 'metro';
/* $FlowFixMe(site=react_native_oss) */
import type {Reporter} from 'metro/src/lib/reporting';
export type Args = {|
+assetExts: $ReadOnlyArray<string>,
+host: string,
+maxWorkers: number,
+nonPersistent: boolean,
+platforms: $ReadOnlyArray<string>,
+port: number,
+projectRoots: $ReadOnlyArray<string>,
+resetCache: boolean,
+sourceExts: $ReadOnlyArray<string>,
+verbose: boolean,
|};
function runServer(
args: Args,
config: ConfigT,
// FIXME: this is weird design. The top-level should pass down a custom
// reporter rather than passing it up as argument to an event.
startedCallback: (reporter: Reporter) => mixed,
readyCallback: (reporter: Reporter) => mixed,
) {
var wsProxy = null;
var ms = null;
const terminal = new Terminal(process.stdout);
const ReporterImpl = getReporterImpl(args.customLogReporterPath || null);
const reporter = new ReporterImpl(terminal);
const packagerServer = getPackagerServer(args, config, reporter);
startedCallback(reporter);
const app = connect()
.use(loadRawBodyMiddleware)
.use(compression())
.use(
'/debugger-ui',
serveStatic(path.join(__dirname, 'util', 'debugger-ui')),
)
.use(
getDevToolsMiddleware(args, () => wsProxy && wsProxy.isChromeConnected()),
)
.use(getDevToolsMiddleware(args, () => ms && ms.isChromeConnected()))
.use(openStackFrameInEditorMiddleware(args))
.use(copyToClipBoardMiddleware)
.use(statusPageMiddleware)
.use(systraceProfileMiddleware)
.use(indexPageMiddleware)
.use(packagerServer.processRequest.bind(packagerServer));
args.projectRoots.forEach(root => app.use(serveStatic(root)));
app.use(morgan('combined')).use(errorhandler());
if (args.https && (!args.key || !args.cert)) {
throw new Error('Cannot use https without specifying key and cert options');
}
const serverInstance = args.https
? https.createServer(
{
key: fs.readFileSync(args.key),
cert: fs.readFileSync(args.cert),
},
app,
)
: http.createServer(app);
serverInstance.listen(args.port, args.host, 511, function() {
attachWebsocketServer({
httpServer: serverInstance,
path: '/hot',
websocketServer: new HmrServer(packagerServer),
});
wsProxy = webSocketProxy.attachToServer(serverInstance, '/debugger-proxy');
ms = messageSocket.attachToServer(serverInstance, '/message');
readyCallback(reporter);
});
// Disable any kind of automatic timeout behavior for incoming
// requests in case it takes the packager more than the default
// timeout of 120 seconds to respond to a request.
serverInstance.timeout = 0;
}
function getReporterImpl(customLogReporterPath: ?string) {
if (customLogReporterPath == null) {
return require('metro/src/lib/TerminalReporter');
}
try {
// First we let require resolve it, so we can require packages in node_modules
// as expected. eg: require('my-package/reporter');
/* $FlowFixMe: can't type dynamic require */
return require(customLogReporterPath);
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
}
// If that doesn't work, then we next try relative to the cwd, eg:
// require('./reporter');
/* $FlowFixMe: can't type dynamic require */
return require(path.resolve(customLogReporterPath));
}
}
function getPackagerServer(args, config, reporter) {
const transformModulePath = args.transformer
? path.resolve(args.transformer)
: config.getTransformModulePath();
const providesModuleNodeModules =
args.providesModuleNodeModules || defaultProvidesModuleNodeModules;
return Metro.createServer({
assetExts: defaultAssetExts.concat(args.assetExts),
assetRegistryPath: ASSET_REGISTRY_PATH,
blacklistRE: config.getBlacklistRE(),
cacheStores: config.cacheStores,
cacheVersion: '3',
enableBabelRCLookup: config.getEnableBabelRCLookup(),
extraNodeModules: config.extraNodeModules,
dynamicDepsInPackages: config.dynamicDepsInPackages,
getModulesRunBeforeMainModule: config.getModulesRunBeforeMainModule,
getPolyfills: config.getPolyfills,
getTransformOptions: config.getTransformOptions,
globalTransformCache: null,
hasteImplModulePath: config.hasteImplModulePath,
maxWorkers: args.maxWorkers,
platforms: defaultPlatforms.concat(args.platforms),
polyfillModuleNames: config.getPolyfillModuleNames(),
postMinifyProcess: config.postMinifyProcess,
postProcessBundleSourcemap: config.postProcessBundleSourcemap,
postProcessModules: config.postProcessModules,
projectRoots: args.projectRoots,
providesModuleNodeModules: providesModuleNodeModules,
reporter,
resetCache: args.resetCache,
sourceExts: args.sourceExts.concat(defaultSourceExts),
transformModulePath: transformModulePath,
transformCache: TransformCaching.useTempDir(),
verbose: args.verbose,
watch: !args.nonPersistent,
workerPath: config.getWorkerPath(),
});
}
module.exports = runServer;

135
node_modules/react-native/local-cli/server/server.js generated vendored Normal file
View File

@@ -0,0 +1,135 @@
/**
* 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.
*
* @flow
*/
'use strict';
const path = require('path');
const runServer = require('./runServer');
import type {RNConfig} from '../core';
import type {ConfigT} from 'metro';
import type {Args as RunServerArgs} from './runServer';
/**
* Starts the React Native Packager Server.
*/
function server(argv: mixed, config: RNConfig, allArgs: Object) {
const {root, ...args} = allArgs;
args.projectRoots = args.projectRoots.concat(root);
const startedCallback = logReporter => {
logReporter.update({
type: 'initialize_started',
port: args.port,
projectRoots: args.projectRoots,
});
process.on('uncaughtException', error => {
logReporter.update({
type: 'initialize_failed',
port: args.port,
error,
});
process.exit(11);
});
};
const readyCallback = logReporter => {
logReporter.update({
type: 'initialize_done',
});
};
const runServerArgs: RunServerArgs = args;
/* $FlowFixMe: ConfigT shouldn't be extendable. */
const configT: ConfigT = config;
runServer(runServerArgs, configT, startedCallback, readyCallback);
}
module.exports = {
name: 'start',
func: server,
description: 'starts the webserver',
options: [{
command: '--port [number]',
default: process.env.RCT_METRO_PORT || 8081,
parse: (val: string) => Number(val),
}, {
command: '--host [string]',
default: '',
}, {
command: '--root [list]',
description: 'add another root(s) to be used by the packager in this project',
parse: (val: string) => val.split(',').map(root => path.resolve(root)),
default: [],
}, {
command: '--projectRoots [list]',
description: 'override the root(s) to be used by the packager',
parse: (val: string) => val.split(','),
default: (config: ConfigT) => config.getProjectRoots(),
}, {
command: '--assetExts [list]',
description: 'Specify any additional asset extensions to be used by the packager',
parse: (val: string) => val.split(','),
default: (config: ConfigT) => config.getAssetExts(),
}, {
command: '--sourceExts [list]',
description: 'Specify any additional source extensions to be used by the packager',
parse: (val: string) => val.split(','),
default: (config: ConfigT) => config.getSourceExts(),
}, {
command: '--platforms [list]',
description: 'Specify any additional platforms to be used by the packager',
parse: (val: string) => val.split(','),
default: (config: ConfigT) => config.getPlatforms(),
}, {
command: '--providesModuleNodeModules [list]',
description: 'Specify any npm packages that import dependencies with providesModule',
parse: (val: string) => val.split(','),
default: (config: RNConfig) => {
if (typeof config.getProvidesModuleNodeModules === 'function') {
return config.getProvidesModuleNodeModules();
}
return null;
},
}, {
command: '--max-workers [number]',
description: 'Specifies the maximum number of workers the worker-pool ' +
'will spawn for transforming files. This defaults to the number of the ' +
'cores available on your machine.',
parse: (workers: string) => Number(workers),
}, {
command: '--skipflow',
description: 'Disable flow checks'
}, {
command: '--nonPersistent',
description: 'Disable file watcher'
}, {
command: '--transformer [string]',
description: 'Specify a custom transformer to be used'
}, {
command: '--reset-cache, --resetCache',
description: 'Removes cached files',
}, {
command: '--custom-log-reporter-path, --customLogReporterPath [string]',
description: 'Path to a JavaScript file that exports a log reporter as a replacement for TerminalReporter',
}, {
command: '--verbose',
description: 'Enables logging',
}, {
command: '--https',
description: 'Enables https connections to the server',
}, {
command: '--key [path]',
description: 'Path to custom SSL key',
}, {
command: '--cert [path]',
description: 'Path to custom SSL cert',
}],
};

View File

@@ -0,0 +1,76 @@
/**
* 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.
*
* @format
* @flow
*/
'use strict';
import type {Server as HTTPServer} from 'http';
import type {Server as HTTPSServer} from 'https';
type WebsocketServiceInterface<T> = {
+onClientConnect: (
url: string,
sendFn: (data: string) => mixed,
) => Promise<T>,
+onClientDisconnect?: (client: T) => mixed,
+onClientError?: (client: T, e: Error) => mixed,
+onClientMessage?: (client: T, message: string) => mixed,
};
type HMROptions<TClient> = {
httpServer: HTTPServer | HTTPSServer,
websocketServer: WebsocketServiceInterface<TClient>,
path: string,
};
/**
* Attaches a WebSocket based connection to the Packager to expose
* Hot Module Replacement updates to the simulator.
*/
function attachWebsocketServer<TClient: Object>({
httpServer,
websocketServer,
path,
}: HMROptions<TClient>) {
const WebSocketServer = require('ws').Server;
const wss = new WebSocketServer({
server: httpServer,
path: path,
});
wss.on('connection', async ws => {
let connected = true;
const url = ws.upgradeReq.url;
const sendFn = (...args) => {
if (connected) {
ws.send(...args);
}
};
const client = await websocketServer.onClientConnect(url, sendFn);
ws.on('error', e => {
websocketServer.onClientError && websocketServer.onClientError(client, e);
});
ws.on('close', () => {
websocketServer.onClientDisconnect &&
websocketServer.onClientDisconnect(client);
connected = false;
});
ws.on('message', message => {
websocketServer.onClientMessage &&
websocketServer.onClientMessage(client, message);
});
});
}
module.exports = attachWebsocketServer;

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.
*/
'use strict';
var child_process = require('child_process');
var spawn = child_process.spawn;
var path = require('path');
var fs = require('fs');
const xsel = path.join(__dirname, 'external/xsel');
fs.chmodSync(xsel, '0755');
/**
* Copy the content to host system clipboard.
*/
function copyToClipBoard(content) {
switch (process.platform) {
case 'darwin':
var child = spawn('pbcopy', []);
child.stdin.end(new Buffer(content, 'utf8'));
return true;
case 'win32':
var child = spawn('clip', []);
child.stdin.end(new Buffer(content, 'utf8'));
return true;
case 'linux':
var child = spawn(xsel, ['--clipboard', '--input']);
child.stdin.end(new Buffer(content, 'utf8'));
return true;
default:
return false;
}
}
module.exports = copyToClipBoard;

View File

@@ -0,0 +1,130 @@
/**
* 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.
*
* @format
*/
/**
* This file is a copy of the reference `DeltaPatcher`, located in
* metro. The reason to not reuse that file is that in this context
* we cannot have flow annotations or CJS syntax (since this file is directly)
* injected into a static HTML page.
*
* TODO: Find a simple and lightweight way to compile `DeltaPatcher` to avoid
* having this duplicated file.
*/
(function(global) {
'use strict';
/**
* This is a reference client for the Delta Bundler: it maintains cached the
* last patched bundle delta and it's capable of applying new Deltas received
* from the Bundler.
*/
class DeltaPatcher {
constructor() {
this._lastBundle = {
pre: new Map(),
post: new Map(),
modules: new Map(),
id: undefined,
};
this._initialized = false;
this._lastNumModifiedFiles = 0;
this._lastModifiedDate = new Date();
}
static get(id) {
let deltaPatcher = this._deltaPatchers.get(id);
if (!deltaPatcher) {
deltaPatcher = new DeltaPatcher();
this._deltaPatchers.set(id, deltaPatcher);
}
return deltaPatcher;
}
/**
* Applies a Delta Bundle to the current bundle.
*/
applyDelta(deltaBundle) {
// Make sure that the first received delta is a fresh one.
if (!this._initialized && !deltaBundle.reset) {
throw new Error(
'DeltaPatcher should receive a fresh Delta when being initialized',
);
}
this._initialized = true;
// Reset the current delta when we receive a fresh delta.
if (deltaBundle.reset) {
this._lastBundle = {
pre: new Map(),
post: new Map(),
modules: new Map(),
id: undefined,
};
}
this._lastNumModifiedFiles =
deltaBundle.pre.size + deltaBundle.post.size + deltaBundle.delta.size;
if (this._lastNumModifiedFiles > 0) {
this._lastModifiedDate = new Date();
}
this._patchMap(this._lastBundle.pre, deltaBundle.pre);
this._patchMap(this._lastBundle.post, deltaBundle.post);
this._patchMap(this._lastBundle.modules, deltaBundle.delta);
this._lastBundle.id = deltaBundle.id;
return this;
}
getLastBundleId() {
return this._lastBundle.id;
}
/**
* Returns the number of modified files in the last received Delta. This is
* currently used to populate the `X-Metro-Files-Changed-Count` HTTP header
* when metro serves the whole JS bundle, and can potentially be removed once
* we only send the actual deltas to clients.
*/
getLastNumModifiedFiles() {
return this._lastNumModifiedFiles;
}
getLastModifiedDate() {
return this._lastModifiedDate;
}
getAllModules() {
return [].concat(
Array.from(this._lastBundle.pre.values()),
Array.from(this._lastBundle.modules.values()),
Array.from(this._lastBundle.post.values()),
);
}
_patchMap(original, patch) {
for (const [key, value] of patch.entries()) {
if (value == null) {
original.delete(key);
} else {
original.set(key, value);
}
}
}
}
DeltaPatcher._deltaPatchers = new Map();
global.DeltaPatcher = DeltaPatcher;
})(window);

View File

@@ -0,0 +1,81 @@
/**
* 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.
*/
/* global __fbBatchedBridge, self, importScripts, postMessage, onmessage: true */
/* eslint no-unused-vars: 0 */
'use strict';
onmessage = (function() {
var visibilityState;
var showVisibilityWarning = (function() {
var hasWarned = false;
return function() {
// Wait until `YellowBox` gets initialized before displaying the warning.
if (hasWarned || console.warn.toString().includes('[native code]')) {
return;
}
hasWarned = true;
console.warn(
'Remote debugger is in a background tab which may cause apps to ' +
'perform slowly. Fix this by foregrounding the tab (or opening it in ' +
'a separate window).'
);
};
})();
var messageHandlers = {
'executeApplicationScript': function(message, sendReply) {
for (var key in message.inject) {
self[key] = JSON.parse(message.inject[key]);
}
var error;
try {
importScripts(message.url);
} catch (err) {
error = err.message;
}
sendReply(null /* result */, error);
},
'setDebuggerVisibility': function(message) {
visibilityState = message.visibilityState;
},
};
return function(message) {
if (visibilityState === 'hidden') {
showVisibilityWarning();
}
var object = message.data;
var sendReply = function(result, error) {
postMessage({replyID: object.id, result: result, error: error});
};
var handler = messageHandlers[object.method];
if (handler) {
// Special cased handlers
handler(object, sendReply);
} else {
// Other methods get called on the bridge
var returnValue = [[], [], [], 0];
var error;
try {
if (typeof __fbBatchedBridge === 'object') {
returnValue = __fbBatchedBridge[object.method].apply(null, object.arguments);
} else {
error = 'Failed to call function, __fbBatchedBridge is undefined';
}
} catch (err) {
error = err.message;
} finally {
sendReply(JSON.stringify(returnValue), error);
}
}
};
})();

View File

@@ -0,0 +1,71 @@
/**
* 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.
*
* @flow
* @format
*/
/* global Blob, URL: true */
(function(global) {
'use strict';
let cachedBundleUrls = new Map();
/**
* Converts the passed delta URL into an URL object containing already the
* whole JS bundle Blob.
*/
async function deltaUrlToBlobUrl(deltaUrl) {
const client = global.DeltaPatcher.get(deltaUrl);
const deltaBundleId = client.getLastBundleId()
? `&deltaBundleId=${client.getLastBundleId()}`
: '';
const data = await fetch(deltaUrl + deltaBundleId);
const bundle = await data.json();
const deltaPatcher = client.applyDelta({
id: bundle.id,
pre: new Map(bundle.pre),
post: new Map(bundle.post),
delta: new Map(bundle.delta),
reset: bundle.reset,
});
let cachedBundle = cachedBundleUrls.get(deltaUrl);
// If nothing changed, avoid recreating a bundle blob by reusing the
// previous one.
if (deltaPatcher.getLastNumModifiedFiles() === 0 && cachedBundle) {
return cachedBundle;
}
// Clean up the previous bundle URL to not leak memory.
if (cachedBundle) {
URL.revokeObjectURL(cachedBundle);
}
// To make Source Maps work correctly, we need to add a newline between
// modules.
const blobContent = deltaPatcher
.getAllModules()
.map(module => module + '\n');
// Build the blob with the whole JS bundle.
const blob = new Blob(blobContent, {
type: 'application/javascript',
});
const bundleContents = URL.createObjectURL(blob);
cachedBundleUrls.set(deltaUrl, bundleContents);
return bundleContents;
}
global.deltaUrlToBlobUrl = deltaUrlToBlobUrl;
})(window || {});

File diff suppressed because one or more lines are too long

BIN
node_modules/react-native/local-cli/server/util/external/xsel generated vendored Executable file

Binary file not shown.

View File

@@ -0,0 +1,113 @@
/**
* Copyright (c) 2013-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.
*
*/
'use strict';
const WebSocket = require('ws');
const parseMessage = require('./messageSocket').parseMessage;
const PROTOCOL_VERSION = 2;
const TARGET_SERVER = 'server';
function getMessageId() {
return `${Date.now()}:${Math.random()}`;
}
class JsPackagerClient {
constructor(url) {
this.ws = new WebSocket(url);
this.msgCallbacks = new Map();
this.openPromise = new Promise((resolve, reject) => {
this.ws.on('error', error => reject(error));
this.ws.on('open', resolve);
});
this.ws.on('message', (data, flags) => {
const message = parseMessage(data, flags.binary);
const msgCallback = this.msgCallbacks.get(message.id);
if (message === undefined || message.id === undefined) {
// gracefully ignore wrong messages or broadcasts
} else if (msgCallback === undefined) {
console.warn(`Response with non-existing message id: '${message.id}'`);
} else {
if (message.error === undefined) {
msgCallback.resolve(message.result);
} else {
msgCallback.reject(message.error);
}
}
});
}
sendRequest(method, target, params) {
return this.openPromise.then(() => new Promise((resolve, reject) => {
const messageId = getMessageId();
this.msgCallbacks.set(messageId, {resolve: resolve, reject: reject});
this.ws.send(
JSON.stringify({
version: PROTOCOL_VERSION,
target: target,
method: method,
id: messageId,
params: params,
}),
error => {
if (error !== undefined) {
this.msgCallbacks.delete(messageId);
reject(error);
}
});
}));
}
sendNotification(method, target, params) {
return this.openPromise.then(() => new Promise((resolve, reject) => {
this.ws.send(
JSON.stringify({
version: PROTOCOL_VERSION,
target: target,
method: method,
params: params,
}),
error => {
if (error !== undefined) {
reject(error);
} else {
resolve();
}
});
}));
}
sendBroadcast(method, params) {
return this.sendNotification(method, undefined, params);
}
getPeers() {
return new Promise((resolve, reject) => {
this.sendRequest('getpeers', TARGET_SERVER, undefined).then(
response => {
if (!response instanceof Map) {
reject('Results received from server are of wrong format:\n' +
JSON.stringify(response));
} else {
resolve(response);
}
},
reject);
});
}
getId() {
return this.sendRequest('getid', TARGET_SERVER, undefined);
}
}
module.exports = JsPackagerClient;

View File

@@ -0,0 +1,55 @@
/**
* 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.
*
* @flow
*/
'use strict';
/* $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 opn = require('opn');
const execSync = require('child_process').execSync;
function commandExistsUnixSync (commandName, callback) {
try {
var stdout = execSync('command -v ' + commandName +
' 2>/dev/null' +
' && { echo >&1 \'' + commandName + ' found\'; exit 0; }');
return !!stdout;
} catch (error) {
return false;
}
}
function getChromeAppName(): string {
switch (process.platform) {
case 'darwin':
return 'google chrome';
case 'win32':
return 'chrome';
case 'linux':
if (commandExistsUnixSync('google-chrome')) {
return 'google-chrome';
} else if (commandExistsUnixSync('chromium-browser')) {
return 'chromium-browser';
} else {
return 'chromium';
}
default:
return 'google-chrome';
}
}
function launchChrome(url: string) {
opn(url, {app: [getChromeAppName()]}, function(err) {
if (err) {
console.error('Google Chrome exited with error:', err);
}
});
}
module.exports = launchChrome;

View File

@@ -0,0 +1,200 @@
/**
* 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.
*/
'use strict';
var chalk = require('chalk');
var fs = require('fs');
var path = require('path');
var child_process = require('child_process');
const isAbsolutePath = require('absolute-path');
const shellQuote = require('shell-quote');
function isTerminalEditor(editor) {
switch (editor) {
case 'vim':
case 'emacs':
case 'nano':
return true;
}
return false;
}
// Map from full process name to binary that starts the process
// We can't just re-use full process name, because it will spawn a new instance
// of the app every time
var COMMON_EDITORS = {
'/Applications/Atom.app/Contents/MacOS/Atom': 'atom',
'/Applications/Atom Beta.app/Contents/MacOS/Atom Beta':
'/Applications/Atom Beta.app/Contents/MacOS/Atom Beta',
'/Applications/IntelliJ IDEA.app/Contents/MacOS/idea': 'idea',
'/Applications/Sublime Text.app/Contents/MacOS/Sublime Text':
'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl',
'/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2':
'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl',
'/Applications/Visual Studio Code.app/Contents/MacOS/Electron': 'code',
'/Applications/WebStorm.app/Contents/MacOS/webstorm': 'webstorm',
};
function addWorkspaceToArgumentsIfExists(args, workspace) {
if (workspace) {
args.unshift(workspace);
}
return args;
}
function getArgumentsForLineNumber(editor, fileName, lineNumber, workspace) {
switch (path.basename(editor)) {
case 'vim':
case 'mvim':
return [fileName, '+' + lineNumber];
case 'atom':
case 'Atom':
case 'Atom Beta':
case 'subl':
case 'sublime':
case 'webstorm':
case 'wstorm':
case 'appcode':
case 'charm':
case 'idea':
return [fileName + ':' + lineNumber];
case 'joe':
case 'emacs':
case 'emacsclient':
return ['+' + lineNumber, fileName];
case 'rmate':
case 'mate':
case 'mine':
return ['--line', lineNumber, fileName];
case 'code':
return addWorkspaceToArgumentsIfExists(['-g', fileName + ':' + lineNumber], workspace);
}
// For all others, drop the lineNumber until we have
// a mapping above, since providing the lineNumber incorrectly
// can result in errors or confusing behavior.
return [fileName];
}
function guessEditor() {
// Explicit config always wins
if (process.env.REACT_EDITOR) {
return shellQuote.parse(process.env.REACT_EDITOR);
}
// Using `ps x` on OSX we can find out which editor is currently running.
// Potentially we could use similar technique for Windows and Linux
if (process.platform === 'darwin') {
try {
var output = child_process.execSync('ps x').toString();
var processNames = Object.keys(COMMON_EDITORS);
for (var i = 0; i < processNames.length; i++) {
var processName = processNames[i];
if (output.indexOf(processName) !== -1) {
return [COMMON_EDITORS[processName]];
}
}
} catch (error) {
// Ignore...
}
}
// Last resort, use old skool env vars
if (process.env.VISUAL) {
return [process.env.VISUAL];
} else if (process.env.EDITOR) {
return [process.env.EDITOR];
}
return [null];
}
function printInstructions(title) {
console.log([
'',
chalk.bgBlue.white.bold(' ' + title + ' '),
' When you see Red Box with stack trace, you can click any ',
' stack frame to jump to the source file. The packager will launch your ',
' editor of choice. It will first look at REACT_EDITOR environment ',
' variable, then at EDITOR. To set it up, you can add something like ',
' export REACT_EDITOR=atom to your ~/.bashrc or ~/.zshrc depending on ',
' which shell you use.',
''
].join('\n'));
}
function transformToAbsolutePathIfNeeded(pathName) {
if (!isAbsolutePath(pathName)) {
pathName = path.resolve(process.cwd(), pathName);
}
return pathName;
}
function findRootForFile(projectRoots, fileName) {
fileName = transformToAbsolutePathIfNeeded(fileName);
return projectRoots.find((root) => {
root = transformToAbsolutePathIfNeeded(root);
return fileName.startsWith(root + path.sep);
});
}
var _childProcess = null;
function launchEditor(fileName, lineNumber, projectRoots) {
if (!fs.existsSync(fileName)) {
return;
}
// Sanitize lineNumber to prevent malicious use on win32
// via: https://github.com/nodejs/node/blob/c3bb4b1aa5e907d489619fb43d233c3336bfc03d/lib/child_process.js#L333
if (lineNumber && isNaN(lineNumber)) {
return;
}
let [editor, ...args] = guessEditor();
if (!editor) {
printInstructions('PRO TIP');
return;
}
var workspace = findRootForFile(projectRoots, fileName);
if (lineNumber) {
args = args.concat(getArgumentsForLineNumber(editor, fileName, lineNumber, workspace));
} else {
args.push(fileName);
}
console.log('Opening ' + chalk.underline(fileName) + ' with ' + chalk.bold(editor));
if (_childProcess && isTerminalEditor(editor)) {
// There's an existing editor process already and it's attached
// to the terminal, so go kill it. Otherwise two separate editor
// instances attach to the stdin/stdout which gets confusing.
_childProcess.kill('SIGKILL');
}
if (process.platform === 'win32') {
// On Windows, launch the editor in a shell because spawn can only
// launch .exe files.
_childProcess = child_process.spawn('cmd.exe', ['/C', editor].concat(args), {stdio: 'inherit'});
} else {
_childProcess = child_process.spawn(editor, args, {stdio: 'inherit'});
}
_childProcess.on('exit', function(errorCode) {
_childProcess = null;
if (errorCode) {
console.log(chalk.red('Your editor exited with an error!'));
printInstructions('Keep these instructions in mind:');
}
});
_childProcess.on('error', function(error) {
console.log(chalk.red(error.message));
printInstructions('How to fix:');
});
}
module.exports = launchEditor;

View File

@@ -0,0 +1,218 @@
/**
* 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.
*/
'use strict';
const url = require('url');
const WebSocketServer = require('ws').Server;
const PROTOCOL_VERSION = 2;
const notifier = require('node-notifier');
function parseMessage(data, binary) {
if (binary) {
console.error('Expected text message, got binary!');
return undefined;
}
try {
const message = JSON.parse(data);
if (message.version === PROTOCOL_VERSION) {
return message;
}
console.error('Received message had wrong protocol version: '
+ message.version);
} catch (e) {
console.error('Failed to parse the message as JSON:\n' + data);
}
return undefined;
}
function isBroadcast(message) {
return (
typeof message.method === 'string' &&
message.id === undefined &&
message.target === undefined
);
}
function isRequest(message) {
return (
typeof message.method === 'string' &&
typeof message.target === 'string');
}
function isResponse(message) {
return (
typeof message.id === 'object' &&
typeof message.id.requestId !== undefined &&
typeof message.id.clientId === 'string' && (
message.result !== undefined ||
message.error !== undefined
));
}
function attachToServer(server, path) {
const wss = new WebSocketServer({
server: server,
path: path
});
const clients = new Map();
let nextClientId = 0;
function getClientWs(clientId) {
const clientWs = clients.get(clientId);
if (clientWs === undefined) {
throw `could not find id "${clientId}" while forwarding request`;
}
return clientWs;
}
function handleSendBroadcast(broadcasterId, message) {
const forwarded = {
version: PROTOCOL_VERSION,
method: message.method,
params: message.params,
};
if (clients.size === 0) {
notifier.notify({
'title': 'React Native: No apps connected',
'message': `Sending '${message.method}' to all React Native apps ` +
'failed. Make sure your app is running in the simulator ' +
'or on a phone connected via USB.'
});
}
for (const [otherId, otherWs] of clients) {
if (otherId !== broadcasterId) {
try {
otherWs.send(JSON.stringify(forwarded));
} catch (e) {
console.error(`Failed to send broadcast to client: '${otherId}' ` +
`due to:\n ${e.toString()}`);
}
}
}
}
wss.on('connection', function(clientWs) {
const clientId = `client#${nextClientId++}`;
function handleCaughtError(message, error) {
const errorMessage = {
id: message.id,
method: message.method,
target: message.target,
error: message.error === undefined ? 'undefined' : 'defined',
params: message.params === undefined ? 'undefined' : 'defined',
result: message.result === undefined ? 'undefined' : 'defined',
};
if (message.id === undefined) {
console.error(
`Handling message from ${clientId} failed with:\n${error}\n` +
`message:\n${JSON.stringify(errorMessage)}`);
} else {
try {
clientWs.send(JSON.stringify({
version: PROTOCOL_VERSION,
error: error,
id: message.id,
}));
} catch (e) {
console.error(`Failed to reply to ${clientId} with error:\n${error}` +
`\nmessage:\n${JSON.stringify(errorMessage)}` +
`\ndue to error: ${e.toString()}`);
}
}
}
function handleServerRequest(message) {
let result = null;
switch (message.method) {
case 'getid':
result = clientId;
break;
case 'getpeers':
result = {};
clients.forEach((otherWs, otherId) => {
if (clientId !== otherId) {
result[otherId] = url.parse(otherWs.upgradeReq.url, true).query;
}
});
break;
default:
throw `unknown method: ${message.method}`;
}
clientWs.send(JSON.stringify({
version: PROTOCOL_VERSION,
result: result,
id: message.id
}));
}
function forwardRequest(message) {
getClientWs(message.target).send(JSON.stringify({
version: PROTOCOL_VERSION,
method: message.method,
params: message.params,
id: (message.id === undefined
? undefined
: {requestId: message.id, clientId: clientId}),
}));
}
function forwardResponse(message) {
getClientWs(message.id.clientId).send(JSON.stringify({
version: PROTOCOL_VERSION,
result: message.result,
error: message.error,
id: message.id.requestId,
}));
}
clients.set(clientId, clientWs);
clientWs.onclose =
clientWs.onerror = () => {
clientWs.onmessage = null;
clients.delete(clientId);
};
clientWs.onmessage = (event) => {
const message = parseMessage(event.data, event.binary);
if (message === undefined) {
console.error('Received message not matching protocol');
return;
}
try {
if (isBroadcast(message)) {
handleSendBroadcast(clientId, message);
} else if (isRequest(message)) {
if (message.target === 'server') {
handleServerRequest(message);
} else {
forwardRequest(message);
}
} else if (isResponse(message)) {
forwardResponse(message);
} else {
throw 'Invalid message, did not match the protocol';
}
} catch (e) {
handleCaughtError(message, e.toString());
}
};
});
return {
broadcast: (method, params) => {
handleSendBroadcast(null, {method: method, params: params});
}
};
}
module.exports = {
attachToServer: attachToServer,
parseMessage: parseMessage,
};

View File

@@ -0,0 +1,75 @@
/**
* 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.
*/
'use strict';
function attachToServer(server, path) {
var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({
server: server,
path: path
});
var debuggerSocket, clientSocket;
function send(dest, message) {
if (!dest) {
return;
}
try {
dest.send(message);
} catch (e) {
console.warn(e);
// Sometimes this call throws 'not opened'
}
}
wss.on('connection', function(ws) {
const {url} = ws.upgradeReq;
if (url.indexOf('role=debugger') > -1) {
if (debuggerSocket) {
ws.close(1011, 'Another debugger is already connected');
return;
}
debuggerSocket = ws;
debuggerSocket.onerror =
debuggerSocket.onclose = () => {
debuggerSocket = null;
if (clientSocket) {
clientSocket.close(1011, 'Debugger was disconnected');
}
};
debuggerSocket.onmessage = ({data}) => send(clientSocket, data);
} else if (url.indexOf('role=client') > -1) {
if (clientSocket) {
clientSocket.onerror = clientSocket.onclose = clientSocket.onmessage = null;
clientSocket.close(1011, 'Another client connected');
}
clientSocket = ws;
clientSocket.onerror =
clientSocket.onclose = () => {
clientSocket = null;
send(debuggerSocket, JSON.stringify({method: '$disconnected'}));
};
clientSocket.onmessage = ({data}) => send(debuggerSocket, data);
} else {
ws.close(1011, 'Missing role param');
}
});
return {
server: wss,
isChromeConnected: function() {
return !!debuggerSocket;
}
};
}
module.exports = {
attachToServer: attachToServer
};