Skip to content

Commit

Permalink
chore: setup CustomEvent polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
danisharora099 committed Oct 10, 2024
1 parent a50fcac commit d8c0b34
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 2 deletions.
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"packages/tests",
"packages/browser-tests",
"packages/build-utils",
"packages/react-native-polyfills"
"packages/react-native-polyfills",
"packages/custom-event-polyfill"
],
"scripts": {
"prepare": "husky",
Expand Down
6 changes: 6 additions & 0 deletions packages/custom-event-polyfill/.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"
}
};
10 changes: 10 additions & 0 deletions packages/custom-event-polyfill/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

## 0.0.1 (2024-04-09)


### Features

* Add react-native polyfills ([#1915](https://github.com/waku-org/js-waku/issues/1915)) ([9be942f](https://github.com/waku-org/js-waku/commit/9be942fc23e1e6c1ed5775e44e0d77ec7627b38c))

## Changelog
43 changes: 43 additions & 0 deletions packages/custom-event-polyfill/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@waku/custom-event-polyfill",
"version": "0.0.1",
"description": "CustomEvent polyfill for environments that don't support it natively",
"module": "./dist/index.js",
"exports": {
".": "./dist/index.js"
},
"type": "module",
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/custom-event-polyfill#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",
"custom-event",
"polyfill",
"web3"
],
"scripts": {
"build": "tsc",
"check": "run-s check:*",
"check:tsc": "tsc -p tsconfig.dev.json",
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
"prepublish": "npm run build"
},
"engines": {
"node": ">=18"
},
"files": [
"dist",
"src/**/*.ts",
"!**/*.json",
"CHANGELOG.md",
"LICENSE",
"README.md"
]
}
12 changes: 12 additions & 0 deletions packages/custom-event-polyfill/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if (typeof CustomEvent === "undefined") {
class CustomEvent<T = unknown> extends Event {
public detail: T;

public constructor(type: string, eventInitDict?: CustomEventInit<T>) {
super(type, eventInitDict);
this.detail = eventInitDict?.detail ?? (null as T);
}
}

(globalThis as Record<string, unknown>).CustomEvent = CustomEvent;
}
3 changes: 3 additions & 0 deletions packages/custom-event-polyfill/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/custom-event-polyfill/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"]
}

0 comments on commit d8c0b34

Please sign in to comment.