@rnx-kit/cli 0.16.28 → 0.16.30

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 (61) hide show
  1. package/lib/align-deps.d.ts +1 -1
  2. package/lib/align-deps.js +8 -9
  3. package/lib/bundle/cliOptions.d.ts +2 -2
  4. package/lib/bundle/cliOptions.js +27 -27
  5. package/lib/bundle/defaultPlugins.js +1 -2
  6. package/lib/bundle/hermes.d.ts +2 -1
  7. package/lib/bundle/hermes.js +5 -12
  8. package/lib/bundle/kit-config.js +2 -3
  9. package/lib/bundle/metro.js +6 -10
  10. package/lib/bundle/overrides.js +2 -2
  11. package/lib/bundle.d.ts +3 -3
  12. package/lib/bundle.js +6 -6
  13. package/lib/clean.d.ts +2 -2
  14. package/lib/clean.js +44 -64
  15. package/lib/copy-assets.js +6 -6
  16. package/lib/helpers/externals.d.ts +4 -0
  17. package/lib/{serve/external.js → helpers/externals.js} +11 -10
  18. package/lib/helpers/filesystem.d.ts +3 -0
  19. package/lib/helpers/filesystem.js +31 -0
  20. package/lib/{metro-config.js → helpers/metro-config.js} +2 -3
  21. package/lib/{parsers.d.ts → helpers/parsers.d.ts} +1 -1
  22. package/lib/{parsers.js → helpers/parsers.js} +20 -19
  23. package/lib/index.d.ts +15 -16
  24. package/lib/index.js +1 -5
  25. package/lib/ram-bundle.d.ts +4 -4
  26. package/lib/ram-bundle.js +4 -4
  27. package/lib/serve/help.js +1 -2
  28. package/lib/serve/keyboard.js +1 -2
  29. package/lib/serve/kit-config.js +1 -2
  30. package/lib/serve/types.d.ts +0 -2
  31. package/lib/start.d.ts +1 -1
  32. package/lib/start.js +35 -35
  33. package/lib/test.d.ts +2 -1
  34. package/lib/test.js +4 -4
  35. package/lib/write-third-party-notices.js +15 -15
  36. package/package.json +6 -8
  37. package/lib/serve/external.d.ts +0 -7
  38. package/src/align-deps.ts +0 -83
  39. package/src/bundle/cliOptions.ts +0 -82
  40. package/src/bundle/defaultPlugins.ts +0 -16
  41. package/src/bundle/hermes.ts +0 -114
  42. package/src/bundle/kit-config.ts +0 -81
  43. package/src/bundle/metro.ts +0 -66
  44. package/src/bundle/overrides.ts +0 -51
  45. package/src/bundle/types.ts +0 -41
  46. package/src/bundle.ts +0 -69
  47. package/src/clean.ts +0 -223
  48. package/src/copy-assets.ts +0 -545
  49. package/src/index.ts +0 -34
  50. package/src/metro-config.ts +0 -208
  51. package/src/parsers.ts +0 -44
  52. package/src/ram-bundle.ts +0 -78
  53. package/src/serve/external.ts +0 -62
  54. package/src/serve/help.ts +0 -59
  55. package/src/serve/keyboard.ts +0 -76
  56. package/src/serve/kit-config.ts +0 -47
  57. package/src/serve/types.ts +0 -87
  58. package/src/start.ts +0 -316
  59. package/src/test.ts +0 -137
  60. package/src/write-third-party-notices.ts +0 -85
  61. /package/lib/{metro-config.d.ts → helpers/metro-config.d.ts} +0 -0
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rnxWriteThirdPartyNoticesCommand = exports.rnxWriteThirdPartyNotices = void 0;
3
+ exports.rnxWriteThirdPartyNoticesCommand = void 0;
4
+ exports.rnxWriteThirdPartyNotices = rnxWriteThirdPartyNotices;
4
5
  const third_party_notices_1 = require("@rnx-kit/third-party-notices");
5
6
  function rnxWriteThirdPartyNotices(_argv, _config, { additionalText, ignoreModules, ignoreScopes, json, outputFile, preambleText, rootPath, sourceMapFile, }) {
6
7
  // react-native-cli is not as rich as yargs, so we have to perform a mapping.
@@ -15,7 +16,6 @@ function rnxWriteThirdPartyNotices(_argv, _config, { additionalText, ignoreModul
15
16
  additionalText: additionalText ? [additionalText] : undefined,
16
17
  });
17
18
  }
