h56-github-scrapper 1.0.4 → 1.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h56-github-scrapper",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "GitHub user scraper",
5
5
  "type": "module",
6
6
  "main": "main-scrapping.js",
@@ -2,45 +2,74 @@
2
2
  /**
3
3
  * scripts/ensure-external-deps.js (ESM)
4
4
  *
5
- * Postinstall helper (ESM). Attempts to install optional dependencies if missing.**/
5
+ * Postinstall helper: idempotent installer for optional external deps.
6
+ * - Implemented as a full ESM module using top-level await.
7
+ * - Detects missing packages using dynamic `import()` (avoids createRequire / CJS).
8
+ * - Skips automatic install in CI by default; set H56_FORCE_POSTINSTALL=1 to override.
9
+ * - Uses spawnSync to run npm install and keeps the script resilient (won't throw on failure).
10
+ *
11
+ */
6
12
 
7
13
  import { spawnSync } from "child_process";
8
- import { createRequire } from "module";
14
+ import path from "path";
15
+ import { fileURLToPath } from "url";
9
16
 
10
- const require = createRequire(import.meta.url);
17
+ const __filename = fileURLToPath(import.meta.url);
18
+ const __dirname = path.dirname(__filename);
11
19
 
12
20
  const optionalDeps = ["h56-translator"];
13
21
 
14
- function isInstalled(name) {
22
+ /**
23
+ * Check whether a package is resolvable via dynamic import.
24
+ * Uses import() which will attempt to load the package; this is the most portable
25
+ * ESM-compatible way to test presence without using CJS helpers.
26
+ *
27
+ * We deliberately avoid `require.resolve` / createRequire to keep file pure ESM.
28
+ */
29
+ async function isInstalled(name) {
15
30
  try {
16
- require.resolve(name);
31
+ // dynamic import of a bare specifier will resolve via Node's resolver
32
+ await import(name);
17
33
  return true;
18
- } catch (_) {
34
+ } catch (err) {
35
+ // import failed => treat as missing
19
36
  return false;
20
37
  }
21
38
  }
22
39
 
40
+ /**
41
+ * Run npm install for the given list of packages (synchronous to keep postinstall simple).
42
+ */
23
43
  function installDeps(deps) {
24
- if (!deps.length) return;
44
+ if (!deps || deps.length === 0) return;
25
45
  const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm";
26
46
  const args = ["install", "--no-audit", "--no-fund", "--save", ...deps];
27
- console.log("Installing optional dependencies:", deps.join(", "));
28
- const res = spawnSync(npmCmd, args, { stdio: "inherit" });
47
+ console.log(`Installing optional dependencies: ${deps.join(", ")}`);
48
+ const res = spawnSync(npmCmd, args, { stdio: "inherit", shell: false, cwd: process.cwd() });
29
49
  if (res.error || res.status !== 0) {
30
- console.error("Failed to install optional dependencies. You can run manually:");
50
+ console.error("Failed to install optional dependencies automatically. Please run manually:");
31
51
  console.error(" npm install " + deps.join(" "));
32
- // do not throw to keep npm install resilient
52
+ // keep postinstall resilient: do not throw/exit non-zero to avoid breaking npm install
33
53
  } else {
34
54
  console.log("Optional dependencies installed.");
35
55
  }
36
56
  }
37
57
 
38
- (function main() {
58
+ async function main() {
39
59
  try {
40
- const toInstall = optionalDeps.filter((d) => !isInstalled(d));
41
- if (toInstall.length === 0) return;
60
+ const toInstall = [];
61
+ for (const dep of optionalDeps) {
62
+ const present = await isInstalled(dep);
63
+ if (!present) toInstall.push(dep);
64
+ }
42
65
 
43
- // Skip auto-install in CI by default to avoid surprises; allow override.
66
+ if (toInstall.length === 0) {
67
+ // nothing to do
68
+ // console.log("All optional dependencies present.");
69
+ return;
70
+ }
71
+
72
+ // Safety: skip auto-install in CI unless explicitly forced
44
73
  if (process.env.CI && !process.env.H56_FORCE_POSTINSTALL) {
45
74
  console.log(
46
75
  "CI environment detected — skipping automatic installation of optional dependencies.",
@@ -51,7 +80,9 @@ function installDeps(deps) {
51
80
 
52
81
  installDeps(toInstall);
53
82
  } catch (err) {
83
+ // Keep postinstall resilient; log error but don't fail the install process.
54
84
  console.error("Postinstall check encountered an error:", err && err.message ? err.message : err);
55
- // do not exit non-zero; keep postinstall resilient
56
85
  }
57
- })();
86
+ }
87
+
88
+ await main();