Skip to content

Commit e784aa6

Browse files
committed
refactor: optimize out some /replay code in bundles
1 parent fa5da59 commit e784aa6

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/replay.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,8 @@ function loadReplayBundle() {
1212
}
1313
}
1414

15-
if (process.env.EXODUS_TEST_ENVIRONMENT === 'bundle') {
16-
// eslint-disable-next-line no-undef
17-
const files = EXODUS_TEST_FILES
18-
const baseFile = files.length === 1 ? files[0] : undefined
19-
// eslint-disable-next-line no-undef
20-
const map = new Map(typeof EXODUS_TEST_RECORDINGS === 'undefined' ? [] : EXODUS_TEST_RECORDINGS)
21-
const resolveRecording = (resolver, f) => resolver(f[0], f[1]).join('/')
22-
readRecordingRaw = (resolver) => (baseFile ? map.get(resolveRecording(resolver, baseFile)) : null)
23-
} else {
15+
// Optimized out in 'bundle' env
16+
async function loadNonBundle() {
2417
// Preload if synchronous lazy-loading is unavailable
2518
// TODO: not under process?.features?.require_module
2619
try {
@@ -65,6 +58,18 @@ if (process.env.EXODUS_TEST_ENVIRONMENT === 'bundle') {
6558
}
6659
}
6760

61+
if (process.env.EXODUS_TEST_ENVIRONMENT === 'bundle') {
62+
// eslint-disable-next-line no-undef
63+
const files = EXODUS_TEST_FILES
64+
const baseFile = files.length === 1 ? files[0] : undefined
65+
// eslint-disable-next-line no-undef
66+
const map = new Map(typeof EXODUS_TEST_RECORDINGS === 'undefined' ? [] : EXODUS_TEST_RECORDINGS)
67+
const resolveRecording = (resolver, f) => resolver(f[0], f[1]).join('/')
68+
readRecordingRaw = (resolver) => (baseFile ? map.get(resolveRecording(resolver, baseFile)) : null)
69+
} else {
70+
await loadNonBundle()
71+
}
72+
6873
function readRecording(resolver) {
6974
const data = readRecordingRaw(resolver)
7075
if (typeof data !== 'string') throw new Error('Can not read recording')

0 commit comments

Comments
 (0)