@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,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) {
|
|
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,139 @@
|
|
|
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 {logger} from '@react-native-community/cli-tools';
|
|
15
|
+
import fs from 'fs';
|
|
16
|
+
import path from 'path';
|
|
17
|
+
import {
|
|
18
|
+
cleanAssetCatalog,
|
|
19
|
+
getImageSet,
|
|
20
|
+
isCatalogAsset,
|
|
21
|
+
writeImageSet,
|
|
22
|
+
} from './assetCatalogIOS';
|
|
23
|
+
import filterPlatformAssetScales from './filterPlatformAssetScales';
|
|
24
|
+
import getAssetDestPathAndroid from './getAssetDestPathAndroid';
|
|
25
|
+
import getAssetDestPathIOS from './getAssetDestPathIOS';
|
|
26
|
+
|
|
27
|
+
type CopiedFiles = {
|
|
28
|
+
[src: string]: string,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
async function saveAssets(
|
|
32
|
+
assets: $ReadOnlyArray<AssetData>,
|
|
33
|
+
platform: string,
|
|
34
|
+
assetsDest?: string,
|
|
35
|
+
assetCatalogDest?: string,
|
|
36
|
+
): Promise<void> {
|
|
37
|
+
if (!assetsDest) {
|
|
38
|
+
logger.warn('Assets destination folder is not set, skipping...');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const filesToCopy: CopiedFiles = {};
|
|
43
|
+
|
|
44
|
+
const getAssetDestPath =
|
|
45
|
+
platform === 'android' ? getAssetDestPathAndroid : getAssetDestPathIOS;
|
|
46
|
+
|
|
47
|
+
const addAssetToCopy = (asset: AssetData) => {
|
|
48
|
+
const validScales = new Set(
|
|
49
|
+
filterPlatformAssetScales(platform, asset.scales),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
asset.scales.forEach((scale, idx) => {
|
|
53
|
+
if (!validScales.has(scale)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const src = asset.files[idx];
|
|
57
|
+
const dest = path.join(assetsDest, getAssetDestPath(asset, scale));
|
|
58
|
+
filesToCopy[src] = dest;
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
if (platform === 'ios' && assetCatalogDest != null) {
|
|
63
|
+
// Use iOS Asset Catalog for images. This will allow Apple app thinning to
|
|
64
|
+
// remove unused scales from the optimized bundle.
|
|
65
|
+
const catalogDir = path.join(assetCatalogDest, 'RNAssets.xcassets');
|
|
66
|
+
if (!fs.existsSync(catalogDir)) {
|
|
67
|
+
logger.error(
|
|
68
|
+
`Could not find asset catalog 'RNAssets.xcassets' in ${assetCatalogDest}. Make sure to create it if it does not exist.`,
|
|
69
|
+
);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
logger.info('Adding images to asset catalog', catalogDir);
|
|
74
|
+
cleanAssetCatalog(catalogDir);
|
|
75
|
+
for (const asset of assets) {
|
|
76
|
+
if (isCatalogAsset(asset)) {
|
|
77
|
+
const imageSet = getImageSet(
|
|
78
|
+
catalogDir,
|
|
79
|
+
asset,
|
|
80
|
+
filterPlatformAssetScales(platform, asset.scales),
|
|
81
|
+
);
|
|
82
|
+
writeImageSet(imageSet);
|
|
83
|
+
} else {
|
|
84
|
+
addAssetToCopy(asset);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
logger.info('Done adding images to asset catalog');
|
|
88
|
+
} else {
|
|
89
|
+
assets.forEach(addAssetToCopy);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return copyAll(filesToCopy);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function copyAll(filesToCopy: CopiedFiles) {
|
|
96
|
+
const queue = Object.keys(filesToCopy);
|
|
97
|
+
if (queue.length === 0) {
|
|
98
|
+
return Promise.resolve();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
logger.info(`Copying ${queue.length} asset files`);
|
|
102
|
+
return new Promise<void>((resolve, reject) => {
|
|
103
|
+
const copyNext = (error?: Error) => {
|
|
104
|
+
if (error) {
|
|
105
|
+
reject(error);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (queue.length === 0) {
|
|
109
|
+
logger.info('Done copying assets');
|
|
110
|
+
resolve();
|
|
111
|
+
} else {
|
|
112
|
+
// queue.length === 0 is checked in previous branch, so this is string
|
|
113
|
+
const src = queue.shift();
|
|
114
|
+
const dest = filesToCopy[src];
|
|
115
|
+
copy(src, dest, copyNext);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
copyNext();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function copy(
|
|
123
|
+
src: string,
|
|
124
|
+
dest: string,
|
|
125
|
+
callback: (error: Error) => void,
|
|
126
|
+
): void {
|
|
127
|
+
const destDir = path.dirname(dest);
|
|
128
|
+
fs.mkdir(destDir, {recursive: true}, (err?) => {
|
|
129
|
+
if (err) {
|
|
130
|
+
callback(err);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
fs.createReadStream(src)
|
|
134
|
+
.pipe(fs.createWriteStream(dest))
|
|
135
|
+
.on('finish', callback);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export default saveAssets;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
Object.defineProperty(exports, "startServerInNewWindow", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _startServerInNewWindow.startServerInNewWindow;
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
var _path = _interopRequireDefault(require("path"));
|
|
14
|
+
var _runServer = _interopRequireDefault(require("./runServer"));
|
|
15
|
+
var _startServerInNewWindow = require("./startServerInNewWindow");
|
|
16
|
+
function _interopRequireDefault(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : { default: obj };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
21
|
+
*
|
|
22
|
+
* This source code is licensed under the MIT license found in the
|
|
23
|
+
* LICENSE file in the root directory of this source tree.
|
|
24
|
+
*
|
|
25
|
+
*
|
|
26
|
+
* @format
|
|
27
|
+
* @oncall react_native
|
|
28
|
+
*/
|
|
29
|
+
var _default = {
|
|
30
|
+
name: "start",
|
|
31
|
+
func: _runServer.default,
|
|
32
|
+
description: "Start the React Native development server.",
|
|
33
|
+
options: [
|
|
34
|
+
{
|
|
35
|
+
name: "--port <number>",
|
|
36
|
+
parse: Number,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "--host <string>",
|
|
40
|
+
default: "",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "--projectRoot <path>",
|
|
44
|
+
description: "Path to a custom project root",
|
|
45
|
+
parse: (val) => _path.default.resolve(val),
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "--watchFolders <list>",
|
|
49
|
+
description:
|
|
50
|
+
"Specify any additional folders to be added to the watch list",
|
|
51
|
+
parse: (val) =>
|
|
52
|
+
val.split(",").map((folder) => _path.default.resolve(folder)),
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "--assetPlugins <list>",
|
|
56
|
+
description:
|
|
57
|
+
"Specify any additional asset plugins to be used by the packager by full filepath",
|
|
58
|
+
parse: (val) => val.split(","),
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "--sourceExts <list>",
|
|
62
|
+
description:
|
|
63
|
+
"Specify any additional source extensions to be used by the packager",
|
|
64
|
+
parse: (val) => val.split(","),
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "--max-workers <number>",
|
|
68
|
+
description:
|
|
69
|
+
"Specifies the maximum number of workers the worker-pool " +
|
|
70
|
+
"will spawn for transforming files. This defaults to the number of the " +
|
|
71
|
+
"cores available on your machine.",
|
|
72
|
+
parse: (workers) => Number(workers),
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "--transformer <string>",
|
|
76
|
+
description: "Specify a custom transformer to be used",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "--reset-cache, --resetCache",
|
|
80
|
+
description: "Removes cached files",
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: "--custom-log-reporter-path, --customLogReporterPath <string>",
|
|
84
|
+
description:
|
|
85
|
+
"Path to a JavaScript file that exports a log reporter as a replacement for TerminalReporter",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "--https",
|
|
89
|
+
description: "Enables https connections to the server",
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "--key <path>",
|
|
93
|
+
description: "Path to custom SSL key",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "--cert <path>",
|
|
97
|
+
description: "Path to custom SSL cert",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "--config <string>",
|
|
101
|
+
description: "Path to the CLI configuration file",
|
|
102
|
+
parse: (val) => _path.default.resolve(val),
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "--no-interactive",
|
|
106
|
+
description: "Disables interactive mode",
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
};
|
|
110
|
+
exports.default = _default;
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
import runServer from './runServer';
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
name: 'start',
|
|
17
|
+
func: runServer,
|
|
18
|
+
description: 'Start the React Native development server.',
|
|
19
|
+
options: [
|
|
20
|
+
{
|
|
21
|
+
name: '--port <number>',
|
|
22
|
+
parse: Number,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: '--host <string>',
|
|
26
|
+
default: '',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: '--projectRoot <path>',
|
|
30
|
+
description: 'Path to a custom project root',
|
|
31
|
+
parse: (val: string): string => path.resolve(val),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: '--watchFolders <list>',
|
|
35
|
+
description:
|
|
36
|
+
'Specify any additional folders to be added to the watch list',
|
|
37
|
+
parse: (val: string): Array<string> =>
|
|
38
|
+
val.split(',').map((folder: string) => path.resolve(folder)),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: '--assetPlugins <list>',
|
|
42
|
+
description:
|
|
43
|
+
'Specify any additional asset plugins to be used by the packager by full filepath',
|
|
44
|
+
parse: (val: string): Array<string> => val.split(','),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: '--sourceExts <list>',
|
|
48
|
+
description:
|
|
49
|
+
'Specify any additional source extensions to be used by the packager',
|
|
50
|
+
parse: (val: string): Array<string> => val.split(','),
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: '--max-workers <number>',
|
|
54
|
+
description:
|
|
55
|
+
'Specifies the maximum number of workers the worker-pool ' +
|
|
56
|
+
'will spawn for transforming files. This defaults to the number of the ' +
|
|
57
|
+
'cores available on your machine.',
|
|
58
|
+
parse: (workers: string): number => Number(workers),
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: '--transformer <string>',
|
|
62
|
+
description: 'Specify a custom transformer to be used',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: '--reset-cache, --resetCache',
|
|
66
|
+
description: 'Removes cached files',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: '--custom-log-reporter-path, --customLogReporterPath <string>',
|
|
70
|
+
description:
|
|
71
|
+
'Path to a JavaScript file that exports a log reporter as a replacement for TerminalReporter',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: '--https',
|
|
75
|
+
description: 'Enables https connections to the server',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: '--key <path>',
|
|
79
|
+
description: 'Path to custom SSL key',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: '--cert <path>',
|
|
83
|
+
description: 'Path to custom SSL cert',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: '--config <string>',
|
|
87
|
+
description: 'Path to the CLI configuration file',
|
|
88
|
+
parse: (val: string): string => path.resolve(val),
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: '--no-interactive',
|
|
92
|
+
description: 'Disables interactive mode',
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export {startServerInNewWindow} from './startServerInNewWindow';
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _metro = _interopRequireDefault(require("metro"));
|
|
8
|
+
var _metroCore = require("metro-core");
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _cliServerApi = require("@react-native-community/cli-server-api");
|
|
11
|
+
var _loadMetroConfig = _interopRequireDefault(
|
|
12
|
+
require("../../utils/loadMetroConfig")
|
|
13
|
+
);
|
|
14
|
+
var _cliTools = require("@react-native-community/cli-tools");
|
|
15
|
+
var _watchMode = _interopRequireDefault(require("./watchMode"));
|
|
16
|
+
function _interopRequireDefault(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : { default: obj };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
21
|
+
*
|
|
22
|
+
* This source code is licensed under the MIT license found in the
|
|
23
|
+
* LICENSE file in the root directory of this source tree.
|
|
24
|
+
*
|
|
25
|
+
*
|
|
26
|
+
* @format
|
|
27
|
+
* @oncall react_native
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
async function runServer(_argv, ctx, args) {
|
|
31
|
+
let reportEvent;
|
|
32
|
+
const terminal = new _metroCore.Terminal(process.stdout);
|
|
33
|
+
const ReporterImpl = getReporterImpl(args.customLogReporterPath);
|
|
34
|
+
const terminalReporter = new ReporterImpl(terminal);
|
|
35
|
+
const metroConfig = await (0, _loadMetroConfig.default)(ctx, {
|
|
36
|
+
config: args.config,
|
|
37
|
+
maxWorkers: args.maxWorkers,
|
|
38
|
+
port: args.port,
|
|
39
|
+
resetCache: args.resetCache,
|
|
40
|
+
watchFolders: args.watchFolders,
|
|
41
|
+
projectRoot: args.projectRoot,
|
|
42
|
+
sourceExts: args.sourceExts,
|
|
43
|
+
reporter: {
|
|
44
|
+
update(event) {
|
|
45
|
+
terminalReporter.update(event);
|
|
46
|
+
if (reportEvent) {
|
|
47
|
+
reportEvent(event);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
if (args.assetPlugins) {
|
|
53
|
+
// $FlowIgnore[cannot-write] Assigning to readonly property
|
|
54
|
+
metroConfig.transformer.assetPlugins = args.assetPlugins.map((plugin) =>
|
|
55
|
+
require.resolve(plugin)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const {
|
|
59
|
+
middleware,
|
|
60
|
+
websocketEndpoints,
|
|
61
|
+
messageSocketEndpoint,
|
|
62
|
+
eventsSocketEndpoint,
|
|
63
|
+
} = (0, _cliServerApi.createDevServerMiddleware)({
|
|
64
|
+
host: args.host,
|
|
65
|
+
port: metroConfig.server.port,
|
|
66
|
+
watchFolders: metroConfig.watchFolders,
|
|
67
|
+
});
|
|
68
|
+
middleware.use(_cliServerApi.indexPageMiddleware);
|
|
69
|
+
const customEnhanceMiddleware = metroConfig.server.enhanceMiddleware;
|
|
70
|
+
// $FlowIgnore[cannot-write] Assigning to readonly property
|
|
71
|
+
metroConfig.server.enhanceMiddleware = (metroMiddleware, server) => {
|
|
72
|
+
if (customEnhanceMiddleware) {
|
|
73
|
+
metroMiddleware = customEnhanceMiddleware(metroMiddleware, server);
|
|
74
|
+
}
|
|
75
|
+
return middleware.use(metroMiddleware);
|
|
76
|
+
};
|
|
77
|
+
const serverInstance = await _metro.default.runServer(metroConfig, {
|
|
78
|
+
host: args.host,
|
|
79
|
+
secure: args.https,
|
|
80
|
+
secureCert: args.cert,
|
|
81
|
+
secureKey: args.key,
|
|
82
|
+
// $FlowFixMe[incompatible-call] Incompatibly defined WebSocketServer type
|
|
83
|
+
websocketEndpoints,
|
|
84
|
+
});
|
|
85
|
+
reportEvent = eventsSocketEndpoint.reportEvent;
|
|
86
|
+
if (args.interactive) {
|
|
87
|
+
(0, _watchMode.default)(messageSocketEndpoint, ctx);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// In Node 8, the default keep-alive for an HTTP connection is 5 seconds. In
|
|
91
|
+
// early versions of Node 8, this was implemented in a buggy way which caused
|
|
92
|
+
// some HTTP responses (like those containing large JS bundles) to be
|
|
93
|
+
// terminated early.
|
|
94
|
+
//
|
|
95
|
+
// As a workaround, arbitrarily increase the keep-alive from 5 to 30 seconds,
|
|
96
|
+
// which should be enough to send even the largest of JS bundles.
|
|
97
|
+
//
|
|
98
|
+
// For more info: https://github.com/nodejs/node/issues/13391
|
|
99
|
+
//
|
|
100
|
+
serverInstance.keepAliveTimeout = 30000;
|
|
101
|
+
await _cliTools.version.logIfUpdateAvailable(ctx.root);
|
|
102
|
+
}
|
|
103
|
+
function getReporterImpl(customLogReporterPath) {
|
|
104
|
+
if (customLogReporterPath == null) {
|
|
105
|
+
return require("metro/src/lib/TerminalReporter");
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
// First we let require resolve it, so we can require packages in node_modules
|
|
109
|
+
// as expected. eg: require('my-package/reporter');
|
|
110
|
+
// $FlowIgnore[unsupported-syntax]
|
|
111
|
+
return require(customLogReporterPath);
|
|
112
|
+
} catch (e) {
|
|
113
|
+
if (e.code !== "MODULE_NOT_FOUND") {
|
|
114
|
+
throw e;
|
|
115
|
+
}
|
|
116
|
+
// If that doesn't work, then we next try relative to the cwd, eg:
|
|
117
|
+
// require('./reporter');
|
|
118
|
+
// $FlowIgnore[unsupported-syntax]
|
|
119
|
+
return require(_path.default.resolve(customLogReporterPath));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
var _default = runServer;
|
|
123
|
+
exports.default = _default;
|