2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-25 00:10:34 +03:00

chore: fix lint

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