@rnx-kit/tools-react-native
Advanced tools
@@ -18,9 +18,19 @@ "use strict"; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importStar = (this && this.__importStar) || (function () { | ||
var ownKeys = function(o) { | ||
ownKeys = Object.getOwnPropertyNames || function (o) { | ||
var ar = []; | ||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
return ar; | ||
}; | ||
return ownKeys(o); | ||
}; | ||
return function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -27,0 +37,0 @@ exports.getCurrentState = getCurrentState; |
@@ -18,9 +18,19 @@ "use strict"; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importStar = (this && this.__importStar) || (function () { | ||
var ownKeys = function(o) { | ||
ownKeys = Object.getOwnPropertyNames || function (o) { | ||
var ar = []; | ||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
return ar; | ||
}; | ||
return ownKeys(o); | ||
}; | ||
return function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -27,0 +37,0 @@ exports.REACT_NATIVE_CONFIG_FILES = void 0; |
export { loadContext, loadContextAsync, readReactNativeConfig, resolveCommunityCLI, } from "./context"; | ||
export { findMetroPath, getMetroVersion, requireModuleFromMetro, } from "./metro"; | ||
export { expandPlatformExtensions, getAvailablePlatforms, getAvailablePlatformsUncached, parsePlatform, platformExtensions, } from "./platform"; | ||
export { expandPlatformExtensions, getAvailablePlatforms, getAvailablePlatformsUncached, getModuleSuffixes, parsePlatform, platformExtensions, platformValues, tryParsePlatform, } from "./platform"; | ||
export type { AllPlatforms } from "./platform"; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.platformExtensions = exports.parsePlatform = exports.getAvailablePlatformsUncached = exports.getAvailablePlatforms = exports.expandPlatformExtensions = exports.requireModuleFromMetro = exports.getMetroVersion = exports.findMetroPath = exports.resolveCommunityCLI = exports.readReactNativeConfig = exports.loadContextAsync = exports.loadContext = void 0; | ||
exports.tryParsePlatform = exports.platformValues = exports.platformExtensions = exports.parsePlatform = exports.getModuleSuffixes = exports.getAvailablePlatformsUncached = exports.getAvailablePlatforms = exports.expandPlatformExtensions = exports.requireModuleFromMetro = exports.getMetroVersion = exports.findMetroPath = exports.resolveCommunityCLI = exports.readReactNativeConfig = exports.loadContextAsync = exports.loadContext = void 0; | ||
var context_1 = require("./context"); | ||
@@ -17,4 +17,7 @@ Object.defineProperty(exports, "loadContext", { enumerable: true, get: function () { return context_1.loadContext; } }); | ||
Object.defineProperty(exports, "getAvailablePlatformsUncached", { enumerable: true, get: function () { return platform_1.getAvailablePlatformsUncached; } }); | ||
Object.defineProperty(exports, "getModuleSuffixes", { enumerable: true, get: function () { return platform_1.getModuleSuffixes; } }); | ||
Object.defineProperty(exports, "parsePlatform", { enumerable: true, get: function () { return platform_1.parsePlatform; } }); | ||
Object.defineProperty(exports, "platformExtensions", { enumerable: true, get: function () { return platform_1.platformExtensions; } }); | ||
Object.defineProperty(exports, "platformValues", { enumerable: true, get: function () { return platform_1.platformValues; } }); | ||
Object.defineProperty(exports, "tryParsePlatform", { enumerable: true, get: function () { return platform_1.tryParsePlatform; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -18,9 +18,19 @@ "use strict"; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importStar = (this && this.__importStar) || (function () { | ||
var ownKeys = function(o) { | ||
ownKeys = Object.getOwnPropertyNames || function (o) { | ||
var ar = []; | ||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
return ar; | ||
}; | ||
return ownKeys(o); | ||
}; | ||
return function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -27,0 +37,0 @@ exports.findMetroPath = findMetroPath; |
/** | ||
* List of supported react-native platforms. | ||
*/ | ||
export type AllPlatforms = "android" | "ios" | "macos" | "win32" | "windows"; | ||
export type AllPlatforms = "android" | "ios" | "macos" | "win32" | "windows" | "visionos"; | ||
/** | ||
@@ -14,2 +14,11 @@ * Returns a list of extensions that should be tried for the target platform in | ||
/** | ||
* Get the module suffixes array for a given platform, suitable for use with TypeScript's moduleSuffixes setting | ||
* in the form of ['.ios', '.native', ''] or ['.windows', '.win', '.native', ''] or similar | ||
* | ||
* @param platform platform to get module suffixes for | ||
* @param appendEmpty finish the suffixes with an empty entry, required for typescript usage | ||
* @returns an array of suffixes to try to match a module to in order of priority | ||
*/ | ||
export declare function getModuleSuffixes(platform: AllPlatforms, appendEmpty?: boolean): string[]; | ||
/** | ||
* Returns a map of available React Native platforms. The result is NOT cached. | ||
@@ -34,2 +43,6 @@ * @param startDir The directory to look for react-native platforms from | ||
/** | ||
* @returns the given string as a platform value or undefined if it is not a valid platform. | ||
*/ | ||
export declare function tryParsePlatform(val: string): AllPlatforms | undefined; | ||
/** | ||
* Parse a string to ensure it maps to a valid react-native platform. | ||
@@ -41,2 +54,6 @@ * | ||
export declare function parsePlatform(val: string): AllPlatforms; | ||
/** | ||
* @returns List of all supported react-native platforms. | ||
*/ | ||
export declare function platformValues(): readonly AllPlatforms[]; | ||
//# sourceMappingURL=platform.d.ts.map |
@@ -18,15 +18,28 @@ "use strict"; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importStar = (this && this.__importStar) || (function () { | ||
var ownKeys = function(o) { | ||
ownKeys = Object.getOwnPropertyNames || function (o) { | ||
var ar = []; | ||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
return ar; | ||
}; | ||
return ownKeys(o); | ||
}; | ||
return function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getAvailablePlatforms = void 0; | ||
exports.expandPlatformExtensions = expandPlatformExtensions; | ||
exports.getModuleSuffixes = getModuleSuffixes; | ||
exports.getAvailablePlatformsUncached = getAvailablePlatformsUncached; | ||
exports.platformExtensions = platformExtensions; | ||
exports.tryParsePlatform = tryParsePlatform; | ||
exports.parsePlatform = parsePlatform; | ||
exports.platformValues = platformValues; | ||
const package_1 = require("@rnx-kit/tools-node/package"); | ||
@@ -36,2 +49,11 @@ const fs = __importStar(require("node:fs")); | ||
const context_1 = require("./context"); | ||
// Possible values for AllPlatforms | ||
const allValues = [ | ||
"android", | ||
"ios", | ||
"macos", | ||
"win32", | ||
"windows", | ||
"visionos", | ||
]; | ||
/** | ||
@@ -54,2 +76,17 @@ * Returns a list of extensions that should be tried for the target platform in | ||
/** | ||
* Get the module suffixes array for a given platform, suitable for use with TypeScript's moduleSuffixes setting | ||
* in the form of ['.ios', '.native', ''] or ['.windows', '.win', '.native', ''] or similar | ||
* | ||
* @param platform platform to get module suffixes for | ||
* @param appendEmpty finish the suffixes with an empty entry, required for typescript usage | ||
* @returns an array of suffixes to try to match a module to in order of priority | ||
*/ | ||
function getModuleSuffixes(platform, appendEmpty = true) { | ||
const extensions = platformExtensions(platform).map((ext) => `.${ext}`); | ||
if (appendEmpty) { | ||
extensions.push(""); | ||
} | ||
return extensions; | ||
} | ||
/** | ||
* Returns a map of available React Native platforms. The result is NOT cached. | ||
@@ -138,2 +175,10 @@ * @param startDir The directory to look for react-native platforms from | ||
/** | ||
* @returns the given string as a platform value or undefined if it is not a valid platform. | ||
*/ | ||
function tryParsePlatform(val) { | ||
return allValues.includes(val) | ||
? val | ||
: undefined; | ||
} | ||
/** | ||
* Parse a string to ensure it maps to a valid react-native platform. | ||
@@ -145,13 +190,14 @@ * | ||
function parsePlatform(val) { | ||
switch (val) { | ||
case "android": | ||
case "ios": | ||
case "macos": | ||
case "win32": | ||
case "windows": | ||
return val; | ||
default: | ||
throw new Error("Invalid platform '" + val + "'"); | ||
const platform = tryParsePlatform(val); | ||
if (!platform) { | ||
throw new Error(`Unknown platform '${val}'`); | ||
} | ||
return platform; | ||
} | ||
/** | ||
* @returns List of all supported react-native platforms. | ||
*/ | ||
function platformValues() { | ||
return allValues; | ||
} | ||
//# sourceMappingURL=platform.js.map |
{ | ||
"name": "@rnx-kit/tools-react-native", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "A collection of supplemental react-native functions and types", | ||
@@ -70,4 +70,4 @@ "homepage": "https://github.com/microsoft/rnx-kit/tree/main/packages/tools-react-native#readme", | ||
"devDependencies": { | ||
"@react-native-community/cli": "^14.0.0", | ||
"@react-native-community/cli-types": "^14.0.0", | ||
"@react-native-community/cli": "^15.0.0", | ||
"@react-native-community/cli-types": "^15.0.0", | ||
"@rnx-kit/eslint-config": "*", | ||
@@ -79,7 +79,7 @@ "@rnx-kit/scripts": "*", | ||
"eslint": "^9.0.0", | ||
"metro": "^0.80.3", | ||
"metro-config": "^0.80.3", | ||
"metro-core": "^0.80.3", | ||
"metro-resolver": "^0.80.3", | ||
"metro-source-map": "^0.80.0", | ||
"metro": "^0.81.0", | ||
"metro-config": "^0.81.0", | ||
"metro-core": "^0.81.0", | ||
"metro-resolver": "^0.81.0", | ||
"metro-source-map": "^0.81.0", | ||
"prettier": "^3.0.0", | ||
@@ -86,0 +86,0 @@ "typescript": "^5.0.0" |
@@ -27,16 +27,19 @@ # @rnx-kit/tools-react-native | ||
| Category | Function | Description | | ||
| -------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| context | `loadContext(projectRoot)` | Equivalent to calling `loadConfig()` from `@react-native-community/cli`, but the result is cached for faster subsequent accesses. | | ||
| context | `loadContextAsync(projectRoot)` | Equivalent to calling `loadConfigAsync()` (with fallback to `loadConfig()`) from `@react-native-community/cli`, but the result is cached for faster subsequent accesses. | | ||
| context | `resolveCommunityCLI(root, reactNativePath)` | Finds path to `@react-native-community/cli`. | | ||
| metro | `findMetroPath(projectRoot)` | Finds the installation path of Metro. | | ||
| metro | `getMetroVersion(projectRoot)` | Returns Metro version number. | | ||
| metro | `requireModuleFromMetro(moduleName, fromDir)` | Imports specified module starting from the installation directory of the currently used `metro` version. | | ||
| platform | `expandPlatformExtensions(platform, extensions)` | Returns a list of extensions that should be tried for the target platform in prioritized order. | | ||
| platform | `getAvailablePlatforms(startDir)` | Returns a map of available React Native platforms. The result is cached. | | ||
| platform | `getAvailablePlatformsUncached(startDir, platformMap)` | Returns a map of available React Native platforms. The result is NOT cached. | | ||
| platform | `parsePlatform(val)` | Parse a string to ensure it maps to a valid react-native platform. | | ||
| platform | `platformExtensions(platform)` | Returns file extensions that can be mapped to the target platform. | | ||
| Category | Function | Description | | ||
| -------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| context | `loadContext(projectRoot)` | Equivalent to calling `loadConfig()` from `@react-native-community/cli`, but the result is cached for faster subsequent accesses. | | ||
| context | `loadContextAsync(projectRoot)` | Equivalent to calling `loadConfigAsync()` (with fallback to `loadConfig()`) from `@react-native-community/cli`, but the result is cached for faster subsequent accesses. | | ||
| context | `resolveCommunityCLI(root, reactNativePath)` | Finds path to `@react-native-community/cli`. | | ||
| metro | `findMetroPath(projectRoot)` | Finds the installation path of Metro. | | ||
| metro | `getMetroVersion(projectRoot)` | Returns Metro version number. | | ||
| metro | `requireModuleFromMetro(moduleName, fromDir)` | Imports specified module starting from the installation directory of the currently used `metro` version. | | ||
| platform | `expandPlatformExtensions(platform, extensions)` | Returns a list of extensions that should be tried for the target platform in prioritized order. | | ||
| platform | `getAvailablePlatforms(startDir)` | Returns a map of available React Native platforms. The result is cached. | | ||
| platform | `getAvailablePlatformsUncached(startDir, platformMap)` | Returns a map of available React Native platforms. The result is NOT cached. | | ||
| platform | `getModuleSuffixes(platform, appendEmpty)` | Get the module suffixes array for a given platform, suitable for use with TypeScript's moduleSuffixes setting in the form of ['.ios', '.native', ''] or ['.windows', '.win', '.native', ''] or similar | | ||
| platform | `parsePlatform(val)` | Parse a string to ensure it maps to a valid react-native platform. | | ||
| platform | `platformExtensions(platform)` | Returns file extensions that can be mapped to the target platform. | | ||
| platform | `platformValues()` | | | ||
| platform | `tryParsePlatform(val)` | | | ||
<!-- @rnx-kit/api end --> |
@@ -16,5 +16,8 @@ export { | ||
getAvailablePlatformsUncached, | ||
getModuleSuffixes, | ||
parsePlatform, | ||
platformExtensions, | ||
platformValues, | ||
tryParsePlatform, | ||
} from "./platform"; | ||
export type { AllPlatforms } from "./platform"; |
@@ -9,4 +9,20 @@ import { findPackageDependencyDir } from "@rnx-kit/tools-node/package"; | ||
*/ | ||
export type AllPlatforms = "android" | "ios" | "macos" | "win32" | "windows"; | ||
export type AllPlatforms = | ||
| "android" | ||
| "ios" | ||
| "macos" | ||
| "win32" | ||
| "windows" | ||
| "visionos"; | ||
// Possible values for AllPlatforms | ||
const allValues: AllPlatforms[] = [ | ||
"android", | ||
"ios", | ||
"macos", | ||
"win32", | ||
"windows", | ||
"visionos", | ||
]; | ||
/** | ||
@@ -35,2 +51,21 @@ * Returns a list of extensions that should be tried for the target platform in | ||
/** | ||
* Get the module suffixes array for a given platform, suitable for use with TypeScript's moduleSuffixes setting | ||
* in the form of ['.ios', '.native', ''] or ['.windows', '.win', '.native', ''] or similar | ||
* | ||
* @param platform platform to get module suffixes for | ||
* @param appendEmpty finish the suffixes with an empty entry, required for typescript usage | ||
* @returns an array of suffixes to try to match a module to in order of priority | ||
*/ | ||
export function getModuleSuffixes( | ||
platform: AllPlatforms, | ||
appendEmpty = true | ||
): string[] { | ||
const extensions = platformExtensions(platform).map((ext) => `.${ext}`); | ||
if (appendEmpty) { | ||
extensions.push(""); | ||
} | ||
return extensions; | ||
} | ||
/** | ||
* Returns a map of available React Native platforms. The result is NOT cached. | ||
@@ -140,2 +175,11 @@ * @param startDir The directory to look for react-native platforms from | ||
/** | ||
* @returns the given string as a platform value or undefined if it is not a valid platform. | ||
*/ | ||
export function tryParsePlatform(val: string): AllPlatforms | undefined { | ||
return allValues.includes(val as AllPlatforms) | ||
? (val as AllPlatforms) | ||
: undefined; | ||
} | ||
/** | ||
* Parse a string to ensure it maps to a valid react-native platform. | ||
@@ -147,13 +191,14 @@ * | ||
export function parsePlatform(val: string): AllPlatforms { | ||
switch (val) { | ||
case "android": | ||
case "ios": | ||
case "macos": | ||
case "win32": | ||
case "windows": | ||
return val; | ||
default: | ||
throw new Error("Invalid platform '" + val + "'"); | ||
const platform = tryParsePlatform(val); | ||
if (!platform) { | ||
throw new Error(`Unknown platform '${val}'`); | ||
} | ||
return platform; | ||
} | ||
/** | ||
* @returns List of all supported react-native platforms. | ||
*/ | ||
export function platformValues(): readonly AllPlatforms[] { | ||
return allValues; | ||
} |
58206
12.31%1298
12.19%45
7.14%