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

Add missing plugin warnings #4158

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
})
})
}
Loading