Skip to content

Commit 5001e4c

Browse files
committed
loader: lazy-load source map cache in CJS loader
1 parent 8ccbe8e commit 5001e4c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ module.exports = {
132132
};
133133

134134
const { BuiltinModule } = require('internal/bootstrap/realm');
135-
const {
136-
maybeCacheSourceMap,
137-
} = require('internal/source_map/source_map_cache');
138135
const { pathToFileURL, fileURLToPath, isURL, URL } = require('internal/url');
139136
const {
140137
pendingDeprecate,
@@ -220,6 +217,8 @@ let { startTimer, endTimer } = debugWithTimer('module_timer', (start, end) => {
220217
endTimer = end;
221218
});
222219

220+
const lazyMaybeCacheSourceMap = getLazy(() =>
221+
require('internal/source_map/source_map_cache').maybeCacheSourceMap);
223222
const { tracingChannel } = require('diagnostics_channel');
224223
const onRequire = getLazy(() => tracingChannel('module.require'));
225224

@@ -1738,7 +1737,7 @@ function wrapSafe(filename, content, cjsModuleInstance, format) {
17381737
// Cache the source map for the module if present.
17391738
const { sourceMapURL, sourceURL } = script;
17401739
if (sourceMapURL) {
1741-
maybeCacheSourceMap(filename, content, cjsModuleInstance, false, sourceURL, sourceMapURL);
1740+
lazyMaybeCacheSourceMap()(filename, content, cjsModuleInstance, false, sourceURL, sourceMapURL);
17421741
}
17431742

17441743
return {
@@ -1763,7 +1762,7 @@ function wrapSafe(filename, content, cjsModuleInstance, format) {
17631762

17641763
// Cache the source map for the module if present.
17651764
if (result.sourceMapURL) {
1766-
maybeCacheSourceMap(filename, content, cjsModuleInstance, false, result.sourceURL, result.sourceMapURL);
1765+
lazyMaybeCacheSourceMap()(filename, content, cjsModuleInstance, false, result.sourceURL, result.sourceMapURL);
17671766
}
17681767

17691768
return result;

0 commit comments

Comments
 (0)