@rnx-kit/cli 0.12.0 → 0.12.3
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 +20 -0
- package/README.md +21 -21
- package/coverage/clover.xml +158 -131
- package/coverage/coverage-final.json +2 -2
- package/coverage/lcov-report/index.html +20 -20
- package/coverage/lcov-report/src/bundle/index.html +1 -1
- package/coverage/lcov-report/src/bundle/kit-config.ts.html +13 -13
- package/coverage/lcov-report/src/bundle/metro.ts.html +2 -2
- package/coverage/lcov-report/src/bundle/overrides.ts.html +4 -4
- package/coverage/lcov-report/src/copy-assets.ts.html +483 -114
- package/coverage/lcov-report/src/index.html +21 -21
- package/coverage/lcov-report/src/metro-config.ts.html +4 -4
- package/coverage/lcov-report/src/typescript/index.html +1 -1
- package/coverage/lcov-report/src/typescript/project-cache.ts.html +1 -1
- package/coverage/lcov.info +289 -242
- package/lib/bundle/metro.js +1 -1
- package/lib/bundle/metro.js.map +1 -1
- package/lib/bundle/overrides.d.ts +1 -1
- package/lib/bundle/overrides.d.ts.map +1 -1
- package/lib/bundle/overrides.js +2 -2
- package/lib/bundle/overrides.js.map +1 -1
- package/lib/bundle.d.ts +1 -0
- package/lib/bundle.d.ts.map +1 -1
- package/lib/bundle.js +8 -0
- package/lib/bundle.js.map +1 -1
- package/lib/clean.d.ts.map +1 -1
- package/lib/clean.js +40 -18
- package/lib/clean.js.map +1 -1
- package/lib/copy-assets.d.ts +11 -1
- package/lib/copy-assets.d.ts.map +1 -1
- package/lib/copy-assets.js +112 -32
- package/lib/copy-assets.js.map +1 -1
- package/lib/metro-config.d.ts +2 -2
- package/lib/metro-config.d.ts.map +1 -1
- package/lib/metro-config.js +3 -3
- package/lib/metro-config.js.map +1 -1
- package/lib/start.js +1 -1
- package/lib/start.js.map +1 -1
- package/lib/test.js +3 -6
- package/lib/test.js.map +1 -1
- package/package.json +1 -1
- package/react-native.config.js +6 -1
- package/src/bundle/metro.ts +1 -1
- package/src/bundle/overrides.ts +3 -3
- package/src/bundle.ts +13 -1
- package/src/clean.ts +6 -7
- package/src/copy-assets.ts +170 -47
- package/src/metro-config.ts +3 -3
- package/src/start.ts +1 -1
- package/src/test.ts +3 -3
- 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/bundle/kit-config.test.ts +23 -1
- package/test/bundle/metro.test.ts +1 -1
- package/test/bundle/overrides.test.ts +3 -13
- package/test/copy-assets/assembleAarBundle.test.ts +306 -0
- package/test/{copy-assets.test.ts → copy-assets/copyAssets.test.ts} +13 -13
- package/test/copy-assets/helpers.ts +13 -0
package/react-native.config.js
CHANGED
|
@@ -69,7 +69,12 @@ module.exports = {
|
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
71
|
name: "--experimental-tree-shake [boolean]",
|
|
72
|
-
description: "
|
|
72
|
+
description: "Deprecated. Use --tree-shake [boolean] instead.",
|
|
73
|
+
parse: parseBoolean,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "--tree-shake [boolean]",
|
|
77
|
+
description: "Enable tree shaking.",
|
|
73
78
|
parse: parseBoolean,
|
|
74
79
|
},
|
|
75
80
|
{
|
package/src/bundle/metro.ts
CHANGED
|
@@ -75,7 +75,7 @@ export async function metroBundle(
|
|
|
75
75
|
bundleConfig.detectCyclicDependencies,
|
|
76
76
|
bundleConfig.detectDuplicateDependencies,
|
|
77
77
|
bundleConfig.typescriptValidation ? typescriptValidationOptions : false,
|
|
78
|
-
bundleConfig.
|
|
78
|
+
bundleConfig.treeShake
|
|
79
79
|
);
|
|
80
80
|
|
|
81
81
|
const metroBundleArgs = createMetroBundleArgs(bundleConfig);
|
package/src/bundle/overrides.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type KitBundleConfigOverrides = {
|
|
|
10
10
|
bundleEncoding?: BundleArgs["bundleEncoding"];
|
|
11
11
|
sourcemapOutput?: string;
|
|
12
12
|
sourcemapSourcesRoot?: string;
|
|
13
|
-
|
|
13
|
+
treeShake?: boolean;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -33,7 +33,7 @@ export function applyKitBundleConfigOverrides(
|
|
|
33
33
|
"bundleEncoding",
|
|
34
34
|
"sourcemapOutput",
|
|
35
35
|
"sourcemapSourcesRoot",
|
|
36
|
-
"
|
|
36
|
+
"treeShake",
|
|
37
37
|
],
|
|
38
38
|
[
|
|
39
39
|
"entryPath",
|
|
@@ -43,7 +43,7 @@ export function applyKitBundleConfigOverrides(
|
|
|
43
43
|
"bundleEncoding",
|
|
44
44
|
"sourcemapOutput",
|
|
45
45
|
"sourcemapSourcesRoot",
|
|
46
|
-
"
|
|
46
|
+
"treeShake",
|
|
47
47
|
]
|
|
48
48
|
);
|
|
49
49
|
if (overridesToApply) {
|
package/src/bundle.ts
CHANGED
|
@@ -17,7 +17,8 @@ export type CLIBundleOptions = {
|
|
|
17
17
|
bundleEncoding?: BundleArgs["bundleEncoding"];
|
|
18
18
|
dev: boolean;
|
|
19
19
|
minify?: boolean;
|
|
20
|
-
experimentalTreeShake?: boolean;
|
|
20
|
+
experimentalTreeShake?: boolean; // Deprecated
|
|
21
|
+
treeShake?: boolean;
|
|
21
22
|
maxWorkers?: number;
|
|
22
23
|
sourcemapOutput?: string;
|
|
23
24
|
sourcemapSourcesRoot?: string;
|
|
@@ -30,6 +31,17 @@ export async function rnxBundle(
|
|
|
30
31
|
cliConfig: CLIConfig,
|
|
31
32
|
cliOptions: CLIBundleOptions
|
|
32
33
|
): Promise<void> {
|
|
34
|
+
// experimentalTreeShake is deprecated. Only use it when treeShake is not specified.
|
|
35
|
+
if (cliOptions.experimentalTreeShake !== undefined) {
|
|
36
|
+
console.warn(
|
|
37
|
+
"Warning: The command-line parameter '--experimental-tree-shake' is deprecated. Use `--tree-shake` instead."
|
|
38
|
+
);
|
|
39
|
+
if (cliOptions.treeShake === undefined) {
|
|
40
|
+
cliOptions.treeShake = cliOptions.experimentalTreeShake;
|
|
41
|
+
}
|
|
42
|
+
delete cliOptions.experimentalTreeShake;
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
const metroConfig = await loadMetroConfig(cliConfig, cliOptions);
|
|
34
46
|
|
|
35
47
|
const kitBundleConfigs = getKitBundleConfigs(
|
package/src/clean.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { Config as CLIConfig } from "@react-native-community/cli-types";
|
|
2
2
|
import { spawn } from "child_process";
|
|
3
|
-
import
|
|
4
|
-
import fs from "fs/promises";
|
|
3
|
+
import * as fs from "fs-extra";
|
|
5
4
|
import ora from "ora";
|
|
6
|
-
import os from "os";
|
|
7
|
-
import path from "path";
|
|
5
|
+
import * as os from "os";
|
|
6
|
+
import * as path from "path";
|
|
8
7
|
|
|
9
8
|
type Args = {
|
|
10
9
|
include?: string;
|
|
@@ -27,7 +26,7 @@ export async function rnxClean(
|
|
|
27
26
|
cliOptions: Args
|
|
28
27
|
): Promise<void> {
|
|
29
28
|
const projectRoot = cliOptions.projectRoot ?? process.cwd();
|
|
30
|
-
if (!
|
|
29
|
+
if (!fs.existsSync(projectRoot)) {
|
|
31
30
|
throw new Error(`Invalid path provided! ${projectRoot}`);
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -152,7 +151,7 @@ export async function rnxClean(
|
|
|
152
151
|
}
|
|
153
152
|
|
|
154
153
|
function cleanDir(path: string): Promise<void> {
|
|
155
|
-
if (!
|
|
154
|
+
if (!fs.existsSync(path)) {
|
|
156
155
|
return Promise.resolve();
|
|
157
156
|
}
|
|
158
157
|
|
|
@@ -163,7 +162,7 @@ function findPath(startPath: string, files: string[]): string | undefined {
|
|
|
163
162
|
// TODO: Find project files via `@react-native-community/cli`
|
|
164
163
|
for (const file of files) {
|
|
165
164
|
const filename = path.resolve(startPath, file);
|
|
166
|
-
if (
|
|
165
|
+
if (fs.existsSync(filename)) {
|
|
167
166
|
return filename;
|
|
168
167
|
}
|
|
169
168
|
}
|
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
|
}
|
|
@@ -69,8 +96,13 @@ function keysOf(record: Record<string, unknown> | undefined): string[] {
|
|
|
69
96
|
return record ? Object.keys(record) : [];
|
|
70
97
|
}
|
|
71
98
|
|
|
72
|
-
function versionOf(pkgName: string): string {
|
|
73
|
-
const
|
|
99
|
+
export function versionOf(pkgName: string): string {
|
|
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
|
@@ -109,14 +109,14 @@ const emptySerializerHook = (_graph: Graph, _delta: DeltaResult): void => {
|
|
|
109
109
|
* @param detectCyclicDependencies When true, cyclic dependency checking is enabled with a default set of options. Otherwise the object allows for fine-grained control over the detection process.
|
|
110
110
|
* @param detectDuplicateDependencies When true, duplicate dependency checking is enabled with a default set of options. Otherwise, the object allows for fine-grained control over the detection process.
|
|
111
111
|
* @param typescriptValidation When true, TypeScript type-checking is enabled with a default set of options. Otherwise, the object allows for fine-grained control over the type-checking process.
|
|
112
|
-
* @param
|
|
112
|
+
* @param treeShake When true, tree shaking is enabled.
|
|
113
113
|
*/
|
|
114
114
|
export function customizeMetroConfig(
|
|
115
115
|
metroConfigReadonly: InputConfigT,
|
|
116
116
|
detectCyclicDependencies: boolean | CyclicDetectorOptions,
|
|
117
117
|
detectDuplicateDependencies: boolean | DuplicateDetectorOptions,
|
|
118
118
|
typescriptValidation: boolean | TypeScriptValidationOptions,
|
|
119
|
-
|
|
119
|
+
treeShake: boolean
|
|
120
120
|
): void {
|
|
121
121
|
// We will be making changes to the Metro configuration. Coerce from a
|
|
122
122
|
// type with readonly props to a type where the props are writeable.
|
|
@@ -134,7 +134,7 @@ export function customizeMetroConfig(
|
|
|
134
134
|
plugins.push(CyclicDependencies());
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
if (
|
|
137
|
+
if (treeShake) {
|
|
138
138
|
metroConfig.serializer.customSerializer = MetroSerializerEsbuild(plugins);
|
|
139
139
|
Object.assign(metroConfig.transformer, esbuildTransformerConfig);
|
|
140
140
|
} else if (plugins.length > 0) {
|
package/src/start.ts
CHANGED
|
@@ -131,7 +131,7 @@ export async function rnxStart(
|
|
|
131
131
|
serverConfig.detectCyclicDependencies,
|
|
132
132
|
serverConfig.detectDuplicateDependencies,
|
|
133
133
|
serverConfig.typescriptValidation ? typescriptValidationOptions : false,
|
|
134
|
-
serverConfig.
|
|
134
|
+
serverConfig.treeShake
|
|
135
135
|
);
|
|
136
136
|
|
|
137
137
|
// create middleware -- a collection of plugins which handle incoming
|
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];
|
|
@@ -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;
|
|
@@ -80,7 +80,7 @@ describe("CLI > Bundle > Kit Config > getKitBundleConfigs", () => {
|
|
|
80
80
|
detectCyclicDependencies: true,
|
|
81
81
|
detectDuplicateDependencies: true,
|
|
82
82
|
typescriptValidation: true,
|
|
83
|
-
|
|
83
|
+
treeShake: true,
|
|
84
84
|
targets: ["ios", "android"],
|
|
85
85
|
platforms: {
|
|
86
86
|
ios: {
|
|
@@ -123,4 +123,26 @@ describe("CLI > Bundle > Kit Config > getKitBundleConfigs", () => {
|
|
|
123
123
|
platform: "android",
|
|
124
124
|
});
|
|
125
125
|
});
|
|
126
|
+
|
|
127
|
+
test("uses deprecated experimental_treeShake", () => {
|
|
128
|
+
const d: Record<string, unknown> = { ...definition };
|
|
129
|
+
delete d.treeShake;
|
|
130
|
+
d.experimental_treeShake = true;
|
|
131
|
+
rnxKitConfig.__setMockConfig({
|
|
132
|
+
bundle: {
|
|
133
|
+
...d,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
consoleWarnSpy.mockReset();
|
|
137
|
+
|
|
138
|
+
const kitBundleConfigs = getKitBundleConfigs(undefined, "ios");
|
|
139
|
+
expect(kitBundleConfigs[0].treeShake).toBe(true);
|
|
140
|
+
expect(consoleWarnSpy).toBeCalledTimes(1);
|
|
141
|
+
expect(consoleWarnSpy).toBeCalledWith(
|
|
142
|
+
expect.stringContaining("deprecated")
|
|
143
|
+
);
|
|
144
|
+
expect(consoleWarnSpy).toBeCalledWith(
|
|
145
|
+
expect.stringContaining("experimental_treeShake")
|
|
146
|
+
);
|
|
147
|
+
});
|
|
126
148
|
});
|
|
@@ -8,7 +8,7 @@ describe("CLI > Bundle > Metro > createMetroBundleArgs", () => {
|
|
|
8
8
|
detectCyclicDependencies: true,
|
|
9
9
|
detectDuplicateDependencies: true,
|
|
10
10
|
typescriptValidation: true,
|
|
11
|
-
|
|
11
|
+
treeShake: true,
|
|
12
12
|
entryPath: "out/entry.js",
|
|
13
13
|
distPath: "out",
|
|
14
14
|
assetsPath: "out/assets",
|
|
@@ -7,7 +7,7 @@ describe("CLI > Bundle > Overrides > applyKitBundleConfigOverrides", () => {
|
|
|
7
7
|
detectCyclicDependencies: true,
|
|
8
8
|
detectDuplicateDependencies: true,
|
|
9
9
|
typescriptValidation: true,
|
|
10
|
-
|
|
10
|
+
treeShake: true,
|
|
11
11
|
entryPath: "dist/index.js",
|
|
12
12
|
distPath: "dist",
|
|
13
13
|
assetsPath: "dist",
|
|
@@ -63,17 +63,7 @@ describe("CLI > Bundle > Overrides > applyKitBundleConfigOverrides", () => {
|
|
|
63
63
|
testOverride("sourcemapSourcesRoot", "out");
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
test("
|
|
67
|
-
|
|
68
|
-
applyKitBundleConfigOverrides(
|
|
69
|
-
{
|
|
70
|
-
experimentalTreeShake: true,
|
|
71
|
-
},
|
|
72
|
-
[copy]
|
|
73
|
-
);
|
|
74
|
-
expect(copy).toEqual({
|
|
75
|
-
...config,
|
|
76
|
-
experimental_treeShake: true,
|
|
77
|
-
});
|
|
66
|
+
test("changes treeShake using an override", () => {
|
|
67
|
+
testOverride("treeShake", true);
|
|
78
68
|
});
|
|
79
69
|
});
|