Skip to content

Commit a9725dd

Browse files
authored
feat: ui detectors priority (#68)
1 parent 8a55838 commit a9725dd

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

detectors/uis.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"detectors": {
1010
"js": [
1111
"[...document.querySelectorAll('*')].map((el) => Boolean(el.__vue__?.$options.isOruga)).filter(Boolean).length",
12-
"[...document.querySelectorAll('*')].map((el) => Boolean(el.__vueParentComponent?.ctx.$options.isOruga)).filter(Boolean).length"
12+
"[...document.querySelectorAll('*')].map((el) => Boolean(el.__vue_app__?.config?.globalProperties?.$oruga)).filter(Boolean).length"
1313
]
1414
}
1515
},
@@ -69,7 +69,8 @@
6969
"<link [^>]*href=\"[^\"]+tailwindcss(?:\\.min)?\\.css",
7070
"<(?:div|button|a) [^>]*class=\"[^\"]*(?:sm:|md:|lg:|xl:|hover:|active:|focus:|disabled:|visited:|first:|last:|odd:|even:|group-hover:|focus-within:)"
7171
]
72-
}
72+
},
73+
"priority": -1
7374
},
7475
"buefy": {
7576
"metas": {

src/detectors.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@ exports.getFramework = async function (context) {
3636
}
3737

3838
exports.getUI = async function (context) {
39-
for (const ui of Object.keys(detectors.uis)) {
40-
if (await isMatching(detectors.uis[ui].detectors, context)) {
41-
return detectors.uis[ui].metas
42-
}
43-
}
44-
return null
39+
const uis = new Set()
40+
41+
await Promise.all(
42+
Object.keys(detectors.uis).map(async (ui) => {
43+
if (await isMatching(detectors.uis[ui].detectors, context)) {
44+
uis.add(detectors.uis[ui])
45+
}
46+
})
47+
)
48+
49+
return Array.from(uis).sort((a, b) => (b.priority ?? 1) - (a.priority ?? 1))[0]
4550
}
4651

4752
exports.getPlugins = async function (context) {

0 commit comments

Comments
 (0)