Skip to content

Commit

Permalink
fix(store): warn and skip when duplicate path detected
Browse files Browse the repository at this point in the history
  • Loading branch information
hjvedvik committed Nov 2, 2018
1 parent 86363c3 commit 215b3e9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 7 additions & 2 deletions gridsome/lib/app/ContentTypeCollection.js
Expand Up @@ -4,6 +4,7 @@ const camelCase = require('camelcase')
const dateFormat = require('dateformat')
const slugify = require('@sindresorhus/slugify')
const { mapKeys, cloneDeep, deepMerge } = require('lodash')
const { warn } = require('../utils/log')

class ContentTypeCollection extends EventEmitter {
constructor (store, pluginStore, options) {
Expand Down Expand Up @@ -41,8 +42,12 @@ class ContentTypeCollection extends EventEmitter {
mimeTypes[mimeType] = this._pluginStore._transformers[mimeType]
}

this.collection.insert(node)
this.emit('change', node)
try {
this.collection.insert(node)
this.emit('change', node)
} catch (err) {
warn(`Skipping duplicate path for ${node.path}`, this.typeName)
}

return node
}
Expand Down
21 changes: 21 additions & 0 deletions gridsome/lib/utils/log.js
@@ -0,0 +1,21 @@
const chalk = require('chalk')

exports.log = function (message, tag) {
log('log', null, message, tag)
}

exports.warn = function (message, tag) {
log('warn', 'yellow', message, tag)
}

exports.error = function (message, tag) {
log('error', 'red', message, tag)
}


function log (type, color, message, tag) {
const formatted = color ? chalk[color](message) : message
const fn = console[type]

tag ? fn(tag, '>', formatted) : fn(format)
}

0 comments on commit 215b3e9

Please sign in to comment.