@react-native/community-cli-plugin 0.73.0 → 0.73.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +7 -3
  2. package/dist/commands/bundle/assetCatalogIOS.js.flow +9 -57
  3. package/dist/commands/bundle/assetPathUtils.js.flow +12 -66
  4. package/dist/commands/bundle/buildBundle.js +16 -7
  5. package/dist/commands/bundle/buildBundle.js.flow +39 -95
  6. package/dist/commands/bundle/filterPlatformAssetScales.js.flow +5 -33
  7. package/dist/commands/bundle/getAssetDestPathAndroid.js.flow +7 -14
  8. package/dist/commands/bundle/getAssetDestPathIOS.js.flow +7 -16
  9. package/dist/commands/bundle/index.js +124 -0
  10. package/dist/commands/bundle/index.js.flow +18 -0
  11. package/dist/commands/bundle/saveAssets.js +1 -1
  12. package/dist/commands/bundle/saveAssets.js.flow +6 -124
  13. package/dist/commands/{bundle/ramBundle.js → ram-bundle/index.js} +17 -19
  14. package/dist/commands/ram-bundle/index.js.flow +15 -0
  15. package/dist/commands/start/attachKeyHandlers.js +109 -0
  16. package/dist/commands/start/attachKeyHandlers.js.flow +22 -0
  17. package/dist/commands/start/index.js +3 -8
  18. package/dist/commands/start/index.js.flow +6 -85
  19. package/dist/commands/start/runServer.js +82 -32
  20. package/dist/commands/start/runServer.js.flow +9 -127
  21. package/dist/index.flow.js +2 -2
  22. package/dist/index.flow.js.flow +5 -5
  23. package/dist/index.js.flow +1 -9
  24. package/dist/utils/KeyPressHandler.js +91 -0
  25. package/dist/utils/KeyPressHandler.js.flow +22 -0
  26. package/dist/utils/isDevServerRunning.js +74 -0
  27. package/dist/utils/isDevServerRunning.js.flow +27 -0
  28. package/dist/utils/loadMetroConfig.js +6 -7
  29. package/dist/utils/loadMetroConfig.js.flow +10 -102
  30. package/dist/utils/metroPlatformResolver.js.flow +4 -18
  31. package/package.json +11 -9
  32. package/dist/commands/bundle/bundle.js +0 -44
  33. package/dist/commands/bundle/bundle.js.flow +0 -37
  34. package/dist/commands/bundle/bundleCommandLineArgs.js +0 -116
  35. package/dist/commands/bundle/bundleCommandLineArgs.js.flow +0 -129
  36. package/dist/commands/bundle/ramBundle.js.flow +0 -43
  37. package/dist/commands/start/startServerInNewWindow.js +0 -132
  38. package/dist/commands/start/startServerInNewWindow.js.flow +0 -125
  39. package/dist/commands/start/watchMode.js +0 -95
  40. package/dist/commands/start/watchMode.js.flow +0 -101
  41. package/launchPackager.bat +0 -7
  42. package/launchPackager.command +0 -10
