Skip to content

Commit

Permalink
fix: React Native specific module bundler issues (#3123)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker authored Jun 21, 2024
1 parent 555af2c commit c38714d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .changeset/weak-timers-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@data-client/react': patch
---

Fix React Native use correct native specific modules

Fully realized path names (including .js at end of import)
was breaking [platform specific extensions](https://docs.expo.dev/router/advanced/platform-specific-modules/#platform-specific-extensions). To workaround this issue, we
simply create a custom react-native build that remaps any
imports with full extension written ("file.native.js")
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = function (api) {
resolved + ext,
);
if (fs.existsSync(absolutePath)) {
return resolved;
return resolved + path.extname(sourcePath);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"ignorePatterns": [
"**/lib*/*",
"**/dist*/*",
"packages/*/native/*",
"**/node_modules*/*",
"node_modules/*"
]
Expand Down
1 change: 1 addition & 0 deletions packages/react/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/lib
/dist
/legacy
/native
/index.d.ts
/next.d.ts
/nextjs.d.ts
Expand Down
17 changes: 13 additions & 4 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@
"mutations"
],
"sideEffects": [
"./lib/hooks/useFocusEffect.native.js"
"./lib/hooks/useFocusEffect.native.js",
"./native/hooks/useFocusEffect.native.js"
],
"main": "dist/index.js",
"react-native": "legacy/index.js",
"react-native": "native/index.js",
"module": "legacy/index.js",
"unpkg": "dist/index.umd.min.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -103,11 +104,15 @@
"module": "./lib/index.js",
"import": "./node.mjs",
"require": "./dist/index.js",
"browser": "./lib/index.js",
"react-native": "./native/index.js",
"default": "./lib/index.js"
},
"./next": {
"types": "./lib/next/index.d.ts",
"require": "./dist/next.js",
"browser": "./lib/next/index.js",
"react-native": "./native/next/index.js",
"default": "./lib/next/index.js"
},
"./nextjs": {
Expand All @@ -122,6 +127,8 @@
"./redux": {
"types": "./lib/server/redux/index.d.ts",
"require": "./dist/server/redux/index.js",
"browser": "./lib/server/redux/index.js",
"react-native": "./native/server/redux/index.js",
"default": "./lib/server/redux/index.js"
},
"./package.json": "./package.json"
Expand All @@ -134,9 +141,10 @@
"src",
"dist",
"lib",
"legacy",
"native",
"ts3.4",
"node.mjs",
"legacy",
"LICENSE",
"README.md",
"./data_client_logo_and_text.svg",
Expand All @@ -145,12 +153,13 @@
"scripts": {
"build:lib": "NODE_ENV=production BROWSERSLIST_ENV='2020' yarn g:babel --out-dir lib",
"build:legacy:lib": "NODE_ENV=production BROWSERSLIST_ENV='2018' yarn g:babel --out-dir legacy",
"build:native:lib": "COMPILE_TARGET=native NODE_ENV=production BROWSERSLIST_ENV='2018' yarn g:babel --out-dir native",
"build:js:node": "BROWSERSLIST_ENV=node12 yarn g:rollup",
"build:js:browser": "BROWSERSLIST_ENV=legacy yarn g:rollup",
"build:bundle": "yarn g:runs build:js:\\* && echo '{\"type\":\"commonjs\"}' > dist/package.json",
"build:clean": "yarn g:clean ./index.d.ts",
"build:legacy-types": "yarn g:downtypes lib ts3.4",
"build": "run build:lib && run build:legacy:lib && run build:bundle",
"build": "run build:lib && run build:legacy:lib && run build:native:lib && run build:bundle",
"dev": "run build:lib -w",
"prepare": "run build:lib",
"prepack": "run prepare && run build:legacy:lib && run build:bundle"
Expand Down

0 comments on commit c38714d

Please sign in to comment.