Skip to content

Commit 02c4c7a

Browse files
committed
Configure a default fs for babel transpiler for the transpiler itself
1 parent a553832 commit 02c4c7a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ let lastConfig = null;
2626

2727
const IGNORED_MODULES = ['util', 'os'];
2828

29+
// Default in memory
30+
BrowserFS.configure({ fs: 'InMemory' }, () => {});
31+
2932
self.process = {
3033
env: { NODE_ENV: 'production' },
3134
platform: 'linux',
@@ -34,11 +37,6 @@ self.process = {
3437
};
3538
// This one is called from the babel transpiler and babel-plugin-macros
3639
self.require = path => {
37-
const module = BrowserFS.BFSRequire(path);
38-
if (module) {
39-
return module;
40-
}
41-
4240
if (path === 'assert') {
4341
return require('assert');
4442
}
@@ -51,6 +49,21 @@ self.require = path => {
5149
};
5250
}
5351

52+
if (path === 'util') {
53+
return require('util');
54+
}
55+
56+
if (path === 'os') {
57+
const os = require('os-browserify');
58+
os.homedir = () => '/home/sandbox';
59+
return os;
60+
}
61+
62+
const module = BrowserFS.BFSRequire(path);
63+
if (module) {
64+
return module;
65+
}
66+
5467
if (IGNORED_MODULES.indexOf(path) > -1) {
5568
return {};
5669
}

0 commit comments

Comments
 (0)