Skip to content

Commit 37a9e99

Browse files
fix: Set source maps support via API (#181)
`env` on different systems behaves differently. On macOS, `env ABC XYZ` will invoke ABC with argument XYZ. On some Linux variants, you need `env -S ABC XYZ` for that. On Alpine, the `-S` flag is not supported, and there is seemingly no way of passing arguments. So this patch undoes the accidental breakage in #179 and uses the `getSourceMapsSupport` API. Technically, both `process.setSourceMapsEnabled` and `module.setSourceMapsSupport` are experimental functions, so to be safe, we do a dynamic existence check before calling them for portability across Node versions.
1 parent cb9c7be commit 37a9e99

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

packages/pyright-scip/index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1-
#!/usr/bin/env node --enable-source-maps
1+
#!/usr/bin/env node
22
/* eslint-disable @typescript-eslint/ban-ts-comment */
33
// @ts-nocheck
44

5+
// Both source map APIs are marked experimental as of Aug 8 2025, so we use dynamic checks
6+
// instead of calling them unconditionally to avoid crashes on unsupported Node.js versions.
7+
// Prefer the recommended module.setSourceMapsSupport() API for newer Node versions (Node.js 23.7.0+, 22.14.0+)
8+
// Fall back to process.setSourceMapsEnabled() for older Node versions (Node.js 16.6.0+, 14.18.0+)
9+
if (typeof module.setSourceMapsSupport === 'function') {
10+
module.setSourceMapsSupport({ nodeModules: true, generatedCode: true });
11+
} else if (typeof process.setSourceMapsEnabled === 'function') {
12+
process.setSourceMapsEnabled(true);
13+
} else {
14+
// Check if source maps are already enabled via NODE_OPTIONS
15+
const nodeOptions = process.env.NODE_OPTIONS || '';
16+
if (!nodeOptions.includes('--enable-source-maps')) {
17+
if (nodeOptions) {
18+
console.warn('Source maps support not available. Consider adding --enable-source-maps to the existing NODE_OPTIONS environment variable.');
19+
} else {
20+
console.warn('Source maps support not available. Consider setting the NODE_OPTIONS environment variable to "--enable-source-maps".');
21+
}
22+
}
23+
}
24+
525
// Stash the base directory into a global variable.
626
global.__rootDirectory = __dirname + '/dist/';
727

0 commit comments

Comments
 (0)