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

3
node_modules/metro-resolver/README.md generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# metro-resolver
🚇 [Metro](https://facebook.github.io/metro/) resolution logic

76
node_modules/metro-resolver/package.json generated vendored Normal file
View File

@@ -0,0 +1,76 @@
{
"_args": [
[
"metro-resolver@0.30.2",
"/home/bernhard/freifunk-app/node_modules/metro"
]
],
"_from": "metro-resolver@0.30.2",
"_id": "metro-resolver@0.30.2",
"_inCache": true,
"_installable": true,
"_location": "/metro-resolver",
"_nodeVersion": "8.9.4",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/metro-resolver_0.30.2_1521165825925_0.1997731067301347"
},
"_npmUser": {
"email": "rafeca@gmail.com",
"name": "rafeca"
},
"_npmVersion": "5.6.0",
"_phantomChildren": {},
"_requested": {
"name": "metro-resolver",
"raw": "metro-resolver@0.30.2",
"rawSpec": "0.30.2",
"scope": null,
"spec": "0.30.2",
"type": "version"
},
"_requiredBy": [
"/metro"
],
"_resolved": "https://registry.npmjs.org/metro-resolver/-/metro-resolver-0.30.2.tgz",
"_shasum": "c26847e59cdc6a8ab1fb4b92d765165ec06946dd",
"_shrinkwrap": null,
"_spec": "metro-resolver@0.30.2",
"_where": "/home/bernhard/freifunk-app/node_modules/metro",
"bugs": {
"url": "https://github.com/facebook/metro/issues"
},
"dependencies": {
"absolute-path": "^0.0.0"
},
"description": "🚇 Metro resolution logic",
"devDependencies": {},
"directories": {},
"dist": {
"fileCount": 17,
"integrity": "sha512-bODCys/WYpqJ+KYbCIENZu1eqdQu3g/d2fXfhAROhutqojMqrT1eIGhzWpk3G1k/J6vlaf69uW6xrVuheg0ktg==",
"shasum": "c26847e59cdc6a8ab1fb4b92d765165ec06946dd",
"tarball": "https://registry.npmjs.org/metro-resolver/-/metro-resolver-0.30.2.tgz",
"unpackedSize": 41887
},
"homepage": "https://github.com/facebook/metro#readme",
"main": "src",
"maintainers": [
{
"name": "rafeca",
"email": "rafeca@gmail.com"
}
],
"name": "metro-resolver",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/facebook/metro.git"
},
"scripts": {
"cleanup-release": "test ! -e build && mv src build && mv src.real src",
"prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src"
},
"version": "0.30.2"
}

4
node_modules/metro-resolver/rn-babelrc.json generated vendored Normal file
View File

@@ -0,0 +1,4 @@
{
"presets": [ "react-native" ],
"plugins": []
}

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.
*
*
* @format
*/
'use strict';
const path = require('path');
class FailedToResolveNameError extends Error {
constructor(
dirPaths,
extraPaths)
{
const displayDirPaths = dirPaths.concat(extraPaths);
const hint = displayDirPaths.length ? ' or in these directories:' : '';
super(
`Module does not exist in the Haste module map${hint}\n` +
displayDirPaths.
map(dirPath => ` ${path.dirname(dirPath)}\n`).
join(', ') +
'\n');
this.dirPaths = dirPaths;
this.extraPaths = extraPaths;
}}
module.exports = FailedToResolveNameError;

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.
*
* @flow
* @format
*/
'use strict';
const path = require('path');
class FailedToResolveNameError extends Error {
dirPaths: $ReadOnlyArray<string>;
extraPaths: $ReadOnlyArray<string>;
constructor(
dirPaths: $ReadOnlyArray<string>,
extraPaths: $ReadOnlyArray<string>,
) {
const displayDirPaths = dirPaths.concat(extraPaths);
const hint = displayDirPaths.length ? ' or in these directories:' : '';
super(
`Module does not exist in the Haste module map${hint}\n` +
displayDirPaths
.map(dirPath => ` ${path.dirname(dirPath)}\n`)
.join(', ') +
'\n',
);
this.dirPaths = dirPaths;
this.extraPaths = extraPaths;
}
}
module.exports = FailedToResolveNameError;

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.
*
*
* @format
*/
'use strict';
const formatFileCandidates = require('./formatFileCandidates');
class FailedToResolvePathError extends Error {
constructor(candidates) {
super(
`The module could not be resolved because none of these files exist:\n\n` +
` * \`${formatFileCandidates(candidates.file)}\`\n` +
` * \`${formatFileCandidates(candidates.dir)}\``);
this.candidates = candidates;
}}
module.exports = FailedToResolvePathError;

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.
*
* @flow
* @format
*/
'use strict';
const formatFileCandidates = require('./formatFileCandidates');
import type {FileAndDirCandidates} from './types';
class FailedToResolvePathError extends Error {
candidates: FileAndDirCandidates;
constructor(candidates: FileAndDirCandidates) {
super(
`The module could not be resolved because none of these files exist:\n\n` +
` * \`${formatFileCandidates(candidates.file)}\`\n` +
` * \`${formatFileCandidates(candidates.dir)}\``,
);
this.candidates = candidates;
}
}
module.exports = FailedToResolvePathError;

