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

130
node_modules/react-native/local-cli/util/Config.js generated vendored Normal file
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
* @flow
*/
'use strict';
const findSymlinkedModules = require('./findSymlinkedModules');
const fs = require('fs');
const getPolyfills = require('../../rn-get-polyfills');
const invariant = require('fbjs/lib/invariant');
const path = require('path');
const {Config: MetroConfig, createBlacklist} = require('metro');
const RN_CLI_CONFIG = 'rn-cli.config.js';
import type {ConfigT as MetroConfigT} from 'metro';
/**
* Configuration file of the CLI.
*/
export type ConfigT = MetroConfigT;
function getProjectPath() {
if (
__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli[\/\\]util$/)
) {
// Packager is running from node_modules.
// This is the default case for all projects created using 'react-native init'.
return path.resolve(__dirname, '../../../..');
} else if (__dirname.match(/Pods[\/\\]React[\/\\]packager$/)) {
// React Native was installed using CocoaPods.
return path.resolve(__dirname, '../../../..');
}
return path.resolve(__dirname, '../..');
}
const resolveSymlinksForRoots = roots =>
roots.reduce(
(arr, rootPath) => arr.concat(findSymlinkedModules(rootPath, roots)),
[...roots],
);
const getProjectRoots = () => {
const root = process.env.REACT_NATIVE_APP_ROOT;
if (root) {
return resolveSymlinksForRoots([path.resolve(root)]);
}
return resolveSymlinksForRoots([getProjectPath()]);
};
const getBlacklistRE = () => {
return createBlacklist([/.*\/__fixtures__\/.*/]);
};
/**
* Module capable of getting the configuration out of a given file.
*
* The function will return all the default configuration, as specified by the
* `DEFAULT` param overriden by those found on `rn-cli.config.js` files, if any. If no
* default config is provided and no configuration can be found in the directory
* hierarchy, an error will be thrown.
*/
const Config = {
DEFAULT: ({
...MetroConfig.DEFAULT,
getBlacklistRE,
getProjectRoots,
getPolyfills,
getModulesRunBeforeMainModule: () => [
require.resolve('../../Libraries/Core/InitializeCore'),
],
}: ConfigT),
find(startDir: string): ConfigT {
return this.findWithPath(startDir).config;
},
findWithPath(startDir: string): {config: ConfigT, projectPath: string} {
const configPath = findConfigPath(startDir);
invariant(
configPath,
`Can't find "${RN_CLI_CONFIG}" file in any parent folder of "${startDir}"`,
);
const projectPath = path.dirname(configPath);
return {config: this.load(configPath, startDir), projectPath};
},
findOptional(startDir: string): ConfigT {
const configPath = findConfigPath(startDir);
return configPath ? this.load(configPath, startDir) : {...Config.DEFAULT};
},
getProjectPath,
getProjectRoots,
load(configFile: string): ConfigT {
return MetroConfig.load(configFile, Config.DEFAULT);
},
};
function findConfigPath(cwd: string): ?string {
const parentDir = findParentDirectory(cwd, RN_CLI_CONFIG);
return parentDir ? path.join(parentDir, RN_CLI_CONFIG) : null;
}
// Finds the most near ancestor starting at `currentFullPath` that has
// a file named `filename`
function findParentDirectory(currentFullPath, filename) {
const root = path.parse(currentFullPath).root;
const testDir = parts => {
if (parts.length === 0) {
return null;
}
const fullPath = path.join(root, parts.join(path.sep));
var exists = fs.existsSync(path.join(fullPath, filename));
return exists ? fullPath : testDir(parts.slice(0, -1));
};
return testDir(currentFullPath.substring(root.length).split(path.sep));
}
module.exports = Config;

View File

