@rnx-kit/cli 0.12.6 → 0.14.1

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.
Files changed (83) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/README.md +90 -65
  3. package/coverage/clover.xml +92 -104
  4. package/coverage/coverage-final.json +7 -6
  5. package/coverage/lcov-report/index.html +29 -29
  6. package/coverage/lcov-report/src/bundle/index.html +29 -29
  7. package/coverage/lcov-report/src/bundle/kit-config.ts.html +63 -117
  8. package/coverage/lcov-report/src/bundle/metro.ts.html +40 -163
  9. package/coverage/lcov-report/src/bundle/overrides.ts.html +28 -58
  10. package/coverage/lcov-report/src/bundler-plugin-defaults.ts.html +115 -0
  11. package/coverage/lcov-report/src/copy-assets.ts.html +1 -1
  12. package/coverage/lcov-report/src/index.html +26 -11
  13. package/coverage/lcov-report/src/metro-config.ts.html +49 -31
  14. package/coverage/lcov-report/src/typescript/index.html +1 -1
  15. package/coverage/lcov-report/src/typescript/project-cache.ts.html +5 -5
  16. package/coverage/lcov.info +173 -193
  17. package/lib/bundle/kit-config.d.ts +9 -15
  18. package/lib/bundle/kit-config.d.ts.map +1 -1
  19. package/lib/bundle/kit-config.js +29 -43
  20. package/lib/bundle/kit-config.js.map +1 -1
  21. package/lib/bundle/metro.d.ts +7 -11
  22. package/lib/bundle/metro.d.ts.map +1 -1
  23. package/lib/bundle/metro.js +10 -40
  24. package/lib/bundle/metro.js.map +1 -1
  25. package/lib/bundle/overrides.d.ts +11 -9
  26. package/lib/bundle/overrides.d.ts.map +1 -1
  27. package/lib/bundle/overrides.js +10 -18
  28. package/lib/bundle/overrides.js.map +1 -1
  29. package/lib/bundle/types.d.ts +4 -17
  30. package/lib/bundle/types.d.ts.map +1 -1
  31. package/lib/bundle.d.ts +8 -7
  32. package/lib/bundle.d.ts.map +1 -1
  33. package/lib/bundle.js +3 -19
  34. package/lib/bundle.js.map +1 -1
  35. package/lib/bundler-plugin-defaults.d.ts +3 -0
  36. package/lib/bundler-plugin-defaults.d.ts.map +1 -0
  37. package/lib/bundler-plugin-defaults.js +13 -0
  38. package/lib/bundler-plugin-defaults.js.map +1 -0
  39. package/lib/index.d.ts +1 -1
  40. package/lib/index.d.ts.map +1 -1
  41. package/lib/index.js +2 -1
  42. package/lib/index.js.map +1 -1
  43. package/lib/metro-config.d.ts +3 -2
  44. package/lib/metro-config.d.ts.map +1 -1
  45. package/lib/metro-config.js +7 -5
  46. package/lib/metro-config.js.map +1 -1
  47. package/lib/parsers.d.ts +2 -0
  48. package/lib/parsers.d.ts.map +1 -1
  49. package/lib/parsers.js +16 -1
  50. package/lib/parsers.js.map +1 -1
  51. package/lib/serve/kit-config.d.ts +6 -5
  52. package/lib/serve/kit-config.d.ts.map +1 -1
  53. package/lib/serve/kit-config.js +16 -6
  54. package/lib/serve/kit-config.js.map +1 -1
  55. package/lib/start.d.ts +2 -2
  56. package/lib/start.d.ts.map +1 -1
  57. package/lib/start.js +4 -11
  58. package/lib/start.js.map +1 -1
  59. package/package.json +9 -7
  60. package/react-native.config.js +65 -59
  61. package/src/bundle/kit-config.ts +42 -60
  62. package/src/bundle/metro.ts +15 -56
  63. package/src/bundle/overrides.ts +24 -34
  64. package/src/bundle/types.ts +17 -23
  65. package/src/bundle.ts +18 -36
  66. package/src/bundler-plugin-defaults.ts +10 -0
  67. package/src/index.ts +1 -1
  68. package/src/metro-config.ts +12 -6
  69. package/src/parsers.ts +19 -0
  70. package/src/serve/kit-config.ts +23 -11
  71. package/src/start.ts +8 -15
  72. package/test/bundle/__mocks__/@rnx-kit/config.js +2 -3
  73. package/test/bundle/__mocks__/@rnx-kit/console.js +1 -0
  74. package/test/bundle/__mocks__/@rnx-kit/metro-service.js +1 -0
  75. package/test/bundle/kit-config.test.ts +102 -100
  76. package/test/bundle/metro.test.ts +58 -98
  77. package/test/bundle/overrides.test.ts +29 -25
  78. package/test/copy-assets/assembleAarBundle.test.ts +1 -0
  79. package/lib/types.d.ts +0 -5
  80. package/lib/types.d.ts.map +0 -1
  81. package/lib/types.js +0 -3
  82. package/lib/types.js.map +0 -1
  83. package/src/types.ts +0 -4
