Skip to content

Commit

Permalink
Add missing plugin warnings (#4158)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed Apr 18, 2024
1 parent b1fff5d commit 816971b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/alpinejs/src/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export function directive(name, callback) {
}
}

export function directiveExists(name) {
return Object.keys(directiveHandlers).includes(name)
}

export function directives(el, attributes, originalAttributeOverride) {
attributes = Array.from(attributes)

Expand Down
26 changes: 25 additions & 1 deletion packages/alpinejs/src/lifecycle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { startObservingMutations, onAttributesAdded, onElAdded, onElRemoved, cleanupAttributes, cleanupElement } from "./mutation"
import { deferHandlingDirectives, directives } from "./directives"
import { deferHandlingDirectives, directiveExists, directives } from "./directives"
import { dispatch } from './utils/dispatch'
import { walk } from "./utils/walk"
import { warn } from './utils/warn'
Expand Down Expand Up @@ -33,6 +33,10 @@ export function start() {
})

dispatch(document, 'alpine:initialized')

setTimeout(() => {
warnAboutMissingPlugins()
})
}

let rootSelectorCallbacks = []
Expand Down Expand Up @@ -98,3 +102,23 @@ export function destroyTree(root, walker = walk) {
cleanupElement(el)
})
}

function warnAboutMissingPlugins() {
let pluginDirectives = [
[ 'ui', 'dialog', ['[x-dialog], [x-popover]'] ],
[ 'anchor', 'anchor', ['[x-anchor]'] ],
[ 'sort', 'sort', ['[x-sort]'] ],
]

pluginDirectives.forEach(([ plugin, directive, selectors ]) => {
if (directiveExists(directive)) return

selectors.some(selector => {
if (document.querySelector(selector)) {
warn(`found "${selector}", but missing ${plugin} plugin`)

return true
}
})
})
}

0 comments on commit 816971b

Please sign in to comment.