Skip to content

Commit 20e9928

Browse files
committed
Fix error overlay and sass resolving
1 parent e45dad5 commit 20e9928

File tree

9 files changed

+22
-17
lines changed

9 files changed

+22
-17
lines changed

packages/app/src/sandbox/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { absolute } from 'common/utils/path';
33
import _debug from 'app/utils/debug';
44
import parseConfigurations from 'common/templates/configuration/parse';
55
import initializeErrorTransformers from 'sandbox-hooks/errors/transformers';
6+
import { inject, unmount } from 'sandbox-hooks/react-error-overlay/overlay';
67

78
import getPreset from './eval';
89
import Manager from './eval/manager';
910

1011
import { resetScreen } from './status-screen';
1112

12-
import { inject, unmount } from 'sandbox-hooks/react-error-overlay/overlay';
1313
import createCodeSandboxOverlay from './codesandbox-overlay';
1414
import handleExternalResources from './external-resources';
1515

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ export default class Manager {
540540

541541
const dependencyName = getDependencyName(connectedPath);
542542

543+
// TODO: fix the stack hack
543544
if (
544545
this.manifest.dependencies.find(d => d.name === dependencyName) ||
545546
this.manifest.dependencyDependencies[dependencyName]
@@ -579,16 +580,22 @@ export default class Manager {
579580

580581
resolveTranspiledModuleAsync = (
581582
path: string,
582-
currentPath: string,
583+
currentTModule: ?TranspiledModule,
583584
ignoredExtensions?: Array<string>
584585
): Promise<TranspiledModule> => {
586+
const tModule =
587+
currentTModule || this.getTranspiledModule(this.modules['/package.json']); // Get arbitrary file from root
585588
try {
586589
return Promise.resolve(
587-
this.resolveTranspiledModule(path, currentPath, ignoredExtensions)
590+
this.resolveTranspiledModule(
591+
path,
592+
tModule.module.path,
593+
ignoredExtensions
594+
)
588595
);
589596
} catch (e) {
590597
if (e.type === 'module-not-found' && e.isDependency) {
591-
return this.downloadDependency(e.path, currentPath, ignoredExtensions);
598+
return this.downloadDependency(e.path, tModule, ignoredExtensions);
592599
}
593600

594601
throw e;

packages/app/src/sandbox/eval/presets/angular-cli/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async function addAngularJSONResources(manager) {
6767

6868
const tModule = await manager.resolveTranspiledModuleAsync(
6969
finalPath,
70-
'/'
70+
null
7171
);
7272

7373
await tModule.transpile(manager);
@@ -80,7 +80,7 @@ async function addAngularJSONResources(manager) {
8080
const finalPath = absolute(join(project.root, p));
8181
const tModule = await manager.resolveTranspiledModuleAsync(
8282
finalPath,
83-
'/'
83+
null
8484
);
8585
tModule.setIsEntry(true);
8686
return tModule.transpile(manager);
@@ -107,7 +107,7 @@ async function addAngularCLIResources(manager) {
107107

108108
const tModule = await manager.resolveTranspiledModuleAsync(
109109
finalPath,
110-
'/'
110+
null
111111
);
112112

113113
await tModule.transpile(manager);
@@ -121,7 +121,7 @@ async function addAngularCLIResources(manager) {
121121
const finalPath = absolute(join(app.root || 'src', p));
122122
const tModule = await manager.resolveTranspiledModuleAsync(
123123
finalPath,
124-
'/'
124+
null
125125
);
126126
tModule.setIsEntry(true);
127127
return tModule.transpile(manager);

packages/app/src/sandbox/eval/presets/dojo/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ export default function initialize() {
1616
{
1717
setup: async manager => {
1818
const stylesPath = absolute(join('src', 'main.css'));
19+
1920
try {
2021
const tModule = await manager.resolveTranspiledModuleAsync(
2122
stylesPath,
22-
'/'
23+
null
2324
);
2425
await tModule.transpile(manager);
2526
tModule.setIsEntry(true);

packages/app/src/sandbox/eval/transpiled-module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ export default class TranspiledModule {
461461
resolveTranspiledModuleAsync: (depPath: string, options = {}) =>
462462
manager.resolveTranspiledModuleAsync(
463463
depPath,
464-
options.isAbsolute ? '/' : this.module.path,
464+
options.isAbsolute ? null : this,
465465
options.ignoredExtensions
466466
),
467467
getModules: (): Array<Module> => manager.getModules(),

packages/app/src/sandbox/eval/transpilers/sass/worker/sass-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const resolveAsyncModule = (
2424
{ ignoredExtensions }?: { ignoredExtensions?: Array<string> }
2525
) =>
2626
new Promise((r, reject) => {
27-
const sendId = Math.random() * 10000;
27+
const sendId = Math.floor(Math.random() * 10000);
2828
self.postMessage({
2929
type: 'resolve-async-transpiled-module',
3030
path,

packages/app/src/sandbox/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ requirePolyfills().then(() => {
7878
sendReady();
7979

8080
setupHistoryListeners();
81-
setupConsole();
81+
// setupConsole();
8282
}
8383

8484
if (process.env.NODE_ENV === 'test' || isStandalone) {

packages/sandbox-hooks/.babelrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/sandbox-hooks/errors/sandbox-error.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ type Suggestion = {
55
title: string,
66
action: Function,
77
};
8+
const ErrorClass = Error;
89

9-
export default class SandboxError extends Error {
10+
export default class SandboxError extends ErrorClass {
1011
severity: 'error' | 'warning';
1112
type: string;
1213
module: Module;

0 commit comments

Comments
 (0)