61
node_modules/metro-resolver/src/InvalidPackageError.js generated vendored Normal file
View File

@@ -0,0 +1,61 @@
/**
* 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 formatFileCandidates = require('./formatFileCandidates');
class InvalidPackageError extends Error {
/**
* The module path prefix we where trying to resolve. For example './beep'.
*/ /**
* The file candidates we tried to find to resolve the `main` field of the
* package. Ex. `/js/foo/beep(.js|.json)?` if `main` is specifying `./beep`
* as the entry point.
*/
constructor(opts)
{
super(
`The package \`${opts.packageJsonPath}\` is invalid because it ` +
`specifies a \`main\` module field that could not be resolved (` +
`\`${opts.mainPrefixPath}\`. Indeed, none of these files exist:\n\n` +
` * \`${formatFileCandidates(opts.fileCandidates)}\`\n` +
` * \`${formatFileCandidates(opts.indexCandidates)}\``);
Object.assign(this, opts);
} /**
* Full path the package we were trying to resolve.
* Ex. `/js/foo/package.json`.
*/ /**
* The 'index' file candidates we tried to find to resolve the `main` field of
* the package. Ex. `/js/foo/beep/index(.js|.json)?` if `main` is specifying
* `./beep` as the entry point.
*/}module.exports = InvalidPackageError;

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.
*
* @flow
* @format
*/
'use strict';
const formatFileCandidates = require('./formatFileCandidates');
import type {FileCandidates} from './types';
class InvalidPackageError extends Error {
/**
* The file candidates we tried to find to resolve the `main` field of the
* package. Ex. `/js/foo/beep(.js|.json)?` if `main` is specifying `./beep`
* as the entry point.
*/
fileCandidates: FileCandidates;
/**
* The 'index' file candidates we tried to find to resolve the `main` field of
* the package. Ex. `/js/foo/beep/index(.js|.json)?` if `main` is specifying
* `./beep` as the entry point.
*/
indexCandidates: FileCandidates;
/**
* The module path prefix we where trying to resolve. For example './beep'.
*/
mainPrefixPath: string;
/**
* Full path the package we were trying to resolve.
* Ex. `/js/foo/package.json`.
*/
packageJsonPath: string;
constructor(opts: {|
+fileCandidates: FileCandidates,
+indexCandidates: FileCandidates,
+mainPrefixPath: string,
+packageJsonPath: string,
|}) {
super(
`The package \`${opts.packageJsonPath}\` is invalid because it ` +
`specifies a \`main\` module field that could not be resolved (` +
`\`${opts.mainPrefixPath}\`. Indeed, none of these files exist:\n\n` +
` * \`${formatFileCandidates(opts.fileCandidates)}\`\n` +
` * \`${formatFileCandidates(opts.indexCandidates)}\``,
);
Object.assign(this, opts);
}
}
module.exports = InvalidPackageError;

View File

@@ -0,0 +1,22 @@
/**
* 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';
function formatFileCandidates(candidates) {
if (candidates.type === 'asset') {
return candidates.name;
}
return `${candidates.filePathPrefix}(${candidates.candidateExts.join('|')})`;
}
module.exports = formatFileCandidates;

View File

@@ -0,0 +1,22 @@
/**
* 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';
import type {FileCandidates} from './types';
function formatFileCandidates(candidates: FileCandidates): string {
if (candidates.type === 'asset') {
return candidates.name;
}
return `${candidates.filePathPrefix}(${candidates.candidateExts.join('|')})`;
}
module.exports = formatFileCandidates;

36
node_modules/metro-resolver/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
/**
* 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 Resolver = {
FailedToResolveNameError: require('./FailedToResolveNameError'),
FailedToResolvePathError: require('./FailedToResolvePathError'),
formatFileCandidates: require('./formatFileCandidates'),
InvalidPackageError: require('./InvalidPackageError'),
resolve: require('./resolve') };
module.exports = Resolver;

36
node_modules/metro-resolver/src/index.js.flow generated vendored Normal file
View File

@@ -0,0 +1,36 @@
/**
* 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';
export type {
DoesFileExist,
IsAssetFile,
ResolutionContext,
ResolveAsset,
} from './resolve';
export type {
AssetFileResolution,
FileAndDirCandidates,
FileCandidates,
FileResolution,
Resolution,
Result,
} from './types';
const Resolver = {
FailedToResolveNameError: require('./FailedToResolveNameError'),
FailedToResolvePathError: require('./FailedToResolvePathError'),
formatFileCandidates: require('./formatFileCandidates'),
InvalidPackageError: require('./InvalidPackageError'),
resolve: require('./resolve'),
};
module.exports = Resolver;

520
node_modules/metro-resolver/src/resolve.js generated vendored Normal file
View File

@@ -0,0 +1,520 @@
/**
* 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';var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};
const FailedToResolveNameError = require('./FailedToResolveNameError');
const FailedToResolvePathError = require('./FailedToResolvePathError');
const InvalidPackageError = require('./InvalidPackageError');
const formatFileCandidates = require('./formatFileCandidates');
const isAbsolutePath = require('absolute-path');
const path = require('path');
function resolve(
context,
moduleName,
platform)
{
if (isRelativeImport(moduleName) || isAbsolutePath(moduleName)) {
return resolveModulePath(context, moduleName, platform);
}
const realModuleName = context.redirectModulePath(moduleName);
// exclude
if (realModuleName === false) {
return { type: 'empty' };
}const
originModulePath = context.originModulePath;
if (isRelativeImport(realModuleName) || isAbsolutePath(realModuleName)) {
// derive absolute path /.../node_modules/originModuleDir/realModuleName
const fromModuleParentIdx =
originModulePath.lastIndexOf('node_modules' + path.sep) + 13;
const originModuleDir = originModulePath.slice(
0,
originModulePath.indexOf(path.sep, fromModuleParentIdx));
const absPath = path.join(originModuleDir, realModuleName);
return resolveModulePath(context, absPath, platform);
}
// At that point we only have module names that
// aren't relative paths nor absolute paths.
if (context.allowHaste) {
const normalizedName = normalizePath(realModuleName);
const result = resolveHasteName(context, normalizedName, platform);
if (result.type === 'resolved') {
return result.resolution;
}
}
const dirPaths = [];
for (
let currDir = path.dirname(originModulePath);
currDir !== '.' && currDir !== path.parse(originModulePath).root;
currDir = path.dirname(currDir))
{
const searchPath = path.join(currDir, 'node_modules');
dirPaths.push(path.join(searchPath, realModuleName));
}
const extraPaths = [];const
extraNodeModules = context.extraNodeModules;
if (extraNodeModules) {
const bits = path.normalize(moduleName).split(path.sep);
const packageName = bits[0];
if (extraNodeModules[packageName]) {
bits[0] = extraNodeModules[packageName];
extraPaths.push(path.join.apply(path, bits));
}
}
const allDirPaths = dirPaths.concat(extraPaths);
for (let i = 0; i < allDirPaths.length; ++i) {
const result = resolveFileOrDir(context, allDirPaths[i], platform);
if (result.type === 'resolved') {
return result.resolution;
}
}
throw new FailedToResolveNameError(dirPaths, extraPaths);
}
/**
* Resolve any kind of module path, whether it's a file or a directory.
* For example we may want to resolve './foobar'. The closest
* `package.json` may define a redirection for this path, for example
* `/smth/lib/foobar`, that may be further resolved to
* `/smth/lib/foobar/index.ios.js`.
*/
function resolveModulePath(
context,
toModuleName,
platform)
{
const modulePath = isAbsolutePath(toModuleName) ?
resolveWindowsPath(toModuleName) :
path.join(path.dirname(context.originModulePath), toModuleName);
const redirectedPath = context.redirectModulePath(modulePath);
if (redirectedPath === false) {
return { type: 'empty' };
}
const result = resolveFileOrDir(context, redirectedPath, platform);
if (result.type === 'resolved') {
return result.resolution;
}
throw new FailedToResolvePathError(result.candidates);
}
/**
* Resolve a module as a Haste module or package. For example we might try to
* resolve `Foo`, that is provided by file `/smth/Foo.js`. Or, in the case of
* a Haste package, it could be `/smth/Foo/index.js`.
*/
function resolveHasteName(
context,
moduleName,
platform)
{
const modulePath = context.resolveHasteModule(moduleName);
if (modulePath != null) {
return resolvedAs({ type: 'sourceFile', filePath: modulePath });
}
let packageName = moduleName;
let packageJsonPath = context.resolveHastePackage(packageName);
while (packageJsonPath == null && packageName && packageName !== '.') {
packageName = path.dirname(packageName);
packageJsonPath = context.resolveHastePackage(packageName);
}
if (packageJsonPath == null) {
return failedFor();
}
const packageDirPath = path.dirname(packageJsonPath);
const pathInModule = moduleName.substring(packageName.length + 1);
const potentialModulePath = path.join(packageDirPath, pathInModule);
const result = resolveFileOrDir(context, potentialModulePath, platform);
if (result.type === 'resolved') {
return result;
}const
candidates = result.candidates;
const opts = { moduleName, packageName, pathInModule, candidates };
throw new MissingFileInHastePackageError(opts);
}
class MissingFileInHastePackageError extends Error {
constructor(opts)
{
super(
`While resolving module \`${opts.moduleName}\`, ` +
`the Haste package \`${opts.packageName}\` was found. However the ` +
`module \`${opts.pathInModule}\` could not be found within ` +
`the package. Indeed, none of these files exist:\n\n` +
` * \`${formatFileCandidates(opts.candidates.file)}\`\n` +
` * \`${formatFileCandidates(opts.candidates.dir)}\``);
Object.assign(this, opts);
}}
/**
* In the NodeJS-style module resolution scheme we want to check potential
* paths both as directories and as files. For example, `/foo/bar` may resolve
* to `/foo/bar.js` (preferred), but it might also be `/foo/bar/index.js`, or
* even a package directory.
*/
function resolveFileOrDir(
context,
potentialModulePath,
platform)
{
const dirPath = path.dirname(potentialModulePath);
const fileNameHint = path.basename(potentialModulePath);
const fileResult = resolveFile(context, dirPath, fileNameHint, platform);
if (fileResult.type === 'resolved') {
return fileResult;
}
const dirResult = resolveDir(context, potentialModulePath, platform);
if (dirResult.type === 'resolved') {
return dirResult;
}
return failedFor({ file: fileResult.candidates, dir: dirResult.candidates });
}
/**
* Try to resolve a potential path as if it was a directory-based module.
* Either this is a directory that contains a package, or that the directory
* contains an index file. If it fails to resolve these options, it returns
* `null` and fills the array of `candidates` that were tried.
*
* For example we could try to resolve `/foo/bar`, that would eventually
* resolve to `/foo/bar/lib/index.ios.js` if we're on platform iOS and that
* `bar` contains a package which entry point is `./lib/index` (or `./lib`).
*/
function resolveDir(
context,
potentialDirPath,
platform)
{
const packageJsonPath = path.join(potentialDirPath, 'package.json');
if (context.doesFileExist(packageJsonPath)) {
const resolution = resolvePackage(context, packageJsonPath, platform);
return { resolution, type: 'resolved' };
}
return resolveFile(context, potentialDirPath, 'index', platform);
}
/**
* Resolve the main module of a package that we know exist. The resolution
* itself cannot fail because we already resolved the path to the package.
* If the `main` of the package is invalid, this is not a resolution failure,
* this means the package is invalid, and should purposefully stop the
* resolution process altogether.
*/
function resolvePackage(
context,
packageJsonPath,
platform)
{
const mainPrefixPath = context.getPackageMainPath(packageJsonPath);
const dirPath = path.dirname(mainPrefixPath);
const prefixName = path.basename(mainPrefixPath);
const fileResult = resolveFile(context, dirPath, prefixName, platform);
if (fileResult.type === 'resolved') {
return fileResult.resolution;
}
const indexResult = resolveFile(context, mainPrefixPath, 'index', platform);
if (indexResult.type === 'resolved') {
return indexResult.resolution;
}
throw new InvalidPackageError({
packageJsonPath,
mainPrefixPath,
indexCandidates: indexResult.candidates,
fileCandidates: fileResult.candidates });
}
/**
* Given a directory path and the base asset name, return a list of all the
* asset file names that match the given base name in that directory. Return
* null if there's no such named asset. `platform` is used to identify
* platform-specific assets, ex. `foo.ios.js` instead of a generic `foo.js`.
*/
/**
* Check existence of a single file.
*/
/**
* Given a file name for a particular directory, return a resolution result
* depending on whether or not we found the corresponding module as a file. For
* example, we might ask for `foo.png`, that resolves to
* `['/js/beep/foo.ios.png']`. Or we may ask for `boop`, that resolves to
* `/js/boop.android.ts`. On the other hand this function does not resolve
* directory-based module names: for example `boop` will not resolve to
* `/js/boop/index.js` (see `_loadAsDir` for that).
*/
function resolveFile(
context,
dirPath,
fileNameHint,
platform)
{const
isAssetFile = context.isAssetFile,resolveAsset = context.resolveAsset;
if (isAssetFile(fileNameHint)) {
const result = resolveAssetFiles(
resolveAsset,
dirPath,
fileNameHint,
platform);
return mapResult(result, filePaths => ({ type: 'assetFiles', filePaths }));
}
const candidateExts = [];
const filePathPrefix = path.join(dirPath, fileNameHint);
const sfContext = _extends({}, context, { candidateExts, filePathPrefix });
const filePath = resolveSourceFile(sfContext, platform);
if (filePath != null) {
return resolvedAs({ type: 'sourceFile', filePath });
}
return failedFor({ type: 'sourceFile', filePathPrefix, candidateExts });
}
/**
* A particular 'base path' can resolve to a number of possibilities depending
* on the context. For example `foo/bar` could resolve to `foo/bar.ios.js`, or
* to `foo/bar.js`. If can also resolve to the bare path `foo/bar` itself, as
* supported by Node.js resolution. On the other hand it doesn't support
* `foo/bar.ios`, for historical reasons.
*
* Return the full path of the resolved module, `null` if no resolution could
* be found.
*/
function resolveSourceFile(
context,
platform)
{
let filePath = resolveSourceFileForAllExts(context, '');
if (filePath) {
return filePath;
}const
sourceExts = context.sourceExts;
for (let i = 0; i < sourceExts.length; i++) {
const ext = `.${sourceExts[i]}`;
filePath = resolveSourceFileForAllExts(context, ext, platform);
if (filePath != null) {
return filePath;
}
}
return null;
}
/**
* For a particular extension, ex. `js`, we want to try a few possibilities,
* such as `foo.ios.js`, `foo.native.js`, and of course `foo.js`. Return the
* full path of the resolved module, `null` if no resolution could be found.
*/
function resolveSourceFileForAllExts(
context,
sourceExt,
platform)
{
if (platform != null) {
const ext = `.${platform}${sourceExt}`;
const filePath = resolveSourceFileForExt(context, ext);
if (filePath) {
return filePath;
}
}
if (context.preferNativePlatform) {
const filePath = resolveSourceFileForExt(context, `.native${sourceExt}`);
if (filePath) {
return filePath;
}
}
const filePath = resolveSourceFileForExt(context, sourceExt);
return filePath;
}
/**
* We try to resolve a single possible extension. If it doesn't exist, then
* we make sure to add the extension to a list of candidates for reporting.
*/
function resolveSourceFileForExt(
context,
extension)
{
const filePath = `${context.filePathPrefix}${extension}`;
if (context.doesFileExist(filePath)) {
return filePath;
}
context.candidateExts.push(extension);
return null;
}
/**
* Find all the asset files corresponding to the file base name, and return
* it wrapped as a resolution result.
*/
function resolveAssetFiles(
resolveAsset,
dirPath,
fileNameHint,
platform)
{
const assetNames = resolveAsset(dirPath, fileNameHint, platform);
if (assetNames != null) {
const res = assetNames.map(assetName => path.join(dirPath, assetName));
return resolvedAs(res);
}
return failedFor({ type: 'asset', name: fileNameHint });
}
// HasteFS stores paths with backslashes on Windows, this ensures the path is in
// the proper format. Will also add drive letter if not present so `/root` will
// resolve to `C:\root`. Noop on other platforms.
function resolveWindowsPath(modulePath) {
if (path.sep !== '\\') {
return modulePath;
}
return path.resolve(modulePath);
}
function isRelativeImport(filePath) {
return (/^[.][.]?(?:[/]|$)/.test(filePath));
}
function normalizePath(modulePath) {
if (path.sep === '/') {
modulePath = path.normalize(modulePath);
} else if (path.posix) {
modulePath = path.posix.normalize(modulePath);
}
return modulePath.replace(/\/$/, '');
}
function resolvedAs(
resolution)
{
return { type: 'resolved', resolution };
}
function failedFor(
candidates)
{
return { type: 'failed', candidates };
}
function mapResult(
result,
mapper)
{
if (result.type === 'failed') {
return result;
}
return { type: 'resolved', resolution: mapper(result.resolution) };
}
module.exports = resolve;