@@ -0,0 +1,72 @@
/**
* 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 spawnSync = require('child_process').spawnSync;
const yarn = require('../util/yarn');
const spawnOpts = {
stdio: 'inherit',
stdin: 'inherit',
};
/**
* Execute npm or yarn command
*
* @param {String} yarnCommand Yarn command to be executed eg. yarn add package
* @param {String} npmCommand Npm command to be executed eg. npm install package
* @return {object} spawnSync's result object
*/
function callYarnOrNpm(yarnCommand, npmCommand) {
let command;
const projectDir = process.cwd();
const isYarnAvailable =
yarn.getYarnVersionIfAvailable() &&
yarn.isGlobalCliUsingYarn(projectDir);
if (isYarnAvailable) {
command = yarnCommand;
} else {
command = npmCommand;
}
const args = command.split(' ');
const cmd = args.shift();
const res = spawnSync(cmd, args, spawnOpts);
return res;
}
/**
* Install package into project using npm or yarn if available
* @param {[type]} packageName Package to be installed
* @return {[type]} spawnSync's result object
*/
function add(packageName) {
return callYarnOrNpm(
`yarn add ${packageName}`,
`npm install ${packageName} --save`
);
}
/**
* Uninstall package from project using npm or yarn if available
* @param {[type]} packageName Package to be uninstalled
* @return {Object} spawnSync's result object
*/
function remove(packageName) {
return callYarnOrNpm(
`yarn remove ${packageName}`,
`npm uninstall --save ${packageName}`
);
}
module.exports = {
add: add,
remove: remove,
};

View File

@@ -0,0 +1,10 @@
/**
* 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.out = () => jest.genMockFn();
module.exports.err = () => jest.genMockFn();

View File

@@ -0,0 +1,30 @@
/**
* 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 { Option } = require('commander');
const { camelCase } = require('lodash');
// Commander.js has a 2 years old open issue to support <...> syntax
// for options. Until that gets merged, we run the checks manually
// https://github.com/tj/commander.js/issues/230
module.exports = function assertRequiredOptions(options, passedOptions) {
options.forEach(opt => {
const option = new Option(opt.command);
if (!option.required) {
return;
}
const name = camelCase(option.long);
if (!passedOptions[name]) {
// Provide commander.js like error message
throw new Error(`error: option '${option.long}' missing`);
}
});
};

View File

@@ -0,0 +1,126 @@
/**
* 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');
// Binary files, don't process these (avoid decoding as utf8)
const binaryExtensions = ['.png', '.jar'];
/**
* Copy a file to given destination, replacing parts of its contents.
* @param srcPath Path to a file to be copied.
* @param destPath Destination path.
* @param replacements: e.g. {'TextToBeReplaced': 'Replacement'}
* @param contentChangedCallback
* Used when upgrading projects. Based on if file contents would change
* when being replaced, allows the caller to specify whether the file
* should be replaced or not.
* If null, files will be overwritten.
* Function(path, 'identical' | 'changed' | 'new') => 'keep' | 'overwrite'
*/
function copyAndReplace(srcPath, destPath, replacements, contentChangedCallback) {
if (fs.lstatSync(srcPath).isDirectory()) {
if (!fs.existsSync(destPath)) {
fs.mkdirSync(destPath);
}
// Not recursive
return;
}
const extension = path.extname(srcPath);
if (binaryExtensions.indexOf(extension) !== -1) {
// Binary file
let shouldOverwrite = 'overwrite';
if (contentChangedCallback) {
const newContentBuffer = fs.readFileSync(srcPath);
let contentChanged = 'identical';
try {
const origContentBuffer = fs.readFileSync(destPath);
if (Buffer.compare(origContentBuffer, newContentBuffer) !== 0) {
contentChanged = 'changed';
}
} catch (err) {
if (err.code === 'ENOENT') {
contentChanged = 'new';
} else {
throw err;
}
}
shouldOverwrite = contentChangedCallback(destPath, contentChanged);
}
if (shouldOverwrite === 'overwrite') {
copyBinaryFile(srcPath, destPath, (err) => {
if (err) { throw err; }
});
}
} else {
// Text file
const srcPermissions = fs.statSync(srcPath).mode;
let content = fs.readFileSync(srcPath, 'utf8');
Object.keys(replacements).forEach(regex =>
content = content.replace(new RegExp(regex, 'g'), replacements[regex])
);
let shouldOverwrite = 'overwrite';
if (contentChangedCallback) {
// Check if contents changed and ask to overwrite
let contentChanged = 'identical';
try {
const origContent = fs.readFileSync(destPath, 'utf8');
if (content !== origContent) {
//console.log('Content changed: ' + destPath);
contentChanged = 'changed';
}
} catch (err) {
if (err.code === 'ENOENT') {
contentChanged = 'new';
} else {
throw err;
}
}
shouldOverwrite = contentChangedCallback(destPath, contentChanged);
}
if (shouldOverwrite === 'overwrite') {
fs.writeFileSync(destPath, content, {
encoding: 'utf8',
mode: srcPermissions,
});
}
}
}
/**
* Same as 'cp' on Unix. Don't do any replacements.
*/
function copyBinaryFile(srcPath, destPath, cb) {
let cbCalled = false;
const srcPermissions = fs.statSync(srcPath).mode;
const readStream = fs.createReadStream(srcPath);
readStream.on('error', function(err) {
done(err);
});
const writeStream = fs.createWriteStream(destPath, {
mode: srcPermissions
});
writeStream.on('error', function(err) {
done(err);
});
writeStream.on('close', function(ex) {
done();
});
readStream.pipe(writeStream);
function done(err) {
if (!cbCalled) {
cb(err);
cbCalled = true;
}
}
}
module.exports = copyAndReplace;

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.
*
* @flow
*/
'use strict';
const path = require('path');
const fs = require('fs');
function findReactNativeScripts(): ?string {
const executablePath = path.resolve(
'node_modules',
'.bin',
'react-native-scripts'
);
if (fs.existsSync(executablePath)) {
return executablePath;
}
return null;
}
module.exports = findReactNativeScripts;

