Skip to content

Commit

Permalink
fix: rm NodeJS type from core, rm react core peer (#681)
Browse files Browse the repository at this point in the history
* remove a NodeJS type from core module which needs to be platform
agnostic
* remove core peer dep from react sdk, which gets core through web-sdk

---------

Signed-off-by: Todd Baert <[email protected]>
Co-authored-by: Michael Beemer <[email protected]>
  • Loading branch information
toddbaert and beeme1mr authored Nov 27, 2023
1 parent 5845370 commit 09ff7b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"publish-all": "npm run publish-if-not-exists --workspace=packages/shared --workspace=packages/server --workspace=packages/client --workspace=packages/react",
"docs": "typedoc",
"core-version": "npm run version --workspace=packages/shared",
"update-core-peers": "export OPENFEATURE_CORE_VERSION=$(npm run --silent core-version) && npm run update-core-peer --workspace=packages/server --workspace=packages/client --workspace=packages/react"
"update-core-peers": "export OPENFEATURE_CORE_VERSION=$(npm run --silent core-version) && npm run update-core-peer --workspace=packages/server --workspace=packages/client"
},
"repository": {
"type": "git",
Expand Down
6 changes: 2 additions & 4 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"postbuild": "shx cp ./../../package.esm.json ./dist/esm/package.json",
"current-version": "echo $npm_package_version",
"prepack": "shx cp ./../../LICENSE ./LICENSE",
"publish-if-not-exists": "cp $NPM_CONFIG_USERCONFIG .npmrc && if [ \"$(npm show $npm_package_name@$npm_package_version version)\" = \"$(npm run current-version -s)\" ]; then echo 'already published, skipping'; else npm publish --access public; fi",
"update-core-peer": "npm install --save-peer --save-exact @openfeature/core@$OPENFEATURE_CORE_VERSION"
"publish-if-not-exists": "cp $NPM_CONFIG_USERCONFIG .npmrc && if [ \"$(npm show $npm_package_name@$npm_package_version version)\" = \"$(npm run current-version -s)\" ]; then echo 'already published, skipping'; else npm publish --access public; fi"
},
"repository": {
"type": "git",
Expand All @@ -47,12 +46,11 @@
},
"homepage": "https://github.com/open-feature/js-sdk#readme",
"peerDependencies": {
"@openfeature/core": "0.0.19",
"@openfeature/web-sdk": ">=0.4.0",
"react": ">=18.0.0"
},
"devDependencies": {
"@openfeature/core": "0.0.19",
"@openfeature/core": "*",
"@openfeature/web-sdk": "*"
}
}
27 changes: 26 additions & 1 deletion packages/shared/src/events/generic-event-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ProviderEvents } from './events';
export abstract class GenericEventEmitter<AdditionalContext extends Record<string, unknown> = Record<string, unknown>>
implements ManageLogger<GenericEventEmitter<AdditionalContext>>
{
protected abstract readonly eventEmitter: NodeJS.EventEmitter;
protected abstract readonly eventEmitter: PlatformEventEmitter;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private readonly _handlers = new WeakMap<EventHandler<any>, EventHandler<any>>();
Expand Down Expand Up @@ -64,4 +64,29 @@ export abstract class GenericEventEmitter<AdditionalContext extends Record<strin
protected get _logger() {
return this._eventLogger ?? this.globalLogger?.();
}
}

/**
* This is an un-exported type that corresponds to NodeJS.EventEmitter.
* We can't use that type here, because this module is used in both the browser, and the server.
* In the server, node (or whatever server runtime) provides an implementation for this.
* In the browser, we bundle in the popular 'events' package, which is a polyfill of NodeJS.EventEmitter.
*/
/* eslint-disable */
interface PlatformEventEmitter {
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
removeAllListeners(event?: string | symbol): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
listeners(eventName: string | symbol): Function[];
rawListeners(eventName: string | symbol): Function[];
emit(eventName: string | symbol, ...args: any[]): boolean;
listenerCount(eventName: string | symbol, listener?: Function): number;
prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
eventNames(): Array<string | symbol>;
}

0 comments on commit 09ff7b4

Please sign in to comment.