@@ -1,49 +1,11 @@
1
- import type { BundleDefinitionWithRequiredParameters } from "@rnx-kit/config";
2
1
  import {
3
- getBundleDefinition,
4
- getBundlePlatformDefinition,
2
+ getBundleConfig,
3
+ getPlatformBundleConfig,
5
4
  getKitConfig,
6
5
  } from "@rnx-kit/config";
7
- import { warn } from "@rnx-kit/console";
8
6
  import type { AllPlatforms } from "@rnx-kit/tools-react-native/platform";
9
- import chalk from "chalk";
10
- import type { KitBundleConfig } from "./types";
11
-
12
- /**
13
- * Get a bundle definition from the kit configuration.
14
- *
15
- * @param id Optional bundle definition id. Only needed when the kit config has more than one definition.
16
- * @returns Bundle definition matching the id (if given), or the first bundle definition found. `undefined` if bundling is disabled or not supported for the kit.
17
- */
18
- export function getKitBundleDefinition(
19
- id?: string
20
- ): BundleDefinitionWithRequiredParameters | undefined {
21
- const kitConfig = getKitConfig();
22
- if (!kitConfig) {
23
- throw new Error(
24
- "No kit configuration found for this react-native experience"
25
- );
26
- }
27
-
28
- if (kitConfig.bundle === null || kitConfig.bundle === undefined) {
29
- warn(
30
- chalk.yellow(
31
- "No bundle configuration found for this react-native experience -- skipping bundling"
32
- )
33
- );
34
- return undefined;
35
- } else if (!kitConfig.bundle) {
36
- warn(
37
- chalk.yellow(
38
- "Bundling is disabled for this react-native experience -- skipping"
39
- )
40
- );
41
- return undefined;
42
- }
43
-
44
- // get the bundle definition
45
- return getBundleDefinition(kitConfig.bundle, id);
46
- }
7
+ import type { CliPlatformBundleConfig } from "./types";
8
+ import { getDefaultBundlerPlugins } from "../bundler-plugin-defaults";
47
9
 
48
10
  /**
49
11
  * Get the list of target platforms for bundling.
@@ -63,36 +25,56 @@ export function getTargetPlatforms(
63
25
  return targetPlatforms;
64
26
  }
65
27
  throw new Error(
66
- "No target platforms given. Update the kit configuration to include a target platform, or provide a target platform on the command-line."
28
+ "No target platforms given. Update the rnx-kit configuration to include a target platform, or provide a target platform on the command-line."
67
29
  );
68
30
  }
69
31
 
32
+ function getDefaultBundleParameters(platform: string) {
33
+ const extension =
34
+ platform === "ios" || platform === "macos" ? "jsbundle" : "bundle";
35
+
36
+ return {
37
+ entryFile: "index.js",
38
+ bundleOutput: `index.${platform}.${extension}`,
39
+ sourcemapUseAbsolutePath: false,
40
+ };
41
+ }
42
+
70
43
  /**
71
- * Get bundle configuration and target platform(s) from kit config. Create
72
- * one config per platform, applying any platform-specific customizations in
73
- * the kit config.
44
+ * Get the bundle configuration and target platform(s) from the rnx-kit
45
+ * configuration. Use them to create an array of platform-specific
46
+ * bundle configurations.
47
+ *
48
+ * If an id is given, search for the matching bundle definition. Otherwise, use the first bundle definition.
74
49
  *
75
- * @param id Optional bundle definition id. Only needed when the kit config has more than one definition.
50
+ * @param id Optional identity of the target bundle definition to return
76
51
  * @param overridePlatform Override platform, typically from the command-line. When given, this overrides the list of target platforms.
77
- * @returns Arrary of kit bundle configurations, one per target platform, or `undefined` if bundling is disabled
52
+ * @returns Arrary of platform-specific bundle configurations
78
53
  */