View File

@@ -0,0 +1,108 @@
/**
* 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
*/
const path = require('path');
const fs = require('fs');
/**
* Find symlinked modules inside "node_modules."
*
* Naively, we could just perform a depth-first search of all folders in
* node_modules, recursing when we find a symlink.
*
* We can be smarter than this due to our knowledge of how npm/Yarn lays out
* "node_modules" / how tools that build on top of npm/Yarn (such as Lerna)
* install dependencies.
*
* Starting from a given root node_modules folder, this algorithm will look at
* both the top level descendants of the node_modules folder or second level
* descendants of folders that start with "@" (which indicates a scoped
* package). If any of those folders is a symlink, it will recurse into the
* link, and perform the same search in the linked folder.
*
* The end result should be a list of all resolved module symlinks for a given
* root.
*/
module.exports = function findSymlinkedModules(
projectRoot: string,
ignoredRoots?: Array<string> = [],
) {
const timeStart = Date.now();
const nodeModuleRoot = path.join(projectRoot, 'node_modules');
const resolvedSymlinks = findModuleSymlinks(nodeModuleRoot, [
...ignoredRoots,
projectRoot,
]);
const timeEnd = Date.now();
console.log(
`Scanning folders for symlinks in ${nodeModuleRoot} (${timeEnd -
timeStart}ms)`,
);
return resolvedSymlinks;
};
function findModuleSymlinks(
modulesPath: string,
ignoredPaths: Array<string> = [],
): Array<string> {
if (!fs.existsSync(modulesPath)) {
return [];
}
// Find module symlinks
const moduleFolders = fs.readdirSync(modulesPath);
const symlinks = moduleFolders.reduce((links, folderName) => {
const folderPath = path.join(modulesPath, folderName);
const maybeSymlinkPaths = [];
if (folderName.startsWith('@')) {
const scopedModuleFolders = fs.readdirSync(folderPath);
maybeSymlinkPaths.push(
...scopedModuleFolders.map(name => path.join(folderPath, name)),
);
} else {
maybeSymlinkPaths.push(folderPath);
}
return links.concat(resolveSymlinkPaths(maybeSymlinkPaths, ignoredPaths));
}, []);
// For any symlinks found, look in _that_ modules node_modules directory
// and find any symlinked modules
const nestedSymlinks = symlinks.reduce(
(links, symlinkPath) =>
links.concat(
// We ignore any found symlinks or anything from the ignored list,
// to prevent infinite recursion
findModuleSymlinks(path.join(symlinkPath, 'node_modules'), [
...ignoredPaths,
...symlinks,
]),
),
[],
);
return [...new Set([...symlinks, ...nestedSymlinks])];
}
function resolveSymlinkPaths(maybeSymlinkPaths, ignoredPaths) {
return maybeSymlinkPaths.reduce((links, maybeSymlinkPath) => {
if (fs.lstatSync(maybeSymlinkPath).isSymbolicLink()) {
const resolved = path.resolve(
path.dirname(maybeSymlinkPath),
fs.readlinkSync(maybeSymlinkPath),
);
if (ignoredPaths.indexOf(resolved) === -1 && fs.existsSync(resolved)) {
links.push(resolved);
}
}
return links;
}, []);
}

