Skip to content

Commit 679d76a

Browse files
authored
enhance: Add react-native entry to package.json exports (#3371)
1 parent 32ebc49 commit 679d76a

File tree

11 files changed

+105
-67
lines changed

11 files changed

+105
-67
lines changed

.changeset/three-needles-brake.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@data-client/normalizr': patch
3+
'@data-client/endpoint': patch
4+
'@data-client/graphql': patch
5+
'@data-client/react': patch
6+
'@data-client/core': patch
7+
'@data-client/rest': patch
8+
'@data-client/test': patch
9+
---
10+
11+
Add react-native entry to package.json exports

babel.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ const path = require('path');
44

55
module.exports = function (api) {
66
api.cache.using(
7-
() => process.env.NODE_ENV + process.env.BROWSERSLIST_ENV + '0',
7+
() =>
8+
process.env.NODE_ENV +
9+
process.env.BROWSERSLIST_ENV +
10+
process.env.COMPILE_TARGET +
11+
'0',
812
);
913
return {
1014
presets: [

packages/core/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@
3737
"module": "./lib/index.js",
3838
"import": "./node.mjs",
3939
"require": "./dist/index.js",
40+
"browser": "./lib/index.js",
41+
"react-native": "./lib/index.js",
4042
"default": "./lib/index.js"
4143
},
4244
"./next": {
4345
"types": "./lib/next/index.d.ts",
4446
"require": "./dist/next.js",
47+
"browser": "./lib/next/index.js",
48+
"react-native": "./lib/next/index.js",
4549
"default": "./lib/next/index.js"
4650
},
4751
"./package.json": "./package.json"

packages/endpoint/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
"module": "./lib/index.js",
8484
"import": "./node.mjs",
8585
"require": "./dist/index.js",
86+
"browser": "./lib/index.js",
87+
"react-native": "./lib/index.js",
8688
"default": "./lib/index.js"
8789
},
8890
"./package.json": "./package.json"

packages/graphql/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
"module": "./lib/index.js",
7070
"import": "./node.mjs",
7171
"require": "./dist/index.js",
72+
"browser": "./lib/index.js",
73+
"react-native": "./lib/index.js",
7274
"default": "./lib/index.js"
7375
},
7476
"./package.json": "./package.json"

packages/normalizr/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
"module": "./lib/index.js",
6969
"import": "./node.mjs",
7070
"require": "./dist/normalizr.js",
71+
"browser": "./lib/index.js",
72+
"react-native": "./lib/index.js",
7173
"default": "./lib/index.js"
7274
},
7375
"./package.json": "./package.json"

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
"scripts": {
154154
"build:lib": "NODE_ENV=production BROWSERSLIST_ENV='2020' yarn g:babel --out-dir lib",
155155
"build:legacy:lib": "NODE_ENV=production BROWSERSLIST_ENV='2018' yarn g:babel --out-dir legacy",
156-
"build:native:lib": "COMPILE_TARGET=native NODE_ENV=production BROWSERSLIST_ENV='2018' yarn g:babel --out-dir native",
156+
"build:native:lib": "COMPILE_TARGET=native NODE_ENV=production BROWSERSLIST_ENV='hermes12' yarn g:babel --out-dir native",
157157
"build:js:node": "BROWSERSLIST_ENV=node12 yarn g:rollup",
158158
"build:js:browser": "BROWSERSLIST_ENV=legacy yarn g:rollup",
159159
"build:bundle": "yarn g:runs build:js:\\* && echo '{\"type\":\"commonjs\"}' > dist/package.json",

packages/react/src/__tests__/integration-garbage-collection.web.tsx

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -90,67 +90,71 @@ const TestComponent = () => {
9090
);
9191
};
9292

