From 01a050f7603183e6833b7fd948adb4fbe1437f5a Mon Sep 17 00:00:00 2001
From: Daniel K <fredy.c@seznam.cz>
Date: Sun, 8 Nov 2020 08:02:44 +0100
Subject: [PATCH] Fix use of react-dom vs react-native

---
 .changeset/young-days-do.md                      | 7 +++++++
 packages/mobx-react-lite/.gitignore              | 2 ++
 packages/mobx-react-lite/es/index.js             | 1 -
 packages/mobx-react-lite/lib/index.js            | 2 --
 packages/mobx-react-lite/package.json            | 8 +++++---
 packages/mobx-react-lite/tsconfig.build.cjs.json | 7 +++++++
 packages/mobx-react-lite/tsconfig.build.es.json  | 7 +++++++
 packages/mobx-react-lite/tsconfig.build.json     | 9 +++++++++
 8 files changed, 37 insertions(+), 6 deletions(-)
 create mode 100644 .changeset/young-days-do.md
 delete mode 100644 packages/mobx-react-lite/es/index.js
 delete mode 100644 packages/mobx-react-lite/lib/index.js
 create mode 100644 packages/mobx-react-lite/tsconfig.build.cjs.json
 create mode 100644 packages/mobx-react-lite/tsconfig.build.es.json
 create mode 100644 packages/mobx-react-lite/tsconfig.build.json

diff --git a/.changeset/young-days-do.md b/.changeset/young-days-do.md
new file mode 100644
index 000000000..992605a32
--- /dev/null
+++ b/.changeset/young-days-do.md
@@ -0,0 +1,7 @@
+---
+"mobx-react-lite": patch
+---
+
+Fix use of react-dom vs react-native
+
+The `es` folder content is compiled only without transpilation to keep `utils/reactBatchedUpdates` which exists in DOM and RN versions. The bundled `esm` is still kept around too, especially the prod/dev ones that should be utilized in modern browser environments.
diff --git a/packages/mobx-react-lite/.gitignore b/packages/mobx-react-lite/.gitignore
index 895c41a78..8c5a1afa2 100644
--- a/packages/mobx-react-lite/.gitignore
+++ b/packages/mobx-react-lite/.gitignore
@@ -1,5 +1,7 @@
 /node_modules/
 
+es/
+lib/
 dist/
 coverage/
 
diff --git a/packages/mobx-react-lite/es/index.js b/packages/mobx-react-lite/es/index.js
deleted file mode 100644
index 271d564bf..000000000
--- a/packages/mobx-react-lite/es/index.js
+++ /dev/null
@@ -1 +0,0 @@
-export * from "../dist/mobxreactlite.esm.development.js"
diff --git a/packages/mobx-react-lite/lib/index.js b/packages/mobx-react-lite/lib/index.js
deleted file mode 100644
index ce7c07547..000000000
--- a/packages/mobx-react-lite/lib/index.js
+++ /dev/null
@@ -1,2 +0,0 @@
-// For the compatibility with current major, should be removed in next one
-export * from "../dist/mobxreactlite.cjs.development.js"
diff --git a/packages/mobx-react-lite/package.json b/packages/mobx-react-lite/package.json
index 546d0bc77..e5b3ce1e6 100644
--- a/packages/mobx-react-lite/package.json
+++ b/packages/mobx-react-lite/package.json
@@ -8,8 +8,8 @@
     "unpkg": "dist/mobxreactlite.umd.production.min.js",
     "jsdelivr": "dist/mobxreactlite.umd.production.min.js",
     "jsnext:main": "dist/mobxreactlite.esm.production.min.js",
-    "module": "dist/mobxreactlite.esm.js",
-    "react-native": "dist/mobxreactlite.esm.js",
+    "module": "es/index.js",
+    "react-native": "es/index.js",
     "types": "dist/index.d.ts",
     "typings": "dist/index.d.ts",
     "files": [
@@ -69,8 +69,10 @@
         "lint": "eslint src/**/* --ext .js,.ts,.tsx",
         "build": "node ../../scripts/build.js mobxreactlite",
         "build:test": "yarn build --target test",
+        "build:cjs": "tsc --project tsconfig.build.cjs.json",
+        "build:es": "tsc --project tsconfig.build.es.json",
         "test": "jest",
         "test:size": "yarn import-size --report . observer useLocalObservable",
-        "prepublish": "yarn build --target publish"
+        "prepublish": "yarn build --target publish && yarn build:cjs && yarn build:es"
     }
 }
diff --git a/packages/mobx-react-lite/tsconfig.build.cjs.json b/packages/mobx-react-lite/tsconfig.build.cjs.json
new file mode 100644
index 000000000..1bceb718e
--- /dev/null
+++ b/packages/mobx-react-lite/tsconfig.build.cjs.json
@@ -0,0 +1,7 @@
+{
+    "extends": "./tsconfig.build.json",
+    "compilerOptions": {
+        "outDir": "lib",
+        "module": "CommonJS"
+    }
+}
diff --git a/packages/mobx-react-lite/tsconfig.build.es.json b/packages/mobx-react-lite/tsconfig.build.es.json
new file mode 100644
index 000000000..156187696
--- /dev/null
+++ b/packages/mobx-react-lite/tsconfig.build.es.json
@@ -0,0 +1,7 @@
+{
+    "extends": "./tsconfig.build.json",
+    "compilerOptions": {
+        "outDir": "es",
+        "module": "ESNext"
+    }
+}
diff --git a/packages/mobx-react-lite/tsconfig.build.json b/packages/mobx-react-lite/tsconfig.build.json
new file mode 100644
index 000000000..568752403
--- /dev/null
+++ b/packages/mobx-react-lite/tsconfig.build.json
@@ -0,0 +1,9 @@
+{
+    "extends": "./tsconfig.json",
+    "compilerOptions": {
+        "esModuleInterop": true,
+        "target": "ES5",
+        "noEmit": false,
+        "declaration": false
+    }
+}