Skip to content

Commit 22b46fe

Browse files
authored
Fix mocked paths in manager (codesandbox#1448)
1 parent 1303c50 commit 22b46fe

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/app/src/sandbox/eval/manager.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ const SHIMMED_MODULE: Module = {
7474
code: `// empty`,
7575
requires: [],
7676
};
77+
78+
const getShimmedModuleFromPath = (currentPath: string, path: string) => ({
79+
...SHIMMED_MODULE,
80+
path: pathUtils.join(pathUtils.dirname(currentPath), path),
81+
});
7782
const debug = _debug('cs:compiler:manager');
7883

7984
type HMRStatus = 'idle' | 'check' | 'apply' | 'fail' | 'dispose';
@@ -568,7 +573,7 @@ export default class Manager {
568573

569574
if (NODE_LIBS.includes(shimmedPath)) {
570575
this.cachedPaths[dirredPath][path] = shimmedPath;
571-
return SHIMMED_MODULE;
576+
return getShimmedModuleFromPath(currentPath, path);
572577
}
573578

574579
try {
@@ -593,7 +598,8 @@ export default class Manager {
593598
this.cachedPaths[dirredPath][path] = foundPath;
594599

595600
if (foundPath === '//empty.js') {
596-
promiseResolve(SHIMMED_MODULE);
601+
promiseResolve(getShimmedModuleFromPath(currentPath, path));
602+
return;
597603
}
598604

599605
if (!this.transpiledModules[foundPath]) {
@@ -641,6 +647,7 @@ export default class Manager {
641647
}
642648
}
643649
}
650+
promiseResolve(this.transpiledModules[resolvedPath].module);
644651
});
645652
}
646653

@@ -672,7 +679,7 @@ export default class Manager {
672679

673680
if (NODE_LIBS.includes(shimmedPath)) {
674681
this.cachedPaths[dirredPath][path] = shimmedPath;
675-
return SHIMMED_MODULE;
682+
return getShimmedModuleFromPath(currentPath, path);
676683
}
677684

678685
try {
@@ -690,7 +697,7 @@ export default class Manager {
690697
this.cachedPaths[dirredPath][path] = resolvedPath;
691698

692699
if (resolvedPath === '//empty.js') {
693-
return SHIMMED_MODULE;
700+
return getShimmedModuleFromPath(currentPath, path);
694701
}
695702

696703
if (!this.transpiledModules[resolvedPath]) {
@@ -735,7 +742,7 @@ export default class Manager {
735742
}
736743

737744
if (resolvedPath === '//empty.js') {
738-
return SHIMMED_MODULE;
745+
return getShimmedModuleFromPath(currentPath, path);
739746
}
740747

741748
return this.transpiledModules[resolvedPath].module;

0 commit comments

Comments
 (0)