18
- exports.rnxWriteThirdPartyNotices = rnxWriteThirdPartyNotices;
19
19
  exports.rnxWriteThirdPartyNoticesCommand = {
20
20
  name: "rnx-write-third-party-notices",
21
21
  description: "Writes third party notices based on the given bundle",
@@ -23,36 +23,36 @@ exports.rnxWriteThirdPartyNoticesCommand = {
23
23
  options: [
24
24
  {
25
25
  name: "--root-path <path>",
26
- description: "The root of the repo. This is the starting point for finding each module in the source map dependency graph.",
26
+ description: "The root of the repo the starting point for finding each module in the source map dependency graph",
27
27
  },
28
28
  {
29
29
  name: "--source-map-file <file>",
30
- description: "The source map file associated with the package's entry file. This source map eventually leads to all package dependencies and their licenses.",
30
+ description: "The source map file associated with the package's entry file this source map eventually leads to all package dependencies and their licenses",
31
31
  },
32
32
  {
33
33
  name: "--json",
34
- description: "Format the 3rd-party notice file as JSON instead of text.",
34
+ description: "Format the 3rd-party notice file as JSON instead of text",
35
35
  default: false,
36
36
  },
37
37
  {
38
- name: "--output-file [file]",
39
- description: "The path to use when writing the 3rd-party notice file.",
38
+ name: "--output-file <file>",
39
+ description: "The path to use when writing the 3rd-party notice file",
40
40
  },
41
41
  {
42
- name: "--ignore-scopes [string]",
43
- description: "Comma-separated list of `npm` scopes to ignore when traversing the source map dependency graph.",
42
+ name: "--ignore-scopes <string>",
43
+ description: "Comma-separated list of npm scopes to ignore when traversing the source map dependency graph",
44
44
  },
45
45
  {
46
- name: "--ignore-modules [string]",
47
- description: "Comma-separated list of modules to ignore when traversing the source map dependency graph.",
46
+ name: "--ignore-modules <string>",
47
+ description: "Comma-separated list of modules to ignore when traversing the source map dependency graph",
48
48
  },
49
49
  {
50
- name: "--preamble-text [string]",
51
- description: "A string to prepend to the start of the 3rd-party notice.",
50
+ name: "--preamble-text <string>",
51
+ description: "A string to prepend to the start of the 3rd-party notice",
52
52
  },
53
53
  {
54
- name: "--additional-text [path]",
55
- description: "A string to append to the end of the 3rd-party notice.",
54
+ name: "--additional-text <string>",
55
+ description: "A string to append to the end of the 3rd-party notice",
56
56
  },
57
57
  ],
58
58
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rnx-kit/cli",
3
- "version": "0.16.28",
3
+ "version": "0.16.30",
4
4
  "description": "Command-line interface for working with kit packages in your repo",
5
5
  "homepage": "https://github.com/microsoft/rnx-kit/tree/main/packages/cli#readme",
6
6
  "license": "MIT",
@@ -11,8 +11,7 @@
11
11
  "files": [
12
12
  "lib/**/*.d.ts",
13
13
  "lib/**/*.js",
14
- "react-native.config.js",
15
- "src"
14
+ "react-native.config.js"
16
15
  ],
17
16
  "main": "lib/index.js",
18
17
  "types": "lib/index.d.ts",
@@ -21,8 +20,8 @@
21
20
  "types": "./lib/index.d.ts",
22
21
  "default": "./lib/index.js"
23
22
  },
24
- "./package.json": "./package.json",
25
- "./react-native.config.js": "./react-native.config.js"
23
+ "./react-native.config.js": "./react-native.config.js",
24
+ "./package.json": "./package.json"
26
25
  },