79
- export function getKitBundleConfigs(
54
+ export function getCliPlatformBundleConfigs(
80
55
  id?: string,
81
56
  overridePlatform?: AllPlatforms
82
- ): KitBundleConfig[] | undefined {
83
- const bundleDefinition = getKitBundleDefinition(id);
84
- if (!bundleDefinition) {
85
- return undefined;
86
- }
57
+ ): CliPlatformBundleConfig[] {
58
+ const kitConfig = getKitConfig();
59
+ const maybeBundleConfig = kitConfig
60
+ ? getBundleConfig(kitConfig, id)
61
+ : undefined;
62
+ const bundleConfig = maybeBundleConfig ?? {};
87
63
 
88
- const platforms = getTargetPlatforms(
89
- overridePlatform,
90
- bundleDefinition.targets
91
- );
64
+ const platforms = getTargetPlatforms(overridePlatform, bundleConfig.targets);
65
+
66
+ return platforms.map<CliPlatformBundleConfig>((platform) => {
67
+ const platformBundleConfig = getPlatformBundleConfig(
68
+ bundleConfig,
69
+ platform
70
+ );
71
+
72
+ // apply defaults to fill in any required props that are missing
92
73
 
93
- return platforms.map<KitBundleConfig>((platform) => {
94
74
  return {
95
- ...getBundlePlatformDefinition(bundleDefinition, platform),
75
+ ...getDefaultBundlerPlugins(),
76
+ ...getDefaultBundleParameters(platform),
77
+ ...platformBundleConfig,
96
78
  platform,
97
79
  };
98
80
  });
@@ -4,81 +4,40 @@ import { createDirectory } from "@rnx-kit/tools-node/fs";
4
4
  import type { ConfigT } from "metro-config";
5
5
  import path from "path";
6
6
  import { customizeMetroConfig } from "../metro-config";
7
- import type { BundleConfig } from "./types";
8
- import type { TypeScriptValidationOptions } from "../types";
9
-
10
- /**
11
- * Create Metro bundler arguments from a bundle configuration.
12
- *
13
- * @param bundleConfig Bundle configuration
14
- * @returns Metro bundle arguments
15
- */
16
- export function createMetroBundleArgs({
17
- entryPath: entryFile,
18
- distPath,
19
- assetsPath: assetsDest,
20
- bundlePrefix,
21
- bundleEncoding,
22
- sourceMapPath: sourcemapOutput,
23
- sourceMapSourceRootPath: sourcemapSourcesRoot,
24
- platform,
25
- dev,
26
- minify,
27
- }: BundleConfig): MetroBundleArgs {
28
- // assemble the full path to the bundle file
29
- const bundleExtension =
30
- platform === "ios" || platform === "macos" ? "jsbundle" : "bundle";
31
- const bundleFile = `${bundlePrefix}.${platform}.${bundleExtension}`;
32
- const bundlePath = path.join(distPath, bundleFile);
33
-
34
- // always create a source-map in dev mode
35
- if (dev) {
36
- sourcemapOutput = sourcemapOutput ?? bundleFile + ".map";
37
- }
38
-
39
- // use an absolute path for the source map file
40
- if (sourcemapOutput) {
41
- sourcemapOutput = path.join(distPath, sourcemapOutput);
42
- }
43
-
44
- return {
45
- assetsDest,
46
- entryFile,
47
- minify,
48
- platform,
49
- dev,
50
- bundleOutput: bundlePath,
51
- bundleEncoding,
52
- sourcemapOutput,
53
- sourcemapSourcesRoot,
54
- };
55
- }
7
+ import type { CliPlatformBundleConfig } from "./types";
56
8
 
57
9
  /**
58
10
  * Run the Metro bundler.
59
11
  *
60
- * @param tsservice TypeScript service to use for type-checking (when enabled)
61
12
  * @param metroConfig Metro configuration
62
13
  * @param bundleConfig Bundle configuration
14
+ * @param dev Choose whether or not this will be a "developer" bundle. The alternative is a "production" bundle.
15
+ * When `true`, warnings are enabled, and the bundle is not minified by default.
16
+ * Further, optimizations like constant folding are disabled.
17
+ * When `false`, warnings are disabled and the bundle is minified by default.
18
+ * @param minify Optionally choose whether or not the bundle is minified. When not set, minification is controlled by the `dev` property.
63
19
  */
64
20
  export async function metroBundle(
65
21
  metroConfig: ConfigT,
66
- bundleConfig: BundleConfig
22
+ bundleConfig: CliPlatformBundleConfig,
23
+ dev: boolean,
24
+ minify?: boolean
67
25
  ): Promise<void> {
68
26
  info(`Bundling ${bundleConfig.platform}...`);
69
27
 
70
- const typescriptValidationOptions: TypeScriptValidationOptions = {
71
- throwOnError: true,
72
- };
73
28
  customizeMetroConfig(
74
29
  metroConfig,
75
30
  bundleConfig.detectCyclicDependencies,
76
31
  bundleConfig.detectDuplicateDependencies,
77
- bundleConfig.typescriptValidation ? typescriptValidationOptions : false,
32
+ bundleConfig.typescriptValidation,
78
33
  bundleConfig.treeShake
79
34
  );
80
35
 
81
- const metroBundleArgs = createMetroBundleArgs(bundleConfig);
36
+ const metroBundleArgs: MetroBundleArgs = {
37
+ ...bundleConfig,
38
+ dev,
39
+ minify,
40
+ };
82
41
 
83
42
  // ensure all output directories exist
84
43
  createDirectory(path.dirname(metroBundleArgs.bundleOutput));
@@ -1,51 +1,41 @@
1
+ import type { TransformProfile } from "metro-babel-transformer";
1
2
  import type { BundleArgs } from "@rnx-kit/metro-service";
2
3
  import { pickValues } from "@rnx-kit/tools-language/properties";
3
- import type { KitBundleConfig } from "./types";
4
+ import type { CliPlatformBundleConfig } from "./types";
4
5
 
5
- export type KitBundleConfigOverrides = {
6
- entryPath?: string;
7
- distPath?: string;
8
- assetsPath?: string;
9
- bundlePrefix?: string;
6
+ export type BundleConfigOverrides = {
7
+ entryFile?: string;
8
+ bundleOutput?: string;
10
9
  bundleEncoding?: BundleArgs["bundleEncoding"];
11
10
  sourcemapOutput?: string;
12
11
  sourcemapSourcesRoot?: string;
12
+ sourcemapUseAbsolutePath?: boolean;
13
+ assetsDest?: string;
13
14
  treeShake?: boolean;
15
+ unstableTransformProfile?: TransformProfile;
14
16
  };
15
17
 
16
18
  /**
17
- * Apply overrides, if any, to each kit bundle config. Overrides are applied in-place.
19
+ * Apply overrides, if any, to each rnx-kit bundle configuration. Overrides are applied in-place.
18
20
  *
19
21
  * @param overrides Optional overrides to apply
20
- * @param configs Array of kit bundle configurations to override. This is modified if any overrides are applied.
22
+ * @param configs Array of platform-specific bundle configurations. This is modified if any overrides are applied.
21
23
  */
22
- export function applyKitBundleConfigOverrides(
23
- overrides: KitBundleConfigOverrides,
24
- configs: KitBundleConfig[]
24
+ export function applyBundleConfigOverrides(
25
+ overrides: BundleConfigOverrides,
26
+ configs: CliPlatformBundleConfig[]
25
27
  ): void {
26
- const overridesToApply = pickValues(
27
- overrides,
28
- [
29
- "entryPath",
30
- "distPath",
31
- "assetsPath",
32
- "bundlePrefix",
33
- "bundleEncoding",
34
- "sourcemapOutput",
35
- "sourcemapSourcesRoot",
36
- "treeShake",
37
- ],
38
- [
39
- "entryPath",
40
- "distPath",
41
- "assetsPath",
42
- "bundlePrefix",
43
- "bundleEncoding",
44
- "sourcemapOutput",
45
- "sourcemapSourcesRoot",
46
- "treeShake",
47
- ]
48
- );
28
+ const overridesToApply = pickValues(overrides, [
29
+ "entryFile",
30
+ "bundleOutput",
31
+ "bundleEncoding",
32
+ "sourcemapOutput",
33
+ "sourcemapSourcesRoot",
34
+ "sourcemapUseAbsolutePath",
35
+ "assetsDest",
36
+ "treeShake",
37
+ "unstableTransformProfile",
38
+ ]);
49
39
  if (overridesToApply) {
50
40
  for (const config of configs) {
51
41
  Object.assign(config, overridesToApply);
@@ -1,30 +1,24 @@
1
- import type {
2
- BundleParameters,
3
- BundleRequiredParameters,
4
- } from "@rnx-kit/config";
1
+ import type { TransformProfile } from "metro-babel-transformer";
2
+ import type { BundleParameters } from "@rnx-kit/config";
5
3
  import type { AllPlatforms } from "@rnx-kit/tools-react-native/platform";
6
4
 
7
- export type KitBundleConfig = BundleParameters &
8
- BundleRequiredParameters & {
5
+ export type CliPlatformBundleConfig = BundleParameters &
6
+ Required<
7
+ Pick<
8
+ BundleParameters,
9
+ | "entryFile"
10
+ | "bundleOutput"
11
+ | "sourcemapUseAbsolutePath"
12
+ | "detectCyclicDependencies"
13
+ | "detectDuplicateDependencies"
14
+ | "typescriptValidation"
15
+ | "treeShake"
16
+ >
17
+ > & {
18
+ unstableTransformProfile?: TransformProfile;
19
+
9
20
  /**
10
21
  * Target platform for the bundle
11
22
  */
12
23
  platform: AllPlatforms;
13
24
  };
14
-
15
- export type BundleConfig = KitBundleConfig & {
16
- /**
17
- * Choose whether or not this will be a "developer" bundle. The alternative is a "production" bundle.
18
- *
19
- * When `true`, warnings are enabled, and the bundle is not minified by default.
20
- * Further, optimizations like constant folding are disabled.
21
- *
22
- * When `false`, warnings are disabled and the bundle is minified by default.
23
- */
24
- dev: boolean;
25
-
26
- /**
27
- * Optionally choose whether or not the bundle is minified. When not set, minification is controlled by the `dev` property.
28
- */
29
- minify?: boolean;
30
- };
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 { getKitBundleConfigs } from "./bundle/kit-config";
5
+ import { getCliPlatformBundleConfigs } from "./bundle/kit-config";
6
6
  import { metroBundle } from "./bundle/metro";
7
- import { applyKitBundleConfigOverrides } from "./bundle/overrides";
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
- experimentalTreeShake?: boolean; // Deprecated
21
- treeShake?: boolean;
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 kitBundleConfigs = getKitBundleConfigs(
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
- applyKitBundleConfigOverrides(cliOptions, kitBundleConfigs);
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(metroConfig, bundleConfig);
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";
@@ -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(options: TypeScriptValidationOptions) {
34
- const projectCache = createProjectCache(options.print);
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
+ }
@@ -1,5 +1,6 @@
1
- import type { ServerWithRequiredParameters } from "@rnx-kit/config";
2
- import { getKitConfig, getServerConfig } from "@rnx-kit/config";
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 kit's server configuration. Apply any overrides.
15
+ * Get the server configuration from the rnx-kit configuration. Apply any overrides.
13
16
  *
14
- * @param overrides Overrides to apply to the output server configuration. These take precedence over the values in the kit config.
15
- * @returns Overridden server configuration
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
- ): ServerWithRequiredParameters {
22
+ ): CliServerConfig {
20
23
  const kitConfig = getKitConfig();
21
- if (!kitConfig) {
22
- throw new Error(
23
- "No kit configuration found for this react-native experience"
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
- ...getServerConfig(kitConfig),
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
@@ -15,7 +15,6 @@ import qrcode from "qrcode";
15
15
  import readline from "readline";
16
16
  import { customizeMetroConfig } from "./metro-config";
17
17
  import { getKitServerConfig } from "./serve/kit-config";
18
- import type { TypeScriptValidationOptions } from "./types";
19
18
 
20
19
  type DevServerMiddleware = ReturnType<
21
20
  typeof CliServerApi["createDevServerMiddleware"]
@@ -31,18 +30,18 @@ type DevServerMiddleware7 = Pick<DevServerMiddleware, "middleware"> & {
31
30
  };
32
31
 
33
32
  export type CLIStartOptions = {
34
- host: string;
35
33
  port: number;
34
+ host: string;
36
35
  projectRoot?: string;
37
36
  watchFolders?: string[];
38
37
  assetPlugins?: string[];
39
38
  sourceExts?: string[];
40
39
  maxWorkers?: number;
40
+ resetCache?: boolean;
41
41
  customLogReporterPath?: string;
42
42
  https?: boolean;
43
43
  key?: string;
44
44
  cert?: string;
45
- resetCache?: boolean;
46
45
  config?: string;
47
46
  interactive: boolean;
48
47
  };
@@ -69,9 +68,6 @@ export async function rnxStart(
69
68
  cliOptions: CLIStartOptions
70
69
  ): Promise<void> {
71
70
  const serverConfig = getKitServerConfig(cliOptions);
72
- if (!serverConfig) {
73
- return Promise.resolve();
74
- }
75
71
 
76
72
  const { createDevServerMiddleware, indexPageMiddleware } = friendlyRequire<
77
73
  typeof CliServerApi
@@ -140,17 +136,15 @@ export async function rnxStart(
140
136
  });
141
137
 
142
138
  // 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
139
  customizeMetroConfig(
149
140
  metroConfig,
150
141
  serverConfig.detectCyclicDependencies,
151
142
  serverConfig.detectDuplicateDependencies,
152
- serverConfig.typescriptValidation ? typescriptValidationOptions : false,
153
- serverConfig.treeShake
143
+ serverConfig.typescriptValidation,
144
+ serverConfig.treeShake,
145
+ (message: string): void => {
146
+ terminal.log(message);
147
+ }
154
148
  );
155
149
 
156
150
  // create middleware -- a collection of plugins which handle incoming
@@ -165,8 +159,7 @@ export async function rnxStart(
165
159
 
166
160
  // merge the Metro config middleware with our middleware
167
161
  const enhanceMiddleware = metroConfig.server.enhanceMiddleware;
168
- // eslint-disable-next-line
169
- // @ts-ignore
162
+ // @ts-expect-error We want to assign to read-only `enhanceMiddleware`
170
163
  metroConfig.server.enhanceMiddleware = (
171
164
  metroMiddleware: Middleware,
172
165
  metroServer: Server
@@ -8,8 +8,7 @@ rnxKitConfig.__setMockConfig = (config) => {
8
8
  };
9
9
 
10
10
  rnxKitConfig.getKitConfig = () => kitConfig;
11
- rnxKitConfig.getBundleDefinition = actualKitConfig.getBundleDefinition;
12
- rnxKitConfig.getBundlePlatformDefinition =
13
- actualKitConfig.getBundlePlatformDefinition;
11
+ rnxKitConfig.getBundleConfig = actualKitConfig.getBundleConfig;
12
+ rnxKitConfig.getPlatformBundleConfig = actualKitConfig.getPlatformBundleConfig;
14
13
 
15
14
  module.exports = rnxKitConfig;