@saurabhreo/package-tracker 1.0.0 → 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 (3) hide show
  1. package/README.md +3 -74
  2. package/package.json +2 -2
  3. package/src/config.js +47 -6
package/README.md CHANGED
@@ -7,7 +7,6 @@ A lightweight npm package tracking utility similar to Reo. Tracks package instal
7
7
  - 🚀 **Zero Runtime Overhead** - Only runs during installation, never at runtime
8
8
  - 🔒 **Privacy-First** - Respects opt-out mechanisms and user preferences
9
9
  - ⚡ **Non-Blocking** - Never interrupts package installation
10
- - 📊 **Rich Data Collection** - System info, OS stats, package metadata, and more
11
10
  - 🔄 **Retry Logic** - Automatic retries with exponential backoff
12
11
  - 🎛️ **Configurable** - Environment variables and package.json settings
13
12
 
@@ -16,7 +15,7 @@ A lightweight npm package tracking utility similar to Reo. Tracks package instal
16
15
  Add this package as a dependency to any npm package you want to track:
17
16
 
18
17
  ```bash
19
- npm install --save @package-tracker/tracker
18
+ npm install --save @saurabhreo/package-tracker
20
19
  ```
21
20
 
22
21
  Once installed, the tracker will automatically run after `npm install` completes.
@@ -53,39 +52,6 @@ Add configuration to your `package.json`:
53
52
  - Custom endpoint URL for tracking data
54
53
  - Falls back to `PACKAGE_TRACKER_ENDPOINT` environment variable
55
54
 
56
- ## How It Works
57
-
58
- 1. **Postinstall Hook**: The tracker runs automatically via npm's `postinstall` script
59
- 2. **Data Collection**: Gathers system info, package metadata, and installation context
60
- 3. **Telemetry Sending**: Sends data to your configured endpoint via HTTP POST
61
- 4. **Non-Blocking**: All operations are asynchronous and won't block installations
62
-
63
- ## Data Collected
64
-
65
- The tracker collects the following information:
66
-
67
- ### Package Information
68
- - Package name and version
69
- - Installation type (dependency, global, top-level)
70
-
71
- ### System Information
72
- - Platform (darwin, linux, win32, etc.)
73
- - Architecture (x64, arm64, etc.)
74
- - Node.js version
75
- - OS type and release
76
- - CPU count
77
-
78
- ### Installation Context
79
- - Timestamp
80
- - Current working directory
81
- - npm version
82
- - Node environment
83
-
84
- ### Optional Metadata
85
- - Git user information (if available)
86
- - Email domain (for company detection)
87
- - CI/CD environment detection
88
-
89
55
  ## Privacy & Opt-Out
90
56
 
91
57
  ### For Package Authors
@@ -123,7 +89,7 @@ npm install
123
89
  1. Add the tracker to your package:
124
90
 
125
91
  ```bash
126
- npm install --save @package-tracker/tracker
92
+ npm install --save @saurabhreo/package-tracker
127
93
  ```
128
94
 
129
95
  2. Configure your endpoint in `package.json`:
@@ -149,44 +115,7 @@ npm install --save @package-tracker/tracker
149
115
  "endpoint": "https://telemetry.reo.dev/data"
150
116
  },
151
117
  "dependencies": {
152
- "@package-tracker/tracker": "^1.0.0"
153
- }
154
- }
155
- ```
156
-
157
- ## Backend API Requirements
158
-
159
- Your backend endpoint should:
160
-
161
- 1. Accept POST requests with JSON payload
162
- 2. Return 2xx status codes for success
163
- 3. Handle the following payload structure:
164
-
165
- ```json
166
- {
167
- "package": {
168
- "name": "package-name",
169
- "version": "1.0.0"
170
- },
171
- "system": {
172
- "platform": "darwin",
173
- "arch": "x64",
174
- "nodeVersion": "v18.0.0",
175
- "osType": "Darwin",
176
- "osRelease": "21.0.0",
177
- "osPlatform": "darwin",
178
- "cpuCount": 8
179
- },
180
- "installation": {
181
- "timestamp": "2026-02-08T12:00:00.000Z",
182
- "cwd": "/path/to/project",
183
- "isTopLevel": false,
184
- "npmVersion": "9.0.0",
185
- "nodeEnv": "production"
186
- },
187
- "metadata": {
188
- "emailDomain": "example.com",
189
- "ci": [{"GITHUB_ACTIONS": "GitHub Actions"}]
118
+ "@saurabhreo/package-tracker": "^1.0.0"
190
119
  }
191
120
  }
192
121
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saurabhreo/package-tracker",
3
- "version": "1.0.0",
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": {
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",
29
- "url": "https://github.com/reodotdev/package_tracker.git"
29
+ "url": "git+https://github.com/reodotdev/package_tracker.git"
30
30
  },
31
31
  "files": [
32
32
  "index.js",
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