Skip to content

Commit e0487b8

Browse files
committed
Add file watching
1 parent 69b9700 commit e0487b8

File tree

14 files changed

+99
-104
lines changed

14 files changed

+99
-104
lines changed

packages/app/config/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const isDev = process.env.NODE_ENV === 'development';
22
const staticAssets = [
33
{
44
from: 'standalone-packages/vscode-editor/release/min/vs',
5-
to: 'public/vscode24/vs',
5+
to: 'public/vscode25/vs',
66
},
77
{
88
from: 'standalone-packages/vscode-extensions/out',

packages/app/config/webpack.prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ module.exports = merge(commonConfig, {
180180
},
181181
},
182182
{
183-
urlPattern: /\/vscode24/,
183+
urlPattern: /\/vscode25/,
184184
handler: 'cacheFirst',
185185
options: {
186186
cache: {

packages/app/scripts/copy-assets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const assets = [
2323
},
2424
{
2525
from: 'standalone-packages/vscode-editor/release/min/vs',
26-
to: 'public/vscode22/vs',
26+
to: 'public/vscode24/vs',
2727
},
2828
{
2929
from: 'packages/app/public',

packages/app/src/app/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@
6868
}
6969
</script>
7070

71-
<link data-name="/public/vscode24/vs/editor/editor.main" rel="preload" as="style" href="/public/vscode24/vs/editor/codesandbox.editor.main.css">
71+
<link data-name="/public/vscode25/vs/editor/editor.main" rel="preload" as="style" href="/public/vscode25/vs/editor/codesandbox.editor.main.css">
7272
</link>
73-
<link rel="preload" as="script" href="/public/vscode24/vs/editor/codesandbox.editor.main.js">
73+
<link rel="preload" as="script" href="/public/vscode25/vs/editor/codesandbox.editor.main.js">
7474
</link>
7575
</head>
7676

packages/app/src/app/overmind/effects/vscode/SandboxFsSync/index.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { dirname } from 'path';
1+
import { dirname, join } from 'path';
22

3+
import browserFs from 'fs';
34
import {
45
getDirectoryPath,
56
getModulePath,
@@ -20,7 +21,6 @@ import { mkdir, rename, rmdir, unlink, writeFile } from './utils';
2021

2122
const global = getGlobal() as Window & { BrowserFS: any };
2223

23-
const browserFs = global.BrowserFS.BFSRequire('fs');
2424
const SERVICE_URL = 'https://ata-fetcher.cloud/api/v5/typings';
2525

2626
declare global {
@@ -77,6 +77,18 @@ class SandboxFsSync {
7777
public create(sandbox: Sandbox): SandboxFs {
7878
const sandboxFs = {};
7979

80+
sandbox.directories.forEach(d => {
81+
const path = getDirectoryPath(sandbox.modules, sandbox.directories, d.id);
82+
83+
d.path = path;
84+
// If this is a single directory with no children
85+
if (!Object.keys(sandboxFs).some(p => dirname(p) === path)) {
86+
sandboxFs[path] = { ...d, type: 'directory' };
87+
}
88+
89+
browserFs.mkdirSync(join('/sandbox', path));
90+
});
91+
8092
sandbox.modules.forEach(m => {
8193
const path = getModulePath(sandbox.modules, sandbox.directories, m.id);
8294
if (path) {
@@ -85,16 +97,8 @@ class SandboxFsSync {
8597
...m,
8698
type: 'file',
8799
};
88-
}
89-
});
90-
91-
sandbox.directories.forEach(d => {
92-
const path = getDirectoryPath(sandbox.modules, sandbox.directories, d.id);
93100

94-
d.path = path;
95-
// If this is a single directory with no children
96-
if (!Object.keys(sandboxFs).some(p => dirname(p) === path)) {
97-
sandboxFs[path] = { ...d, type: 'directory' };
101+
browserFs.writeFileSync(join('/sandbox', path), m.code);
98102
}
99103
});
100104

@@ -106,6 +110,11 @@ class SandboxFsSync {
106110

107111
writeFile(fs, copy);
108112
this.send('write-file', copy);
113+
browserFs.writeFileSync(
114+
join('/sandbox', module.path),
115+
module.code,
116+
() => {}
117+
);
109118

110119
if (module.title === 'package.json') {
111120
this.syncDependencyTypings();
@@ -118,27 +127,35 @@ class SandboxFsSync {
118127
fromPath,
119128
toPath,
120129
});
130+
browserFs.rename(
131+
join('/sandbox', fromPath),
132+
join('/sandbox', toPath),
133+
() => {}
134+
);
121135
}
122136

123137
public rmdir(fs: SandboxFs, directory: Directory) {
124138
const copy = json(directory);
125139

126140
rmdir(fs, copy);
127141
this.send('rmdir', copy);
142+
browserFs.rmdir(join('/sandbox', directory.path), () => {});
128143
}
129144

130145
public unlink(fs: SandboxFs, module: Module) {
131146
const copy = json(module);
132147

133148
unlink(fs, copy);
134149
this.send('unlink', copy);
150+
browserFs.unlink(join('/sandbox', module.path), () => {});
135151
}
136152

137153
public mkdir(fs: SandboxFs, directory: Directory) {
138154
const copy = json(directory);
139155

140156
mkdir(fs, copy);
141157
this.send('mkdir', copy);
158+
browserFs.mkdir(join('/sandbox', directory.path), () => {});
142159
}
143160

144161
private onWorkerMessage = evt => {

packages/app/src/app/overmind/effects/vscode/metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const VSCODE_METADATA = {
22
CORE: {
33
paths: {
4-
src: process.env.VSCODE ? '/vscode/out/vs' : '/public/vscode24/vs',
4+
src: process.env.VSCODE ? '/vscode/out/vs' : '/public/vscode25/vs',
55
'npm/dev': 'node_modules/monaco-editor-core/dev/vs',
66
'npm/min': 'node_modules/monaco-editor-core/min/vs',
77
built: '/vscode/out-monaco-editor-core/min/vs',

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import * as internalActions from './internalActions';
2323

2424
export const internal = internalActions;
2525

26-
export const onNavigateAway: Action = () => {};
26+
export const onNavigateAway: Action = () => { };
2727

2828
export const addNpmDependency: AsyncAction<{
2929
name: string;
@@ -316,7 +316,7 @@ export const moduleSelected: Action<{
316316

317317
if (path) {
318318
module = effects.utils.resolveModule(
319-
path.replace(/^\//, ''),
319+
path.replace(/^\/sandbox\//, ''),
320320
sandbox.modules,
321321
sandbox.directories
322322
);
@@ -465,7 +465,7 @@ export const quickActionsClosed: Action = ({ state }) => {
465465
state.editor.quickActionsOpen = false;
466466
};
467467

468-
export const setPreviewContent: Action = () => {};
468+
export const setPreviewContent: Action = () => { };
469469

470470
export const togglePreviewContent: Action = ({ state }) => {
471471
state.editor.previewWindowVisible = !state.editor.previewWindowVisible;

standalone-packages/codesandbox-browserfs/.eslintrc.json

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

standalone-packages/codesandbox-browserfs/src/backend/CodeSandboxEditorFS.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export default class CodeSandboxEditorFS extends SynchronousFileSystem
247247
return;
248248
}
249249

250-
cb(undefined, new CodeSandboxFile(this, p, flag, stats, r)) ;
250+
cb(undefined, new CodeSandboxFile(this, p, flag, stats, r));
251251
});
252252
});
253253
return;
@@ -322,6 +322,8 @@ export default class CodeSandboxEditorFS extends SynchronousFileSystem
322322

323323
public _sync(p: string, data: Buffer, cb: BFSCallback<Stats>): void {
324324
warn('Sync not supported');
325+
326+
cb(null, undefined);
325327
}
326328

327329
public _syncSync(p: string, data: Buffer): void {

0 commit comments

Comments
 (0)