Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

Commit a0bda70

Browse files
committed
fix: exclude nitro renderer from import protection
1 parent 484714a commit a0bda70

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/nuxt/src/core/nitro.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ export async function initNitro (nuxt: Nuxt) {
112112
patterns: [
113113
...['#app', /^#build(\/|$)/]
114114
.map(p => [p, 'Vue app aliases are not allowed in server routes.']) as [RegExp | string, string][]
115-
]
115+
],
116+
exclude: [/core[\\/]runtime[\\/]nitro[\\/]renderer/]
116117
}))
117118

118119
// Extend nitro config with hook

packages/nuxt/src/core/plugins/import-protection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const _require = createRequire(import.meta.url)
1010
interface ImportProtectionOptions {
1111
rootDir: string
1212
patterns: [importPattern: string | RegExp, warning?: string][]
13+
exclude?: Array<RegExp | string>
1314
}
1415

1516
export const vueAppPatterns = (nuxt: Nuxt) => [
@@ -25,10 +26,13 @@ export const vueAppPatterns = (nuxt: Nuxt) => [
2526

2627
export const ImportProtectionPlugin = createUnplugin(function (options: ImportProtectionOptions) {
2728
const cache: Record<string, Map<string | RegExp, boolean>> = {}
29+
const importersToExclude = options?.exclude || []
2830
return {
2931
name: 'nuxt:import-protection',
3032
enforce: 'pre',
3133
resolveId (id, importer) {
34+
if (importersToExclude.some(p => typeof p === 'string' ? importer === p : p.test(importer))) { return }
35+
3236
const invalidImports = options.patterns.filter(([pattern]) => pattern instanceof RegExp ? pattern.test(id) : pattern === id)
3337
let matched: boolean
3438
for (const match of invalidImports) {

0 commit comments

Comments
 (0)