93-
test('switch between list and detail view', async () => {
94-
jest.useFakeTimers();
95-
mockGetList.mockReturnValue([
96-
{ id: 1, title: 'Article 1', content: 'Content 1' },
97-
{ id: 2, title: 'Article 2', content: 'Content 2' },
98-
]);
99-
mockGet.mockReturnValue({
100-
id: 1,
101-
title: 'Article 1',
102-
content: 'Content 1',
93+
describe('Integration Garbage Collection Web', () => {
94+
it('should render list view and detail view correctly', async () => {
95+
jest.useFakeTimers();
96+
mockGetList.mockReturnValue([
97+
{ id: 1, title: 'Article 1', content: 'Content 1' },
98+
{ id: 2, title: 'Article 2', content: 'Content 2' },
99+
]);
100+
mockGet.mockReturnValue({
101+
id: 1,
102+
title: 'Article 1',
103+
content: 'Content 1',
104+
});
105+
106+
render(<TestComponent />);
107+
108+
// Initial render, should show list view
109+
expect(await screen.findByText('Article 1')).toBeInTheDocument();
110+
111+
// Switch to detail view
112+
act(() => {
113+
screen.getByText('Article 1').click();
114+
});
115+
116+
// Detail view should render
117+
expect(await screen.findByText('Content 1')).toBeInTheDocument();
118+
119+
// Jest time pass to trigger sweep but not expired
120+
act(() => {
121+
jest.advanceTimersByTime(GC_INTERVAL);
122+
});
123+
124+
// Switch back to list view
125+
act(() => {
126+
screen.getByText('Home').click();
127+
});
128+
129+
// List view should instantly render
130+
expect(await screen.findByText('Article 1')).toBeInTheDocument();
131+
132+
// Switch back to detail view
133+
act(() => {
134+
screen.getByText('Article 1').click();
135+
});
136+
137+
// Jest time pass to expiry
138+
act(() => {
139+
jest.advanceTimersByTime(
140+
ArticleResource.getList.dataExpiryLength ?? 60000,
141+
);
142+
});
143+
expect(await screen.findByText('Content 1')).toBeInTheDocument();
144+
145+
// Re-render detail view to make sure it still renders
146+
act(() => {
147+
screen.getByText('Toggle Re-render').click();
148+
});
149+
expect(await screen.findByText('Toggle state: true')).toBeInTheDocument();
150+
expect(await screen.findByText('Content 1')).toBeInTheDocument();
151+
152+
// Visit list view and see suspense fallback
153+
act(() => {
154+
screen.getByText('Home').click();
155+
});
156+
157+
expect(screen.getByText('Loading...')).toBeInTheDocument();
158+
jest.useRealTimers();
103159
});
104-
105-
render(<TestComponent />);
106-
107-
// Initial render, should show list view
108-
expect(await screen.findByText('Article 1')).toBeInTheDocument();
109-
110-
// Switch to detail view
111-
act(() => {
112-
screen.getByText('Article 1').click();
113-
});
114-
115-
// Detail view should render
116-
expect(await screen.findByText('Content 1')).toBeInTheDocument();
117-
118-
// Jest time pass to trigger sweep but not expired
119-
act(() => {
120-
jest.advanceTimersByTime(GC_INTERVAL);
121-
});
122-
123-
// Switch back to list view
124-
act(() => {
125-
screen.getByText('Home').click();
126-
});
127-
128-
// List view should instantly render
129-
expect(await screen.findByText('Article 1')).toBeInTheDocument();
130-
131-
// Switch back to detail view
132-
act(() => {
133-
screen.getByText('Article 1').click();
134-
});
135-
136-
// Jest time pass to expiry
137-
act(() => {
138-
jest.advanceTimersByTime(ArticleResource.getList.dataExpiryLength ?? 60000);
139-
});
140-
expect(await screen.findByText('Content 1')).toBeInTheDocument();
141-
142-
// Re-render detail view to make sure it still renders
143-
act(() => {
144-
screen.getByText('Toggle Re-render').click();
145-
});
146-
expect(await screen.findByText('Toggle state: true')).toBeInTheDocument();
147-
expect(await screen.findByText('Content 1')).toBeInTheDocument();
148-
149-
// Visit list view and see suspense fallback
150-
act(() => {
151-
screen.getByText('Home').click();
152-
});
153-
154-
expect(screen.getByText('Loading...')).toBeInTheDocument();
155-
jest.useRealTimers();
156160
});

packages/rest/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,15 @@
8787
"module": "./lib/index.js",
8888
"import": "./node.mjs",
8989
"require": "./dist/index.js",
90+
"browser": "./lib/index.js",
91+
"react-native": "./lib/index.js",
9092
"default": "./lib/index.js"
9193
},
9294
"./next": {
9395
"types": "./lib/next/index.d.ts",
9496
"require": "./dist/next.js",
97+
"browser": "./lib/next/index.js",
98+
"react-native": "./lib/next/index.js",
9599
"default": "./lib/next/index.js"
96100
},
97101
"./package.json": "./package.json"

packages/test/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/lib
22
/dist
33
/legacy
4+
/native

0 commit comments

Comments
 (0)