Skip to content

Commit 24c2129

Browse files
authored
* Vue 2.5 * Fix warnings and error api
1 parent 0d005af commit 24c2129

File tree

17 files changed

+321
-181
lines changed

17 files changed

+321
-181
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@
158158
"styled-components": "^2.1.1",
159159
"svg-react-loader": "^0.4.4",
160160
"tern": "^0.21.0",
161-
"vue": "^2.4.2",
162-
"vue-template-compiler": "^2.4.2",
163-
"vue-template-es2015-compiler": "^1.5.3"
161+
"vue": "^2.5.2",
162+
"vue-template-compiler": "^2.5.2",
163+
"vue-template-es2015-compiler": "^1.6.0"
164164
},
165165
"scripts": {
166166
"start": "cross-env LOCAL_SERVER=1 node scripts/start.js",

src/app/store/preview-actions-api/actions.js

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This executes all actions that are requested by the preview
22
import resolveModule from 'common/sandbox/resolve-module';
3+
import _debug from 'debug';
34

45
import notifActions from '../notifications/actions';
56
import moduleActions from '../entities/sandboxes/modules/actions';
@@ -8,8 +9,25 @@ import { modulesFromSandboxSelector } from '../entities/sandboxes/modules/select
89
import { directoriesFromSandboxSelector } from '../entities/sandboxes/directories/selectors';
910
import { singleSandboxSelector } from '../entities/sandboxes/selectors';
1011

12+
const debug = _debug('cs:preview-api');
13+
14+
function getModule(sandboxId: string, path: string, getState: Function) {
15+
const sandbox = singleSandboxSelector(getState(), { id: sandboxId });
16+
const modules = modulesFromSandboxSelector(getState(), { sandbox });
17+
const directories = directoriesFromSandboxSelector(getState(), {
18+
sandbox,
19+
});
20+
21+
try {
22+
return resolveModule(path.replace(/^\//, ''), modules, directories);
23+
} catch (e) {
24+
return null;
25+
}
26+
}
27+
1128
export default {
1229
executeAction: action => async (dispatch: Function, getState: Function) => {
30+
debug('Received new preview action', action);
1331
switch (action.action) {
1432
case 'notification': {
1533
const { title, timeAlive, notificationType } = action;
@@ -18,21 +36,27 @@ export default {
1836
);
1937
}
2038
case 'show-error': {
21-
return dispatch(moduleActions.setError(action.moduleId, action));
39+
const { sandboxId, path } = action;
40+
41+
const module = getModule(sandboxId, path, getState);
42+
if (module) {
43+
return dispatch(moduleActions.setError(module.id, action));
44+
}
45+
return null;
2246
}
2347
case 'show-correction': {
24-
return dispatch(moduleActions.addCorrection(action.moduleId, action));
48+
const { sandboxId, path } = action;
49+
50+
const module = getModule(sandboxId, path, getState);
51+
if (module) {
52+
return dispatch(moduleActions.addCorrection(module.id, action));
53+
}
54+
return null;
2555
}
2656
case 'source.module.rename': {
2757
const { sandboxId, path, title } = action;
2858

29-
const sandbox = singleSandboxSelector(getState(), { id: sandboxId });
30-
const modules = modulesFromSandboxSelector(getState(), { sandbox });
31-
const directories = directoriesFromSandboxSelector(getState(), {
32-
sandbox,
33-
});
34-
35-
const module = resolveModule(path, modules, directories);
59+
const module = getModule(sandboxId, path, getState);
3660
if (module) {
3761
return dispatch(
3862
sandboxActions.renameModule(sandboxId, module.id, title)
@@ -46,9 +70,16 @@ export default {
4670
return dispatch(sandboxActions.forceRender(sandboxId));
4771
}
4872
case 'editor.open-module': {
49-
const { moduleId, sandboxId /* , lineNumber */ } = action;
50-
// TODO functionality to open specific lineNumber
51-
return dispatch(sandboxActions.setCurrentModule(sandboxId, moduleId));
73+
const { sandboxId, path } = action;
74+
75+
const module = getModule(sandboxId, path, getState);
76+
if (module) {
77+
// TODO functionality to open specific lineNumber
78+
return dispatch(
79+
sandboxActions.setCurrentModule(sandboxId, module.id)
80+
);
81+
}
82+
return null;
5283
}
5384
default:
5485
return null;

src/node_modules/codesandbox-api/package.json

Lines changed: 11 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node_modules/codesandbox-api/src/actions/correction.ts

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node_modules/codesandbox-api/src/actions/editor.ts

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node_modules/codesandbox-api/src/actions/error.ts

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/sandbox/errors/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function buildErrorMessage(e) {
3636
}
3737

3838
return {
39-
moduleId: e.tModule ? e.tModule.module.id : e.moduleId,
39+
path: e.tModule ? e.tModule.module.path : e.path,
4040
title,
4141
message,
4242
line: parseInt(line, 10),
@@ -79,7 +79,7 @@ function buildDynamicError(ref: ErrorRecord) {
7979
return {
8080
type: 'action',
8181
action: 'show-error',
82-
moduleId: module.id,
82+
path: module.path,
8383
title: ref.error.name,
8484
message: ref.error.message,
8585
line: relevantFrame._originalLineNumber,
@@ -114,7 +114,7 @@ export default function showError(ref: ErrorRecord) {
114114
actions.error.show(errorToSend.title, errorToSend.message, {
115115
line: errorToSend.line,
116116
column: errorToSend.column,
117-
moduleId: errorToSend.moduleId,
117+
path: errorToSend.path,
118118
payload: errorToSend.payload,
119119
})
120120
);

src/sandbox/eval/errors/module-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default class ModuleError extends Error {
77
super();
88

99
this.name = 'ModuleError';
10-
this.module = module;
10+
this.path = err.fileName || module.module.path;
1111
this.message =
1212
err && typeof err === 'object' && err.message ? err.message : err;
1313
this.error = err;

src/sandbox/eval/errors/module-warning.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import TranspiledModule from '../transpiled-module';
2+
import { WarningStructure } from '../transpilers/utils/worker-warning-handler';
23

34
export default class ModuleWarning extends Error {
4-
constructor(module, warning) {
5+
constructor(module: TranspiledModule, warning: WarningStructure) {
56
super();
67

78
this.name = 'ModuleWarning';
8-
this.module = module;
9+
this.path = warning.fileName || module.module.path;
910
this.message = warning.message;
1011
this.warning = warning.message;
1112
this.lineNumber = warning.lineNumber;
@@ -16,7 +17,7 @@ export default class ModuleWarning extends Error {
1617
Error.captureStackTrace(this, this.constructor);
1718
}
1819

19-
module: TranspiledModule;
20+
path: string;
2021
message: string;
2122
warning: string;
2223
message: string;

src/sandbox/eval/transpiled-module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export default class TranspiledModule {
381381
actions.correction.show(warning.message, {
382382
line: warning.lineNumber,
383383
column: warning.columnNumber,
384-
moduleId: warning.module.module.id,
384+
path: warning.path,
385385
source: warning.source,
386386
severity: 'warning',
387387
})

0 commit comments

Comments
 (0)