import testRule from 'skypager-util/lib/path-matcher'

export const rules = [
  /package.json$/
]

export const testDocument = (doc) => (
  typeof rules.find(rule => testRule(rule, doc.fileBaseName)) !== 'undefined'
)

export const decorate = (doc) => {
  return Object.assign(doc, {
    loadProject(options = {}) {
      return doc.project
        ? doc.project.portfolio.load(doc.file.dirname, {fresh: true, sync: false})
        : doc.project
    }
  })
}

export default decorate
