@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
@@ -0,0 +1,37 @@
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;
@@ -0,0 +1,116 @@
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;
@@ -0,0 +1,129 @@
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
+ ];
@@ -0,0 +1,47 @@
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
+ const ALLOWED_SCALES = {
19
+ ios: [1, 2, 3],
20
+ };
21
+ function filterPlatformAssetScales(platform, scales) {
22
+ const whitelist = ALLOWED_SCALES[platform];
23
+ if (!whitelist) {
24
+ return scales;
25
+ }
26
+ const result = scales.filter((scale) => whitelist.indexOf(scale) > -1);
27
+ if (result.length === 0 && scales.length > 0) {
28
+ // No matching scale found, but there are some available. Ideally we don't
29
+ // want to be in this situation and should throw, but for now as a fallback
30
+ // let's just use the closest larger image
31
+ const maxScale = whitelist[whitelist.length - 1];
32
+ for (const scale of scales) {
33
+ if (scale > maxScale) {
34
+ result.push(scale);
35
+ break;
36
+ }
37
+ }
38
+
39
+ // There is no larger scales available, use the largest we have
40
+ if (result.length === 0) {
41
+ result.push(scales[scales.length - 1]);
42
+ }
43
+ }
44
+ return result;
45
+ }
46
+ var _default = filterPlatformAssetScales;
47
+ exports.default = _default;
@@ -0,0 +1,45 @@
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
+ const ALLOWED_SCALES: {[key: string]: number[]} = {
13
+ ios: [1, 2, 3],
14
+ };
15
+
16
+ function filterPlatformAssetScales(
17
+ platform: string,
18
+ scales: $ReadOnlyArray<number>,
19
+ ): $ReadOnlyArray<number> {
20
+ const whitelist: number[] = ALLOWED_SCALES[platform];
21
+ if (!whitelist) {
22
+ return scales;
23
+ }
24
+ const result = scales.filter(scale => whitelist.indexOf(scale) > -1);
25
+ if (result.length === 0 && scales.length > 0) {
26
+ // No matching scale found, but there are some available. Ideally we don't
27
+ // want to be in this situation and should throw, but for now as a fallback
28
+ // let's just use the closest larger image
29
+ const maxScale = whitelist[whitelist.length - 1];
30
+ for (const scale of scales) {
31
+ if (scale > maxScale) {
32
+ result.push(scale);
33
+ break;
34
+ }
35
+ }
36
+
37
+ // There is no larger scales available, use the largest we have
38
+ if (result.length === 0) {
39
+ result.push(scales[scales.length - 1]);
40
+ }
41
+ }
42
+ return result;
43
+ }
44
+
45
+ export default filterPlatformAssetScales;
@@ -0,0 +1,32 @@
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 _assetPathUtils = _interopRequireDefault(require("./assetPathUtils"));
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
+ function getAssetDestPathAndroid(asset, scale) {
24
+ const androidFolder = _assetPathUtils.default.getAndroidResourceFolderName(
25
+ asset,
26
+ scale
27
+ );
28
+ const fileName = _assetPathUtils.default.getResourceIdentifier(asset);
29
+ return _path.default.join(androidFolder, `${fileName}.${asset.type}`);
30
+ }
31
+ var _default = getAssetDestPathAndroid;
32
+ exports.default = _default;
@@ -0,0 +1,26 @@
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 {PackagerAsset} from './assetPathUtils';
13
+
14
+ import path from 'path';
15
+ import assetPathUtils from './assetPathUtils';
16
+
17
+ function getAssetDestPathAndroid(asset: PackagerAsset, scale: number): string {
18
+ const androidFolder = assetPathUtils.getAndroidResourceFolderName(
19
+ asset,
20
+ scale,
21
+ );
22
+ const fileName = assetPathUtils.getResourceIdentifier(asset);
23
+ return path.join(androidFolder, `${fileName}.${asset.type}`);
24
+ }
25
+
26
+ export default getAssetDestPathAndroid;
@@ -0,0 +1,34 @@
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
+
22
+ function getAssetDestPathIOS(asset, scale) {
23
+ const suffix = scale === 1 ? "" : `@${scale}x`;
24
+ const fileName = `${asset.name + suffix}.${asset.type}`;
25
+ return _path.default.join(
26
+ // Assets can have relative paths outside of the project root.
27
+ // Replace `../` with `_` to make sure they don't end up outside of
28
+ // the expected assets directory.
29
+ asset.httpServerLocation.substr(1).replace(/\.\.\//g, "_"),
30
+ fileName
31
+ );
32
+ }
33
+ var _default = getAssetDestPathIOS;
34
+ exports.default = _default;
@@ -0,0 +1,28 @@
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 {PackagerAsset} from './assetPathUtils';
13
+
14
+ import path from 'path';
15
+
16
+ function getAssetDestPathIOS(asset: PackagerAsset, scale: number): string {
17
+ const suffix = scale === 1 ? '' : `@${scale}x`;
18
+ const fileName = `${asset.name + suffix}.${asset.type}`;
19
+ return path.join(
20
+ // Assets can have relative paths outside of the project root.
21
+ // Replace `../` with `_` to make sure they don't end up outside of
22
+ // the expected assets directory.
23
+ asset.httpServerLocation.substr(1).replace(/\.\.\//g, '_'),
24
+ fileName,
25
+ );
26
+ }
27
+
28
+ export default getAssetDestPathIOS;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ exports.ramBundle = ramBundle;
8
+ var _RamBundle = _interopRequireDefault(
9
+ require("metro/src/shared/output/RamBundle")
10
+ );
11
+ var _bundle = require("./bundle");
12
+ var _bundleCommandLineArgs = _interopRequireDefault(
13
+ require("./bundleCommandLineArgs")
14
+ );
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
+ /**
30
+ * Builds the bundle starting to look for dependencies at the given entry path.
31
+ */
32
+ function ramBundle(argv, config, args) {
33
+ return (0, _bundle.bundleWithOutput)(argv, config, args, _RamBundle.default);
34
+ }
35
+ var _default = {
36
+ name: "ram-bundle",
37
+ description:
38
+ "Build the RAM bundle for the provided JavaScript entry file. See https://reactnative.dev/docs/ram-bundles-inline-requires.",
39
+ func: ramBundle,
40
+ options: _bundleCommandLineArgs.default.concat({
41
+ name: "--indexed-ram-bundle",
42
+ description:
43
+ 'Force the "Indexed RAM" bundle file format, even when building for android',
44
+ default: false,
45
+ }),
46
+ };
47
+ exports.default = _default;
@@ -0,0 +1,43 @@
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};