@rnx-kit/cli 0.12.7 → 0.14.2
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 +117 -0
- package/README.md +90 -65
- package/coverage/clover.xml +92 -104
- package/coverage/coverage-final.json +7 -6
- package/coverage/lcov-report/index.html +29 -29
- package/coverage/lcov-report/src/bundle/index.html +29 -29
- package/coverage/lcov-report/src/bundle/kit-config.ts.html +63 -117
- package/coverage/lcov-report/src/bundle/metro.ts.html +40 -163
- package/coverage/lcov-report/src/bundle/overrides.ts.html +28 -58
- package/coverage/lcov-report/src/bundler-plugin-defaults.ts.html +115 -0
- package/coverage/lcov-report/src/copy-assets.ts.html +1 -1
- package/coverage/lcov-report/src/index.html +26 -11
- package/coverage/lcov-report/src/metro-config.ts.html +49 -31
- package/coverage/lcov-report/src/typescript/index.html +1 -1
- package/coverage/lcov-report/src/typescript/project-cache.ts.html +5 -5
- package/coverage/lcov.info +173 -193
- package/lib/bundle/kit-config.d.ts +9 -15
- package/lib/bundle/kit-config.d.ts.map +1 -1
- package/lib/bundle/kit-config.js +34 -43
- package/lib/bundle/kit-config.js.map +1 -1
- package/lib/bundle/metro.d.ts +7 -11
- package/lib/bundle/metro.d.ts.map +1 -1
- package/lib/bundle/metro.js +21 -59
- package/lib/bundle/metro.js.map +1 -1
- package/lib/bundle/overrides.d.ts +11 -9
- package/lib/bundle/overrides.d.ts.map +1 -1
- package/lib/bundle/overrides.js +10 -18
- package/lib/bundle/overrides.js.map +1 -1
- package/lib/bundle/types.d.ts +4 -17
- package/lib/bundle/types.d.ts.map +1 -1
- package/lib/bundle.d.ts +8 -7
- package/lib/bundle.d.ts.map +1 -1
- package/lib/bundle.js +8 -35
- package/lib/bundle.js.map +1 -1
- package/lib/bundler-plugin-defaults.d.ts +3 -0
- package/lib/bundler-plugin-defaults.d.ts.map +1 -0
- package/lib/bundler-plugin-defaults.js +13 -0
- package/lib/bundler-plugin-defaults.js.map +1 -0
- package/lib/clean.js +106 -117
- package/lib/clean.js.map +1 -1
- package/lib/copy-assets.js +194 -210
- package/lib/copy-assets.js.map +1 -1
- package/lib/dep-check.js +12 -7
- package/lib/dep-check.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/metro-config.d.ts +3 -2
- package/lib/metro-config.d.ts.map +1 -1
- package/lib/metro-config.js +7 -5
- package/lib/metro-config.js.map +1 -1
- package/lib/parsers.d.ts +2 -0
- package/lib/parsers.d.ts.map +1 -1
- package/lib/parsers.js +16 -1
- package/lib/parsers.js.map +1 -1
- package/lib/serve/kit-config.d.ts +6 -5
- package/lib/serve/kit-config.d.ts.map +1 -1
- package/lib/serve/kit-config.js +21 -6
- package/lib/serve/kit-config.js.map +1 -1
- package/lib/start.d.ts +2 -2
- package/lib/start.d.ts.map +1 -1
- package/lib/start.js +146 -158
- package/lib/start.js.map +1 -1
- package/package.json +9 -6
- package/react-native.config.js +65 -59
- package/src/bundle/kit-config.ts +42 -60
- package/src/bundle/metro.ts +15 -56
- package/src/bundle/overrides.ts +24 -34
- package/src/bundle/types.ts +17 -23
- package/src/bundle.ts +18 -36
- package/src/bundler-plugin-defaults.ts +10 -0
- package/src/index.ts +1 -1
- package/src/metro-config.ts +12 -6
- package/src/parsers.ts +19 -0
- package/src/serve/kit-config.ts +23 -11
- package/src/start.ts +23 -29
- package/test/bundle/__mocks__/@rnx-kit/config.js +2 -3
- package/test/bundle/__mocks__/@rnx-kit/console.js +1 -0
- package/test/bundle/__mocks__/@rnx-kit/metro-service.js +1 -0
- package/test/bundle/kit-config.test.ts +102 -100
- package/test/bundle/metro.test.ts +58 -98
- package/test/bundle/overrides.test.ts +29 -25
- package/test/copy-assets/assembleAarBundle.test.ts +1 -0
- package/lib/types.d.ts +0 -5
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -3
- package/lib/types.js.map +0 -1
- package/src/types.ts +0 -4
package/src/bundle.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
+
import type { TransformProfile } from "metro-babel-transformer";
|
|
1
2
|
import type { Config as CLIConfig } from "@react-native-community/cli-types";
|
|
2
3
|
import { BundleArgs, loadMetroConfig } from "@rnx-kit/metro-service";
|
|
3
|
-
import { extendObjectArray } from "@rnx-kit/tools-language/properties";
|
|
4
4
|
import type { AllPlatforms } from "@rnx-kit/tools-react-native/platform";
|
|
5
|
-
import {
|
|
5
|
+
import { getCliPlatformBundleConfigs } from "./bundle/kit-config";
|
|
6
6
|
import { metroBundle } from "./bundle/metro";
|
|
7
|
-
import {
|
|
8
|
-
import type { BundleConfig, KitBundleConfig } from "./bundle/types";
|
|
7
|
+
import { applyBundleConfigOverrides } from "./bundle/overrides";
|
|
9
8
|
|
|
10
9
|
export type CLIBundleOptions = {
|
|
11
10
|
id?: string;
|
|
11
|
+
entryFile?: string;
|
|
12
12
|
platform?: AllPlatforms;
|
|
13
|
-
entryPath?: string;
|
|
14
|
-
distPath?: string;
|
|
15
|
-
assetsPath?: string;
|
|
16
|
-
bundlePrefix?: string;
|
|
17
|
-
bundleEncoding?: BundleArgs["bundleEncoding"];
|
|
18
13
|
dev: boolean;
|
|
19
14
|
minify?: boolean;
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
bundleOutput?: string;
|
|
16
|
+
bundleEncoding?: BundleArgs["bundleEncoding"];
|
|
22
17
|
maxWorkers?: number;
|
|
23
18
|
sourcemapOutput?: string;
|
|
24
19
|
sourcemapSourcesRoot?: string;
|
|
20
|
+
sourcemapUseAbsolutePath?: boolean;
|
|
21
|
+
assetsDest?: string;
|
|
22
|
+
treeShake?: boolean;
|
|
23
|
+
unstableTransformProfile?: TransformProfile;
|
|
25
24
|
resetCache?: boolean;
|
|
26
25
|
config?: string;
|
|
27
26
|
};
|
|
@@ -31,39 +30,22 @@ export async function rnxBundle(
|
|
|
31
30
|
cliConfig: CLIConfig,
|
|
32
31
|
cliOptions: CLIBundleOptions
|
|
33
32
|
): 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
|
-
|
|
45
33
|
const metroConfig = await loadMetroConfig(cliConfig, cliOptions);
|
|
46
34
|
|
|
47
|
-
const
|
|
35
|
+
const bundleConfigs = getCliPlatformBundleConfigs(
|
|
48
36
|
cliOptions.id,
|
|
49
37
|
cliOptions.platform
|
|
50
38
|
);
|
|
51
|
-
if (!kitBundleConfigs) {
|
|
52
|
-
return Promise.resolve();
|
|
53
|
-
}
|
|
54
39
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const bundleConfigs = extendObjectArray<KitBundleConfig, BundleConfig>(
|
|
58
|
-
kitBundleConfigs,
|
|
59
|
-
{
|
|
60
|
-
dev: cliOptions.dev,
|
|
61
|
-
minify: cliOptions.minify,
|
|
62
|
-
}
|
|
63
|
-
);
|
|
40
|
+
applyBundleConfigOverrides(cliOptions, bundleConfigs);
|
|
64
41
|
|
|
65
42
|
for (const bundleConfig of bundleConfigs) {
|
|
66
|
-
await metroBundle(
|
|
43
|
+
await metroBundle(
|
|
44
|
+
metroConfig,
|
|
45
|
+
bundleConfig,
|
|
46
|
+
cliOptions.dev,
|
|
47
|
+
cliOptions.minify
|
|
48
|
+
);
|
|
67
49
|
}
|
|
68
50
|
|
|
69
51
|
return Promise.resolve();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BundlerPlugins } from "@rnx-kit/config";
|
|
2
|
+
|
|
3
|
+
export function getDefaultBundlerPlugins(): Required<BundlerPlugins> {
|
|
4
|
+
return {
|
|
5
|
+
detectCyclicDependencies: true,
|
|
6
|
+
detectDuplicateDependencies: true,
|
|
7
|
+
typescriptValidation: true,
|
|
8
|
+
treeShake: false,
|
|
9
|
+
};
|
|
10
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { rnxDepCheck, rnxDepCheckCommand } from "./dep-check";
|
|
|
4
4
|
export { rnxStart } from "./start";
|
|
5
5
|
export { rnxTest, rnxTestCommand } from "./test";
|
|
6
6
|
export { rnxWriteThirdPartyNotices } from "./write-third-party-notices";
|
|
7
|
-
export { parseBoolean } from "./parsers";
|
|
7
|
+
export { parseBoolean, parseTransformProfile } from "./parsers";
|
|
8
8
|
export { rnxClean } from "./clean";
|
package/src/metro-config.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TypeScriptValidationOptions } from "@rnx-kit/config";
|
|
1
2
|
import {
|
|
2
3
|
CyclicDependencies,
|
|
3
4
|
PluginOptions as CyclicDetectorOptions,
|
|
@@ -15,7 +16,6 @@ import { AllPlatforms } from "@rnx-kit/tools-react-native/platform";
|
|
|
15
16
|
import { Project } from "@rnx-kit/typescript-service";
|
|
16
17
|
|
|
17
18
|
import { createProjectCache } from "./typescript/project-cache";
|
|
18
|
-
import type { TypeScriptValidationOptions } from "./types";
|
|
19
19
|
|
|
20
20
|
import type { DeltaResult, Graph } from "metro";
|
|
21
21
|
import type { InputConfigT, SerializerConfigT } from "metro-config";
|
|
@@ -28,10 +28,14 @@ import type { InputConfigT, SerializerConfigT } from "metro-config";
|
|
|
28
28
|
* Source file in node_modules (external packages) are ignored.
|
|
29
29
|
*
|
|
30
30
|
* @param options TypeScript validation options
|
|
31
|
+
* @param print Optional function to use when printing status messages to the Metro console
|
|
31
32
|
* @returns Hook function
|
|
32
33
|
*/
|
|
33
|
-
function createSerializerHook(
|
|
34
|
-
|
|
34
|
+
function createSerializerHook(
|
|
35
|
+
options: TypeScriptValidationOptions,
|
|
36
|
+
print?: (message: string) => void
|
|
37
|
+
) {
|
|
38
|
+
const projectCache = createProjectCache(print);
|
|
35
39
|
|
|
36
40
|
const patternNodeModules = /[/\\]node_modules[/\\]/;
|
|
37
41
|
const excludeNodeModules = (p: string) => !patternNodeModules.test(p);
|
|
@@ -116,13 +120,15 @@ const emptySerializerHook = (_graph: Graph, _delta: DeltaResult): void => {
|
|
|
116
120
|
* @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.
|
|
117
121
|
* @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.
|
|
118
122
|
* @param treeShake When true, tree shaking is enabled.
|
|
123
|
+
* @param print Optional function to use when printing status messages to the Metro console
|
|
119
124
|
*/
|
|
120
125
|
export function customizeMetroConfig(
|
|
121
126
|
metroConfigReadonly: InputConfigT,
|
|
122
127
|
detectCyclicDependencies: boolean | CyclicDetectorOptions,
|
|
123
128
|
detectDuplicateDependencies: boolean | DuplicateDetectorOptions,
|
|
124
129
|
typescriptValidation: boolean | TypeScriptValidationOptions,
|
|
125
|
-
treeShake: boolean
|
|
130
|
+
treeShake: boolean,
|
|
131
|
+
print?: (message: string) => void
|
|
126
132
|
): void {
|
|
127
133
|
// We will be making changes to the Metro configuration. Coerce from a
|
|
128
134
|
// type with readonly props to a type where the props are writeable.
|
|
@@ -163,9 +169,9 @@ export function customizeMetroConfig(
|
|
|
163
169
|
|
|
164
170
|
let hook = emptySerializerHook;
|
|
165
171
|
if (typeof typescriptValidation === "object") {
|
|
166
|
-
hook = createSerializerHook(typescriptValidation);
|
|
172
|
+
hook = createSerializerHook(typescriptValidation, print);
|
|
167
173
|
} else if (typescriptValidation !== false) {
|
|
168
|
-
hook = createSerializerHook({});
|
|
174
|
+
hook = createSerializerHook({}, print);
|
|
169
175
|
}
|
|
170
176
|
metroConfig.serializer.experimentalSerializerHook = hook;
|
|
171
177
|
}
|
package/src/parsers.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { TransformProfile } from "metro-babel-transformer";
|
|
2
|
+
|
|
1
3
|
export function parseBoolean(val: string): boolean {
|
|
2
4
|
if (val === "false") {
|
|
3
5
|
return false;
|
|
@@ -9,3 +11,20 @@ export function parseBoolean(val: string): boolean {
|
|
|
9
11
|
"Invalid boolean value '" + val + "' -- must be true or false"
|
|
10
12
|
);
|
|
11
13
|
}
|
|
14
|
+
|
|
15
|
+
export function parseTransformProfile(val: string): TransformProfile {
|
|
16
|
+
const allowedProfiles: TransformProfile[] = [
|
|
17
|
+
"hermes-stable",
|
|
18
|
+
"hermes-canary",
|
|
19
|
+
"default",
|
|
20
|
+
];
|
|
21
|
+
if (val in allowedProfiles) {
|
|
22
|
+
return val as TransformProfile;
|
|
23
|
+
}
|
|
24
|
+
throw new Error(
|
|
25
|
+
"Invalid transform profile '" +
|
|
26
|
+
val +
|
|
27
|
+
"' -- must be one of " +
|
|
28
|
+
allowedProfiles.join(", ")
|
|
29
|
+
);
|
|
30
|
+
}
|
package/src/serve/kit-config.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { getKitConfig,
|
|
1
|
+
import type { ServerConfig, BundlerPlugins } from "@rnx-kit/config";
|
|
2
|
+
import { getKitConfig, getBundleConfig } from "@rnx-kit/config";
|
|
3
|
+
import { getDefaultBundlerPlugins } from "../bundler-plugin-defaults";
|
|
3
4
|
import { pickValues } from "@rnx-kit/tools-language/properties";
|
|
4
5
|
|
|
5
6
|
export type ServerConfigOverrides = {
|
|
@@ -8,24 +9,35 @@ export type ServerConfigOverrides = {
|
|
|
8
9
|
sourceExts?: string[];
|
|
9
10
|
};
|
|
10
11
|
|
|
12
|
+
export type CliServerConfig = ServerConfig & Required<BundlerPlugins>;
|
|
13
|
+
|
|
11
14
|
/**
|
|
12
|
-
* Get the
|
|
15
|
+
* Get the server configuration from the rnx-kit configuration. Apply any overrides.
|
|
13
16
|
*
|
|
14
|
-
* @param overrides Overrides to apply
|
|
15
|
-
* @returns
|
|
17
|
+
* @param overrides Overrides to apply. These take precedence over the values in the rnx-kit configuration.
|
|
18
|
+
* @returns Server configuration
|
|
16
19
|
*/
|
|
17
20
|
export function getKitServerConfig(
|
|
18
21
|
overrides: ServerConfigOverrides
|
|
19
|
-
):
|
|
22
|
+
): CliServerConfig {
|
|
20
23
|
const kitConfig = getKitConfig();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
)
|
|
24
|
+
let serverConfig = kitConfig?.server;
|
|
25
|
+
if (!serverConfig && kitConfig) {
|
|
26
|
+
const maybeBundleConfig = getBundleConfig(kitConfig);
|
|
27
|
+
if (maybeBundleConfig) {
|
|
28
|
+
serverConfig = pickValues(maybeBundleConfig, [
|
|
29
|
+
"detectCyclicDependencies",
|
|
30
|
+
"detectDuplicateDependencies",
|
|
31
|
+
"typescriptValidation",
|
|
32
|
+
//"treeShake", // don't pull in treeShake yet, since it doesn't work with the server
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
25
35
|
}
|
|
26
36
|
|
|
27
37
|
return {
|
|
28
|
-
...
|
|
38
|
+
...getDefaultBundlerPlugins(),
|
|
39
|
+
...serverConfig,
|
|
40
|
+
treeShake: false, // tree shaking does not work with the bundle server
|
|
29
41
|
...pickValues(overrides, ["projectRoot", "assetPlugins", "sourceExts"]),
|
|
30
42
|
};
|
|
31
43
|
}
|
package/src/start.ts
CHANGED
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
startServer,
|
|
7
7
|
} from "@rnx-kit/metro-service";
|
|
8
8
|
import chalk from "chalk";
|
|
9
|
+
import type { Server as HttpServer } from "http";
|
|
10
|
+
import type { Server as HttpsServer } from "https";
|
|
9
11
|
import type { ReportableEvent, Reporter } from "metro";
|
|
10
12
|
import type { Middleware } from "metro-config";
|
|
11
13
|
import type Server from "metro/src/Server";
|
|
@@ -15,34 +17,32 @@ import qrcode from "qrcode";
|
|
|
15
17
|
import readline from "readline";
|
|
16
18
|
import { customizeMetroConfig } from "./metro-config";
|
|
17
19
|
import { getKitServerConfig } from "./serve/kit-config";
|
|
18
|
-
import type { TypeScriptValidationOptions } from "./types";
|
|
19
20
|
|
|
20
21
|
type DevServerMiddleware = ReturnType<
|
|
21
22
|
typeof CliServerApi["createDevServerMiddleware"]
|
|
22
23
|
>;
|
|
23
24
|
|
|
24
|
-
type
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
eventsSocketEndpoint: DevServer["eventsSocket"];
|
|
25
|
+
type DevServerMiddleware6 = Pick<DevServerMiddleware, "middleware"> & {
|
|
26
|
+
attachToServer: (server: HttpServer | HttpsServer) => {
|
|
27
|
+
debuggerProxy: DevServerMiddleware["debuggerProxyEndpoint"];
|
|
28
|
+
eventsSocket: DevServerMiddleware["eventsSocketEndpoint"];
|
|
29
|
+
messageSocket: DevServerMiddleware["messageSocketEndpoint"];
|
|
30
|
+
};
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
export type CLIStartOptions = {
|
|
34
|
-
host: string;
|
|
35
34
|
port: number;
|
|
35
|
+
host: string;
|
|
36
36
|
projectRoot?: string;
|
|
37
37
|
watchFolders?: string[];
|
|
38
38
|
assetPlugins?: string[];
|
|
39
39
|
sourceExts?: string[];
|
|
40
40
|
maxWorkers?: number;
|
|
41
|
+
resetCache?: boolean;
|
|
41
42
|
customLogReporterPath?: string;
|
|
42
43
|
https?: boolean;
|
|
43
44
|
key?: string;
|
|
44
45
|
cert?: string;
|
|
45
|
-
resetCache?: boolean;
|
|
46
46
|
config?: string;
|
|
47
47
|
interactive: boolean;
|
|
48
48
|
};
|
|
@@ -57,10 +57,10 @@ function friendlyRequire<T>(module: string): T {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
function
|
|
61
|
-
devServer: DevServerMiddleware |
|
|
62
|
-
): devServer is
|
|
63
|
-
return
|
|
60
|
+
function hasAttachToServerFunction(
|
|
61
|
+
devServer: DevServerMiddleware | DevServerMiddleware6
|
|
62
|
+
): devServer is DevServerMiddleware6 {
|
|
63
|
+
return "attachToServer" in devServer;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export async function rnxStart(
|
|
@@ -69,9 +69,6 @@ export async function rnxStart(
|
|
|
69
69
|
cliOptions: CLIStartOptions
|
|
70
70
|
): Promise<void> {
|
|
71
71
|
const serverConfig = getKitServerConfig(cliOptions);
|
|
72
|
-
if (!serverConfig) {
|
|
73
|
-
return Promise.resolve();
|
|
74
|
-
}
|
|
75
72
|
|
|
76
73
|
const { createDevServerMiddleware, indexPageMiddleware } = friendlyRequire<
|
|
77
74
|
typeof CliServerApi
|
|
@@ -140,17 +137,15 @@ export async function rnxStart(
|
|
|
140
137
|
});
|
|
141
138
|
|
|
142
139
|
// customize the metro config to include plugins, presets, etc.
|
|
143
|
-
const typescriptValidationOptions: TypeScriptValidationOptions = {
|
|
144
|
-
print: (message: string): void => {
|
|
145
|
-
terminal.log(message);
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
140
|
customizeMetroConfig(
|
|
149
141
|
metroConfig,
|
|
150
142
|
serverConfig.detectCyclicDependencies,
|
|
151
143
|
serverConfig.detectDuplicateDependencies,
|
|
152
|
-
serverConfig.typescriptValidation
|
|
153
|
-
serverConfig.treeShake
|
|
144
|
+
serverConfig.typescriptValidation,
|
|
145
|
+
serverConfig.treeShake,
|
|
146
|
+
(message: string): void => {
|
|
147
|
+
terminal.log(message);
|
|
148
|
+
}
|
|
154
149
|
);
|
|
155
150
|
|
|
156
151
|
// create middleware -- a collection of plugins which handle incoming
|
|
@@ -165,8 +160,7 @@ export async function rnxStart(
|
|
|
165
160
|
|
|
166
161
|
// merge the Metro config middleware with our middleware
|
|
167
162
|
const enhanceMiddleware = metroConfig.server.enhanceMiddleware;
|
|
168
|
-
//
|
|
169
|
-
// @ts-ignore
|
|
163
|
+
// @ts-expect-error We want to assign to read-only `enhanceMiddleware`
|
|
170
164
|
metroConfig.server.enhanceMiddleware = (
|
|
171
165
|
metroMiddleware: Middleware,
|
|
172
166
|
metroServer: Server
|
|
@@ -181,9 +175,9 @@ export async function rnxStart(
|
|
|
181
175
|
// `createDevServerMiddleware` changed its return type in
|
|
182
176
|
// https://github.com/react-native-community/cli/pull/1560
|
|
183
177
|
let websocketEndpoints: unknown = undefined;
|
|
184
|
-
let messageSocketEndpoint:
|
|
178
|
+
let messageSocketEndpoint: DevServerMiddleware["messageSocketEndpoint"];
|
|
185
179
|
|
|
186
|
-
if (
|
|
180
|
+
if (!hasAttachToServerFunction(devServer)) {
|
|
187
181
|
websocketEndpoints = devServer.websocketEndpoints;
|
|
188
182
|
messageSocketEndpoint = devServer.messageSocketEndpoint;
|
|
189
183
|
|
|
@@ -201,7 +195,7 @@ export async function rnxStart(
|
|
|
201
195
|
};
|
|
202
196
|
const serverInstance = await startServer(metroConfig, serverOptions);
|
|
203
197
|
|
|
204
|
-
if (
|
|
198
|
+
if (hasAttachToServerFunction(devServer)) {
|
|
205
199
|
const { messageSocket, eventsSocket } =
|
|
206
200
|
devServer.attachToServer(serverInstance);
|
|
207
201
|
messageSocketEndpoint = messageSocket;
|
|
@@ -8,8 +8,7 @@ rnxKitConfig.__setMockConfig = (config) => {
|
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
rnxKitConfig.getKitConfig = () => kitConfig;
|
|
11
|
-
rnxKitConfig.
|
|
12
|
-
rnxKitConfig.
|
|
13
|
-
actualKitConfig.getBundlePlatformDefinition;
|
|
11
|
+
rnxKitConfig.getBundleConfig = actualKitConfig.getBundleConfig;
|
|
12
|
+
rnxKitConfig.getPlatformBundleConfig = actualKitConfig.getPlatformBundleConfig;
|
|
14
13
|
|
|
15
14
|
module.exports = rnxKitConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = jest.createMockFromModule("@rnx-kit/console");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = jest.createMockFromModule("@rnx-kit/metro-service");
|
|
@@ -1,55 +1,12 @@
|
|
|
1
1
|
import "jest-extended";
|
|
2
|
-
import type { BundleDefinitionWithRequiredParameters } from "@rnx-kit/config";
|
|
3
2
|
import {
|
|
4
|
-
getKitBundleConfigs,
|
|
5
|
-
getKitBundleDefinition,
|
|
6
3
|
getTargetPlatforms,
|
|
4
|
+
getCliPlatformBundleConfigs,
|
|
7
5
|
} from "../../src/bundle/kit-config";
|
|
8
6
|
|
|
9
7
|
const rnxKitConfig = require("@rnx-kit/config");
|
|
10
|
-
const consoleWarnSpy = jest.spyOn(global.console, "warn");
|
|
11
8
|
|
|
12
|
-
describe("CLI > Bundle > Kit Config >
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
rnxKitConfig.__setMockConfig(undefined);
|
|
15
|
-
consoleWarnSpy.mockReset();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test("throws when kit config is not found", () => {
|
|
19
|
-
expect(() => getKitBundleDefinition()).toThrowError();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test("returns undefined with a warning message when bundle configuration is missing", () => {
|
|
23
|
-
rnxKitConfig.__setMockConfig({});
|
|
24
|
-
expect(getKitBundleDefinition()).toBeUndefined();
|
|
25
|
-
expect(consoleWarnSpy).toBeCalledTimes(1);
|
|
26
|
-
expect(consoleWarnSpy).toBeCalledWith(
|
|
27
|
-
expect.anything(),
|
|
28
|
-
expect.stringContaining("No bundle configuration found")
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test("returns undefined with a warning message when bundling is disabled", () => {
|
|
33
|
-
rnxKitConfig.__setMockConfig({ bundle: false });
|
|
34
|
-
expect(getKitBundleDefinition()).toBeUndefined();
|
|
35
|
-
expect(consoleWarnSpy).toBeCalledTimes(1);
|
|
36
|
-
expect(consoleWarnSpy).toBeCalledWith(
|
|
37
|
-
expect.anything(),
|
|
38
|
-
expect.stringContaining("Bundling is disabled")
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("returns a bundle definition when bundling is enabled", () => {
|
|
43
|
-
rnxKitConfig.__setMockConfig({ bundle: true });
|
|
44
|
-
const definition = getKitBundleDefinition();
|
|
45
|
-
expect(consoleWarnSpy).not.toBeCalled();
|
|
46
|
-
expect(definition).toBeObject();
|
|
47
|
-
expect(definition.entryPath).toBeString();
|
|
48
|
-
expect(definition.entryPath.length).toBeGreaterThan(0);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe("CLI > Bundle > Kit Config > getTargetPlatforms ", () => {
|
|
9
|
+
describe("CLI > Bundle > Kit Config > getTargetPlatforms", () => {
|
|
53
10
|
test("returns the override platform", () => {
|
|
54
11
|
const platforms = getTargetPlatforms("ios", ["android", "ios", "windows"]);
|
|
55
12
|
expect(platforms).toBeArrayOfSize(1);
|
|
@@ -71,78 +28,123 @@ describe("CLI > Bundle > Kit Config > getTargetPlatforms ", () => {
|
|
|
71
28
|
});
|
|
72
29
|
});
|
|
73
30
|
|
|
74
|
-
describe("CLI > Bundle > Kit Config >
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
assetsPath: "out/assets",
|
|
79
|
-
bundlePrefix: "fabrikam",
|
|
31
|
+
describe("CLI > Bundle > Kit Config > getCliPlatformBundleConfigs", () => {
|
|
32
|
+
const defaultConfig = {
|
|
33
|
+
entryFile: "index.js",
|
|
34
|
+
sourcemapUseAbsolutePath: false,
|
|
80
35
|
detectCyclicDependencies: true,
|
|
81
36
|
detectDuplicateDependencies: true,
|
|
82
37
|
typescriptValidation: true,
|
|
83
|
-
treeShake:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
38
|
+
treeShake: false,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const defaultConfigIOS = {
|
|
42
|
+
...defaultConfig,
|
|
43
|
+
bundleOutput: "index.ios.jsbundle",
|
|
44
|
+
platform: "ios",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const defaultConfigMacOS = {
|
|
48
|
+
...defaultConfig,
|
|
49
|
+
bundleOutput: "index.macos.jsbundle",
|
|
50
|
+
platform: "macos",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const defaultConfigAndroid = {
|
|
54
|
+
...defaultConfig,
|
|
55
|
+
bundleOutput: "index.android.bundle",
|
|
56
|
+
platform: "android",
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const defaultConfigWindows = {
|
|
60
|
+
...defaultConfig,
|
|
61
|
+
bundleOutput: "index.windows.bundle",
|
|
62
|
+
platform: "windows",
|
|
90
63
|
};
|
|
91
64
|
|
|
92
65
|
beforeEach(() => {
|
|
93
|
-
rnxKitConfig.__setMockConfig(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
66
|
+
rnxKitConfig.__setMockConfig(undefined);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("returns defaults for iOS when package has no config", () => {
|
|
70
|
+
const configs = getCliPlatformBundleConfigs(undefined, "ios");
|
|
71
|
+
expect(configs).toBeArrayOfSize(1);
|
|
72
|
+
expect(configs[0]).toEqual(defaultConfigIOS);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("returns defaults for MacOS when package has no config", () => {
|
|
76
|
+
const configs = getCliPlatformBundleConfigs(undefined, "macos");
|
|
77
|
+
expect(configs).toBeArrayOfSize(1);
|
|
78
|
+
expect(configs[0]).toEqual(defaultConfigMacOS);
|
|
99
79
|
});
|
|
100
80
|
|
|
101
|
-
test("returns
|
|
102
|
-
const
|
|
103
|
-
expect(
|
|
81
|
+
test("returns defaults for Android when package has no config", () => {
|
|
82
|
+
const configs = getCliPlatformBundleConfigs(undefined, "android");
|
|
83
|
+
expect(configs).toBeArrayOfSize(1);
|
|
84
|
+
expect(configs[0]).toEqual(defaultConfigAndroid);
|
|
104
85
|
});
|
|
105
86
|
|
|
106
|
-
test("
|
|
107
|
-
const
|
|
108
|
-
expect(
|
|
109
|
-
expect(
|
|
110
|
-
expect(kitBundleConfigs[1].platform).toEqual("android");
|
|
87
|
+
test("returns defaults for Windows when package has no config", () => {
|
|
88
|
+
const configs = getCliPlatformBundleConfigs(undefined, "windows");
|
|
89
|
+
expect(configs).toBeArrayOfSize(1);
|
|
90
|
+
expect(configs[0]).toEqual(defaultConfigWindows);
|
|
111
91
|
});
|
|
112
92
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
93
|
+
const testConfig = {
|
|
94
|
+
bundle: {
|
|
95
|
+
entryFile: "entry.js",
|
|
96
|
+
typescriptValidation: false,
|
|
97
|
+
assetsDest: "dist",
|
|
98
|
+
targets: ["ios", "macos", "android", "windows"],
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
test("returns config with defaults for all target platforms", () => {
|
|
103
|
+
rnxKitConfig.__setMockConfig(testConfig);
|
|
104
|
+
const configs = getCliPlatformBundleConfigs();
|
|
105
|
+
expect(configs).toBeArrayOfSize(4);
|
|
106
|
+
expect(configs[0]).toEqual({ ...defaultConfigIOS, ...testConfig.bundle });
|
|
107
|
+
expect(configs[1]).toEqual({ ...defaultConfigMacOS, ...testConfig.bundle });
|
|
108
|
+
expect(configs[2]).toEqual({
|
|
109
|
+
...defaultConfigAndroid,
|
|
110
|
+
...testConfig.bundle,
|
|
120
111
|
});
|
|
121
|
-
expect(
|
|
122
|
-
...
|
|
123
|
-
|
|
112
|
+
expect(configs[3]).toEqual({
|
|
113
|
+
...defaultConfigWindows,
|
|
114
|
+
...testConfig.bundle,
|
|
124
115
|
});
|
|
125
116
|
});
|
|
126
117
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
bundle: {
|
|
133
|
-
...d,
|
|
118
|
+
const testMultiConfig = {
|
|
119
|
+
bundle: [
|
|
120
|
+
{
|
|
121
|
+
id: "first",
|
|
122
|
+
entryFile: "first.js",
|
|
134
123
|
},
|
|
124
|
+
{
|
|
125
|
+
id: "second",
|
|
126
|
+
entryFile: "second.js",
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
test("returns the first config when no id is given", () => {
|
|
132
|
+
rnxKitConfig.__setMockConfig(testMultiConfig);
|
|
133
|
+
const configs = getCliPlatformBundleConfigs(undefined, "ios");
|
|
134
|
+
expect(configs).toBeArrayOfSize(1);
|
|
135
|
+
expect(configs[0]).toEqual({
|
|
136
|
+
...defaultConfigIOS,
|
|
137
|
+
...testMultiConfig.bundle[0],
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("returns the selected config when an id is given", () => {
|
|
142
|
+
rnxKitConfig.__setMockConfig(testMultiConfig);
|
|
143
|
+
const configs = getCliPlatformBundleConfigs("second", "android");
|
|
144
|
+
expect(configs).toBeArrayOfSize(1);
|
|
145
|
+
expect(configs[0]).toEqual({
|
|
146
|
+
...defaultConfigAndroid,
|
|
147
|
+
...testMultiConfig.bundle[1],
|
|
135
148
|
});
|
|
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
149
|
});
|
|
148
150
|
});
|