@rnx-kit/cli 0.16.29 → 0.17.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 +172 -98
- package/bin/rnx-cli.cjs +2 -0
- package/lib/align-deps.js +5 -5
- package/lib/bin/context.d.ts +25 -0
- package/lib/bin/context.js +98 -0
- package/lib/bin/externalCommands.d.ts +3 -0
- package/lib/bin/externalCommands.js +34 -0
- package/lib/bin/rnx-cli.d.ts +2 -0
- package/lib/bin/rnx-cli.js +55 -0
- package/lib/bundle/cliOptions.d.ts +2 -2
- package/lib/bundle/cliOptions.js +27 -27
- package/lib/bundle/hermes.d.ts +2 -1
- package/lib/bundle/hermes.js +9 -15
- package/lib/bundle/metro.js +6 -9
- package/lib/bundle.d.ts +3 -3
- package/lib/bundle.js +4 -4
- package/lib/clean.d.ts +3 -3
- package/lib/clean.js +47 -67
- package/lib/copy-assets.d.ts +5 -3
- package/lib/copy-assets.js +31 -28
- package/lib/helpers/externals.d.ts +4 -0
- package/lib/{serve/external.js → helpers/externals.js} +10 -8
- package/lib/helpers/filesystem.d.ts +3 -0
- package/lib/helpers/filesystem.js +31 -0
- package/lib/{metro-config.js → helpers/metro-config.js} +1 -1
- package/lib/{parsers.d.ts → helpers/parsers.d.ts} +1 -1
- package/lib/{parsers.js → helpers/parsers.js} +17 -15
- package/lib/index.d.ts +2 -188
- package/lib/index.js +1 -5
- package/lib/ram-bundle.d.ts +4 -4
- package/lib/ram-bundle.js +2 -2
- package/lib/serve/keyboard.js +3 -6
- package/lib/serve/types.d.ts +2 -2
- package/lib/start.d.ts +1 -1
- package/lib/start.js +34 -34
- package/lib/test.d.ts +2 -1
- package/lib/test.js +7 -5
- package/lib/write-third-party-notices.js +13 -13
- package/package.json +24 -23
- package/lib/serve/external.d.ts +0 -7
- package/src/align-deps.ts +0 -82
- package/src/bundle/cliOptions.ts +0 -82
- package/src/bundle/defaultPlugins.ts +0 -16
- package/src/bundle/hermes.ts +0 -114
- package/src/bundle/kit-config.ts +0 -81
- package/src/bundle/metro.ts +0 -66
- package/src/bundle/overrides.ts +0 -51
- package/src/bundle/types.ts +0 -41
- package/src/bundle.ts +0 -69
- package/src/clean.ts +0 -223
- package/src/copy-assets.ts +0 -545
- package/src/index.ts +0 -34
- package/src/metro-config.ts +0 -208
- package/src/parsers.ts +0 -44
- package/src/ram-bundle.ts +0 -78
- package/src/serve/external.ts +0 -62
- package/src/serve/help.ts +0 -59
- package/src/serve/keyboard.ts +0 -76
- package/src/serve/kit-config.ts +0 -47
- package/src/serve/types.ts +0 -87
- package/src/start.ts +0 -316
- package/src/test.ts +0 -137
- package/src/write-third-party-notices.ts +0 -85
- /package/lib/{metro-config.d.ts → helpers/metro-config.d.ts} +0 -0
package/lib/bundle/cliOptions.js
CHANGED
|
@@ -2,74 +2,74 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.commonBundleCommandOptions = void 0;
|
|
4
4
|
const platform_1 = require("@rnx-kit/tools-react-native/platform");
|
|
5
|
-
const parsers_1 = require("../parsers");
|
|
5
|
+
const parsers_1 = require("../helpers/parsers");
|
|
6
6
|
exports.commonBundleCommandOptions = [
|
|
7
7
|
{
|
|
8
|
-
name: "--id
|
|
9
|
-
description: "Target bundle definition
|
|
8
|
+
name: "--id <id>",
|
|
9
|
+
description: "Target bundle definition; only needed when the rnx-kit configuration has multiple bundle definitions",
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
|
-
name: "--entry-file
|
|
13
|
-
description: "Path to the root JavaScript or TypeScript file, either absolute or relative to the package
|
|
12
|
+
name: "--entry-file <path>",
|
|
13
|
+
description: "Path to the root JavaScript or TypeScript file, either absolute or relative to the package",
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
|
-
name: "--platform
|
|
17
|
-
description: "Target platform
|
|
16
|
+
name: "--platform <ios|android|windows|win32|macos>",
|
|
17
|
+
description: "Target platform; when unspecified, all platforms in the rnx-kit configuration are bundled",
|
|
18
18
|
parse: platform_1.parsePlatform,
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
name: "--dev [boolean]",
|
|
22
|
-
description: "If false, warnings are disabled and the bundle is minified
|
|
22
|
+
description: "If false, warnings are disabled and the bundle is minified",
|
|
23
23
|
default: true,
|
|
24
24
|
parse: parsers_1.asBoolean,
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
name: "--minify [boolean]",
|
|
28
|
-
description: "Controls whether or not the bundle is minified
|
|
28
|
+
description: "Controls whether or not the bundle is minified (useful for test builds)",
|
|
29
29
|
parse: parsers_1.asBoolean,
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
|
-
name: "--bundle-output
|
|
33
|
-
description: "Path to the output bundle file, either absolute or relative to the package
|
|
32
|
+
name: "--bundle-output <string>",
|
|
33
|
+
description: "Path to the output bundle file, either absolute or relative to the package",
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
|
-
name: "--bundle-encoding
|
|
37
|
-
description: "Character encoding to use when writing the bundle file
|
|
36
|
+
name: "--bundle-encoding <utf8|utf16le|ascii>",
|
|
37
|
+
description: "Character encoding to use when writing the bundle file",
|
|
38
38
|
default: "utf8",
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
|
-
name: "--max-workers
|
|
42
|
-
description: "Specifies the maximum number of parallel worker threads to use for transforming files
|
|
41
|
+
name: "--max-workers <number>",
|
|
42
|
+
description: "Specifies the maximum number of parallel worker threads to use for transforming files; defaults to the number of cores available on your machine",
|
|
43
43
|
parse: parsers_1.asNumber,
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
|
-
name: "--sourcemap-output
|
|
47
|
-
description: "Path where the bundle source map is written, either absolute or relative to the package
|
|
46
|
+
name: "--sourcemap-output <string>",
|
|
47
|
+
description: "Path where the bundle source map is written, either absolute or relative to the package",
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
|
-
name: "--sourcemap-sources-root
|
|
51
|
-
description: "Path to use when relativizing file entries in the bundle source map
|
|
50
|
+
name: "--sourcemap-sources-root <string>",
|
|
51
|
+
description: "Path to use when relativizing file entries in the bundle source map",
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
54
|
name: "--sourcemap-use-absolute-path",
|
|
55
55
|
description: "Report SourceMapURL using its full path",
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
|
-
name: "--assets-dest
|
|
59
|
-
description: "Path where bundle assets like images are written, either absolute or relative to the package
|
|
58
|
+
name: "--assets-dest <path>",
|
|
59
|
+
description: "Path where bundle assets like images are written, either absolute or relative to the package; if unspecified, assets are ignored",
|
|
60
60
|
},
|
|
61
61
|
{
|
|
62
|
-
name: "--unstable-transform-profile
|
|
63
|
-
description: "Experimental
|
|
64
|
-
parse: parsers_1.
|
|
62
|
+
name: "--unstable-transform-profile <string>",
|
|
63
|
+
description: "[Experimental] Transform JS for a specific JS engine; currently supported: hermes, hermes-canary, default",
|
|
64
|
+
parse: parsers_1.asTransformProfile,
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
name: "--reset-cache",
|
|
68
|
-
description: "Reset the Metro cache
|
|
68
|
+
description: "Reset the Metro cache",
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
|
-
name: "--config
|
|
72
|
-
description: "Path to the Metro configuration file
|
|
71
|
+
name: "--config <string>",
|
|
72
|
+
description: "Path to the Metro configuration file",
|
|
73
73
|
},
|
|
74
74
|
];
|
|
75
75
|
//# sourceMappingURL=cliOptions.js.map
|
package/lib/bundle/hermes.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Config as CLIConfig } from "@react-native-community/cli-types";
|
|
1
2
|
import type { HermesOptions } from "@rnx-kit/config";
|
|
2
|
-
export declare function emitBytecode(input: string, sourcemap: string | undefined, options: HermesOptions): void;
|
|
3
|
+
export declare function emitBytecode(cliConfig: CLIConfig, input: string, sourcemap: string | undefined, options: HermesOptions): void;
|
|
3
4
|
//# sourceMappingURL=hermes.d.ts.map
|
package/lib/bundle/hermes.js
CHANGED
|
@@ -27,10 +27,10 @@ exports.emitBytecode = emitBytecode;
|
|
|
27
27
|
const console_1 = require("@rnx-kit/console");
|
|
28
28
|
const package_1 = require("@rnx-kit/tools-node/package");
|
|
29
29
|
const metro_1 = require("@rnx-kit/tools-react-native/metro");
|
|
30
|
-
const
|
|
31
|
-
const fs = __importStar(require("fs"));
|
|
32
|
-
const os = __importStar(require("os"));
|
|
33
|
-
const path = __importStar(require("path"));
|
|
30
|
+
const node_child_process_1 = require("node:child_process");
|
|
31
|
+
const fs = __importStar(require("node:fs"));
|
|
32
|
+
const os = __importStar(require("node:os"));
|
|
33
|
+
const path = __importStar(require("node:path"));
|
|
34
34
|
function hermesBinaryInDir(hermesc) {
|
|
35
35
|
switch (os.platform()) {
|
|
36
36
|
case "darwin":
|
|
@@ -43,15 +43,9 @@ function hermesBinaryInDir(hermesc) {
|
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
function findHermesBinary() {
|
|
46
|
+
function findHermesBinary({ reactNativePath }) {
|
|
47
47
|
const locations = [
|
|
48
|
-
() =>
|
|
49
|
-
const rnPath = (0, package_1.findPackageDependencyDir)("react-native");
|
|
50
|
-
if (!rnPath) {
|
|
51
|
-
throw new Error("Cannot find module 'react-native'");
|
|
52
|
-
}
|
|
53
|
-
return path.join(rnPath, "sdks", "hermesc");
|
|
54
|
-
},
|
|
48
|
+
() => path.join(reactNativePath, "sdks", "hermesc"),
|
|
55
49
|
() => (0, package_1.findPackageDependencyDir)("hermes-engine"),
|
|
56
50
|
];
|
|
57
51
|
for (const getLocation of locations) {
|
|
@@ -78,9 +72,9 @@ function getOutput(args) {
|
|
|
78
72
|
}
|
|
79
73
|
return null;
|
|
80
74
|
}
|
|
81
|
-
function emitBytecode(input, sourcemap, options) {
|
|
75
|
+
function emitBytecode(cliConfig, input, sourcemap, options) {
|
|
82
76
|
var _a;
|
|
83
|
-
const cmd = options.command || findHermesBinary();
|
|
77
|
+
const cmd = options.command || findHermesBinary(cliConfig);
|
|
84
78
|
if (!cmd) {
|
|
85
79
|
(0, console_1.error)("No Hermes compiler was found");
|
|
86
80
|
return;
|
|
@@ -103,7 +97,7 @@ function emitBytecode(input, sourcemap, options) {
|
|
|
103
97
|
}
|
|
104
98
|
args.push(input);
|
|
105
99
|
(0, console_1.info)("Emitting bytecode to:", output);
|
|
106
|
-
const result = (0,
|
|
100
|
+
const result = (0, node_child_process_1.spawnSync)(cmd, args, { stdio: "inherit" });
|
|
107
101
|
if (result.status !== 0) {
|
|
108
102
|
throw result.error;
|
|
109
103
|
}
|
package/lib/bundle/metro.js
CHANGED
|
@@ -26,12 +26,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.metroBundle = metroBundle;
|
|
27
27
|
const console_1 = require("@rnx-kit/console");
|
|
28
28
|
const metro_service_1 = require("@rnx-kit/metro-service");
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const metro_config_1 = require("../metro-config");
|
|
32
|
-
function ensureDir(p) {
|
|
33
|
-
fs.mkdirSync(p, { recursive: true, mode: 0o755 });
|
|
34
|
-
}
|
|
29
|
+
const path = __importStar(require("node:path"));
|
|
30
|
+
const filesystem_1 = require("../helpers/filesystem");
|
|
31
|
+
const metro_config_1 = require("../helpers/metro-config");
|
|
35
32
|
/**
|
|
36
33
|
* Run the Metro bundler.
|
|
37
34
|
*
|
|
@@ -66,12 +63,12 @@ async function metroBundle(metroConfig, bundleConfig, dev, minify, output = metr
|
|
|
66
63
|
minify,
|
|
67
64
|
};
|
|
68
65
|
// ensure all output directories exist
|
|
69
|
-
ensureDir(path.dirname(metroBundleArgs.bundleOutput));
|
|
66
|
+
(0, filesystem_1.ensureDir)(path.dirname(metroBundleArgs.bundleOutput));
|
|
70
67
|
if (metroBundleArgs.sourcemapOutput) {
|
|
71
|
-
ensureDir(path.dirname(metroBundleArgs.sourcemapOutput));
|
|
68
|
+
(0, filesystem_1.ensureDir)(path.dirname(metroBundleArgs.sourcemapOutput));
|
|
72
69
|
}
|
|
73
70
|
if (metroBundleArgs.assetsDest) {
|
|
74
|
-
ensureDir(metroBundleArgs.assetsDest);
|
|
71
|
+
(0, filesystem_1.ensureDir)(metroBundleArgs.assetsDest);
|
|
75
72
|
}
|
|
76
73
|
// create the bundle
|
|
77
74
|
await output(metroBundleArgs, metroConfig);
|
package/lib/bundle.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Config as CLIConfig } from "@react-native-community/cli-types";
|
|
2
2
|
import type { CLICommonBundleOptions } from "./bundle/types";
|
|
3
|
-
import { asBoolean } from "./parsers";
|
|
3
|
+
import { asBoolean } from "./helpers/parsers";
|
|
4
4
|
type CLIBundleOptions = CLICommonBundleOptions & {
|
|
5
5
|
treeShake?: boolean;
|
|
6
6
|
};
|
|
@@ -37,12 +37,12 @@ export declare const rnxBundleCommand: {
|
|
|
37
37
|
} | {
|
|
38
38
|
name: string;
|
|
39
39
|
description: string;
|
|
40
|
-
parse: typeof import("./parsers").asNumber;
|
|
40
|
+
parse: typeof import("./helpers/parsers").asNumber;
|
|
41
41
|
default?: undefined;
|
|
42
42
|
} | {
|
|
43
43
|
name: string;
|
|
44
44
|
description: string;
|
|
45
|
-
parse: typeof import("./parsers").
|
|
45
|
+
parse: typeof import("./helpers/parsers").asTransformProfile;
|
|
46
46
|
default?: undefined;
|
|
47
47
|
})[];
|
|
48
48
|
};
|
package/lib/bundle.js
CHANGED
|
@@ -8,7 +8,7 @@ const hermes_1 = require("./bundle/hermes");
|
|
|
8
8
|
const kit_config_1 = require("./bundle/kit-config");
|
|
9
9
|
const metro_1 = require("./bundle/metro");
|
|
10
10
|
const overrides_1 = require("./bundle/overrides");
|
|
11
|
-
const parsers_1 = require("./parsers");
|
|
11
|
+
const parsers_1 = require("./helpers/parsers");
|
|
12
12
|
async function rnxBundle(_argv, cliConfig, cliOptions) {
|
|
13
13
|
const metroConfig = await (0, metro_service_1.loadMetroConfig)(cliConfig, cliOptions);
|
|
14
14
|
const bundleConfigs = (0, kit_config_1.getCliPlatformBundleConfigs)(cliOptions.id, cliOptions.platform);
|
|
@@ -21,19 +21,19 @@ async function rnxBundle(_argv, cliConfig, cliOptions) {
|
|
|
21
21
|
await (0, metro_1.metroBundle)(metroConfig, bundleConfig, cliOptions.dev, cliOptions.minify);
|
|
22
22
|
const { bundleOutput, hermes, sourcemapOutput } = bundleConfig;
|
|
23
23
|
if (hermes) {
|
|
24
|
-
(0, hermes_1.emitBytecode)(bundleOutput, sourcemapOutput, hermes === true ? {} : hermes);
|
|
24
|
+
(0, hermes_1.emitBytecode)(cliConfig, bundleOutput, sourcemapOutput, hermes === true ? {} : hermes);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
exports.rnxBundleCommand = {
|
|
29
29
|
name: "rnx-bundle",
|
|
30
|
-
description: "Bundle your
|
|
30
|
+
description: "Bundle your JavaScript for offline use",
|
|
31
31
|
func: rnxBundle,
|
|
32
32
|
options: [
|
|
33
33
|
...cliOptions_1.commonBundleCommandOptions,
|
|
34
34
|
{
|
|
35
35
|
name: "--tree-shake [boolean]",
|
|
36
|
-
description: "Enable tree shaking to remove unused code and reduce the bundle size
|
|
36
|
+
description: "Enable tree shaking to remove unused code and reduce the bundle size",
|
|
37
37
|
parse: parsers_1.asBoolean,
|
|
38
38
|
},
|
|
39
39
|
],
|
package/lib/clean.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Config as CLIConfig } from "@react-native-community/cli-types";
|
|
2
|
-
import { asResolvedPath } from "./parsers";
|
|
2
|
+
import { asResolvedPath } from "./helpers/parsers";
|
|
3
3
|
type Args = {
|
|
4
4
|
include?: string;
|
|
5
5
|
projectRoot?: string;
|
|
6
|
-
|
|
6
|
+
verifyCache?: boolean;
|
|
7
7
|
};
|
|
8
|
-
export declare function rnxClean(_argv: string[],
|
|
8
|
+
export declare function rnxClean(_argv: string[], { root }: CLIConfig, cliOptions: Args): Promise<void>;
|
|
9
9
|
export declare const rnxCleanCommand: {
|
|
10
10
|
name: string;
|
|
11
11
|
func: typeof rnxClean;
|
package/lib/clean.js
CHANGED
|
@@ -28,29 +28,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.rnxCleanCommand = void 0;
|
|
30
30
|
exports.rnxClean = rnxClean;
|
|
31
|
-
const
|
|
32
|
-
const
|
|
31
|
+
const node_child_process_1 = require("node:child_process");
|
|
32
|
+
const node_fs_1 = require("node:fs");
|
|
33
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
34
|
+
const os = __importStar(require("node:os"));
|
|
35
|
+
const path = __importStar(require("node:path"));
|
|
33
36
|
const ora_1 = __importDefault(require("ora"));
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var _a, _b, _c;
|
|
40
|
-
const projectRoot = (_a = cliOptions.projectRoot) !== null && _a !== void 0 ? _a : process.cwd();
|
|
41
|
-
if (!fs.existsSync(projectRoot)) {
|
|
42
|
-
throw new Error(`Invalid path provided! ${projectRoot}`);
|
|
43
|
-
}
|
|
44
|
-
const spinner = (0, ora_1.default)();
|
|
45
|
-
try {
|
|
46
|
-
(0, external_1.requireExternal)("@react-native-community/cli-clean");
|
|
47
|
-
spinner.warn("`rnx-clean` has been upstreamed to `@react-native-community/cli`. Please use `npx react-native clean` instead.");
|
|
48
|
-
}
|
|
49
|
-
catch (_) {
|
|
50
|
-
// Ignore
|
|
37
|
+
const parsers_1 = require("./helpers/parsers");
|
|
38
|
+
async function rnxClean(_argv, { root = process.cwd() }, cliOptions) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
if (!(0, node_fs_1.existsSync)(root)) {
|
|
41
|
+
throw new Error(`Invalid project root: ${root}`);
|
|
51
42
|
}
|
|
52
43
|
const npm = os.platform() === "win32" ? "npm.cmd" : "npm";
|
|
53
44
|
const yarn = os.platform() === "win32" ? "yarn.cmd" : "yarn";
|
|
45
|
+
const execute = (command, args, cwd = root) => {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const process = (0, node_child_process_1.spawn)(command, args, {
|
|
48
|
+
cwd,
|
|
49
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
50
|
+
shell: command.endsWith(".bat") || command.endsWith(".cmd"),
|
|
51
|
+
});
|
|
52
|
+
process.on("error", (e) => {
|
|
53
|
+
const code = "code" in e ? e.code : "errno" in e ? e.errno : "1";
|
|
54
|
+
reject(`${e.message} (code: ${code})`);
|
|
55
|
+
});
|
|
56
|
+
process.on("close", (code) => {
|
|
57
|
+
if (code === 0) {
|
|
58
|
+
resolve();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
};
|
|
54
63
|
const COMMANDS = {
|
|
55
64
|
android: [
|
|
56
65
|
{
|
|
@@ -59,7 +68,7 @@ async function rnxClean(_argv, _config, cliOptions) {
|
|
|
59
68
|
const candidates = os.platform() === "win32"
|
|
60
69
|
? ["android/gradlew.bat", "gradlew.bat"]
|
|
61
70
|
: ["android/gradlew", "gradlew"];
|
|
62
|
-
const gradlew = findPath(
|
|
71
|
+
const gradlew = findPath(root, candidates);
|
|
63
72
|
if (gradlew) {
|
|
64
73
|
const script = path.basename(gradlew);
|
|
65
74
|
return execute(os.platform() === "win32" ? script : `./${script}`, ["clean"], path.dirname(gradlew));
|
|
@@ -73,7 +82,7 @@ async function rnxClean(_argv, _config, cliOptions) {
|
|
|
73
82
|
cocoapods: [
|
|
74
83
|
{
|
|
75
84
|
label: "Clean CocoaPods cache",
|
|
76
|
-
action: () => execute("pod", ["cache", "clean", "--all"]
|
|
85
|
+
action: () => execute("pod", ["cache", "clean", "--all"]),
|
|
77
86
|
},
|
|
78
87
|
],
|
|
79
88
|
metro: [
|
|
@@ -93,13 +102,13 @@ async function rnxClean(_argv, _config, cliOptions) {
|
|
|
93
102
|
npm: [
|
|
94
103
|
{
|
|
95
104
|
label: "Remove node_modules",
|
|
96
|
-
action: () => cleanDir(`${
|
|
105
|
+
action: () => cleanDir(`${root}/node_modules`),
|
|
97
106
|
},
|
|
98
|
-
...(cliOptions.
|
|
107
|
+
...(cliOptions.verifyCache
|
|
99
108
|
? [
|
|
100
109
|
{
|
|
101
110
|
label: "Verify npm cache",
|
|
102
|
-
action: () => execute(npm, ["cache", "verify"]
|
|
111
|
+
action: () => execute(npm, ["cache", "verify"]),
|
|
103
112
|
},
|
|
104
113
|
]
|
|
105
114
|
: []),
|
|
@@ -107,26 +116,24 @@ async function rnxClean(_argv, _config, cliOptions) {
|
|
|
107
116
|
watchman: [
|
|
108
117
|
{
|
|
109
118
|
label: "Stop Watchman",
|
|
110
|
-
action: () => execute(os.platform() === "win32" ? "tskill" : "killall", [
|
|
119
|
+
action: () => execute(os.platform() === "win32" ? "tskill" : "killall", [
|
|
120
|
+
"watchman",
|
|
121
|
+
]),
|
|
111
122
|
},
|
|
112
123
|
{
|
|
113
124
|
label: "Delete Watchman cache",
|
|
114
|
-
action: () => execute("watchman", ["watch-del-all"]
|
|
125
|
+
action: () => execute("watchman", ["watch-del-all"]),
|
|
115
126
|
},
|
|
116
127
|
],
|
|
117
128
|
yarn: [
|
|
118
129
|
{
|
|
119
130
|
label: "Clean Yarn cache",
|
|
120
|
-
action: () => execute(yarn, ["cache", "clean"]
|
|
131
|
+
action: () => execute(yarn, ["cache", "clean"]),
|
|
121
132
|
},
|
|
122
133
|
],
|
|
123
134
|
};
|
|
124
|
-
const categories = (
|
|
125
|
-
|
|
126
|
-
"npm",
|
|
127
|
-
"watchman",
|
|
128
|
-
"yarn",
|
|
129
|
-
];
|
|
135
|
+
const categories = (_b = (_a = cliOptions.include) === null || _a === void 0 ? void 0 : _a.split(",")) !== null && _b !== void 0 ? _b : ["metro", "watchman"];
|
|
136
|
+
const spinner = (0, ora_1.default)();
|
|
130
137
|
for (const category of categories) {
|
|
131
138
|
const commands = COMMANDS[category];
|
|
132
139
|
if (!commands) {
|
|
@@ -146,57 +153,30 @@ async function rnxClean(_argv, _config, cliOptions) {
|
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
155
|
function cleanDir(path) {
|
|
149
|
-
if (!
|
|
156
|
+
if (!(0, node_fs_1.existsSync)(path)) {
|
|
150
157
|
return Promise.resolve();
|
|
151
158
|
}
|
|
152
|
-
return fs.
|
|
159
|
+
return fs.rm(path, { maxRetries: 3, recursive: true });
|
|
153
160
|
}
|
|
154
161
|
function findPath(startPath, files) {
|
|
155
162
|
// TODO: Find project files via `@react-native-community/cli`
|
|
156
163
|
for (const file of files) {
|
|
157
164
|
const filename = path.resolve(startPath, file);
|
|
158
|
-
if (
|
|
165
|
+
if ((0, node_fs_1.existsSync)(filename)) {
|
|
159
166
|
return filename;
|
|
160
167
|
}
|
|
161
168
|
}
|
|
162
169
|
return undefined;
|
|
163
170
|
}
|
|
164
|
-
function execute(command, args, cwd) {
|
|
165
|
-
return new Promise((resolve, reject) => {
|
|
166
|
-
const process = (0, child_process_1.spawn)(command, args, {
|
|
167
|
-
cwd,
|
|
168
|
-
stdio: ["inherit", null, null],
|
|
169
|
-
shell: command.endsWith(".bat") || command.endsWith(".cmd"),
|
|
170
|
-
});
|
|
171
|
-
const stderr = [];
|
|
172
|
-
process.stderr.on("data", (data) => {
|
|
173
|
-
stderr.push(data);
|
|
174
|
-
});
|
|
175
|
-
process.on("close", (code, signal) => {
|
|
176
|
-
if (code === 0) {
|
|
177
|
-
resolve();
|
|
178
|
-
}
|
|
179
|
-
else if (stderr) {
|
|
180
|
-
reject(Buffer.concat(stderr).toString().trimEnd());
|
|
181
|
-
}
|
|
182
|
-
else if (signal) {
|
|
183
|
-
reject(`Failed with signal ${signal}`);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
reject(`Failed with exit code ${code}`);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
171
|
exports.rnxCleanCommand = {
|
|
192
172
|
name: "rnx-clean",
|
|
193
173
|
func: rnxClean,
|
|
194
174
|
description: "Clears React Native project related caches",
|
|
195
175
|
options: [
|
|
196
176
|
{
|
|
197
|
-
name: "--include
|
|
198
|
-
description: "Comma-separated flag of caches to clear
|
|
199
|
-
default: "metro,
|
|
177
|
+
name: "--include <android,cocoapods,metro,npm,watchman,yarn>",
|
|
178
|
+
description: "Comma-separated flag of caches to clear e.g., `npm,yarn`",
|
|
179
|
+
default: "metro,watchman",
|
|
200
180
|
},
|
|
201
181
|
{
|
|
202
182
|
name: "--project-root <path>",
|
|
@@ -205,7 +185,7 @@ exports.rnxCleanCommand = {
|
|
|
205
185
|
parse: parsers_1.asResolvedPath,
|
|
206
186
|
},
|
|
207
187
|
{
|
|
208
|
-
name: "--verify",
|
|
188
|
+
name: "--verify-cache",
|
|
209
189
|
description: "Whether to verify the integrity of the cache",
|
|
210
190
|
default: false,
|
|
211
191
|
},
|
package/lib/copy-assets.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Config as CLIConfig } from "@react-native-community/cli-types";
|
|
|
2
2
|
import type { PackageManifest } from "@rnx-kit/tools-node/package";
|
|
3
3
|
import type { AllPlatforms } from "@rnx-kit/tools-react-native";
|
|
4
4
|
import { parsePlatform } from "@rnx-kit/tools-react-native";
|
|
5
|
+
import * as nodefs from "fs";
|
|
5
6
|
export type AndroidArchive = {
|
|
6
7
|
targetName?: string;
|
|
7
8
|
version?: string;
|
|
@@ -36,13 +37,14 @@ export type Context = {
|
|
|
36
37
|
projectRoot: string;
|
|
37
38
|
manifest: PackageManifest;
|
|
38
39
|
options: Options;
|
|
40
|
+
reactNativePath: string;
|
|
39
41
|
};
|
|
40
42
|
export type AssetsConfig = {
|
|
41
43
|
getAssets?: (context: Context) => Promise<NativeAssets>;
|
|
42
44
|
};
|
|
43
45
|
export declare function versionOf(pkgName: string): string;
|
|
44
46
|
export declare function assembleAarBundle(context: Context, packageName: string, { aar }: NativeAssets): Promise<void>;
|
|
45
|
-
export declare function copyAssets({ options: { assetsDest, xcassetsDest } }: Context, packageName: string, { assets, strings, xcassets }: NativeAssets): Promise<void>;
|
|
47
|
+
export declare function copyAssets({ options: { assetsDest, xcassetsDest } }: Context, packageName: string, { assets, strings, xcassets }: NativeAssets, fs?: typeof nodefs): Promise<void>;
|
|
46
48
|
export declare function gatherConfigs({ projectRoot, manifest, }: Context): Promise<Record<string, AssetsConfig | null> | undefined>;
|
|
47
49
|
/**
|
|
48
50
|
* Copies additional assets not picked by bundlers into desired directory.
|
|
@@ -97,11 +99,11 @@ export declare function gatherConfigs({ projectRoot, manifest, }: Context): Prom
|
|
|
97
99
|
*
|
|
98
100
|
* @param options Options dictate what gets copied where
|
|
99
101
|
*/
|
|
100
|
-
export declare function copyProjectAssets(options: Options): Promise<void>;
|
|
102
|
+
export declare function copyProjectAssets(options: Options, { root: projectRoot, reactNativePath }: CLIConfig): Promise<void>;
|
|
101
103
|
export declare const rnxCopyAssetsCommand: {
|
|
102
104
|
name: string;
|
|
103
105
|
description: string;
|
|
104
|
-
func: (_argv: string[],
|
|
106
|
+
func: (_argv: string[], config: CLIConfig, options: Options) => Promise<void>;
|
|
105
107
|
options: ({
|
|
106
108
|
name: string;
|
|
107
109
|
description: string;
|