@react-native/community-cli-plugin 0.73.0-nightly-20230922-52104c6ee

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 (38) hide show
  1. package/README.md +91 -0
  2. package/dist/commands/bundle/assetCatalogIOS.js +74 -0
  3. package/dist/commands/bundle/assetCatalogIOS.js.flow +29 -0
  4. package/dist/commands/bundle/assetPathUtils.js +79 -0
  5. package/dist/commands/bundle/assetPathUtils.js.flow +39 -0
  6. package/dist/commands/bundle/buildBundle.js +121 -0
  7. package/dist/commands/bundle/buildBundle.js.flow +64 -0
  8. package/dist/commands/bundle/filterPlatformAssetScales.js +47 -0
  9. package/dist/commands/bundle/filterPlatformAssetScales.js.flow +17 -0
  10. package/dist/commands/bundle/getAssetDestPathAndroid.js +32 -0
  11. package/dist/commands/bundle/getAssetDestPathAndroid.js.flow +19 -0
  12. package/dist/commands/bundle/getAssetDestPathIOS.js +34 -0
  13. package/dist/commands/bundle/getAssetDestPathIOS.js.flow +19 -0
  14. package/dist/commands/bundle/index.js +124 -0
  15. package/dist/commands/bundle/index.js.flow +18 -0
  16. package/dist/commands/bundle/saveAssets.js +138 -0
  17. package/dist/commands/bundle/saveAssets.js.flow +21 -0
  18. package/dist/commands/ram-bundle/index.js +45 -0
  19. package/dist/commands/ram-bundle/index.js.flow +15 -0
  20. package/dist/commands/start/attachKeyHandlers.js +109 -0
  21. package/dist/commands/start/attachKeyHandlers.js.flow +22 -0
  22. package/dist/commands/start/index.js +105 -0
  23. package/dist/commands/start/index.js.flow +18 -0
  24. package/dist/commands/start/runServer.js +173 -0
  25. package/dist/commands/start/runServer.js.flow +38 -0
  26. package/dist/index.flow.js +36 -0
  27. package/dist/index.flow.js.flow +16 -0
  28. package/dist/index.js +3 -0
  29. package/dist/index.js.flow +12 -0
  30. package/dist/utils/KeyPressHandler.js +91 -0
  31. package/dist/utils/KeyPressHandler.js.flow +22 -0
  32. package/dist/utils/isDevServerRunning.js +74 -0
  33. package/dist/utils/isDevServerRunning.js.flow +27 -0
  34. package/dist/utils/loadMetroConfig.js +107 -0
  35. package/dist/utils/loadMetroConfig.js.flow +33 -0
  36. package/dist/utils/metroPlatformResolver.js +46 -0
  37. package/dist/utils/metroPlatformResolver.js.flow +30 -0
  38. package/package.json +43 -0
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ var _buildBundle = _interopRequireDefault(require("./buildBundle"));
9
+ function _interopRequireDefault(obj) {
10
+ return obj && obj.__esModule ? obj : { default: obj };
11
+ }
12
+ /**
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ *
19
+ * @format
20
+ * @oncall react_native
21
+ */
22
+
23
+ const bundleCommand = {
24
+ name: "bundle",
25
+ description: "Build the bundle for the provided JavaScript entry file.",
26
+ func: _buildBundle.default,
27
+ options: [
28
+ {
29
+ name: "--entry-file <path>",
30
+ description:
31
+ "Path to the root JS file, either absolute or relative to JS root",
32
+ },
33
+ {
34
+ name: "--platform <string>",
35
+ description: 'Either "ios" or "android"',
36
+ default: "ios",
37
+ },
38
+ {
39
+ name: "--transformer <string>",
40
+ description: "Specify a custom transformer to be used",
41
+ },
42
+ {
43
+ name: "--dev [boolean]",
44
+ description: "If false, warnings are disabled and the bundle is minified",
45
+ parse: (val) => val !== "false",
46
+ default: true,
47
+ },
48
+ {
49
+ name: "--minify [boolean]",
50
+ description:
51
+ "Allows overriding whether bundle is minified. This defaults to " +
52
+ "false if dev is true, and true if dev is false. Disabling minification " +
53
+ "can be useful for speeding up production builds for testing purposes.",
54
+ parse: (val) => val !== "false",
55
+ },
56
+ {
57
+ name: "--bundle-output <string>",
58
+ description:
59
+ "File name where to store the resulting bundle, ex. /tmp/groups.bundle",
60
+ },
61
+ {
62
+ name: "--bundle-encoding <string>",
63
+ description:
64
+ "Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).",
65
+ default: "utf8",
66
+ },
67
+ {
68
+ name: "--max-workers <number>",
69
+ description:
70
+ "Specifies the maximum number of workers the worker-pool " +
71
+ "will spawn for transforming files. This defaults to the number of the " +
72
+ "cores available on your machine.",
73
+ parse: (workers) => Number(workers),
74
+ },
75
+ {
76
+ name: "--sourcemap-output <string>",
77
+ description:
78
+ "File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map",
79
+ },
80
+ {
81
+ name: "--sourcemap-sources-root <string>",
82
+ description:
83
+ "Path to make sourcemap's sources entries relative to, ex. /root/dir",
84
+ },
85
+ {
86
+ name: "--sourcemap-use-absolute-path",
87
+ description: "Report SourceMapURL using its full path",
88
+ default: false,
89
+ },
90
+ {
91
+ name: "--assets-dest <string>",
92
+ description:
93
+ "Directory name where to store assets referenced in the bundle",
94
+ },
95
+ {
96
+ name: "--unstable-transform-profile <string>",
97
+ description:
98
+ "Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default",
99
+ default: "default",
100
+ },
101
+ {
102
+ name: "--asset-catalog-dest [string]",
103
+ description: "Path where to create an iOS Asset Catalog for images",
104
+ },
105
+ {
106
+ name: "--reset-cache",
107
+ description: "Removes cached files",
108
+ default: false,
109
+ },
110
+ {
111
+ name: "--read-global-cache",
112
+ description:
113
+ "Try to fetch transformed JS code from the global cache, if configured.",
114
+ default: false,
115
+ },
116
+ {
117
+ name: "--config <string>",
118
+ description: "Path to the CLI configuration file",
119
+ parse: (val) => _path.default.resolve(val),
120
+ },
121
+ ],
122
+ };
123
+ var _default = bundleCommand;
124
+ exports.default = _default;
@@ -0,0 +1,18 @@
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 strict-local
8
+ * @format
9
+ * @oncall react_native
10
+ */
11
+
12
+ import type { Command } from "@react-native-community/cli-types";
13
+
14
+ export type { BundleCommandArgs } from "./buildBundle";
15
+
16
+ declare const bundleCommand: Command;
17
+
18
+ declare export default bundleCommand;
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ var _cliTools = require("@react-native-community/cli-tools");
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _assetCatalogIOS = require("./assetCatalogIOS");
11
+ var _filterPlatformAssetScales = _interopRequireDefault(
12
+ require("./filterPlatformAssetScales")
13
+ );
14
+ var _getAssetDestPathAndroid = _interopRequireDefault(
15
+ require("./getAssetDestPathAndroid")
16
+ );
17
+ var _getAssetDestPathIOS = _interopRequireDefault(
18
+ require("./getAssetDestPathIOS")
19
+ );
20
+ function _interopRequireDefault(obj) {
21
+ return obj && obj.__esModule ? obj : { default: obj };
22
+ }
23
+ /**
24
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
25
+ *
26
+ * This source code is licensed under the MIT license found in the
27
+ * LICENSE file in the root directory of this source tree.
28
+ *
29
+ *
30
+ * @format
31
+ * @oncall react_native
32
+ */
33
+
34
+ async function saveAssets(assets, platform, assetsDest, assetCatalogDest) {
35
+ if (assetsDest == null) {
36
+ _cliTools.logger.warn("Assets destination folder is not set, skipping...");
37
+ return;
38
+ }
39
+ const filesToCopy = {};
40
+ const getAssetDestPath =
41
+ platform === "android"
42
+ ? _getAssetDestPathAndroid.default
43
+ : _getAssetDestPathIOS.default;
44
+ const addAssetToCopy = (asset) => {
45
+ const validScales = new Set(
46
+ (0, _filterPlatformAssetScales.default)(platform, asset.scales)
47
+ );
48
+ asset.scales.forEach((scale, idx) => {
49
+ if (!validScales.has(scale)) {
50
+ return;
51
+ }
52
+ const src = asset.files[idx];
53
+ const dest = _path.default.join(
54
+ assetsDest,
55
+ getAssetDestPath(asset, scale)
56
+ );
57
+ filesToCopy[src] = dest;
58
+ });
59
+ };
60
+ if (platform === "ios" && assetCatalogDest != null) {
61
+ // Use iOS Asset Catalog for images. This will allow Apple app thinning to
62
+ // remove unused scales from the optimized bundle.
63
+ const catalogDir = _path.default.join(
64
+ assetCatalogDest,
65
+ "RNAssets.xcassets"
66
+ );
67
+ if (!_fs.default.existsSync(catalogDir)) {
68
+ _cliTools.logger.error(
69
+ `Could not find asset catalog 'RNAssets.xcassets' in ${assetCatalogDest}. Make sure to create it if it does not exist.`
70
+ );
71
+ return;
72
+ }
73
+ _cliTools.logger.info("Adding images to asset catalog", catalogDir);
74
+ (0, _assetCatalogIOS.cleanAssetCatalog)(catalogDir);
75
+ for (const asset of assets) {
76
+ if ((0, _assetCatalogIOS.isCatalogAsset)(asset)) {
77
+ const imageSet = (0, _assetCatalogIOS.getImageSet)(
78
+ catalogDir,
79
+ asset,
80
+ (0, _filterPlatformAssetScales.default)(platform, asset.scales)
81
+ );
82
+ (0, _assetCatalogIOS.writeImageSet)(imageSet);
83
+ } else {
84
+ addAssetToCopy(asset);
85
+ }
86
+ }
87
+ _cliTools.logger.info("Done adding images to asset catalog");
88
+ } else {
89
+ assets.forEach(addAssetToCopy);
90
+ }
91
+ return copyAll(filesToCopy);
92
+ }
93
+ function copyAll(filesToCopy) {
94
+ const queue = Object.keys(filesToCopy);
95
+ if (queue.length === 0) {
96
+ return Promise.resolve();
97
+ }
98
+ _cliTools.logger.info(`Copying ${queue.length} asset files`);
99
+ return new Promise((resolve, reject) => {
100
+ const copyNext = (error) => {
101
+ if (error) {
102
+ reject(error);
103
+ return;
104
+ }
105
+ if (queue.length === 0) {
106
+ _cliTools.logger.info("Done copying assets");
107
+ resolve();
108
+ } else {
109
+ // queue.length === 0 is checked in previous branch, so this is string
110
+ const src = queue.shift();
111
+ const dest = filesToCopy[src];
112
+ copy(src, dest, copyNext);
113
+ }
114
+ };
115
+ copyNext();
116
+ });
117
+ }
118
+ function copy(src, dest, callback) {
119
+ const destDir = _path.default.dirname(dest);
120
+ _fs.default.mkdir(
121
+ destDir,
122
+ {
123
+ recursive: true,
124
+ },
125
+ (err) => {
126
+ if (err) {
127
+ callback(err);
128
+ return;
129
+ }
130
+ _fs.default
131
+ .createReadStream(src)
132
+ .pipe(_fs.default.createWriteStream(dest))
133
+ .on("finish", callback);
134
+ }
135
+ );
136
+ }
137
+ var _default = saveAssets;
138
+ exports.default = _default;
@@ -0,0 +1,21 @@
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 strict-local
8
+ * @format
9
+ * @oncall react_native
10
+ */
11
+
12
+ import type { AssetData } from "metro/src/Assets";
13
+
14
+ declare function saveAssets(
15
+ assets: $ReadOnlyArray<AssetData>,
16
+ platform: string,
17
+ assetsDest?: string,
18
+ assetCatalogDest?: string
19
+ ): Promise<void>;
20
+
21
+ declare export default saveAssets;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ var _RamBundle = _interopRequireDefault(
8
+ require("metro/src/shared/output/RamBundle")
9
+ );
10
+ var _bundle = _interopRequireDefault(require("../bundle"));
11
+ var _buildBundle = _interopRequireDefault(require("../bundle/buildBundle"));
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
+ const ramBundleCommand = {
27
+ name: "ram-bundle",
28
+ description:
29
+ "Build the RAM bundle for the provided JavaScript entry file. See https://reactnative.dev/docs/ram-bundles-inline-requires.",
30
+ func: (argv, config, args) => {
31
+ return (0, _buildBundle.default)(argv, config, args, _RamBundle.default);
32
+ },
33
+ options: [
34
+ // $FlowFixMe[incompatible-type] options is nonnull
35
+ ..._bundle.default.options,
36
+ {
37
+ name: "--indexed-ram-bundle",
38
+ description:
39
+ 'Force the "Indexed RAM" bundle file format, even when building for android',
40
+ default: false,
41
+ },
42
+ ],
43
+ };
44
+ var _default = ramBundleCommand;
45
+ exports.default = _default;
@@ -0,0 +1,15 @@
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 strict-local
8
+ * @format
9
+ * @oncall react_native
10
+ */
11
+
12
+ import type { Command } from "@react-native-community/cli-types";
13
+ declare const ramBundleCommand: Command;
14
+
15
+ declare export default ramBundleCommand;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = attachKeyHandlers;
7
+ var _cliTools = require("@react-native-community/cli-tools");
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+ var _execa = _interopRequireDefault(require("execa"));
10
+ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
11
+ var _readline = _interopRequireDefault(require("readline"));
12
+ var _KeyPressHandler = require("../../utils/KeyPressHandler");
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
+ const CTRL_C = "\u0003";
28
+ const CTRL_D = "\u0004";
29
+ function attachKeyHandlers({
30
+ cliConfig,
31
+ serverInstance,
32
+ devServerUrl,
33
+ messageSocket,
34
+ }) {
35
+ if (process.stdin.isTTY !== true) {
36
+ _cliTools.logger.debug(
37
+ "Interactive mode is not supported in this environment"
38
+ );
39
+ return;
40
+ }
41
+ _readline.default.emitKeypressEvents(process.stdin);
42
+ // $FlowIgnore[prop-missing]
43
+ process.stdin.setRawMode(true);
44
+ const execaOptions = {
45
+ env: {
46
+ FORCE_COLOR: _chalk.default.supportsColor ? "true" : "false",
47
+ },
48
+ };
49
+ const keyPressHandler = new _KeyPressHandler.KeyPressHandler(async (key) => {
50
+ switch (key) {
51
+ case "r":
52
+ messageSocket.broadcast("reload", null);
53
+ _cliTools.logger.info("Reloading connected app(s)...");
54
+ break;
55
+ case "d":
56
+ messageSocket.broadcast("devMenu", null);
57
+ _cliTools.logger.info("Opening Dev Menu...");
58
+ break;
59
+ case "i":
60
+ _cliTools.logger.info("Opening app on iOS...");
61
+ (0, _execa.default)(
62
+ "npx",
63
+ [
64
+ "react-native",
65
+ "run-ios",
66
+ ...(cliConfig.project.ios?.watchModeCommandParams ?? []),
67
+ ],
68
+ execaOptions
69
+ ).stdout?.pipe(process.stdout);
70
+ break;
71
+ case "a":
72
+ _cliTools.logger.info("Opening app on Android...");
73
+ (0, _execa.default)(
74
+ "npx",
75
+ [
76
+ "react-native",
77
+ "run-android",
78
+ ...(cliConfig.project.android?.watchModeCommandParams ?? []),
79
+ ],
80
+ execaOptions
81
+ ).stdout?.pipe(process.stdout);
82
+ break;
83
+ case "j":
84
+ await (0, _nodeFetch.default)(devServerUrl + "/open-debugger", {
85
+ method: "POST",
86
+ });
87
+ break;
88
+ case CTRL_C:
89
+ case CTRL_D:
90
+ _cliTools.logger.info("Stopping server");
91
+ listener?.({
92
+ pause: true,
93
+ });
94
+ serverInstance.close(() => {
95
+ process.emit("SIGINT");
96
+ process.exit();
97
+ });
98
+ }
99
+ });
100
+ const listener = keyPressHandler.createInteractionListener();
101
+ keyPressHandler.startInterceptingKeyStrokes();
102
+ _cliTools.logger.log(`
103
+ ${_chalk.default.bold("i")} - run on iOS
104
+ ${_chalk.default.bold("a")} - run on Android
105
+ ${_chalk.default.bold("d")} - open Dev Menu
106
+ ${_chalk.default.bold("j")} - open debugger
107
+ ${_chalk.default.bold("r")} - reload app
108
+ `);
109
+ }
@@ -0,0 +1,22 @@
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 strict-local
8
+ * @format
9
+ * @oncall react_native
10
+ */
11
+
12
+ import type { Config } from "@react-native-community/cli-types";
13
+
14
+ declare export default function attachKeyHandlers({
15
+ cliConfig: Config,
16
+ devServerUrl: string,
17
+ serverInstance: http$Server | https$Server,
18
+ messageSocket: $ReadOnly<{
19
+ broadcast: (type: string, params?: Record<string, mixed> | null) => void,
20
+ ...
21
+ }>,
22
+ }): void;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ var _path = _interopRequireDefault(require("path"));
8
+ var _runServer = _interopRequireDefault(require("./runServer"));
9
+ function _interopRequireDefault(obj) {
10
+ return obj && obj.__esModule ? obj : { default: obj };
11
+ }
12
+ /**
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ *
19
+ * @format
20
+ * @oncall react_native
21
+ */
22
+
23
+ const startCommand = {
24
+ name: "start",
25
+ func: _runServer.default,
26
+ description: "Start the React Native development server.",
27
+ options: [
28
+ {
29
+ name: "--port <number>",
30
+ parse: Number,
31
+ },
32
+ {
33
+ name: "--host <string>",
34
+ default: "",
35
+ },
36
+ {
37
+ name: "--projectRoot <path>",
38
+ description: "Path to a custom project root",
39
+ parse: (val) => _path.default.resolve(val),
40
+ },
41
+ {
42
+ name: "--watchFolders <list>",
43
+ description:
44
+ "Specify any additional folders to be added to the watch list",
45
+ parse: (val) =>
46
+ val.split(",").map((folder) => _path.default.resolve(folder)),
47
+ },
48
+ {
49
+ name: "--assetPlugins <list>",
50
+ description:
51
+ "Specify any additional asset plugins to be used by the packager by full filepath",
52
+ parse: (val) => val.split(","),
53
+ },
54
+ {
55
+ name: "--sourceExts <list>",
56
+ description:
57
+ "Specify any additional source extensions to be used by the packager",
58
+ parse: (val) => val.split(","),
59
+ },
60
+ {
61
+ name: "--max-workers <number>",
62
+ description:
63
+ "Specifies the maximum number of workers the worker-pool " +
64
+ "will spawn for transforming files. This defaults to the number of the " +
65
+ "cores available on your machine.",
66
+ parse: (workers) => Number(workers),
67
+ },
68
+ {
69
+ name: "--transformer <string>",
70
+ description: "Specify a custom transformer to be used",
71
+ },
72
+ {
73
+ name: "--reset-cache, --resetCache",
74
+ description: "Removes cached files",
75
+ },
76
+ {
77
+ name: "--custom-log-reporter-path, --customLogReporterPath <string>",
78
+ description:
79
+ "Path to a JavaScript file that exports a log reporter as a replacement for TerminalReporter",
80
+ },
81
+ {
82
+ name: "--https",
83
+ description: "Enables https connections to the server",
84
+ },
85
+ {
86
+ name: "--key <path>",
87
+ description: "Path to custom SSL key",
88
+ },
89
+ {
90
+ name: "--cert <path>",
91
+ description: "Path to custom SSL cert",
92
+ },
93
+ {
94
+ name: "--config <string>",
95
+ description: "Path to the CLI configuration file",
96
+ parse: (val) => _path.default.resolve(val),
97
+ },
98
+ {
99
+ name: "--no-interactive",
100
+ description: "Disables interactive mode",
101
+ },
102
+ ],
103
+ };
104
+ var _default = startCommand;
105
+ exports.default = _default;
@@ -0,0 +1,18 @@
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 strict-local
8
+ * @format
9
+ * @oncall react_native
10
+ */
11
+
12
+ import type { Command } from "@react-native-community/cli-types";
13
+
14
+ export type { StartCommandArgs } from "./runServer";
15
+
16
+ declare const startCommand: Command;
17
+
18
+ declare export default startCommand;