react-native-update-cli 1.43.6 → 1.44.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.
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "checkLockFiles", {
9
9
  }
10
10
  });
11
11
  const _nodefs = /*#__PURE__*/ _interop_require_default(require("node:fs"));
12
+ const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
12
13
  const _i18n = require("./i18n");
13
14
  function _interop_require_default(obj) {
14
15
  return obj && obj.__esModule ? obj : {
@@ -22,21 +23,71 @@ const lockFiles = [
22
23
  'bun.lockb',
23
24
  'bun.lock'
24
25
  ];
25
- const existingLockFiles = [];
26
- function checkLockFiles() {
26
+ // Function to check if a package.json has a workspaces field
27
+ function hasWorkspaces(dir) {
28
+ const pkgPath = _nodepath.default.join(dir, 'package.json');
29
+ if (_nodefs.default.existsSync(pkgPath)) {
30
+ try {
31
+ const pkg = JSON.parse(_nodefs.default.readFileSync(pkgPath, 'utf-8'));
32
+ return !!pkg.workspaces;
33
+ } catch (e) {
34
+ // Ignore parsing errors
35
+ }
36
+ }
37
+ return false;
38
+ }
39
+ // Helper function to find lock files in a specific directory
40
+ function findLockFilesInDir(directory) {
41
+ const found = [];
27
42
  for (const file of lockFiles){
28
- if (_nodefs.default.existsSync(file)) {
29
- existingLockFiles.push(file);
43
+ const filePath = _nodepath.default.join(directory, file);
44
+ if (_nodefs.default.existsSync(filePath)) {
45
+ found.push(filePath);
30
46
  }
31
47
  }
32
- if (existingLockFiles.length === 1) {
48
+ return found;
49
+ }
50
+ function checkLockFiles() {
51
+ const cwd = process.cwd();
52
+ let searchDir = cwd;
53
+ let foundLockFiles = findLockFilesInDir(searchDir);
54
+ // If no lock file in cwd, try to find monorepo root and check there
55
+ if (foundLockFiles.length === 0) {
56
+ // Search upwards for package.json with workspaces
57
+ let currentDir = _nodepath.default.dirname(cwd); // Start searching from parent
58
+ let projectRootDir = null;
59
+ while(true){
60
+ if (hasWorkspaces(currentDir)) {
61
+ projectRootDir = currentDir;
62
+ break;
63
+ }
64
+ const parentDir = _nodepath.default.dirname(currentDir);
65
+ if (parentDir === currentDir) {
66
+ break;
67
+ }
68
+ currentDir = parentDir;
69
+ }
70
+ // If a potential root was found, switch search directory and re-check
71
+ if (projectRootDir) {
72
+ searchDir = projectRootDir;
73
+ foundLockFiles = findLockFilesInDir(searchDir);
74
+ }
75
+ // If no projectRootDir found, foundLockFiles remains empty and searchDir remains cwd
76
+ }
77
+ // Handle results based on findings in the final searchDir
78
+ if (foundLockFiles.length === 1) {
79
+ // Successfully found one lock file in the determined searchDir
33
80
  return;
34
81
  }
35
- console.warn((0, _i18n.t)('lockBestPractice'));
36
- if (existingLockFiles.length === 0) {
37
- throw new Error((0, _i18n.t)('lockNotFound'));
82
+ if (foundLockFiles.length > 1) {
83
+ // Found multiple lock files in the determined searchDir
84
+ console.warn((0, _i18n.t)('lockBestPractice'));
85
+ throw new Error((0, _i18n.t)('multipleLocksFound', {
86
+ lockFiles: foundLockFiles.join(', ')
87
+ }));
38
88
  }
39
- throw new Error((0, _i18n.t)('multipleLocksFound', {
40
- lockFiles: existingLockFiles.join(', ')
41
- }));
89
+ // If we reach here, foundLockFiles.length === 0
90
+ console.warn((0, _i18n.t)('lockBestPractice'));
91
+ // Warn instead of throwing an error if no lock file is found
92
+ console.warn((0, _i18n.t)('lockNotFound'));
42
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "1.43.6",
3
+ "version": "1.44.0",
4
4
  "description": "command line tool for react-native-update (remote updates for react native)",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,4 +1,5 @@
1
1
  import fs from 'node:fs';
2
+ import path from 'node:path';
2
3
  import { t } from './i18n';
3
4
 
4
5
  const lockFiles = [
@@ -9,21 +10,80 @@ const lockFiles = [
9
10
  'bun.lock',
10
11
  ];
11
12
 
12
- const existingLockFiles: string[] = [];
13
- export function checkLockFiles() {
13
+ // Function to check if a package.json has a workspaces field
14
+ function hasWorkspaces(dir: string): boolean {
15
+ const pkgPath = path.join(dir, 'package.json');
16
+ if (fs.existsSync(pkgPath)) {
17
+ try {
18
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
19
+ return !!pkg.workspaces;
20
+ } catch (e) {
21
+ // Ignore parsing errors
22
+ }
23
+ }
24
+ return false;
25
+ }
26
+
27
+ // Helper function to find lock files in a specific directory
28
+ function findLockFilesInDir(directory: string): string[] {
29
+ const found: string[] = [];
14
30
  for (const file of lockFiles) {
15
- if (fs.existsSync(file)) {
16
- existingLockFiles.push(file);
31
+ const filePath = path.join(directory, file);
32
+ if (fs.existsSync(filePath)) {
33
+ found.push(filePath);
17
34
  }
18
35
  }
19
- if (existingLockFiles.length === 1) {
36
+ return found;
37
+ }
38
+
39
+ export function checkLockFiles() {
40
+ const cwd = process.cwd();
41
+ let searchDir = cwd;
42
+ let foundLockFiles = findLockFilesInDir(searchDir);
43
+
44
+ // If no lock file in cwd, try to find monorepo root and check there
45
+ if (foundLockFiles.length === 0) {
46
+ // Search upwards for package.json with workspaces
47
+ let currentDir = path.dirname(cwd); // Start searching from parent
48
+ let projectRootDir: string | null = null;
49
+
50
+ while (true) {
51
+ if (hasWorkspaces(currentDir)) {
52
+ projectRootDir = currentDir;
53
+ break;
54
+ }
55
+ const parentDir = path.dirname(currentDir);
56
+ if (parentDir === currentDir) {
57
+ // Reached the filesystem root
58
+ break;
59
+ }
60
+ currentDir = parentDir;
61
+ }
62
+
63
+ // If a potential root was found, switch search directory and re-check
64
+ if (projectRootDir) {
65
+ searchDir = projectRootDir;
66
+ foundLockFiles = findLockFilesInDir(searchDir);
67
+ }
68
+ // If no projectRootDir found, foundLockFiles remains empty and searchDir remains cwd
69
+ }
70
+
71
+ // Handle results based on findings in the final searchDir
72
+ if (foundLockFiles.length === 1) {
73
+ // Successfully found one lock file in the determined searchDir
20
74
  return;
21
75
  }
22
- console.warn(t('lockBestPractice'));
23
- if (existingLockFiles.length === 0) {
24
- throw new Error(t('lockNotFound'));
76
+
77
+ if (foundLockFiles.length > 1) {
78
+ // Found multiple lock files in the determined searchDir
79
+ console.warn(t('lockBestPractice'));
80
+ throw new Error(
81
+ t('multipleLocksFound', { lockFiles: foundLockFiles.join(', ') }),
82
+ );
25
83
  }
26
- throw new Error(
27
- t('multipleLocksFound', { lockFiles: existingLockFiles.join(', ') }),
28
- );
84
+
85
+ // If we reach here, foundLockFiles.length === 0
86
+ console.warn(t('lockBestPractice'));
87
+ // Warn instead of throwing an error if no lock file is found
88
+ console.warn(t('lockNotFound'));
29
89
  }