View File

@@ -0,0 +1,57 @@
/**
* 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.
*/
const path = require('path');
const fs = require('fs');
/**
* Find and resolve symlinks in `lookupFolder`.
* Ignore any descendants of the paths in `ignoredRoots`.
*/
module.exports = function findSymlinksPaths(lookupFolder, ignoredRoots) {
const timeStart = Date.now();
const folders = fs.readdirSync(lookupFolder);
const resolvedSymlinks = [];
folders.forEach(folder => {
const visited = [];
let symlink = path.resolve(lookupFolder, folder);
while (fs.lstatSync(symlink).isSymbolicLink()) {
const index = visited.indexOf(symlink);
if (index !== -1) {
throw Error(
'Infinite symlink recursion detected:\n ' +
visited.slice(index).join('\n ')
);
}
visited.push(symlink);
symlink = path.resolve(
path.dirname(symlink),
fs.readlinkSync(symlink)
);
}
if (visited.length && !rootExists(ignoredRoots, symlink)) {
resolvedSymlinks.push(symlink);
}
});
const timeEnd = Date.now();
console.log(`Scanning ${folders.length} folders for symlinks in ${lookupFolder} (${timeEnd - timeStart}ms)`);
return resolvedSymlinks;
};
function rootExists(roots, child) {
return roots.some(root => isDescendant(root, child));
}
function isDescendant(root, child) {
return root === child || child.startsWith(root + path.sep);
}

View File

@@ -0,0 +1,29 @@
/**
* 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 fetch = require('node-fetch');
/**
* Indicates whether or not the packager is running. It returns a promise that
* when fulfilled can returns one out of these possible values:
* - `running`: the packager is running
* - `not_running`: the packager nor any process is running on the expected
* port.
* - `unrecognized`: one other process is running on the port we expect the
* packager to be running.
*/
function isPackagerRunning(packagerPort = (process.env.RCT_METRO_PORT || 8081)) {
return fetch(`http://localhost:${packagerPort}/status`).then(
res => res.text().then(body =>
body === 'packager-status:running' ? 'running' : 'unrecognized'
),
() => 'not_running'
);
}
module.exports = isPackagerRunning;

View File