@@ -1,44 +0,0 @@
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;
@@ -1,37 +0,0 @@
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 {CommandLineArgs} from './bundleCommandLineArgs';
14
-
15
- import buildBundle from './buildBundle';
16
- import bundleCommandLineArgs from './bundleCommandLineArgs';
17
-
18
- /**
19
- * Builds the bundle starting to look for dependencies at the given entry path.
20
- */
21
- export function bundleWithOutput(
22
- _: Array<string>,
23
- config: Config,
24
- args: CommandLineArgs,
25
- output: any, // untyped metro/src/shared/output/bundle or metro/src/shared/output/RamBundle
26
- ): Promise<void> {
27
- return buildBundle(args, config, output);
28
- }
29
-
30
- const bundleCommand = {
31
- name: 'bundle',
32
- description: 'Build the bundle for the provided JavaScript entry file.',
33
- func: bundleWithOutput,
34
- options: bundleCommandLineArgs,
35
- };
36
-
37
- export default bundleCommand;
@@ -1,116 +0,0 @@
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
- function _interopRequireDefault(obj) {
9
- return obj && obj.__esModule ? obj : { default: obj };
10
- }
11
- /**
12
- * Copyright (c) Meta Platforms, Inc. and affiliates.
13
- *
14
- * This source code is licensed under the MIT license found in the
15
- * LICENSE file in the root directory of this source tree.
16
- *
17
- *
18
- * @format
19
- * @oncall react_native
20
- */
21
- var _default = [
22
- {
23
- name: "--entry-file <path>",
24
- description:
25
- "Path to the root JS file, either absolute or relative to JS root",
26
- },
27
- {
28
- name: "--platform <string>",
29
- description: 'Either "ios" or "android"',
30
- default: "ios",
31
- },
32
- {
33
- name: "--transformer <string>",
34
- description: "Specify a custom transformer to be used",
35
- },
36
- {
37
- name: "--dev [boolean]",
38
- description: "If false, warnings are disabled and the bundle is minified",
39
- parse: (val) => val !== "false",
40
- default: true,
41
- },
42
- {
43
- name: "--minify [boolean]",
44
- description:
45
- "Allows overriding whether bundle is minified. This defaults to " +
46
- "false if dev is true, and true if dev is false. Disabling minification " +
47
- "can be useful for speeding up production builds for testing purposes.",
48
- parse: (val) => val !== "false",
49
- },
50
- {
51
- name: "--bundle-output <string>",
52
- description:
53
- "File name where to store the resulting bundle, ex. /tmp/groups.bundle",
54
- },
55
- {
56
- name: "--bundle-encoding <string>",
57
- description:
58
- "Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).",
59
- default: "utf8",
60
- },
61
- {
62
- name: "--max-workers <number>",
63
- description:
64
- "Specifies the maximum number of workers the worker-pool " +
65
- "will spawn for transforming files. This defaults to the number of the " +
66
- "cores available on your machine.",
67
- parse: (workers) => Number(workers),
68
- },
69
- {
70
- name: "--sourcemap-output <string>",
71
- description:
72
- "File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map",
73
- },
74
- {
75
- name: "--sourcemap-sources-root <string>",
76
- description:
77
- "Path to make sourcemap's sources entries relative to, ex. /root/dir",
78
- },
79
- {
80
- name: "--sourcemap-use-absolute-path",
81
- description: "Report SourceMapURL using its full path",
82
- default: false,
83
- },
84
- {
85
- name: "--assets-dest <string>",
86
- description:
87
- "Directory name where to store assets referenced in the bundle",
88
- },
89
- {
90
- name: "--unstable-transform-profile <string>",
91
- description:
92
- "Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default",
93
- default: "default",
94
- },
95
- {
96
- name: "--asset-catalog-dest [string]",
97
- description: "Path where to create an iOS Asset Catalog for images",
98
- },
99
- {
100
- name: "--reset-cache",
101
- description: "Removes cached files",
102
- default: false,
103
- },
104
- {
105
- name: "--read-global-cache",
106
- description:
107
- "Try to fetch transformed JS code from the global cache, if configured.",
108
- default: false,
109
- },
110
- {
111
- name: "--config <string>",
112
- description: "Path to the CLI configuration file",
113
- parse: (val) => _path.default.resolve(val),
114
- },
115
- ];
116
- exports.default = _default;
@@ -1,129 +0,0 @@
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 path from 'path';
13
-
14
- export interface CommandLineArgs {
15
- assetsDest?: string;
16
- assetCatalogDest?: string;
17
- entryFile: string;
18
- resetCache: boolean;
19
- resetGlobalCache: boolean;
20
- transformer?: string;
21
- minify?: boolean;
22
- config?: string;
23
- platform: string;
24
- dev: boolean;
25
- bundleOutput: string;
26
- bundleEncoding?: 'utf8' | 'utf16le' | 'ascii';
27
- maxWorkers?: number;
28
- sourcemapOutput?: string;
29
- sourcemapSourcesRoot?: string;
30
- sourcemapUseAbsolutePath: boolean;
31
- verbose: boolean;
32
- unstableTransformProfile: string;
33
- }
34
-
35
- export default [
36
- {
37
- name: '--entry-file <path>',
38
- description:
39
- 'Path to the root JS file, either absolute or relative to JS root',
40
- },
41
- {
42
- name: '--platform <string>',
43
- description: 'Either "ios" or "android"',
44
- default: 'ios',
45
- },
46
- {
47
- name: '--transformer <string>',
48
- description: 'Specify a custom transformer to be used',
49
- },
50
- {
51
- name: '--dev [boolean]',
52
- description: 'If false, warnings are disabled and the bundle is minified',
53
- parse: (val: string): boolean => val !== 'false',
54
- default: true,
55
- },
56
- {
57
- name: '--minify [boolean]',
58
- description:
59
- 'Allows overriding whether bundle is minified. This defaults to ' +
60
- 'false if dev is true, and true if dev is false. Disabling minification ' +
61
- 'can be useful for speeding up production builds for testing purposes.',
62
- parse: (val: string): boolean => val !== 'false',
63
- },
64
- {
65
- name: '--bundle-output <string>',
66
- description:
67
- 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
68
- },
69
- {
70
- name: '--bundle-encoding <string>',
71
- description:
72
- 'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).',
73
- default: 'utf8',
74
- },
75
- {
76
- name: '--max-workers <number>',
77
- description:
78
- 'Specifies the maximum number of workers the worker-pool ' +
79
- 'will spawn for transforming files. This defaults to the number of the ' +
80
- 'cores available on your machine.',
81
- parse: (workers: string): number => Number(workers),
82
- },
83
- {
84
- name: '--sourcemap-output <string>',
85
- description:
86
- 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map',
87
- },
88
- {
89
- name: '--sourcemap-sources-root <string>',
90
- description:
91
- "Path to make sourcemap's sources entries relative to, ex. /root/dir",
92
- },
93
- {
94
- name: '--sourcemap-use-absolute-path',
95
- description: 'Report SourceMapURL using its full path',
96
- default: false,
97
- },
98
- {
99
- name: '--assets-dest <string>',
100
- description:
101
- 'Directory name where to store assets referenced in the bundle',
102
- },
103
- {
104
- name: '--unstable-transform-profile <string>',
105
- description:
106
- 'Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default',
107
- default: 'default',
108
- },
109
- {
110
- name: '--asset-catalog-dest [string]',
111
- description: 'Path where to create an iOS Asset Catalog for images',
112
- },
113
- {
114
- name: '--reset-cache',
115
- description: 'Removes cached files',
116
- default: false,
117
- },
118
- {
119
- name: '--read-global-cache',
120
- description:
121
- 'Try to fetch transformed JS code from the global cache, if configured.',
122
- default: false,
123
- },
124
- {
125
- name: '--config <string>',
126
- description: 'Path to the CLI configuration file',
127
- parse: (val: string): string => path.resolve(val),
128
- },
129
- ];
@@ -1,43 +0,0 @@
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 {CommandLineArgs} from './bundleCommandLineArgs';
14
-
15
- import outputUnbundle from 'metro/src/shared/output/RamBundle';
16
- import {bundleWithOutput} from './bundle';
17
- import bundleCommandLineArgs from './bundleCommandLineArgs';
18
-
19
- /**
20
- * Builds the bundle starting to look for dependencies at the given entry path.
21
- */
22
- function ramBundle(
23
- argv: Array<string>,
24
- config: Config,
25
- args: CommandLineArgs,
26
- ): Promise<void> {
27
- return bundleWithOutput(argv, config, args, outputUnbundle);
28
- }
29
-
30
- export default {
31
- name: 'ram-bundle',
32
- description:
33
- 'Build the RAM bundle for the provided JavaScript entry file. See https://reactnative.dev/docs/ram-bundles-inline-requires.',
34
- func: ramBundle,
35
- options: (bundleCommandLineArgs.concat({
36
- name: '--indexed-ram-bundle',
37
- description:
38
- 'Force the "Indexed RAM" bundle file format, even when building for android',
39
- default: false,
40
- }): Array<Object>),
41
- };
42
-
43
- export {ramBundle};
@@ -1,132 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true,
5
- });
6
- exports.startServerInNewWindow = startServerInNewWindow;
7
- var _path = _interopRequireDefault(require("path"));
8
- var _fs = _interopRequireDefault(require("fs"));
9
- var _execa = _interopRequireDefault(require("execa"));
10
- var _cliTools = require("@react-native-community/cli-tools");
11
- function _interopRequireDefault(obj) {
12
- return obj && obj.__esModule ? obj : { default: obj };
13
- }
14
- /**
15
- * Copyright (c) Meta Platforms, Inc. and affiliates.
16
- *
17
- * This source code is licensed under the MIT license found in the
18
- * LICENSE file in the root directory of this source tree.
19
- *
20
- *
21
- * @format
22
- * @oncall react_native
23
- */
24
-
25
- function startServerInNewWindow(port, terminal, projectRoot, reactNativePath) {
26
- /**
27
- * Set up OS-specific filenames and commands
28
- */
29
- const isWindows = /^win/.test(process.platform);
30
- const scriptFile = isWindows
31
- ? "launchPackager.bat"
32
- : "launchPackager.command";
33
- const packagerEnvFilename = isWindows ? ".packager.bat" : ".packager.env";
34
- const packagerEnvFileExportContent = isWindows
35
- ? `set RCT_METRO_PORT=${port}\nset PROJECT_ROOT=${projectRoot}\nset REACT_NATIVE_PATH=${reactNativePath}`
36
- : `export RCT_METRO_PORT=${port}\nexport PROJECT_ROOT=${projectRoot}\nexport REACT_NATIVE_PATH=${reactNativePath}`;
37
- const nodeModulesPath = (0, _cliTools.resolveNodeModuleDir)(
38
- projectRoot,
39
- ".bin"
40
- );
41
- const cliPluginMetroPath = _path.default.join(
42
- _path.default.dirname(
43
- require.resolve("@react-native/community-cli-plugin/package.json")
44
- ),
45
- "build"
46
- );
47
-
48
- /**
49
- * Set up the `.packager.(env|bat)` file to ensure the packager starts on the right port and in right directory.
50
- */
51
- const packagerEnvFile = _path.default.join(
52
- nodeModulesPath,
53
- `${packagerEnvFilename}`
54
- );
55
-
56
- /**
57
- * Set up the `launchPackager.(command|bat)` file.
58
- * It lives next to `.packager.(bat|env)`
59
- */
60
- const launchPackagerScript = _path.default.join(nodeModulesPath, scriptFile);
61
- const procConfig = {
62
- cwd: _path.default.dirname(packagerEnvFile),
63
- };
64
-
65
- /**
66
- * Ensure we overwrite file by passing the `w` flag
67
- */
68
- _fs.default.writeFileSync(packagerEnvFile, packagerEnvFileExportContent, {
69
- encoding: "utf8",
70
- flag: "w",
71
- });
72
-
73
- /**
74
- * Copy files into `node_modules/.bin`.
75
- */
76
-
77
- try {
78
- if (isWindows) {
79
- _fs.default.copyFileSync(
80
- _path.default.join(cliPluginMetroPath, "launchPackager.bat"),
81
- _path.default.join(nodeModulesPath, "launchPackager.bat")
82
- );
83
- } else {
84
- _fs.default.copyFileSync(
85
- _path.default.join(cliPluginMetroPath, "launchPackager.command"),
86
- _path.default.join(nodeModulesPath, "launchPackager.command")
87
- );
88
- }
89
- } catch (error) {
90
- return new _cliTools.CLIError(
91
- `Couldn't copy the script for running bundler. Please check if the "${scriptFile}" file exists in the "node_modules/@react-native/community-cli-plugin" folder and try again.`,
92
- error
93
- );
94
- }
95
- if (process.platform === "darwin") {
96
- try {
97
- return _execa.default.sync(
98
- "open",
99
- ["-a", terminal, launchPackagerScript],
100
- procConfig
101
- );
102
- } catch (error) {
103
- return _execa.default.sync("open", [launchPackagerScript], procConfig);
104
- }
105
- }
106
- if (process.platform === "linux") {
107
- try {
108
- return _execa.default.sync(
109
- terminal,
110
- ["-e", `sh ${launchPackagerScript}`],
111
- {
112
- ...procConfig,
113
- detached: true,
114
- }
115
- );
116
- } catch (error) {
117
- // By default, the child shell process will be attached to the parent
118
- return _execa.default.sync("sh", [launchPackagerScript], procConfig);
119
- }
120
- }
121
- if (isWindows) {
122
- // Awaiting this causes the CLI to hang indefinitely, so this must execute without await.
123
- return (0, _execa.default)("cmd.exe", ["/C", launchPackagerScript], {
124
- ...procConfig,
125
- detached: true,
126
- stdio: "ignore",
127
- });
128
- }
129
- _cliTools.logger.error(
130
- `Cannot start the packager. Unknown platform ${process.platform}`
131
- );
132
- }
@@ -1,125 +0,0 @@
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 {ExecaPromise, SyncResult} from 'execa';
13
-
14
- import path from 'path';
15
- import fs from 'fs';
16
- import execa from 'execa';
17
- import {
18
- CLIError,
19
- logger,
20
- resolveNodeModuleDir,
21
- } from '@react-native-community/cli-tools';
22
-
23
- export function startServerInNewWindow(
24
- port: number,
25
- terminal: string,
26
- projectRoot: string,
27
- reactNativePath: string,
28
- ): SyncResult | ExecaPromise | CLIError | void {
29
- /**
30
- * Set up OS-specific filenames and commands
31
- */
32
- const isWindows = /^win/.test(process.platform);
33
- const scriptFile = isWindows
34
- ? 'launchPackager.bat'
35
- : 'launchPackager.command';
36
- const packagerEnvFilename = isWindows ? '.packager.bat' : '.packager.env';
37
- const packagerEnvFileExportContent = isWindows
38
- ? `set RCT_METRO_PORT=${port}\nset PROJECT_ROOT=${projectRoot}\nset REACT_NATIVE_PATH=${reactNativePath}`
39
- : `export RCT_METRO_PORT=${port}\nexport PROJECT_ROOT=${projectRoot}\nexport REACT_NATIVE_PATH=${reactNativePath}`;
40
- const nodeModulesPath = resolveNodeModuleDir(projectRoot, '.bin');
41
- const cliPluginMetroPath = path.join(
42
- path.dirname(
43
- require.resolve('@react-native/community-cli-plugin/package.json'),
44
- ),
45
- 'build',
46
- );
47
-
48
- /**
49
- * Set up the `.packager.(env|bat)` file to ensure the packager starts on the right port and in right directory.
50
- */
51
- const packagerEnvFile = path.join(nodeModulesPath, `${packagerEnvFilename}`);
52
-
53
- /**
54
- * Set up the `launchPackager.(command|bat)` file.
55
- * It lives next to `.packager.(bat|env)`
56
- */
57
- const launchPackagerScript = path.join(nodeModulesPath, scriptFile);
58
- const procConfig = {cwd: path.dirname(packagerEnvFile)};
59
-
60
- /**
61
- * Ensure we overwrite file by passing the `w` flag
62
- */
63
- fs.writeFileSync(packagerEnvFile, packagerEnvFileExportContent, {
64
- encoding: 'utf8',
65
- flag: 'w',
66
- });
67
-
68
- /**
69
- * Copy files into `node_modules/.bin`.
70
- */
71
-
72
- try {
73
- if (isWindows) {
74
- fs.copyFileSync(
75
- path.join(cliPluginMetroPath, 'launchPackager.bat'),
76
- path.join(nodeModulesPath, 'launchPackager.bat'),
77
- );
78
- } else {
79
- fs.copyFileSync(
80
- path.join(cliPluginMetroPath, 'launchPackager.command'),
81
- path.join(nodeModulesPath, 'launchPackager.command'),
82
- );
83
- }
84
- } catch (error) {
85
- return new CLIError(
86
- `Couldn't copy the script for running bundler. Please check if the "${scriptFile}" file exists in the "node_modules/@react-native/community-cli-plugin" folder and try again.`,
87
- error,
88
- );
89
- }
90
-
91
- if (process.platform === 'darwin') {
92
- try {
93
- return execa.sync(
94
- 'open',
95
- ['-a', terminal, launchPackagerScript],
96
- procConfig,
97
- );
98
- } catch (error) {
99
- return execa.sync('open', [launchPackagerScript], procConfig);
100
- }
101
- }
102
- if (process.platform === 'linux') {
103
- try {
104
- return execa.sync(terminal, ['-e', `sh ${launchPackagerScript}`], {
105
- ...procConfig,
106
- detached: true,
107
- });
108
- } catch (error) {
109
- // By default, the child shell process will be attached to the parent
110
- return execa.sync('sh', [launchPackagerScript], procConfig);
111
- }
112
- }
113
- if (isWindows) {
114
- // Awaiting this causes the CLI to hang indefinitely, so this must execute without await.
115
- return execa('cmd.exe', ['/C', launchPackagerScript], {
116
- ...procConfig,
117
- detached: true,
118
- stdio: 'ignore',
119
- });
120
- }
121
- logger.error(
122
- `Cannot start the packager. Unknown platform ${process.platform}`,
123
- );
124
- return;
125
- }