From e069f3946e90ecd91f0ea5addc95ba449b6b8e13 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 12 Apr 2023 16:06:31 -0500 Subject: [PATCH] fix: try esm exports for rn package --- .changeset/chilled-melons-laugh.md | 5 +++++ packages/react-native/lib/index.tsx | 2 +- packages/react-native/package.json | 7 ++++--- packages/react-native/scripts/build.js | 19 ++++++++++++++----- pnpm-lock.yaml | 12 ++++++++++-- 5 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 .changeset/chilled-melons-laugh.md diff --git a/.changeset/chilled-melons-laugh.md b/.changeset/chilled-melons-laugh.md new file mode 100644 index 0000000..0567ea9 --- /dev/null +++ b/.changeset/chilled-melons-laugh.md @@ -0,0 +1,5 @@ +--- +"@svbstrate/react-native": patch +--- + +Attempt to fix React Native import issues by publishing ESM exports. diff --git a/packages/react-native/lib/index.tsx b/packages/react-native/lib/index.tsx index feb2518..2bea223 100644 --- a/packages/react-native/lib/index.tsx +++ b/packages/react-native/lib/index.tsx @@ -3,7 +3,7 @@ import React from "react"; import { View, ViewProps } from "react-native"; import * as Polymorphic from "@radix-ui/react-polymorphic"; -export * as presets from "@svbstrate/core/presets"; +export * as presets from "@svbstrate/core/dist/presets"; const defaultProperties: svbstrate.ThemeConfig["properties"] = { width: { diff --git a/packages/react-native/package.json b/packages/react-native/package.json index 44d2ace..aeced1b 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -2,7 +2,8 @@ "name": "@svbstrate/react-native", "version": "0.0.9", "description": "", - "main": "dist/index.js", + "main": "dist/index.cjs.js", + "module": "dist/index.esm.js", "types": "dist/index.d.ts", "scripts": { "build": "node scripts/build && pnpm typegen", @@ -26,11 +27,11 @@ "@svbstrate/core": "workspace:^0.0.10" }, "peerDependencies": { - "react": "18", + "react": "*", "react-native": "*" }, "devDependencies": { - "@types/react": "18", + "@types/react": "17", "@types/react-native": "*", "esbuild": "^0.17.16", "react": "18", diff --git a/packages/react-native/scripts/build.js b/packages/react-native/scripts/build.js index c17cce1..66d5865 100644 --- a/packages/react-native/scripts/build.js +++ b/packages/react-native/scripts/build.js @@ -1,13 +1,22 @@ const path = require("path"); -require("esbuild").buildSync({ +const options = { entryPoints: ["lib/index.tsx"], - outdir: path.join(__dirname, "../dist"), bundle: true, - platform: "node", - target: "es2015", - minify: true, sourcemap: true, + minify: true, logLevel: "info", external: ["react", "react-native"], +}; + +require("esbuild").buildSync({ + format: "cjs", + outfile: path.join(__dirname, "../dist/index.cjs.js"), + ...options, +}); + +require("esbuild").buildSync({ + format: "esm", + outfile: path.join(__dirname, "../dist/index.esm.js"), + ...options, }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f78aa0e..96fe8e8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -40,7 +40,7 @@ importers: specifiers: '@radix-ui/react-polymorphic': ^0.0.14 '@svbstrate/core': workspace:^0.0.10 - '@types/react': '18' + '@types/react': '17' '@types/react-native': '*' esbuild: ^0.17.16 react: '18' @@ -49,7 +49,7 @@ importers: '@radix-ui/react-polymorphic': 0.0.14_react@18.2.0 '@svbstrate/core': link:../core devDependencies: - '@types/react': 18.0.34 + '@types/react': 17.0.58 '@types/react-native': 0.71.5 esbuild: 0.17.16 react: 18.2.0 @@ -1966,6 +1966,14 @@ packages: '@types/react': 18.0.34 dev: true + /@types/react/17.0.58: + resolution: {integrity: sha512-c1GzVY97P0fGxwGxhYq989j4XwlcHQoto6wQISOC2v6wm3h0PORRWJFHlkRjfGsiG3y1609WdQ+J+tKxvrEd6A==} + dependencies: + '@types/prop-types': 15.7.5 + '@types/scheduler': 0.16.3 + csstype: 3.1.2 + dev: true + /@types/react/18.0.34: resolution: {integrity: sha512-NO1UO8941541CJl1BeOXi8a9dNKFK09Gnru5ZJqkm4Q3/WoQJtHvmwt0VX0SB9YCEwe7TfSSxDuaNmx6H2BAIQ==} dependencies: