mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +00:00
fix(nuxt): do not apply import protection to top-level resolution (#7344)
This commit is contained in:
parent
83949c3734
commit
9abc7a2122
@ -1,4 +1,4 @@
|
|||||||
import { normalize, resolve } from 'pathe'
|
import { join, normalize, resolve } from 'pathe'
|
||||||
import { createHooks } from 'hookable'
|
import { createHooks } from 'hookable'
|
||||||
import type { Nuxt, NuxtOptions, NuxtConfig, ModuleContainer, NuxtHooks } from '@nuxt/schema'
|
import type { Nuxt, NuxtOptions, NuxtConfig, ModuleContainer, NuxtHooks } from '@nuxt/schema'
|
||||||
import { loadNuxtConfig, LoadNuxtOptions, nuxtCtx, installModule, addComponent, addVitePlugin, addWebpackPlugin, tryResolveModule } from '@nuxt/kit'
|
import { loadNuxtConfig, LoadNuxtOptions, nuxtCtx, installModule, addComponent, addVitePlugin, addWebpackPlugin, tryResolveModule } from '@nuxt/kit'
|
||||||
@ -62,6 +62,8 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
// Add import protection
|
// Add import protection
|
||||||
const config = {
|
const config = {
|
||||||
rootDir: nuxt.options.rootDir,
|
rootDir: nuxt.options.rootDir,
|
||||||
|
// Exclude top-level resolutions by plugins
|
||||||
|
exclude: [join(nuxt.options.rootDir, 'index.html')],
|
||||||
patterns: vueAppPatterns(nuxt)
|
patterns: vueAppPatterns(nuxt)
|
||||||
}
|
}
|
||||||
addVitePlugin(ImportProtectionPlugin.vite(config))
|
addVitePlugin(ImportProtectionPlugin.vite(config))
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { createRequire } from 'node:module'
|
import { createRequire } from 'node:module'
|
||||||
import { createUnplugin } from 'unplugin'
|
import { createUnplugin } from 'unplugin'
|
||||||
import { logger } from '@nuxt/kit'
|
import { logger } from '@nuxt/kit'
|
||||||
import { isAbsolute, relative, resolve } from 'pathe'
|
import { isAbsolute, join, relative, resolve } from 'pathe'
|
||||||
import type { Nuxt } from '@nuxt/schema'
|
import type { Nuxt } from '@nuxt/schema'
|
||||||
import escapeRE from 'escape-string-regexp'
|
import escapeRE from 'escape-string-regexp'
|
||||||
|
|
||||||
@ -32,6 +32,12 @@ export const ImportProtectionPlugin = createUnplugin(function (options: ImportPr
|
|||||||
enforce: 'pre',
|
enforce: 'pre',
|
||||||
resolveId (id, importer) {
|
resolveId (id, importer) {
|
||||||
if (!importer) { return }
|
if (!importer) { return }
|
||||||
|
if (id.startsWith('.')) {
|
||||||
|
id = join(importer, '..', id)
|
||||||
|
}
|
||||||
|
if (isAbsolute(id)) {
|
||||||
|
id = relative(options.rootDir, id)
|
||||||
|
}
|
||||||
if (importersToExclude.some(p => typeof p === 'string' ? importer === p : p.test(importer))) { return }
|
if (importersToExclude.some(p => typeof p === 'string' ? importer === p : p.test(importer))) { return }
|
||||||
|
|
||||||
const invalidImports = options.patterns.filter(([pattern]) => pattern instanceof RegExp ? pattern.test(id) : pattern === id)
|
const invalidImports = options.patterns.filter(([pattern]) => pattern instanceof RegExp ? pattern.test(id) : pattern === id)
|
||||||
|
Loading…
Reference in New Issue
Block a user