Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 4 additions & 54 deletions android/autolink.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// @ts-check
import * as crypto from "node:crypto";
import { getCurrentState } from "@rnx-kit/tools-react-native/cache";
import { loadContext } from "@rnx-kit/tools-react-native/context";
import * as fs from "node:fs";
import * as path from "node:path";
import {
findFile,
isMain,
readJSONFile,
readTextFile,
requireTransitive,
writeTextFile,
} from "../scripts/helpers.js";

Expand All @@ -33,45 +32,6 @@ function ensureDirForFile(p) {
fs.mkdirSync(path.dirname(p), { recursive: true, mode: 0o755 });
}

/**
* @param {crypto.Hash} hash
* @param {string[]} files
* @param {string} projectRoot
* @param {"all" | "first-only"} mode
*/
function updateHash(hash, files, projectRoot, mode) {
for (const file of files) {
const p = findFile(file, projectRoot);
if (p) {
hash.update(fs.readFileSync(p));
if (mode === "first-only") {
break;
}
}
}
}

/**
* @param {string} projectRoot
* @returns {string}
*/
function getCurrentState(projectRoot) {
const sha2 = crypto.createHash("sha256");

const configFiles = ["package.json", "react-native.config.js"];
updateHash(sha2, configFiles, projectRoot, "all");

const lockfiles = [
"yarn.lock",
"package-lock.json",
"pnpm-lock.yaml",
"bun.lockb",
];
updateHash(sha2, lockfiles, projectRoot, "first-only");

return sha2.digest("hex");
}

/**
* @param {Config} config
* @returns {AndroidDependencies}
Expand Down Expand Up @@ -132,19 +92,9 @@ function loadConfig(json, projectRoot) {
return readJSONFile(json);
}

/** @type {import("@react-native-community/cli")} */
const { loadConfig } = requireTransitive(
["react-native", "@react-native-community/cli"],
projectRoot
);

// The signature of `loadConfig` changed in 14.0.0:
// https://github.com/react-native-community/cli/commit/b787c89edb781bb788576cd615d2974fc81402fc
const argc = loadConfig.length;
// @ts-expect-error TS2345: Argument of type X is not assignable to parameter of type Y
const config = loadConfig(argc === 1 ? { projectRoot } : projectRoot);

const config = loadContext(projectRoot);
const prunedConfig = pruneDependencies(config);

ensureDirForFile(json);
writeTextFile(json, JSON.stringify(prunedConfig, undefined, 2) + "\n");
writeTextFile(stateFile, state);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
},
"dependencies": {
"@rnx-kit/react-native-host": "^0.5.0",
"@rnx-kit/tools-react-native": "^2.0.0",
"ajv": "^8.0.0",
"cliui": "^8.0.0",
"fast-xml-parser": "^4.0.0",
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12380,6 +12380,7 @@ __metadata:
"@react-native-community/template": "npm:^0.75.0"
"@rnx-kit/eslint-plugin": "npm:^0.8.0"
"@rnx-kit/react-native-host": "npm:^0.5.0"
"@rnx-kit/tools-react-native": "npm:^2.0.0"
"@rnx-kit/tsconfig": "npm:^2.0.0"
"@types/js-yaml": "npm:^4.0.5"
"@types/mustache": "npm:^4.0.0"
Expand Down