Skip to content

Better ignores implementation / documentation #2017

@davestewart

Description

@davestewart

Is your feature request related to a problem?

Overview

The current ignores implementation has a few issues:

  • options are converted to RegExps which only work as folder / file name prefixes
  • this a) is not made clear in the docs and b) could be avoided
  • content watching / refresh does not respect ignored files

Implementation

Looking at the ignore code, it means ignore options can only ever be prefixes:

export const contentIgnores: Array<RegExp> = contentConfig.ignores.map((p: any) =>
  typeof p === 'string' ? new RegExp(`^${p}\|:${p}`) : p

This makes sense in the terms of the supplied defaults:

ignores: ['\\.', '-'],

But is limiting in terms of more flexible ignoring (unless you get quite creative with the input strings).

Additionally: the implementation suggests that RegExps might be able to be passed, but they seem to get nuked by being squeezed through getRuntimeConfig().

Docs

The docs actually don't mention the prefixing, they suggest you can ignore words:

This should be clarified.

File watching

It looks like the ignores config doesn't have any effect on the storage instance at the bottom of src/module.ts.

Saving ignored files still triggers refreshNuxtData() via a sockets call.

Describe the solution you'd like

To support the documented ignores format, change the default to:

const ignores: string[] = [
  '^[.-]|:[.-]'
]

And simplify the contentIgnores map to:

const contentIgnores = contentConfig.ignores.map(p => new RegExp(p))

Although, if prefixing is a specific design decision, then document it and provide a couple of examples:

[
  '.+?\\.txt$' // converts to /:.+?\.txt$/, matching text files only
]

To prevent triggering a refresh when changing ignored files, in the module watch use the same algorithm to prevent a sockets broadcast:

      await nitro.storage.watch(async (event: WatchEvent, key: string) => {
        // Ignore events that are not related to content
        if (isIgnored(key)) {
          return
        }
        ...
      })

Finally, as the ignore functionality will be used three times at this point, consolidate into a reusable function:

Describe alternatives you've considered

I've been poring through the ignores code in the IDE and debugger, and pretty sure this is the only option.

Additional context

Trying to optimise the updating code in Nuxt Content Assets:

Pretty sure I know enough about Nuxt Content's source now to do a PR.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions