From 38bc5ce2a3b353ffd37327a443ca46d166b7eb1f Mon Sep 17 00:00:00 2001 From: Angelo Ashmore Date: Fri, 11 Mar 2022 15:38:31 -1000 Subject: [PATCH] chore: support React Native's Metro bundler (#3) --- package-lock.json | 12 ++++++------ package.json | 1 + siroc.config.ts | 21 ++++++++++++++++++++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3a2c689..5c7d368 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6844,9 +6844,9 @@ "dev": true }, "node_modules/sort-package-json": { - "version": "1.53.1", - "resolved": "https://registry.npmjs.org/sort-package-json/-/sort-package-json-1.53.1.tgz", - "integrity": "sha512-ltLORrQuuPMpy23YkWCA8fO7zBOxM4P1j9LcGxci4K2Fk8jmSyCA/ATU6CFyy8qR2HQRx4RBYWzoi78FU/Anuw==", + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/sort-package-json/-/sort-package-json-1.54.0.tgz", + "integrity": "sha512-MA0nRiSfZ4/CNM/9rz70Hwq4PpvtBc3v532tzQSmoaLSdeBB3cCd488xmNruLL0fb/ZdbKlcaDDudwnrObbjBw==", "dev": true, "dependencies": { "detect-indent": "^6.0.0", @@ -13043,9 +13043,9 @@ "dev": true }, "sort-package-json": { - "version": "1.53.1", - "resolved": "https://registry.npmjs.org/sort-package-json/-/sort-package-json-1.53.1.tgz", - "integrity": "sha512-ltLORrQuuPMpy23YkWCA8fO7zBOxM4P1j9LcGxci4K2Fk8jmSyCA/ATU6CFyy8qR2HQRx4RBYWzoi78FU/Anuw==", + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/sort-package-json/-/sort-package-json-1.54.0.tgz", + "integrity": "sha512-MA0nRiSfZ4/CNM/9rz70Hwq4PpvtBc3v532tzQSmoaLSdeBB3cCd488xmNruLL0fb/ZdbKlcaDDudwnrObbjBw==", "dev": true, "requires": { "detect-indent": "^6.0.0", diff --git a/package.json b/package.json index 1749b3d..a618a65 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ }, "main": "dist/index.cjs", "module": "dist/index.mjs", + "react-native": "dist/index.js", "types": "dist/index.d.ts", "files": [ "dist", diff --git a/siroc.config.ts b/siroc.config.ts index d4474b7..640e399 100644 --- a/siroc.config.ts +++ b/siroc.config.ts @@ -1,4 +1,5 @@ -import { defineSirocConfig } from "siroc"; +import { defineSirocConfig, PackageJson } from "siroc"; +import fs from "fs"; export default defineSirocConfig({ rollup: { @@ -6,4 +7,22 @@ export default defineSirocConfig({ sourcemap: true, }, }, + hooks: { + "build:done": (pkg) => { + // Type assertion is needed to add the `react-native` + // key. It is non-standard and not included in + // `siroc`'s built-in types. + const packageJson = pkg.pkg as PackageJson & { + ["react-native"]?: string; + }; + + if ( + packageJson.module && + packageJson["react-native"] && + pkg.pkg.module !== packageJson["react-native"] + ) { + fs.copyFileSync(packageJson.module, packageJson["react-native"]); + } + }, + }, });