diff --git a/example/babel.config.js b/example/babel.config.js index 3c25e5d9..0729213f 100644 --- a/example/babel.config.js +++ b/example/babel.config.js @@ -1,3 +1,12 @@ +const path = require("path"); +const pkg = require("../package.json"); + +const resolverConfig = { + extensions: [".ts", ".tsx", ".js", ".jsx", ".json"], + alias: { [pkg.name]: path.resolve(__dirname, "../src") }, +}; + module.exports = { presets: ["module:@react-native/babel-preset"], + plugins: [["module-resolver", resolverConfig]], }; diff --git a/example/metro.config.js b/example/metro.config.js index 892433a8..707004c0 100644 --- a/example/metro.config.js +++ b/example/metro.config.js @@ -1,4 +1,27 @@ +const path = require("path"); +const pkg = require("../package.json"); + const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config"); +const escape = require("escape-string-regexp"); +const exclusionList = require("metro-config/src/defaults/exclusionList"); + +const peerDependencies = Object.keys(pkg.peerDependencies); +const root = path.resolve(__dirname, ".."); +const projectNodeModules = path.join(__dirname, "node_modules"); +const rootNodeModules = path.join(root, "node_modules"); + +// We need to make sure that only one version is loaded for peerDependencies +// So we block them at the root, and alias them to the versions in example's node_modules +const blacklistRE = exclusionList( + peerDependencies.map( + (name) => new RegExp(`^${escape(path.join(rootNodeModules, name))}\\/.*$`), + ), +); + +const extraNodeModules = peerDependencies.reduce((acc, name) => { + acc[name] = path.join(projectNodeModules, name); + return acc; +}, {}); /** * Metro configuration @@ -6,6 +29,10 @@ const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config"); * * @type {import('metro-config').MetroConfig} */ -const config = {}; +const config = { + projectRoot: __dirname, + watchFolders: [root], + resolver: { blacklistRE, extraNodeModules }, +}; module.exports = mergeConfig(getDefaultConfig(__dirname), config); diff --git a/example/package.json b/example/package.json index d0b137b9..09501322 100644 --- a/example/package.json +++ b/example/package.json @@ -6,10 +6,9 @@ "node": ">=18" }, "scripts": { - "clean-modules": "rm -rf ./node_modules/react-native-bootsplash/{example,node_modules}", "clean": "rm -rf ./node_modules ./ios/Pods", - "preinstall": "cd .. && yarn build && cd example", - "postinstall": "yarn clean-modules && pod-install", + "preinstall": "cd .. && yarn && yarn build && cd example", + "postinstall": "yarn pod-install", "start": "react-native start", "web": "webpack serve", "reinstall": "yarn clean && yarn install" @@ -19,7 +18,7 @@ "react-dom": "18.2.0", "react-native": "0.73.1", "react-native-bars": "2.4.2", - "react-native-bootsplash": "file:../", + "react-native-bootsplash": "link:../", "react-native-web": "0.19.10" }, "devDependencies": { @@ -30,6 +29,7 @@ "@react-native/metro-config": "^0.73.2", "@types/react": "^18.2.46", "babel-loader": "^9.1.3", + "babel-plugin-module-resolver": "^5.0.0", "html-webpack-plugin": "^5.6.0", "pod-install": "^0.1.39", "react-native-web-image-loader": "^0.1.1", diff --git a/example/tsconfig.json b/example/tsconfig.json index 9663ce16..0510031e 100644 --- a/example/tsconfig.json +++ b/example/tsconfig.json @@ -21,8 +21,12 @@ "noImplicitReturns": false, "noUncheckedIndexedAccess": true, "noUnusedLocals": true, - "noUnusedParameters": true + "noUnusedParameters": true, + + "paths": { + "react-native-bootsplash": ["../src"] + } }, - "include": ["**/*.ts", "**/*.tsx"], + "include": ["src"], "exclude": ["node_modules", "babel.config.js", "metro.config.js"] } diff --git a/example/yarn.lock b/example/yarn.lock index 65a8c859..aced372f 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -2230,6 +2230,17 @@ babel-loader@^9.1.3: find-cache-dir "^4.0.0" schema-utils "^4.0.0" +babel-plugin-module-resolver@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/babel-plugin-module-resolver/-/babel-plugin-module-resolver-5.0.0.tgz#2b7fc176bd55da25f516abf96015617b4f70fc73" + integrity sha512-g0u+/ChLSJ5+PzYwLwP8Rp8Rcfowz58TJNCe+L/ui4rpzE/mg//JVX0EWBUYoxaextqnwuGHzfGp2hh0PPV25Q== + dependencies: + find-babel-config "^2.0.0" + glob "^8.0.3" + pkg-up "^3.1.0" + reselect "^4.1.7" + resolve "^1.22.1" + babel-plugin-polyfill-corejs2@^0.4.7: version "0.4.7" resolved "https://registry.yarnpkg.com/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.7.tgz#679d1b94bf3360f7682e11f2cb2708828a24fe8c" @@ -2374,6 +2385,13 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + braces@^3.0.2, braces@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" @@ -3337,6 +3355,14 @@ finalhandler@1.2.0: statuses "2.0.1" unpipe "~1.0.0" +find-babel-config@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/find-babel-config/-/find-babel-config-2.0.0.tgz#a8216f825415a839d0f23f4d18338a1cc966f701" + integrity sha512-dOKT7jvF3hGzlW60Gc3ONox/0rRZ/tz7WCil0bqA1In/3I8f1BctpXahRnEKDySZqci7u+dqq93sZST9fOJpFw== + dependencies: + json5 "^2.1.1" + path-exists "^4.0.0" + find-cache-dir@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-2.1.0.tgz#8d0f94cd13fe43c6c7c261a0d86115ca918c05f7" @@ -3517,6 +3543,17 @@ glob@^7.1.1, glob@^7.1.3: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^8.0.3: + version "8.1.0" + resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e" + integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^5.0.1" + once "^1.3.0" + globals@^11.1.0: version "11.12.0" resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" @@ -4110,7 +4147,7 @@ json-schema-traverse@^1.0.0: resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2" integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug== -json5@^2.1.2, json5@^2.2.3: +json5@^2.1.1, json5@^2.1.2, json5@^2.2.3: version "2.2.3" resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283" integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg== @@ -4558,6 +4595,13 @@ minimatch@^3.0.2, minimatch@^3.1.1: dependencies: brace-expansion "^1.1.7" +minimatch@^5.0.1: + version "5.1.6" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96" + integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g== + dependencies: + brace-expansion "^2.0.1" + minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.6: version "1.2.8" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" @@ -4973,6 +5017,13 @@ pkg-dir@^7.0.0: dependencies: find-up "^6.3.0" +pkg-up@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-3.1.0.tgz#100ec235cc150e4fd42519412596a28512a0def5" + integrity sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA== + dependencies: + find-up "^3.0.0" + pod-install@^0.1.39: version "0.1.39" resolved "https://registry.yarnpkg.com/pod-install/-/pod-install-0.1.39.tgz#853a0585bafbd332c2ca6543854fd4919958cfb3" @@ -5177,17 +5228,9 @@ react-native-bars@2.4.2: resolved "https://registry.yarnpkg.com/react-native-bars/-/react-native-bars-2.4.2.tgz#7a9bf5122b7dbc9a16a5170733b5461afa233d85" integrity sha512-0tyLiiRkT6/HGTDg5VZa+W9fKSYV/Hk0OuRuBkl91emBAeO56QDHKyCXGlqgzPMR5P120nwjxnlsAG9g78//Hg== -"react-native-bootsplash@file:..": - version "5.2.1" - dependencies: - detect-indent "^6.1.0" - fs-extra "^11.2.0" - node-html-parser "^6.1.12" - picocolors "^1.0.0" - prettier "^3.1.1" - sharp "^0.32.6" - ts-dedent "^2.2.0" - xml-formatter "^3.6.0" +"react-native-bootsplash@link:..": + version "0.0.0" + uid "" react-native-web-image-loader@^0.1.1: version "0.1.1" @@ -5410,6 +5453,11 @@ requires-port@^1.0.0: resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" integrity sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ== +reselect@^4.1.7: + version "4.1.8" + resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.1.8.tgz#3f5dc671ea168dccdeb3e141236f69f02eaec524" + integrity sha512-ab9EmR80F/zQTMNeneUr4cv+jSwPJgIlvEmVwLerwrWVbpLlBuls9XHzIeTFy4cegU2NHBp3va0LKOzU5qFEYQ== + resolve-cwd@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-3.0.0.tgz#0f0075f1bb2544766cf73ba6a6e2adfebcb13f2d" @@ -5427,7 +5475,7 @@ resolve-from@^5.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== -resolve@^1.14.2, resolve@^1.20.0: +resolve@^1.14.2, resolve@^1.20.0, resolve@^1.22.1: version "1.22.8" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d" integrity sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw== diff --git a/package.json b/package.json index 6a9b9fd7..3cfba92a 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "*": "prettier -u -w" }, "peerDependencies": { + "react": ">=18.1.0", "react-native": ">=0.70.0" }, "dependencies": { diff --git a/tsconfig.json b/tsconfig.json index c9599d40..968b88da 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,6 +23,6 @@ "noUnusedLocals": true, "noUnusedParameters": true }, - "include": ["src/**/*.ts", "src/**/*.tsx"], - "exclude": ["node_modules"] + "include": ["src"], + "exclude": ["example", "node_modules"] }