Skip to content

Commit 2d14b85

Browse files
committed
Fix babel macros for styled-components
1 parent 0768bcb commit 2d14b85

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,34 @@ export async function downloadPath(absolutePath) {
8383

8484
const fs = BrowserFS.BFSRequire('fs');
8585

86-
mkDirByPathSync(BrowserFS.BFSRequire('path').dirname(r.path));
86+
let existingFile;
87+
88+
try {
89+
existingFile = fs.readFileSync(r.path);
90+
} catch (e) {}
91+
92+
if (existingFile) {
93+
try {
94+
// Maybe there was a redirect from package.json. Manager only returns the redirect,
95+
// if the babel worker doesn't have the package.json it enters an infinite loop.
96+
const r2 = await resolveAsyncModule(
97+
path.join(absolutePath, 'package.json'),
98+
{}
99+
);
100+
if (r2) {
101+
mkDirByPathSync(path.dirname(r2.path));
102+
103+
fs.writeFileSync(r2.path, r2.code);
104+
}
105+
} catch (e) {}
106+
107+
return Promise.resolve({
108+
code: existingFile,
109+
path: r.path,
110+
});
111+
}
112+
113+
mkDirByPathSync(path.dirname(r.path));
87114

88115
fs.writeFileSync(r.path, r.code);
89116

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export default function evaluate(
2828
return () => {};
2929
}
3030

31+
if (requirePath === 'stream') {
32+
return {};
33+
}
34+
3135
if (requirePath === 'constants') {
3236
return {};
3337
}
@@ -59,15 +63,15 @@ export default function evaluate(
5963
availablePlugins[requirePath] ||
6064
availablePlugins[requirePath.replace('babel-plugin-', '')] ||
6165
availablePlugins[requirePath.replace('@babel/plugin-', '')];
62-
if (plugin) {
66+
if (plugin && requirePath !== 'react') {
6367
return plugin;
6468
}
6569

6670
const preset =
6771
availablePresets[requirePath] ||
6872
availablePresets[requirePath.replace('babel-preset-', '')] ||
6973
availablePresets[requirePath.replace('@babel/preset-', '')];
70-
if (preset) {
74+
if (preset && requirePath !== 'react') {
7175
return preset;
7276
}
7377

0 commit comments

Comments
 (0)