diff --git a/packages/nuxt/src/components/module.ts b/packages/nuxt/src/components/module.ts index d21bc541c7..c086d6ee29 100644 --- a/packages/nuxt/src/components/module.ts +++ b/packages/nuxt/src/components/module.ts @@ -98,7 +98,7 @@ export default defineNuxtModule({ pattern: dirOptions.pattern || `**/*.{${extensions.join(',')},}`, ignore: [ '**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}', // ignore mixins - '**/*.d.ts', // .d.ts files + '**/*.d.{cts,mts,ts}', // .d.ts files ...(dirOptions.ignore || []) ], transpile: (transpile === 'auto' ? dirPath.includes('node_modules') : transpile) diff --git a/packages/nuxt/src/components/transform.ts b/packages/nuxt/src/components/transform.ts index 3872703cd7..579cf42e7b 100644 --- a/packages/nuxt/src/components/transform.ts +++ b/packages/nuxt/src/components/transform.ts @@ -5,6 +5,7 @@ import { createUnimport } from 'unimport' import { createUnplugin } from 'unplugin' import { parseURL } from 'ufo' import { parseQuery } from 'vue-router' +import { normalize } from 'pathe' import type { getComponentsT } from './module' const COMPONENT_QUERY_RE = /[?&]nuxt_component=/ @@ -45,7 +46,8 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT return createUnplugin(() => ({ name: 'nuxt:components:imports', transformInclude (id) { - return !isIgnored(id) + id = normalize(id) + return id.startsWith('virtual:') || id.startsWith(nuxt.options.buildDir) || !isIgnored(id) }, async transform (code, id) { // Virtual component wrapper diff --git a/packages/nuxt/src/core/builder.ts b/packages/nuxt/src/core/builder.ts index 9a397d4e9a..c6fd13cda3 100644 --- a/packages/nuxt/src/core/builder.ts +++ b/packages/nuxt/src/core/builder.ts @@ -76,13 +76,12 @@ function createWatcher () { ignoreInitial: true, ignored: [ isIgnored, - '.nuxt', 'node_modules' ] }) watcher.on('all', (event, path) => nuxt.callHook('builder:watch', event, normalize(path))) - nuxt.hook('close', () => watcher.close()) + nuxt.hook('close', () => watcher?.close()) } function createGranularWatcher () { @@ -104,7 +103,7 @@ function createGranularWatcher () { } for (const dir of pathsToWatch) { pending++ - const watcher = chokidar.watch(dir, { ...nuxt.options.watchers.chokidar, ignoreInitial: false, depth: 0, ignored: [isIgnored] }) + const watcher = chokidar.watch(dir, { ...nuxt.options.watchers.chokidar, ignoreInitial: false, depth: 0, ignored: [isIgnored, '**/node_modules'] }) const watchers: Record = {} watcher.on('all', (event, path) => { @@ -113,13 +112,13 @@ function createGranularWatcher () { nuxt.callHook('builder:watch', event, path) } if (event === 'unlinkDir' && path in watchers) { - watchers[path].close() + watchers[path]?.close() delete watchers[path] } if (event === 'addDir' && path !== dir && !ignoredDirs.has(path) && !pathsToWatch.includes(path) && !(path in watchers) && !isIgnored(path)) { watchers[path] = chokidar.watch(path, { ...nuxt.options.watchers.chokidar, ignored: [isIgnored] }) watchers[path].on('all', (event, path) => nuxt.callHook('builder:watch', event, normalize(path))) - nuxt.hook('close', () => watchers[path].close()) + nuxt.hook('close', () => watchers[path]?.close()) } }) watcher.on('ready', () => { @@ -150,7 +149,6 @@ async function createParcelWatcher () { }, { ignore: [ ...nuxt.options.ignore, - '.nuxt', 'node_modules' ] }) diff --git a/packages/schema/src/config/common.ts b/packages/schema/src/config/common.ts index 1e13d6c269..ffd76c8b45 100644 --- a/packages/schema/src/config/common.ts +++ b/packages/schema/src/config/common.ts @@ -1,5 +1,5 @@ import { defineUntypedSchema } from 'untyped' -import { join, resolve } from 'pathe' +import { join, relative, resolve } from 'pathe' import { isDebug, isDevelopment } from 'std-env' import { defu } from 'defu' import { findWorkspaceDir } from 'pkg-types' @@ -352,14 +352,13 @@ export default defineUntypedSchema({ */ ignore: { $resolve: async (val, get) => [ - '**/*.stories.{js,ts,jsx,tsx}', // ignore storybook files - '**/*.{spec,test}.{js,ts,jsx,tsx}', // ignore tests - '**/*.d.ts', // ignore type declarations - '.output', - '.git', - '.cache', - await get('analyzeDir'), - await get('buildDir'), + '**/*.stories.{js,cts,mts,ts,jsx,tsx}', // ignore storybook files + '**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}', // ignore tests + '**/*.d.{cts,mts,ts}', // ignore type declarations + '**/.{vercel,netlify,output,git,cache,data}', + '**/dist', + relative(await get('rootDir'), await get('analyzeDir')), + relative(await get('rootDir'), await get('buildDir')), await get('ignorePrefix') && `**/${await get('ignorePrefix')}*.*` ].concat(val).filter(Boolean) }, diff --git a/test/setup.ts b/test/setup.ts index a444d934b2..e04fd8d8f4 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -10,7 +10,9 @@ export async function setup () { if (fs.existsSync(tempDir)) { await fs.remove(tempDir) } - await fs.copy(fixtureDir, tempDir) + await fs.copy(fixtureDir, tempDir, { + filter: src => !src.includes('.cache') + }) } export async function teardown () {