runtimedev-link 1.0.0 → 1.0.1

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/lib/fs_scan.js +56 -25
  2. package/package.json +1 -1
package/lib/fs_scan.js CHANGED
@@ -25,18 +25,44 @@ function shouldSkipPath(absPath) {
25
25
 
26
26
  function skipDirName(name) {
27
27
  if (!name || name === '.' || name === '..') return true;
28
- const lower = name.toLowerCase();
29
- return lower === 'node_modules' || lower === '$recycle.bin';
28
+ switch (String(name).toLowerCase()) {
29
+ case 'system volume information':
30
+ case '$recycle.bin':
31
+ case 'recovery':
32
+ case 'node_modules':
33
+ return true;
34
+ default:
35
+ return false;
36
+ }
30
37
  }
31
38
 
32
39
  function defaultScanRoot() {
33
40
  try {
41
+ if (process.platform === 'win32') {
42
+ const profile = process.env.USERPROFILE;
43
+ if (profile) return profile;
44
+ }
34
45
  return process.env.HOME || process.env.USERPROFILE || process.cwd();
35
46
  } catch {
36
47
  return '.';
37
48
  }
38
49
  }
39
50
 
51
+ function entryKind(absPath, entry) {
52
+ try {
53
+ if (entry.isDirectory()) return 'directory';
54
+ if (entry.isFile()) return 'file';
55
+ if (entry.isSymbolicLink()) {
56
+ const st = fs.statSync(absPath);
57
+ if (st.isDirectory()) return 'directory';
58
+ if (st.isFile()) return 'file';
59
+ }
60
+ } catch {
61
+ // unreadable entry
62
+ }
63
+ return null;
64
+ }
65
+
40
66
  function scanDirectory(root, opts) {
41
67
  const maxEntries =
42
68
  opts && opts.maxEntries > 0
@@ -45,20 +71,23 @@ function scanDirectory(root, opts) {
45
71
  const depth =
46
72
  opts && opts.depth > 0 ? Math.min(opts.depth, 50) : 5;
47
73
  const cleanRoot = path.resolve(String(root || defaultScanRoot()));
48
- if (shouldSkipPath(cleanRoot)) {
74
+
75
+ try {
76
+ const st = fs.statSync(cleanRoot);
77
+ if (!st.isDirectory()) return null;
78
+ } catch {
49
79
  return null;
50
80
  }
51
- const state = { count: 0 };
52
- return walkDir(cleanRoot, path.basename(cleanRoot) || '/', depth, maxEntries, state);
81
+
82
+ if (shouldSkipPath(cleanRoot)) return null;
83
+
84
+ // Match agent-go: root node is named "/" regardless of path.
85
+ return walkDir(cleanRoot, '/', depth, maxEntries);
53
86
  }
54
87
 
55
- function walkDir(absPath, displayName, remainingDepth, maxEntries, state) {
56
- if (state.count >= maxEntries) {
57
- return { name: displayName, type: 'directory', children: [] };
58
- }
59
- if (shouldSkipPath(absPath)) {
60
- return null;
61
- }
88
+ function walkDir(absPath, displayName, remainingDepth, maxEntries) {
89
+ if (remainingDepth <= 0) return null;
90
+ if (shouldSkipPath(absPath)) return null;
62
91
 
63
92
  let entries = [];
64
93
  try {
@@ -68,30 +97,32 @@ function walkDir(absPath, displayName, remainingDepth, maxEntries, state) {
68
97
  }
69
98
 
70
99
  const children = [];
100
+ let n = 0;
101
+
71
102
  for (const entry of entries) {
72
- if (state.count >= maxEntries) break;
103
+ if (n >= maxEntries) break;
73
104
  if (skipDirName(entry.name)) continue;
74
105
 
75
106
  const subPath = path.join(absPath, entry.name);
76
107
  if (shouldSkipPath(subPath)) continue;
77
108
 
78
- if (entry.isDirectory()) {
79
- state.count += 1;
109
+ const kind = entryKind(subPath, entry);
110
+ if (!kind) continue;
111
+
112
+ if (kind === 'directory') {
80
113
  if (remainingDepth <= 1) {
81
114
  children.push({ name: entry.name, type: 'directory' });
115
+ n += 1;
82
116
  continue;
83
117
  }
84
- const sub = walkDir(
85
- subPath,
86
- entry.name,
87
- remainingDepth - 1,
88
- maxEntries,
89
- state
90
- );
91
- if (sub) children.push(sub);
92
- } else if (entry.isFile()) {
93
- state.count += 1;
118
+ const sub = walkDir(subPath, entry.name, remainingDepth - 1, maxEntries);
119
+ if (sub) {
120
+ children.push(sub);
121
+ n += 1;
122
+ }
123
+ } else {
94
124
  children.push({ name: entry.name, type: 'file' });
125
+ n += 1;
95
126
  }
96
127
  }
97
128
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runtimedev-link",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Pure Node.js telemetry for RuntimeDev platform",
5
5
  "main": "lib/transport.js",
6
6
  "bin": {