find-primordials 1.0.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.
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +178 -0
- package/analyzer.mjs +2209 -0
- package/ignore.mjs +161 -0
- package/index.d.mts +201 -0
- package/index.mjs +381 -0
- package/package.json +85 -0
- package/primordials.d.mts +32 -0
- package/primordials.mjs +836 -0
- package/worker.mjs +35 -0
package/worker.mjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
import { parentPort } from 'worker_threads';
|
|
3
|
+
|
|
4
|
+
import { analyzeFile } from '#/analyzer';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Shape a thrown value into the same result envelope analyzeFile returns.
|
|
8
|
+
* @param {string} filePath - The file being analyzed
|
|
9
|
+
* @param {unknown} err - The thrown value
|
|
10
|
+
* @returns {{ filePath: string, result: { error: string, findings: [] } }}
|
|
11
|
+
*/
|
|
12
|
+
export function toErrorResult(filePath, err) {
|
|
13
|
+
return {
|
|
14
|
+
filePath,
|
|
15
|
+
result: {
|
|
16
|
+
error: err instanceof Error ? err.message : String(err),
|
|
17
|
+
findings: [],
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Worker receives file paths and options, analyzes them, and sends results back
|
|
23
|
+
if (parentPort) {
|
|
24
|
+
const port = parentPort;
|
|
25
|
+
port.on('message', (message) => {
|
|
26
|
+
const { filePath, options } = message;
|
|
27
|
+
try {
|
|
28
|
+
const result = analyzeFile(filePath, options);
|
|
29
|
+
port.postMessage({ filePath, result });
|
|
30
|
+
} catch (err) {
|
|
31
|
+
// Defensive: analyzeFile catches its own errors and returns them
|
|
32
|
+
port.postMessage(toErrorResult(filePath, err));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|