Skip to content

Commit 6423792

Browse files
committed
chore: move vue version to detector
1 parent 81a56d8 commit 6423792

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

detectors/vue.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{
1+
{
22
"html": "<[^>]+\\sdata-v(?:ue)?-",
3-
"js": "window.Vue || window.$nuxt || [...document.querySelectorAll('*')].map((el) => Boolean(el.__vue__)).filter(Boolean).length",
3+
"js": "(window.Vue && window.Vue.version) || window.$nuxt || [...document.querySelectorAll('*')].map((el) => Boolean(el.__vue__)).filter(Boolean).length",
44
"script": [
55
"vue[.-]([\\d.]*\\d)[^/]*\\.js\\;version:\\1",
66
"(?:/([\\d.]+))?/vue(?:\\.min)?\\.js\\;version:\\1"

detectors/vue.meta.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"version": {
3+
"eval": "(window.$nuxt && window.$nuxt.$root && window.$nuxt.$root.constructor.version) || (window.Vue && window.Vue.version) || [...document.querySelectorAll('*')].map((el) => el.__vue__ && el.__vue__.$root && el.__vue__.$root.constructor.version).filter(Boolean)[0]"
4+
},
25
"ssr": {
36
"originalHtml": "<div [^>]*data-server-rendered=\"true\"",
47
"html": [

src/detectors.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ const detectors = {
1313
}
1414

1515
exports.hasVue = function (context) {
16-
return isMatching(detectors.vue, context)
16+
return match(detectors.vue, context)
1717
}
1818

1919
exports.getVueMeta = async function(context) {
2020
const meta = {}
2121
await Promise.all(
2222
Object.keys(detectors.meta).map(async (key) => {
23-
meta[key] = await isMatching(detectors.meta[key], context)
23+
meta[key] = await match(detectors.meta[key], context)
2424
})
2525
)
2626
return meta
2727
}
2828

2929
exports.getFramework = async function (context) {
3030
for (const framework of Object.keys(detectors.frameworks)) {
31-
if (await isMatching(detectors.frameworks[framework].detectors, context)) {
31+
if (await match(detectors.frameworks[framework].detectors, context)) {
3232
return detectors.frameworks[framework].metas
3333
}
3434
}
@@ -37,7 +37,7 @@ exports.getFramework = async function (context) {
3737

3838
exports.getUI = async function (context) {
3939
for (const ui of Object.keys(detectors.uis)) {
40-
if (await isMatching(detectors.uis[ui].detectors, context)) {
40+
if (await match(detectors.uis[ui].detectors, context)) {
4141
return detectors.uis[ui].metas
4242
}
4343
}
@@ -49,7 +49,7 @@ exports.getPlugins = async function (context) {
4949

5050
await Promise.all(
5151
Object.keys(detectors.plugins).map(async (plugin) => {
52-
if (await isMatching(detectors.plugins[plugin].detectors, context)) {
52+
if (await match(detectors.plugins[plugin].detectors, context)) {
5353
plugins.add(detectors.plugins[plugin].metas)
5454
}
5555
})
@@ -63,7 +63,7 @@ exports.getNuxtMeta = async function (context) {
6363

6464
await Promise.all(
6565
Object.keys(detectors.nuxt.meta).map(async (key) => {
66-
meta[key] = await isMatching(detectors.nuxt.meta[key], context)
66+
meta[key] = await match(detectors.nuxt.meta[key], context)
6767
})
6868
)
6969

@@ -75,7 +75,7 @@ exports.getNuxtModules = async function (context) {
7575

7676
await Promise.all(
7777
Object.keys(detectors.nuxt.modules).map(async (name) => {
78-
if (await isMatching(detectors.nuxt.modules[name].detectors, context)) {
78+
if (await match(detectors.nuxt.modules[name].detectors, context)) {
7979
modules.add(detectors.nuxt.modules[name].metas)
8080
}
8181
})
@@ -84,7 +84,15 @@ exports.getNuxtModules = async function (context) {
8484
return Array.from(modules)
8585
}
8686

87-
async function isMatching (detector, { originalHtml, html, scripts, page }) {
87+
async function match (detector, { originalHtml, html, scripts, page }) {
88+
// JS eval (for string value)
89+
if (detector.eval) {
90+
for (const js of asArray(detector.eval)) {
91+
const value = await page.evaluate(js)
92+
if (value) return value
93+
}
94+
return null
95+
}
8896
// If we can detect technology from response html
8997
if (detector.originalHtml) {
9098
for (const pattern of parsePatterns(detector.originalHtml)) {

src/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,9 @@ module.exports = async function (originalUrl) {
135135
infos.meta.language = matches[1].split('-')[0]
136136
}
137137

138-
// Get Vue version
139-
const version = await page.evaluate('(window.$nuxt && window.$nuxt.$root && window.$nuxt.$root.constructor.version) || (window.Vue && window.Vue.version) || [...document.querySelectorAll("*")].map((el) => el.__vue__ && el.__vue__.$root && el.__vue__.$root.constructor.version).filter(Boolean)[0]')
140-
if (version) {
141-
infos.vueVersion = version
142-
}
143-
144138
// Get Vue metas
145-
const { ssr } = await getVueMeta(context)
139+
const { ssr, version } = await getVueMeta(context)
140+
infos.vueVersion = version
146141
infos.hasSSR = ssr
147142

148143
// Get Vue ecosystem infos

0 commit comments

Comments
 (0)