Skip to content

Commit

Permalink
Fix mocked paths in manager (#1448)
Browse files Browse the repository at this point in the history
  • Loading branch information
CompuIves authored Jan 20, 2019
1 parent 1303c50 commit 22b46fe
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/app/src/sandbox/eval/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ const SHIMMED_MODULE: Module = {
code: `// empty`,
requires: [],
};

const getShimmedModuleFromPath = (currentPath: string, path: string) => ({
...SHIMMED_MODULE,
path: pathUtils.join(pathUtils.dirname(currentPath), path),
});
const debug = _debug('cs:compiler:manager');

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

if (NODE_LIBS.includes(shimmedPath)) {
this.cachedPaths[dirredPath][path] = shimmedPath;
return SHIMMED_MODULE;
return getShimmedModuleFromPath(currentPath, path);
}

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

if (foundPath === '//empty.js') {
promiseResolve(SHIMMED_MODULE);
promiseResolve(getShimmedModuleFromPath(currentPath, path));
return;
}

if (!this.transpiledModules[foundPath]) {
Expand Down Expand Up @@ -641,6 +647,7 @@ export default class Manager {
}
}
}
promiseResolve(this.transpiledModules[resolvedPath].module);
});
}

Expand Down Expand Up @@ -672,7 +679,7 @@ export default class Manager {

if (NODE_LIBS.includes(shimmedPath)) {
this.cachedPaths[dirredPath][path] = shimmedPath;
return SHIMMED_MODULE;
return getShimmedModuleFromPath(currentPath, path);
}

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

if (resolvedPath === '//empty.js') {
return SHIMMED_MODULE;
return getShimmedModuleFromPath(currentPath, path);
}

if (!this.transpiledModules[resolvedPath]) {
Expand Down Expand Up @@ -735,7 +742,7 @@ export default class Manager {
}

if (resolvedPath === '//empty.js') {
return SHIMMED_MODULE;
return getShimmedModuleFromPath(currentPath, path);
}

return this.transpiledModules[resolvedPath].module;
Expand Down

0 comments on commit 22b46fe

Please sign in to comment.