27
26
  "repository": {
28
27
  "type": "git",
@@ -44,12 +43,12 @@
44
43
  "@rnx-kit/metro-plugin-duplicates-checker": "^2.1.1",
45
44
  "@rnx-kit/metro-plugin-typescript": "^0.4.4",
46
45
  "@rnx-kit/metro-serializer": "^1.0.14",
47
- "@rnx-kit/metro-serializer-esbuild": "^0.1.31",
46
+ "@rnx-kit/metro-serializer-esbuild": "^0.1.36",
48
47
  "@rnx-kit/metro-service": "^3.1.6",
49
48
  "@rnx-kit/third-party-notices": "^1.3.4",
50
49
  "@rnx-kit/tools-language": "^2.0.0",
51
50
  "@rnx-kit/tools-node": "^2.1.1",
52
- "@rnx-kit/tools-react-native": "^1.3.5",
51
+ "@rnx-kit/tools-react-native": "^1.4.0",
53
52
  "fs-extra": "^10.0.0",
54
53
  "node-fetch": "^2.6.7",
55
54
  "ora": "^5.4.1",
@@ -71,7 +70,6 @@
71
70
  "devDependencies": {
72
71
  "@babel/core": "^7.20.0",
73
72
  "@babel/preset-env": "^7.20.0",
74
- "@react-native-community/cli-clean": "^12.3.0",
75
73
  "@react-native-community/cli-types": "^12.3.0",
76
74
  "@rnx-kit/eslint-config": "*",
77
75
  "@rnx-kit/jest-preset": "*",
@@ -1,7 +0,0 @@
1
- import type { CliServerApi, CoreDevMiddleware } from "./types";
2
- type CliClean = typeof import("@react-native-community/cli-clean");
3
- export declare function requireExternal(module: "@react-native-community/cli-clean"): CliClean;
4
- export declare function requireExternal(module: "@react-native-community/cli-server-api"): CliServerApi;
5
- export declare function requireExternal(module: "@react-native/dev-middleware"): CoreDevMiddleware;
6
- export {};
7
- //# sourceMappingURL=external.d.ts.map
package/src/align-deps.ts DELETED
@@ -1,83 +0,0 @@
1
- import type { Config as CLIConfig } from "@react-native-community/cli-types";
2
- import { cli, cliOptions } from "@rnx-kit/align-deps";
3
- import { pickValues } from "@rnx-kit/tools-language/properties";
4
-
5
- type CLIArgs = Record<string, string | number | boolean | undefined>;
6
-
7
- const optionsMap: Partial<Record<keyof typeof cliOptions, string>> = {
8
- "exclude-packages": "excludePackages",
9
- init: "init",
10
- presets: "presets",
11
- requirements: "requirements",
12
- "set-version": "setVersion",
13
- };
14
-
15
- export function rnxAlignDeps(
16
- argv: string[],
17
- _config: CLIConfig,
18
- args: CLIArgs
19
- ): void {
20
- cli({
21
- ...pickValues(args, Object.values(optionsMap), Object.keys(optionsMap)),
22
- "diff-mode": args.diffMode?.toString(),
23
- loose: Boolean(args.loose),
24
- "migrate-config": Boolean(args.migrateConfig),
25
- "no-unmanaged": Boolean(args.noUnmanaged),
26
- verbose: Boolean(args.verbose),
27
- write: Boolean(args.write),
28
- packages: argv,
29
- });
30
- }
31
-
32
- export const rnxAlignDepsCommand = {
33
- name: "rnx-align-deps",
34
- description:
35
- "Manage dependencies within a repository and across many repositories",
36
- func: rnxAlignDeps,
37
- options: [
38
- {
39
- name: `--diff-mode [${cliOptions["diff-mode"].choices.join("|")}]`,
40
- description: cliOptions["diff-mode"].description,
41
- },
42
- {
43
- name: "--exclude-packages [packages]",
44
- description: cliOptions["exclude-packages"].description,
45
- },
46
- {
47
- name: `--init [${cliOptions.init.choices?.join("|")}]`,
48
- description: cliOptions.init.description,
49
- },
50
- {
51
- name: "--loose",
52
- description: cliOptions.loose.description,
53
- },
54
- {
55
- name: "--migrate-config",
56
- description: cliOptions["migrate-config"].description,
57
- },
58
- {
59
- name: "--no-unmanaged",
60
- description: cliOptions["no-unmanaged"].description,
61
- },
62
- {
63
- name: "--presets [presets]",
64
- description: cliOptions.presets.description,
65
- },
66
- {
67
- name: "--requirements [requirements]",
68
- description: cliOptions.requirements.description,
69
- },
70
- {
71
- name: "--set-version [versions]",
72
- description: cliOptions["set-version"].description,
73
- },
74
- {
75
- name: "--verbose",
76
- description: cliOptions.verbose.description,
77
- },
78
- {
79
- name: "--write",
80
- description: cliOptions.write.description,
81
- },
82
- ],
83
- };
@@ -1,82 +0,0 @@
1
- import { parsePlatform } from "@rnx-kit/tools-react-native/platform";
2
- import { asBoolean, asNumber, parseTransformProfile } from "../parsers";
3
-
4
- export const commonBundleCommandOptions = [
5
- {
6
- name: "--id [id]",
7
- description:
8
- "Target bundle definition. This is only needed when the rnx-kit configuration has multiple bundle definitions.",
9
- },
10
- {
11
- name: "--entry-file [path]",
12
- description:
13
- "Path to the root JavaScript or TypeScript file, either absolute or relative to the package.",
14
- },
15
- {
16
- name: "--platform [ios|android|windows|win32|macos]",
17
- description:
18
- "Target platform. When not given, all platforms in the rnx-kit configuration are bundled.",
19
- parse: parsePlatform,
20
- },
21
- {
22
- name: "--dev [boolean]",
23
- description: "If false, warnings are disabled and the bundle is minified.",
24
- default: true,
25
- parse: asBoolean,
26
- },
27
- {
28
- name: "--minify [boolean]",
29
- description:
30
- "Controls whether or not the bundle is minified. Disabling minification is useful for test builds.",
31
- parse: asBoolean,
32
- },
33
- {
34
- name: "--bundle-output [string]",
35
- description:
36
- "Path to the output bundle file, either absolute or relative to the package.",
37
- },
38
- {
39
- name: "--bundle-encoding [utf8|utf16le|ascii]",
40
- description: "Character encoding to use when writing the bundle file.",
41
- default: "utf8",
42
- },
43
- {
44
- name: "--max-workers [number]",
45
- description:
46
- "Specifies the maximum number of parallel worker threads to use for transforming files. This defaults to the number of cores available on your machine.",
47
- parse: asNumber,
48
- },
49
- {
50
- name: "--sourcemap-output [string]",
51
- description:
52
- "Path where the bundle source map is written, either absolute or relative to the package.",
53
- },
54
- {
55
- name: "--sourcemap-sources-root [string]",
56
- description:
57
- "Path to use when relativizing file entries in the bundle source map.",
58
- },
59
- {
60
- name: "--sourcemap-use-absolute-path",
61
- description: "Report SourceMapURL using its full path",
62
- },
63
- {
64
- name: "--assets-dest [path]",
65
- description:
66
- "Path where bundle assets like images are written, either absolute or relative to the package. If not given, assets are ignored.",
67
- },
68
- {
69
- name: "--unstable-transform-profile [string]",
70
- description:
71
- "Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default",
72
- parse: parseTransformProfile,
73
- },
74
- {
75
- name: "--reset-cache",
76
- description: "Reset the Metro cache.",
77
- },
78
- {
79
- name: "--config [string]",
80
- description: "Path to the Metro configuration file.",
81
- },
82
- ];
@@ -1,16 +0,0 @@
1
- import type { BundleParameters } from "@rnx-kit/config";
2
-
3
- type DefaultPlugins = Pick<Required<BundleParameters>, "plugins" | "treeShake">;
4
-
5
- const defaultPlugins: DefaultPlugins = {
6
- plugins: [
7
- "@rnx-kit/metro-plugin-cyclic-dependencies-detector",
8
- "@rnx-kit/metro-plugin-duplicates-checker",
9
- "@rnx-kit/metro-plugin-typescript",
10
- ],
11
- treeShake: false,
12
- };
13
-
14
- export function getDefaultBundlerPlugins(): DefaultPlugins {
15
- return defaultPlugins;
16
- }
@@ -1,114 +0,0 @@
1
- import type { HermesOptions } from "@rnx-kit/config";
2
- import { error, info } from "@rnx-kit/console";
3
- import { findPackageDependencyDir } from "@rnx-kit/tools-node/package";
4
- import { requireModuleFromMetro } from "@rnx-kit/tools-react-native/metro";
5
- import { spawnSync } from "child_process";
6
- import * as fs from "fs";
7
- import * as os from "os";
8
- import * as path from "path";
9
-
10
- function hermesBinaryInDir(hermesc: string): string | null {
11
- switch (os.platform()) {
12
- case "darwin":
13
- return path.join(hermesc, "osx-bin", "hermesc");
14
- case "linux":
15
- return path.join(hermesc, "linux64-bin", "hermesc");
16
- case "win32":
17
- return path.join(hermesc, "win64-bin", "hermesc.exe");
18
- default:
19
- return null;
20
- }
21
- }
22
-
23
- function findHermesBinary() {
24
- const locations = [
25
- () => {
26
- const rnPath = findPackageDependencyDir("react-native");
27
- if (!rnPath) {
28
- throw new Error("Cannot find module 'react-native'");
29
- }
30
- return path.join(rnPath, "sdks", "hermesc");
31
- },
32
- () => findPackageDependencyDir("hermes-engine"),
33
- ];
34
-
35
- for (const getLocation of locations) {
36
- const location = getLocation();
37
- if (location) {
38
- const hermesc = hermesBinaryInDir(location);
39
- if (hermesc && fs.existsSync(hermesc)) {
40
- return hermesc;
41
- }
42
- }
43
- }
44
-
45
- return null;
46
- }
47
-
48
- function getOutput(args: string[]): string | null {
49
- const length = args.length;
50
- for (let i = 0; i < length; ++i) {
51
- const flag = args[i];
52
- if (flag === "-out") {
53
- return args[i + 1];
54
- } else if (flag.startsWith("-out=")) {
55
- return flag.substring(5);
56
- }
57
- }
58
- return null;
59
- }
60
-
61
- export function emitBytecode(
62
- input: string,
63
- sourcemap: string | undefined,
64
- options: HermesOptions
65
- ): void {
66
- const cmd = options.command || findHermesBinary();
67
- if (!cmd) {
68
- error("No Hermes compiler was found");
69
- return;
70
- }
71
-
72
- const args = [
73
- "-emit-binary",
74
- // If Hermes can't detect the width of the terminal, it will set the limit
75
- // to "unlimited". Since we might be passing a minified bundle to Hermes,
76
- // limit output width to avoid issues when it outputs diagnostics. See:
77
- // - https://github.com/microsoft/rnx-kit/issues/2416
78
- // - https://github.com/microsoft/rnx-kit/issues/2419
79
- // - https://github.com/microsoft/rnx-kit/issues/2424
80
- "-max-diagnostic-width=80",
81
- ...(options.flags ?? ["-O", "-output-source-map", "-w"]),
82
- ];
83
-
84
- let output = getOutput(args);
85
- if (!output) {
86
- output = input + ".hbc";
87
- args.push("-out", output);
88
- }
89
-
90
- args.push(input);
91
-
92
- info("Emitting bytecode to:", output);
93
- const result = spawnSync(cmd, args, { stdio: "inherit" });
94
- if (result.status !== 0) {
95
- throw result.error;
96
- }
97
-
98
- if (sourcemap && args.includes("-output-source-map")) {
99
- const outputMap = output + ".map";
100
- info(`Combining source maps: ${sourcemap} + ${outputMap}`);
101
-
102
- const options = { encoding: "utf-8" } as const;
103
- const packagerSourcemap = JSON.parse(fs.readFileSync(sourcemap, options));
104
- const compilerSourcemap = JSON.parse(fs.readFileSync(outputMap, options));
105
-
106
- // `composeSourceMaps` was introduced in 0.56 — see
107
- // https://github.com/facebook/metro/commit/6017085bdad96ca5cec39d50038eb5622ce1097b
108
- // @ts-expect-error Property 'composeSourceMaps' does not exist
109
- const { composeSourceMaps } = requireModuleFromMetro("metro-source-map");
110
-
111
- const composed = composeSourceMaps([packagerSourcemap, compilerSourcemap]);
112
- fs.writeFileSync(outputMap, JSON.stringify(composed));
113
- }
114
- }
@@ -1,81 +0,0 @@
1
- import {
2
- getBundleConfig,
3
- getKitConfig,
4
- getPlatformBundleConfig,
5
- } from "@rnx-kit/config";
6
- import type { AllPlatforms } from "@rnx-kit/tools-react-native/platform";
7
- import { getDefaultBundlerPlugins } from "./defaultPlugins";
8
- import type { CliPlatformBundleConfig } from "./types";
9
-
10
- /**
11
- * Get the list of target platforms for bundling.
12
- *
13
- * @param overridePlatform Override platform, typically from the command-line. When given, this overrides the list of target platforms.
14
- * @param targetPlatforms Target platforms, typically from the kit configuration.
15
- * @returns Array of target platforms
16
- */
17
- export function getTargetPlatforms(
18
- overridePlatform?: AllPlatforms,
19
- targetPlatforms?: AllPlatforms[]
20
- ): AllPlatforms[] {
21
- if (overridePlatform) {
22
- return [overridePlatform];
23
- }
24
- if (targetPlatforms && targetPlatforms.length > 0) {
25
- return targetPlatforms;
26
- }
27
- throw new Error(
28
- "No target platforms given. Update the rnx-kit configuration to include a target platform, or provide a target platform on the command-line."
29
- );
30
- }
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
-
43
- /**
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.
49
- *
50
- * @param id Optional identity of the target bundle definition to return
51
- * @param overridePlatform Override platform, typically from the command-line. When given, this overrides the list of target platforms.
52
- * @returns Array of platform-specific bundle configurations
53
- */
54
- export function getCliPlatformBundleConfigs(
55
- id?: string,
56
- overridePlatform?: AllPlatforms
57
- ): CliPlatformBundleConfig[] {
58
- const kitConfig = getKitConfig();
59
- const maybeBundleConfig = kitConfig
60
- ? getBundleConfig(kitConfig, id)
61
- : undefined;
62
- const bundleConfig = maybeBundleConfig ?? {};
63
-
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
73
-
74
- return {
75
- ...getDefaultBundlerPlugins(),
76
- ...getDefaultBundleParameters(platform),
77
- ...platformBundleConfig,
78
- platform,
79
- };
80
- });
81
- }
@@ -1,66 +0,0 @@
1
- import { info } from "@rnx-kit/console";
2
- import type { BundleArgs as MetroBundleArgs } from "@rnx-kit/metro-service";
3
- import { bundle } from "@rnx-kit/metro-service";
4
- import * as fs from "fs";
5
- import type { ConfigT } from "metro-config";
6
- import * as path from "path";
7
- import { customizeMetroConfig } from "../metro-config";
8
- import type { CliPlatformBundleConfig } from "./types";
9
-
10
- function ensureDir(p: string): void {
11
- fs.mkdirSync(p, { recursive: true, mode: 0o755 });
12
- }
13
-
14
- /**
15
- * Run the Metro bundler.
16
- *
17
- * @param metroConfig Metro configuration
18
- * @param bundleConfig Bundle configuration
19
- * @param dev Choose whether or not this will be a "developer" bundle. The alternative is a "production" bundle.
20
- * When `true`, warnings are enabled, and the bundle is not minified by default.
21
- * Further, optimizations like constant folding are disabled.
22
- * When `false`, warnings are disabled and the bundle is minified by default.
23
- * @param minify Optionally choose whether or not the bundle is minified. When not set, minification is controlled by the `dev` property.
24
- * @param output Output bundle format; defaults to plain JS
25
- */
26
- export async function metroBundle(
27
- metroConfig: ConfigT,
28
- bundleConfig: CliPlatformBundleConfig,
29
- dev: boolean,
30
- minify?: boolean,
31
- output = bundle
32
- ): Promise<void> {
33
- info(`Bundling ${bundleConfig.platform}...`);
34
-
35
- if (!dev && bundleConfig.treeShake) {
36
- if (minify != null) {
37
- if (typeof bundleConfig.treeShake === "object") {
38
- bundleConfig.treeShake.minify = minify;
39
- } else {
40
- bundleConfig.treeShake = { minify };
41
- }
42
- }
43
- } else {
44
- bundleConfig.treeShake = false;
45
- }
46
-
47
- customizeMetroConfig(metroConfig, bundleConfig);
48
-
49
- const metroBundleArgs: MetroBundleArgs = {
50
- ...bundleConfig,
51
- dev,
52
- minify,
53
- };
54
-
55
- // ensure all output directories exist
56
- ensureDir(path.dirname(metroBundleArgs.bundleOutput));
57
- if (metroBundleArgs.sourcemapOutput) {
58
- ensureDir(path.dirname(metroBundleArgs.sourcemapOutput));
59
- }
60
- if (metroBundleArgs.assetsDest) {
61
- ensureDir(metroBundleArgs.assetsDest);
62
- }
63
-
64
- // create the bundle
65
- await output(metroBundleArgs, metroConfig);
66
- }
@@ -1,51 +0,0 @@
1
- import { pickValues } from "@rnx-kit/tools-language/properties";
2
- import type { CliPlatformBundleConfig } from "./types";
3
-
4
- type BundleConfigOverrides = Partial<
5
- Pick<
6
- CliPlatformBundleConfig,
7
- | "entryFile"
8
- | "bundleOutput"
9
- | "bundleEncoding"
10
- | "sourcemapOutput"
11
- | "sourcemapSourcesRoot"
12
- | "sourcemapUseAbsolutePath"
13
- | "assetsDest"
14
- | "treeShake"
15
- | "unstableTransformProfile"
16
- | "indexedRamBundle"
17
- | "hermes"
18
- >
19
- >;
20
-
21
- export const overridableCommonBundleOptions: readonly (keyof BundleConfigOverrides)[] =
22
- [
23
- "assetsDest",
24
- "bundleEncoding",
25
- "bundleOutput",
26
- "entryFile",
27
- "sourcemapOutput",
28
- "sourcemapSourcesRoot",
29
- "sourcemapUseAbsolutePath",
30
- "unstableTransformProfile",
31
- ];
32
-
33
- /**
34
- * Apply overrides, if any, to each rnx-kit bundle configuration. Overrides are applied in-place.
35
- *
36
- * @param overrides Optional overrides to apply
37
- * @param configs Array of platform-specific bundle configurations. This is modified if any overrides are applied.
38
- * @param keys Config keys to pick from {@link overrides}
39
- */
40
- export function applyBundleConfigOverrides(
41
- overrides: BundleConfigOverrides,
42
- configs: CliPlatformBundleConfig[],
43
- keys: (keyof BundleConfigOverrides)[]
44
- ): void {
45
- const overridesToApply = pickValues(overrides, keys);
46
- if (overridesToApply) {
47
- for (const config of configs) {
48
- Object.assign(config, overridesToApply);
49
- }
50
- }
51
- }
@@ -1,41 +0,0 @@
1
- import type { BundleParameters } from "@rnx-kit/config";
2
- import type { BundleArgs } from "@rnx-kit/metro-service";
3
- import type { AllPlatforms } from "@rnx-kit/tools-react-native/platform";
4
- import type { TransformProfile } from "metro-babel-transformer";
5
-
6
- export type CLICommonBundleOptions = {
7
- id?: string;
8
- entryFile?: string;
9
- platform?: AllPlatforms;
10
- dev: boolean;
11
- minify?: boolean;
12
- bundleOutput?: string;
13
- bundleEncoding?: BundleArgs["bundleEncoding"];
14
- maxWorkers?: number;
15
- sourcemapOutput?: string;
16
- sourcemapSourcesRoot?: string;
17
- sourcemapUseAbsolutePath?: boolean;
18
- assetsDest?: string;
19
- unstableTransformProfile?: TransformProfile;
20
- resetCache?: boolean;
21
- config?: string;
22
- };
23
-
24
- export type CliPlatformBundleConfig = BundleParameters &
25
- Required<
26
- Pick<
27
- BundleParameters,
28
- | "entryFile"
29
- | "bundleOutput"
30
- | "sourcemapUseAbsolutePath"
31
- | "treeShake"
32
- | "plugins"
33
- >
34
- > & {
35
- unstableTransformProfile?: TransformProfile;
36
-
37
- /**
38
- * Target platform for the bundle
39
- */
40
- platform: AllPlatforms;
41
- };