@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
@@ -1,6 +1,6 @@
1
1
  import type { Config as CLIConfig } from "@react-native-community/cli-types";
2
2
  type CLIArgs = Record<string, string | number | boolean | undefined>;
3
- export declare function rnxAlignDeps(argv: string[], _config: CLIConfig, args: CLIArgs): void;
3
+ export declare function rnxAlignDeps(_argv: string[], _config: CLIConfig, args: CLIArgs): void;
4
4
  export declare const rnxAlignDepsCommand: {
5
5
  name: string;
6
6
  description: string;
package/lib/align-deps.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.rnxAlignDepsCommand = exports.rnxAlignDeps = void 0;
4
+ exports.rnxAlignDepsCommand = void 0;
5
+ exports.rnxAlignDeps = rnxAlignDeps;
5
6
  const align_deps_1 = require("@rnx-kit/align-deps");
6
7
  const properties_1 = require("@rnx-kit/tools-language/properties");
7
8
  const optionsMap = {
@@ -11,7 +12,7 @@ const optionsMap = {
11
12
  requirements: "requirements",
12
13
  "set-version": "setVersion",
13
14
  };
14
- function rnxAlignDeps(argv, _config, args) {
15
+ function rnxAlignDeps(_argv, _config, args) {
15
16
  var _a;
16
17
  (0, align_deps_1.cli)({
17
18
  ...(0, properties_1.pickValues)(args, Object.values(optionsMap), Object.keys(optionsMap)),
@@ -21,25 +22,23 @@ function rnxAlignDeps(argv, _config, args) {
21
22
  "no-unmanaged": Boolean(args.noUnmanaged),
22
23
  verbose: Boolean(args.verbose),
23
24
  write: Boolean(args.write),
24
- packages: argv,
25
25
  });
26
26
  }
27
- exports.rnxAlignDeps = rnxAlignDeps;
28
27
  exports.rnxAlignDepsCommand = {
29
28
  name: "rnx-align-deps",
30
29
  description: "Manage dependencies within a repository and across many repositories",
31
30
  func: rnxAlignDeps,
32
31
  options: [
33
32
  {
34
- name: `--diff-mode [${align_deps_1.cliOptions["diff-mode"].choices.join("|")}]`,
33
+ name: `--diff-mode <${align_deps_1.cliOptions["diff-mode"].choices.join("|")}>`,
35
34
  description: align_deps_1.cliOptions["diff-mode"].description,
36
35
  },
37
36
  {
38
- name: "--exclude-packages [packages]",
37
+ name: "--exclude-packages <packages>",
39
38
  description: align_deps_1.cliOptions["exclude-packages"].description,
40
39
  },
41
40
  {
42
- name: `--init [${(_a = align_deps_1.cliOptions.init.choices) === null || _a === void 0 ? void 0 : _a.join("|")}]`,
41
+ name: `--init <${(_a = align_deps_1.cliOptions.init.choices) === null || _a === void 0 ? void 0 : _a.join("|")}>`,
43
42
  description: align_deps_1.cliOptions.init.description,
44
43
  },
45
44
  {
@@ -55,11 +54,11 @@ exports.rnxAlignDepsCommand = {
55
54
  description: align_deps_1.cliOptions["no-unmanaged"].description,
56
55
  },
57
56
  {
58
- name: "--presets [presets]",
57
+ name: "--presets <presets>",
59
58
  description: align_deps_1.cliOptions.presets.description,
60
59
  },
61
60
  {
62
- name: "--requirements [requirements]",
61
+ name: "--requirements <requirements>",
63
62
  description: align_deps_1.cliOptions.requirements.description,
64
63
  },
65
64
  {
@@ -1,5 +1,5 @@
1
1
  import { parsePlatform } from "@rnx-kit/tools-react-native/platform";
2
- import { asBoolean, asNumber, parseTransformProfile } from "../parsers";
2
+ import { asBoolean, asNumber, asTransformProfile } from "../helpers/parsers";
3
3
  export declare const commonBundleCommandOptions: ({
4
4
  name: string;
5
5
  description: string;
@@ -33,7 +33,7 @@ export declare const commonBundleCommandOptions: ({
33
33
  } | {
34
34
  name: string;
35
35
  description: string;
36
- parse: typeof parseTransformProfile;
36
+ parse: typeof asTransformProfile;
37
37
  default?: undefined;
38
38
  })[];
39
39
  //# sourceMappingURL=cliOptions.d.ts.map
@@ -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 [id]",
9
- description: "Target bundle definition. This is only needed when the rnx-kit configuration has multiple bundle definitions.",
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 [path]",
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 [ios|android|windows|win32|macos]",
17
- description: "Target platform. When not given, all platforms in the rnx-kit configuration are bundled.",
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. Disabling minification is useful for test builds.",
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 [string]",
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 [utf8|utf16le|ascii]",
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 [number]",
42
- description: "Specifies the maximum number of parallel worker threads to use for transforming files. This defaults to the number of cores available on your machine.",
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 [string]",
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 [string]",
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 [path]",
59
- description: "Path where bundle assets like images are written, either absolute or relative to the package. If not given, assets are ignored.",
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 [string]",
63
- description: "Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default",
64
- parse: parsers_1.parseTransformProfile,
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 [string]",
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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultBundlerPlugins = void 0;
3
+ exports.getDefaultBundlerPlugins = getDefaultBundlerPlugins;
4
4
  const defaultPlugins = {
5
5
  plugins: [
6
6
  "@rnx-kit/metro-plugin-cyclic-dependencies-detector",
@@ -12,5 +12,4 @@ const defaultPlugins = {
12
12
  function getDefaultBundlerPlugins() {
13
13
  return defaultPlugins;
14
14
  }
15
- exports.getDefaultBundlerPlugins = getDefaultBundlerPlugins;
16
15
  //# sourceMappingURL=defaultPlugins.js.map
@@ -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
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.emitBytecode = void 0;
26
+ 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");
@@ -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;
@@ -121,5 +115,4 @@ function emitBytecode(input, sourcemap, options) {
121
115
  fs.writeFileSync(outputMap, JSON.stringify(composed));
122
116
  }
123
117
  }
124
- exports.emitBytecode = emitBytecode;
125
118
  //# sourceMappingURL=hermes.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCliPlatformBundleConfigs = exports.getTargetPlatforms = void 0;
3
+ exports.getTargetPlatforms = getTargetPlatforms;
4
+ exports.getCliPlatformBundleConfigs = getCliPlatformBundleConfigs;
4
5
  const config_1 = require("@rnx-kit/config");
5
6
  const defaultPlugins_1 = require("./defaultPlugins");
6
7
  /**
@@ -19,7 +20,6 @@ function getTargetPlatforms(overridePlatform, targetPlatforms) {
19
20
  }
20
21
  throw new Error("No target platforms given. Update the rnx-kit configuration to include a target platform, or provide a target platform on the command-line.");
21
22
  }
22
- exports.getTargetPlatforms = getTargetPlatforms;
23
23
  function getDefaultBundleParameters(platform) {
24
24
  const extension = platform === "ios" || platform === "macos" ? "jsbundle" : "bundle";
25
25
  return {
@@ -57,5 +57,4 @@ function getCliPlatformBundleConfigs(id, overridePlatform) {
57
57
  };
58
58
  });
59
59
  }
60
- exports.getCliPlatformBundleConfigs = getCliPlatformBundleConfigs;
61
60
  //# sourceMappingURL=kit-config.js.map
@@ -23,15 +23,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.metroBundle = void 0;
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 fs = __importStar(require("fs"));
30
29
  const path = __importStar(require("path"));
31
- const metro_config_1 = require("../metro-config");
32
- function ensureDir(p) {
33
- fs.mkdirSync(p, { recursive: true, mode: 0o755 });
34
- }
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,15 +63,14 @@ 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);
78
75
  }
79
- exports.metroBundle = metroBundle;
80
76
  //# sourceMappingURL=metro.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyBundleConfigOverrides = exports.overridableCommonBundleOptions = void 0;
3
+ exports.overridableCommonBundleOptions = void 0;
4
+ exports.applyBundleConfigOverrides = applyBundleConfigOverrides;
4
5
  const properties_1 = require("@rnx-kit/tools-language/properties");
5
6
  exports.overridableCommonBundleOptions = [
6
7
  "assetsDest",
@@ -27,5 +28,4 @@ function applyBundleConfigOverrides(overrides, configs, keys) {
27
28
  }
28
29
  }
29
30
  }
30
- exports.applyBundleConfigOverrides = applyBundleConfigOverrides;
31
31
  //# sourceMappingURL=overrides.js.map
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").parseTransformProfile;
45
+ parse: typeof import("./helpers/parsers").asTransformProfile;
46
46
  default?: undefined;
47
47
  })[];
48
48
  };
package/lib/bundle.js CHANGED
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rnxBundleCommand = exports.rnxBundle = void 0;
3
+ exports.rnxBundleCommand = void 0;
4
+ exports.rnxBundle = rnxBundle;
4
5
  const metro_service_1 = require("@rnx-kit/metro-service");
5
6
  const cliOptions_1 = require("./bundle/cliOptions");
6
7
  const hermes_1 = require("./bundle/hermes");
7
8
  const kit_config_1 = require("./bundle/kit-config");
8
9
  const metro_1 = require("./bundle/metro");
9
10
  const overrides_1 = require("./bundle/overrides");
10
- const parsers_1 = require("./parsers");
11
+ const parsers_1 = require("./helpers/parsers");
11
12
  async function rnxBundle(_argv, cliConfig, cliOptions) {
12
13
  const metroConfig = await (0, metro_service_1.loadMetroConfig)(cliConfig, cliOptions);
13
14
  const bundleConfigs = (0, kit_config_1.getCliPlatformBundleConfigs)(cliOptions.id, cliOptions.platform);
@@ -20,20 +21,19 @@ async function rnxBundle(_argv, cliConfig, cliOptions) {
20
21
  await (0, metro_1.metroBundle)(metroConfig, bundleConfig, cliOptions.dev, cliOptions.minify);
21
22
  const { bundleOutput, hermes, sourcemapOutput } = bundleConfig;
22
23
  if (hermes) {
23
- (0, hermes_1.emitBytecode)(bundleOutput, sourcemapOutput, hermes === true ? {} : hermes);
24
+ (0, hermes_1.emitBytecode)(cliConfig, bundleOutput, sourcemapOutput, hermes === true ? {} : hermes);
24
25
  }
25
26
  }
26
27
  }
27
- exports.rnxBundle = rnxBundle;
28
28
  exports.rnxBundleCommand = {
29
29
  name: "rnx-bundle",
30
- description: "Bundle your rnx-kit package for offline use. See https://aka.ms/rnx-kit.",
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
  verify?: boolean;
7
7
  };
8
- export declare function rnxClean(_argv: string[], _config: CLIConfig, cliOptions: Args): Promise<void>;
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
@@ -26,30 +26,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.rnxCleanCommand = exports.rnxClean = void 0;
29
+ exports.rnxCleanCommand = void 0;
30
+ exports.rnxClean = rnxClean;
30
31
  const child_process_1 = require("child_process");
31
- const fs = __importStar(require("fs-extra"));
32
+ const fs_1 = require("fs");
33
+ const fs = __importStar(require("fs/promises"));
32
34
  const ora_1 = __importDefault(require("ora"));
33
35
  const os = __importStar(require("os"));
34
36
  const path = __importStar(require("path"));
35
- const parsers_1 = require("./parsers");
36
- const external_1 = require("./serve/external");
37
- async function rnxClean(_argv, _config, cliOptions) {
38
- var _a, _b, _c;
39
- const projectRoot = (_a = cliOptions.projectRoot) !== null && _a !== void 0 ? _a : process.cwd();
40
- if (!fs.existsSync(projectRoot)) {
41
- throw new Error(`Invalid path provided! ${projectRoot}`);
42
- }
43
- const spinner = (0, ora_1.default)();
44
- try {
45
- (0, external_1.requireExternal)("@react-native-community/cli-clean");
46
- spinner.warn("`rnx-clean` has been upstreamed to `@react-native-community/cli`. Please use `npx react-native clean` instead.");
47
- }
48
- catch (_) {
49
- // Ignore
37
+ const parsers_1 = require("./helpers/parsers");
38
+ async function rnxClean(_argv, { root = process.cwd() }, cliOptions) {
39
+ var _a, _b;
40
+ if (!(0, fs_1.existsSync)(root)) {
41
+ throw new Error(`Invalid project root: ${root}`);
50
42
  }
51
43
  const npm = os.platform() === "win32" ? "npm.cmd" : "npm";
52
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, 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
+ };
53
63
  const COMMANDS = {
54
64
  android: [
55
65
  {
@@ -58,7 +68,7 @@ async function rnxClean(_argv, _config, cliOptions) {
58
68
  const candidates = os.platform() === "win32"
59
69
  ? ["android/gradlew.bat", "gradlew.bat"]
60
70
  : ["android/gradlew", "gradlew"];
61
- const gradlew = findPath(projectRoot, candidates);
71
+ const gradlew = findPath(root, candidates);
62
72
  if (gradlew) {
63
73
  const script = path.basename(gradlew);
64
74
  return execute(os.platform() === "win32" ? script : `./${script}`, ["clean"], path.dirname(gradlew));
@@ -72,7 +82,7 @@ async function rnxClean(_argv, _config, cliOptions) {
72
82
  cocoapods: [
73
83
  {
74
84
  label: "Clean CocoaPods cache",
75
- action: () => execute("pod", ["cache", "clean", "--all"], projectRoot),
85
+ action: () => execute("pod", ["cache", "clean", "--all"]),
76
86
  },
77
87
  ],
78
88
  metro: [
@@ -92,13 +102,13 @@ async function rnxClean(_argv, _config, cliOptions) {
92
102
  npm: [
93
103
  {
94
104
  label: "Remove node_modules",
95
- action: () => cleanDir(`${projectRoot}/node_modules`),
105
+ action: () => cleanDir(`${root}/node_modules`),
96
106
  },
97
107
  ...(cliOptions.verify
98
108
  ? [
99
109
  {
100
110
  label: "Verify npm cache",
101
- action: () => execute(npm, ["cache", "verify"], projectRoot),
111
+ action: () => execute(npm, ["cache", "verify"]),
102
112
  },
103
113
  ]
104
114
  : []),
@@ -106,26 +116,24 @@ async function rnxClean(_argv, _config, cliOptions) {
106
116
  watchman: [
107
117
  {
108
118
  label: "Stop Watchman",
109
- action: () => execute(os.platform() === "win32" ? "tskill" : "killall", ["watchman"], projectRoot),
119
+ action: () => execute(os.platform() === "win32" ? "tskill" : "killall", [
120
+ "watchman",
121
+ ]),
110
122
  },
111
123
  {
112
124
  label: "Delete Watchman cache",
113
- action: () => execute("watchman", ["watch-del-all"], projectRoot),
125
+ action: () => execute("watchman", ["watch-del-all"]),
114
126
  },
115
127
  ],
116
128
  yarn: [
117
129
  {
118
130
  label: "Clean Yarn cache",
119
- action: () => execute(yarn, ["cache", "clean"], projectRoot),
131
+ action: () => execute(yarn, ["cache", "clean"]),
120
132
  },
121
133
  ],
122
134
  };
123
- const categories = (_c = (_b = cliOptions.include) === null || _b === void 0 ? void 0 : _b.split(",")) !== null && _c !== void 0 ? _c : [
124
- "metro",
125
- "npm",
126
- "watchman",
127
- "yarn",
128
- ];
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)();
129
137
  for (const category of categories) {
130
138
  const commands = COMMANDS[category];
131
139
  if (!commands) {
@@ -144,59 +152,31 @@ async function rnxClean(_argv, _config, cliOptions) {
144
152
  }
145
153
  }
146
154
  }
147
- exports.rnxClean = rnxClean;
148
155
  function cleanDir(path) {
149
- if (!fs.existsSync(path)) {
156
+ if (!(0, fs_1.existsSync)(path)) {
150
157
  return Promise.resolve();
151
158
  }
152
- return fs.rmdir(path, { maxRetries: 3, recursive: true });
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 (fs.existsSync(filename)) {
165
+ if ((0, 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 [android,cocoapods,metro,npm,watchman,yarn]",
198
- description: "Comma-separated flag of caches to clear, e.g. `npm,yarn`. When not specified, only non-platform specific caches are cleared.",
199
- default: "metro,npm,watchman,yarn",
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>",
@@ -23,7 +23,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.rnxCopyAssetsCommand = exports.copyProjectAssets = exports.gatherConfigs = exports.copyAssets = exports.assembleAarBundle = exports.versionOf = void 0;
26
+ exports.rnxCopyAssetsCommand = void 0;
27
+ exports.versionOf = versionOf;
28
+ exports.assembleAarBundle = assembleAarBundle;
29
+ exports.copyAssets = copyAssets;
30
+ exports.gatherConfigs = gatherConfigs;
31
+ exports.copyProjectAssets = copyProjectAssets;
27
32
  const console_1 = require("@rnx-kit/console");
28
33
  const properties_1 = require("@rnx-kit/tools-language/properties");
29
34
  const package_1 = require("@rnx-kit/tools-node/package");
@@ -71,7 +76,6 @@ function versionOf(pkgName) {
71
76
  const { version } = (0, package_1.readPackage)(packageDir);
72
77
  return version;
73
78
  }
74
- exports.versionOf = versionOf;
75
79
  function getAndroidPaths(context, packageName, { targetName, version, output }) {
76
80
  const projectRoot = (0, package_1.findPackageDependencyDir)(packageName);
77
81
  if (!projectRoot) {
@@ -224,7 +228,6 @@ async function assembleAarBundle(context, packageName, { aar }) {
224
228
  }
225
229
  await Promise.all(targetsToCopy.map(([src, dest]) => fs.copy(src, dest)));
226
230
  }
227
- exports.assembleAarBundle = assembleAarBundle;
228
231
  function copyFiles(files, destination) {
229
232
  if (!Array.isArray(files) || files.length === 0) {
230
233
  return [];
@@ -244,7 +247,6 @@ async function copyAssets({ options: { assetsDest, xcassetsDest } }, packageName
244
247
  }
245
248
  await Promise.all(tasks);
246
249
  }
247
- exports.copyAssets = copyAssets;
248
250
  async function gatherConfigs({ projectRoot, manifest, }) {
249
251
  const { dependencies, devDependencies } = manifest;
250
252
  const packages = [...(0, properties_1.keysOf)(dependencies), ...(0, properties_1.keysOf)(devDependencies)];
@@ -281,7 +283,6 @@ async function gatherConfigs({ projectRoot, manifest, }) {
281
283
  }
282
284
  return assetsConfigs;
283
285
  }
284
- exports.gatherConfigs = gatherConfigs;
285
286
  /**
286
287
  * Copies additional assets not picked by bundlers into desired directory.
287
288
  *
@@ -377,7 +378,6 @@ async function copyProjectAssets(options) {
377
378
  await Promise.all(copyTasks);
378
379
  }
379
380
  }
380
- exports.copyProjectAssets = copyProjectAssets;
381
381
  exports.rnxCopyAssetsCommand = {
382
382
  name: "rnx-copy-assets",
383
383
  description: "Copies additional assets not picked by bundlers into desired directory.",