@rnx-kit/cli 0.18.2 → 0.18.3
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/lib/bin/constants.d.ts +3 -0
- package/lib/bin/constants.js +6 -0
- package/lib/bin/context.d.ts +3 -17
- package/lib/bin/context.js +33 -24
- package/lib/bin/externalCommands.js +2 -1
- package/lib/bin/rnx-cli.d.ts +1 -1
- package/lib/bin/rnx-cli.js +2 -2
- package/lib/build.d.ts +2 -0
- package/lib/build.js +4 -0
- package/package.json +2 -2
package/lib/bin/context.d.ts
CHANGED
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
import type { Command as BaseCommand, Config as BaseConfig } from "@react-native-community/cli-types";
|
|
2
|
+
import { RNX_FAST_PATH } from "./constants";
|
|
2
3
|
type Command = BaseCommand<false> | BaseCommand<true>;
|
|
3
4
|
type Config = BaseConfig & {
|
|
4
|
-
|
|
5
|
+
[RNX_FAST_PATH]?: true;
|
|
5
6
|
commands: Command[];
|
|
6
7
|
};
|
|
7
|
-
export declare function getCoreCommands(): {
|
|
8
|
-
name: string;
|
|
9
|
-
description?: string;
|
|
10
|
-
detached?: false | undefined;
|
|
11
|
-
examples?: Array<{
|
|
12
|
-
desc: string;
|
|
13
|
-
cmd: string;
|
|
14
|
-
}>;
|
|
15
|
-
pkg?: {
|
|
16
|
-
name: string;
|
|
17
|
-
version: string;
|
|
18
|
-
};
|
|
19
|
-
func: import("@react-native-community/cli-types").CommandFunction<Object>;
|
|
20
|
-
options?: import("@react-native-community/cli-types").CommandOption<(ctx: BaseConfig) => import("@react-native-community/cli-types").OptionValue>[] | undefined;
|
|
21
|
-
}[];
|
|
22
8
|
export declare function uniquify(commands: Command[]): Command[];
|
|
23
|
-
export declare function loadContextForCommand(userCommand: string, root?: string): Config
|
|
9
|
+
export declare function loadContextForCommand(userCommand: string, root?: string): Promise<Config>;
|
|
24
10
|
export {};
|
|
25
11
|
//# sourceMappingURL=context.d.ts.map
|
package/lib/bin/context.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCoreCommands = getCoreCommands;
|
|
4
3
|
exports.uniquify = uniquify;
|
|
5
4
|
exports.loadContextForCommand = loadContextForCommand;
|
|
6
5
|
const package_1 = require("@rnx-kit/tools-node/package");
|
|
7
6
|
const cache_1 = require("@rnx-kit/tools-react-native/cache");
|
|
8
7
|
const context_1 = require("@rnx-kit/tools-react-native/context");
|
|
9
8
|
const index_1 = require("../index");
|
|
10
|
-
const
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
function canUseFastPath(userCommand) {
|
|
11
|
+
const cmd = constants_1.RNX_PREFIX + userCommand;
|
|
12
|
+
for (const command of index_1.reactNativeConfig.commands) {
|
|
13
|
+
if (command.name === cmd) {
|
|
14
|
+
return !(constants_1.RNX_FAST_PATH in command) || command[constants_1.RNX_FAST_PATH] !== false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
11
19
|
function findReactNativePath(root, resolveSymlinks = false) {
|
|
12
20
|
const dir = (0, package_1.findPackageDependencyDir)("react-native", {
|
|
13
21
|
startDir: root,
|
|
@@ -18,19 +26,12 @@ function findReactNativePath(root, resolveSymlinks = false) {
|
|
|
18
26
|
}
|
|
19
27
|
return dir;
|
|
20
28
|
}
|
|
21
|
-
function getCoreCommands() {
|
|
22
|
-
const start = RNX_PREFIX.length;
|
|
23
|
-
return index_1.reactNativeConfig.commands.map((command) => ({
|
|
24
|
-
...command,
|
|
25
|
-
name: command.name.substring(start),
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
29
|
function uniquify(commands) {
|
|
29
30
|
const uniqueCommands = {};
|
|
30
31
|
for (const command of commands) {
|
|
31
32
|
const { name } = command;
|
|
32
|
-
if (name.startsWith(RNX_PREFIX)) {
|
|
33
|
-
command.name = name.substring(RNX_PREFIX.length);
|
|
33
|
+
if (name.startsWith(constants_1.RNX_PREFIX)) {
|
|
34
|
+
command.name = name.substring(constants_1.RNX_PREFIX.length);
|
|
34
35
|
uniqueCommands[command.name] = command;
|
|
35
36
|
}
|
|
36
37
|
else if (!uniqueCommands[name]) {
|
|
@@ -39,16 +40,23 @@ function uniquify(commands) {
|
|
|
39
40
|
}
|
|
40
41
|
return Object.values(uniqueCommands);
|
|
41
42
|
}
|
|
42
|
-
function
|
|
43
|
+
async function loadContextWithCLI(root) {
|
|
44
|
+
const rncli = (0, context_1.resolveCommunityCLI)(root);
|
|
45
|
+
const { loadConfig, loadConfigAsync } = require(rncli);
|
|
46
|
+
if (!loadConfigAsync) {
|
|
47
|
+
const options = loadConfig.length === 1 ? { projectRoot: root } : root;
|
|
48
|
+
return loadConfig(options);
|
|
49
|
+
}
|
|
50
|
+
return await loadConfigAsync({ projectRoot: root });
|
|
51
|
+
}
|
|
52
|
+
async function loadContextForCommand(userCommand, root = process.cwd()) {
|
|
43
53
|
// The fast path avoids traversing project dependencies because we know what
|
|
44
54
|
// information our commands depend on.
|
|
45
|
-
|
|
46
|
-
const useFastPath = coreCommands.some(({ name }) => name === userCommand);
|
|
47
|
-
if (useFastPath) {
|
|
55
|
+
if (canUseFastPath(userCommand)) {
|
|
48
56
|
let reactNativePath;
|
|
49
57
|
let reactNativeVersion;
|
|
50
58
|
return {
|
|
51
|
-
|
|
59
|
+
[constants_1.RNX_FAST_PATH]: true,
|
|
52
60
|
root,
|
|
53
61
|
get reactNativePath() {
|
|
54
62
|
if (!reactNativePath) {
|
|
@@ -68,7 +76,13 @@ function loadContextForCommand(userCommand, root = process.cwd()) {
|
|
|
68
76
|
throw new Error("Unexpected access to `dependencies`");
|
|
69
77
|
},
|
|
70
78
|
assets: [],
|
|
71
|
-
commands
|
|
79
|
+
get commands() {
|
|
80
|
+
const start = constants_1.RNX_PREFIX.length;
|
|
81
|
+
return index_1.reactNativeConfig.commands.map((command) => ({
|
|
82
|
+
...command,
|
|
83
|
+
name: command.name.substring(start),
|
|
84
|
+
}));
|
|
85
|
+
},
|
|
72
86
|
get healthChecks() {
|
|
73
87
|
throw new Error("Unexpected access to `healthChecks`");
|
|
74
88
|
},
|
|
@@ -76,16 +90,11 @@ function loadContextForCommand(userCommand, root = process.cwd()) {
|
|
|
76
90
|
throw new Error("Unexpected access to `platforms`");
|
|
77
91
|
},
|
|
78
92
|
get project() {
|
|
79
|
-
|
|
80
|
-
return (0, context_1.loadContext)(root).project;
|
|
93
|
+
throw new Error("Unexpected access to `project`");
|
|
81
94
|
},
|
|
82
95
|
};
|
|
83
96
|
}
|
|
84
|
-
const
|
|
85
|
-
const { loadConfig } = require(rncli);
|
|
86
|
-
const config = loadConfig.length === 1
|
|
87
|
-
? loadConfig({ projectRoot: root })
|
|
88
|
-
: loadConfig(root);
|
|
97
|
+
const config = await loadContextWithCLI(root);
|
|
89
98
|
// We will always load from disk because functions cannot be serialized.
|
|
90
99
|
// However, we should refresh the cache if needed.
|
|
91
100
|
const state = (0, cache_1.getCurrentState)(root);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findExternalCommands = findExternalCommands;
|
|
4
4
|
const context_1 = require("@rnx-kit/tools-react-native/context");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
5
6
|
function tryImport(module, fromDir) {
|
|
6
7
|
try {
|
|
7
8
|
const p = require.resolve(module, { paths: [fromDir] });
|
|
@@ -12,7 +13,7 @@ function tryImport(module, fromDir) {
|
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
function findExternalCommands(config) {
|
|
15
|
-
if (
|
|
16
|
+
if (constants_1.RNX_FAST_PATH in config) {
|
|
16
17
|
// Fast path means we don't need to do anything here
|
|
17
18
|
return [];
|
|
18
19
|
}
|
package/lib/bin/rnx-cli.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function main(): void
|
|
1
|
+
export declare function main(): Promise<void>;
|
|
2
2
|
//# sourceMappingURL=rnx-cli.d.ts.map
|
package/lib/bin/rnx-cli.js
CHANGED
|
@@ -28,9 +28,9 @@ const commander_1 = require("commander");
|
|
|
28
28
|
const path = __importStar(require("node:path"));
|
|
29
29
|
const context_1 = require("./context");
|
|
30
30
|
const externalCommands_1 = require("./externalCommands");
|
|
31
|
-
function main() {
|
|
31
|
+
async function main() {
|
|
32
32
|
const [, , userCommand] = process.argv;
|
|
33
|
-
const context = (0, context_1.loadContextForCommand)(userCommand);
|
|
33
|
+
const context = await (0, context_1.loadContextForCommand)(userCommand);
|
|
34
34
|
const allCommands = context.commands.concat((0, externalCommands_1.findExternalCommands)(context));
|
|
35
35
|
const program = new commander_1.Command(path.basename(__filename, ".js"));
|
|
36
36
|
for (const { name, description, detached, options = [], func, } of allCommands) {
|
package/lib/build.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Config } from "@react-native-community/cli-types";
|
|
2
|
+
import { RNX_FAST_PATH } from "./bin/constants";
|
|
2
3
|
import { setCcacheDir } from "./build/ccache";
|
|
3
4
|
import type { BuildConfiguration, DeviceType, InputParams } from "./build/types";
|
|
4
5
|
declare function asConfiguration(configuration: string): BuildConfiguration;
|
|
5
6
|
declare function asDestination(destination: string): DeviceType;
|
|
6
7
|
export declare function rnxBuild(_argv: string[], config: Config, buildParams: InputParams): Promise<import("./build/android").BuildResult> | Promise<import("./build/apple").BuildResult>;
|
|
7
8
|
export declare const rnxBuildCommand: {
|
|
9
|
+
[RNX_FAST_PATH]: boolean;
|
|
8
10
|
name: string;
|
|
9
11
|
description: string;
|
|
10
12
|
func: typeof rnxBuild;
|
package/lib/build.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.rnxBuildCommand = void 0;
|
|
4
4
|
exports.rnxBuild = rnxBuild;
|
|
5
5
|
const commander_1 = require("commander");
|
|
6
|
+
const constants_1 = require("./bin/constants");
|
|
6
7
|
const android_1 = require("./build/android");
|
|
7
8
|
const ccache_1 = require("./build/ccache");
|
|
8
9
|
const ios_1 = require("./build/ios");
|
|
@@ -49,6 +50,9 @@ function rnxBuild(_argv, config, buildParams) {
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
exports.rnxBuildCommand = {
|
|
53
|
+
// The build command requires the `project` field, which currently requires
|
|
54
|
+
// loading the full config.
|
|
55
|
+
[constants_1.RNX_FAST_PATH]: false,
|
|
52
56
|
name: "rnx-build",
|
|
53
57
|
description: "Build your native app for testing in emulator/simulator or on device",
|
|
54
58
|
func: rnxBuild,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rnx-kit/cli",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.3",
|
|
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#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"@types/jest": "^29.2.1",
|
|
84
84
|
"@types/node": "^20.0.0",
|
|
85
85
|
"@types/qrcode": "^1.4.2",
|
|
86
|
-
"eslint": "^
|
|
86
|
+
"eslint": "^9.0.0",
|
|
87
87
|
"jest": "^29.2.1",
|
|
88
88
|
"markdown-table": "^3.0.0",
|
|
89
89
|
"metro": "^0.80.3",
|