Skip to content

Commit 3966f59

Browse files
committed
Fix @babel/runtime direct requires to node_modules
We now check if node_modules is directly mentioned, only prepend it if it's not there yet. Fixes codesandbox#1264
1 parent a61bb76 commit 3966f59

File tree

2 files changed

+3180
-5288
lines changed

2 files changed

+3180
-5288
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,12 @@ export default class Manager {
614614
delete this.cachedPaths[dirredPath][path];
615615
}
616616

617-
let connectedPath = /^(\w|@\w)/.test(shimmedPath)
618-
? pathUtils.join('/node_modules', shimmedPath)
619-
: pathUtils.join(pathUtils.dirname(currentPath), shimmedPath);
617+
let connectedPath = shimmedPath;
618+
if (connectedPath.indexOf('/node_modules') !== 0) {
619+
connectedPath = /^(\w|@\w)/.test(shimmedPath)
620+
? pathUtils.join('/node_modules', shimmedPath)
621+
: pathUtils.join(pathUtils.dirname(currentPath), shimmedPath);
622+
}
620623

621624
const isDependency = connectedPath.includes('/node_modules/');
622625

@@ -694,16 +697,20 @@ export default class Manager {
694697
throw new Error(`Could not find '${resolvedPath}' in local files.`);
695698
}
696699
} catch (e) {
700+
// MAKE SURE TO SYNC THIS WITH ASYNC VERSION
697701
if (
698702
this.cachedPaths[dirredPath] &&
699703
this.cachedPaths[dirredPath][path]
700704
) {
701705
delete this.cachedPaths[dirredPath][path];
702706
}
703707

704-
let connectedPath = /^(\w|@\w)/.test(shimmedPath)
705-
? pathUtils.join('/node_modules', shimmedPath)
706-
: pathUtils.join(pathUtils.dirname(currentPath), shimmedPath);
708+
let connectedPath = shimmedPath;
709+
if (connectedPath.indexOf('/node_modules') !== 0) {
710+
connectedPath = /^(\w|@\w)/.test(shimmedPath)
711+
? pathUtils.join('/node_modules', shimmedPath)
712+
: pathUtils.join(pathUtils.dirname(currentPath), shimmedPath);
713+
}
707714

708715
const isDependency = connectedPath.includes('/node_modules/');
709716

0 commit comments

Comments
 (0)