Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(nuxt): allow plugins with .jsx or .tsx extensions
  • Loading branch information
toyi committed Mar 13, 2024
commit 5e40c92f264f678cbbc2f1ce4cec28bc2835bba7
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 @@ export async function resolveApp (nuxt: Nuxt, app: NuxtApp) {
...(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}/*.{ts,js,mjs,cjs,mts,cts,jsx,tsx}`,
`${pluginDir}/*/index.*{ts,js,mjs,cjs,mts,cts,jsx,tsx}` // TODO: remove, only scan top-level plugins #18418
])
: []
].map(plugin => normalizePlugin(plugin as NuxtPlugin)))
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
6 changes: 3 additions & 3 deletions packages/nuxt/test/plugin-metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ describe('plugin-metadata', () => {
const properties = Object.entries({
name: 'test',
enforce: 'post',
hooks: { 'app:mounted': () => {} },
setup: () => {},
hooks: { 'app:mounted': () => { } },
setup: () => { return { provide: { jsx: '[JSX]' } } },
order: 1
})

Expand All @@ -19,7 +19,7 @@ describe('plugin-metadata', () => {

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