@rnx-kit/cli 0.16.28 → 0.16.30

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 (61) hide show
  1. package/lib/align-deps.d.ts +1 -1
  2. package/lib/align-deps.js +8 -9
  3. package/lib/bundle/cliOptions.d.ts +2 -2
  4. package/lib/bundle/cliOptions.js +27 -27
  5. package/lib/bundle/defaultPlugins.js +1 -2
  6. package/lib/bundle/hermes.d.ts +2 -1
  7. package/lib/bundle/hermes.js +5 -12
  8. package/lib/bundle/kit-config.js +2 -3
  9. package/lib/bundle/metro.js +6 -10
  10. package/lib/bundle/overrides.js +2 -2
  11. package/lib/bundle.d.ts +3 -3
  12. package/lib/bundle.js +6 -6
  13. package/lib/clean.d.ts +2 -2
  14. package/lib/clean.js +44 -64
  15. package/lib/copy-assets.js +6 -6
  16. package/lib/helpers/externals.d.ts +4 -0
  17. package/lib/{serve/external.js → helpers/externals.js} +11 -10
  18. package/lib/helpers/filesystem.d.ts +3 -0
  19. package/lib/helpers/filesystem.js +31 -0
  20. package/lib/{metro-config.js → helpers/metro-config.js} +2 -3
  21. package/lib/{parsers.d.ts → helpers/parsers.d.ts} +1 -1
  22. package/lib/{parsers.js → helpers/parsers.js} +20 -19
  23. package/lib/index.d.ts +15 -16
  24. package/lib/index.js +1 -5
  25. package/lib/ram-bundle.d.ts +4 -4
  26. package/lib/ram-bundle.js +4 -4
  27. package/lib/serve/help.js +1 -2
  28. package/lib/serve/keyboard.js +1 -2
  29. package/lib/serve/kit-config.js +1 -2
  30. package/lib/serve/types.d.ts +0 -2
  31. package/lib/start.d.ts +1 -1
  32. package/lib/start.js +35 -35
  33. package/lib/test.d.ts +2 -1
  34. package/lib/test.js +4 -4
  35. package/lib/write-third-party-notices.js +15 -15
  36. package/package.json +6 -8
  37. package/lib/serve/external.d.ts +0 -7
  38. package/src/align-deps.ts +0 -83
  39. package/src/bundle/cliOptions.ts +0 -82
  40. package/src/bundle/defaultPlugins.ts +0 -16
  41. package/src/bundle/hermes.ts +0 -114
  42. package/src/bundle/kit-config.ts +0 -81
  43. package/src/bundle/metro.ts +0 -66
  44. package/src/bundle/overrides.ts +0 -51
  45. package/src/bundle/types.ts +0 -41
  46. package/src/bundle.ts +0 -69
  47. package/src/clean.ts +0 -223
  48. package/src/copy-assets.ts +0 -545
  49. package/src/index.ts +0 -34
  50. package/src/metro-config.ts +0 -208
  51. package/src/parsers.ts +0 -44
  52. package/src/ram-bundle.ts +0 -78
  53. package/src/serve/external.ts +0 -62
  54. package/src/serve/help.ts +0 -59
  55. package/src/serve/keyboard.ts +0 -76
  56. package/src/serve/kit-config.ts +0 -47
  57. package/src/serve/types.ts +0 -87
  58. package/src/start.ts +0 -316
  59. package/src/test.ts +0 -137
  60. package/src/write-third-party-notices.ts +0 -85
  61. /package/lib/{metro-config.d.ts → helpers/metro-config.d.ts} +0 -0
