@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.
- package/README.md +87 -0
- package/dist/commands/bundle/assetCatalogIOS.js +74 -0
- package/dist/commands/bundle/assetCatalogIOS.js.flow +77 -0
- package/dist/commands/bundle/assetPathUtils.js +79 -0
- package/dist/commands/bundle/assetPathUtils.js.flow +93 -0
- package/dist/commands/bundle/buildBundle.js +112 -0
- package/dist/commands/bundle/buildBundle.js.flow +120 -0
- package/dist/commands/bundle/bundle.js +44 -0
- package/dist/commands/bundle/bundle.js.flow +37 -0
- package/dist/commands/bundle/bundleCommandLineArgs.js +116 -0
- package/dist/commands/bundle/bundleCommandLineArgs.js.flow +129 -0
- package/dist/commands/bundle/filterPlatformAssetScales.js +47 -0
- package/dist/commands/bundle/filterPlatformAssetScales.js.flow +45 -0
- package/dist/commands/bundle/getAssetDestPathAndroid.js +32 -0
- package/dist/commands/bundle/getAssetDestPathAndroid.js.flow +26 -0
- package/dist/commands/bundle/getAssetDestPathIOS.js +34 -0
- package/dist/commands/bundle/getAssetDestPathIOS.js.flow +28 -0
- package/dist/commands/bundle/ramBundle.js +47 -0
- package/dist/commands/bundle/ramBundle.js.flow +43 -0
- package/dist/commands/bundle/saveAssets.js +138 -0
- package/dist/commands/bundle/saveAssets.js.flow +139 -0
- package/dist/commands/start/index.js +110 -0
- package/dist/commands/start/index.js.flow +97 -0
- package/dist/commands/start/runServer.js +123 -0
- package/dist/commands/start/runServer.js.flow +156 -0
- package/dist/commands/start/startServerInNewWindow.js +132 -0
- package/dist/commands/start/startServerInNewWindow.js.flow +125 -0
- package/dist/commands/start/watchMode.js +95 -0
- package/dist/commands/start/watchMode.js.flow +101 -0
- package/dist/index.flow.js +36 -0
- package/dist/index.flow.js.flow +16 -0
- package/dist/index.js +3 -0
- package/dist/index.js.flow +20 -0
- package/dist/utils/loadMetroConfig.js +108 -0
- package/dist/utils/loadMetroConfig.js.flow +125 -0
- package/dist/utils/metroPlatformResolver.js +46 -0
- package/dist/utils/metroPlatformResolver.js.flow +44 -0
- package/launchPackager.bat +7 -0
- package/launchPackager.command +10 -0
- package/package.json +29 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = loadMetroConfig;
|
|
7
|
+
var _path = _interopRequireDefault(require("path"));
|
|
8
|
+
var _metroConfig = require("metro-config");
|
|
9
|
+
var _cliTools = require("@react-native-community/cli-tools");
|
|
10
|
+
var _metroPlatformResolver = require("./metroPlatformResolver");
|
|
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
|
+
/**
|
|
26
|
+
* Get the config options to override based on RN CLI inputs.
|
|
27
|
+
*/
|
|
28
|
+
function getOverrideConfig(ctx) {
|
|
29
|
+
const outOfTreePlatforms = Object.keys(ctx.platforms).filter(
|
|
30
|
+
(platform) => ctx.platforms[platform].npmPackageName
|
|
31
|
+
);
|
|
32
|
+
const resolver = {
|
|
33
|
+
platforms: [...Object.keys(ctx.platforms), "native"],
|
|
34
|
+
};
|
|
35
|
+
if (outOfTreePlatforms.length) {
|
|
36
|
+
resolver.resolveRequest = (0,
|
|
37
|
+
_metroPlatformResolver.reactNativePlatformResolver)(
|
|
38
|
+
outOfTreePlatforms.reduce((result, platform) => {
|
|
39
|
+
result[platform] = ctx.platforms[platform].npmPackageName;
|
|
40
|
+
return result;
|
|
41
|
+
}, {})
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
resolver,
|
|
46
|
+
serializer: {
|
|
47
|
+
// We can include multiple copies of InitializeCore here because metro will
|
|
48
|
+
// only add ones that are already part of the bundle
|
|
49
|
+
getModulesRunBeforeMainModule: () => [
|
|
50
|
+
require.resolve(
|
|
51
|
+
_path.default.join(
|
|
52
|
+
ctx.reactNativePath,
|
|
53
|
+
"Libraries/Core/InitializeCore"
|
|
54
|
+
),
|
|
55
|
+
{
|
|
56
|
+
paths: [ctx.root],
|
|
57
|
+
}
|
|
58
|
+
),
|
|
59
|
+
...outOfTreePlatforms.map((platform) =>
|
|
60
|
+
require.resolve(
|
|
61
|
+
`${ctx.platforms[platform].npmPackageName}/Libraries/Core/InitializeCore`
|
|
62
|
+
)
|
|
63
|
+
),
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Load Metro config.
|
|
70
|
+
*
|
|
71
|
+
* Allows the CLI to override select values in `metro.config.js` based on
|
|
72
|
+
* dynamic user options in `ctx`.
|
|
73
|
+
*/
|
|
74
|
+
async function loadMetroConfig(ctx, options = {}) {
|
|
75
|
+
const overrideConfig = getOverrideConfig(ctx);
|
|
76
|
+
if (options.reporter) {
|
|
77
|
+
overrideConfig.reporter = options.reporter;
|
|
78
|
+
}
|
|
79
|
+
const projectConfig = await (0, _metroConfig.resolveConfig)(
|
|
80
|
+
undefined,
|
|
81
|
+
ctx.root
|
|
82
|
+
);
|
|
83
|
+
if (projectConfig.isEmpty) {
|
|
84
|
+
throw new _cliTools.CLIError(`No metro config found in ${ctx.root}`);
|
|
85
|
+
}
|
|
86
|
+
_cliTools.logger.debug(`Reading Metro config from ${projectConfig.filepath}`);
|
|
87
|
+
if (!global.__REACT_NATIVE_METRO_CONFIG_LOADED) {
|
|
88
|
+
for (const line of `
|
|
89
|
+
=================================================================================================
|
|
90
|
+
From React Native 0.73, your project's Metro config should extend '@react-native/metro-config'
|
|
91
|
+
or it will fail to build. Please copy the template at:
|
|
92
|
+
https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js
|
|
93
|
+
This warning will be removed in future (https://github.com/facebook/metro/issues/1018).
|
|
94
|
+
=================================================================================================
|
|
95
|
+
`
|
|
96
|
+
.trim()
|
|
97
|
+
.split("\n")) {
|
|
98
|
+
_cliTools.logger.warn(line);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return (0, _metroConfig.mergeConfig)(
|
|
102
|
+
await (0, _metroConfig.loadConfig)({
|
|
103
|
+
cwd: ctx.root,
|
|
104
|
+
...options,
|
|
105
|
+
}),
|
|
106
|
+
overrideConfig
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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 {ConfigT, InputConfigT} from 'metro-config';
|
|
14
|
+
|
|
15
|
+
import path from 'path';
|
|
16
|
+
import {loadConfig, mergeConfig, resolveConfig} from 'metro-config';
|
|
17
|
+
import {CLIError, logger} from '@react-native-community/cli-tools';
|
|
18
|
+
import {reactNativePlatformResolver} from './metroPlatformResolver';
|
|
19
|
+
|
|
20
|
+
export type {Config};
|
|
21
|
+
|
|
22
|
+
export type ConfigLoadingContext = $ReadOnly<{
|
|
23
|
+
root: Config['root'],
|
|
24
|
+
reactNativePath: Config['reactNativePath'],
|
|
25
|
+
platforms: Config['platforms'],
|
|
26
|
+
...
|
|
27
|
+
}>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get the config options to override based on RN CLI inputs.
|
|
31
|
+
*/
|
|
32
|
+
function getOverrideConfig(ctx: ConfigLoadingContext): InputConfigT {
|
|
33
|
+
const outOfTreePlatforms = Object.keys(ctx.platforms).filter(
|
|
34
|
+
platform => ctx.platforms[platform].npmPackageName,
|
|
35
|
+
);
|
|
36
|
+
const resolver: Partial<{...ConfigT['resolver']}> = {
|
|
37
|
+
platforms: [...Object.keys(ctx.platforms), 'native'],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (outOfTreePlatforms.length) {
|
|
41
|
+
resolver.resolveRequest = reactNativePlatformResolver(
|
|
42
|
+
outOfTreePlatforms.reduce<{[platform: string]: string}>(
|
|
43
|
+
(result, platform) => {
|
|
44
|
+
result[platform] = ctx.platforms[platform].npmPackageName;
|
|
45
|
+
return result;
|
|
46
|
+
},
|
|
47
|
+
{},
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
resolver,
|
|
54
|
+
serializer: {
|
|
55
|
+
// We can include multiple copies of InitializeCore here because metro will
|
|
56
|
+
// only add ones that are already part of the bundle
|
|
57
|
+
getModulesRunBeforeMainModule: () => [
|
|
58
|
+
require.resolve(
|
|
59
|
+
path.join(ctx.reactNativePath, 'Libraries/Core/InitializeCore'),
|
|
60
|
+
{paths: [ctx.root]},
|
|
61
|
+
),
|
|
62
|
+
...outOfTreePlatforms.map(platform =>
|
|
63
|
+
require.resolve(
|
|
64
|
+
`${ctx.platforms[platform].npmPackageName}/Libraries/Core/InitializeCore`,
|
|
65
|
+
),
|
|
66
|
+
),
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type ConfigOptionsT = $ReadOnly<{
|
|
73
|
+
maxWorkers?: number,
|
|
74
|
+
port?: number,
|
|
75
|
+
projectRoot?: string,
|
|
76
|
+
resetCache?: boolean,
|
|
77
|
+
watchFolders?: string[],
|
|
78
|
+
sourceExts?: string[],
|
|
79
|
+
reporter?: any,
|
|
80
|
+
config?: string,
|
|
81
|
+
}>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Load Metro config.
|
|
85
|
+
*
|
|
86
|
+
* Allows the CLI to override select values in `metro.config.js` based on
|
|
87
|
+
* dynamic user options in `ctx`.
|
|
88
|
+
*/
|
|
89
|
+
export default async function loadMetroConfig(
|
|
90
|
+
ctx: ConfigLoadingContext,
|
|
91
|
+
options: ConfigOptionsT = {},
|
|
92
|
+
): Promise<ConfigT> {
|
|
93
|
+
const overrideConfig = getOverrideConfig(ctx);
|
|
94
|
+
if (options.reporter) {
|
|
95
|
+
overrideConfig.reporter = options.reporter;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const projectConfig = await resolveConfig(undefined, ctx.root);
|
|
99
|
+
|
|
100
|
+
if (projectConfig.isEmpty) {
|
|
101
|
+
throw new CLIError(`No metro config found in ${ctx.root}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
logger.debug(`Reading Metro config from ${projectConfig.filepath}`);
|
|
105
|
+
|
|
106
|
+
if (!global.__REACT_NATIVE_METRO_CONFIG_LOADED) {
|
|
107
|
+
const warning = `
|
|
108
|
+
=================================================================================================
|
|
109
|
+
From React Native 0.73, your project's Metro config should extend '@react-native/metro-config'
|
|
110
|
+
or it will fail to build. Please copy the template at:
|
|
111
|
+
https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js
|
|
112
|
+
This warning will be removed in future (https://github.com/facebook/metro/issues/1018).
|
|
113
|
+
=================================================================================================
|
|
114
|
+
`;
|
|
115
|
+
|
|
116
|
+
for (const line of warning.trim().split('\n')) {
|
|
117
|
+
logger.warn(line);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return mergeConfig(
|
|
122
|
+
await loadConfig({cwd: ctx.root, ...options}),
|
|
123
|
+
overrideConfig,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.reactNativePlatformResolver = reactNativePlatformResolver;
|
|
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
|
+
* This is an implementation of a metro resolveRequest option which will remap react-native imports
|
|
20
|
+
* to different npm packages based on the platform requested. This allows a single metro instance/config
|
|
21
|
+
* to produce bundles for multiple out of tree platforms at a time.
|
|
22
|
+
*
|
|
23
|
+
* @param platformImplementations
|
|
24
|
+
* A map of platform to npm package that implements that platform
|
|
25
|
+
*
|
|
26
|
+
* Ex:
|
|
27
|
+
* {
|
|
28
|
+
* windows: 'react-native-windows'
|
|
29
|
+
* macos: 'react-native-macos'
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
function reactNativePlatformResolver(platformImplementations) {
|
|
33
|
+
return (context, moduleName, platform) => {
|
|
34
|
+
let modifiedModuleName = moduleName;
|
|
35
|
+
if (platform != null && platformImplementations[platform]) {
|
|
36
|
+
if (moduleName === "react-native") {
|
|
37
|
+
modifiedModuleName = platformImplementations[platform];
|
|
38
|
+
} else if (moduleName.startsWith("react-native/")) {
|
|
39
|
+
modifiedModuleName = `${
|
|
40
|
+
platformImplementations[platform]
|
|
41
|
+
}/${modifiedModuleName.slice("react-native/".length)}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return context.resolveRequest(context, modifiedModuleName, platform);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 {CustomResolver} from 'metro-resolver';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This is an implementation of a metro resolveRequest option which will remap react-native imports
|
|
16
|
+
* to different npm packages based on the platform requested. This allows a single metro instance/config
|
|
17
|
+
* to produce bundles for multiple out of tree platforms at a time.
|
|
18
|
+
*
|
|
19
|
+
* @param platformImplementations
|
|
20
|
+
* A map of platform to npm package that implements that platform
|
|
21
|
+
*
|
|
22
|
+
* Ex:
|
|
23
|
+
* {
|
|
24
|
+
* windows: 'react-native-windows'
|
|
25
|
+
* macos: 'react-native-macos'
|
|
26
|
+
* }
|
|
27
|
+
*/
|
|
28
|
+
export function reactNativePlatformResolver(platformImplementations: {
|
|
29
|
+
[platform: string]: string,
|
|
30
|
+
}): CustomResolver {
|
|
31
|
+
return (context, moduleName, platform) => {
|
|
32
|
+
let modifiedModuleName = moduleName;
|
|
33
|
+
if (platform != null && platformImplementations[platform]) {
|
|
34
|
+
if (moduleName === 'react-native') {
|
|
35
|
+
modifiedModuleName = platformImplementations[platform];
|
|
36
|
+
} else if (moduleName.startsWith('react-native/')) {
|
|
37
|
+
modifiedModuleName = `${
|
|
38
|
+
platformImplementations[platform]
|
|
39
|
+
}/${modifiedModuleName.slice('react-native/'.length)}`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return context.resolveRequest(context, modifiedModuleName, platform);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
|
|
2
|
+
|
|
3
|
+
source "$THIS_DIR/.packager.env"
|
|
4
|
+
cd $PROJECT_ROOT
|
|
5
|
+
$REACT_NATIVE_PATH/cli.js start
|
|
6
|
+
|
|
7
|
+
if [[ -z "$CI" ]]; then
|
|
8
|
+
echo "Process terminated. Press <enter> to close the window"
|
|
9
|
+
read -r
|
|
10
|
+
fi
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-native/community-cli-plugin",
|
|
3
|
+
"version": "0.73.0",
|
|
4
|
+
"description": "Core CLI commands for React Native",
|
|
5
|
+
"keywords": ["react-native", "tools"],
|
|
6
|
+
"homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/buid-scripts#readme",
|
|
7
|
+
"bugs": "https://github.com/facebook/react-native/issues",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/facebook/react-native.git",
|
|
11
|
+
"directory": "packages/community-cli-plugin"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"exports": { ".": "./dist/index.js", "./package.json": "./package.json" },
|
|
15
|
+
"files": ["dist", "launchPackager.bat", "launchPackager.command"],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@react-native-community/cli-server-api": "12.0.0-alpha.7",
|
|
18
|
+
"@react-native-community/cli-tools": "12.0.0-alpha.7",
|
|
19
|
+
"@react-native/metro-babel-transformer": "^0.73.11",
|
|
20
|
+
"chalk": "^4.0.0",
|
|
21
|
+
"execa": "^5.1.1",
|
|
22
|
+
"metro": "0.77.0",
|
|
23
|
+
"metro-config": "0.77.0",
|
|
24
|
+
"metro-core": "0.77.0",
|
|
25
|
+
"metro-resolver": "0.77.0",
|
|
26
|
+
"readline": "^1.3.0"
|
|
27
|
+
},
|
|
28
|
+
"engines": { "node": ">=18" }
|
|
29
|
+
}
|