Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: source maps in Node v21.6.0+ & v20.12.0+ #518

Merged
merged 13 commits into from
Apr 4, 2024
3 changes: 2 additions & 1 deletion src/source-map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Transformed } from './utils/transform/apply-transformers.js';
import { isFeatureSupported, prepareStackTraceWithSourcemap } from './utils/node-features.js';

const inlineSourceMapPrefix = '\n//# sourceMappingURL=data:application/json;base64,';

Expand All @@ -18,7 +19,7 @@ export const installSourceMapSupport = () => {
*
* https://github.com/nodejs/node/blob/91193825551f9301b6ab52d96211b38889149892/lib/internal/errors.js#L141
*/
&& typeof Error.prepareStackTrace !== 'function'
&& (isFeatureSupported(prepareStackTraceWithSourcemap) || typeof Error.prepareStackTrace !== 'function')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

);

if (hasNativeSourceMapSupport) {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/node-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ export const importAttributes: Version[] = [
export const testRunnerGlob: Version[] = [
[21, 0, 0],
];

// https://nodejs.org/docs/latest-v20.x/api/cli.html#--enable-source-maps
// https://github.com/nodejs/node/pull/50827
// Allow using --enable-source-maps together with custom Error.prepareStackTrace
export const prepareStackTraceWithSourcemap: Version[] = [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const prepareStackTraceWithSourcemap: Version[] = [
export const prepareStackTraceExposed: Version[] = [

[20, 12, 0],
Copy link
Owner

@privatenumber privatenumber Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

];