Skip to content

Commit 3c4fa9b

Browse files
authored
Babel 7.3.4 (codesandbox#1580)
* Upgrade babel to new version * Add require plugin by default * Remove logs * Remove assert from ignored modules
1 parent 96510b0 commit 3c4fa9b

File tree

3 files changed

+85732
-9
lines changed

3 files changed

+85732
-9
lines changed

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

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,37 @@ let fsInitialized = false;
2424
let fsLoading = false;
2525
let lastConfig = null;
2626

27-
// This one is called from babel-plugin-macros
27+
const IGNORED_MODULES = ['util', 'os'];
28+
29+
self.process = {
30+
env: { NODE_ENV: 'production' },
31+
platform: 'linux',
32+
argv: [],
33+
stderr: {},
34+
};
35+
// This one is called from the babel transpiler and babel-plugin-macros
2836
self.require = path => {
37+
const module = BrowserFS.BFSRequire(path);
38+
if (module) {
39+
return module;
40+
}
41+
42+
if (path === 'assert') {
43+
return require('assert');
44+
}
45+
46+
if (path === 'tty') {
47+
return {
48+
isatty() {
49+
return false;
50+
},
51+
};
52+
}
53+
54+
if (IGNORED_MODULES.indexOf(path) > -1) {
55+
return {};
56+
}
57+
2958
const fs = BrowserFS.BFSRequire('fs');
3059
return evaluateFromPath(
3160
fs,
@@ -248,7 +277,7 @@ function getCustomConfig(
248277
};
249278
}
250279

251-
async function compile(code, customConfig, path) {
280+
async function compile(code, customConfig, path, isV7) {
252281
try {
253282
let result;
254283
try {
@@ -274,7 +303,14 @@ async function compile(code, customConfig, path) {
274303
}
275304

276305
const dependencies = getDependencies(detective.metadata(result));
277-
306+
if (isV7) {
307+
// Force push this dependency, there are cases where it isn't included out of our control.
308+
// https://twitter.com/vigs072/status/1103005932886343680
309+
dependencies.push({
310+
type: 'direct',
311+
path: '@babel/runtime/helpers/interopRequireDefault',
312+
});
313+
}
278314
dependencies.forEach(dependency => {
279315
self.postMessage({
280316
type: 'add-dependency',
@@ -305,11 +341,15 @@ async function compile(code, customConfig, path) {
305341
}
306342
}
307343

308-
self.importScripts(
309-
process.env.NODE_ENV === 'development'
310-
? `${process.env.CODESANDBOX_HOST || ''}/static/js/babel.7.00-1.min.js`
311-
: `${process.env.CODESANDBOX_HOST || ''}/static/js/babel.7.00-1.min.js`
312-
);
344+
try {
345+
self.importScripts(
346+
process.env.NODE_ENV === 'development'
347+
? `${process.env.CODESANDBOX_HOST || ''}/static/js/babel.7.3.4.min.js`
348+
: `${process.env.CODESANDBOX_HOST || ''}/static/js/babel.7.3.4.min.js`
349+
);
350+
} catch (e) {
351+
console.error(e);
352+
}
313353

314354
self.postMessage('ready');
315355

@@ -558,7 +598,8 @@ self.addEventListener('message', async event => {
558598
await compile(
559599
code,
560600
version === 7 ? normalizeV7Config(customConfig) : customConfig,
561-
path
601+
path,
602+
version === 7
562603
);
563604
} catch (e) {
564605
console.error(e);

0 commit comments

Comments
 (0)