mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-18 01:00:33 +03:00
chore: fix lint
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ import { hasMetaInfo } from './shared/meta-helpers'
|
||||
* Plugin install function.
|
||||
* @param {Function} Vue - the Vue constructor.
|
||||
*/
|
||||
function install(Vue, options = {}) {
|
||||
function install (Vue, options = {}) {
|
||||
if (Vue.__vuemeta_installed) {
|
||||
return
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ import { getOptions } from '../shared/options'
|
||||
import { pause, resume } from '../shared/pausing'
|
||||
import refresh from './refresh'
|
||||
|
||||
export default function _$meta(options = {}) {
|
||||
export default function _$meta (options = {}) {
|
||||
const _refresh = refresh(options)
|
||||
const inject = () => {}
|
||||
|
||||
@@ -12,7 +12,7 @@ export default function _$meta(options = {}) {
|
||||
* @this {Object} - the Vue instance (a root component)
|
||||
* @return {Object} - injector
|
||||
*/
|
||||
return function $meta() {
|
||||
return function $meta () {
|
||||
if (!this.$root._vueMeta) {
|
||||
return {
|
||||
getOptions: showWarningNotSupported,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { isFunction } from '../utils/is-type'
|
||||
import { clientSequences } from '../shared/escaping'
|
||||
import updateClientMetaInfo from './updateClientMetaInfo'
|
||||
|
||||
export default function _refresh(options = {}) {
|
||||
export default function _refresh (options = {}) {
|
||||
/**
|
||||
* When called, will update the current meta info with new meta info.
|
||||
* Useful when updating meta info as the result of an asynchronous
|
||||
@@ -14,7 +14,7 @@ export default function _refresh(options = {}) {
|
||||
*
|
||||
* @return {Object} - new meta info
|
||||
*/
|
||||
return function refresh() {
|
||||
return function refresh () {
|
||||
const metaInfo = getMetaInfo(options, this.$root, clientSequences)
|
||||
|
||||
const appId = this.$root._vueMeta.appId
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// store an id to keep track of DOM updates
|
||||
let batchId = null
|
||||
|
||||
export function triggerUpdate(vm, hookName) {
|
||||
export function triggerUpdate (vm, hookName) {
|
||||
// if an update was triggered during initialization or when an update was triggered by the
|
||||
// metaInfo watcher, set initialized to null
|
||||
// then we keep falsy value but know we need to run a triggerUpdate after initialization
|
||||
@@ -22,7 +22,7 @@ export function triggerUpdate(vm, hookName) {
|
||||
* @param {Function} callback - the update to perform
|
||||
* @return {Number} id - a new ID
|
||||
*/
|
||||
export function batchUpdate(callback, timeout = 10) {
|
||||
export function batchUpdate (callback, timeout = 10) {
|
||||
clearTimeout(batchId)
|
||||
|
||||
batchId = setTimeout(() => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { isArray } from '../utils/is-type'
|
||||
import { includes } from '../utils/array'
|
||||
import { updateAttribute, updateTag, updateTitle } from './updaters'
|
||||
|
||||
function getTag(tags, tag) {
|
||||
function getTag (tags, tag) {
|
||||
if (!tags[tag]) {
|
||||
tags[tag] = document.getElementsByTagName(tag)[0]
|
||||
}
|
||||
@@ -16,7 +16,7 @@ function getTag(tags, tag) {
|
||||
*
|
||||
* @param {Object} newInfo - the meta info to update to
|
||||
*/
|
||||
export default function updateClientMetaInfo(appId, options = {}, newInfo) {
|
||||
export default function updateClientMetaInfo (appId, options = {}, newInfo) {
|
||||
const { ssrAttribute } = options
|
||||
|
||||
// only cache tags for current update
|
||||
|
||||
@@ -8,7 +8,7 @@ import { isArray } from '../../utils/is-type'
|
||||
* @param {Object} attrs - the new document html attributes
|
||||
* @param {HTMLElement} tag - the HTMLElement tag to update with new attrs
|
||||
*/
|
||||
export default function updateAttribute({ attribute } = {}, attrs, tag) {
|
||||
export default function updateAttribute ({ attribute } = {}, attrs, tag) {
|
||||
const vueMetaAttrString = tag.getAttribute(attribute)
|
||||
const vueMetaAttrs = vueMetaAttrString ? vueMetaAttrString.split(',') : []
|
||||
const toRemove = toArray(vueMetaAttrs)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { booleanHtmlAttributes } from '../../shared/constants'
|
||||
import { isUndefined } from '../../utils/is-type'
|
||||
import { toArray, includes } from '../../utils/array'
|
||||
|
||||
/**
|
||||
@@ -10,7 +9,7 @@ import { toArray, includes } from '../../utils/array'
|
||||
* @param {(Array<Object>|Object)} tags - an array of tag objects or a single object in case of base
|
||||
* @return {Object} - a representation of what tags changed
|
||||
*/
|
||||
export default function updateTag(appId, { attribute, tagIDKeyName } = {}, type, tags, headTag, bodyTag) {
|
||||
export default function updateTag (appId, { attribute, tagIDKeyName } = {}, type, tags, headTag, bodyTag) {
|
||||
const oldHeadTags = toArray(headTag.querySelectorAll(`${type}[${attribute}="${appId}"], ${type}[data-${tagIDKeyName}]`))
|
||||
const oldBodyTags = toArray(bodyTag.querySelectorAll(`${type}[${attribute}="${appId}"][data-body="true"], ${type}[data-${tagIDKeyName}][data-body="true"]`))
|
||||
const dataAttributes = [tagIDKeyName, 'body']
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* @param {String} title - the new title of the document
|
||||
*/
|
||||
export default function updateTitle(title) {
|
||||
export default function updateTitle (title) {
|
||||
if (title === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import { hasMetaInfo } from './shared/meta-helpers'
|
||||
* Plugin install function.
|
||||
* @param {Function} Vue - the Vue constructor.
|
||||
*/
|
||||
function install(Vue, options = {}) {
|
||||
function install (Vue, options = {}) {
|
||||
if (Vue.__vuemeta_installed) {
|
||||
return
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ import { pause, resume } from '../shared/pausing'
|
||||
import refresh from '../client/refresh'
|
||||
import inject from './inject'
|
||||
|
||||
export default function _$meta(options = {}) {
|
||||
export default function _$meta (options = {}) {
|
||||
const _refresh = refresh(options)
|
||||
const _inject = inject(options)
|
||||
|
||||
@@ -12,7 +12,7 @@ export default function _$meta(options = {}) {
|
||||
* @this {Object} - the Vue instance (a root component)
|
||||
* @return {Object} - injector
|
||||
*/
|
||||
return function $meta() {
|
||||
return function $meta () {
|
||||
return {
|
||||
getOptions: () => getOptions(options),
|
||||
refresh: _refresh.bind(this),
|
||||
|
||||
@@ -9,7 +9,7 @@ import { titleGenerator, attributeGenerator, tagGenerator } from './generators'
|
||||
* @return {Object} - the new injector
|
||||
*/
|
||||
|
||||
export default function generateServerInjector(appId, options, type, data) {
|
||||
export default function generateServerInjector (appId, options, type, data) {
|
||||
if (type === 'title') {
|
||||
return titleGenerator(appId, options, type, data)
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import { isUndefined, isArray } from '../../utils/is-type'
|
||||
* @param {Object} data - the attributes to generate
|
||||
* @return {Object} - the attribute generator
|
||||
*/
|
||||
export default function attributeGenerator({ attribute } = {}, type, data) {
|
||||
export default function attributeGenerator ({ attribute } = {}, type, data) {
|
||||
return {
|
||||
text() {
|
||||
text () {
|
||||
let attributeStr = ''
|
||||
const watchedAttrs = []
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { booleanHtmlAttributes, tagsWithoutEndTag, tagsWithInnerContent, tagAttributeAsInnerContent } from '../../shared/constants'
|
||||
import { isUndefined } from '../../utils/is-type'
|
||||
|
||||
/**
|
||||
* Generates meta, base, link, style, script, noscript tags for use on the server
|
||||
@@ -8,9 +7,9 @@ import { isUndefined } from '../../utils/is-type'
|
||||
* @param {(Array<Object>|Object)} tags - an array of tag objects or a single object in case of base
|
||||
* @return {Object} - the tag generator
|
||||
*/
|
||||
export default function tagGenerator(appId, { attribute, tagIDKeyName } = {}, type, tags) {
|
||||
export default function tagGenerator (appId, { attribute, tagIDKeyName } = {}, type, tags) {
|
||||
return {
|
||||
text({ body = false } = {}) {
|
||||
text ({ body = false } = {}) {
|
||||
// build a string containing all tags of this type
|
||||
return tags.reduce((tagsStr, tag) => {
|
||||
const tagKeys = Object.keys(tag)
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
* @param {String} data - the title text
|
||||
* @return {Object} - the title generator
|
||||
*/
|
||||
export default function titleGenerator(appId, { attribute } = {}, type, data) {
|
||||
export default function titleGenerator (appId, { attribute } = {}, type, data) {
|
||||
return {
|
||||
text() {
|
||||
text () {
|
||||
return `<${type}>${data}</${type}>`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { metaInfoOptionKeys } from '../shared/constants'
|
||||
import { serverSequences } from '../shared/escaping'
|
||||
import generateServerInjector from './generateServerInjector'
|
||||
|
||||
export default function _inject(options = {}) {
|
||||
export default function _inject (options = {}) {
|
||||
/**
|
||||
* Converts the state of the meta info object such that each item
|
||||
* can be compiled to a tag string on the server
|
||||
@@ -11,7 +11,7 @@ export default function _inject(options = {}) {
|
||||
* @this {Object} - Vue instance - ideally the root component
|
||||
* @return {Object} - server meta info with `toString` methods
|
||||
*/
|
||||
return function inject() {
|
||||
return function inject () {
|
||||
// get meta info with sensible defaults
|
||||
const metaInfo = getMetaInfo(options, this.$root, serverSequences)
|
||||
|
||||
|
||||
@@ -12,14 +12,14 @@ export const serverSequences = [
|
||||
|
||||
export const clientSequences = [
|
||||
[/&/g, '\u0026'],
|
||||
[/</g, '\u003c'],
|
||||
[/>/g, '\u003e'],
|
||||
[/</g, '\u003C'],
|
||||
[/>/g, '\u003E'],
|
||||
[/"/g, '\u0022'],
|
||||
[/'/g, '\u0027']
|
||||
]
|
||||
|
||||
// sanitizes potentially dangerous characters
|
||||
export function escape(info, options, escapeOptions) {
|
||||
export function escape (info, options, escapeOptions) {
|
||||
const { tagIDKeyName } = options
|
||||
const { doEscape = v => v } = escapeOptions
|
||||
const escaped = {}
|
||||
|
||||
@@ -18,7 +18,7 @@ import { inMetaInfoBranch } from './meta-helpers'
|
||||
* @param {Object} [result={}] - result so far
|
||||
* @return {Object} result - final aggregated result
|
||||
*/
|
||||
export default function getComponentOption(options = {}, component, result = {}) {
|
||||
export default function getComponentOption (options = {}, component, result = {}) {
|
||||
const { keyName, metaTemplateKeyName, tagIDKeyName } = options
|
||||
const { $options, $children } = component
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import getComponentOption from './getComponentOption'
|
||||
* @param {Object} component - the Vue instance to get meta info from
|
||||
* @return {Object} - returned meta info
|
||||
*/
|
||||
export default function getMetaInfo(options = {}, component, escapeSequences = []) {
|
||||
export default function getMetaInfo (options = {}, component, escapeSequences = []) {
|
||||
// collect & aggregate all metaInfo $options
|
||||
let info = getComponentOption(options, component, defaultInfo)
|
||||
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ import { findIndex } from '../utils/array'
|
||||
import { applyTemplate } from './template'
|
||||
import { metaInfoAttributeKeys, booleanHtmlAttributes } from './constants'
|
||||
|
||||
export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, contentKeyName }, target, source) {
|
||||
export function arrayMerge ({ component, tagIDKeyName, metaTemplateKeyName, contentKeyName }, target, source) {
|
||||
// we concat the arrays without merging objects contained in,
|
||||
// but we check for a `vmid` property on each object in the array
|
||||
// using an O(1) lookup associative array exploit
|
||||
@@ -65,7 +65,7 @@ export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, conte
|
||||
return destination.concat(source)
|
||||
}
|
||||
|
||||
export function merge(target, source, options = {}) {
|
||||
export function merge (target, source, options = {}) {
|
||||
// remove properties explicitly set to false so child components can
|
||||
// optionally _not_ overwrite the parents content
|
||||
// (for array properties this is checked in arrayMerge)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { isUndefined, isObject } from '../utils/is-type'
|
||||
|
||||
// Vue $root instance has a _vueMeta object property, otherwise its a boolean true
|
||||
export function hasMetaInfo(vm = this) {
|
||||
export function hasMetaInfo (vm = this) {
|
||||
return vm && (vm._vueMeta === true || isObject(vm._vueMeta))
|
||||
}
|
||||
|
||||
// a component is in a metaInfo branch when itself has meta info or one of its (grand-)children has
|
||||
export function inMetaInfoBranch(vm = this) {
|
||||
export function inMetaInfoBranch (vm = this) {
|
||||
return vm && !isUndefined(vm._vueMeta)
|
||||
}
|
||||
|
||||
+3
-3
@@ -6,16 +6,16 @@ import { addNavGuards } from './nav-guards'
|
||||
|
||||
let appId = 1
|
||||
|
||||
export default function createMixin(Vue, options) {
|
||||
export default function createMixin (Vue, options) {
|
||||
// for which Vue lifecycle hooks should the metaInfo be refreshed
|
||||
const updateOnLifecycleHook = ['activated', 'deactivated', 'beforeMount']
|
||||
|
||||
// watch for client side component updates
|
||||
return {
|
||||
beforeCreate() {
|
||||
beforeCreate () {
|
||||
Object.defineProperty(this, '_hasMetaInfo', {
|
||||
configurable: true,
|
||||
get() {
|
||||
get () {
|
||||
// Show deprecation warning once when devtools enabled
|
||||
if (Vue.config.devtools && !this.$root._vueMeta.hasMetaInfoDeprecationWarningShown) {
|
||||
console.warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead') // eslint-disable-line no-console
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { isFunction } from '../utils/is-type'
|
||||
|
||||
export function addNavGuards(vm) {
|
||||
export function addNavGuards (vm) {
|
||||
// return when nav guards already added or no router exists
|
||||
if (vm.$root._vueMeta.navGuards || !vm.$root.$router) {
|
||||
/* istanbul ignore next */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { isObject } from '../utils/is-type'
|
||||
import { defaultOptions } from './constants'
|
||||
|
||||
export function setOptions(options) {
|
||||
export function setOptions (options) {
|
||||
// combine options
|
||||
options = isObject(options) ? options : {}
|
||||
|
||||
@@ -14,7 +14,7 @@ export function setOptions(options) {
|
||||
return options
|
||||
}
|
||||
|
||||
export function getOptions(options) {
|
||||
export function getOptions (options) {
|
||||
const optionsCopy = {}
|
||||
for (const key in options) {
|
||||
optionsCopy[key] = options[key]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
export function pause(refresh = true) {
|
||||
export function pause (refresh = true) {
|
||||
this.$root._vueMeta.paused = true
|
||||
|
||||
return () => resume(refresh)
|
||||
}
|
||||
|
||||
export function resume(refresh = true) {
|
||||
export function resume (refresh = true) {
|
||||
this.$root._vueMeta.paused = false
|
||||
|
||||
if (refresh) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { isUndefined, isFunction } from '../utils/is-type'
|
||||
|
||||
export function applyTemplate({ component, metaTemplateKeyName, contentKeyName }, headObject, template, chunk) {
|
||||
export function applyTemplate ({ component, metaTemplateKeyName, contentKeyName }, headObject, template, chunk) {
|
||||
if (isUndefined(template)) {
|
||||
template = headObject[metaTemplateKeyName]
|
||||
delete headObject[metaTemplateKeyName]
|
||||
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
// which means the polyfills are removed for other build formats
|
||||
const polyfill = process.env.NODE_ENV === 'test'
|
||||
|
||||
export function findIndex(array, predicate) {
|
||||
export function findIndex (array, predicate) {
|
||||
if (polyfill && !Array.prototype.findIndex) {
|
||||
// idx needs to be a Number, for..in returns string
|
||||
for (let idx = 0; idx < array.length; idx++) {
|
||||
@@ -24,14 +24,14 @@ export function findIndex(array, predicate) {
|
||||
return array.findIndex(predicate, arguments[2])
|
||||
}
|
||||
|
||||
export function toArray(arg) {
|
||||
export function toArray (arg) {
|
||||
if (polyfill && !Array.from) {
|
||||
return Array.prototype.slice.call(arg)
|
||||
}
|
||||
return Array.from(arg)
|
||||
}
|
||||
|
||||
export function includes(array, value) {
|
||||
export function includes (array, value) {
|
||||
if (polyfill && !Array.prototype.includes) {
|
||||
for (const idx in array) {
|
||||
if (array[idx] === value) {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { isArray, isObject } from './is-type'
|
||||
|
||||
export function ensureIsArray(arg, key) {
|
||||
export function ensureIsArray (arg, key) {
|
||||
if (!key || !isObject(arg)) {
|
||||
return isArray(arg) ? arg : []
|
||||
}
|
||||
@@ -11,7 +11,7 @@ export function ensureIsArray(arg, key) {
|
||||
return arg
|
||||
}
|
||||
|
||||
export function ensuredPush(object, key, el) {
|
||||
export function ensuredPush (object, key, el) {
|
||||
ensureIsArray(object, key)
|
||||
|
||||
object[key].push(el)
|
||||
|
||||
@@ -3,22 +3,22 @@
|
||||
* @param {any} arg - the object to check
|
||||
* @return {Boolean} - true if `arg` is an array
|
||||
*/
|
||||
export function isArray(arg) {
|
||||
export function isArray (arg) {
|
||||
return Array.isArray(arg)
|
||||
}
|
||||
|
||||
export function isUndefined(arg) {
|
||||
export function isUndefined (arg) {
|
||||
return typeof arg === 'undefined'
|
||||
}
|
||||
|
||||
export function isObject(arg) {
|
||||
export function isObject (arg) {
|
||||
return typeof arg === 'object'
|
||||
}
|
||||
|
||||
export function isFunction(arg) {
|
||||
export function isFunction (arg) {
|
||||
return typeof arg === 'function'
|
||||
}
|
||||
|
||||
export function isString(arg) {
|
||||
export function isString (arg) {
|
||||
return typeof arg === 'string'
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { isUndefined } from './is-type'
|
||||
|
||||
export function hasGlobalWindowFn() {
|
||||
export function hasGlobalWindowFn () {
|
||||
try {
|
||||
return !isUndefined(window)
|
||||
} catch (e) {
|
||||
|
||||
@@ -23,9 +23,9 @@ describe(browserString, () => {
|
||||
|
||||
browser = await createBrowser(browserString, {
|
||||
BrowserStackLocal: { folder },
|
||||
extendPage(page) {
|
||||
extendPage (page) {
|
||||
return {
|
||||
async navigate(path) {
|
||||
async navigate (path) {
|
||||
// IMPORTANT: use (arrow) function with block'ed body
|
||||
// see: https://github.com/tunnckoCoreLabs/parse-function/issues/179
|
||||
await page.runAsyncScript((path) => {
|
||||
@@ -49,7 +49,7 @@ describe(browserString, () => {
|
||||
})
|
||||
}, path)
|
||||
},
|
||||
routeData() {
|
||||
routeData () {
|
||||
return page.runScript(() => ({
|
||||
path: window.$vueMeta.$route.path,
|
||||
query: window.$vueMeta.$route.query
|
||||
|
||||
Vendored
+1
-1
@@ -6,7 +6,7 @@ Vue.use(Router)
|
||||
|
||||
const Post = () => import('./views/about.vue')
|
||||
|
||||
export default function createRouter() {
|
||||
export default function createRouter () {
|
||||
return new Router({
|
||||
mode: 'hash',
|
||||
base: '/',
|
||||
|
||||
@@ -110,7 +110,7 @@ describe('client', () => {
|
||||
|
||||
const Component = Vue.extend({
|
||||
metaInfo: { title: 'Test' },
|
||||
render(h) {
|
||||
render (h) {
|
||||
return h('div', null, 'Test')
|
||||
}
|
||||
})
|
||||
@@ -157,10 +157,10 @@ describe('client', () => {
|
||||
localVue: Vue,
|
||||
mocks: {
|
||||
$router: {
|
||||
beforeEach(fn) {
|
||||
beforeEach (fn) {
|
||||
guards.before = fn
|
||||
},
|
||||
afterEach(fn) {
|
||||
afterEach (fn) {
|
||||
guards.after = fn
|
||||
}
|
||||
}
|
||||
@@ -192,10 +192,10 @@ describe('client', () => {
|
||||
localVue: Vue,
|
||||
mocks: {
|
||||
$router: {
|
||||
beforeEach(fn) {
|
||||
beforeEach (fn) {
|
||||
guards.before = fn
|
||||
},
|
||||
afterEach(fn) {
|
||||
afterEach (fn) {
|
||||
guards.after = fn
|
||||
}
|
||||
}
|
||||
@@ -225,21 +225,21 @@ describe('client', () => {
|
||||
// this component uses a computed prop to simulate a non-synchronous
|
||||
// metaInfo update like you would have with a Vuex mutation
|
||||
const Component = Vue.extend({
|
||||
data() {
|
||||
data () {
|
||||
return {
|
||||
hiddenTheme: 'light'
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
theme() {
|
||||
theme () {
|
||||
return this.hiddenTheme
|
||||
}
|
||||
},
|
||||
beforeMount() {
|
||||
beforeMount () {
|
||||
this.hiddenTheme = 'dark'
|
||||
},
|
||||
render: h => h('div'),
|
||||
metaInfo() {
|
||||
metaInfo () {
|
||||
return {
|
||||
htmlAttrs: {
|
||||
theme: this.theme
|
||||
@@ -270,21 +270,21 @@ describe('client', () => {
|
||||
document.body.appendChild(el)
|
||||
|
||||
const Component = Vue.extend({
|
||||
data() {
|
||||
data () {
|
||||
return {
|
||||
hiddenTheme: 'light'
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
theme() {
|
||||
theme () {
|
||||
return this.hiddenTheme
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
mounted () {
|
||||
this.hiddenTheme = 'dark'
|
||||
},
|
||||
render: h => h('div'),
|
||||
metaInfo() {
|
||||
metaInfo () {
|
||||
return {
|
||||
htmlAttrs: {
|
||||
theme: this.theme
|
||||
|
||||
@@ -23,7 +23,7 @@ describe('getComponentOption', () => {
|
||||
test('calls a function option, injecting the component as context', () => {
|
||||
const component = new Vue({
|
||||
name: 'Foobar',
|
||||
someFunc() {
|
||||
someFunc () {
|
||||
return { opt: this.$options.name }
|
||||
}
|
||||
})
|
||||
@@ -90,13 +90,13 @@ describe('getComponentOption', () => {
|
||||
|
||||
localVue.component('meta-child', {
|
||||
foo: { bar: 'baz' },
|
||||
render(h) {
|
||||
render (h) {
|
||||
return h('div', this.$slots.default)
|
||||
}
|
||||
})
|
||||
|
||||
localVue.component('nometa-child', {
|
||||
render(h) {
|
||||
render (h) {
|
||||
return h('div', this.$slots.default)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -208,7 +208,7 @@ describe('getMetaInfo', () => {
|
||||
{ charset: 'utf-8' }
|
||||
]
|
||||
},
|
||||
data() {
|
||||
data () {
|
||||
return {
|
||||
helloWorldText: 'Function World'
|
||||
}
|
||||
@@ -648,7 +648,7 @@ describe('getMetaInfo', () => {
|
||||
|
||||
test('no errors when metaInfo returns nothing', () => {
|
||||
const component = new Vue({
|
||||
metaInfo() {},
|
||||
metaInfo () {},
|
||||
el: document.createElement('div'),
|
||||
render: h => h('div', null, [])
|
||||
})
|
||||
|
||||
@@ -90,7 +90,7 @@ describe('plugin', () => {
|
||||
})
|
||||
|
||||
const Component = Vue.component('test-component', {
|
||||
metaInfo() {
|
||||
metaInfo () {
|
||||
return {
|
||||
title: this.title
|
||||
}
|
||||
@@ -161,7 +161,7 @@ describe('plugin', () => {
|
||||
})
|
||||
|
||||
const Component = Vue.component('test-component', {
|
||||
metaInfo() {
|
||||
metaInfo () {
|
||||
return {
|
||||
title: this.title
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ import puppeteer from 'puppeteer-core'
|
||||
import ChromeDetector from './chrome'
|
||||
|
||||
export default class Browser {
|
||||
constructor() {
|
||||
constructor () {
|
||||
this.detector = new ChromeDetector()
|
||||
}
|
||||
|
||||
async start(options = {}) {
|
||||
async start (options = {}) {
|
||||
// https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions
|
||||
const _opts = {
|
||||
args: [
|
||||
@@ -25,13 +25,13 @@ export default class Browser {
|
||||
this.browser = await puppeteer.launch(_opts)
|
||||
}
|
||||
|
||||
async close() {
|
||||
if (!this.browser) return
|
||||
async close () {
|
||||
if (!this.browser) { return }
|
||||
await this.browser.close()
|
||||
}
|
||||
|
||||
async page(url, globalName = 'vueMeta') {
|
||||
if (!this.browser) throw new Error('Please call start() before page(url)')
|
||||
async page (url, globalName = 'vueMeta') {
|
||||
if (!this.browser) { throw new Error('Please call start() before page(url)') }
|
||||
const page = await this.browser.newPage()
|
||||
|
||||
// pass on console messages
|
||||
@@ -69,7 +69,7 @@ export default class Browser {
|
||||
page.$vueMeta = await page.evaluateHandle(page.$globalHandle)
|
||||
|
||||
page.vueMeta = {
|
||||
async navigate(path, waitEnd = true) {
|
||||
async navigate (path, waitEnd = true) {
|
||||
const hook = page.evaluate(`
|
||||
new Promise(resolve =>
|
||||
${page.$globalHandle}.$once('routeChanged', resolve)
|
||||
@@ -85,7 +85,7 @@ export default class Browser {
|
||||
}
|
||||
return { hook }
|
||||
},
|
||||
routeData() {
|
||||
routeData () {
|
||||
return page.evaluate(($vueMeta) => {
|
||||
return {
|
||||
path: $vueMeta.$route.path,
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ import { createRenderer } from 'vue-server-renderer'
|
||||
|
||||
const renderer = createRenderer()
|
||||
|
||||
export function webpackRun(config) {
|
||||
export function webpackRun (config) {
|
||||
const compiler = webpack(config)
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -21,7 +21,7 @@ export function webpackRun(config) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function buildFixture(fixture, config = {}) {
|
||||
export async function buildFixture (fixture, config = {}) {
|
||||
if (!fixture) {
|
||||
throw new Error('buildFixture should be called with a fixture name')
|
||||
}
|
||||
@@ -69,7 +69,7 @@ export async function buildFixture(fixture, config = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
export function createWebpackConfig(config = {}) {
|
||||
export function createWebpackConfig (config = {}) {
|
||||
const publicPath = '.vue-meta'
|
||||
|
||||
return {
|
||||
|
||||
+12
-12
@@ -17,19 +17,19 @@ const newLineRegex = /\r?\n/
|
||||
* https://github.com/gwuhaolin/chrome-finder
|
||||
*/
|
||||
export default class ChromeDetector {
|
||||
constructor() {
|
||||
constructor () {
|
||||
this.platform = isWsl ? 'wsl' : process.platform
|
||||
}
|
||||
|
||||
detect(platform = this.platform) {
|
||||
detect (platform = this.platform) {
|
||||
const handler = this[platform]
|
||||
if (typeof handler !== 'function') {
|
||||
throw new Error(`${platform} is not supported.`)
|
||||
throw new TypeError(`${platform} is not supported.`)
|
||||
}
|
||||
return this[platform]()[0]
|
||||
}
|
||||
|
||||
darwin() {
|
||||
darwin () {
|
||||
const suffixes = [
|
||||
'/Contents/MacOS/Chromium',
|
||||
'/Contents/MacOS/Google Chrome Canary',
|
||||
@@ -88,7 +88,7 @@ export default class ChromeDetector {
|
||||
* 2. Look into the directories where .desktop are saved on gnome based distro's
|
||||
* 3. Look for google-chrome-stable & google-chrome executables by using the which command
|
||||
*/
|
||||
linux() {
|
||||
linux () {
|
||||
let installations = []
|
||||
// 1. Look into CHROME_PATH env variable
|
||||
const customChromePath = this.resolveChromePath()
|
||||
@@ -147,7 +147,7 @@ export default class ChromeDetector {
|
||||
return this.sort(uniq(installations.filter(Boolean)), priorities)
|
||||
}
|
||||
|
||||
wsl() {
|
||||
wsl () {
|
||||
// Manually populate the environment variables assuming it's the default config
|
||||
process.env.LOCALAPPDATA = this.getLocalAppDataPath(process.env.PATH)
|
||||
process.env.PROGRAMFILES = '/mnt/c/Program Files'
|
||||
@@ -155,7 +155,7 @@ export default class ChromeDetector {
|
||||
return this.win32()
|
||||
}
|
||||
|
||||
win32() {
|
||||
win32 () {
|
||||
const installations = []
|
||||
const sep = path.sep
|
||||
const suffixes = [
|
||||
@@ -185,7 +185,7 @@ export default class ChromeDetector {
|
||||
return installations
|
||||
}
|
||||
|
||||
resolveChromePath() {
|
||||
resolveChromePath () {
|
||||
if (this.canAccess(process.env.CHROME_PATH)) {
|
||||
return process.env.CHROME_PATH
|
||||
}
|
||||
@@ -198,13 +198,13 @@ export default class ChromeDetector {
|
||||
}
|
||||
}
|
||||
|
||||
getLocalAppDataPath(path) {
|
||||
getLocalAppDataPath (path) {
|
||||
const userRegExp = /\/mnt\/([a-z])\/Users\/([^/:]+)\/AppData\//
|
||||
const results = userRegExp.exec(path) || []
|
||||
return `/mnt/${results[1]}/Users/${results[2]}/AppData/Local`
|
||||
}
|
||||
|
||||
sort(installations, priorities) {
|
||||
sort (installations, priorities) {
|
||||
const defaultPriority = 10
|
||||
return installations
|
||||
.map((inst) => {
|
||||
@@ -219,7 +219,7 @@ export default class ChromeDetector {
|
||||
.map(pair => pair.path)
|
||||
}
|
||||
|
||||
canAccess(file) {
|
||||
canAccess (file) {
|
||||
if (!file) {
|
||||
return false
|
||||
}
|
||||
@@ -231,7 +231,7 @@ export default class ChromeDetector {
|
||||
}
|
||||
}
|
||||
|
||||
findChromeExecutables(folder) {
|
||||
findChromeExecutables (folder) {
|
||||
const argumentsRegex = /(^[^ ]+).*/ // Take everything up to the first space
|
||||
const chromeExecRegex = '^Exec=/.*/(google-chrome|chrome|chromium)-.*'
|
||||
const installations = []
|
||||
|
||||
+2
-2
@@ -13,11 +13,11 @@ export {
|
||||
VueMetaServerPlugin
|
||||
}
|
||||
|
||||
export function getVue() {
|
||||
export function getVue () {
|
||||
return createLocalVue()
|
||||
}
|
||||
|
||||
export function loadVueMetaPlugin(browser, options, localVue = getVue()) {
|
||||
export function loadVueMetaPlugin (browser, options, localVue = getVue()) {
|
||||
if (browser) {
|
||||
localVue.use(VueMetaBrowserPlugin, Object.assign({}, defaultOptions, options))
|
||||
} else {
|
||||
|
||||
@@ -5,7 +5,7 @@ const metaInfoData = {
|
||||
add: {
|
||||
data: 'Hello World',
|
||||
expect: ['<title>Hello World</title>'],
|
||||
test(side, defaultTest) {
|
||||
test (side, defaultTest) {
|
||||
if (side === 'client') {
|
||||
// client side vue-meta uses document.title and doesnt change the html
|
||||
return () => {
|
||||
@@ -65,7 +65,7 @@ const metaInfoData = {
|
||||
'<meta data-vue-meta="test" charset="utf-16">',
|
||||
'<meta data-vue-meta="test" property="a" content="c">'
|
||||
],
|
||||
test(side, defaultTest) {
|
||||
test (side, defaultTest) {
|
||||
if (side === 'client') {
|
||||
return () => {
|
||||
const tags = defaultTest()
|
||||
@@ -120,7 +120,7 @@ const metaInfoData = {
|
||||
'<script data-vue-meta="test" src="src" defer data-vmid="content"></script>',
|
||||
'<script data-vue-meta="test" src="src" defer data-body="true"></script>'
|
||||
],
|
||||
test(side, defaultTest) {
|
||||
test (side, defaultTest) {
|
||||
return () => {
|
||||
if (side === 'client') {
|
||||
for (const index in this.expect) {
|
||||
|
||||
Reference in New Issue
Block a user