@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/bundle.ts DELETED
@@ -1,69 +0,0 @@
1
- import type { Config as CLIConfig } from "@react-native-community/cli-types";
2
- import { loadMetroConfig } from "@rnx-kit/metro-service";
3
- import { commonBundleCommandOptions } from "./bundle/cliOptions";
4
- import { emitBytecode } from "./bundle/hermes";
5
- import { getCliPlatformBundleConfigs } from "./bundle/kit-config";
6
- import { metroBundle } from "./bundle/metro";
7
- import {
8
- applyBundleConfigOverrides,
9
- overridableCommonBundleOptions,
10
- } from "./bundle/overrides";
11
- import type { CLICommonBundleOptions } from "./bundle/types";
12
- import { asBoolean } from "./parsers";
13
-
14
- type CLIBundleOptions = CLICommonBundleOptions & {
15
- treeShake?: boolean;
16
- };
17
-
18
- export async function rnxBundle(
19
- _argv: string[],
20
- cliConfig: CLIConfig,
21
- cliOptions: CLIBundleOptions
22
- ): Promise<void> {
23
- const metroConfig = await loadMetroConfig(cliConfig, cliOptions);
24
-
25
- const bundleConfigs = getCliPlatformBundleConfigs(
26
- cliOptions.id,
27
- cliOptions.platform
28
- );
29
-
30
- applyBundleConfigOverrides(cliOptions, bundleConfigs, [
31
- ...overridableCommonBundleOptions,
32
- "hermes",
33
- "treeShake",
34
- ]);
35
-
36
- for (const bundleConfig of bundleConfigs) {
37
- await metroBundle(
38
- metroConfig,
39
- bundleConfig,
40
- cliOptions.dev,
41
- cliOptions.minify
42
- );
43
-
44
- const { bundleOutput, hermes, sourcemapOutput } = bundleConfig;
45
- if (hermes) {
46
- emitBytecode(
47
- bundleOutput,
48
- sourcemapOutput,
49
- hermes === true ? {} : hermes
50
- );
51
- }
52
- }
53
- }
54
-
55
- export const rnxBundleCommand = {
56
- name: "rnx-bundle",
57
- description:
58
- "Bundle your rnx-kit package for offline use. See https://aka.ms/rnx-kit.",
59
- func: rnxBundle,
60
- options: [
61
- ...commonBundleCommandOptions,
62
- {
63
- name: "--tree-shake [boolean]",
64
- description:
65
- "Enable tree shaking to remove unused code and reduce the bundle size.",
66
- parse: asBoolean,
67
- },
68
- ],
69
- };
package/src/clean.ts DELETED
@@ -1,223 +0,0 @@
1
- import type { Config as CLIConfig } from "@react-native-community/cli-types";
2
- import { spawn } from "child_process";
3
- import * as fs from "fs-extra";
4
- import ora from "ora";
5
- import * as os from "os";
6
- import * as path from "path";
7
- import { asResolvedPath } from "./parsers";
8
- import { requireExternal } from "./serve/external";
9
-
10
- type Args = {
11
- include?: string;
12
- projectRoot?: string;
13
- verify?: boolean;
14
- };
15
-
16
- type Task = {
17
- label: string;
18
- action: () => Promise<void>;
19
- };
20
-
21
- type CLICommand = Record<string, Task[]>;
22
-
23
- export async function rnxClean(
24
- _argv: string[],
25
- _config: CLIConfig,
26
- cliOptions: Args
27
- ): Promise<void> {
28
- const projectRoot = cliOptions.projectRoot ?? process.cwd();
29
- if (!fs.existsSync(projectRoot)) {
30
- throw new Error(`Invalid path provided! ${projectRoot}`);
31
- }
32
-
33
- const spinner = ora();
34
- try {
35
- requireExternal("@react-native-community/cli-clean");
36
- spinner.warn(
37
- "`rnx-clean` has been upstreamed to `@react-native-community/cli`. Please use `npx react-native clean` instead."
38
- );
39
- } catch (_) {
40
- // Ignore
41
- }
42
-
43
- const npm = os.platform() === "win32" ? "npm.cmd" : "npm";
44
- const yarn = os.platform() === "win32" ? "yarn.cmd" : "yarn";
45
-
46
- const COMMANDS: CLICommand = {
47
- android: [
48
- {
49
- label: "Clean Gradle cache",
50
- action: () => {
51
- const candidates =
52
- os.platform() === "win32"
53
- ? ["android/gradlew.bat", "gradlew.bat"]
54
- : ["android/gradlew", "gradlew"];
55
- const gradlew = findPath(projectRoot, candidates);
56
- if (gradlew) {
57
- const script = path.basename(gradlew);
58
- return execute(
59
- os.platform() === "win32" ? script : `./${script}`,
60
- ["clean"],
61
- path.dirname(gradlew)
62
- );
63
- } else {
64
- return Promise.resolve();
65
- }
66
- },
67
- },
68
- ],
69
- cocoapods: [
70
- {
71
- label: "Clean CocoaPods cache",
72
- action: () => execute("pod", ["cache", "clean", "--all"], projectRoot),
73
- },
74
- ],
75
- metro: [
76
- {
77
- label: "Clean Metro cache",
78
- action: () => cleanDir(`${os.tmpdir()}/metro-*`),
79
- },
80
- {
81
- label: "Clean Haste cache",
82
- action: () => cleanDir(`${os.tmpdir()}/haste-map-*`),
83
- },
84
- {
85
- label: "Clean React Native cache",
86
- action: () => cleanDir(`${os.tmpdir()}/react-*`),
87
- },
88
- ],
89
- npm: [
90
- {
91
- label: "Remove node_modules",
92
- action: () => cleanDir(`${projectRoot}/node_modules`),
93
- },
94
- ...(cliOptions.verify
95
- ? [
96
- {
97
- label: "Verify npm cache",
98
- action: () => execute(npm, ["cache", "verify"], projectRoot),
99
- },
100
- ]
101
- : []),
102
- ],
103
- watchman: [
104
- {
105
- label: "Stop Watchman",
106
- action: () =>
107
- execute(
108
- os.platform() === "win32" ? "tskill" : "killall",
109
- ["watchman"],
110
- projectRoot
111
- ),
112
- },
113
- {
114
- label: "Delete Watchman cache",
115
- action: () => execute("watchman", ["watch-del-all"], projectRoot),
116
- },
117
- ],
118
- yarn: [
119
- {
120
- label: "Clean Yarn cache",
121
- action: () => execute(yarn, ["cache", "clean"], projectRoot),
122
- },
123
- ],
124
- };
125
-
126
- const categories = cliOptions.include?.split(",") ?? [
127
- "metro",
128
- "npm",
129
- "watchman",
130
- "yarn",
131
- ];
132
-
133
- for (const category of categories) {
134
- const commands = COMMANDS[category];
135
- if (!commands) {
136
- spinner.warn(`Unknown category: ${category}`);
137
- return;
138
- }
139
-
140
- for (const { action, label } of commands) {
141
- spinner.start(label);
142
- await action()
143
- .then(() => {
144
- spinner.succeed();
145
- })
146
- .catch((e) => {
147
- spinner.fail(`${label} » ${e}`);
148
- });
149
- }
150
- }
151
- }
152
-
153
- function cleanDir(path: string): Promise<void> {
154
- if (!fs.existsSync(path)) {
155
- return Promise.resolve();
156
- }
157
-
158
- return fs.rmdir(path, { maxRetries: 3, recursive: true });
159
- }
160
-
161
- function findPath(startPath: string, files: string[]): string | undefined {
162
- // TODO: Find project files via `@react-native-community/cli`
163
- for (const file of files) {
164
- const filename = path.resolve(startPath, file);
165
- if (fs.existsSync(filename)) {
166
- return filename;
167
- }
168
- }
169
-
170
- return undefined;
171
- }
172
-
173
- function execute(command: string, args: string[], cwd: string): Promise<void> {
174
- return new Promise((resolve, reject) => {
175
- const process = spawn(command, args, {
176
- cwd,
177
- stdio: ["inherit", null, null],
178
- shell: command.endsWith(".bat") || command.endsWith(".cmd"),
179
- });
180
-
181
- const stderr: Buffer[] = [];
182
- process.stderr.on("data", (data) => {
183
- stderr.push(data);
184
- });
185
-
186
- process.on("close", (code, signal) => {
187
- if (code === 0) {
188
- resolve();
189
- } else if (stderr) {
190
- reject(Buffer.concat(stderr).toString().trimEnd());
191
- } else if (signal) {
192
- reject(`Failed with signal ${signal}`);
193
- } else {
194
- reject(`Failed with exit code ${code}`);
195
- }
196
- });
197
- });
198
- }
199
-
200
- export const rnxCleanCommand = {
201
- name: "rnx-clean",
202
- func: rnxClean,
203
- description: "Clears React Native project related caches",
204
- options: [
205
- {
206
- name: "--include [android,cocoapods,metro,npm,watchman,yarn]",
207
- description:
208
- "Comma-separated flag of caches to clear, e.g. `npm,yarn`. When not specified, only non-platform specific caches are cleared.",
209
- default: "metro,npm,watchman,yarn",
210
- },
211
- {
212
- name: "--project-root <path>",
213
- description: "Root path to your React Native project",
214
- default: process.cwd(),
215
- parse: asResolvedPath,
216
- },
217
- {
218
- name: "--verify",
219
- description: "Whether to verify the integrity of the cache",
220
- default: false,
221
- },
222
- ],
223
- };