@saurabhreo/package-tracker 1.0.2 → 1.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/config.js +47 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saurabhreo/package-tracker",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Package tracking utility similar to Reo - tracks npm package installations",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/config.js CHANGED
@@ -14,20 +14,61 @@ class Config {
14
14
 
15
15
  /**
16
16
  * Find package.json by walking up the directory tree
17
+ * Skips the tracker's own package.json to find the parent package
17
18
  */
18
19
  findPackageJson() {
19
20
  let currentDir = process.cwd();
20
21
  const root = path.parse(currentDir).root;
22
+ const trackerPackageName = '@saurabhreo/package-tracker';
21
23
 
22
- while (currentDir !== root) {
23
- const packagePath = path.join(currentDir, 'package.json');
24
- if (fs.existsSync(packagePath)) {
25
- return packagePath;
24
+ // If we're in node_modules, walk up until we exit node_modules
25
+ // to find the parent package that installed the tracker
26
+ if (currentDir.includes('node_modules')) {
27
+ // Walk up until we exit node_modules
28
+ // e.g., /project/node_modules/@saurabhreo/package-tracker -> /project
29
+ while (currentDir !== root && currentDir.includes('node_modules')) {
30
+ currentDir = path.dirname(currentDir);
31
+ }
32
+
33
+ // Now look for package.json in the parent package directory (first one we find)
34
+ // This should be the package that installed the tracker
35
+ while (currentDir !== root) {
36
+ const packagePath = path.join(currentDir, 'package.json');
37
+ if (fs.existsSync(packagePath)) {
38
+ try {
39
+ const content = fs.readFileSync(packagePath, 'utf8');
40
+ const pkg = JSON.parse(content);
41
+ // Skip if this is the tracker's own package.json
42
+ if (pkg.name !== trackerPackageName) {
43
+ return packagePath;
44
+ }
45
+ } catch (error) {
46
+ // Continue searching if package.json is invalid
47
+ }
48
+ }
49
+ currentDir = path.dirname(currentDir);
50
+ }
51
+ } else {
52
+ // Not in node_modules, search normally but skip tracker's package.json
53
+ while (currentDir !== root) {
54
+ const packagePath = path.join(currentDir, 'package.json');
55
+ if (fs.existsSync(packagePath)) {
56
+ try {
57
+ const content = fs.readFileSync(packagePath, 'utf8');
58
+ const pkg = JSON.parse(content);
59
+ // Skip if this is the tracker's own package.json
60
+ if (pkg.name !== trackerPackageName) {
61
+ return packagePath;
62
+ }
63
+ } catch (error) {
64
+ // Continue searching if package.json is invalid
65
+ }
66
+ }
67
+ currentDir = path.dirname(currentDir);
26
68
  }
27
- currentDir = path.dirname(currentDir);
28
69
  }
29
70
 
30
- // Fallback to current directory
71
+ // Fallback: return tracker's package.json if parent not found
31
72
  return path.join(process.cwd(), 'package.json');
32
73
  }
33
74