@@ -0,0 +1,13 @@
/**
* 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 isValidPackageName(name) {
return name.match(/^[$A-Z_][0-9A-Z_$]*$/i);
}
module.exports = isValidPackageName;

27
node_modules/react-native/local-cli/util/log.js generated vendored Normal file
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';
var _enabled = true;
function disable() {
_enabled = false;
}
function log(stream, module) {
return function() {
if (!_enabled) {
return;
}
const message = Array.prototype.slice.call(arguments).join(' ');
stream.write(module + ': ' + message + '\n');
};
}
module.exports.out = log.bind(null, process.stdout);
module.exports.err = log.bind(null, process.stderr);
module.exports.disable = disable;

View File

@@ -0,0 +1,78 @@
/**
* 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.
*
* Wrapper on-top of `optimist` in order to properly support boolean flags
* and have a slightly less awkward API.
*
* Usage example:
* var argv = parseCommandLine([{
* command: 'web',
* description: 'Run in a web browser instead of iOS',
* default: true
* }])
*
* NOTE: This file is used internally at Facebook and not in `local-cli` itself.
* No changes should be made to this file without prior discussion with FB team.
*/
'use strict';
var optimistModule = require('optimist');
function parseCommandLine(config, args) {
var optimist = new optimistModule();
args = args || process.argv;
// optimist default API requires you to write the command name three time
// This is a small wrapper to accept an object instead
for (var i = 0; i < config.length; ++i) {
if (config[i].type === 'string') {
optimist.string(config[i].command);
} else {
optimist.boolean(config[i].command);
}
optimist
.default(config[i].command, config[i].default)
.describe(config[i].command, config[i].description);
if (config[i].required) {
optimist.demand(config[i].command);
}
}
var argv = optimist.parse(args);
// optimist doesn't have support for --dev=false, instead it returns 'false'
for (var i = 0; i < config.length; ++i) {
var command = config[i].command;
if (argv[command] === undefined) {
argv[command] = config[i].default;
}
if (argv[command] === 'true') {
argv[command] = true;
}
if (argv[command] === 'false') {
argv[command] = false;
}
if (config[i].type === 'string') {
// According to https://github.com/substack/node-optimist#numbers,
// every argument that looks like a number should be converted to one.
var strValue = argv[command];
var numValue = strValue ? Number(strValue) : undefined;
if (typeof numValue === 'number' && !isNaN(numValue)) {
argv[command] = numValue;
}
}
}
// Show --help
if (argv.help || argv.h) {
optimist.showHelp();
process.exit();
}
return argv;
}
module.exports = parseCommandLine;

24
node_modules/react-native/local-cli/util/walk.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
/**
* 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');
function walk(current) {
if (!fs.lstatSync(current).isDirectory()) {
return [current];
}
const files = fs.readdirSync(current).map(child => {
child = path.join(current, child);
return walk(child);
});
return [].concat.apply([current], files);
}
module.exports = walk;

55
node_modules/react-native/local-cli/util/yarn.js generated vendored Normal file
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.
*/
'use strict';
const execSync = require('child_process').execSync;
const fs = require('fs');
const path = require('path');
const semver = require('semver');
/**
* Use Yarn if available, it's much faster than the npm client.
* Return the version of yarn installed on the system, null if yarn is not available.
*/
function getYarnVersionIfAvailable() {
let yarnVersion;
try {
// execSync returns a Buffer -> convert to string
yarnVersion = (execSync('yarn --version', {
stdio: [ 0, 'pipe', 'ignore', ]
}).toString() || '').trim();
} catch (error) {
return null;
}
// yarn < 0.16 has a 'missing manifest' bug
try {
if (semver.gte(yarnVersion, '0.16.0')) {
return yarnVersion;
} else {
return null;
}
} catch (error) {
console.error('Cannot parse yarn version: ' + yarnVersion);
return null;
}
}
/**
* Check that 'react-native init' itself used yarn to install React Native.
* When using an old global react-native-cli@1.0.0 (or older), we don't want
* to install React Native with npm, and React + Jest with yarn.
* Let's be safe and not mix yarn and npm in a single project.
* @param projectDir e.g. /Users/martin/AwesomeApp
*/
function isGlobalCliUsingYarn(projectDir) {
return fs.existsSync(path.join(projectDir, 'yarn.lock'));
}
module.exports = {
getYarnVersionIfAvailable: getYarnVersionIfAvailable,
isGlobalCliUsingYarn: isGlobalCliUsingYarn,
};