@rnx-kit/tools-react-native
Advanced tools
Comparing version 1.4.1 to 1.4.2
import type { Config } from "@react-native-community/cli-types"; | ||
import * as nodefs from "fs"; | ||
export declare function getCurrentState(projectRoot: string): string; | ||
export declare function getSavedState(projectRoot: string, fs?: typeof nodefs): string | false; | ||
export declare function loadConfigFromCache(projectRoot: string, fs?: typeof nodefs): Config | null; | ||
export declare function saveConfigToCache(projectRoot: string, state: string, config: Config, fs?: typeof nodefs): void; | ||
export declare function getSavedState(projectRoot: string, | ||
/** @internal */ fs?: typeof nodefs): string | false; | ||
export declare function invalidateState(projectRoot?: string, | ||
/** @internal */ fs?: typeof nodefs): void; | ||
export declare function loadConfigFromCache(projectRoot: string, | ||
/** @internal */ fs?: typeof nodefs): Config | null; | ||
export declare function saveConfigToCache(projectRoot: string, state: string, config: Config, | ||
/** @internal */ fs?: typeof nodefs): void; | ||
//# sourceMappingURL=cache.d.ts.map |
@@ -28,2 +28,3 @@ "use strict"; | ||
exports.getSavedState = getSavedState; | ||
exports.invalidateState = invalidateState; | ||
exports.loadConfigFromCache = loadConfigFromCache; | ||
@@ -37,3 +38,3 @@ exports.saveConfigToCache = saveConfigToCache; | ||
const UTF8 = { encoding: "utf-8" }; | ||
function ensureDir(p, fs = nodefs) { | ||
function ensureDir(p, /** @internal */ fs = nodefs) { | ||
fs.mkdirSync(p, { recursive: true, mode: 0o755 }); | ||
@@ -50,3 +51,4 @@ } | ||
} | ||
function updateHash(hash, files, projectRoot, mode, fs = nodefs) { | ||
function updateHash(hash, files, projectRoot, mode, | ||
/** @internal */ fs = nodefs) { | ||
const options = { startDir: projectRoot }; | ||
@@ -76,7 +78,14 @@ for (const file of files) { | ||
} | ||
function getSavedState(projectRoot, fs = nodefs) { | ||
function getSavedState(projectRoot, | ||
/** @internal */ fs = nodefs) { | ||
const stateFile = cacheStatePath(projectRoot); | ||
return fs.existsSync(stateFile) && fs.readFileSync(stateFile, UTF8); | ||
} | ||
function loadConfigFromCache(projectRoot, fs = nodefs) { | ||
function invalidateState(projectRoot = process.cwd(), | ||
/** @internal */ fs = nodefs) { | ||
fs.rmSync(configCachePath(projectRoot)); | ||
fs.rmSync(cacheStatePath(projectRoot)); | ||
} | ||
function loadConfigFromCache(projectRoot, | ||
/** @internal */ fs = nodefs) { | ||
const cacheFile = configCachePath(projectRoot); | ||
@@ -89,3 +98,4 @@ if (!fs.existsSync(cacheFile)) { | ||
} | ||
function saveConfigToCache(projectRoot, state, config, fs = nodefs) { | ||
function saveConfigToCache(projectRoot, state, config, | ||
/** @internal */ fs = nodefs) { | ||
const data = JSON.stringify(config); | ||
@@ -92,0 +102,0 @@ const configPath = configCachePath(projectRoot); |
{ | ||
"name": "@rnx-kit/tools-react-native", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"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": "^13.6.4", | ||
"@react-native-community/cli-types": "^13.6.4", | ||
"@react-native-community/cli": "^14.0.0", | ||
"@react-native-community/cli-types": "^14.0.0", | ||
"@rnx-kit/eslint-config": "*", | ||
@@ -74,0 +74,0 @@ "@rnx-kit/scripts": "*", |
@@ -10,3 +10,3 @@ import type { Config } from "@react-native-community/cli-types"; | ||
function ensureDir(p: string, fs = nodefs): void { | ||
function ensureDir(p: string, /** @internal */ fs = nodefs): void { | ||
fs.mkdirSync(p, { recursive: true, mode: 0o755 }); | ||
@@ -32,3 +32,3 @@ } | ||
mode: "all" | "first-only", | ||
fs = nodefs | ||
/** @internal */ fs = nodefs | ||
) { | ||
@@ -66,3 +66,3 @@ const options = { startDir: projectRoot }; | ||
projectRoot: string, | ||
fs = nodefs | ||
/** @internal */ fs = nodefs | ||
): string | false { | ||
@@ -73,5 +73,13 @@ const stateFile = cacheStatePath(projectRoot); | ||
export function invalidateState( | ||
projectRoot = process.cwd(), | ||
/** @internal */ fs = nodefs | ||
) { | ||
fs.rmSync(configCachePath(projectRoot)); | ||
fs.rmSync(cacheStatePath(projectRoot)); | ||
} | ||
export function loadConfigFromCache( | ||
projectRoot: string, | ||
fs = nodefs | ||
/** @internal */ fs = nodefs | ||
): Config | null { | ||
@@ -91,3 +99,3 @@ const cacheFile = configCachePath(projectRoot); | ||
config: Config, | ||
fs = nodefs | ||
/** @internal */ fs = nodefs | ||
): void { | ||
@@ -94,0 +102,0 @@ const data = JSON.stringify(config); |
45719
1020