fix(nuxt3): don't restrict nitro/nuxt3 runtime components (#2885)

This commit is contained in:
Daniel Roe 2022-01-24 14:32:08 +00:00 committed by GitHub
parent 03cc1913a3
commit 81ee59ce0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,14 +14,14 @@ interface ImportProtectionOptions {
const escapeRE = (str: string) => str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
export const vueAppPatterns = (nuxt: Nuxt) => [
[/(^|node_modules\/)(nuxt3|nuxt)/, '`nuxt3`/`nuxt` cannot be imported directly. Instead, import runtime Nuxt composables from `#app` or `#imports`.'],
[/^(nuxt3|nuxt)/, '`nuxt3`/`nuxt` cannot be imported directly. Instead, import runtime Nuxt composables from `#app` or `#imports`.'],
[/nuxt\.config/, 'Importing directly from a `nuxt.config` file is not allowed. Instead, use runtime config or a module.'],
[/(^|node_modules\/)@vue\/composition-api/],
...nuxt.options.modules.filter(m => typeof m === 'string').map((m: string) =>
[new RegExp(`^${escapeRE(m)}$`), 'Importing directly from module entrypoints is not allowed.']),
...['#static-assets', '#static', '#config', '#assets', '#storage', '#server-middleware']
.map(i => [i, 'Nitro aliases cannot be imported in the Vue part of your app.']),
...[/(^|node_modules\/)@nuxt\/kit/, /(^|node_modules\/)@nuxt\/nitro/]
...[/(^|node_modules\/)@nuxt\/kit/, /^@nuxt\/nitro/]
.map(i => [i, 'This module cannot be imported in the Vue part of your app.']),
[new RegExp(escapeRE(resolve(nuxt.options.srcDir, (nuxt.options.dir as any).server || 'server'))), 'Importing from server middleware is not allowed in the Vue part of your app.']
] as ImportProtectionOptions['patterns']