520
node_modules/metro-resolver/src/resolve.js.flow generated vendored Normal file
View File

@@ -0,0 +1,520 @@
/**
* 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';
const FailedToResolveNameError = require('./FailedToResolveNameError');
const FailedToResolvePathError = require('./FailedToResolvePathError');
const InvalidPackageError = require('./InvalidPackageError');
const formatFileCandidates = require('./formatFileCandidates');
const isAbsolutePath = require('absolute-path');
const path = require('path');
import type {
AssetFileResolution,
FileAndDirCandidates,
FileCandidates,
FileResolution,
Resolution,
Result,
} from './types';
export type ResolutionContext = ModulePathContext &
HasteContext & {
originModulePath: string,
allowHaste: boolean,
extraNodeModules: ?{[string]: string},
};
function resolve(
context: ResolutionContext,
moduleName: string,
platform: string | null,
): Resolution {
if (isRelativeImport(moduleName) || isAbsolutePath(moduleName)) {
return resolveModulePath(context, moduleName, platform);
}
const realModuleName = context.redirectModulePath(moduleName);
// exclude
if (realModuleName === false) {
return {type: 'empty'};
}
const {originModulePath} = context;
if (isRelativeImport(realModuleName) || isAbsolutePath(realModuleName)) {
// derive absolute path /.../node_modules/originModuleDir/realModuleName
const fromModuleParentIdx =
originModulePath.lastIndexOf('node_modules' + path.sep) + 13;
const originModuleDir = originModulePath.slice(
0,
originModulePath.indexOf(path.sep, fromModuleParentIdx),
);
const absPath = path.join(originModuleDir, realModuleName);
return resolveModulePath(context, absPath, platform);
}
// At that point we only have module names that
// aren't relative paths nor absolute paths.
if (context.allowHaste) {
const normalizedName = normalizePath(realModuleName);
const result = resolveHasteName(context, normalizedName, platform);
if (result.type === 'resolved') {
return result.resolution;
}
}
const dirPaths = [];
for (
let currDir = path.dirname(originModulePath);
currDir !== '.' && currDir !== path.parse(originModulePath).root;
currDir = path.dirname(currDir)
) {
const searchPath = path.join(currDir, 'node_modules');
dirPaths.push(path.join(searchPath, realModuleName));
}
const extraPaths = [];
const {extraNodeModules} = context;
if (extraNodeModules) {
const bits = path.normalize(moduleName).split(path.sep);
const packageName = bits[0];
if (extraNodeModules[packageName]) {
bits[0] = extraNodeModules[packageName];
extraPaths.push(path.join.apply(path, bits));
}
}
const allDirPaths = dirPaths.concat(extraPaths);
for (let i = 0; i < allDirPaths.length; ++i) {
const result = resolveFileOrDir(context, allDirPaths[i], platform);
if (result.type === 'resolved') {
return result.resolution;
}
}
throw new FailedToResolveNameError(dirPaths, extraPaths);
}
type ModulePathContext = FileOrDirContext & {
/**
* Full path of the module that is requiring or importing the module to be
* resolved.
*/
+originModulePath: string,
/**
* Lookup the module's closest `package.json` and process the redirects
* metadata. Return an absolute path to the resolved path.
*/
+redirectModulePath: (modulePath: string) => string | false,
};
/**
* Resolve any kind of module path, whether it's a file or a directory.
* For example we may want to resolve './foobar'. The closest
* `package.json` may define a redirection for this path, for example
* `/smth/lib/foobar`, that may be further resolved to
* `/smth/lib/foobar/index.ios.js`.
*/
function resolveModulePath(
context: ModulePathContext,
toModuleName: string,
platform: string | null,
): Resolution {
const modulePath = isAbsolutePath(toModuleName)
? resolveWindowsPath(toModuleName)
: path.join(path.dirname(context.originModulePath), toModuleName);
const redirectedPath = context.redirectModulePath(modulePath);
if (redirectedPath === false) {
return {type: 'empty'};
}
const result = resolveFileOrDir(context, redirectedPath, platform);
if (result.type === 'resolved') {
return result.resolution;
}
throw new FailedToResolvePathError(result.candidates);
}
type HasteContext = FileOrDirContext & {
/**
* Given a name, this should return the full path to the file that provides
* a Haste module of that name. Ex. for `Foo` it may return `/smth/Foo.js`.
*/
+resolveHasteModule: (name: string) => ?string,
/**
* Given a name, this should return the full path to the package manifest that
* provides a Haste package of that name. Ex. for `Foo` it may return
* `/smth/Foo/package.json`.
*/
+resolveHastePackage: (name: string) => ?string,
};
/**
* Resolve a module as a Haste module or package. For example we might try to
* resolve `Foo`, that is provided by file `/smth/Foo.js`. Or, in the case of
* a Haste package, it could be `/smth/Foo/index.js`.
*/
function resolveHasteName(
context: HasteContext,
moduleName: string,
platform: string | null,
): Result<FileResolution, void> {
const modulePath = context.resolveHasteModule(moduleName);
if (modulePath != null) {
return resolvedAs({type: 'sourceFile', filePath: modulePath});
}
let packageName = moduleName;
let packageJsonPath = context.resolveHastePackage(packageName);
while (packageJsonPath == null && packageName && packageName !== '.') {
packageName = path.dirname(packageName);
packageJsonPath = context.resolveHastePackage(packageName);
}
if (packageJsonPath == null) {
return failedFor();
}
const packageDirPath = path.dirname(packageJsonPath);
const pathInModule = moduleName.substring(packageName.length + 1);
const potentialModulePath = path.join(packageDirPath, pathInModule);
const result = resolveFileOrDir(context, potentialModulePath, platform);
if (result.type === 'resolved') {
return result;
}
const {candidates} = result;
const opts = {moduleName, packageName, pathInModule, candidates};
throw new MissingFileInHastePackageError(opts);
}
class MissingFileInHastePackageError extends Error {
candidates: FileAndDirCandidates;
moduleName: string;
packageName: string;
pathInModule: string;
constructor(opts: {|
+candidates: FileAndDirCandidates,
+moduleName: string,
+packageName: string,
+pathInModule: string,
|}) {
super(
`While resolving module \`${opts.moduleName}\`, ` +
`the Haste package \`${opts.packageName}\` was found. However the ` +
`module \`${opts.pathInModule}\` could not be found within ` +
`the package. Indeed, none of these files exist:\n\n` +
` * \`${formatFileCandidates(opts.candidates.file)}\`\n` +
` * \`${formatFileCandidates(opts.candidates.dir)}\``,
);
Object.assign(this, opts);
}
}
type FileOrDirContext = FileContext & {
/**
* This should return the path of the "main" module of the specified
* `package.json` file, after post-processing: for example, applying the
* 'browser' field if necessary.
*
* FIXME: move the post-processing here. Right now it is
* located in `node-haste/Package.js`, and fully duplicated in
* `ModuleGraph/node-haste/Package.js` (!)
*/
+getPackageMainPath: (packageJsonPath: string) => string,
};
/**
* In the NodeJS-style module resolution scheme we want to check potential
* paths both as directories and as files. For example, `/foo/bar` may resolve
* to `/foo/bar.js` (preferred), but it might also be `/foo/bar/index.js`, or
* even a package directory.
*/
function resolveFileOrDir(
context: FileOrDirContext,
potentialModulePath: string,
platform: string | null,
): Result<FileResolution, FileAndDirCandidates> {
const dirPath = path.dirname(potentialModulePath);
const fileNameHint = path.basename(potentialModulePath);
const fileResult = resolveFile(context, dirPath, fileNameHint, platform);
if (fileResult.type === 'resolved') {
return fileResult;
}
const dirResult = resolveDir(context, potentialModulePath, platform);
if (dirResult.type === 'resolved') {
return dirResult;
}
return failedFor({file: fileResult.candidates, dir: dirResult.candidates});
}
/**
* Try to resolve a potential path as if it was a directory-based module.
* Either this is a directory that contains a package, or that the directory
* contains an index file. If it fails to resolve these options, it returns
* `null` and fills the array of `candidates` that were tried.
*
* For example we could try to resolve `/foo/bar`, that would eventually
* resolve to `/foo/bar/lib/index.ios.js` if we're on platform iOS and that
* `bar` contains a package which entry point is `./lib/index` (or `./lib`).
*/
function resolveDir(
context: FileOrDirContext,
potentialDirPath: string,
platform: string | null,
): Result<FileResolution, FileCandidates> {
const packageJsonPath = path.join(potentialDirPath, 'package.json');
if (context.doesFileExist(packageJsonPath)) {
const resolution = resolvePackage(context, packageJsonPath, platform);
return {resolution, type: 'resolved'};
}
return resolveFile(context, potentialDirPath, 'index', platform);
}
/**
* Resolve the main module of a package that we know exist. The resolution
* itself cannot fail because we already resolved the path to the package.
* If the `main` of the package is invalid, this is not a resolution failure,
* this means the package is invalid, and should purposefully stop the
* resolution process altogether.
*/
function resolvePackage(
context: FileOrDirContext,
packageJsonPath: string,
platform: string | null,
): FileResolution {
const mainPrefixPath = context.getPackageMainPath(packageJsonPath);
const dirPath = path.dirname(mainPrefixPath);
const prefixName = path.basename(mainPrefixPath);
const fileResult = resolveFile(context, dirPath, prefixName, platform);
if (fileResult.type === 'resolved') {
return fileResult.resolution;
}
const indexResult = resolveFile(context, mainPrefixPath, 'index', platform);
if (indexResult.type === 'resolved') {
return indexResult.resolution;
}
throw new InvalidPackageError({
packageJsonPath,
mainPrefixPath,
indexCandidates: indexResult.candidates,
fileCandidates: fileResult.candidates,
});
}
/**
* Given a directory path and the base asset name, return a list of all the
* asset file names that match the given base name in that directory. Return
* null if there's no such named asset. `platform` is used to identify
* platform-specific assets, ex. `foo.ios.js` instead of a generic `foo.js`.
*/
export type ResolveAsset = (
dirPath: string,
assetName: string,
platform: string | null,
) => ?$ReadOnlyArray<string>;
/**
* Check existence of a single file.
*/
export type DoesFileExist = (filePath: string) => boolean;
export type IsAssetFile = (fileName: string) => boolean;
type FileContext = {
+doesFileExist: DoesFileExist,
+isAssetFile: IsAssetFile,
+preferNativePlatform: boolean,
+resolveAsset: ResolveAsset,
+sourceExts: $ReadOnlyArray<string>,
};
/**
* Given a file name for a particular directory, return a resolution result
* depending on whether or not we found the corresponding module as a file. For
* example, we might ask for `foo.png`, that resolves to
* `['/js/beep/foo.ios.png']`. Or we may ask for `boop`, that resolves to
* `/js/boop.android.ts`. On the other hand this function does not resolve
* directory-based module names: for example `boop` will not resolve to
* `/js/boop/index.js` (see `_loadAsDir` for that).
*/
function resolveFile(
context: FileContext,
dirPath: string,
fileNameHint: string,
platform: string | null,
): Result<FileResolution, FileCandidates> {
const {isAssetFile, resolveAsset} = context;
if (isAssetFile(fileNameHint)) {
const result = resolveAssetFiles(
resolveAsset,
dirPath,
fileNameHint,
platform,
);
return mapResult(result, filePaths => ({type: 'assetFiles', filePaths}));
}
const candidateExts = [];
const filePathPrefix = path.join(dirPath, fileNameHint);
const sfContext = {...context, candidateExts, filePathPrefix};
const filePath = resolveSourceFile(sfContext, platform);
if (filePath != null) {
return resolvedAs({type: 'sourceFile', filePath});
}
return failedFor({type: 'sourceFile', filePathPrefix, candidateExts});
}
type SourceFileContext = SourceFileForAllExtsContext & {
+sourceExts: $ReadOnlyArray<string>,
};
/**
* A particular 'base path' can resolve to a number of possibilities depending
* on the context. For example `foo/bar` could resolve to `foo/bar.ios.js`, or
* to `foo/bar.js`. If can also resolve to the bare path `foo/bar` itself, as
* supported by Node.js resolution. On the other hand it doesn't support
* `foo/bar.ios`, for historical reasons.
*
* Return the full path of the resolved module, `null` if no resolution could
* be found.
*/
function resolveSourceFile(
context: SourceFileContext,
platform: ?string,
): ?string {
let filePath = resolveSourceFileForAllExts(context, '');
if (filePath) {
return filePath;
}
const {sourceExts} = context;
for (let i = 0; i < sourceExts.length; i++) {
const ext = `.${sourceExts[i]}`;
filePath = resolveSourceFileForAllExts(context, ext, platform);
if (filePath != null) {
return filePath;
}
}
return null;
}
type SourceFileForAllExtsContext = SourceFileForExtContext & {
+preferNativePlatform: boolean,
};
/**
* For a particular extension, ex. `js`, we want to try a few possibilities,
* such as `foo.ios.js`, `foo.native.js`, and of course `foo.js`. Return the
* full path of the resolved module, `null` if no resolution could be found.
*/
function resolveSourceFileForAllExts(
context: SourceFileForAllExtsContext,
sourceExt: string,
platform: ?string,
): ?string {
if (platform != null) {
const ext = `.${platform}${sourceExt}`;
const filePath = resolveSourceFileForExt(context, ext);
if (filePath) {
return filePath;
}
}
if (context.preferNativePlatform) {
const filePath = resolveSourceFileForExt(context, `.native${sourceExt}`);
if (filePath) {
return filePath;
}
}
const filePath = resolveSourceFileForExt(context, sourceExt);
return filePath;
}
type SourceFileForExtContext = {
+candidateExts: Array<string>,
+doesFileExist: DoesFileExist,
+filePathPrefix: string,
};
/**
* We try to resolve a single possible extension. If it doesn't exist, then
* we make sure to add the extension to a list of candidates for reporting.
*/
function resolveSourceFileForExt(
context: SourceFileForExtContext,
extension: string,
): ?string {
const filePath = `${context.filePathPrefix}${extension}`;
if (context.doesFileExist(filePath)) {
return filePath;
}
context.candidateExts.push(extension);
return null;
}
/**
* Find all the asset files corresponding to the file base name, and return
* it wrapped as a resolution result.
*/
function resolveAssetFiles(
resolveAsset: ResolveAsset,
dirPath: string,
fileNameHint: string,
platform: string | null,
): Result<AssetFileResolution, FileCandidates> {
const assetNames = resolveAsset(dirPath, fileNameHint, platform);
if (assetNames != null) {
const res = assetNames.map(assetName => path.join(dirPath, assetName));
return resolvedAs(res);
}
return failedFor({type: 'asset', name: fileNameHint});
}
// HasteFS stores paths with backslashes on Windows, this ensures the path is in
// the proper format. Will also add drive letter if not present so `/root` will
// resolve to `C:\root`. Noop on other platforms.
function resolveWindowsPath(modulePath) {
if (path.sep !== '\\') {
return modulePath;
}
return path.resolve(modulePath);
}
function isRelativeImport(filePath: string) {
return /^[.][.]?(?:[/]|$)/.test(filePath);
}
function normalizePath(modulePath) {
if (path.sep === '/') {
modulePath = path.normalize(modulePath);
} else if (path.posix) {
modulePath = path.posix.normalize(modulePath);
}
return modulePath.replace(/\/$/, '');
}
function resolvedAs<TResolution, TCandidates>(
resolution: TResolution,
): Result<TResolution, TCandidates> {
return {type: 'resolved', resolution};
}
function failedFor<TResolution, TCandidates>(
candidates: TCandidates,
): Result<TResolution, TCandidates> {
return {type: 'failed', candidates};
}
function mapResult<TResolution, TNewResolution, TCandidates>(
result: Result<TResolution, TCandidates>,
mapper: TResolution => TNewResolution,
): Result<TNewResolution, TCandidates> {
if (result.type === 'failed') {
return result;
}
return {type: 'resolved', resolution: mapper(result.resolution)};
}
module.exports = resolve;

