wstp-node 0.4.4 → 0.4.6

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": "wstp-node",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "Native Node.js addon for Wolfram/Mathematica WSTP — kernel sessions with evaluation queue, streaming Print/messages, Dialog subsessions, and side-channel WstpReader",
5
5
  "main": "build/Release/wstp.node",
6
6
  "types": "index.d.ts",
@@ -30,6 +30,7 @@
30
30
  "src/addon.cc",
31
31
  "scripts/wstp_dir.js",
32
32
  "scripts/install.js",
33
+ "scripts/diagnose-windows.ps1",
33
34
  "build.sh",
34
35
  "binding.gyp",
35
36
  "index.d.ts",
@@ -0,0 +1,60 @@
1
+ # diagnose-windows.ps1
2
+ # Run this in PowerShell to find the WSTP DeveloperKit on your Windows machine.
3
+ # It searches for the two files that wstp-node needs:
4
+ # wstp.h (C header)
5
+ # wstp64i4s.lib (static import library)
6
+ #
7
+ # Usage:
8
+ # powershell -ExecutionPolicy Bypass -File diagnose-windows.ps1
9
+
10
+ Write-Host "`n=== Searching for WSTP DeveloperKit files ===`n" -ForegroundColor Cyan
11
+
12
+ $files = @("wstp.h", "wstp64i4s.lib")
13
+ $searchRoots = @(
14
+ "C:\Program Files\Wolfram Research",
15
+ "C:\Program Files (x86)\Wolfram Research",
16
+ "$env:LOCALAPPDATA\Programs\Wolfram Research",
17
+ "C:\Program Files\Wolfram Research\Mathematica",
18
+ "C:\Program Files\Wolfram Research\Wolfram Engine"
19
+ ) | Where-Object { (Test-Path $_) -and -not (Test-Path (Join-Path $_ "wsl.exe")) }
20
+
21
+ $found = @{}
22
+
23
+ foreach ($root in $searchRoots) {
24
+ if (-not (Test-Path $root)) { continue }
25
+ Write-Host "Searching under: $root" -ForegroundColor Gray
26
+ foreach ($file in $files) {
27
+ $results = Get-ChildItem -Path $root -Filter $file -Recurse -ErrorAction SilentlyContinue
28
+ foreach ($r in $results) {
29
+ Write-Host " FOUND $file at: $($r.FullName)" -ForegroundColor Green
30
+ $found[$file] = $r.DirectoryName
31
+ }
32
+ }
33
+ }
34
+
35
+ Write-Host ""
36
+
37
+ if ($found.Count -eq 0) {
38
+ Write-Host "Neither wstp.h nor wstp64i4s.lib found." -ForegroundColor Red
39
+ Write-Host "Make sure Wolfram Engine or Mathematica is installed."
40
+ exit 1
41
+ }
42
+
43
+ # If both are in the same directory, suggest WSTP_DIR
44
+ $dirs = $found.Values | Sort-Object -Unique
45
+ if ($dirs.Count -eq 1) {
46
+ $dir = $dirs[0]
47
+ Write-Host "Both files are in:" -ForegroundColor Cyan
48
+ Write-Host " $dir" -ForegroundColor Yellow
49
+ Write-Host ""
50
+ Write-Host "Run this before npm install:" -ForegroundColor Cyan
51
+ Write-Host " `$env:WSTP_DIR = `"$dir`"" -ForegroundColor Yellow
52
+ Write-Host " npm install" -ForegroundColor Yellow
53
+ } else {
54
+ Write-Host "Files found in different directories — use the directory containing both:" -ForegroundColor Yellow
55
+ foreach ($kv in $found.GetEnumerator()) {
56
+ Write-Host " $($kv.Key) => $($kv.Value)"
57
+ }
58
+ Write-Host ""
59
+ Write-Host "Set WSTP_DIR to the folder containing both files, then run npm install."
60
+ }
@@ -22,59 +22,90 @@ function resolve () {
22
22
 
23
23
  // ── 2. Windows ──────────────────────────────────────────────────────────
24
24
  if (process.platform === 'win32') {
25
- const base = process.env.PROGRAMFILES || 'C:\\Program Files';
25
+ const pf = process.env.PROGRAMFILES || 'C:\\Program Files';
26
+ const pf86 = process.env['PROGRAMFILES(X86)'] || 'C:\\Program Files (x86)';
27
+ const local = process.env.LOCALAPPDATA || '';
26
28
 
27
- // Wolfram products to try, in priority order
28
- const products = [
29
- 'Wolfram Research\\Wolfram Engine',
30
- 'Wolfram Research\\Mathematica',
31
- 'Wolfram Research\\WolframEngine',
32
- ];
29
+ // All candidate root directories to search under
30
+ const searchRoots = [
31
+ path.join(pf, 'Wolfram Research'),
32
+ path.join(pf86, 'Wolfram Research'),
33
+ local ? path.join(local, 'Programs', 'Wolfram Research') : null,
34
+ ].filter(Boolean);
33
35
 
34
- for (const product of products) {
35
- const productDir = path.join(base, product);
36
- let entries;
37
- try { entries = fs.readdirSync(productDir); } catch (e) { continue; }
38
-
39
- // Find version subfolders (e.g. "14.2", "13.1") any dir starting with a digit
40
- const versions = entries
41
- .filter(d => {
42
- if (!/^\d/.test(d)) return false;
43
- try { return fs.statSync(path.join(productDir, d)).isDirectory(); } catch (e) { return false; }
44
- })
45
- .sort()
46
- .reverse();
47
-
48
- if (!versions.length) {
49
- // Help diagnose: show what IS there
50
- process.stderr.write(
51
- `wstp_dir: found "${productDir}" but no version subfolder.\n` +
52
- ` Contents: ${entries.join(', ') || '(empty)'}\n`
53
- );
54
- continue;
55
- }
36
+ // Product subfolder names to try
37
+ const productNames = ['Mathematica', 'Wolfram Engine', 'WolframEngine'];
38
+
39
+ for (const root of searchRoots) {
40
+ let rootEntries;
41
+ try { rootEntries = fs.readdirSync(root); } catch (e) { continue; }
42
+
43
+ for (const product of productNames) {
44
+ const productDir = path.join(root, product);
45
+ let entries;
46
+ try { entries = fs.readdirSync(productDir); } catch (e) { continue; }
47
+
48
+ // Skip if this looks like WSL rather than a Wolfram product
49
+ if (entries.includes('wsl.exe') || entries.includes('wslservice.exe')) {
50
+ process.stderr.write(
51
+ `wstp_dir: skipping "${productDir}" looks like WSL, not Wolfram\n`
52
+ );
53
+ continue;
54
+ }
56
55
 
57
- const wstp = path.join(
58
- productDir, versions[0],
59
- 'SystemFiles', 'Links', 'WSTP', 'DeveloperKit',
60
- 'Windows-x86-64', 'CompilerAdditions'
61
- );
62
- if (!fs.existsSync(path.join(wstp, 'wstp.h')) &&
63
- !fs.existsSync(path.join(wstp, 'wstp64i4s.lib'))) {
64
- process.stderr.write(
65
- `wstp_dir: WSTP DeveloperKit not found at expected path:\n ${wstp}\n`
56
+ // Find version subfolders (e.g. "14.2", "13.1") — dirs starting with a digit
57
+ const versions = entries
58
+ .filter(d => {
59
+ if (!/^\d/.test(d)) return false;
60
+ try { return fs.statSync(path.join(productDir, d)).isDirectory(); } catch (e) { return false; }
61
+ })
62
+ .sort()
63
+ .reverse();
64
+
65
+ if (!versions.length) {
66
+ process.stderr.write(
67
+ `wstp_dir: "${productDir}" has no version subfolder — skipping\n` +
68
+ ` Contents: ${entries.join(', ')}\n`
69
+ );
70
+ continue;
71
+ }
72
+
73
+ const wstp = path.join(
74
+ productDir, versions[0],
75
+ 'SystemFiles', 'Links', 'WSTP', 'DeveloperKit',
76
+ 'Windows-x86-64', 'CompilerAdditions'
66
77
  );
67
- continue;
78
+
79
+ const hasHeader = fs.existsSync(path.join(wstp, 'wstp.h'));
80
+ const hasLib = fs.existsSync(path.join(wstp, 'wstp64i4s.lib'));
81
+
82
+ if (!hasHeader || !hasLib) {
83
+ process.stderr.write(
84
+ `wstp_dir: found version "${versions[0]}" but WSTP DeveloperKit missing.\n` +
85
+ ` Expected both files inside:\n` +
86
+ ` ${wstp}\n` +
87
+ ` wstp.h (C header) — ${hasHeader ? 'FOUND' : 'MISSING'}\n` +
88
+ ` wstp64i4s.lib (import lib) — ${hasLib ? 'FOUND' : 'MISSING'}\n`
89
+ );
90
+ continue;
91
+ }
92
+
93
+ return wstp;
68
94
  }
69
- return wstp;
70
95
  }
71
96
 
72
97
  throw new Error(
73
- `WSTP DeveloperKit not found.\n` +
74
- `Tried under "${base}" for: ${products.join(', ')}\n\n` +
75
- `Set WSTP_DIR to your CompilerAdditions folder, e.g.:\n` +
76
- ` set WSTP_DIR=C:\\Program Files\\Wolfram Research\\Wolfram Engine\\14.2\\SystemFiles\\Links\\WSTP\\DeveloperKit\\Windows-x86-64\\CompilerAdditions\n` +
77
- `then run npm install again.`
98
+ `WSTP DeveloperKit not found on Windows.\n\n` +
99
+ `The build requires two files from the Wolfram Engine / Mathematica installation:\n` +
100
+ ` wstp.h (C header)\n` +
101
+ ` wstp64i4s.lib (static import library)\n\n` +
102
+ `These live inside:\n` +
103
+ ` <WolframEngine>\\<version>\\SystemFiles\\Links\\WSTP\\DeveloperKit\\Windows-x86-64\\CompilerAdditions\\\n\n` +
104
+ `Run the diagnostic to find them:\n` +
105
+ ` powershell -ExecutionPolicy Bypass -File scripts\\diagnose-windows.ps1\n\n` +
106
+ `Then set WSTP_DIR and retry:\n` +
107
+ ` set WSTP_DIR=<path shown above>\n` +
108
+ ` npm install`
78
109
  );
79
110
  }
80
111