@rnx-kit/cli 0.12.7 → 0.14.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.
- package/CHANGELOG.md +117 -0
- package/README.md +90 -65
- package/coverage/clover.xml +92 -104
- package/coverage/coverage-final.json +7 -6
- package/coverage/lcov-report/index.html +29 -29
- package/coverage/lcov-report/src/bundle/index.html +29 -29
- package/coverage/lcov-report/src/bundle/kit-config.ts.html +63 -117
- package/coverage/lcov-report/src/bundle/metro.ts.html +40 -163
- package/coverage/lcov-report/src/bundle/overrides.ts.html +28 -58
- package/coverage/lcov-report/src/bundler-plugin-defaults.ts.html +115 -0
- package/coverage/lcov-report/src/copy-assets.ts.html +1 -1
- package/coverage/lcov-report/src/index.html +26 -11
- package/coverage/lcov-report/src/metro-config.ts.html +49 -31
- package/coverage/lcov-report/src/typescript/index.html +1 -1
- package/coverage/lcov-report/src/typescript/project-cache.ts.html +5 -5
- package/coverage/lcov.info +173 -193
- package/lib/bundle/kit-config.d.ts +9 -15
- package/lib/bundle/kit-config.d.ts.map +1 -1
- package/lib/bundle/kit-config.js +34 -43
- package/lib/bundle/kit-config.js.map +1 -1
- package/lib/bundle/metro.d.ts +7 -11
- package/lib/bundle/metro.d.ts.map +1 -1
- package/lib/bundle/metro.js +21 -59
- package/lib/bundle/metro.js.map +1 -1
- package/lib/bundle/overrides.d.ts +11 -9
- package/lib/bundle/overrides.d.ts.map +1 -1
- package/lib/bundle/overrides.js +10 -18
- package/lib/bundle/overrides.js.map +1 -1
- package/lib/bundle/types.d.ts +4 -17
- package/lib/bundle/types.d.ts.map +1 -1
- package/lib/bundle.d.ts +8 -7
- package/lib/bundle.d.ts.map +1 -1
- package/lib/bundle.js +8 -35
- package/lib/bundle.js.map +1 -1
- package/lib/bundler-plugin-defaults.d.ts +3 -0
- package/lib/bundler-plugin-defaults.d.ts.map +1 -0
- package/lib/bundler-plugin-defaults.js +13 -0
- package/lib/bundler-plugin-defaults.js.map +1 -0
- package/lib/clean.js +106 -117
- package/lib/clean.js.map +1 -1
- package/lib/copy-assets.js +194 -210
- package/lib/copy-assets.js.map +1 -1
- package/lib/dep-check.js +12 -7
- package/lib/dep-check.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/metro-config.d.ts +3 -2
- package/lib/metro-config.d.ts.map +1 -1
- package/lib/metro-config.js +7 -5
- package/lib/metro-config.js.map +1 -1
- package/lib/parsers.d.ts +2 -0
- package/lib/parsers.d.ts.map +1 -1
- package/lib/parsers.js +16 -1
- package/lib/parsers.js.map +1 -1
- package/lib/serve/kit-config.d.ts +6 -5
- package/lib/serve/kit-config.d.ts.map +1 -1
- package/lib/serve/kit-config.js +21 -6
- package/lib/serve/kit-config.js.map +1 -1
- package/lib/start.d.ts +2 -2
- package/lib/start.d.ts.map +1 -1
- package/lib/start.js +146 -158
- package/lib/start.js.map +1 -1
- package/package.json +9 -6
- package/react-native.config.js +65 -59
- package/src/bundle/kit-config.ts +42 -60
- package/src/bundle/metro.ts +15 -56
- package/src/bundle/overrides.ts +24 -34
- package/src/bundle/types.ts +17 -23
- package/src/bundle.ts +18 -36
- package/src/bundler-plugin-defaults.ts +10 -0
- package/src/index.ts +1 -1
- package/src/metro-config.ts +12 -6
- package/src/parsers.ts +19 -0
- package/src/serve/kit-config.ts +23 -11
- package/src/start.ts +23 -29
- package/test/bundle/__mocks__/@rnx-kit/config.js +2 -3
- package/test/bundle/__mocks__/@rnx-kit/console.js +1 -0
- package/test/bundle/__mocks__/@rnx-kit/metro-service.js +1 -0
- package/test/bundle/kit-config.test.ts +102 -100
- package/test/bundle/metro.test.ts +58 -98
- package/test/bundle/overrides.test.ts +29 -25
- package/test/copy-assets/assembleAarBundle.test.ts +1 -0
- package/lib/types.d.ts +0 -5
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -3
- package/lib/types.js.map +0 -1
- package/src/types.ts +0 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rnx-kit/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.2",
|
|
4
4
|
"description": "Command-line interface for working with kit packages in your repo",
|
|
5
5
|
"homepage": "https://github.com/microsoft/rnx-kit/tree/main/packages/cli",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"test": "rnx-kit-scripts test"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@rnx-kit/config": "^0.
|
|
22
|
+
"@rnx-kit/config": "^0.5.0",
|
|
23
23
|
"@rnx-kit/console": "^1.0.11",
|
|
24
24
|
"@rnx-kit/dep-check": "^1.12.0",
|
|
25
25
|
"@rnx-kit/metro-plugin-cyclic-dependencies-detector": "^1.0.21",
|
|
26
26
|
"@rnx-kit/metro-plugin-duplicates-checker": "^1.2.15",
|
|
27
27
|
"@rnx-kit/metro-serializer": "^1.0.11",
|
|
28
28
|
"@rnx-kit/metro-serializer-esbuild": "^0.1.0",
|
|
29
|
-
"@rnx-kit/metro-service": "^
|
|
29
|
+
"@rnx-kit/metro-service": "^3.0.0",
|
|
30
30
|
"@rnx-kit/third-party-notices": "^1.2.13",
|
|
31
31
|
"@rnx-kit/tools-language": "^1.3.0",
|
|
32
32
|
"@rnx-kit/tools-node": "^1.2.7",
|
|
@@ -53,17 +53,20 @@
|
|
|
53
53
|
"@react-native-community/cli-types": "^6.0.0",
|
|
54
54
|
"@rnx-kit/scripts": "*",
|
|
55
55
|
"@types/metro": "^0.66.0",
|
|
56
|
+
"@types/metro-babel-transformer": "^0.66.0",
|
|
56
57
|
"@types/metro-config": "^0.66.0",
|
|
57
58
|
"@types/qrcode": "^1.4.2",
|
|
58
|
-
"jest
|
|
59
|
+
"jest": "^27.0.0",
|
|
60
|
+
"jest-extended": "^2.0.0",
|
|
59
61
|
"memfs": "^3.4.1",
|
|
62
|
+
"metro-config": "^0.67.0",
|
|
60
63
|
"typescript": "^4.0.0"
|
|
61
64
|
},
|
|
62
65
|
"depcheck": {
|
|
63
66
|
"ignoreMatches": [
|
|
64
67
|
"@react-native-community/cli-clean",
|
|
65
68
|
"metro",
|
|
66
|
-
"metro-
|
|
69
|
+
"metro-babel-transformer",
|
|
67
70
|
"readline"
|
|
68
71
|
]
|
|
69
72
|
},
|
|
@@ -73,7 +76,7 @@
|
|
|
73
76
|
"jest": {
|
|
74
77
|
"preset": "@rnx-kit/scripts",
|
|
75
78
|
"setupFilesAfterEnv": [
|
|
76
|
-
"jest-extended"
|
|
79
|
+
"jest-extended/all"
|
|
77
80
|
]
|
|
78
81
|
}
|
|
79
82
|
}
|
package/react-native.config.js
CHANGED
|
@@ -2,6 +2,7 @@ const { parsePlatform } = require("@rnx-kit/tools-react-native/platform");
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const {
|
|
4
4
|
parseBoolean,
|
|
5
|
+
parseTransformProfile,
|
|
5
6
|
rnxBundle,
|
|
6
7
|
rnxCopyAssetsCommand,
|
|
7
8
|
rnxStart,
|
|
@@ -15,83 +16,86 @@ module.exports = {
|
|
|
15
16
|
commands: [
|
|
16
17
|
{
|
|
17
18
|
name: "rnx-bundle",
|
|
18
|
-
description:
|
|
19
|
+
description:
|
|
20
|
+
"Bundle your rnx-kit package for offline use. See https://aka.ms/rnx-kit.",
|
|
19
21
|
func: rnxBundle,
|
|
20
22
|
options: [
|
|
21
23
|
{
|
|
22
24
|
name: "--id [id]",
|
|
23
25
|
description:
|
|
24
|
-
"Target bundle definition. This is only needed when the kit configuration has multiple bundle definitions.",
|
|
26
|
+
"Target bundle definition. This is only needed when the rnx-kit configuration has multiple bundle definitions.",
|
|
25
27
|
},
|
|
26
28
|
{
|
|
27
|
-
name: "--
|
|
29
|
+
name: "--entry-file [path]",
|
|
28
30
|
description:
|
|
29
|
-
"
|
|
30
|
-
parse: parsePlatform,
|
|
31
|
+
"Path to the root JavaScript or TypeScript file, either absolute or relative to the package.",
|
|
31
32
|
},
|
|
32
33
|
{
|
|
33
|
-
name: "--
|
|
34
|
+
name: "--platform [ios|android|windows|win32|macos]",
|
|
34
35
|
description:
|
|
35
|
-
"
|
|
36
|
+
"Target platform. When not given, all platforms in the rnx-kit configuration are bundled.",
|
|
37
|
+
parse: parsePlatform,
|
|
36
38
|
},
|
|
37
39
|
{
|
|
38
|
-
name: "--
|
|
40
|
+
name: "--dev [boolean]",
|
|
39
41
|
description:
|
|
40
|
-
"
|
|
42
|
+
"If false, warnings are disabled and the bundle is minified.",
|
|
43
|
+
default: true,
|
|
44
|
+
parse: parseBoolean,
|
|
41
45
|
},
|
|
42
46
|
{
|
|
43
|
-
name: "--
|
|
47
|
+
name: "--minify [boolean]",
|
|
44
48
|
description:
|
|
45
|
-
"
|
|
49
|
+
"Controls whether or not the bundle is minified. Disabling minification is useful for test builds.",
|
|
50
|
+
parse: parseBoolean,
|
|
46
51
|
},
|
|
47
52
|
{
|
|
48
|
-
name: "--bundle-
|
|
53
|
+
name: "--bundle-output [string]",
|
|
49
54
|
description:
|
|
50
|
-
"
|
|
55
|
+
"Path to the output bundle file, either absolute or relative to the package.",
|
|
51
56
|
},
|
|
52
57
|
{
|
|
53
58
|
name: "--bundle-encoding [utf8|utf16le|ascii]",
|
|
54
59
|
description:
|
|
55
60
|
"Character encoding to use when writing the bundle file.",
|
|
61
|
+
default: "utf8",
|
|
56
62
|
},
|
|
57
63
|
{
|
|
58
|
-
name: "--
|
|
64
|
+
name: "--max-workers [number]",
|
|
59
65
|
description:
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
parse: parseBoolean,
|
|
66
|
+
"Specifies the maximum number of parallel worker threads to use for transforming files. This defaults to the number of cores available on your machine.",
|
|
67
|
+
parse: parseInt,
|
|
63
68
|
},
|
|
64
69
|
{
|
|
65
|
-
name: "--
|
|
70
|
+
name: "--sourcemap-output [string]",
|
|
66
71
|
description:
|
|
67
|
-
"
|
|
68
|
-
parse: parseBoolean,
|
|
72
|
+
"Path where the bundle source map is written, either absolute or relative to the package.",
|
|
69
73
|
},
|
|
70
74
|
{
|
|
71
|
-
name: "--
|
|
72
|
-
description:
|
|
73
|
-
|
|
75
|
+
name: "--sourcemap-sources-root [string]",
|
|
76
|
+
description:
|
|
77
|
+
"Path to use when relativizing file entries in the bundle source map.",
|
|
74
78
|
},
|
|
75
79
|
{
|
|
76
|
-
name: "--
|
|
77
|
-
description: "
|
|
78
|
-
parse: parseBoolean,
|
|
80
|
+
name: "--sourcemap-use-absolute-path",
|
|
81
|
+
description: "Report SourceMapURL using its full path",
|
|
79
82
|
},
|
|
80
83
|
{
|
|
81
|
-
name: "--
|
|
84
|
+
name: "--assets-dest [path]",
|
|
82
85
|
description:
|
|
83
|
-
"
|
|
84
|
-
parse: parseInt,
|
|
86
|
+
"Path where bundle assets like images are written, either absolute or relative to the package. If not given, assets are ignored.",
|
|
85
87
|
},
|
|
86
88
|
{
|
|
87
|
-
name: "--
|
|
89
|
+
name: "--tree-shake [boolean]",
|
|
88
90
|
description:
|
|
89
|
-
"
|
|
91
|
+
"Enable tree shaking to remove unused code and reduce the bundle size.",
|
|
92
|
+
parse: parseBoolean,
|
|
90
93
|
},
|
|
91
94
|
{
|
|
92
|
-
name: "--
|
|
95
|
+
name: "--unstable-transform-profile [string]",
|
|
93
96
|
description:
|
|
94
|
-
"
|
|
97
|
+
"Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default",
|
|
98
|
+
parse: parseTransformProfile,
|
|
95
99
|
},
|
|
96
100
|
{
|
|
97
101
|
name: "--reset-cache",
|
|
@@ -109,12 +113,6 @@ module.exports = {
|
|
|
109
113
|
description:
|
|
110
114
|
"Start a bundle-server to host your react-native experience during development",
|
|
111
115
|
options: [
|
|
112
|
-
{
|
|
113
|
-
name: "--host [string]",
|
|
114
|
-
description:
|
|
115
|
-
"Host name or address to bind when listening for incoming server requests. When not given, requests from all addresses are accepted.",
|
|
116
|
-
default: "",
|
|
117
|
-
},
|
|
118
116
|
{
|
|
119
117
|
name: "--port [number]",
|
|
120
118
|
description:
|
|
@@ -123,25 +121,31 @@ module.exports = {
|
|
|
123
121
|
default: 8081,
|
|
124
122
|
},
|
|
125
123
|
{
|
|
126
|
-
name: "--
|
|
124
|
+
name: "--host [string]",
|
|
125
|
+
description:
|
|
126
|
+
"Host name or address to bind when listening for incoming server requests. When not given, requests from all addresses are accepted.",
|
|
127
|
+
default: "",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: "--projectRoot [path]",
|
|
127
131
|
description:
|
|
128
|
-
"Path to the root of your react-native
|
|
132
|
+
"Path to the root of your react-native project. The bundle server uses this root path to resolve all web requests.",
|
|
129
133
|
parse: (val) => path.resolve(val),
|
|
130
134
|
},
|
|
131
135
|
{
|
|
132
|
-
name: "--
|
|
136
|
+
name: "--watchFolders [paths]",
|
|
133
137
|
description:
|
|
134
|
-
"Additional folders which will be added to the file-watch list. Comma-separated. By default, Metro watches all project files
|
|
138
|
+
"Additional folders which will be added to the file-watch list. Comma-separated. By default, Metro watches all project files.",
|
|
135
139
|
parse: (val) => val.split(",").map((folder) => path.resolve(folder)),
|
|
136
140
|
},
|
|
137
141
|
{
|
|
138
|
-
name: "--
|
|
142
|
+
name: "--assetPlugins [list]",
|
|
139
143
|
description:
|
|
140
|
-
"Additional asset plugins to be used by the Metro Babel transformer. Comma-separated list containing plugin
|
|
144
|
+
"Additional asset plugins to be used by the Metro Babel transformer. Comma-separated list containing plugin module names or absolute paths to plugin packages.",
|
|
141
145
|
parse: (val) => val.split(","),
|
|
142
146
|
},
|
|
143
147
|
{
|
|
144
|
-
name: "--
|
|
148
|
+
name: "--sourceExts [list]",
|
|
145
149
|
description:
|
|
146
150
|
"Additional source-file extensions to include when generating bundles. Comma-separated list, excluding the leading dot.",
|
|
147
151
|
parse: (val) => val.split(","),
|
|
@@ -152,6 +156,10 @@ module.exports = {
|
|
|
152
156
|
"Specifies the maximum number of parallel worker threads to use for transforming files. This defaults to the number of cores available on your machine.",
|
|
153
157
|
parse: parseInt,
|
|
154
158
|
},
|
|
159
|
+
{
|
|
160
|
+
name: "--reset-cache",
|
|
161
|
+
description: "Reset the Metro cache.",
|
|
162
|
+
},
|
|
155
163
|
{
|
|
156
164
|
name: "--custom-log-reporter-path [string]",
|
|
157
165
|
description:
|
|
@@ -172,10 +180,6 @@ module.exports = {
|
|
|
172
180
|
description:
|
|
173
181
|
"Path to a custom SSL certificate file to use for secure (https) communication.",
|
|
174
182
|
},
|
|
175
|
-
{
|
|
176
|
-
name: "--reset-cache",
|
|
177
|
-
description: "Reset the Metro cache.",
|
|
178
|
-
},
|
|
179
183
|
{
|
|
180
184
|
name: "--config [string]",
|
|
181
185
|
description: "Path to the Metro configuration file.",
|
|
@@ -198,41 +202,43 @@ module.exports = {
|
|
|
198
202
|
{
|
|
199
203
|
name: "--root-path <path>",
|
|
200
204
|
description:
|
|
201
|
-
"The root of the repo
|
|
205
|
+
"The root of the repo. This is the starting point for finding each module in the source map dependency graph.",
|
|
202
206
|
},
|
|
203
207
|
{
|
|
204
208
|
name: "--source-map-file <file>",
|
|
205
|
-
description:
|
|
209
|
+
description:
|
|
210
|
+
"The source map file associated with the package's entry file. This source map eventually leads to all package dependencies and their licenses.",
|
|
206
211
|
},
|
|
207
212
|
{
|
|
208
213
|
name: "--json",
|
|
209
|
-
description:
|
|
214
|
+
description:
|
|
215
|
+
"Format the 3rd-party notice file as JSON instead of text.",
|
|
210
216
|
default: false,
|
|
211
217
|
parse: parseBoolean,
|
|
212
218
|
},
|
|
213
219
|
{
|
|
214
220
|
name: "--output-file [file]",
|
|
215
|
-
description:
|
|
221
|
+
description:
|
|
222
|
+
"The path to use when writing the 3rd-party notice file.",
|
|
216
223
|
},
|
|
217
224
|
{
|
|
218
225
|
name: "--ignore-scopes [string]",
|
|
219
226
|
description:
|
|
220
|
-
"Comma
|
|
227
|
+
"Comma-separated list of `npm` scopes to ignore when traversing the source map dependency graph.",
|
|
221
228
|
},
|
|
222
229
|
{
|
|
223
230
|
name: "--ignore-modules [string]",
|
|
224
231
|
description:
|
|
225
|
-
"Comma
|
|
232
|
+
"Comma-separated list of modules to ignore when traversing the source map dependency graph.",
|
|
226
233
|
},
|
|
227
234
|
{
|
|
228
235
|
name: "--preamble-text [string]",
|
|
229
236
|
description:
|
|
230
|
-
"A string to prepend
|
|
237
|
+
"A string to prepend to the start of the 3rd-party notice.",
|
|
231
238
|
},
|
|
232
239
|
{
|
|
233
240
|
name: "--additional-text [path]",
|
|
234
|
-
description:
|
|
235
|
-
"A string to append at the end of the generated licence file.",
|
|
241
|
+
description: "A string to append to the end of the 3rd-party notice.",
|
|
236
242
|
},
|
|
237
243
|
],
|
|
238
244
|
},
|
package/src/bundle/kit-config.ts
CHANGED
|
@@ -1,49 +1,11 @@
|
|
|
1
|
-
import type { BundleDefinitionWithRequiredParameters } from "@rnx-kit/config";
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
getBundleConfig,
|
|
3
|
+
getPlatformBundleConfig,
|
|
5
4
|
getKitConfig,
|
|
6
5
|
} from "@rnx-kit/config";
|
|
7
|
-
import { warn } from "@rnx-kit/console";
|
|
8
6
|
import type { AllPlatforms } from "@rnx-kit/tools-react-native/platform";
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Get a bundle definition from the kit configuration.
|
|
14
|
-
*
|
|
15
|
-
* @param id Optional bundle definition id. Only needed when the kit config has more than one definition.
|
|
16
|
-
* @returns Bundle definition matching the id (if given), or the first bundle definition found. `undefined` if bundling is disabled or not supported for the kit.
|
|
17
|
-
*/
|
|
18
|
-
export function getKitBundleDefinition(
|
|
19
|
-
id?: string
|
|
20
|
-
): BundleDefinitionWithRequiredParameters | undefined {
|
|
21
|
-
const kitConfig = getKitConfig();
|
|
22
|
-
if (!kitConfig) {
|
|
23
|
-
throw new Error(
|
|
24
|
-
"No kit configuration found for this react-native experience"
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (kitConfig.bundle === null || kitConfig.bundle === undefined) {
|
|
29
|
-
warn(
|
|
30
|
-
chalk.yellow(
|
|
31
|
-
"No bundle configuration found for this react-native experience -- skipping bundling"
|
|
32
|
-
)
|
|
33
|
-
);
|
|
34
|
-
return undefined;
|
|
35
|
-
} else if (!kitConfig.bundle) {
|
|
36
|
-
warn(
|
|
37
|
-
chalk.yellow(
|
|
38
|
-
"Bundling is disabled for this react-native experience -- skipping"
|
|
39
|
-
)
|
|
40
|
-
);
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// get the bundle definition
|
|
45
|
-
return getBundleDefinition(kitConfig.bundle, id);
|
|
46
|
-
}
|
|
7
|
+
import type { CliPlatformBundleConfig } from "./types";
|
|
8
|
+
import { getDefaultBundlerPlugins } from "../bundler-plugin-defaults";
|
|
47
9
|
|
|
48
10
|
/**
|
|
49
11
|
* Get the list of target platforms for bundling.
|
|
@@ -63,36 +25,56 @@ export function getTargetPlatforms(
|
|
|
63
25
|
return targetPlatforms;
|
|
64
26
|
}
|
|
65
27
|
throw new Error(
|
|
66
|
-
"No target platforms given. Update the kit configuration to include a target platform, or provide a target platform on the command-line."
|
|
28
|
+
"No target platforms given. Update the rnx-kit configuration to include a target platform, or provide a target platform on the command-line."
|
|
67
29
|
);
|
|
68
30
|
}
|
|
69
31
|
|
|
32
|
+
function getDefaultBundleParameters(platform: string) {
|
|
33
|
+
const extension =
|
|
34
|
+
platform === "ios" || platform === "macos" ? "jsbundle" : "bundle";
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
entryFile: "index.js",
|
|
38
|
+
bundleOutput: `index.${platform}.${extension}`,
|
|
39
|
+
sourcemapUseAbsolutePath: false,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
70
43
|
/**
|
|
71
|
-
* Get bundle configuration and target platform(s) from kit
|
|
72
|
-
*
|
|
73
|
-
*
|
|
44
|
+
* Get the bundle configuration and target platform(s) from the rnx-kit
|
|
45
|
+
* configuration. Use them to create an array of platform-specific
|
|
46
|
+
* bundle configurations.
|
|
47
|
+
*
|
|
48
|
+
* If an id is given, search for the matching bundle definition. Otherwise, use the first bundle definition.
|
|
74
49
|
*
|
|
75
|
-
* @param id Optional
|
|
50
|
+
* @param id Optional identity of the target bundle definition to return
|
|
76
51
|
* @param overridePlatform Override platform, typically from the command-line. When given, this overrides the list of target platforms.
|
|
77
|
-
* @returns Arrary of
|
|
52
|
+
* @returns Arrary of platform-specific bundle configurations
|
|
78
53
|
*/
|
|
79
|
-
export function
|
|
54
|
+
export function getCliPlatformBundleConfigs(
|
|
80
55
|
id?: string,
|
|
81
56
|
overridePlatform?: AllPlatforms
|
|
82
|
-
):
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
57
|
+
): CliPlatformBundleConfig[] {
|
|
58
|
+
const kitConfig = getKitConfig();
|
|
59
|
+
const maybeBundleConfig = kitConfig
|
|
60
|
+
? getBundleConfig(kitConfig, id)
|
|
61
|
+
: undefined;
|
|
62
|
+
const bundleConfig = maybeBundleConfig ?? {};
|
|
87
63
|
|
|
88
|
-
const platforms = getTargetPlatforms(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
64
|
+
const platforms = getTargetPlatforms(overridePlatform, bundleConfig.targets);
|
|
65
|
+
|
|
66
|
+
return platforms.map<CliPlatformBundleConfig>((platform) => {
|
|
67
|
+
const platformBundleConfig = getPlatformBundleConfig(
|
|
68
|
+
bundleConfig,
|
|
69
|
+
platform
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
// apply defaults to fill in any required props that are missing
|
|
92
73
|
|
|
93
|
-
return platforms.map<KitBundleConfig>((platform) => {
|
|
94
74
|
return {
|
|
95
|
-
...
|
|
75
|
+
...getDefaultBundlerPlugins(),
|
|
76
|
+
...getDefaultBundleParameters(platform),
|
|
77
|
+
...platformBundleConfig,
|
|
96
78
|
platform,
|
|
97
79
|
};
|
|
98
80
|
});
|
package/src/bundle/metro.ts
CHANGED
|
@@ -4,81 +4,40 @@ import { createDirectory } from "@rnx-kit/tools-node/fs";
|
|
|
4
4
|
import type { ConfigT } from "metro-config";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import { customizeMetroConfig } from "../metro-config";
|
|
7
|
-
import type {
|
|
8
|
-
import type { TypeScriptValidationOptions } from "../types";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Create Metro bundler arguments from a bundle configuration.
|
|
12
|
-
*
|
|
13
|
-
* @param bundleConfig Bundle configuration
|
|
14
|
-
* @returns Metro bundle arguments
|
|
15
|
-
*/
|
|
16
|
-
export function createMetroBundleArgs({
|
|
17
|
-
entryPath: entryFile,
|
|
18
|
-
distPath,
|
|
19
|
-
assetsPath: assetsDest,
|
|
20
|
-
bundlePrefix,
|
|
21
|
-
bundleEncoding,
|
|
22
|
-
sourceMapPath: sourcemapOutput,
|
|
23
|
-
sourceMapSourceRootPath: sourcemapSourcesRoot,
|
|
24
|
-
platform,
|
|
25
|
-
dev,
|
|
26
|
-
minify,
|
|
27
|
-
}: BundleConfig): MetroBundleArgs {
|
|
28
|
-
// assemble the full path to the bundle file
|
|
29
|
-
const bundleExtension =
|
|
30
|
-
platform === "ios" || platform === "macos" ? "jsbundle" : "bundle";
|
|
31
|
-
const bundleFile = `${bundlePrefix}.${platform}.${bundleExtension}`;
|
|
32
|
-
const bundlePath = path.join(distPath, bundleFile);
|
|
33
|
-
|
|
34
|
-
// always create a source-map in dev mode
|
|
35
|
-
if (dev) {
|
|
36
|
-
sourcemapOutput = sourcemapOutput ?? bundleFile + ".map";
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// use an absolute path for the source map file
|
|
40
|
-
if (sourcemapOutput) {
|
|
41
|
-
sourcemapOutput = path.join(distPath, sourcemapOutput);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
assetsDest,
|
|
46
|
-
entryFile,
|
|
47
|
-
minify,
|
|
48
|
-
platform,
|
|
49
|
-
dev,
|
|
50
|
-
bundleOutput: bundlePath,
|
|
51
|
-
bundleEncoding,
|
|
52
|
-
sourcemapOutput,
|
|
53
|
-
sourcemapSourcesRoot,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
7
|
+
import type { CliPlatformBundleConfig } from "./types";
|
|
56
8
|
|
|
57
9
|
/**
|
|
58
10
|
* Run the Metro bundler.
|
|
59
11
|
*
|
|
60
|
-
* @param tsservice TypeScript service to use for type-checking (when enabled)
|
|
61
12
|
* @param metroConfig Metro configuration
|
|
62
13
|
* @param bundleConfig Bundle configuration
|
|
14
|
+
* @param dev Choose whether or not this will be a "developer" bundle. The alternative is a "production" bundle.
|
|
15
|
+
* When `true`, warnings are enabled, and the bundle is not minified by default.
|
|
16
|
+
* Further, optimizations like constant folding are disabled.
|
|
17
|
+
* When `false`, warnings are disabled and the bundle is minified by default.
|
|
18
|
+
* @param minify Optionally choose whether or not the bundle is minified. When not set, minification is controlled by the `dev` property.
|
|
63
19
|
*/
|
|
64
20
|
export async function metroBundle(
|
|
65
21
|
metroConfig: ConfigT,
|
|
66
|
-
bundleConfig:
|
|
22
|
+
bundleConfig: CliPlatformBundleConfig,
|
|
23
|
+
dev: boolean,
|
|
24
|
+
minify?: boolean
|
|
67
25
|
): Promise<void> {
|
|
68
26
|
info(`Bundling ${bundleConfig.platform}...`);
|
|
69
27
|
|
|
70
|
-
const typescriptValidationOptions: TypeScriptValidationOptions = {
|
|
71
|
-
throwOnError: true,
|
|
72
|
-
};
|
|
73
28
|
customizeMetroConfig(
|
|
74
29
|
metroConfig,
|
|
75
30
|
bundleConfig.detectCyclicDependencies,
|
|
76
31
|
bundleConfig.detectDuplicateDependencies,
|
|
77
|
-
bundleConfig.typescriptValidation
|
|
32
|
+
bundleConfig.typescriptValidation,
|
|
78
33
|
bundleConfig.treeShake
|
|
79
34
|
);
|
|
80
35
|
|
|
81
|
-
const metroBundleArgs =
|
|
36
|
+
const metroBundleArgs: MetroBundleArgs = {
|
|
37
|
+
...bundleConfig,
|
|
38
|
+
dev,
|
|
39
|
+
minify,
|
|
40
|
+
};
|
|
82
41
|
|
|
83
42
|
// ensure all output directories exist
|
|
84
43
|
createDirectory(path.dirname(metroBundleArgs.bundleOutput));
|
package/src/bundle/overrides.ts
CHANGED
|
@@ -1,51 +1,41 @@
|
|
|
1
|
+
import type { TransformProfile } from "metro-babel-transformer";
|
|
1
2
|
import type { BundleArgs } from "@rnx-kit/metro-service";
|
|
2
3
|
import { pickValues } from "@rnx-kit/tools-language/properties";
|
|
3
|
-
import type {
|
|
4
|
+
import type { CliPlatformBundleConfig } from "./types";
|
|
4
5
|
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
assetsPath?: string;
|
|
9
|
-
bundlePrefix?: string;
|
|
6
|
+
export type BundleConfigOverrides = {
|
|
7
|
+
entryFile?: string;
|
|
8
|
+
bundleOutput?: string;
|
|
10
9
|
bundleEncoding?: BundleArgs["bundleEncoding"];
|
|
11
10
|
sourcemapOutput?: string;
|
|
12
11
|
sourcemapSourcesRoot?: string;
|
|
12
|
+
sourcemapUseAbsolutePath?: boolean;
|
|
13
|
+
assetsDest?: string;
|
|
13
14
|
treeShake?: boolean;
|
|
15
|
+
unstableTransformProfile?: TransformProfile;
|
|
14
16
|
};
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
|
-
* Apply overrides, if any, to each kit bundle
|
|
19
|
+
* Apply overrides, if any, to each rnx-kit bundle configuration. Overrides are applied in-place.
|
|
18
20
|
*
|
|
19
21
|
* @param overrides Optional overrides to apply
|
|
20
|
-
* @param configs Array of
|
|
22
|
+
* @param configs Array of platform-specific bundle configurations. This is modified if any overrides are applied.
|
|
21
23
|
*/
|
|
22
|
-
export function
|
|
23
|
-
overrides:
|
|
24
|
-
configs:
|
|
24
|
+
export function applyBundleConfigOverrides(
|
|
25
|
+
overrides: BundleConfigOverrides,
|
|
26
|
+
configs: CliPlatformBundleConfig[]
|
|
25
27
|
): void {
|
|
26
|
-
const overridesToApply = pickValues(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
],
|
|
38
|
-
[
|
|
39
|
-
"entryPath",
|
|
40
|
-
"distPath",
|
|
41
|
-
"assetsPath",
|
|
42
|
-
"bundlePrefix",
|
|
43
|
-
"bundleEncoding",
|
|
44
|
-
"sourcemapOutput",
|
|
45
|
-
"sourcemapSourcesRoot",
|
|
46
|
-
"treeShake",
|
|
47
|
-
]
|
|
48
|
-
);
|
|
28
|
+
const overridesToApply = pickValues(overrides, [
|
|
29
|
+
"entryFile",
|
|
30
|
+
"bundleOutput",
|
|
31
|
+
"bundleEncoding",
|
|
32
|
+
"sourcemapOutput",
|
|
33
|
+
"sourcemapSourcesRoot",
|
|
34
|
+
"sourcemapUseAbsolutePath",
|
|
35
|
+
"assetsDest",
|
|
36
|
+
"treeShake",
|
|
37
|
+
"unstableTransformProfile",
|
|
38
|
+
]);
|
|
49
39
|
if (overridesToApply) {
|
|
50
40
|
for (const config of configs) {
|
|
51
41
|
Object.assign(config, overridesToApply);
|
package/src/bundle/types.ts
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
BundleRequiredParameters,
|
|
4
|
-
} from "@rnx-kit/config";
|
|
1
|
+
import type { TransformProfile } from "metro-babel-transformer";
|
|
2
|
+
import type { BundleParameters } from "@rnx-kit/config";
|
|
5
3
|
import type { AllPlatforms } from "@rnx-kit/tools-react-native/platform";
|
|
6
4
|
|
|
7
|
-
export type
|
|
8
|
-
|
|
5
|
+
export type CliPlatformBundleConfig = BundleParameters &
|
|
6
|
+
Required<
|
|
7
|
+
Pick<
|
|
8
|
+
BundleParameters,
|
|
9
|
+
| "entryFile"
|
|
10
|
+
| "bundleOutput"
|
|
11
|
+
| "sourcemapUseAbsolutePath"
|
|
12
|
+
| "detectCyclicDependencies"
|
|
13
|
+
| "detectDuplicateDependencies"
|
|
14
|
+
| "typescriptValidation"
|
|
15
|
+
| "treeShake"
|
|
16
|
+
>
|
|
17
|
+
> & {
|
|
18
|
+
unstableTransformProfile?: TransformProfile;
|
|
19
|
+
|
|
9
20
|
/**
|
|
10
21
|
* Target platform for the bundle
|
|
11
22
|
*/
|
|
12
23
|
platform: AllPlatforms;
|
|
13
24
|
};
|
|
14
|
-
|
|
15
|
-
export type BundleConfig = KitBundleConfig & {
|
|
16
|
-
/**
|
|
17
|
-
* Choose whether or not this will be a "developer" bundle. The alternative is a "production" bundle.
|
|
18
|
-
*
|
|
19
|
-
* When `true`, warnings are enabled, and the bundle is not minified by default.
|
|
20
|
-
* Further, optimizations like constant folding are disabled.
|
|
21
|
-
*
|
|
22
|
-
* When `false`, warnings are disabled and the bundle is minified by default.
|
|
23
|
-
*/
|
|
24
|
-
dev: boolean;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Optionally choose whether or not the bundle is minified. When not set, minification is controlled by the `dev` property.
|
|
28
|
-
*/
|
|
29
|
-
minify?: boolean;
|
|
30
|
-
};
|