@react-native/community-cli-plugin 0.73.0

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 (40) hide show
  1. package/README.md +87 -0
  2. package/dist/commands/bundle/assetCatalogIOS.js +74 -0
  3. package/dist/commands/bundle/assetCatalogIOS.js.flow +77 -0
  4. package/dist/commands/bundle/assetPathUtils.js +79 -0
  5. package/dist/commands/bundle/assetPathUtils.js.flow +93 -0
  6. package/dist/commands/bundle/buildBundle.js +112 -0
  7. package/dist/commands/bundle/buildBundle.js.flow +120 -0
  8. package/dist/commands/bundle/bundle.js +44 -0
  9. package/dist/commands/bundle/bundle.js.flow +37 -0
  10. package/dist/commands/bundle/bundleCommandLineArgs.js +116 -0
  11. package/dist/commands/bundle/bundleCommandLineArgs.js.flow +129 -0
  12. package/dist/commands/bundle/filterPlatformAssetScales.js +47 -0
  13. package/dist/commands/bundle/filterPlatformAssetScales.js.flow +45 -0
  14. package/dist/commands/bundle/getAssetDestPathAndroid.js +32 -0
  15. package/dist/commands/bundle/getAssetDestPathAndroid.js.flow +26 -0
  16. package/dist/commands/bundle/getAssetDestPathIOS.js +34 -0
  17. package/dist/commands/bundle/getAssetDestPathIOS.js.flow +28 -0
  18. package/dist/commands/bundle/ramBundle.js +47 -0
  19. package/dist/commands/bundle/ramBundle.js.flow +43 -0
  20. package/dist/commands/bundle/saveAssets.js +138 -0
  21. package/dist/commands/bundle/saveAssets.js.flow +139 -0
  22. package/dist/commands/start/index.js +110 -0
  23. package/dist/commands/start/index.js.flow +97 -0
  24. package/dist/commands/start/runServer.js +123 -0
  25. package/dist/commands/start/runServer.js.flow +156 -0
  26. package/dist/commands/start/startServerInNewWindow.js +132 -0
  27. package/dist/commands/start/startServerInNewWindow.js.flow +125 -0
  28. package/dist/commands/start/watchMode.js +95 -0
  29. package/dist/commands/start/watchMode.js.flow +101 -0
  30. package/dist/index.flow.js +36 -0
  31. package/dist/index.flow.js.flow +16 -0
  32. package/dist/index.js +3 -0
  33. package/dist/index.js.flow +20 -0
  34. package/dist/utils/loadMetroConfig.js +108 -0
  35. package/dist/utils/loadMetroConfig.js.flow +125 -0
  36. package/dist/utils/metroPlatformResolver.js +46 -0
  37. package/dist/utils/metroPlatformResolver.js.flow +44 -0
  38. package/launchPackager.bat +7 -0
  39. package/launchPackager.command +10 -0
  40. package/package.json +29 -0
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # @react-native/community-cli-plugin
2
+
3
+ > This is an internal dependency of React Native. **Please don't depend on it directly.**
4
+
5
+ CLI entry points supporting core React Native development features.
6
+
7
+ Formerly [@react-native-community/cli-plugin-metro](https://www.npmjs.com/package/@react-native-community/cli-plugin-metro).
8
+
9
+ ## Commands
10
+
11
+ ### `start`
12
+
13
+ Start the React Native development server.
14
+
15
+ #### Usage
16
+
17
+ ```sh
18
+ react-native start [options]
19
+ ```
20
+
21
+ #### Options
22
+
23
+ | Option | Description |
24
+ | - | - |
25
+ | `--port <number>` | Set the server port. |
26
+ | `--host <string>` | Set the server host. |
27
+ | `--projectRoot <path>` | Set the path to the project root. |
28
+ | `--watchFolders <list>` | Specify additional folders to be added to the watch list. |
29
+ | `--assetPlugins <list>` | Specify additional asset plugins. |
30
+ | `--sourceExts <list>` | Specify additional source extensions to bundle. |
31
+ | `--max-workers <number>` | Set the maximum number of workers the worker-pool will spawn for transforming files. Defaults to the number of the cores available on your machine. |
32
+ | `--transformer <string>` | Specify a custom transformer. |
33
+ | `--reset-cache` | Remove cached files. |
34
+ | `--custom-log-reporter-path <string>` | Specify a module path exporting a replacement for `TerminalReporter`. |
35
+ | `--https` | Enable HTTPS connections. |
36
+ | `--key <path>`| Specify path to a custom SSL key. |
37
+ | `--cert <path>` | Specify path to a custom SSL cert. |
38
+ | `--config <string>` | Path to the CLI configuration file. |
39
+ | `--no-interactive` | Disable interactive mode. |
40
+
41
+ ### `bundle`
42
+
43
+ Build the bundle for the provided JavaScript entry file.
44
+
45
+ #### Usage
46
+
47
+ ```sh
48
+ react-native bundle --entry-file <path> [options]
49
+ ```
50
+
51
+ #### Options
52
+
53
+ | Option | Description |
54
+ | - | - |
55
+ | `--entry-file <path>` | Set the path to the root JavaScript entry file. |
56
+ | `--platform <string>` | Set the target platform (either `"android"` or `"ios"`). Defaults to `"ios"`. |
57
+ | `--transformer <string>` | Specify a custom transformer. |
58
+ | `--dev [boolean]` | If `false`, warnings are disabled and the bundle is minified. Defaults to `true`. |
59
+ | `--minify [boolean]` | Allows overriding whether bundle is minified. Defaults to `false` if `--dev` is set. Disabling minification can be useful for speeding up production builds for testing purposes. |
60
+ | `--bundle-output <string>` | Specify the path to store the resulting bundle. |
61
+ | `--bundle-encoding <string>` | Specify the encoding for writing the bundle (<https://nodejs.org/api/buffer.html#buffer_buffer>). |
62
+ | `--sourcemap-output <string>` | Specify the path to store the source map file for the resulting bundle. |
63
+ | `--sourcemap-sources-root <string>` | Set the root path for source map entries. |
64
+ | `--sourcemap-use-absolute-path` | Report `SourceMapURL` using its full path. |
65
+ | `--max-workers <number>` | Set the maximum number of workers the worker-pool will spawn for transforming files. Defaults to the number of the cores available on your machine. |
66
+ | `--assets-dest <string>` | Specify the directory path for storing assets referenced in the bundle. |
67
+ | `--reset-cache` | Remove cached files. |
68
+ | `--read-global-cache` | Attempt to fetch transformed JS code from the global cache, if configured. Defaults to `false`. |
69
+ | `--config <string>` | Path to the CLI configuration file. |
70
+
71
+ ### `ram-bundle`
72
+
73
+ Build the [RAM bundle](https://reactnative.dev/docs/ram-bundles-inline-requires) for the provided JavaScript entry file.
74
+
75
+ #### Usage
76
+
77
+ ```sh
78
+ react-native ram-bundle --entry-file <path> [options]
79
+ ```
80
+
81
+ #### Options
82
+
83
+ Accepts all options supported by [`bundle`](#bundle) and the following:
84
+
85
+ | Option | Description |
86
+ | - | - |
87
+ | `--indexed-ram-bundle` | Force the "Indexed RAM" bundle file format, even when building for Android. |
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.cleanAssetCatalog = cleanAssetCatalog;
7
+ exports.getImageSet = getImageSet;
8
+ exports.isCatalogAsset = isCatalogAsset;
9
+ exports.writeImageSet = writeImageSet;
10
+ var _path = _interopRequireDefault(require("path"));
11
+ var _fs = _interopRequireDefault(require("fs"));
12
+ var _assetPathUtils = _interopRequireDefault(require("./assetPathUtils"));
13
+ function _interopRequireDefault(obj) {
14
+ return obj && obj.__esModule ? obj : { default: obj };
15
+ }
16
+ /**
17
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
18
+ *
19
+ * This source code is licensed under the MIT license found in the
20
+ * LICENSE file in the root directory of this source tree.
21
+ *
22
+ *
23
+ * @format
24
+ * @oncall react_native
25
+ */
26
+
27
+ function cleanAssetCatalog(catalogDir) {
28
+ const files = _fs.default
29
+ .readdirSync(catalogDir)
30
+ .filter((file) => file.endsWith(".imageset"));
31
+ for (const file of files) {
32
+ _fs.default.rmSync(_path.default.join(catalogDir, file));
33
+ }
34
+ }
35
+ function getImageSet(catalogDir, asset, scales) {
36
+ const fileName = _assetPathUtils.default.getResourceIdentifier(asset);
37
+ return {
38
+ basePath: _path.default.join(catalogDir, `${fileName}.imageset`),
39
+ files: scales.map((scale, idx) => {
40
+ const suffix = scale === 1 ? "" : `@${scale}x`;
41
+ return {
42
+ name: `${fileName + suffix}.${asset.type}`,
43
+ scale,
44
+ src: asset.files[idx],
45
+ };
46
+ }),
47
+ };
48
+ }
49
+ function isCatalogAsset(asset) {
50
+ return asset.type === "png" || asset.type === "jpg" || asset.type === "jpeg";
51
+ }
52
+ function writeImageSet(imageSet) {
53
+ _fs.default.mkdirSync(imageSet.basePath, {
54
+ recursive: true,
55
+ });
56
+ for (const file of imageSet.files) {
57
+ const dest = _path.default.join(imageSet.basePath, file.name);
58
+ _fs.default.copyFileSync(file.src, dest);
59
+ }
60
+ _fs.default.writeFileSync(
61
+ _path.default.join(imageSet.basePath, "Contents.json"),
62
+ JSON.stringify({
63
+ images: imageSet.files.map((file) => ({
64
+ filename: file.name,
65
+ idiom: "universal",
66
+ scale: `${file.scale}x`,
67
+ })),
68
+ info: {
69
+ author: "xcode",
70
+ version: 1,
71
+ },
72
+ })
73
+ );
74
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
8
+ * @format
9
+ * @oncall react_native
10
+ */
11
+
12
+ import type {AssetData} from 'metro/src/Assets';
13
+
14
+ import path from 'path';
15
+ import fs from 'fs';
16
+ import assetPathUtils from './assetPathUtils';
17
+
18
+ export function cleanAssetCatalog(catalogDir: string): void {
19
+ const files = fs
20
+ .readdirSync(catalogDir)
21
+ .filter(file => file.endsWith('.imageset'));
22
+ for (const file of files) {
23
+ fs.rmSync(path.join(catalogDir, file));
24
+ }
25
+ }
26
+
27
+ type ImageSet = {
28
+ basePath: string,
29
+ files: {name: string, src: string, scale: number}[],
30
+ };
31
+
32
+ export function getImageSet(
33
+ catalogDir: string,
34
+ asset: AssetData,
35
+ scales: $ReadOnlyArray<number>,
36
+ ): ImageSet {
37
+ const fileName = assetPathUtils.getResourceIdentifier(asset);
38
+ return {
39
+ basePath: path.join(catalogDir, `${fileName}.imageset`),
40
+ files: scales.map((scale, idx) => {
41
+ const suffix = scale === 1 ? '' : `@${scale}x`;
42
+ return {
43
+ name: `${fileName + suffix}.${asset.type}`,
44
+ scale,
45
+ src: asset.files[idx],
46
+ };
47
+ }),
48
+ };
49
+ }
50
+
51
+ export function isCatalogAsset(asset: AssetData): boolean {
52
+ return asset.type === 'png' || asset.type === 'jpg' || asset.type === 'jpeg';
53
+ }
54
+
55
+ export function writeImageSet(imageSet: ImageSet): void {
56
+ fs.mkdirSync(imageSet.basePath, {recursive: true});
57
+
58
+ for (const file of imageSet.files) {
59
+ const dest = path.join(imageSet.basePath, file.name);
60
+ fs.copyFileSync(file.src, dest);
61
+ }
62
+
63
+ fs.writeFileSync(
64
+ path.join(imageSet.basePath, 'Contents.json'),
65
+ JSON.stringify({
66
+ images: imageSet.files.map(file => ({
67
+ filename: file.name,
68
+ idiom: 'universal',
69
+ scale: `${file.scale}x`,
70
+ })),
71
+ info: {
72
+ author: 'xcode',
73
+ version: 1,
74
+ },
75
+ }),
76
+ );
77
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ /**
8
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
9
+ *
10
+ * This source code is licensed under the MIT license found in the
11
+ * LICENSE file in the root directory of this source tree.
12
+ *
13
+ *
14
+ * @format
15
+ * @oncall react_native
16
+ */
17
+
18
+ /**
19
+ * FIXME: using number to represent discrete scale numbers is fragile in essence because of
20
+ * floating point numbers imprecision.
21
+ */
22
+ function getAndroidAssetSuffix(scale) {
23
+ switch (scale) {
24
+ case 0.75:
25
+ return "ldpi";
26
+ case 1:
27
+ return "mdpi";
28
+ case 1.5:
29
+ return "hdpi";
30
+ case 2:
31
+ return "xhdpi";
32
+ case 3:
33
+ return "xxhdpi";
34
+ case 4:
35
+ return "xxxhdpi";
36
+ default:
37
+ return "";
38
+ }
39
+ }
40
+
41
+ // See https://developer.android.com/guide/topics/resources/drawable-resource.html
42
+ const drawableFileTypes = new Set(["gif", "jpeg", "jpg", "png", "webp", "xml"]);
43
+ function getAndroidResourceFolderName(asset, scale) {
44
+ if (!drawableFileTypes.has(asset.type)) {
45
+ return "raw";
46
+ }
47
+ const suffix = getAndroidAssetSuffix(scale);
48
+ if (!suffix) {
49
+ throw new Error(
50
+ `Don't know which android drawable suffix to use for asset: ${JSON.stringify(
51
+ asset
52
+ )}`
53
+ );
54
+ }
55
+ return `drawable-${suffix}`;
56
+ }
57
+ function getResourceIdentifier(asset) {
58
+ const folderPath = getBasePath(asset);
59
+ return `${folderPath}/${asset.name}`
60
+ .toLowerCase()
61
+ .replace(/\//g, "_") // Encode folder structure in file name
62
+ .replace(/([^a-z0-9_])/g, "") // Remove illegal chars
63
+ .replace(/^assets_/, ""); // Remove "assets_" prefix
64
+ }
65
+
66
+ function getBasePath(asset) {
67
+ let basePath = asset.httpServerLocation;
68
+ if (basePath[0] === "/") {
69
+ basePath = basePath.substr(1);
70
+ }
71
+ return basePath;
72
+ }
73
+ var _default = {
74
+ getAndroidAssetSuffix,
75
+ getAndroidResourceFolderName,
76
+ getResourceIdentifier,
77
+ getBasePath,
78
+ };
79
+ exports.default = _default;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
8
+ * @format
9
+ * @oncall react_native
10
+ */
11
+
12
+ export type PackagerAsset = $ReadOnly<{
13
+ httpServerLocation: string,
14
+ name: string,
15
+ type: string,
16
+ ...
17
+ }>;
18
+
19
+ /**
20
+ * FIXME: using number to represent discrete scale numbers is fragile in essence because of
21
+ * floating point numbers imprecision.
22
+ */
23
+ function getAndroidAssetSuffix(scale: number): string {
24
+ switch (scale) {
25
+ case 0.75:
26
+ return 'ldpi';
27
+ case 1:
28
+ return 'mdpi';
29
+ case 1.5:
30
+ return 'hdpi';
31
+ case 2:
32
+ return 'xhdpi';
33
+ case 3:
34
+ return 'xxhdpi';
35
+ case 4:
36
+ return 'xxxhdpi';
37
+ default:
38
+ return '';
39
+ }
40
+ }
41
+
42
+ // See https://developer.android.com/guide/topics/resources/drawable-resource.html
43
+ const drawableFileTypes = new Set<string>([
44
+ 'gif',
45
+ 'jpeg',
46
+ 'jpg',
47
+ 'png',
48
+ 'webp',
49
+ 'xml',
50
+ ]);
51
+
52
+ function getAndroidResourceFolderName(
53
+ asset: PackagerAsset,
54
+ scale: number,
55
+ ): string {
56
+ if (!drawableFileTypes.has(asset.type)) {
57
+ return 'raw';
58
+ }
59
+ const suffix = getAndroidAssetSuffix(scale);
60
+ if (!suffix) {
61
+ throw new Error(
62
+ `Don't know which android drawable suffix to use for asset: ${JSON.stringify(
63
+ asset,
64
+ )}`,
65
+ );
66
+ }
67
+ const androidFolder = `drawable-${suffix}`;
68
+ return androidFolder;
69
+ }
70
+
71
+ function getResourceIdentifier(asset: PackagerAsset): string {
72
+ const folderPath = getBasePath(asset);
73
+ return `${folderPath}/${asset.name}`
74
+ .toLowerCase()
75
+ .replace(/\//g, '_') // Encode folder structure in file name
76
+ .replace(/([^a-z0-9_])/g, '') // Remove illegal chars
77
+ .replace(/^assets_/, ''); // Remove "assets_" prefix
78
+ }
79
+
80
+ function getBasePath(asset: PackagerAsset): string {
81
+ let basePath = asset.httpServerLocation;
82
+ if (basePath[0] === '/') {
83
+ basePath = basePath.substr(1);
84
+ }
85
+ return basePath;
86
+ }
87
+
88
+ export default {
89
+ getAndroidAssetSuffix,
90
+ getAndroidResourceFolderName,
91
+ getResourceIdentifier,
92
+ getBasePath,
93
+ };
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.unstable_buildBundleWithConfig = exports.default = void 0;
7
+ var _Server = _interopRequireDefault(require("metro/src/Server"));
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _chalk = _interopRequireDefault(require("chalk"));
10
+ var _saveAssets = _interopRequireDefault(require("./saveAssets"));
11
+ var _loadMetroConfig = _interopRequireDefault(
12
+ require("../../utils/loadMetroConfig")
13
+ );
14
+ var _cliTools = require("@react-native-community/cli-tools");
15
+ function _interopRequireDefault(obj) {
16
+ return obj && obj.__esModule ? obj : { default: obj };
17
+ }
18
+ /**
19
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
20
+ *
21
+ * This source code is licensed under the MIT license found in the
22
+ * LICENSE file in the root directory of this source tree.
23
+ *
24
+ *
25
+ * @format
26
+ * @oncall react_native
27
+ */
28
+
29
+ const outputBundle = require("metro/src/shared/output/bundle");
30
+ async function buildBundle(args, ctx, output = outputBundle) {
31
+ const config = await (0, _loadMetroConfig.default)(ctx, {
32
+ maxWorkers: args.maxWorkers,
33
+ resetCache: args.resetCache,
34
+ config: args.config,
35
+ });
36
+ return buildBundleWithConfig(args, config, output);
37
+ }
38
+ async function buildBundleWithConfig(args, config, output = outputBundle) {
39
+ if (config.resolver.platforms.indexOf(args.platform) === -1) {
40
+ _cliTools.logger.error(
41
+ `Invalid platform ${
42
+ args.platform ? `"${_chalk.default.bold(args.platform)}" ` : ""
43
+ }selected.`
44
+ );
45
+ _cliTools.logger.info(
46
+ `Available platforms are: ${config.resolver.platforms
47
+ .map((x) => `"${_chalk.default.bold(x)}"`)
48
+ .join(
49
+ ", "
50
+ )}. If you are trying to bundle for an out-of-tree platform, it may not be installed.`
51
+ );
52
+ throw new Error("Bundling failed");
53
+ }
54
+
55
+ // This is used by a bazillion of npm modules we don't control so we don't
56
+ // have other choice than defining it as an env variable here.
57
+ process.env.NODE_ENV = args.dev ? "development" : "production";
58
+ let sourceMapUrl = args.sourcemapOutput;
59
+ if (sourceMapUrl && !args.sourcemapUseAbsolutePath) {
60
+ sourceMapUrl = _path.default.basename(sourceMapUrl);
61
+ }
62
+
63
+ // $FlowIgnore[prop-missing]
64
+ const requestOpts = {
65
+ entryFile: args.entryFile,
66
+ sourceMapUrl,
67
+ dev: args.dev,
68
+ minify: args.minify !== undefined ? args.minify : !args.dev,
69
+ platform: args.platform,
70
+ unstable_transformProfile: args.unstableTransformProfile,
71
+ };
72
+ const server = new _Server.default(config);
73
+ try {
74
+ const bundle = await output.build(server, requestOpts);
75
+
76
+ // $FlowIgnore[class-object-subtyping]
77
+ // $FlowIgnore[incompatible-call]
78
+ await output.save(bundle, args, _cliTools.logger.info);
79
+
80
+ // Save the assets of the bundle
81
+ const outputAssets = await server.getAssets({
82
+ ..._Server.default.DEFAULT_BUNDLE_OPTIONS,
83
+ ...requestOpts,
84
+ bundleType: "todo",
85
+ });
86
+
87
+ // When we're done saving bundle output and the assets, we're done.
88
+ return await (0, _saveAssets.default)(
89
+ outputAssets,
90
+ args.platform,
91
+ args.assetsDest,
92
+ args.assetCatalogDest
93
+ );
94
+ } finally {
95
+ server.end();
96
+ }
97
+ }
98
+
99
+ /**
100
+ * UNSTABLE: This function is likely to be relocated and its API changed in
101
+ * the near future. `@react-native/community-cli-plugin` should not be directly
102
+ * depended on by projects or integrators -- this is exported for legacy
103
+ * compatibility.
104
+ *
105
+ * Create a bundle using a pre-loaded Metro config. The config can be
106
+ * re-used for several bundling calls if multiple platforms are being
107
+ * bundled.
108
+ */
109
+ const unstable_buildBundleWithConfig = buildBundleWithConfig;
110
+ exports.unstable_buildBundleWithConfig = unstable_buildBundleWithConfig;
111
+ var _default = buildBundle;
112
+ exports.default = _default;
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
8
+ * @format
9
+ * @oncall react_native
10
+ */
11
+
12
+ import type {Config} from '@react-native-community/cli-types';
13
+ import type {RequestOptions} from 'metro/src/shared/types.flow';
14
+ import type {ConfigT} from 'metro-config';
15
+ import type {CommandLineArgs} from './bundleCommandLineArgs';
16
+
17
+ import Server from 'metro/src/Server';
18
+ const outputBundle = require('metro/src/shared/output/bundle');
19
+ import path from 'path';
20
+ import chalk from 'chalk';
21
+ import saveAssets from './saveAssets';
22
+ import {default as loadMetroConfig} from '../../utils/loadMetroConfig';
23
+ import {logger} from '@react-native-community/cli-tools';
24
+
25
+ async function buildBundle(
26
+ args: CommandLineArgs,
27
+ ctx: Config,
28
+ output: typeof outputBundle = outputBundle,
29
+ ): Promise<void> {
30
+ const config = await loadMetroConfig(ctx, {
31
+ maxWorkers: args.maxWorkers,
32
+ resetCache: args.resetCache,
33
+ config: args.config,
34
+ });
35
+
36
+ return buildBundleWithConfig(args, config, output);
37
+ }
38
+
39
+ async function buildBundleWithConfig(
40
+ args: CommandLineArgs,
41
+ config: ConfigT,
42
+ output: typeof outputBundle = outputBundle,
43
+ ): Promise<void> {
44
+ if (config.resolver.platforms.indexOf(args.platform) === -1) {
45
+ logger.error(
46
+ `Invalid platform ${
47
+ args.platform ? `"${chalk.bold(args.platform)}" ` : ''
48
+ }selected.`,
49
+ );
50
+
51
+ logger.info(
52
+ `Available platforms are: ${config.resolver.platforms
53
+ .map(x => `"${chalk.bold(x)}"`)
54
+ .join(
55
+ ', ',
56
+ )}. If you are trying to bundle for an out-of-tree platform, it may not be installed.`,
57
+ );
58
+
59
+ throw new Error('Bundling failed');
60
+ }
61
+
62
+ // This is used by a bazillion of npm modules we don't control so we don't
63
+ // have other choice than defining it as an env variable here.
64
+ process.env.NODE_ENV = args.dev ? 'development' : 'production';
65
+
66
+ let sourceMapUrl = args.sourcemapOutput;
67
+ if (sourceMapUrl && !args.sourcemapUseAbsolutePath) {
68
+ sourceMapUrl = path.basename(sourceMapUrl);
69
+ }
70
+
71
+ // $FlowIgnore[prop-missing]
72
+ const requestOpts: RequestOptions & {...} = {
73
+ entryFile: args.entryFile,
74
+ sourceMapUrl,
75
+ dev: args.dev,
76
+ minify: args.minify !== undefined ? args.minify : !args.dev,
77
+ platform: args.platform,
78
+ unstable_transformProfile: args.unstableTransformProfile,
79
+ };
80
+ const server = new Server(config);
81
+
82
+ try {
83
+ const bundle = await output.build(server, requestOpts);
84
+
85
+ // $FlowIgnore[class-object-subtyping]
86
+ // $FlowIgnore[incompatible-call]
87
+ await output.save(bundle, args, logger.info);
88
+
89
+ // Save the assets of the bundle
90
+ const outputAssets = await server.getAssets({
91
+ ...Server.DEFAULT_BUNDLE_OPTIONS,
92
+ ...requestOpts,
93
+ bundleType: 'todo',
94
+ });
95
+
96
+ // When we're done saving bundle output and the assets, we're done.
97
+ return await saveAssets(
98
+ outputAssets,
99
+ args.platform,
100
+ args.assetsDest,
101
+ args.assetCatalogDest,
102
+ );
103
+ } finally {
104
+ server.end();
105
+ }
106
+ }
107
+
108
+ /**
109
+ * UNSTABLE: This function is likely to be relocated and its API changed in
110
+ * the near future. `@react-native/community-cli-plugin` should not be directly
111
+ * depended on by projects or integrators -- this is exported for legacy
112
+ * compatibility.
113
+ *
114
+ * Create a bundle using a pre-loaded Metro config. The config can be
115
+ * re-used for several bundling calls if multiple platforms are being
116
+ * bundled.
117
+ */
118
+ export const unstable_buildBundleWithConfig = buildBundleWithConfig;
119
+
120
+ export default buildBundle;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.bundleWithOutput = bundleWithOutput;
7
+ exports.default = void 0;
8
+ var _buildBundle = _interopRequireDefault(require("./buildBundle"));
9
+ var _bundleCommandLineArgs = _interopRequireDefault(
10
+ require("./bundleCommandLineArgs")
11
+ );
12
+ function _interopRequireDefault(obj) {
13
+ return obj && obj.__esModule ? obj : { default: obj };
14
+ }
15
+ /**
16
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
17
+ *
18
+ * This source code is licensed under the MIT license found in the
19
+ * LICENSE file in the root directory of this source tree.
20
+ *
21
+ *
22
+ * @format
23
+ * @oncall react_native
24
+ */
25
+
26
+ /**
27
+ * Builds the bundle starting to look for dependencies at the given entry path.
28
+ */
29
+ function bundleWithOutput(
30
+ _,
31
+ config,
32
+ args,
33
+ output // untyped metro/src/shared/output/bundle or metro/src/shared/output/RamBundle
34
+ ) {
35
+ return (0, _buildBundle.default)(args, config, output);
36
+ }
37
+ const bundleCommand = {
38
+ name: "bundle",
39
+ description: "Build the bundle for the provided JavaScript entry file.",
40
+ func: bundleWithOutput,
41
+ options: _bundleCommandLineArgs.default,
42
+ };
43
+ var _default = bundleCommand;
44
+ exports.default = _default;