Skip to content

Commit 4cbe22a

Browse files
committed
fix: React Native build
1 parent d291db9 commit 4cbe22a

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

packages/core/cjsBuild.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const path = require("path")
2+
3+
const isProd = process.argv[2] === "--prod"
4+
5+
const fixCjsPlugin = {
6+
name: "fixCJS",
7+
setup(build) {
8+
build.onResolve({ filter: /useSyncExternalStore/ }, (args) => {
9+
return {
10+
path: path.join(args.resolveDir, args.path + "Cjs.ts"),
11+
}
12+
})
13+
},
14+
}
15+
16+
require("esbuild")
17+
.build({
18+
entryPoints: ["src/index.tsx"],
19+
bundle: true,
20+
outfile: isProd
21+
? "./dist/core.cjs.production.min.js"
22+
: "./dist/core.cjs.development.js",
23+
target: "es2015",
24+
minify: isProd,
25+
external: ["react", "rxjs", "use-sync-external-store"],
26+
format: "cjs",
27+
sourcemap: true,
28+
plugins: [fixCjsPlugin],
29+
})
30+
.catch((error) => {
31+
console.error(error)
32+
process.exit(1)
33+
})

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"build": "yarn build:ts && yarn build:esm2017 && yarn build:esm2019 && yarn build:cjs:dev && yarn build:cjs:prod",
2828
"build:esm2019": "esbuild src/index.tsx --bundle --outfile=./dist/core.es2019.mjs --target=es2019 --external:react --external:rxjs --external:use-sync-external-store --format=esm --sourcemap",
2929
"build:esm2017": "esbuild src/index.tsx --bundle --outfile=./dist/core.es2017.js --target=es2017 --external:react --external:rxjs --external:use-sync-external-store --format=esm --sourcemap",
30-
"build:cjs:dev": "esbuild src/index.tsx --bundle --outfile=./dist/core.cjs.development.js --target=es2015 --external:react --external:rxjs --external:use-sync-external-store --format=cjs --sourcemap",
31-
"build:cjs:prod": "esbuild src/index.tsx --bundle --outfile=./dist/core.cjs.production.min.js --target=es2015 --external:react --external:rxjs --external:use-sync-external-store --format=cjs --minify --sourcemap",
30+
"build:cjs:dev": "node cjsBuild.js",
31+
"build:cjs:prod": "node cjsBuild.js --prod",
3232
"build:ts": "tsc -p ./tsconfig-build.json --outDir ./dist --skipLibCheck --emitDeclarationOnly",
3333
"test": "jest --coverage",
3434
"lint": "prettier --check README.md \"src/**/*.{js,jsx,ts,tsx,json,md}\"",

packages/core/src/internal/useObservable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Subscription } from "rxjs"
2-
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js"
32
import { useRef, useState } from "react"
43
import { SUSPENSE, filterOutSuspense } from "../SUSPENSE"
54
import { DefaultedStateObservable, StateObservable } from "@josepot/rxjs-state"
65
import { EMPTY_VALUE } from "./empty-value"
6+
import useSyncExternalStore from "./useSyncExternalStore"
77

88
type VoidCb = () => void
99

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { useSyncExternalStore as default } from "use-sync-external-store/shim/index.js"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { useSyncExternalStore as default } from "use-sync-external-store/shim"

0 commit comments

Comments
 (0)