Skip to content

Commit

Permalink
Merge pull request #157 from jpudysz/feature/plugins
Browse files Browse the repository at this point in the history
chore: stop throwing errors for duplicated plugins in dev mode
  • Loading branch information
jpudysz authored Mar 4, 2024
2 parents 3fe06d1 + 7e5ef54 commit 51bae80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const isIOS = Platform.OS === 'ios'
export const isAndroid = Platform.OS === 'android'
export const isMobile = isIOS || isAndroid
export const isServer = typeof window === 'undefined'
export const isDev = process.env.NODE_ENV !== 'production'

export const ScreenOrientation = {
Landscape: 'landscape',
Expand Down
16 changes: 11 additions & 5 deletions src/core/UnistyleRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UnistylesBridge, UnistylesConfig, UnistylesPlugin } from '../types'
import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
import { isWeb, UnistylesError } from '../common'
import { isDev, isWeb, UnistylesError } from '../common'
import { cssMediaQueriesPlugin, normalizeWebStylesPlugin } from '../plugins'

export class UnistyleRegistry {
Expand Down Expand Up @@ -87,12 +87,18 @@ export class UnistyleRegistry {
throw new Error(UnistylesError.InvalidPluginName)
}

if (this.plugins.some(({ name }) => name === plugin.name)) {
throw new Error(UnistylesError.DuplicatePluginName)
const isAlreadyRegistered = this.plugins.some(({ name }) => name === plugin.name)

if (!isAlreadyRegistered) {
this.plugins = [plugin].concat(this.plugins)
this.unistylesBridge.addPlugin(plugin.name, notify)

return
}

this.plugins = [plugin].concat(this.plugins)
this.unistylesBridge.addPlugin(plugin.name, notify)
if (!isDev) {
throw new Error(UnistylesError.DuplicatePluginName)
}
}

public removePlugin = (plugin: UnistylesPlugin) => {
Expand Down

0 comments on commit 51bae80

Please sign in to comment.