package/src/start.ts DELETED
@@ -1,316 +0,0 @@
1
- import type { Config } from "@react-native-community/cli-types";
2
- import * as logger from "@rnx-kit/console";
3
- import {
4
- isDevServerRunning,
5
- loadMetroConfig,
6
- makeReporter,
7
- makeTerminal,
8
- startServer,
9
- } from "@rnx-kit/metro-service";
10
- import type { ReportableEvent, Reporter, RunServerOptions } from "metro";
11
- import type { Middleware } from "metro-config";
12
- import type Server from "metro/src/Server";
13
- import * as path from "path";
14
- import { customizeMetroConfig } from "./metro-config";
15
- import { asNumber, asResolvedPath, asStringArray } from "./parsers";
16
- import { requireExternal } from "./serve/external";
17
- import { makeHelp } from "./serve/help";
18
- import { attachKeyHandlers } from "./serve/keyboard";
19
- import { getKitServerConfig } from "./serve/kit-config";
20
- import type {
21
- DevServerMiddleware,
22
- DevServerMiddleware6,
23
- StartCommandArgs,
24
- } from "./serve/types";
25
-
26
- function hasAttachToServerFunction(
27
- devServer: DevServerMiddleware | DevServerMiddleware6
28
- ): devServer is DevServerMiddleware6 {
29
- return "attachToServer" in devServer;
30
- }
31
-
32
- export async function rnxStart(
33
- _argv: string[],
34
- ctx: Config,
35
- args: StartCommandArgs
36
- ): Promise<void> {
37
- const serverConfig = getKitServerConfig(args);
38
-
39
- const { createDevServerMiddleware, indexPageMiddleware } = requireExternal(
40
- "@react-native-community/cli-server-api"
41
- );
42
-
43
- // interactive mode requires raw access to stdin
44
- let interactive = args.interactive;
45
- if (interactive) {
46
- interactive = process.stdin.isTTY;
47
- if (!interactive) {
48
- logger.warn("Interactive mode is not supported in this environment");
49
- }
50
- }
51
-
52
- // load Metro configuration, applying overrides from the command line
53
- const metroConfig = await loadMetroConfig(ctx, {
54
- ...args,
55
- ...(serverConfig.projectRoot
56
- ? { projectRoot: path.resolve(serverConfig.projectRoot) }
57
- : undefined),
58
- ...(serverConfig.sourceExts
59
- ? { sourceExts: serverConfig.sourceExts }
60
- : undefined),
61
- ...(serverConfig.assetPlugins
62
- ? {
63
- assetPlugins: serverConfig.assetPlugins.map((p) =>
64
- require.resolve(p)
65
- ),
66
- }
67
- : undefined),
68
- });
69
-
70
- const { projectRoot, watchFolders } = metroConfig;
71
- const terminal = makeTerminal(projectRoot);
72
-
73
- // customize the metro config to include plugins, presets, etc.
74
- const log = (message: string): void => terminal.log(message);
75
- customizeMetroConfig(metroConfig, serverConfig, log);
76
-
77
- const { port } = metroConfig.server;
78
- const scheme = args.https === true ? "https" : "http";
79
- const serverStatus = await isDevServerRunning(
80
- scheme,
81
- args.host,
82
- port,
83
- projectRoot
84
- );
85
-
86
- switch (serverStatus) {
87
- case "already_running":
88
- logger.info(
89
- `A dev server is already running for this project on port ${port}. ` +
90
- "Exiting..."
91
- );
92
- return;
93
- case "in_use":
94
- logger.error(
95
- `Another process is using port ${port}. Please terminate this ` +
96
- "process and try again, or try another port with `--port`."
97
- );
98
- return;
99
- }
100
-
101
- // create middleware -- a collection of plugins which handle incoming
102
- // http(s) requests, routing them to static pages or JS functions.
103
- const host = args.host?.length ? args.host : "localhost";
104
- const devServerUrl = `${scheme}://${host}:${port}`;
105
- const devServer = createDevServerMiddleware({ host, port, watchFolders });
106
-
107
- const coreDevMiddleware = (() => {
108
- try {
109
- // https://github.com/facebook/react-native/blob/7888338295476f4d4f00733309e54b8d22318e1e/packages/community-cli-plugin/src/commands/start/runServer.js#L115
110
- const { createDevMiddleware } = requireExternal(
111
- "@react-native/dev-middleware"
112
- );
113
- return createDevMiddleware({
114
- projectRoot,
115
- serverBaseUrl: devServerUrl,
116
- logger,
117
- unstable_experiments: {
118
- // NOTE: Only affects the /open-debugger endpoint
119
- enableCustomDebuggerFrontend: true,
120
- },
121
- });
122
- } catch (_) {
123
- // Fallback to the behavior from before 0.73
124
- const middleware = devServer.middleware;
125
- middleware.use(indexPageMiddleware);
126
-
127
- // merge the Metro config middleware with our middleware
128
- const enhanceMiddleware = metroConfig.server.enhanceMiddleware;
129
- // @ts-expect-error We want to override `enhanceMiddleware`
130
- metroConfig.server.enhanceMiddleware = (
131
- metroMiddleware: Middleware,
132
- metroServer: Server
133
- ) => {
134
- return middleware.use(
135
- enhanceMiddleware
136
- ? enhanceMiddleware(metroMiddleware, metroServer)
137
- : metroMiddleware
138
- );
139
- };
140
- return undefined;
141
- }
142
- })();
143
-
144
- // `createDevServerMiddleware` changed its return type in
145
- // https://github.com/react-native-community/cli/pull/1560
146
- let websocketEndpoints: RunServerOptions["websocketEndpoints"] = undefined;
147
- let messageSocketEndpoint: DevServerMiddleware["messageSocketEndpoint"];
148
- let reportEventDelegate: Reporter["update"] | undefined = undefined;
149
-
150
- if (!hasAttachToServerFunction(devServer)) {
151
- websocketEndpoints = devServer.websocketEndpoints;
152
- messageSocketEndpoint = devServer.messageSocketEndpoint;
153
-
154
- // bind our `reportEvent` delegate to the Metro server
155
- reportEventDelegate = devServer.eventsSocketEndpoint.reportEvent;
156
- }
157
-
158
- const help = makeHelp(terminal, { hasDebugger: Boolean(coreDevMiddleware) });
159
- const terminalReporter = makeReporter(
160
- args.customLogReporterPath,
161
- terminal,
162
- projectRoot
163
- );
164
-
165
- // @ts-expect-error We want to override `reporter`
166
- metroConfig.reporter = {
167
- update(event: ReportableEvent) {
168
- terminalReporter.update(event);
169
- reportEventDelegate?.(event);
170
- if (interactive && event.type === "dep_graph_loading") {
171
- help();
172
- }
173
- },
174
- };
175
-
176
- const serverInstance = await startServer(metroConfig, {
177
- host: args.host,
178
- secure: args.https,
179
- secureCert: args.cert,
180
- secureKey: args.key,
181
- ...(coreDevMiddleware
182
- ? {
183
- unstable_extraMiddleware: [
184
- devServer.middleware,
185
- indexPageMiddleware,
186
- coreDevMiddleware.middleware,
187
- ],
188
- websocketEndpoints: {
189
- ...websocketEndpoints,
190
- ...coreDevMiddleware.websocketEndpoints,
191
- },
192
- }
193
- : { websocketEndpoints }),
194
- });
195
-
196
- if (hasAttachToServerFunction(devServer)) {
197
- const { messageSocket, eventsSocket } =
198
- devServer.attachToServer(serverInstance);
199
- messageSocketEndpoint = messageSocket;
200
-
201
- // bind our `reportEvent` delegate to the Metro server
202
- reportEventDelegate = eventsSocket.reportEvent;
203
- } else {
204
- // `messageSocketEndpoint` should already be set at this point. But this
205
- // makes TypeScript happier.
206
- messageSocketEndpoint = devServer.messageSocketEndpoint;
207
- }
208
-
209
- // In Node 8, the default keep-alive for an HTTP connection is 5 seconds. In
210
- // early versions of Node 8, this was implemented in a buggy way which caused
211
- // some HTTP responses (like those containing large JS bundles) to be
212
- // terminated early.
213
- //
214
- // As a workaround, arbitrarily increase the keep-alive from 5 to 30 seconds,
215
- // which should be enough to send even the largest of JS bundles.
216
- //
217
- // For more info: https://github.com/nodejs/node/issues/13391
218
- //
219
- serverInstance.keepAliveTimeout = 30000;
220
-
221
- // in interactive mode, listen for keyboard events from stdin and bind
222
- // them to specific actions.
223
- if (interactive) {
224
- attachKeyHandlers({ devServerUrl, help, messageSocketEndpoint, terminal });
225
- }
226
- }
227
-
228
- export const rnxStartCommand = {
229
- name: "rnx-start",
230
- func: rnxStart,
231
- description:
232
- "Start a bundle-server to host your react-native experience during development",
233
- options: [
234
- {
235
- name: "--port [number]",
236
- description:
237
- "Host port to use when listening for incoming server requests.",
238
- parse: asNumber,
239
- default: 8081,
240
- },
241
- {
242
- name: "--host [string]",
243
- description:
244
- "Host name or address to bind when listening for incoming server requests. When not given, requests from all addresses are accepted.",
245
- default: "",
246
- },
247
- {
248
- name: "--projectRoot [path]",
249
- description:
250
- "Path to the root of your react-native project. The bundle server uses this root path to resolve all web requests.",
251
- parse: asResolvedPath,
252
- },
253
- {
254
- name: "--watchFolders [paths]",
255
- description:
256
- "Additional folders which will be added to the file-watch list. Comma-separated. By default, Metro watches all project files.",
257
- parse: (val: string) => asStringArray(val).map(asResolvedPath),
258
- },
259
- {
260
- name: "--assetPlugins [list]",
261
- description:
262
- "Additional asset plugins to be used by the Metro Babel transformer. Comma-separated list containing plugin module names or absolute paths to plugin packages.",
263
- parse: asStringArray,
264
- },
265
- {
266
- name: "--sourceExts [list]",
267
- description:
268
- "Additional source-file extensions to include when generating bundles. Comma-separated list, excluding the leading dot.",
269
- parse: asStringArray,
270
- },
271
- {
272
- name: "--max-workers [number]",
273
- description:
274
- "Specifies the maximum number of parallel worker threads to use for transforming files. This defaults to the number of cores available on your machine.",
275
- parse: asNumber,
276
- },
277
- {
278
- name: "--reset-cache",
279
- description: "Reset the Metro cache.",
280
- },
281
- {
282
- name: "--custom-log-reporter-path [string]",
283
- description:
284
- "Path to a JavaScript file which exports a Metro 'TerminalReporter' function. This replaces the default reporter, which writes all messages to the Metro console.",
285
- },
286
- {
287
- name: "--https",
288
- description:
289
- "Use a secure (https) web server. When not specified, an insecure (http) web server is used.",
290
- },
291
- {
292
- name: "--key [path]",
293
- description:
294
- "Path to a custom SSL private key file to use for secure (https) communication.",
295
- },
296
- {
297
- name: "--cert [path]",
298
- description:
299
- "Path to a custom SSL certificate file to use for secure (https) communication.",
300
- },
301
- {
302
- name: "--config [string]",
303
- description: "Path to the Metro configuration file.",
304
- parse: asResolvedPath,
305
- },
306
- {
307
- name: "--no-interactive",
308
- description: "Disables interactive mode.",
309
- },
310
- {
311
- name: "--id [string]",
312
- description:
313
- "Specify which bundle configuration to use if server configuration is missing.",
314
- },
315
- ],
316
- };
package/src/test.ts DELETED
@@ -1,137 +0,0 @@
1
- import type { Config as CLIConfig } from "@react-native-community/cli-types";
2
- import { error } from "@rnx-kit/console";
3
- import {
4
- findPackageDir,
5
- resolveDependencyChain,
6
- } from "@rnx-kit/tools-node/package";
7
- import { parsePlatform } from "@rnx-kit/tools-react-native/platform";
8
-
9
- type Args = {
10
- platform: "android" | "ios" | "macos" | "windows" | "win32";
11
- };
12
-
13
- type Options = {
14
- name: string;
15
- description?: string;
16
- parse?: (val: string) => unknown;
17
- default?:
18
- | string
19
- | boolean
20
- | number
21
- | ((config: CLIConfig) => string | boolean | number);
22
- };
23
-
24
- const COMMAND_NAME = "rnx-test";
25
- const JEST_CLI = ["jest", "jest-cli"];
26
-
27
- export function rnxTest(
28
- _argv: string[],
29
- { root }: CLIConfig,
30
- { platform }: Args
31
- ): void {
32
- const runJest: (argv: string[]) => void = (() => {
33
- try {
34
- const { run } = require(resolveDependencyChain(JEST_CLI, root));
35
- return run;
36
- } catch (e) {
37
- error("'rnx-test' is unavailable because 'jest' is not installed");
38
- throw e;
39
- }
40
- })();
41
-
42
- const commandIndex = process.argv.indexOf(COMMAND_NAME);
43
- if (commandIndex < 0) {
44
- throw new Error("Failed to parse command arguments");
45
- }
46
-
47
- // Copy and remove the first arguments from `node react-native rnx-test ...`
48
- const argv = process.argv.slice(commandIndex + 1);
49
-
50
- const platformIndex = argv.indexOf("--platform");
51
- if (platformIndex < 0) {
52
- throw new Error("A target platform must be specified");
53
- }
54
-
55
- // Remove `--platform` otherwise Jest will complain about an unrecognized
56
- // option. We can pass the rest of the arguments to Jest as they are.
57
- argv.splice(platformIndex, 2);
58
-
59
- process.env["RN_TARGET_PLATFORM"] = platform;
60
- runJest(argv);
61
- }
62
-
63
- export function jestOptions(): Options[] {
64
- const options = (() => {
65
- const jestCliPath = (() => {
66
- try {
67
- return resolveDependencyChain(JEST_CLI);
68
- } catch (_) {
69
- return undefined;
70
- }
71
- })();
72
- if (!jestCliPath) {
73
- return {};
74
- }
75
-
76
- try {
77
- // `yargsOptions` is exported as of 29.5.0
78
- // https://github.com/jestjs/jest/commit/0e8ed24a527b951efe11ed49da46e0bd8c0ebef9
79
- const { yargsOptions } = require(jestCliPath);
80
- if (yargsOptions) {
81
- return yargsOptions;
82
- }
83
- } catch (_) {
84
- // ignore
85
- }
86
-
87
- // Starting with Jest 27, we are getting this error:
88
- //
89
- // Package subpath './build/cli/args' is not defined by "exports" in
90
- // /~/node_modules/jest-cli/package.json
91
- //
92
- // To work around this, resolve `jest-cli` first, then use the resolved
93
- // path to import `./build/cli/args`.
94
- const jestPath = findPackageDir(jestCliPath) || "jest-cli";
95
-
96
- try {
97
- // `args.js` was moved in 29.2.0
98
- // https://github.com/jestjs/jest/commit/2ecf723c50c5d25b2fe94e1ff8081f36aed9d67b
99
- const { options } = require(`${jestPath}/build/args`);
100
- return options;
101
- } catch (_) {
102
- // ignore
103
- }
104
-
105
- try {
106
- const { options } = require(`${jestPath}/build/cli/args`);
107
- return options;
108
- } catch (_) {
109
- // ignore
110
- }
111
-
112
- return {};
113
- })();
114
- return Object.keys(options).map((option) => {
115
- const { alias, default: defaultValue, description, type } = options[option];
116
- const name = `--${option} [${type}]`;
117
- return {
118
- name: alias ? `-${alias}, ${name}` : name,
119
- description,
120
- default: defaultValue,
121
- };
122
- });
123
- }
124
-
125
- export const rnxTestCommand = {
126
- name: COMMAND_NAME,
127
- description: "Test runner for React Native apps",
128
- func: rnxTest,
129
- options: [
130
- {
131
- name: "--platform [android|ios|macos|windows|win32]",
132
- description: "Platform to target",
133
- parse: parsePlatform,
134
- },
135
- ...jestOptions(),
136
- ],
137
- };
@@ -1,85 +0,0 @@
1
- import type { Config as CLIConfig } from "@react-native-community/cli-types";
2
- import { writeThirdPartyNotices } from "@rnx-kit/third-party-notices";
3
-
4
- type CliThirdPartyNoticesOptions = {
5
- rootPath: string;
6
- sourceMapFile: string;
7
- json: boolean;
8
- outputFile?: string;
9
- ignoreScopes?: string;
10
- ignoreModules?: string;
11
- preambleText?: string;
12
- additionalText?: string;
13
- };
14
-
15
- export function rnxWriteThirdPartyNotices(
16
- _argv: string[],
17
- _config: CLIConfig,
18
- {
19
- additionalText,
20
- ignoreModules,
21
- ignoreScopes,
22
- json,
23
- outputFile,
24
- preambleText,
25
- rootPath,
26
- sourceMapFile,
27
- }: CliThirdPartyNoticesOptions
28
- ): void {
29
- // react-native-cli is not as rich as yargs, so we have to perform a mapping.
30
- writeThirdPartyNotices({
31
- rootPath,
32
- sourceMapFile,
33
- json,
34
- outputFile,
35
- ignoreScopes: ignoreScopes?.split(","),
36
- ignoreModules: ignoreModules?.split(","),
37
- preambleText: preambleText ? [preambleText] : undefined,
38
- additionalText: additionalText ? [additionalText] : undefined,
39
- });
40
- }
41
-
42
- export const rnxWriteThirdPartyNoticesCommand = {
43
- name: "rnx-write-third-party-notices",
44
- description: "Writes third party notices based on the given bundle",
45
- func: rnxWriteThirdPartyNotices,
46
- options: [
47
- {
48
- name: "--root-path <path>",
49
- description:
50
- "The root of the repo. This is the starting point for finding each module in the source map dependency graph.",
51
- },
52
- {
53
- name: "--source-map-file <file>",
54
- description:
55
- "The source map file associated with the package's entry file. This source map eventually leads to all package dependencies and their licenses.",
56
- },
57
- {
58
- name: "--json",
59
- description: "Format the 3rd-party notice file as JSON instead of text.",
60
- default: false,
61
- },
62
- {
63
- name: "--output-file [file]",
64
- description: "The path to use when writing the 3rd-party notice file.",
65
- },
66
- {
67
- name: "--ignore-scopes [string]",
68
- description:
69
- "Comma-separated list of `npm` scopes to ignore when traversing the source map dependency graph.",
70
- },
71
- {
72
- name: "--ignore-modules [string]",
73
- description:
74
- "Comma-separated list of modules to ignore when traversing the source map dependency graph.",
75
- },
76
- {
77
- name: "--preamble-text [string]",
78
- description: "A string to prepend to the start of the 3rd-party notice.",
79
- },
80
- {
81
- name: "--additional-text [path]",
82
- description: "A string to append to the end of the 3rd-party notice.",
83
- },
84
- ],
85
- };