chore: add mobile app

This commit is contained in:
2026-02-07 22:33:02 +01:00
parent db34640acc
commit e89384ad4e
29327 changed files with 3886944 additions and 12 deletions
+19
View File
@@ -0,0 +1,19 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @oncall react_native
*/
/**
* Determine if a file path should be considered an asset file based on the
* given `assetExts`.
*/
declare function isAssetFile(
filePath: string,
assetExts: ReadonlySet<string>,
): boolean;
export default isAssetFile;
+22
View File
@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = isAssetFile;
var _path = _interopRequireDefault(require("path"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
function isAssetFile(filePath, assetExts) {
const baseName = _path.default.basename(filePath);
for (let i = baseName.length - 1; i >= 0; i--) {
if (baseName[i] === ".") {
const ext = baseName.slice(i + 1);
if (assetExts.has(ext)) {
return true;
}
}
}
return false;
}
@@ -0,0 +1,35 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
* @oncall react_native
*/
import path from 'path';
/**
* Determine if a file path should be considered an asset file based on the
* given `assetExts`.
*/
export default function isAssetFile(
filePath: string,
assetExts: $ReadOnlySet<string>,
): boolean {
const baseName = path.basename(filePath);
for (let i = baseName.length - 1; i >= 0; i--) {
if (baseName[i] === '.') {
const ext = baseName.slice(i + 1);
if (assetExts.has(ext)) {
return true;
}
}
}
return false;
}
@@ -0,0 +1,21 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @oncall react_native
*/
/**
* Identifies whether the given subpath is defined in the given "exports"-like
* mapping. Does not reduce exports conditions (therefore does not identify
* whether the subpath is mapped to a value).
*/
import type {NormalizedExportsLikeMap} from '../types';
export declare function isSubpathDefinedInExportsLike(
exportsLikeMap: NormalizedExportsLikeMap,
subpath: string,
): boolean;
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.isSubpathDefinedInExportsLike = isSubpathDefinedInExportsLike;
var _matchSubpathPattern = require("./matchSubpathPattern");
function isSubpathDefinedInExportsLike(exportsLikeMap, subpath) {
if (exportsLikeMap.has(subpath)) {
return true;
}
for (const key of exportsLikeMap.keys()) {
if (
key.split("*").length === 2 &&
(0, _matchSubpathPattern.matchSubpathPattern)(key, subpath) != null
) {
return true;
}
}
return false;
}
@@ -0,0 +1,40 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
/**
* Identifies whether the given subpath is defined in the given "exports"-like
* mapping. Does not reduce exports conditions (therefore does not identify
* whether the subpath is mapped to a value).
*/
import type {NormalizedExportsLikeMap} from '../types';
import {matchSubpathPattern} from './matchSubpathPattern';
export function isSubpathDefinedInExportsLike(
exportsLikeMap: NormalizedExportsLikeMap,
subpath: string,
): boolean {
if (exportsLikeMap.has(subpath)) {
return true;
}
// Attempt to match after expanding any subpath pattern keys
for (const key of exportsLikeMap.keys()) {
if (
key.split('*').length === 2 &&
matchSubpathPattern(key, subpath) != null
) {
return true;
}
}
return false;
}
@@ -0,0 +1,24 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @oncall react_native
*/
import type {NormalizedExportsLikeMap, ResolutionContext} from '../types';
/**
* Get the mapped replacement for the given subpath.
*
* Implements modern package resolution behaviour based on the [Package Entry
* Points spec](https://nodejs.org/docs/latest-v19.x/api/packages.html#package-entry-points).
*/
export declare function matchSubpathFromExportsLike(
context: ResolutionContext,
subpath: string,
exportsLikeMap: NormalizedExportsLikeMap,
platform: string | null,
createConfigError: (reason: string) => Error,
): Readonly<{target: string | null; patternMatch: string | null}>;
@@ -0,0 +1,61 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.matchSubpathFromExportsLike = matchSubpathFromExportsLike;
var _matchSubpathPattern = require("./matchSubpathPattern");
var _reduceExportsLikeMap = require("./reduceExportsLikeMap");
function matchSubpathFromExportsLike(
context,
subpath,
exportsLikeMap,
platform,
createConfigError,
) {
const conditionNames = new Set([
"default",
context.isESMImport === true ? "import" : "require",
...context.unstable_conditionNames,
...(platform != null
? (context.unstable_conditionsByPlatform[platform] ?? [])
: []),
]);
const exportsLikeMapAfterConditions = (0,
_reduceExportsLikeMap.reduceExportsLikeMap)(
exportsLikeMap,
conditionNames,
createConfigError,
);
let target = exportsLikeMapAfterConditions.get(subpath);
let patternMatch = null;
if (target == null) {
const expansionKeys = [...exportsLikeMapAfterConditions.keys()]
.map((key) => ({
key,
baseLength: key.indexOf("*"),
}))
.filter((data) => data.baseLength !== -1)
.sort((a, b) => {
if (a.baseLength === b.baseLength) {
return b.key.length - a.key.length;
}
return b.baseLength - a.baseLength;
});
for (const { key } of expansionKeys) {
const value = exportsLikeMapAfterConditions.get(key);
patternMatch = (0, _matchSubpathPattern.matchSubpathPattern)(
key,
subpath,
);
if (patternMatch != null) {
target = value;
break;
}
}
}
return {
target: target ?? null,
patternMatch,
};
}
@@ -0,0 +1,85 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
import type {NormalizedExportsLikeMap, ResolutionContext} from '../types';
import {matchSubpathPattern} from './matchSubpathPattern';
import {reduceExportsLikeMap} from './reduceExportsLikeMap';
/**
* Get the mapped replacement for the given subpath.
*
* Implements modern package resolution behaviour based on the [Package Entry
* Points spec](https://nodejs.org/docs/latest-v19.x/api/packages.html#package-entry-points).
*/
export function matchSubpathFromExportsLike(
context: ResolutionContext,
/**
* The package-relative subpath (beginning with '.') to match against either
* an exact subpath key or subpath pattern key in "exports".
*/
subpath: string,
exportsLikeMap: NormalizedExportsLikeMap,
platform: string | null,
createConfigError: (reason: string) => Error,
): $ReadOnly<{
target: string | null,
patternMatch: string | null,
}> {
const conditionNames = new Set([
'default',
context.isESMImport === true ? 'import' : 'require',
...context.unstable_conditionNames,
...(platform != null
? (context.unstable_conditionsByPlatform[platform] ?? [])
: []),
]);
const exportsLikeMapAfterConditions = reduceExportsLikeMap(
exportsLikeMap,
conditionNames,
createConfigError,
);
let target = exportsLikeMapAfterConditions.get(subpath);
let patternMatch = null;
// Attempt to match after expanding any subpath pattern keys
if (target == null) {
// Gather keys which are subpath patterns in descending order of specificity
// For ordering, see `PATTERN_KEY_COMPARE` in:
// https://nodejs.org/api/esm.html#resolution-algorithm-specification
const expansionKeys = [...exportsLikeMapAfterConditions.keys()]
.map(key => ({key, baseLength: key.indexOf('*')}))
.filter(data => data.baseLength !== -1)
.sort((a, b) => {
if (a.baseLength === b.baseLength) {
// If wildcards are in equal positions, the longer key is more
// specific
return b.key.length - a.key.length;
}
return b.baseLength - a.baseLength;
});
for (const {key} of expansionKeys) {
const value = exportsLikeMapAfterConditions.get(key);
patternMatch = matchSubpathPattern(key, subpath);
if (patternMatch != null) {
target = value;
break;
}
}
}
return {target: target ?? null, patternMatch};
}
@@ -0,0 +1,20 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @oncall react_native
*/
/**
* If a subpath pattern expands to the passed subpath, return the subpath match
* (value to substitute for '*'). Otherwise, return `null`.
*
* See https://nodejs.org/docs/latest-v19.x/api/packages.html#subpath-patterns.
*/
export declare function matchSubpathPattern(
subpathPattern: string,
subpath: string,
): string | null;
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.matchSubpathPattern = matchSubpathPattern;
function matchSubpathPattern(subpathPattern, subpath) {
const [patternBase, patternTrailer] = subpathPattern.split("*");
if (
subpath.startsWith(patternBase) &&
(patternTrailer.length === 0 ||
(subpath.endsWith(patternTrailer) &&
subpath.length >= subpathPattern.length))
) {
return subpath.substring(
patternBase.length,
subpath.length - patternTrailer.length,
);
}
return null;
}
@@ -0,0 +1,37 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
* @oncall react_native
*/
/**
* If a subpath pattern expands to the passed subpath, return the subpath match
* (value to substitute for '*'). Otherwise, return `null`.
*
* See https://nodejs.org/docs/latest-v19.x/api/packages.html#subpath-patterns.
*/
export function matchSubpathPattern(
subpathPattern: string,
subpath: string,
): string | null {
const [patternBase, patternTrailer] = subpathPattern.split('*');
if (
subpath.startsWith(patternBase) &&
(patternTrailer.length === 0 ||
(subpath.endsWith(patternTrailer) &&
subpath.length >= subpathPattern.length))
) {
return subpath.substring(
patternBase.length,
subpath.length - patternTrailer.length,
);
}
return null;
}
@@ -0,0 +1,21 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @oncall react_native
*/
/**
* Reduce an "exports"-like mapping to a flat subpath mapping after resolving
* conditional exports.
*/
import type {FlattenedExportMap, NormalizedExportsLikeMap} from '../types';
export declare function reduceExportsLikeMap(
exportsLikeMap: NormalizedExportsLikeMap,
conditionNames: ReadonlySet<string>,
createConfigError: (reason: string) => Error,
): FlattenedExportMap;
@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.reduceExportsLikeMap = reduceExportsLikeMap;
function reduceExportsLikeMap(
exportsLikeMap,
conditionNames,
createConfigError,
) {
const result = new Map();
for (const [subpath, value] of exportsLikeMap) {
const subpathValue = reduceConditionalExport(value, conditionNames);
if (subpathValue !== "no-match") {
result.set(subpath, subpathValue);
}
}
for (const value of result.values()) {
if (value != null && !value.startsWith("./")) {
throw createConfigError(
'One or more mappings for subpaths defined in "exports" are invalid. ' +
'All values must begin with "./".',
);
}
}
return result;
}
function reduceConditionalExport(subpathValue, conditionNames) {
let reducedValue = subpathValue;
while (reducedValue != null && typeof reducedValue !== "string") {
let match;
if ("default" in reducedValue) {
match = "no-match";
} else {
match = null;
}
for (const conditionName in reducedValue) {
if (conditionNames.has(conditionName)) {
match = reducedValue[conditionName];
break;
}
}
reducedValue = match;
}
return reducedValue;
}
@@ -0,0 +1,90 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
/**
* Reduce an "exports"-like mapping to a flat subpath mapping after resolving
* conditional exports.
*/
import type {
ExportsLikeMap,
FlattenedExportMap,
NormalizedExportsLikeMap,
} from '../types';
export function reduceExportsLikeMap(
exportsLikeMap: NormalizedExportsLikeMap,
conditionNames: $ReadOnlySet<string>,
createConfigError: (reason: string) => Error,
): FlattenedExportMap {
const result = new Map<string, string | null>();
for (const [subpath, value] of exportsLikeMap) {
const subpathValue = reduceConditionalExport(value, conditionNames);
// If a subpath has no resolution for the passed `conditionNames`, do not
// include it in the result. (This includes only explicit `null` values,
// which may conditionally hide higher-specificity subpath patterns.)
if (subpathValue !== 'no-match') {
result.set(subpath, subpathValue);
}
}
for (const value of result.values()) {
if (value != null && !value.startsWith('./')) {
throw createConfigError(
'One or more mappings for subpaths defined in "exports" are invalid. ' +
'All values must begin with "./".',
);
}
}
return result;
}
/**
* Reduce an "exports"-like subpath value after asserting the passed
* `conditionNames` in any nested conditions.
*
* Returns `'no-match'` in the case that none of the asserted `conditionNames`
* are matched.
*
* See https://nodejs.org/docs/latest-v19.x/api/packages.html#conditional-exports.
*/
function reduceConditionalExport(
subpathValue: $Values<ExportsLikeMap>,
conditionNames: $ReadOnlySet<string>,
): string | null | 'no-match' {
let reducedValue = subpathValue;
while (reducedValue != null && typeof reducedValue !== 'string') {
let match: typeof subpathValue | 'no-match';
// when conditions are present and default is not specified
// the default condition is implicitly set to null, to allow
// for restricting access to unexported internals of a package.
if ('default' in reducedValue) {
match = 'no-match';
} else {
match = null;
}
for (const conditionName in reducedValue) {
if (conditionNames.has(conditionName)) {
match = reducedValue[conditionName];
break;
}
}
reducedValue = match;
}
return reducedValue;
}
+16
View File
@@ -0,0 +1,16 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @oncall react_native
*/
/**
* Replace path separators in the passed string to coerce to a POSIX path. This
* is a no-op on POSIX systems.
*/
declare function toPosixPath(relativePathOrSpecifier: string): string;
export default toPosixPath;
+23
View File
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.default = toPosixPath;
var _path = _interopRequireDefault(require("path"));
function _interopRequireDefault(e) {
return e && e.__esModule ? e : { default: e };
}
const MATCH_NON_POSIX_PATH_SEPS = new RegExp(
"\\" + _path.default.win32.sep,
"g",
);
function toPosixPath(relativePathOrSpecifier) {
if (_path.default.sep === _path.default.posix.sep) {
return relativePathOrSpecifier;
}
return relativePathOrSpecifier.replace(
MATCH_NON_POSIX_PATH_SEPS,
_path.default.posix.sep,
);
}
@@ -0,0 +1,29 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
* @oncall react_native
*/
import path from 'path';
const MATCH_NON_POSIX_PATH_SEPS = new RegExp('\\' + path.win32.sep, 'g');
/**
* Replace path separators in the passed string to coerce to a POSIX path. This
* is a no-op on POSIX systems.
*/
export default function toPosixPath(relativePathOrSpecifier: string): string {
if (path.sep === path.posix.sep) {
return relativePathOrSpecifier;
}
return relativePathOrSpecifier.replace(
MATCH_NON_POSIX_PATH_SEPS,
path.posix.sep,
);
}