Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nuxt): allow auto-registration of plugins with .jsx or .tsx extensions #26230

Merged
merged 5 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/nuxt/src/core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@
...(config.plugins || []),
...config.srcDir
? await resolveFiles(config.srcDir, [
`${pluginDir}/*.{ts,js,mjs,cjs,mts,cts}`,
`${pluginDir}/*/index.*{ts,js,mjs,cjs,mts,cts}` // TODO: remove, only scan top-level plugins #18418
`${pluginDir}/*{${nuxt.options.extensions.join(',')}}`,
`${pluginDir}/*/index{${nuxt.options.extensions.join(',')}}` // TODO: remove, only scan top-level plugins #18418
])
: []
].map(plugin => normalizePlugin(plugin as NuxtPlugin)))
Expand Down Expand Up @@ -225,7 +225,7 @@
for (const plugin of _plugins) {
// Make sure dependency plugins are registered
if (plugin.dependsOn && plugin.dependsOn.some(name => !pluginNames.includes(name))) {
console.error(`Plugin \`${plugin.name}\` depends on \`${plugin.dependsOn.filter(name => !pluginNames.includes(name)).join(', ')}\` but they are not registered.`)

Check warning on line 228 in packages/nuxt/src/core/app.ts

View workflow job for this annotation

GitHub Actions / code

Unexpected console statement
}
// Make graph to detect circular dependencies
if (plugin.name) {
Expand All @@ -234,7 +234,7 @@
}
const checkDeps = (name: string, visited: string[] = []): string[] => {
if (visited.includes(name)) {
console.error(`Circular dependency detected in plugins: ${visited.join(' -> ')} -> ${name}`)

Check warning on line 237 in packages/nuxt/src/core/app.ts

View workflow job for this annotation

GitHub Actions / code

Unexpected console statement
return []
}
visited.push(name)
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/core/plugins/plugin-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function extractMetadata (code: string) {
if (metaCache[code]) {
return metaCache[code]
}
const js = await transform(code, { loader: 'ts' })
const js = await transform(code, { loader: 'tsx' })
walk(parse(js.code, {
sourceType: 'module',
ecmaVersion: 'latest'
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/test/plugin-metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
name: 'test',
enforce: 'post',
hooks: { 'app:mounted': () => {} },
setup: () => {},
setup: () => { return { provide: { jsx: '[JSX]' } } },
order: 1
})

Expand All @@ -19,7 +19,7 @@

const meta = await extractMetadata([
'export default defineNuxtPlugin({',
...obj.map(([key, value]) => `${key}: ${typeof value === 'function' ? value.toString() : JSON.stringify(value)},`),
...obj.map(([key, value]) => `${key}: ${typeof value === 'function' ? value.toString().replace('"[JSX]"', '() => <span>JSX</span>') : JSON.stringify(value)},`),
'})'
].join('\n'))

Expand Down Expand Up @@ -83,7 +83,7 @@
src: ''
}
])
expect(console.error).toBeCalledWith('Plugin `B` depends on `D` but they are not registered.')

Check warning on line 86 in packages/nuxt/test/plugin-metadata.test.ts

View workflow job for this annotation

GitHub Actions / code

Unexpected console statement
vi.restoreAllMocks()
})

Expand All @@ -106,9 +106,9 @@
src: ''
}
])
expect(console.error).toBeCalledWith('Circular dependency detected in plugins: A -> B -> C -> A')

Check warning on line 109 in packages/nuxt/test/plugin-metadata.test.ts

View workflow job for this annotation

GitHub Actions / code

Unexpected console statement
expect(console.error).toBeCalledWith('Circular dependency detected in plugins: B -> C -> A -> B')

Check warning on line 110 in packages/nuxt/test/plugin-metadata.test.ts

View workflow job for this annotation

GitHub Actions / code

Unexpected console statement
expect(console.error).toBeCalledWith('Circular dependency detected in plugins: C -> A -> B -> C')

Check warning on line 111 in packages/nuxt/test/plugin-metadata.test.ts

View workflow job for this annotation

GitHub Actions / code

Unexpected console statement
vi.restoreAllMocks()
})
})