@rnx-kit/cli 0.12.2 → 0.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/coverage/clover.xml +224 -188
- package/coverage/coverage-final.json +3 -3
- package/coverage/lcov-report/index.html +27 -27
- package/coverage/lcov-report/src/bundle/index.html +1 -1
- package/coverage/lcov-report/src/bundle/kit-config.ts.html +1 -1
- package/coverage/lcov-report/src/bundle/metro.ts.html +1 -1
- package/coverage/lcov-report/src/bundle/overrides.ts.html +1 -1
- package/coverage/lcov-report/src/copy-assets.ts.html +480 -111
- package/coverage/lcov-report/src/index.html +30 -30
- package/coverage/lcov-report/src/metro-config.ts.html +40 -22
- package/coverage/lcov-report/src/typescript/index.html +13 -13
- package/coverage/lcov-report/src/typescript/project-cache.ts.html +97 -16
- package/coverage/lcov.info +399 -335
- package/lib/copy-assets.d.ts +10 -1
- package/lib/copy-assets.d.ts.map +1 -1
- package/lib/copy-assets.js +111 -32
- package/lib/copy-assets.js.map +1 -1
- package/lib/metro-config.d.ts.map +1 -1
- package/lib/metro-config.js +17 -8
- package/lib/metro-config.js.map +1 -1
- package/lib/start.d.ts.map +1 -1
- package/lib/start.js +27 -8
- package/lib/start.js.map +1 -1
- package/lib/test.js +3 -6
- package/lib/test.js.map +1 -1
- package/lib/typescript/project-cache.d.ts +1 -1
- package/lib/typescript/project-cache.d.ts.map +1 -1
- package/lib/typescript/project-cache.js +26 -4
- package/lib/typescript/project-cache.js.map +1 -1
- package/package.json +1 -1
- package/src/copy-assets.ts +169 -46
- package/src/metro-config.ts +17 -11
- package/src/start.ts +48 -8
- package/src/test.ts +3 -3
- package/src/typescript/project-cache.ts +35 -8
- package/test/__mocks__/child_process.js +5 -0
- package/test/__mocks__/fs-extra.js +2 -0
- package/test/__mocks__/fs.js +19 -0
- package/test/copy-assets/assembleAarBundle.test.ts +306 -0
- package/test/{copy-assets.test.ts → copy-assets/copyAssets.test.ts} +3 -13
- package/test/copy-assets/helpers.ts +13 -0
package/package.json
CHANGED
package/src/copy-assets.ts
CHANGED
|
@@ -2,7 +2,11 @@ import type { Config as CLIConfig } from "@react-native-community/cli-types";
|
|
|
2
2
|
import { error, info, warn } from "@rnx-kit/console";
|
|
3
3
|
import { isNonEmptyArray } from "@rnx-kit/tools-language/array";
|
|
4
4
|
import type { PackageManifest } from "@rnx-kit/tools-node/package";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
findPackageDependencyDir,
|
|
7
|
+
findPackageDir,
|
|
8
|
+
readPackage,
|
|
9
|
+
} from "@rnx-kit/tools-node/package";
|
|
6
10
|
import type { AllPlatforms } from "@rnx-kit/tools-react-native";
|
|
7
11
|
import { parsePlatform } from "@rnx-kit/tools-react-native";
|
|
8
12
|
import { spawnSync } from "child_process";
|
|
@@ -11,9 +15,17 @@ import * as os from "os";
|
|
|
11
15
|
import * as path from "path";
|
|
12
16
|
|
|
13
17
|
export type AndroidArchive = {
|
|
14
|
-
targetName
|
|
18
|
+
targetName?: string;
|
|
15
19
|
version?: string;
|
|
16
20
|
output?: string;
|
|
21
|
+
android?: {
|
|
22
|
+
androidPluginVersion?: string;
|
|
23
|
+
compileSdkVersion?: number;
|
|
24
|
+
defaultConfig?: {
|
|
25
|
+
minSdkVersion?: number;
|
|
26
|
+
targetSdkVersion?: number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
17
29
|
};
|
|
18
30
|
|
|
19
31
|
export type NativeAssets = {
|
|
@@ -44,6 +56,15 @@ export type AssetsConfig = {
|
|
|
44
56
|
getAssets?: (context: Context) => Promise<NativeAssets>;
|
|
45
57
|
};
|
|
46
58
|
|
|
59
|
+
const defaultAndroidConfig: Required<Required<AndroidArchive>["android"]> = {
|
|
60
|
+
androidPluginVersion: "7.1.3",
|
|
61
|
+
compileSdkVersion: 31,
|
|
62
|
+
defaultConfig: {
|
|
63
|
+
minSdkVersion: 23,
|
|
64
|
+
targetSdkVersion: 29,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
47
68
|
function ensureOption(options: Options, opt: string, flag = opt) {
|
|
48
69
|
if (options[opt] == null) {
|
|
49
70
|
error(`Missing required option: --${flag}`);
|
|
@@ -61,6 +82,12 @@ function findGradleProject(projectRoot: string): string | undefined {
|
|
|
61
82
|
return undefined;
|
|
62
83
|
}
|
|
63
84
|
|
|
85
|
+
function gradleTargetName(packageName: string): string {
|
|
86
|
+
return (
|
|
87
|
+
packageName.startsWith("@") ? packageName.slice(1) : packageName
|
|
88
|
+
).replace(/[^\w\-.]+/g, "_");
|
|
89
|
+
}
|
|
90
|
+
|
|
64
91
|
function isAssetsConfig(config: unknown): config is AssetsConfig {
|
|
65
92
|
return typeof config === "object" && config !== null && "getAssets" in config;
|
|
66
93
|
}
|
|
@@ -70,7 +97,12 @@ function keysOf(record: Record<string, unknown> | undefined): string[] {
|
|
|
70
97
|
}
|
|
71
98
|
|
|
72
99
|
export function versionOf(pkgName: string): string {
|
|
73
|
-
const
|
|
100
|
+
const packageDir = findPackageDependencyDir(pkgName);
|
|
101
|
+
if (!packageDir) {
|
|
102
|
+
throw new Error(`Could not find module '${pkgName}'`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const { version } = readPackage(packageDir);
|
|
74
106
|
return version;
|
|
75
107
|
}
|
|
76
108
|
|
|
@@ -79,13 +111,19 @@ function getAndroidPaths(
|
|
|
79
111
|
packageName: string,
|
|
80
112
|
{ targetName, version, output }: AndroidArchive
|
|
81
113
|
) {
|
|
82
|
-
const projectRoot =
|
|
83
|
-
|
|
84
|
-
|
|
114
|
+
const projectRoot = findPackageDependencyDir(packageName);
|
|
115
|
+
if (!projectRoot) {
|
|
116
|
+
throw new Error(`Could not find module '${packageName}'`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const gradleFriendlyName = targetName || gradleTargetName(packageName);
|
|
120
|
+
const aarVersion = version || versionOf(packageName);
|
|
85
121
|
|
|
86
122
|
switch (packageName) {
|
|
87
123
|
case "hermes-engine":
|
|
88
124
|
return {
|
|
125
|
+
targetName: gradleFriendlyName,
|
|
126
|
+
version: aarVersion,
|
|
89
127
|
projectRoot,
|
|
90
128
|
output: path.join(projectRoot, "android", "hermes-release.aar"),
|
|
91
129
|
destination: path.join(
|
|
@@ -97,6 +135,8 @@ function getAndroidPaths(
|
|
|
97
135
|
|
|
98
136
|
case "react-native":
|
|
99
137
|
return {
|
|
138
|
+
targetName: gradleFriendlyName,
|
|
139
|
+
version: aarVersion,
|
|
100
140
|
projectRoot,
|
|
101
141
|
output: path.join(projectRoot, "android"),
|
|
102
142
|
destination: path.join(
|
|
@@ -109,6 +149,8 @@ function getAndroidPaths(
|
|
|
109
149
|
default: {
|
|
110
150
|
const androidProject = findGradleProject(projectRoot);
|
|
111
151
|
return {
|
|
152
|
+
targetName: gradleFriendlyName,
|
|
153
|
+
version: aarVersion,
|
|
112
154
|
projectRoot,
|
|
113
155
|
androidProject,
|
|
114
156
|
output:
|
|
@@ -119,19 +161,19 @@ function getAndroidPaths(
|
|
|
119
161
|
"build",
|
|
120
162
|
"outputs",
|
|
121
163
|
"aar",
|
|
122
|
-
`${
|
|
164
|
+
`${gradleFriendlyName}-release.aar`
|
|
123
165
|
)),
|
|
124
166
|
destination: path.join(
|
|
125
167
|
context.options.assetsDest,
|
|
126
168
|
"aar",
|
|
127
|
-
`${
|
|
169
|
+
`${gradleFriendlyName}-${aarVersion}.aar`
|
|
128
170
|
),
|
|
129
171
|
};
|
|
130
172
|
}
|
|
131
173
|
}
|
|
132
174
|
}
|
|
133
175
|
|
|
134
|
-
async function assembleAarBundle(
|
|
176
|
+
export async function assembleAarBundle(
|
|
135
177
|
context: Context,
|
|
136
178
|
packageName: string,
|
|
137
179
|
{ aar }: NativeAssets
|
|
@@ -149,55 +191,136 @@ async function assembleAarBundle(
|
|
|
149
191
|
return;
|
|
150
192
|
}
|
|
151
193
|
|
|
152
|
-
const { androidProject, output } = getAndroidPaths(
|
|
194
|
+
const { targetName, version, androidProject, output } = getAndroidPaths(
|
|
195
|
+
context,
|
|
196
|
+
packageName,
|
|
197
|
+
aar
|
|
198
|
+
);
|
|
153
199
|
if (!androidProject || !output) {
|
|
154
200
|
warn(`Skipped \`${packageName}\`: cannot find \`build.gradle\``);
|
|
155
201
|
return;
|
|
156
202
|
}
|
|
157
203
|
|
|
158
|
-
const {
|
|
204
|
+
const { env: customEnv, dependencies, android } = aar;
|
|
205
|
+
const env = {
|
|
206
|
+
NODE_MODULES_PATH: path.join(process.cwd(), "node_modules"),
|
|
207
|
+
REACT_NATIVE_VERSION: versionOf("react-native"),
|
|
208
|
+
...process.env,
|
|
209
|
+
...customEnv,
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const outputDir = path.join(context.options.assetsDest, "aar");
|
|
213
|
+
await fs.ensureDir(outputDir);
|
|
214
|
+
|
|
215
|
+
const dest = path.join(outputDir, `${targetName}-${version}.aar`);
|
|
216
|
+
|
|
159
217
|
const targets = [`:${targetName}:assembleRelease`];
|
|
160
|
-
const targetsToCopy: [string, string][] = [];
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
218
|
+
const targetsToCopy: [string, string][] = [[output, dest]];
|
|
219
|
+
|
|
220
|
+
const settings = path.join(androidProject, "settings.gradle");
|
|
221
|
+
if (fs.existsSync(settings)) {
|
|
222
|
+
if (dependencies) {
|
|
223
|
+
for (const [dependencyName, aar] of Object.entries(dependencies)) {
|
|
224
|
+
const { targetName, output, destination } = getAndroidPaths(
|
|
225
|
+
context,
|
|
226
|
+
dependencyName,
|
|
227
|
+
aar
|
|
228
|
+
);
|
|
229
|
+
if (output) {
|
|
230
|
+
if (!fs.existsSync(output)) {
|
|
231
|
+
targets.push(`:${targetName}:assembleRelease`);
|
|
232
|
+
targetsToCopy.push([output, destination]);
|
|
233
|
+
} else if (!fs.existsSync(destination)) {
|
|
234
|
+
targetsToCopy.push([output, destination]);
|
|
235
|
+
}
|
|
174
236
|
}
|
|
175
237
|
}
|
|
176
238
|
}
|
|
177
|
-
}
|
|
178
239
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
REACT_NATIVE_VERSION: versionOf("react-native"),
|
|
187
|
-
...process.env,
|
|
188
|
-
...env,
|
|
189
|
-
},
|
|
190
|
-
});
|
|
240
|
+
// Run only one Gradle task at a time
|
|
241
|
+
spawnSync(gradlew, targets, { cwd: androidProject, stdio: "inherit", env });
|
|
242
|
+
} else {
|
|
243
|
+
const reactNativePath = findPackageDependencyDir("react-native");
|
|
244
|
+
if (!reactNativePath) {
|
|
245
|
+
throw new Error("Could not find 'react-native'");
|
|
246
|
+
}
|
|
191
247
|
|
|
192
|
-
|
|
193
|
-
|
|
248
|
+
const buildDir = path.join(
|
|
249
|
+
process.cwd(),
|
|
250
|
+
"node_modules",
|
|
251
|
+
".rnx-gradle-build",
|
|
252
|
+
targetName
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
const compileSdkVersion =
|
|
256
|
+
android?.compileSdkVersion ?? defaultAndroidConfig.compileSdkVersion;
|
|
257
|
+
const minSdkVersion =
|
|
258
|
+
android?.defaultConfig?.minSdkVersion ??
|
|
259
|
+
defaultAndroidConfig.defaultConfig.minSdkVersion;
|
|
260
|
+
const targetSdkVersion =
|
|
261
|
+
android?.defaultConfig?.targetSdkVersion ??
|
|
262
|
+
defaultAndroidConfig.defaultConfig.targetSdkVersion;
|
|
263
|
+
const androidPluginVersion =
|
|
264
|
+
android?.androidPluginVersion ??
|
|
265
|
+
defaultAndroidConfig.androidPluginVersion;
|
|
266
|
+
const buildRelativeReactNativePath = path.relative(
|
|
267
|
+
buildDir,
|
|
268
|
+
reactNativePath
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
const buildGradle = [
|
|
272
|
+
"buildscript {",
|
|
273
|
+
" ext {",
|
|
274
|
+
` compileSdkVersion = ${compileSdkVersion}`,
|
|
275
|
+
` minSdkVersion = ${minSdkVersion}`,
|
|
276
|
+
` targetSdkVersion = ${targetSdkVersion}`,
|
|
277
|
+
` androidPluginVersion = "${androidPluginVersion}"`,
|
|
278
|
+
" }",
|
|
279
|
+
"",
|
|
280
|
+
" repositories {",
|
|
281
|
+
" mavenCentral()",
|
|
282
|
+
" google()",
|
|
283
|
+
" }",
|
|
284
|
+
"",
|
|
285
|
+
" dependencies {",
|
|
286
|
+
' classpath("com.android.tools.build:gradle:${project.ext.androidPluginVersion}")',
|
|
287
|
+
" }",
|
|
288
|
+
"}",
|
|
289
|
+
"",
|
|
290
|
+
"allprojects {",
|
|
291
|
+
" repositories {",
|
|
292
|
+
" maven {",
|
|
293
|
+
" // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm",
|
|
294
|
+
` url("\${rootDir}/${buildRelativeReactNativePath}/android")`,
|
|
295
|
+
" }",
|
|
296
|
+
" mavenCentral()",
|
|
297
|
+
" google()",
|
|
298
|
+
" }",
|
|
299
|
+
"}",
|
|
300
|
+
"",
|
|
301
|
+
].join("\n");
|
|
302
|
+
|
|
303
|
+
const gradleProperties = "android.useAndroidX=true\n";
|
|
304
|
+
|
|
305
|
+
const settingsGradle = [
|
|
306
|
+
`include(":${targetName}")`,
|
|
307
|
+
`project(":${targetName}").projectDir = file("${androidProject}")`,
|
|
308
|
+
"",
|
|
309
|
+
].join("\n");
|
|
310
|
+
|
|
311
|
+
await fs.ensureDir(buildDir);
|
|
312
|
+
await fs.writeFile(path.join(buildDir, "build.gradle"), buildGradle);
|
|
313
|
+
await fs.writeFile(
|
|
314
|
+
path.join(buildDir, "gradle.properties"),
|
|
315
|
+
gradleProperties
|
|
316
|
+
);
|
|
317
|
+
await fs.writeFile(path.join(buildDir, "settings.gradle"), settingsGradle);
|
|
318
|
+
|
|
319
|
+
// Run only one Gradle task at a time
|
|
320
|
+
spawnSync(gradlew, targets, { cwd: buildDir, stdio: "inherit", env });
|
|
321
|
+
}
|
|
194
322
|
|
|
195
|
-
|
|
196
|
-
const dest = path.join(destination, `${targetName}-${aarVersion}.aar`);
|
|
197
|
-
await Promise.all([
|
|
198
|
-
fs.copy(output, dest),
|
|
199
|
-
...targetsToCopy.map(([src, dest]) => fs.copy(src, dest)),
|
|
200
|
-
]);
|
|
323
|
+
await Promise.all(targetsToCopy.map(([src, dest]) => fs.copy(src, dest)));
|
|
201
324
|
}
|
|
202
325
|
|
|
203
326
|
async function copyFiles(files: unknown, destination: string): Promise<void> {
|
package/src/metro-config.ts
CHANGED
|
@@ -62,22 +62,28 @@ function createSerializerHook(options: TypeScriptValidationOptions) {
|
|
|
62
62
|
excludeNodeModules
|
|
63
63
|
);
|
|
64
64
|
|
|
65
|
-
//
|
|
65
|
+
// Try to map each file to a TypeScript project, and apply its delta operation.
|
|
66
|
+
// Some projects may not actually be TypeScript projects (ignore those).
|
|
66
67
|
const tsprojectsToValidate: Set<Project> = new Set();
|
|
67
68
|
adds.concat(updates).forEach((sourceFile) => {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
const projectInfo = projectCache.getProjectInfo(sourceFile, platform);
|
|
70
|
+
if (projectInfo) {
|
|
71
|
+
// This is a TypeScript project. Validate it.
|
|
72
|
+
const { tsproject, tssourceFiles } = projectInfo;
|
|
73
|
+
if (tssourceFiles.has(sourceFile)) {
|
|
74
|
+
tsproject.setFile(sourceFile);
|
|
75
|
+
tsprojectsToValidate.add(tsproject);
|
|
76
|
+
}
|
|
75
77
|
}
|
|
76
78
|
});
|
|
77
79
|
deletes.forEach((sourceFile) => {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
const projectInfo = projectCache.getProjectInfo(sourceFile, platform);
|
|
81
|
+
if (projectInfo) {
|
|
82
|
+
// This is a TypeScript project. Validate it.
|
|
83
|
+
const { tsproject } = projectInfo;
|
|
84
|
+
tsproject.removeFile(sourceFile);
|
|
85
|
+
tsprojectsToValidate.add(tsproject);
|
|
86
|
+
}
|
|
81
87
|
});
|
|
82
88
|
|
|
83
89
|
// Validate all projects which changed, printing all type errors.
|
package/src/start.ts
CHANGED
|
@@ -17,6 +17,19 @@ import { customizeMetroConfig } from "./metro-config";
|
|
|
17
17
|
import { getKitServerConfig } from "./serve/kit-config";
|
|
18
18
|
import type { TypeScriptValidationOptions } from "./types";
|
|
19
19
|
|
|
20
|
+
type DevServerMiddleware = ReturnType<
|
|
21
|
+
typeof CliServerApi["createDevServerMiddleware"]
|
|
22
|
+
>;
|
|
23
|
+
|
|
24
|
+
type DevServer = ReturnType<DevServerMiddleware["attachToServer"]>;
|
|
25
|
+
|
|
26
|
+
type DevServerMiddleware7 = Pick<DevServerMiddleware, "middleware"> & {
|
|
27
|
+
websocketEndpoints: unknown;
|
|
28
|
+
debuggerProxyEndpoint: DevServer["debuggerProxy"];
|
|
29
|
+
messageSocketEndpoint: DevServer["messageSocket"];
|
|
30
|
+
eventsSocketEndpoint: DevServer["eventsSocket"];
|
|
31
|
+
};
|
|
32
|
+
|
|
20
33
|
export type CLIStartOptions = {
|
|
21
34
|
host: string;
|
|
22
35
|
port: number;
|
|
@@ -44,6 +57,12 @@ function friendlyRequire<T>(module: string): T {
|
|
|
44
57
|
}
|
|
45
58
|
}
|
|
46
59
|
|
|
60
|
+
function hasWebsocketEndpoints(
|
|
61
|
+
devServer: DevServerMiddleware | DevServerMiddleware7
|
|
62
|
+
): devServer is DevServerMiddleware7 {
|
|
63
|
+
return !("attachToServer" in devServer);
|
|
64
|
+
}
|
|
65
|
+
|
|
47
66
|
export async function rnxStart(
|
|
48
67
|
_argv: Array<string>,
|
|
49
68
|
cliConfig: CLIConfig,
|
|
@@ -136,11 +155,12 @@ export async function rnxStart(
|
|
|
136
155
|
|
|
137
156
|
// create middleware -- a collection of plugins which handle incoming
|
|
138
157
|
// http(s) requests, routing them to static pages or JS functions.
|
|
139
|
-
const
|
|
158
|
+
const devServer = createDevServerMiddleware({
|
|
140
159
|
host: cliOptions.host,
|
|
141
160
|
port: metroConfig.server.port,
|
|
142
161
|
watchFolders: metroConfig.watchFolders,
|
|
143
162
|
});
|
|
163
|
+
const middleware = devServer.middleware;
|
|
144
164
|
middleware.use(indexPageMiddleware);
|
|
145
165
|
|
|
146
166
|
// merge the Metro config middleware with our middleware
|
|
@@ -158,17 +178,37 @@ export async function rnxStart(
|
|
|
158
178
|
);
|
|
159
179
|
};
|
|
160
180
|
|
|
181
|
+
// `createDevServerMiddleware` changed its return type in
|
|
182
|
+
// https://github.com/react-native-community/cli/pull/1560
|
|
183
|
+
let websocketEndpoints: unknown = undefined;
|
|
184
|
+
let messageSocketEndpoint: DevServer["messageSocket"];
|
|
185
|
+
|
|
186
|
+
if (hasWebsocketEndpoints(devServer)) {
|
|
187
|
+
websocketEndpoints = devServer.websocketEndpoints;
|
|
188
|
+
messageSocketEndpoint = devServer.messageSocketEndpoint;
|
|
189
|
+
|
|
190
|
+
// bind our `reportEvent` delegate to the Metro server
|
|
191
|
+
reportEventDelegate = devServer.eventsSocketEndpoint.reportEvent;
|
|
192
|
+
}
|
|
193
|
+
|
|
161
194
|
// start the Metro server
|
|
162
|
-
const
|
|
195
|
+
const serverOptions = {
|
|
163
196
|
host: cliOptions.host,
|
|
164
197
|
secure: cliOptions.https,
|
|
165
198
|
secureCert: cliOptions.cert,
|
|
166
199
|
secureKey: cliOptions.key,
|
|
167
|
-
|
|
168
|
-
|
|
200
|
+
websocketEndpoints,
|
|
201
|
+
};
|
|
202
|
+
const serverInstance = await startServer(metroConfig, serverOptions);
|
|
203
|
+
|
|
204
|
+
if (!hasWebsocketEndpoints(devServer)) {
|
|
205
|
+
const { messageSocket, eventsSocket } =
|
|
206
|
+
devServer.attachToServer(serverInstance);
|
|
207
|
+
messageSocketEndpoint = messageSocket;
|
|
169
208
|
|
|
170
|
-
|
|
171
|
-
|
|
209
|
+
// bind our `reportEvent` delegate to the Metro server
|
|
210
|
+
reportEventDelegate = eventsSocket.reportEvent;
|
|
211
|
+
}
|
|
172
212
|
|
|
173
213
|
// In Node 8, the default keep-alive for an HTTP connection is 5 seconds. In
|
|
174
214
|
// early versions of Node 8, this was implemented in a buggy way which caused
|
|
@@ -217,12 +257,12 @@ export async function rnxStart(
|
|
|
217
257
|
|
|
218
258
|
case "d":
|
|
219
259
|
terminal.log(chalk.green("Opening developer menu..."));
|
|
220
|
-
|
|
260
|
+
messageSocketEndpoint.broadcast("devMenu", undefined);
|
|
221
261
|
break;
|
|
222
262
|
|
|
223
263
|
case "r":
|
|
224
264
|
terminal.log(chalk.green("Reloading app..."));
|
|
225
|
-
|
|
265
|
+
messageSocketEndpoint.broadcast("reload", undefined);
|
|
226
266
|
break;
|
|
227
267
|
}
|
|
228
268
|
}
|
package/src/test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Config as CLIConfig } from "@react-native-community/cli-types";
|
|
2
|
+
import { findPackageDependencyDir } from "@rnx-kit/tools-node";
|
|
2
3
|
import { parsePlatform } from "@rnx-kit/tools-react-native/platform";
|
|
3
4
|
import { run as runJest } from "jest-cli";
|
|
4
|
-
import path from "path";
|
|
5
5
|
|
|
6
6
|
type Args = {
|
|
7
7
|
platform: "android" | "ios" | "macos" | "windows" | "win32";
|
|
@@ -54,8 +54,8 @@ function jestOptions(): Options[] {
|
|
|
54
54
|
//
|
|
55
55
|
// To work around this, resolve `jest-cli` first, then use the resolved path
|
|
56
56
|
// to import `./build/cli/args`.
|
|
57
|
-
const jestPath =
|
|
58
|
-
const { options } = require(`${
|
|
57
|
+
const jestPath = findPackageDependencyDir("jest-cli") || "jest-cli";
|
|
58
|
+
const { options } = require(`${jestPath}/build/cli/args`);
|
|
59
59
|
|
|
60
60
|
return Object.keys(options).map((option) => {
|
|
61
61
|
const { default: defaultValue, description, type } = options[option];
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
Project,
|
|
10
10
|
readConfigFile,
|
|
11
11
|
} from "@rnx-kit/typescript-service";
|
|
12
|
+
import fs from "fs";
|
|
12
13
|
import path from "path";
|
|
13
14
|
import ts from "typescript";
|
|
14
15
|
|
|
@@ -44,7 +45,10 @@ export interface ProjectCache {
|
|
|
44
45
|
* @param sourceFile Source file
|
|
45
46
|
* @returns Project targeting the given platform and containing the given source file
|
|
46
47
|
*/
|
|
47
|
-
getProjectInfo(
|
|
48
|
+
getProjectInfo(
|
|
49
|
+
sourceFile: string,
|
|
50
|
+
platform: AllPlatforms
|
|
51
|
+
): ProjectInfo | undefined;
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
/**
|
|
@@ -84,8 +88,19 @@ export function createProjectCache(
|
|
|
84
88
|
return root;
|
|
85
89
|
}
|
|
86
90
|
|
|
87
|
-
function readTSConfig(root: string): ts.ParsedCommandLine {
|
|
91
|
+
function readTSConfig(root: string): ts.ParsedCommandLine | undefined {
|
|
88
92
|
const configFileName = path.join(root, "tsconfig.json");
|
|
93
|
+
if (!fs.existsSync(configFileName)) {
|
|
94
|
+
// Allow for packages that aren't TypeScript.
|
|
95
|
+
//
|
|
96
|
+
// Example: Users who enable bundling with all the config defaults will
|
|
97
|
+
// have type validation enabled automatically. They may not actually be
|
|
98
|
+
// using TypeScript.
|
|
99
|
+
//
|
|
100
|
+
// We shouldn't break them. We should use TS validation only for TS packages.
|
|
101
|
+
//
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
89
104
|
|
|
90
105
|
const cmdLine = readConfigFile(configFileName);
|
|
91
106
|
if (!cmdLine) {
|
|
@@ -102,9 +117,13 @@ export function createProjectCache(
|
|
|
102
117
|
function createProjectInfo(
|
|
103
118
|
root: string,
|
|
104
119
|
platform: AllPlatforms
|
|
105
|
-
): ProjectInfo {
|
|
120
|
+
): ProjectInfo | undefined {
|
|
106
121
|
// Load the TypeScript configuration file for this project.
|
|
107
122
|
const cmdLine = readTSConfig(root);
|
|
123
|
+
if (!cmdLine) {
|
|
124
|
+
// Not a TypeScript project
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
108
127
|
|
|
109
128
|
// Trim down the list of source files found by TypeScript. This ensures
|
|
110
129
|
// that only explicitly added files are loaded and parsed by TypeScript.
|
|
@@ -151,15 +170,23 @@ export function createProjectCache(
|
|
|
151
170
|
function getProjectInfo(
|
|
152
171
|
sourceFile: string,
|
|
153
172
|
platform: AllPlatforms
|
|
154
|
-
): ProjectInfo {
|
|
173
|
+
): ProjectInfo | undefined {
|
|
155
174
|
const root = findProjectRoot(sourceFile);
|
|
156
175
|
projects[root] ||= {};
|
|
157
176
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
177
|
+
const platforms = projects[root];
|
|
178
|
+
|
|
179
|
+
// Have we seen the project/platform for this source file before,
|
|
180
|
+
// even if what we saw is 'undefined' (e.g. not a TS project)?
|
|
181
|
+
if (Object.prototype.hasOwnProperty.call(platforms, platform)) {
|
|
182
|
+
return platforms[platform];
|
|
162
183
|
}
|
|
184
|
+
|
|
185
|
+
// We haven't seen this project/platform before. Try to load it,
|
|
186
|
+
// even if it isn't a TS project. Cache the result so we don't
|
|
187
|
+
// do this again.
|
|
188
|
+
const info = createProjectInfo(root, platform);
|
|
189
|
+
platforms[platform] = info;
|
|
163
190
|
return info;
|
|
164
191
|
}
|
|
165
192
|
|
|
@@ -14,7 +14,9 @@ fs.__toJSON = () => vol.toJSON();
|
|
|
14
14
|
|
|
15
15
|
fs.copy = (...args) => vol.promises.copyFile(...args);
|
|
16
16
|
fs.ensureDir = (dir) => vol.promises.mkdir(dir, { recursive: true });
|
|
17
|
+
fs.existsSync = (...args) => vol.existsSync(...args);
|
|
17
18
|
fs.pathExists = (...args) => Promise.resolve(vol.existsSync(...args));
|
|
18
19
|
fs.readFile = (...args) => vol.promises.readFile(...args);
|
|
20
|
+
fs.writeFile = (...args) => vol.promises.writeFile(...args);
|
|
19
21
|
|
|
20
22
|
module.exports = fs;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const fs = jest.createMockFromModule("fs");
|
|
2
|
+
|
|
3
|
+
const { vol } = require("memfs");
|
|
4
|
+
|
|
5
|
+
/** @type {(newMockFiles: { [filename: string]: string }) => void} */
|
|
6
|
+
fs.__setMockFiles = (files) => {
|
|
7
|
+
vol.reset();
|
|
8
|
+
vol.fromJSON(files);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
fs.__toJSON = () => vol.toJSON();
|
|
12
|
+
|
|
13
|
+
fs.lstat = (...args) => Promise.resolve(vol.lstat(...args));
|
|
14
|
+
fs.lstatSync = (...args) => vol.lstatSync(...args);
|
|
15
|
+
fs.readFileSync = (...args) => vol.readFileSync(...args);
|
|
16
|
+
fs.stat = (...args) => Promise.resolve(vol.stat(...args));
|
|
17
|
+
fs.statSync = (...args) => vol.statSync(...args);
|
|
18
|
+
|
|
19
|
+
module.exports = fs;
|