Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add react-native polyfills #1915

Merged
merged 13 commits into from
Apr 2, 2024
2 changes: 1 addition & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
pre-release:
name: pre-release
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master'
if: github.event_name == 'workflow_dispatch'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side change to allow publishing from other branches

steps:
- uses: actions/checkout@v3
with:
Expand Down
60,262 changes: 39,316 additions & 20,946 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"packages/sdk",
"packages/tests",
"packages/browser-tests",
"packages/build-utils"
"packages/build-utils",
"packages/polyfills"
],
"scripts": {
"prepare": "husky install",
Expand Down
6 changes: 6 additions & 0 deletions packages/polyfills/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
parserOptions: {
tsconfigRootDir: __dirname,
project: "./tsconfig.dev.json"
}
};
1 change: 1 addition & 0 deletions packages/polyfills/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
Copy link
Collaborator

@danisharora099 danisharora099 Mar 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we need this file? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

63 changes: 63 additions & 0 deletions packages/polyfills/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@waku/polyfills",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waku-org/js-waku-developers how do you like the name? It is intended for ReactNative polyfilling.
I'd like to avoid long two worded names if possible.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, considering it's just for react-native, i would personally prefer to have that part of the package name for max verbosity

maybe in the future when we have different kinds of polyfills, this name would make more sense :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to react-native-polyfills

"version": "0.0.1",
"description": "Set of polyfills for Waku for React Native environment",
"module": "./dist/index.js",
"exports": {
".": "./dist/index.js",
"./metro": "./dist/metro.js"
},
"type": "module",
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/polyfills#readme",
"repository": {
"type": "git",
"url": "https://github.com/waku-org/js-waku.git"
},
"bugs": {
"url": "https://github.com/waku-org/js-waku/issues"
},
"license": "MIT OR Apache-2.0",
"keywords": [
"waku",
"decentralised",
"communication",
"web3",
"ethereum",
"dapps"
],
"scripts": {
"build": "run-s build:**",
"build:esm": "tsc",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important to note that rollup will not be bundling this package as bundling not needed and should be figured out by react-native application

"fix": "run-s fix:*",
"fix:lint": "eslint src *.js --fix",
"check": "run-s check:*",
"check:tsc": "tsc -p tsconfig.dev.json",
"check:lint": "eslint src *.js",
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
"prepublish": "npm run build"
},
"engines": {
"node": ">=18"
},
"dependencies": {
"event-target-polyfill": "^0.0.4",
"react-native-url-polyfill": "^2.0.0",
"text-encoding-polyfill": "^0.6.7"
},
"devDependencies": {
"expo": "~50.0.13"
},
"peerDependencies": {
"expo": "~50.0.13",
"react-native": "0.73.6"
},
"files": [
"dist",
"bundle",
"src/**/*.ts",
"!**/*.json",
"CHANGELOG.md",
"LICENSE",
"README.md"
]
}
3 changes: 3 additions & 0 deletions packages/polyfills/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import "event-target-polyfill";
import "text-encoding-polyfill";
import "react-native-url-polyfill/auto";
15 changes: 15 additions & 0 deletions packages/polyfills/src/metro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import path, { dirname } from "path";
import { fileURLToPath } from "url";

import type { MetroConfig } from "expo/metro-config";

const __dirname = dirname(fileURLToPath(import.meta.url));

type Writeable<T> = { -readonly [P in keyof T]: Writeable<T[P]> };

export function setupWakuMetroConfig(config: Writeable<MetroConfig>): void {
config.resolver.unstable_enablePackageExports = true;
config.resolver.extraNodeModules = {
url: path.resolve(__dirname, "node_modules", "react-native-url-polyfill")
};
}
3 changes: 3 additions & 0 deletions packages/polyfills/tsconfig.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.dev"
}
10 changes: 10 additions & 0 deletions packages/polyfills/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "dist/",
"rootDir": "src",
"tsBuildInfoFile": "dist/.tsbuildinfo"
},
"include": ["src"],
"exclude": ["src/**/*.spec.ts", "src/test_utils"]
}
3 changes: 2 additions & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"packages/message-encryption": {},
"packages/sdk": {},
"packages/relay": {},
"packages/discovery": {}
"packages/discovery": {},
"packages/polyfills": {}
}
}
Loading