11
node_modules/metro-resolver/src/types.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
/**
* 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';

44
node_modules/metro-resolver/src/types.js.flow generated vendored Normal file
View File

@@ -0,0 +1,44 @@
/**
* 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';
export type Result<+TResolution, +TCandidates> =
| {|+type: 'resolved', +resolution: TResolution|}
| {|+type: 'failed', +candidates: TCandidates|};
export type Resolution = FileResolution | {|+type: 'empty'|};
export type AssetFileResolution = $ReadOnlyArray<string>;
export type FileResolution =
| {|+type: 'sourceFile', +filePath: string|}
| {|+type: 'assetFiles', +filePaths: AssetFileResolution|};
export type FileAndDirCandidates = {|
+dir: FileCandidates,
+file: FileCandidates,
|};
/**
* This is a way to describe what files we tried to look for when resolving
* a module name as file. This is mainly used for error reporting, so that
* we can explain why we cannot resolve a module.
*/
export type FileCandidates =
// We only tried to resolve a specific asset.
| {|+type: 'asset', +name: string|}
// We attempted to resolve a name as being a source file (ex. JavaScript,
// JSON...), in which case there can be several extensions we tried, for
// example `/js/foo.ios.js`, `/js/foo.js`, etc. for a single prefix '/js/foo'.
| {|
+type: 'sourceFile',
+filePathPrefix: string,
+candidateExts: $ReadOnlyArray<string>,
|};