Skip to content

Commit de3c5df

Browse files
authored
fix(android): support ESM config files (#2323)
1 parent 5f83f8e commit de3c5df

25 files changed

+56
-316
lines changed

.github/actions/setup-toolchain/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ runs:
7272
- name: Set up Node.js
7373
uses: actions/[email protected]
7474
with:
75-
node-version: "20"
75+
node-version: "22"
7676
cache: ${{ inputs.cache-npm-dependencies }}
7777
- name: Set up Xcode
7878
if: ${{ inputs.xcode-developer-dir != '' }}

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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@
8181
"postpack": "node scripts/internal/pack.mjs post",
8282
"release-notes": "node scripts/internal/release-notes.mjs",
8383
"set-react-version": "node scripts/internal/set-react-version.mjs",
84-
"show-affected": "node --import tsx scripts/build/affected.ts",
84+
"show-affected": "node --experimental-transform-types --no-warnings scripts/build/affected.ts",
8585
"test": "node scripts/internal/test.mjs",
86-
"test:js": "node --import tsx --test $(git ls-files '*.test.ts')",
86+
"test:js": "node --experimental-transform-types --no-warnings --test $(git ls-files '*.test.ts')",
8787
"test:matrix": "node scripts/testing/test-matrix.mjs",
8888
"test:rb": "bundle exec ruby -Ilib:test -e \"Dir.glob('./test/test_*.rb').each { |file| require(file) }\""
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",
@@ -146,7 +146,6 @@
146146
"react-native-windows": "^0.75.0",
147147
"semantic-release": "^24.0.0",
148148
"suggestion-bot": "^3.0.0",
149-
"tsx": "^4.16.2",
150149
"typescript": "^5.0.0"
151150
},
152151
"engines": {

scripts/internal/test.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ switch (getTarget(input)) {
3131
break;
3232
case "typescript":
3333
testWith(process.argv0, [
34-
"--import",
35-
"tsx",
34+
"--experimental-transform-types",
35+
"--no-warnings",
3636
"--test",
3737
"--experimental-test-coverage",
3838
...input,

test/android/gradle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import * as path from "node:path";
66
import { URL, fileURLToPath } from "node:url";
77
import { gatherConfig, writeAllFiles } from "../../scripts/configure.mjs";
88
import { findNearest, readJSONFile } from "../../scripts/helpers.js";
9-
import type { ConfigureParams } from "../../scripts/types.js";
10-
import { templatePath } from "../template.js";
9+
import type { ConfigureParams } from "../../scripts/types.ts";
10+
import { templatePath } from "../template.ts";
1111

1212
const GRADLE_TEST_TASK = "nodeTest";
1313
const MKDIR_OPTIONS = { recursive: true, mode: 0o755 };

test/android/test-app-util.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
reactNativeVersion,
77
removeProject,
88
runGradleWithProject,
9-
} from "./gradle.js";
9+
} from "./gradle.ts";
1010

1111
describe("test-app-util.gradle", () => {
1212
const defaultTestProject = "TestAppUtilTest";

test/configure/gatherConfig.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { describe, it } from "node:test";
33
import { gatherConfig as gatherConfigActual } from "../../scripts/configure.mjs";
44
import { readTextFile } from "../../scripts/helpers.js";
55
import { join } from "../../scripts/template.mjs";
6-
import type { Configuration, ConfigureParams } from "../../scripts/types.js";
7-
import { templatePath } from "../template.js";
8-
import { mockParams } from "./mockParams.js";
6+
import type { Configuration, ConfigureParams } from "../../scripts/types.ts";
7+
import { templatePath } from "../template.ts";
8+
import { mockParams } from "./mockParams.ts";
99

1010
describe("gatherConfig()", () => {
1111
const templateDir = templatePath.substring(

test/configure/getAppName.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { equal } from "node:assert/strict";
22
import { afterEach, describe, it } from "node:test";
33
import { getAppName as getAppNameActual } from "../../scripts/configure.mjs";
4-
import { fs, setMockFiles } from "../fs.mock.js";
4+
import { fs, setMockFiles } from "../fs.mock.ts";
55

66
describe("getAppName()", () => {
77
const getAppName: typeof getAppNameActual = (p) => getAppNameActual(p, fs);

test/configure/getConfig.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
getConfig as getConfigActual,
66
getPlatformPackage,
77
} from "../../scripts/configure.mjs";
8-
import type { ConfigureParams, Platform } from "../../scripts/types.js";
9-
import { templatePath } from "../template.js";
10-
import { mockParams } from "./mockParams.js";
8+
import type { ConfigureParams, Platform } from "../../scripts/types.ts";
9+
import { templatePath } from "../template.ts";
10+
import { mockParams } from "./mockParams.ts";
1111

1212
describe("getConfig()", () => {
1313
const getConfig: typeof getConfigActual = (params, platform) =>

test/configure/isDestructive.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { equal, ok } from "node:assert/strict";
22
import { afterEach, describe, it } from "node:test";
33
import { isDestructive as isDestructiveActual } from "../../scripts/configure.mjs";
4-
import { fs, setMockFiles } from "../fs.mock.js";
4+
import { fs, setMockFiles } from "../fs.mock.ts";
55

66
describe("isDestructive()", () => {
77
/**

0 commit comments

Comments
 (0)