Skip to content

Commit 2d4f683

Browse files
committed
fix(android): support ESM config files
1 parent 5f83f8e commit 2d4f683

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

android/autolink.mjs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22
import { getCurrentState } from "@rnx-kit/tools-react-native/cache";
3-
import { loadContext } from "@rnx-kit/tools-react-native/context";
3+
import { loadContextAsync } from "@rnx-kit/tools-react-native";
44
import * as fs from "node:fs";
55
import * as path from "node:path";
66
import {
@@ -83,16 +83,16 @@ export function pruneDependencies(config) {
8383
/**
8484
* @param {string} json
8585
* @param {string} projectRoot
86-
* @returns {Config}
86+
* @returns {Promise<Config>}
8787
*/
88-
function loadConfig(json, projectRoot) {
88+
async function loadConfig(json, projectRoot) {
8989
const state = getCurrentState(projectRoot);
9090
const stateFile = json.substring(0, json.length - "json".length) + "sha256";
9191
if (fs.existsSync(stateFile) && readTextFile(stateFile) === state) {
9292
return readJSONFile(json);
9393
}
9494

95-
const config = loadContext(projectRoot);
95+
const config = await loadContextAsync(projectRoot);
9696
const prunedConfig = pruneDependencies(config);
9797

9898
ensureDirForFile(json);
@@ -101,10 +101,13 @@ function loadConfig(json, projectRoot) {
101101
return prunedConfig;
102102
}
103103

104-
if (isMain(import.meta.url)) {
105-
const [, , projectRoot = process.cwd(), output] = process.argv;
106-
107-
const config = loadConfig(
104+
/**
105+
* @param {string} projectRoot
106+
* @param {string} output
107+
* @returns {Promise<void>}
108+
*/
109+
async function main(projectRoot, output) {
110+
const config = await loadConfig(
108111
output.replace(
109112
/[/\\]app[/\\]build[/\\]generated[/\\]rnta[/\\]/,
110113
"/build/generated/autolinking/"
@@ -121,3 +124,8 @@ if (isMain(import.meta.url)) {
121124
writeTextFile(output, json + "\n");
122125
}
123126
}
127+
128+
if (isMain(import.meta.url)) {
129+
const [, , projectRoot = process.cwd(), output = ""] = process.argv;
130+
await main(projectRoot, output);
131+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
},
9090
"dependencies": {
9191
"@rnx-kit/react-native-host": "^0.5.0",
92-
"@rnx-kit/tools-react-native": "^2.0.0",
92+
"@rnx-kit/tools-react-native": "^2.0.1",
9393
"ajv": "^8.0.0",
9494
"cliui": "^8.0.0",
9595
"fast-xml-parser": "^4.0.0",

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,12 +3352,12 @@ __metadata:
33523352
languageName: node
33533353
linkType: hard
33543354

3355-
"@rnx-kit/tools-react-native@npm:^2.0.0":
3356-
version: 2.0.0
3357-
resolution: "@rnx-kit/tools-react-native@npm:2.0.0"
3355+
"@rnx-kit/tools-react-native@npm:^2.0.0, @rnx-kit/tools-react-native@npm:^2.0.1":
3356+
version: 2.0.1
3357+
resolution: "@rnx-kit/tools-react-native@npm:2.0.1"
33583358
dependencies:
33593359
"@rnx-kit/tools-node": "npm:^3.0.0"
3360-
checksum: 10c0/859ababb03313d6130b4eaa91fc6a9ec2fd97edec7e30a8fecf82491050e65eae3c1865950613cca87d0d78fff530fd8d72e85bd3a57b45151825f7c357abd48
3360+
checksum: 10c0/55ec8ea8c279b994da7d4411e216d0d7ed643d817f4f87271606a8f11fb4eebfa596c17dc2effb188a94769b754bc590d3ed1e48724edf9f7d1e5d24c7e06379
33613361
languageName: node
33623362
linkType: hard
33633363

@@ -12206,7 +12206,7 @@ __metadata:
1220612206
"@react-native-community/template": "npm:^0.75.0"
1220712207
"@rnx-kit/eslint-plugin": "npm:^0.8.0"
1220812208
"@rnx-kit/react-native-host": "npm:^0.5.0"
12209-
"@rnx-kit/tools-react-native": "npm:^2.0.0"
12209+
"@rnx-kit/tools-react-native": "npm:^2.0.1"
1221012210
"@rnx-kit/tsconfig": "npm:^2.0.0"
1221112211
"@types/js-yaml": "npm:^4.0.5"
1221212212
"@types/mustache": "npm:^4.0.0"

0 commit comments

Comments
 (0)