wstp-node 0.4.5 → 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.5",
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",
@@ -13,8 +13,10 @@ $files = @("wstp.h", "wstp64i4s.lib")
13
13
  $searchRoots = @(
14
14
  "C:\Program Files\Wolfram Research",
15
15
  "C:\Program Files (x86)\Wolfram Research",
16
- "$env:LOCALAPPDATA\Programs\Wolfram Research"
17
- )
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")) }
18
20
 
19
21
  $found = @{}
20
22
 
@@ -22,67 +22,89 @@ 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: found version "${versions[0]}" but WSTP DeveloperKit missing.\n` +
66
- ` Expected these files inside:\n` +
67
- ` ${wstp}\n` +
68
- ` wstp.h (C header)\n` +
69
- ` wstp64i4s.lib (static import library)\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'
70
77
  );
71
- 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;
72
94
  }
73
- return wstp;
74
95
  }
75
96
 
76
97
  throw new Error(
77
- `WSTP DeveloperKit not found.\n` +
78
- `Searched under "${base}" for: ${products.join(', ')}\n\n` +
79
- `The build needs these two files:\n` +
98
+ `WSTP DeveloperKit not found on Windows.\n\n` +
99
+ `The build requires two files from the Wolfram Engine / Mathematica installation:\n` +
80
100
  ` wstp.h (C header)\n` +
81
101
  ` wstp64i4s.lib (static import library)\n\n` +
82
- `Run the diagnostic script to find them:\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` +
83
105
  ` powershell -ExecutionPolicy Bypass -File scripts\\diagnose-windows.ps1\n\n` +
84
- `Then set WSTP_DIR to the folder containing both files and retry:\n` +
85
- ` set WSTP_DIR=C:\\Program Files\\Wolfram Research\\Wolfram Engine\\14.2\\SystemFiles\\Links\\WSTP\\DeveloperKit\\Windows-x86-64\\CompilerAdditions\n` +
106
+ `Then set WSTP_DIR and retry:\n` +
107
+ ` set WSTP_DIR=<path shown above>\n` +
86
108
  ` npm install`
87
109
  );
88
110
  }