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

Revert "feat: generate middleware types" #824

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions packages/bridge-schema/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import app from './app'
import build from './build'
import cli from './cli'
Expand Down
6 changes: 1 addition & 5 deletions packages/bridge/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useNuxt, addTemplate, resolveAlias, addWebpackPlugin, addVitePlugin, ad
import { NuxtModule } from '@nuxt/schema'
import { normalize, resolve } from 'pathe'
import { resolveImports } from 'mlly'
import { componentsTypeTemplate, schemaTemplate, middlewareTypeTemplate } from './type-templates'
import { componentsTypeTemplate, schemaTemplate } from './type-templates'
import { distDir } from './dirs'
import { VueCompat } from './vue-compat'

Expand Down Expand Up @@ -57,12 +57,8 @@ export async function setupAppBridge (_options: any) {
...componentsTypeTemplate,
options: { components, buildDir: nuxt.options.buildDir }
})

addTemplate(middlewareTypeTemplate)

nuxt.hook('prepare:types', ({ references }) => {
references.push({ path: resolve(nuxt.options.buildDir, 'types/components.d.ts') })
references.push({ path: resolve(nuxt.options.buildDir, 'types/middleware.d.ts') })
})

// Augment schema with module types
Expand Down
1 change: 1 addition & 0 deletions packages/bridge/src/runtime/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import type { NuxtAppCompat } from '@nuxt/bridge-schema'
import { defineComponent, getCurrentInstance } from './composables'
export const isVue2 = true
Expand Down
25 changes: 4 additions & 21 deletions packages/bridge/src/type-templates.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import { isAbsolute, relative, join } from 'pathe'
import type { Component, Nuxt, NuxtApp } from '@nuxt/schema'
import { genDynamicImport, genString } from 'knitwork'
Expand All @@ -9,11 +10,6 @@ type ComponentsTemplateOptions = {
components: Component[]
}

interface TemplateContext {
nuxt: Nuxt
app: NuxtApp & { templateVars: Record<string, any> }
}

export const componentsTypeTemplate = {
filename: 'types/components.d.ts',
getContents: ({ options }: { options: ComponentsTemplateOptions }) => {
Expand All @@ -32,22 +28,9 @@ export const componentNames: string[]
}
}

export const middlewareTypeTemplate = {
filename: 'types/middleware.d.ts',
getContents: ({ app }: TemplateContext) => {
const middleware = app.templateVars.middleware

return [
'import type { NuxtAppCompat } from \'@nuxt/bridge-schema\'',
`export type MiddlewareKey = ${middleware.map(mw => genString(mw.name)).join(' | ') || 'string'}`,
'declare module \'vue/types/options\' {',
' export type Middleware = MiddlewareKey | ((ctx: NuxtAppCompat, cb: Function) => Promise<void> | void)',
' interface ComponentOptions<V extends Vue> {',
' middleware?: Middleware | Middleware[]',
' }',
'}'
].join('\n')
}
interface TemplateContext {
nuxt: Nuxt
app: NuxtApp
}

const adHocModules = ['router', 'pages', 'auto-imports', 'meta', 'components']
Expand Down