@lynx-js/lynxtron-rebuild 0.0.5 → 0.0.7

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/index.js +22 -21
  2. package/package.json +2 -1
package/lib/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import { fileURLToPath } from 'node:url';
2
2
  import path from 'node:path';
3
3
  import fs from 'node:fs';
4
- import https from 'node:https';
5
- import { pipeline } from 'node:stream/promises';
6
4
  import { spawn } from 'node:child_process';
7
5
  import { zip } from 'compressing';
6
+ import fetch from 'node-fetch';
8
7
 
9
8
  const __filename = fileURLToPath(import.meta.url);
10
9
  const __dirname = path.dirname(__filename);
@@ -30,22 +29,12 @@ function getLynxtronVersion() {
30
29
  }
31
30
 
32
31
  async function downloadFile(url, destPath) {
33
- return new Promise((resolve, reject) => {
34
- const file = fs.createWriteStream(destPath);
35
- https.get(url, (response) => {
36
- if (response.statusCode !== 200) {
37
- fs.unlink(destPath, () => {});
38
- reject(new Error(`Failed to download ${url}, status: ${response.statusCode}`));
39
- return;
40
- }
41
- pipeline(response, file)
42
- .then(resolve)
43
- .catch(reject);
44
- }).on('error', (err) => {
45
- fs.unlink(destPath, () => {});
46
- reject(err);
47
- });
48
- });
32
+ const response = await fetch(url);
33
+ if (!response.ok) {
34
+ throw new Error(`Failed to download ${url}, status: ${response.status}`);
35
+ }
36
+ const buffer = Buffer.from(await response.arrayBuffer());
37
+ await fs.promises.writeFile(destPath, buffer);
49
38
  }
50
39
 
51
40
  async function extractZip(zipPath, destDir) {
@@ -93,12 +82,24 @@ function findModulesWithNativeCode(buildPath) {
93
82
  const packages = fs.readdirSync(nodeModulesPath, { withFileTypes: true });
94
83
 
95
84
  for (const pkg of packages) {
96
- if (!pkg.isDirectory()) continue;
97
85
  if (pkg.name.startsWith('.')) continue;
98
-
86
+
99
87
  const pkgPath = path.join(nodeModulesPath, pkg.name);
88
+
89
+ // Under pnpm the package entries in node_modules are symlinks into the
90
+ // .pnpm store, so Dirent.isDirectory() (which does NOT follow symlinks)
91
+ // reports false. Use statSync, which follows the link, to get the real
92
+ // type. Skip anything that isn't ultimately a directory.
93
+ let stats;
94
+ try {
95
+ stats = fs.statSync(pkgPath);
96
+ } catch {
97
+ continue; // broken symlink
98
+ }
99
+ if (!stats.isDirectory()) continue;
100
+
100
101
  const bindingGypPath = path.join(pkgPath, 'binding.gyp');
101
-
102
+
102
103
  if (fs.existsSync(bindingGypPath)) {
103
104
  modules.push(pkgPath);
104
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/lynxtron-rebuild",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Rebuild native modules for Lynxtron",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -19,6 +19,7 @@
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
21
  "compressing": "^1.10.0",
22
+ "node-fetch": "^3.3.2",
22
23
  "node-gyp": "^12.2.0"
23
24
  }
24
25
  }