Skip to content

Commit 933eb7a

Browse files
refactor: remove unused source map logic (#10)
1 parent 625e6c3 commit 933eb7a

File tree

5 files changed

+7
-34
lines changed

5 files changed

+7
-34
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
},
3333
"./esm": "./dist/esm/index.mjs",
3434
"./cli": "./dist/cli.mjs",
35-
"./source-map": "./dist/source-map.cjs",
3635
"./suppress-warnings": "./dist/suppress-warnings.cjs",
3736
"./preflight": "./dist/preflight.cjs",
3837
"./repl": "./dist/repl.mjs"

src/esm/api/register.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import module from 'node:module';
2-
import { installSourceMapSupport } from '../../source-map.js';
32

43
export const register = () => {
5-
installSourceMapSupport();
4+
process.setSourceMapsEnabled(true);
65

76
module.register(
87
'./index.mjs',

src/esm/hook/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export const initialize: InitializeHook = async (data) => {
1111
* but it shares a closure with the new load hook
1212
*/
1313
export const globalPreload: GlobalPreloadHook = () => `
14-
const require = getBuiltin('module').createRequire("${import.meta.url}");
15-
require('../source-map.cjs').installSourceMapSupport();
14+
const require = getBuiltin('module').createRequire('${import.meta.url}');
15+
process.setSourceMapsEnabled(true);
1616
`;
1717

1818
export { load } from './load.js';

src/esm/hook/load.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { LoadHook } from 'node:module';
33
import type { TransformOptions } from 'esbuild';
44
import { transform } from '../../utils/transform/index.js';
55
import { transformDynamicImport } from '../../utils/transform/transform-dynamic-import.js';
6-
import { installSourceMapSupport } from '../../source-map.js';
6+
import { inlineSourceMap } from '../../source-map.js';
77
import { isFeatureSupported, importAttributes } from '../../utils/node-features.js';
88
import { parent } from '../../utils/ipc/client.js';
99
import {
@@ -12,7 +12,7 @@ import {
1212
isJsonPattern,
1313
} from './utils.js';
1414

15-
const applySourceMap = installSourceMapSupport();
15+
process.setSourceMapsEnabled(true);
1616

1717
const contextAttributesProperty = (
1818
isFeatureSupported(importAttributes)
@@ -69,14 +69,14 @@ export const load: LoadHook = async (
6969

7070
return {
7171
format: 'module',
72-
source: applySourceMap(transformed),
72+
source: inlineSourceMap(transformed),
7373
};
7474
}
7575

7676
if (loaded.format === 'module') {
7777
const dynamicImportTransformed = transformDynamicImport(filePath, code);
7878
if (dynamicImportTransformed) {
79-
loaded.source = applySourceMap(dynamicImportTransformed);
79+
loaded.source = inlineSourceMap(dynamicImportTransformed);
8080
}
8181
}
8282

src/source-map.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,3 @@ export const inlineSourceMap = (
1212
+ inlineSourceMapPrefix
1313
+ Buffer.from(JSON.stringify(map), 'utf8').toString('base64')
1414
);
15-
16-
const noSourceMap = ({ code }: Transformed) => code;
17-
18-
export const installSourceMapSupport = () => {
19-
/**
20-
* Check if native source maps are supported by seeing if the API is available
21-
* https://nodejs.org/dist/latest-v18.x/docs/api/process.html#processsetsourcemapsenabledval
22-
*
23-
* Previously, we also checked Error.prepareStackTrace to opt-out of source maps
24-
* as per this recommendation:
25-
* https://nodejs.org/dist/latest-v18.x/docs/api/cli.html#:~:text=Overriding%20Error.prepareStackTrace%20prevents%20%2D%2Denable%2Dsource%2Dmaps%20from%20modifying%20the%20stack%20trace.
26-
*
27-
* But it's been removed because:
28-
* 1. It's set by default from Node v21.6.0 and v20.12.0
29-
* 2. It may have been possible for a custom prepareStackTrace to parse the source maps
30-
*/
31-
const hasNativeSourceMapSupport = 'setSourceMapsEnabled' in process;
32-
33-
if (hasNativeSourceMapSupport) {
34-
process.setSourceMapsEnabled(true);
35-
return inlineSourceMap;
36-
}
37-
38-
return noSourceMap;
39-
};

0 commit comments

Comments
 (0)