Skip to content

Commit

Permalink
Fix @babel/runtime issues (#836)
Browse files Browse the repository at this point in the history
* Add `@babel/runtime` as dependancy

* Revert "Add `@babel/runtime` as dependancy"

This reverts commit 693d8c5.

* `disableImportExportTransform` in babel config

* Fix to tests

* Change how reanimated is polyfilled
  • Loading branch information
YoussefHenna authored Feb 11, 2024
1 parent 2a8f8b7 commit d6460cc
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 44 deletions.
28 changes: 22 additions & 6 deletions packages/core/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
module.exports = {
presets: ["module:metro-react-native-babel-preset"],
plugins: [
"@babel/plugin-proposal-export-namespace-from",
"react-native-reanimated/plugin",
],
module.exports = (api) => {
const isTest = api.env("test");

return {
presets: [
[
"module:metro-react-native-babel-preset",
{
/**
* Addresses issue caused on snack that leads to `Unable to resolve module 'app/node_modules/@babel/runtime/helpers/interopRequireDefault.js'`
* See: https://github.com/expo/snack/pull/302
* Always false for tests for jest to work
*/
disableImportExportTransform: !isTest,
},
],
],
plugins: [
"@babel/plugin-proposal-export-namespace-from",
"react-native-reanimated/plugin",
],
};
};
20 changes: 18 additions & 2 deletions packages/maps/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
module.exports = {
presets: ["module:metro-react-native-babel-preset"],
module.exports = (api) => {
const isTest = api.env("test");

return {
presets: [
[
"module:metro-react-native-babel-preset",
{
/**
* Addresses issue caused on snack that leads to `Unable to resolve module 'app/node_modules/@babel/runtime/helpers/interopRequireDefault.js'`
* See: https://github.com/expo/snack/pull/302
* Always false for tests for jest to work
*/
disableImportExportTransform: !isTest,
},
],
],
};
};
20 changes: 18 additions & 2 deletions packages/native/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
module.exports = {
presets: ["module:metro-react-native-babel-preset"],
module.exports = (api) => {
const isTest = api.env("test");

return {
presets: [
[
"module:metro-react-native-babel-preset",
{
/**
* Addresses issue caused on snack that leads to `Unable to resolve module 'app/node_modules/@babel/runtime/helpers/interopRequireDefault.js'`
* See: https://github.com/expo/snack/pull/302
* Always false for tests for jest to work
*/
disableImportExportTransform: !isTest,
},
],
],
};
};
20 changes: 18 additions & 2 deletions packages/types/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
module.exports = {
presets: ["module:metro-react-native-babel-preset"],
module.exports = (api) => {
const isTest = api.env("test");

return {
presets: [
[
"module:metro-react-native-babel-preset",
{
/**
* Addresses issue caused on snack that leads to `Unable to resolve module 'app/node_modules/@babel/runtime/helpers/interopRequireDefault.js'`
* See: https://github.com/expo/snack/pull/302
* Always false for tests for jest to work
*/
disableImportExportTransform: !isTest,
},
],
],
};
};
28 changes: 22 additions & 6 deletions packages/ui/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
module.exports = {
presets: ["module:metro-react-native-babel-preset"],
plugins: [
"@babel/plugin-proposal-export-namespace-from",
"react-native-reanimated/plugin",
],
module.exports = (api) => {
const isTest = api.env("test");

return {
presets: [
[
"module:metro-react-native-babel-preset",
{
/**
* Addresses issue caused on snack that leads to `Unable to resolve module 'app/node_modules/@babel/runtime/helpers/interopRequireDefault.js'`
* See: https://github.com/expo/snack/pull/302
* Always false for tests for jest to work
*/
disableImportExportTransform: !isTest,
},
],
],
plugins: [
"@babel/plugin-proposal-export-namespace-from",
"react-native-reanimated/plugin",
],
};
};
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"scripts": {
"clean": "rimraf lib",
"clean:modules": "rimraf node_modules",
"build:commonjs": "../../node_modules/.bin/babel src --out-dir lib/commonjs --extensions .tsx,.ts,.js,.jsx && ts-node scripts/polyfillReanimatedWorkletInitForSnack.ts",
"build:commonjs": "../../node_modules/.bin/babel src --out-dir lib/commonjs --extensions .tsx,.ts,.js,.jsx",
"build": "yarn clean && yarn build:commonjs && yarn tsc",
"test": "jest",
"test:coverage": "jest --coverage"
Expand Down
25 changes: 0 additions & 25 deletions packages/ui/scripts/polyfillReanimatedWorkletInitForSnack.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/ui/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./polyfillReanimatedWorkletInit";
import { Icon } from "@draftbit/native";
export { Icon, LinearGradient, WebView } from "@draftbit/native";

Expand Down
16 changes: 16 additions & 0 deletions packages/ui/src/polyfillReanimatedWorkletInit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* When the @draftbit/ui is used with snack, we run into the error: 'r.g.__reanimatedWorkletInit is not a function'
* The solution is to add a polyfill for the global.__reanimatedWorkletInit function
* https://forums.expo.dev/t/react-native-reanimated-error-r-g-reanimatedworkletinit-is-not-a-function/68222/3
*
* This polyfill needs to be done at the first point of execution, placing at the top of index.tsx does not guarantee that
* since the build reorders the code around (such as hoisting imports/exports) which results in it not being the top most call. Having it as an import of
* a seperate file guarantees it's the first import
*
*/

//@ts-ignore
if (!global.__reanimatedWorkletInit) {
//@ts-ignore
global.__reanimatedWorkletInit = function () {};
}

0 comments on commit d6460cc

Please sign in to comment.